This update for csrye.org tables
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 23 May 2016 20:07:13 +0000 (16:07 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 23 May 2016 20:07:13 +0000 (16:07 -0400)
This toolbox had the files in the bus table.
They usually are in the files table.

controllers/ToolboxImport.php

index bfae9e3..a643145 100644 (file)
             if (!$this->_options['toolbox_paragraphs_table']) {
                 $errors[] = 'Toolbox Paragraph Table';
             }
-            if (!$this->_options['toolbox_files_table']) {
-                $errors[] = 'Toolbox Files Table';
-            }
-            if (!$this->_options['toolbox_files_url']) {
-                $errors[] = 'Toolbox Files URL';
-            }
+            //if (!$this->_options['toolbox_files_table']) {
+            //    $errors[] = 'Toolbox Files Table';
+            //}
+            //if (!$this->_options['toolbox_files_url']) {
+            //    $errors[] = 'Toolbox Files URL';
+            //}
             return $errors;
         }
 
 
         private function _displayFile($data)
         {
-            //if ($this->_options['toolbox_paragraphs_table'] == 'pages') {
-                //$file_id = $this->_handleMediaFile($data['filename']);
-            //} else {
-                //$file_id = $this->_handleMediaFile(
-                    //$data['filename'],
-                    //'',
-                    //0,
-                    //$this->_options['site_url'] . 'uploads/'
-                //);
-            //}
-
-            //if (!$file_id) {
-                //return false;
-            //}
-            //$fileUrl = wp_get_attachment_url($file_id);
             $fileUrl =$this->_options['toolbox_files_url'] . '/' . $data['filename'];
             $fileName = ($data['urltext']) ? $data['urltext'] : $data['filename'];
             return "\n".'<a href="'.$fileUrl.'">'.$fileName.'</a>';
         }
 
+        private function _displayFile2($file, $filename)
+        {
+            $fileUrl =$this->_options['site_url'] . 'uploads/' . $file;
+            $fileName = ($filename) ? $filename : $file;
+            return "\n".'<a href="'.$fileUrl.'">'.$fileName.'</a>';
+        }
+
+
         private function _addMedia($file, $postId)
         {
             $fileType = wp_check_filetype(basename($file), null);
                 FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']}
                 $WHERE
             ORDER BY parent,pos";
-            $pageSql .= ($limit) ? " LIMIT $limit OFFSET $offset" : '';
+            //$pageSql .= ($limit) ? " LIMIT $limit OFFSET $offset" : '';
             $pageData = $this->_dbh->query($pageSql)->fetchAll(PDO::FETCH_ASSOC);
             if ($this->_options['toolbox_page_table'] == 'pages') {
                 $paragraphSql = "
                    WHERE bcb.catid = :page
                 ORDER BY bcb.pos";
                 $paraStmt = $this->_dbh->prepare($paragraphSql);
-                $fileSql = "
-                  SELECT *
-                    FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_files_table']}
-                   WHERE bus_id = :pid
-                ORDER BY bus_id,pos";
+                if ($this->_options['toolbox_files_table'] == 'pages') {
+                    $fileSql = "
+                      SELECT *
+                        FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_files_table']}
+                       WHERE bus_id = :pid
+                    ORDER BY bus_id,pos";
+                } else {
+                    $fileSql = "
+                      SELECT file,filename,file2,file2name,file3,file3name
+                        FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_paragraphs_table']}
+                       WHERE id = :pid";
+                }
                 $fileStmt = $this->_dbh->prepare($fileSql);
             }
             $data = $this->_dbh->query($pageSql)->fetchAll();
                         break;
                     }
                     $page['pageContent'] .= $paragraph['description'];
-                    //preg_match_all("/<img .*?(?=src)src=\"([^\"]+)\"/si", $paragraph['description'], $matches);
-            //echo '<pre>' . print_r($matches, true) . '</pre>';
-
-                    /*
-                    for ($i = 0; $i < count($matches[0]); $i++) {
-                        if ($matches[1][$i]) {
-                            $newSrc  = $this->_getDescriptionImage($matches[1][$i]);
-                            $parsUrl = parse_url($newSrc);
-                            $imgName = basename($parsUrl['path']);
-                            $page['pageContent'] = str_replace($matches[1][$i], $newSrc, $page['pageContent']);
-                            $page['srcs'][] = $imgName;
-                        }
-                    }
-                     */
-                    //var_dump($paragraph['id']);
                     $fileStmt->bindParam(':pid', $paragraph['id'], PDO::PARAM_INT);
                     $fileStmt->execute();
                     while ($file = $fileStmt->fetch()) {
-            //echo '<pre>Files: ' . print_r($file, true) . '</pre>';
-                        //$page['files'][] = $file['filename'];
-                        $page['pageContent'] .= $this->_displayFile($file);
+                        echo '<pre>$file: ' . print_r($file, true) . '</pre>';
+                        if ($this->_options['toolbox_files_table'] == 'pages') {
+                            $page['pageContent'] .= $this->_displayFile($file);
+                        } else {
+                            if ($file['file']) {
+                                $page['pageContent'] .= $this->_displayFile2($file['file'], $file['filename']);
+                            }
+                            if ($file['file2']) {
+                                $page['pageContent'] .= $this->_displayFile2($file['file2'], $file['file2name']);
+                            }
+                            if ($file['file3']) {
+                                $page['pageContent'] .= $this->_displayFile2($file['file3'], $file['file3name']);
+                            }
+                        }
                     }
                     ++$iterator;
                 }