Example #1
0
 function display()
 {
     $osamaps = new OnpubSAMaps($this->pdo);
     $oarticles = new OnpubArticles($this->pdo);
     $articles = array();
     en('<h3 class="onpub-field-header">Visible Articles</h3>');
     en('<p>');
     en('<small>These articles will be displayed by the Frontend in the same order as listed below.</small>', 1, 1);
     en('<select name="articleIDs[]" size="10" multiple="multiple" id="articles">');
     $queryOptions = new OnpubQueryOptions();
     $queryOptions->orderBy = "ID";
     $queryOptions->order = "ASC";
     $samaps = $osamaps->select($queryOptions, $this->osection->ID);
     if (sizeof($samaps)) {
         for ($i = 0; $i < sizeof($samaps); $i++) {
             $article = $oarticles->get($samaps[$i]->articleID);
             en('<option value="' . $article->ID . '">' . strip_tags($article->title) . '</option>');
             $articles[] = $article;
         }
     } else {
         en('<option value="">None</option>');
     }
     en('</select>');
     en('</p>');
     en('<p><input type="button" value="Move Up" id="moveUp"> <input type="button" value="Move Down" id="moveDown"> <input type="button" value="Sort By Date" id="sortByDate"> <input type="button" value="Hide" id="hide"></p>');
     // Output articles as JS objects to enable sorting articles list.
     en('<script type="text/javascript">');
     en('var onpub_articles = [');
     for ($i = 0; $i < sizeof($articles); $i++) {
         $created = $articles[$i]->getCreated();
         en('{ID: ' . $articles[$i]->ID . ', title: "' . str_replace('"', '\\"', strip_tags($articles[$i]->title)) . '", created: new Date(' . $created->format("Y") . ', ' . ($created->format("n") - 1) . ', ' . $created->format("j") . ', ' . $created->format("G") . ', ' . $created->format("i") . ', ' . $created->format("s") . ')}', 0);
         if ($i + 1 < sizeof($articles)) {
             en(',');
         }
     }
     en('];');
     en('</script>');
 }
Example #2
0
 /**
  * @param OnpubSection $section The section to be updated.
  * @return int 1 if the section was updated. 0 if the section was not updated or does not exist.
  */
 public function update(OnpubSection $section)
 {
     $oarticles = new OnpubArticles($this->pdo, FALSE);
     $osamaps = new OnpubSAMaps($this->pdo, FALSE);
     $now = new DateTime();
     $inTransaction = FALSE;
     if ($this->enableTransactions) {
         $status = $this->pdo->beginTransaction();
         OnpubDatabase::verifyTransaction($this->pdo, $status);
         $inTransaction = TRUE;
     }
     if ($section->ID == $section->parentID) {
         $section->parentID = NULL;
     }
     if ($section->parentID) {
         $this->enableTransactions = FALSE;
         $parentID = $section->parentID;
         while ($parentID) {
             try {
                 $parent = $this->get($parentID);
             } catch (PDOException $e) {
                 if ($inTransaction) {
                     $this->pdo->rollBack();
                 }
                 throw $e;
             }
             if (!$parent) {
                 $section->parentID = NULL;
                 break;
             }
             if ($section->ID == $parent->parentID) {
                 $section->parentID = NULL;
                 break;
             }
             $parentID = $parent->parentID;
         }
         $this->enableTransactions = TRUE;
     }
     $stmt = $this->pdo->prepare("UPDATE OnpubSections SET imageID = :imageID, parentID = :parentID, name = :name, url = :url, modified = :modified WHERE ID = :ID");
     OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions);
     $ID = $section->ID;
     $imageID = $section->imageID;
     $parentID = $section->parentID;
     $name = OnpubDatabase::utf8Decode(trim($section->name));
     $url = OnpubDatabase::utf8Decode(trim($section->url));
     $modified = $now->format('Y-m-d H:i:s');
     $stmt->bindParam(':ID', $ID);
     $stmt->bindParam(':imageID', $imageID);
     $stmt->bindParam(':parentID', $parentID);
     $stmt->bindParam(':name', $name);
     $stmt->bindParam(':url', $url);
     $stmt->bindParam(':modified', $modified);
     $result = $stmt->execute();
     OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo());
     try {
         $osamaps->delete($section->ID, NULL);
     } catch (PDOException $e) {
         if ($this->enableTransactions) {
             $this->pdo->rollBack();
         }
         throw $e;
     }
     $articles = $section->articles;
     $samaps = array();
     foreach ($articles as $article) {
         if ($article->ID) {
             try {
                 $article = $oarticles->get($article->ID, new OnpubQueryOptions());
             } catch (PDOException $e) {
                 if ($this->enableTransactions) {
                     $this->pdo->rollBack();
                 }
                 throw $e;
             }
             $samap = new OnpubSAMap();
             $samap->sectionID = $section->ID;
             $samap->articleID = $article->ID;
             $samap->setCreated($article->getCreated());
             $samap->setModified($article->getModified());
             $samaps[] = $samap;
         } else {
             try {
                 $articleID = $oarticles->insert($article);
             } catch (PDOException $e) {
                 if ($this->enableTransactions) {
                     $this->pdo->rollBack();
                 }
                 throw $e;
             }
             $samap = new OnpubSAMap();
             $samap->sectionID = $section->ID;
             $samap->articleID = $articleID;
             $samaps[] = $samap;
         }
     }
     try {
         $osamaps->insert($samaps);
     } catch (PDOException $e) {
         if ($this->enableTransactions) {
             $this->pdo->rollBack();
         }
         throw $e;
     }
     if ($this->enableTransactions) {
         $status = $this->pdo->commit();
         OnpubDatabase::verifyTransaction($this->pdo, $status);
     }
     return $stmt->rowCount();
 }
Example #3
0
 /**
  * Update an article already in the database.
  *
  * If you set the article's sectionIDs to NULL, it will be unmapped from
  * any sections it was previously mapped to.
  *
  * @param OnpubArticle $article The article to be updated.
  * @param bool $overwriteAAMaps False by default. If set to TRUE, the
  * article-author maps for this article will be deleted and recreated, if
  * applicable.
  * @return int 1 if the article was updated. 0 if the article does not exist in the database.
  */
 public function update(OnpubArticle $article, $overwriteAAMaps = FALSE)
 {
     $oaamaps = new OnpubAAMaps($this->pdo, FALSE);
     $oauthors = new OnpubAuthors($this->pdo, FALSE);
     $osamaps = new OnpubSAMaps($this->pdo, FALSE);
     $oimages = new OnpubImages($this->pdo, FALSE);
     $now = new DateTime();
     if ($this->enableTransactions) {
         $status = $this->pdo->beginTransaction();
         OnpubDatabase::verifyTransaction($this->pdo, $status);
     }
     $stmt = $this->pdo->prepare("UPDATE OnpubArticles SET imageID = :imageID, title = :title, content = :content, url = :url, created = :created, modified = :modified WHERE ID = :ID");
     OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions);
     if ($article->image) {
         try {
             $imageID = $oimages->insert($article->image);
             $article->imageID = $imageID;
         } catch (PDOException $e) {
             if ($this->enableTransactions) {
                 $this->pdo->rollBack();
             }
             throw $e;
         }
     }
     $ID = $article->ID;
     $imageID = $article->imageID;
     $title = OnpubDatabase::utf8Decode(trim($article->title));
     $content = OnpubDatabase::utf8Decode(trim($article->content));
     $url = OnpubDatabase::utf8Decode(trim($article->url));
     $created = $article->getCreated()->format('Y-m-d H:i:s');
     $modified = $now->format('Y-m-d H:i:s');
     $stmt->bindParam(':ID', $ID);
     $stmt->bindParam(':imageID', $imageID);
     $stmt->bindParam(':title', $title);
     $stmt->bindParam(':content', $content);
     $stmt->bindParam(':url', $url);
     $stmt->bindParam(':created', $created);
     $stmt->bindParam(':modified', $modified);
     $result = $stmt->execute();
     OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo());
     if ($overwriteAAMaps) {
         try {
             $oaamaps->delete($article->ID, NULL);
         } catch (PDOException $e) {
             if ($this->enableTransactions) {
                 $this->pdo->rollBack();
             }
             throw $e;
         }
     }
     $authors = $article->authors;
     foreach ($authors as $author) {
         if ($author->ID) {
             try {
                 $oauthors->update($author);
             } catch (PDOException $e) {
                 if ($this->enableTransactions) {
                     $this->pdo->rollBack();
                 }
                 throw $e;
             }
         } else {
             try {
                 $oauthors->insert($author);
             } catch (PDOException $e) {
                 if ($this->enableTransactions) {
                     $this->pdo->rollBack();
                 }
                 throw $e;
             }
         }
         try {
             $aamap = new OnpubAAMap();
             $aamap->articleID = $article->ID;
             $aamap->authorID = $author->ID;
             $oaamaps->insert($aamap);
         } catch (PDOException $e) {
             if ($this->enableTransactions) {
                 $this->pdo->rollBack();
             }
             throw $e;
         }
     }
     $sectionIDs = $article->sectionIDs;
     if ($sectionIDs === NULL) {
         try {
             $samaps = $osamaps->delete(NULL, $article->ID);
         } catch (PDOException $e) {
             if ($this->enableTransactions) {
                 $this->pdo->rollBack();
             }
             throw $e;
         }
     } elseif (sizeof($sectionIDs)) {
         $queryOptions = new OnpubQueryOptions();
         $queryOptions->orderBy = "ID";
         $queryOptions->order = "ASC";
         try {
             $samaps = $osamaps->select($queryOptions, NULL, $article->ID);
         } catch (PDOException $e) {
             if ($this->enableTransactions) {
                 $this->pdo->rollBack();
             }
             throw $e;
         }
         // Unmap sections not included in $sectionIDs.
         foreach ($samaps as $samap) {
             if (!in_array($samap->sectionID, $sectionIDs)) {
                 try {
                     $osamaps->delete($samap->sectionID, $article->ID);
                 } catch (PDOException $e) {
                     if ($this->enableTransactions) {
                         $this->pdo->rollBack();
                     }
                     throw $e;
                 }
             }
         }
         foreach ($sectionIDs as $sectionID) {
             $samap = new OnpubSAMap();
             $samap->sectionID = $sectionID;
             $samap->articleID = $article->ID;
             $samap->setCreated($article->getCreated());
             $samap->setModified($article->getModified());
             try {
                 $samapID = $osamaps->getID($samap);
             } catch (PDOException $e) {
                 if ($this->enableTransactions) {
                     $this->pdo->rollBack();
                 }
                 throw $e;
             }
             if ($samapID) {
                 $samap->ID = $samapID;
                 try {
                     $osamaps->update($samap);
                 } catch (PDOException $e) {
                     if ($this->enableTransactions) {
                         $this->pdo->rollBack();
                     }
                     throw $e;
                 }
             } else {
                 try {
                     $osamaps->insert($samap);
                 } catch (PDOException $e) {
                     if ($this->enableTransactions) {
                         $this->pdo->rollBack();
                     }
                     throw $e;
                 }
             }
         }
     }
     if ($this->enableTransactions) {
         $status = $this->pdo->commit();
         OnpubDatabase::verifyTransaction($this->pdo, $status);
     }
     return $stmt->rowCount();
 }
Example #4
0
 /**
  * Check the status of the Onpub schema.
  *
  * @return mixed The version of the schema in the database as an int. An array
  * of PDOException objects will be returned if the schema is incomplete or
  * not installed.
  */
 public function status()
 {
     $oaamaps = new OnpubAAMaps($this->pdo);
     $oarticles = new OnpubArticles($this->pdo);
     $oauthors = new OnpubAuthors($this->pdo);
     $oimages = new OnpubImages($this->pdo);
     $osamaps = new OnpubSAMaps($this->pdo);
     $osections = new OnpubSections($this->pdo);
     $owebsites = new OnpubWebsites($this->pdo);
     $owsmaps = new OnpubWSMaps($this->pdo);
     $queryOptions = new OnpubQueryOptions($this->pdo);
     $queryOptions->setPage(1, 1);
     $exceptions = array();
     $version = 0;
     try {
         $oaamaps->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     try {
         $oarticles->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     try {
         $oauthors->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     try {
         $oimages->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     try {
         $osamaps->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     try {
         $osections->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     try {
         $owebsites->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     try {
         $owsmaps->select($queryOptions);
     } catch (PDOException $e) {
         $exceptions[] = $e;
     }
     if (sizeof($exceptions)) {
         return $exceptions;
     }
     $version = 1;
     return $version;
 }
Example #5
0
 public function display()
 {
     $oarticles = new OnpubArticles($this->pdo);
     $owebsites = new OnpubWebsites($this->pdo);
     $osamaps = new OnpubSAMaps($this->pdo);
     $osections = new OnpubSections($this->pdo);
     $oimages = new OnpubImages($this->pdo);
     try {
         $queryOptions = new OnpubQueryOptions();
         $queryOptions->includeAuthors = TRUE;
         $this->oarticle = $oarticles->get($this->oarticle->ID, $queryOptions);
         $queryOptions = new OnpubQueryOptions();
         $queryOptions->orderBy = "fileName";
         $queryOptions->order = "ASC";
         $images = $oimages->select($queryOptions);
         $queryOptions = new OnpubQueryOptions();
         $queryOptions->orderBy = "name";
         $queryOptions->order = "ASC";
         $websites = $owebsites->select($queryOptions);
         $queryOptions = new OnpubQueryOptions();
         $samaps = $osamaps->select($queryOptions, NULL, $this->oarticle->ID);
     } catch (PDOException $e) {
         throw $e;
     }
     $author = $this->oarticle->authors;
     if (sizeof($author)) {
         $author = $author[0];
     } else {
         $author = new OnpubAuthor();
     }
     $widget = new OnpubWidgetHeader("Article " . $this->oarticle->ID . " - " . $this->oarticle->title, ONPUBAPI_SCHEMA_VERSION, $this->pdo);
     $widget->display();
     en('<form id="onpub-form" action="index.php" method="post">');
     en('<div>');
     en('<p><textarea rows="25" name="content" style="width: 100%;">' . htmlentities($this->oarticle->content) . '</textarea></p>');
     ?>
 <script type="text/javascript">
   if (CKEDITOR) {
     CKEDITOR.replace('content', {
       'height': 350,
       'uiColor': '#eff0f0',
       'resize_dir': 'vertical',
       'dataIndentationChars': '  ',
       'allowedContent': true,
       <?php 
     if (file_exists(ONPUBGUI_YUI_DIRECTORY)) {
         en("'contentsCss': [onpub_dir_yui + 'cssnormalize/cssnormalize-min.css', onpub_dir_yui + 'cssfonts/cssfonts-min.css', onpub_dir_yui + 'cssgrids/cssgrids-min.css', '" . ONPUBGUI_CKEDITOR_DIRECTORY . "contents.css', 'css/ckeditor.css']");
     } else {
         en("'contentsCss': ['http://yui.yahooapis.com/" . ONPUBGUI_YUI_VERSION . "/build/cssnormalize/cssnormalize-min.css', 'http://yui.yahooapis.com/" . ONPUBGUI_YUI_VERSION . "/build/cssfonts/cssfonts-min.css', 'http://yui.yahooapis.com/" . ONPUBGUI_YUI_VERSION . "/build/cssgrids/cssgrids-min.css', '" . ONPUBGUI_CKEDITOR_DIRECTORY . "contents.css', 'css/ckeditor.css']");
     }
     ?>
     });
   }
 </script>
 <?php 
     en('<div class="yui3-g">');
     en('<div class="yui3-u-1-2">');
     en('<h3 class="onpub-field-header">Title</h3><p><input type="text" maxlength="255" size="40" name="title" value="' . htmlentities($this->oarticle->title) . '"></p>');
     en('</div>');
     en('<div class="yui3-u-1-2">');
     en('<h3 class="onpub-field-header">Author</h3><p><input type="text" maxlength="255" size="40" name="displayAs" value="' . htmlentities($author->displayAs) . '"></p>');
     en('</div>');
     en('</div>');
     en('<div class="yui3-g">');
     en('<div class="yui3-u-1-2">');
     $widget = new OnpubWidgetSections();
     $widget->websites = $websites;
     $widget->osections = $osections;
     $widget->samaps = $samaps;
     $widget->display();
     en('</div>');
     en('<div class="yui3-u-1-2">');
     $widget = new OnpubWidgetImages("Image", $this->oarticle->imageID, $images);
     $widget->display();
     en('</div>');
     en('</div>');
     if ($this->oarticle->url) {
         $go = ' <a href="' . $this->oarticle->url . '" target="_blank"><img src="' . ONPUBGUI_IMAGE_DIRECTORY . 'world_go.png" border="0" align="top" alt="Go" title="Go" width="16" height="16"></a>';
     } else {
         $go = '';
     }
     en('<div class="yui3-g">');
     en('<div class="yui3-u-1-2">');
     en('<h3 class="onpub-field-header">Static Link</h3><p><small>The Frontend will link this article to the path or URL entered below.<br>Leave blank to use auto-generated Frontend URLs.</small><br><input type="text" maxlength="255" size="40" name="url" value="' . htmlentities($this->oarticle->url) . '">' . $go . '</p>');
     en('</div>');
     en('<div class="yui3-u-1-2">');
     if (sizeof($samaps)) {
         $websitesMap = array();
         foreach ($websites as $website) {
             $websitesMap["{$website->ID}"] = $website;
         }
         $sections = array();
         $articleIDs = array();
         foreach ($samaps as $samap) {
             $section = $osections->get($samap->sectionID);
             if ($section && isset($websitesMap["{$section->websiteID}"])) {
                 $website = $websitesMap["{$section->websiteID}"];
                 if ($website->url) {
                     $sections[] = $section;
                     $articleIDs[] = $samap->articleID;
                 }
             }
         }
         if (sizeof($sections)) {
             $urlLabel = sizeof($sections) > 1 ? 'URLs' : 'URL';
             en('<h3 class="onpub-field-header">Frontend ' . $urlLabel . '</h3>');
             en('<p>');
             en('<small>This article is displayed by the Frontend at the ' . $urlLabel . ' listed below.</small><br>');
             for ($i = 0; $i < sizeof($sections); $i++) {
                 $section = $sections[$i];
                 $website = $websitesMap["{$section->websiteID}"];
                 $frontendURL = addTrailingSlash($website->url) . 'index.php?s=' . $section->ID . '&amp;a=' . $articleIDs[$i];
                 en('&bull; <a href="' . $frontendURL . '" target="_blank">' . $frontendURL . '</a>');
                 if ($i + 1 != sizeof($sections)) {
                     en('<br>');
                 }
             }
             en('</p>');
         }
     }
     en('</div>');
     en('</div>');
     $widget = new OnpubWidgetDateCreated($this->oarticle->getCreated());
     $widget->display();
     $modified = $this->oarticle->getModified();
     en('<h3 class="onpub-field-header">Modified</h3><p>' . $modified->format('M j, Y g:i:s A') . '</p>');
     en('<input type="submit" value="Save"> <input type="button" value="Delete" id="deleteArticle">');
     en('<input type="hidden" name="articleID" id="articleID" value="' . $this->oarticle->ID . '">');
     en('<input type="hidden" name="authorID" value="' . $author->ID . '">');
     en('<input type="hidden" name="authorImageID" value="' . $author->imageID . '">');
     en('<input type="hidden" name="lastDisplayAs" value="' . htmlentities($author->displayAs) . '">');
     en('<input type="hidden" name="onpub" value="EditArticleProcess">');
     en('</div>');
     en('</form>');
     $widget = new OnpubWidgetFooter();
     $widget->display();
 }