Update for placing the page title into wp posts title.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Jul 2016 12:45:23 +0000 (08:45 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Jul 2016 12:45:23 +0000 (08:45 -0400)
Adding a checkbox for the glm wp importer settings that will enable the
setup to place the page titles into the posts titles. This was needed on
Petoskey Area because their design had a separate area for placing the
page title. Usually it would be inside the page content.

controllers/Admin.php
controllers/ToolboxImport.php
views/checkbox.php [new file with mode: 0644]

index 194b4fc..8721dea 100644 (file)
@@ -87,6 +87,11 @@ class GlmWPImporter_Admin_Controller
         );
 
         $fieldNames = array(
+            array(
+                'name'  => 'navigation_name_in_content',
+                'label' => 'Place the navigation title into page content',
+                'type'  => 'checkbox'
+            ),
             array(
                 'name'  => 'site_url',
                 'label' => 'Site URL',
@@ -189,6 +194,9 @@ class GlmWPImporter_Admin_Controller
             case 'text':
                 $callback = 'glmwpimporterRenderText';
                 break;
+            case 'checkbox':
+                $callback = 'glmwpimporterRenderCheckbox';
+                break;
             default:
                 return false;
                 break;
@@ -212,6 +220,14 @@ class GlmWPImporter_Admin_Controller
         include $this->path . 'views/text.php';
     }
 
+    public function glmwpimporterRenderCheckbox($fieldName) {
+        static $options;
+        if (!$options) {
+            $options = get_option(GLM_WP_IMPORT_SETTINGS);
+        }
+        include $this->path . 'views/checkbox.php';
+    }
+
     public function glmwpimporter_settings_section_callback()
     {
         echo __('Database Options', 'wordpress');
index da836de..9a7b984 100644 (file)
 
         private function _displayFile2($file, $filename)
         {
-            $fileUrl =$this->_options['site_url'] . 'uploads/' . $file;
+            $fileUrl =$this->_options['site_url'] . '/uploads/' . $file;
             $fileName = ($filename) ? $filename : $file;
             return "\n".'<a href="'.$fileUrl.'">'.$fileName.'</a>';
         }
                 $fileStmt = $this->_dbh->prepare($fileSql);
             }
             $data = $this->_dbh->query($pageSql)->fetchAll();
-            //echo '<pre>' . print_r($data, true) . '</pre>';
-            //exit;
             foreach ($data as &$page) {
                 $page['srcs'] = array();
                 $paraStmt->bindParam(':page', $page['id'], PDO::PARAM_INT);
                 $paraStmt->execute();
                 $paragraphs     = $paraStmt->fetchAll();
-            //echo '<pre>' . print_r($paragraphs, true) . '</pre>';
-            //exit;
                 $primaryAlign   = 'right';
                 $secondaryAlign = 'right';
                 $alternateImg   = false;
                 $page['pageContent'] = '';
                 $iterator = 1;
                 if ($this->_options['toolbox_page_table'] == 'bus_category') {
-                    $page['pageContent'] .= '<h1>'.$page['category'].'</h1>';
+                    if ( $this->_options['navigation_name_in_content'] ) {
+                        $page['pageContent'] .= '<h1>'.$page['category'].'</h1>';
+                    } else {
+                        $page['title'] .= $page['category'];
+                    }
                     ++$iterator;
                     if ($page['image']) {
-                        //$page['images'][]     = $page['image'];
                         $page['pageContent'] .= $this->_displayImage($page, $primaryAlign);
                     }
                     $page['pageContent'] .= $page['description'];
                     switch ($iterator) {
                     case 1:
                         if (isset($paragraph['title']) && $paragraph['title']) {
-                            $page['pageContent'] .= '<h1>'.$paragraph['title'].'</h1>';
+                            if ( $this->_options['navigation_name_in_content'] ) {
+                                $page['pageContent'] .= '<h1>'.$paragraph['title'].'</h1>';
+                            } else {
+                                $page['title'] = $paragraph['title'];
+                            }
                         }
                         if (isset($paragraph['image']) && $paragraph['image']) {
-                            //$page['images'][]     = $paragraph['image'];
                             $page['pageContent'] .= $this->_displayImage($paragraph, $primaryAlign);
                         }
                         break;
                             $page['pageContent'] .= '<h2>'.$paragraph['title'].'</h2>';
                         }
                         if (isset($paragraph['image']) && $paragraph['image']) {
-                            //$page['images'][]     = $paragraph['image'];
                             $page['pageContent'] .= $this->_displayImage($paragraph, $secondaryAlign);
                         }
                         break;
                             $align = $secondaryAlign;
                         }
                         if (isset($paragraph['image']) && $paragraph['image']) {
-                            //$page['images'][]     = $paragraph['image'];
                             $page['pageContent'] .= $this->_displayImage($paragraph, $align);
                         }
                         break;
                     }
                     ++$iterator;
                 }
-                //echo '<pre>Files: ' . print_r($page['files'], true) . '</pre>';
             }
             return $data;
         }
                 if ($page['parent']) {
 
                 }
-                $pageName = (isset($page['navigation_name']))
-                    ? $page['navigation_name']
-                    : $page['category'];
+                if ( $page['title'] ) {
+                    $pageName = $page['title'];
+                } else if ( $page['navigation_name'] ) {
+                    $pageName = $page['navigation_name'];
+                } else {
+                    $pageName = $page['category'];
+                }
                 // if you don't find the parent page id then use the default given or 0
                 $parent = isset($this->_post[$page['parent']])
                     ? $this->_post[$page['parent']]
                 $sql = "
                 SELECT *
                   FROM {$this->_options['ckeditor_schema']}.{$this->_options['ckeditor_images_table']}";
-        
+
                 $sql .= " LIMIT $limit OFFSET $offset";
                 $stmt = $this->_dbh->query($sql);
 
diff --git a/views/checkbox.php b/views/checkbox.php
new file mode 100644 (file)
index 0000000..47336b8
--- /dev/null
@@ -0,0 +1,5 @@
+<input type="checkbox" name="<?php echo GLM_WP_IMPORT_SETTINGS;?>[<?php echo $fieldName;?>]"
+value="1" <?php if ($options[$fieldName]) {
+    echo ' checked';
+}
+?>>