From: Steve Sutton Date: Fri, 10 Jul 2015 18:35:26 +0000 (-0400) Subject: Adding code for putting together the pages X-Git-Tag: v0.0.2^2~44 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d0c9426c32c2bc3a97e43d2906b9bbda7d7c46fe;p=WP-Plugins%2Fglm-wp-importer.git Adding code for putting together the pages --- diff --git a/NOTES.md b/NOTES.md index 4f0e03c..bd35942 100644 --- a/NOTES.md +++ b/NOTES.md @@ -48,3 +48,6 @@ $post = array( 'page_template' => [ ] // Requires name of template file, eg template.php. Default empty. ); ``` + +##Settings +Will also need to add the site url to the setting and this will need to be required. I need to build the urls for the images. diff --git a/controllers/Import.php b/controllers/Import.php index 5aa61e4..c17725d 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -43,13 +43,17 @@ class Toolbox_Import extends WP_Importer { private $_dbh; + private $_post; function __construct() { } function connect() { - // read optios for the import and if they aren't set then give a warning. + if ($this->_dbh) { + return; + } + // read options for the import and if they aren't set then give a warning. $options = get_option(GLM_WP_IMPORT_SETTINGS); // try making a postgres connection to the database $connString = 'dbname=' . $options['db_name']; @@ -86,13 +90,112 @@ echo 'Start the Import Now'; } + function displayImage($data, $alignment) + { + if ($data['caption']) { + $content .= '[caption id="attachment_'.$data['id'].'" align="align'.$alignment.'"]' + .' ' + . $data['caption'] . '[/caption]'; + } else { + $content .= ''; + } + return $content; + } + function fetchAllPages() { + $this->connect(); + $pageSql = " + SELECT * + FROM toolbox.pages + ORDER BY parent,pos"; + $pageData = $this->_dbh->query($pageSql)->fetchAll(PDO::FETCH_ASSOC); + $paragraphSql = " + SELECT * + FROM toolbox.paragraphs + WHERE page = :page + ORDER BY pos"; + $paraStmt = $this->_dbh->prepare($paragraphSql); + $data = $this->_dbh->query($pageSql)->fetchAll(); + foreach ($data as &$page) { + $paraStmt->bindParam(':page', $page['id'], PDO::PARAM_INT); + $paraStmt->execute(); + $paragraphs = $paraStmt->fetchAll(PDO::FETCH_ASSOC); + $primaryAlign = 'right'; + $secondaryAlign = 'right'; + $alternateImg = false; + + switch ($page['template']) { + case 1: + break; + case 2: + $primaryAlign = 'left'; + $secondaryAlign = 'left'; + break; + case 3: + $secondaryAlign = 'left'; + $alternateImg = true; + break; + case 4: + $primaryAlign = 'left'; + $alternateImg = true; + break; + case 5: + $primaryAlign = 'left'; + break; + case 6: + $secondaryAlign = 'left'; + break; + } + $iterator = 1; + $page['pageContent'] = ''; + foreach ($paragraphs as $paragraph) { + switch ($iterator) { + case 1: + if ($paragraph['title']) { + $page['pageContent'] .= '

'.$paragraph['title'].'

'; + } + if ($paragraph['image']) { + $page['pageContent'] .= $this->displayImage($paragraph, $primaryAlign); + } + break; + case 2: + if ($paragraph['title']) { + $page['pageContent'] .= '

'.$paragraph['title'].'

'; + } + if ($paragraph['image']) { + $page['pageContent'] .= $this->displayImage($paragraph, $secondaryAlign); + } + break; + default: + if ($paragraph['title']) { + $page['pageContent'] .= '

'.$paragraph['title'].'

'; + } + if ($alternateImg && $page['template'] == 3) { + $align = ($iterator%2 == 0) ? 'left' : 'right'; + } else { + $align = $secondaryAlign; + } + if ($paragraph['image']) { + $page['pageContent'] .= $this->displayImage($paragraph, $align); + } + break; + } + $page['pageContent'] .= $paragraph['description']; + ++$iterator; + } + } + return $data; } function import() { - + echo '

Fetching Pages

'; + // grab all pages and build the post array + $pages = $this->fetchAllPages(); + echo '
'.print_r($pages, true).'
'; } function dispatch()