Exemplo n.º 1
0
 public function process()
 {
     $oarticles = new OnpubArticles($this->pdo);
     $queryOptions = new OnpubQueryOptions();
     $queryOptions->includeAuthors = TRUE;
     try {
         for ($i = 0; $i < sizeof($this->articleIDs); $i++) {
             $article = $oarticles->get($this->articleIDs[$i], $queryOptions);
             $article->sectionIDs = $this->sectionIDs;
             $oarticles->update($article);
         }
     } catch (PDOException $e) {
         throw $e;
     }
 }
Exemplo n.º 2
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>');
 }
Exemplo n.º 3
0
 public function display()
 {
     $oarticles = new OnpubArticles($this->pdo);
     $articles = array();
     try {
         if (is_array($this->articleIDs)) {
             $queryOptions = new OnpubQueryOptions();
             $queryOptions->includeContent = false;
             for ($i = 0; $i < sizeof($this->articleIDs); $i++) {
                 $articles[] = $oarticles->get($this->articleIDs[$i], $queryOptions);
             }
         }
     } catch (PDOException $e) {
         throw $e;
     }
     $widget = new OnpubWidgetHeader("Delete Articles", ONPUBAPI_SCHEMA_VERSION, $this->pdo);
     $widget->display();
     en('<form id="onpub-form" action="index.php" method="post">');
     en('<div>');
     if (sizeof($articles)) {
         en('<h3>Selected Articles</h3>');
         en('<ul>');
         for ($i = 0; $i < sizeof($articles); $i++) {
             en('<li><a href="index.php?onpub=EditArticle&amp;articleID=' . $articles[$i]->ID . '" title="Edit">' . $articles[$i]->title . '</a></li>');
             en('<input type="hidden" name="articleIDs[]" value="' . $articles[$i]->ID . '">');
         }
         en('</ul>');
         en('<input type="submit" value="Delete" id="confirmDeleteArticle">');
     } else {
         en('<span class="onpub-error">No articles were selected to delete.</span>');
     }
     en('<input type="hidden" name="onpub" value="DeleteArticleProcess">');
     en('</div>');
     en('</form>');
     $widget = new OnpubWidgetFooter();
     $widget->display();
 }
Exemplo n.º 4
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();
 }
Exemplo n.º 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();
 }