From b832fe18d2cab9b273dac576c90f956f1e9defa6 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 14 Jul 2015 10:44:44 -0400 Subject: [PATCH] File now working Now it grabs the files and puts them into the post_content. Also adds the files into the Media Library. --- controllers/Admin.php | 2 +- controllers/Import.php | 42 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/controllers/Admin.php b/controllers/Admin.php index 98f45d5..dd21ff3 100644 --- a/controllers/Admin.php +++ b/controllers/Admin.php @@ -149,7 +149,7 @@ class GlmWPImporter_Admin_Controller ), array( 'name' => 'member_page_id', - 'label' => 'Page ID for Members Only', + 'label' => 'Ignore Pages', 'type' => 'text' ), ); diff --git a/controllers/Import.php b/controllers/Import.php index 33ced49..eb5f72e 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -224,7 +224,8 @@ if (!$img_id) { return false; } - $img_url = wp_get_attachment_url($img_id); + $image = wp_get_attachment_image_src($img_id, 'medium'); + $img_url = $image[0]; if ($data['caption']) { $content .= '[caption id="attachment_'.$img_id.'" align="align'.$alignment.'"]' .'_handleMediaFile($data['filename']); + if (!$file_id) { + return false; + } + $fileUrl = wp_get_attachment_url($file_id); + $fileName = ($data['urltext']) ? $data['urltext'] : $data['filename']; + return "\n".''.$fileName.''; + } + /** * _handleMediaFile * @@ -328,9 +340,9 @@ curl_close($ch); fclose($fp); // Set correct file permissions - $stat = stat( dirname( $path . '/' . $filename ) ); - $perms = $stat['mode'] & 0000666; - @chmod( $path . '/' . $filename, $perms ); + $oldUmask = umask(0); + chmod( $path . '/' . $filename, 0660 ); + umask($oldUmask); return $filename; } @@ -348,7 +360,7 @@ $where = ''; if ($this->_options['member_page_id']) { $where = "WHERE id NOT IN ({$this->_options['member_page_id']}) - AND parent != {$this->_options['member_page_id']} "; + AND parent NOT IN ({$this->_options['member_page_id']}) "; } $pageSql = " SELECT * @@ -362,6 +374,12 @@ WHERE page = :page ORDER BY pos"; $paraStmt = $this->_dbh->prepare($paragraphSql); + $fileSql = " + SELECT * + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_files_table']} + WHERE paragraph = :pid + ORDER BY pos"; + $fileStmt = $this->_dbh->prepare($fileSql); $data = $this->_dbh->query($pageSql)->fetchAll(); foreach ($data as &$page) { $paraStmt->bindParam(':page', $page['id'], PDO::PARAM_INT); @@ -431,6 +449,12 @@ break; } $page['pageContent'] .= $paragraph['description']; + $fileStmt->bindParam(':pid', $paragraph['id'], PDO::PARAM_INT); + $fileStmt->execute(); + while ($file = $fileStmt->fetch()) { + $page['files'][] = $file['filename']; + $page['pageContent'] .= $this->_displayFile($file); + } ++$iterator; } } @@ -492,6 +516,12 @@ wp_update_post(array('ID' => $img_id, 'post_parent' => $ID)); } } + foreach ($page['files'] as $file) { + $file_id = array_search($file, $this->_files); + if ($file_id) { + wp_update_post(array('ID' => $file_id, 'post_parent' => $ID)); + } + } } } @@ -501,7 +531,7 @@ /** * dispatch * - * Dispatch Funcion. + * Dispatch Function. * Checks which step admin user is on and calls appropriate methods. * * @access public -- 2.17.1