File now working
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Jul 2015 14:44:44 +0000 (10:44 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Jul 2015 14:44:44 +0000 (10:44 -0400)
Now it grabs the files and puts them into the post_content.
Also adds the files into the Media Library.

controllers/Admin.php
controllers/Import.php

index 98f45d5..dd21ff3 100644 (file)
@@ -149,7 +149,7 @@ class GlmWPImporter_Admin_Controller
             ),
             array(
                 'name'  => 'member_page_id',
-                'label' => 'Page ID for Members Only',
+                'label' => 'Ignore Pages',
                 'type'  => 'text'
             ),
         );
index 33ced49..eb5f72e 100644 (file)
             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.'"]'
                     .'<img class="align'.$alignment.' size-medium wp-image-' . $img_id . '" '
             return $content;
         }
 
+        private function _displayFile($data)
+        {
+            $file_id = $this->_handleMediaFile($data['filename']);
+            if (!$file_id) {
+                return false;
+            }
+            $fileUrl = wp_get_attachment_url($file_id);
+            $fileName = ($data['urltext']) ? $data['urltext'] : $data['filename'];
+            return "\n".'<a href="'.$fileUrl.'">'.$fileName.'</a>';
+        }
+
         /**
          * _handleMediaFile
          *
             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;
         }
 
             $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 *
                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);
                         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;
                 }
             }
                             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));
+                        }
+                    }
                 }
 
             }
         /**
          * dispatch
          *
-         * Dispatch Funcion.
+         * Dispatch Function.
          * Checks which step admin user is on and calls appropriate methods.
          *
          * @access public