/** * @param int $ID ID of the image to delete. * @return int 1 if the image was deleted, 0 if the image does not exist in the database. */ public function delete($ID) { $stmt = $this->pdo->prepare("DELETE FROM OnpubImages WHERE ID = :ID"); OnpubDatabase::verifyPrepare($this->pdo, $stmt, FALSE); $stmt->bindParam(':ID', $ID); $result = $stmt->execute(); OnpubDatabase::verifyExecute($this->pdo, $result, FALSE, $stmt->errorInfo()); return $stmt->rowCount(); }
/** * @param OnpubSAMap $samap The map to be updated. * @return int 1 if the map was updated. 0 if the map does not exist in the database. */ public function update(OnpubSAMap $samap) { $stmt = $this->pdo->prepare("UPDATE OnpubSAMaps SET sectionID = :sectionID, articleID = :articleID, created = :created, modified = :modified WHERE ID = :ID"); OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions); $ID = $samap->ID; $sectionID = $samap->sectionID; $articleID = $samap->articleID; $created = $samap->getCreated()->format('Y-m-d H:i:s'); $modified = $samap->getModified()->format('Y-m-d H:i:s'); $stmt->bindParam(':ID', $ID); $stmt->bindParam(':sectionID', $sectionID); $stmt->bindParam(':articleID', $articleID); $stmt->bindParam(':created', $created); $stmt->bindParam(':modified', $modified); $result = $stmt->execute(); OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo()); return $stmt->rowCount(); }
/** * @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(); }
/** * 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(); }
public function display() { if ($this->pdo) { $odatabase = new OnpubDatabase($this->pdo); $oarticles = new OnpubArticles($this->pdo); $oauthors = new OnpubAuthors($this->pdo); $oimages = new OnpubImages($this->pdo); $osections = new OnpubSections($this->pdo); $owebsites = new OnpubWebsites($this->pdo); $status = $odatabase->status(); $driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME); $widget = new OnpubWidgetHeader("Dashboard", $status, $this->pdo); } else { $status = null; $widget = new OnpubWidgetHeader("Dashboard", $status, $this->pdo); } $widget->display(); en('<div class="yui3-g">'); if ($status == ONPUBAPI_SCHEMA_VERSION) { // Onpub schema is installed. $numsites = $owebsites->count(); $numarticles = $oarticles->count(); en('<div class="yui3-u-1-2">'); en('<div style="padding-right: 1em;">'); if ($numsites == 0) { en('<h3 style="margin-top: 0;">You are ready to start publishing content with Onpub.</h3>'); en('<p><b><a href="index.php?onpub=NewWebsite">Create a website</a></b> to get started.</p>'); } else { if ($numarticles) { en('<form id="onpub-form" action="index.php" method="get">'); en('<div>'); en('<input type="hidden" name="onpub" value="EditArticles">'); en('<input type="hidden" name="fullTextSearch" value="1">'); en('<p style="margin-top: 0;"><input type="text" name="keywords" style="width: 18.5em;"> <input type="submit" value="Search Articles"></p>'); //en(' For what: <select name="onpub"><option value="EditArticles">Articles</option><option value="EditSections">Sections</option><option value="EditWebsites">Websites</option></select>'); en('</div>'); en('</form>'); } $queryOptions = new OnpubQueryOptions(); $queryOptions->rowLimit = 10; $queryOptions->orderBy = "created"; $queryOptions->order = "DESC"; $articles = $oarticles->select($queryOptions); if (sizeof($articles)) { en('<table style="width: 100%;" colspan="2">'); en('<tr><th style="text-align: left; width: 75%;">Recent Articles</th><th>Created</th></tr>'); foreach ($articles as $article) { en('<tr><td><a href="index.php?onpub=EditArticle&articleID=' . $article->ID . '" title="Edit">' . $article->title . '</a></td><td>' . $article->getCreated()->format("M j, Y") . '</td></tr>'); } en('</table>'); } } en('<div class="yui3-g">'); en('<div class="yui3-u-1-2">'); en('<h3 style="margin-top: 0;">Quick Links</h3>'); en('<ul>'); en('<li><a href="index.php?onpub=NewArticle">New Article</a></li>'); en('<li><a href="index.php?onpub=NewSection">New Section</a></li>'); en('<li><a href="index.php?onpub=UploadImages">Upload Images</a></li>'); en('</ul>'); en('</div>'); en('<div class="yui3-u-1-2">'); en('<table style="float: right;">'); en('<tr><th colspan="2">Content Stats</th></tr>'); en('<tr><td><a href="index.php?onpub=EditArticles">Articles</a>:</td><td>' . $numarticles . '</td></tr>'); //en('<tr><td>Authors:</td><td>' . $oauthors->count() . '</td></tr>'); en('<tr><td><a href="index.php?onpub=EditImages">Images</a>:</td><td>' . $oimages->count() . '</td></tr>'); en('<tr><td><a href="index.php?onpub=EditSections">Sections</a>:</td><td>' . $osections->count() . '</td></tr>'); en('<tr><td><a href="index.php?onpub=EditWebsites">Websites</a>:</td><td>' . $numsites . '</td></tr>'); en('</table>'); en('</div>'); en('</div>'); en('</div>'); en('</div>'); en('<div class="yui3-u-1-2">'); } elseif ($this->pdo === NULL) { en('<div class="yui3-u-1-2">'); en('<h3><span class="onpub-error">PDOException:</span> ' . $this->pdoException->getMessage() . '</h3>'); switch ($this->pdoException->getCode()) { case 1044: // Bad database name. en('<p>Onpub is unable to connect to the specified MySQL database.</p>'); break; case 1045: // Bad credentials. en('<p>Onpub is unable to connect to the specified MySQL database using the logged-in user\'s username and/or password.</p>'); en('<p>Try logging out and log back in with the correct MySQL credentials.</p>'); break; case 2002: // Server is down en('<p>Onpub is unable to connect to the database server.</p>'); en('<p>Start the specified MySQL server and reload this page to try again.</p>'); break; case 2003: // Server is inaccessible (firewall, wrong port, etc.) en('<p>Onpub is unable to access the specified MySQL database server.</p>'); break; case 2005: // Bad host name en('<p>Onpub is unable to connect to the specified MySQL database server host.</p>'); break; } if ($this->pdoException->getMessage() == 'could not find driver') { en('<p>Either PDO_MYSQL is not installed or it is not configured correctly.</p>'); en('<p>Onpub requires the PDO and PDO_MYSQL PHP extensions in order to connect to a MySQL database server.</p>'); en('<p>You will be unable to use Onpub until PDO_MYSQL is installed.</p>'); en('<p>Please refer to the <a href="http://onpub.com/index.php?s=8&a=11" target="_blank">Onpub System Requirements</a> and the <a href="http://www.php.net/manual/en/ref.pdo-mysql.php" target="_blank">PHP Manual</a> for more information.</p>'); } en('</div>'); en('<div class="yui3-u-1-2">'); } else { // Onpub schema is not installed yet. Prompt user to install. en('<div class="yui3-u-1-2">'); en('<h2 style="margin-top: 0;">Welcome to Onpub</h2>'); if ($odatabase->current()) { en('<p>This appears to be the first time you have connected to this MySQL database with Onpub.</p>'); en('<p>Before you can publish a website with Onpub, you must add the Onpub schema to the connected database: <em>' . $_SESSION['PDO_DATABASE'] . '</em>.</p>'); en('<p>Please click the link below to continue:</p>'); en('<ul><li><b><a href="index.php?onpub=SchemaInstall">Install the Onpub MySQL database schema</a></b></li></ul>'); } else { $dbs = $odatabase->listDBs(); if (sizeof($dbs)) { en('<p>Please select the MySQL Database that you would like to work with and click Connect.</p>'); en('<form id="onpub-form" action="index.php" method="post">'); en('<div>'); en('<p>'); en('<select name="pdoDatabase">'); foreach ($dbs as $db) { en('<option value="' . $db . '">' . $db . '</option>'); } en('</select>'); en('</p>'); en('<p><input type="submit" value="Connect"></p>'); en('<input type="hidden" name="onpub" value="LoginProcess">'); en('</div>'); en('</form>'); } else { // User has no database permissions. en('<p>Your MySQL User <em>' . $_SESSION['PDO_USER'] . '</em> does not have the permissions to access any databases on this host.</p>'); en('<p><a href="http://onpub.com/index.php?s=8&a=118#setup" target="_blank">Click here for instructions</a> on how to setup a MySQL User and Database for use with Onpub.'); } } en('</div>'); en('<div class="yui3-u-1-2">'); } if ($this->pdo) { en('<table>'); en('<tr><th colspan="2">Database Connection</th></tr>'); en('<tr style="vertical-align: top;"><td>MySQL Host:</td><td>' . $this->pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS) . '</td></tr>'); en('<tr style="vertical-align: top;"><td>MySQL Client:</td><td>' . $this->pdo->getAttribute(PDO::ATTR_CLIENT_VERSION) . '</td></tr>'); en('<tr style="vertical-align: top;"><td>MySQL Server:</td><td>' . $this->pdo->getAttribute(PDO::ATTR_SERVER_VERSION) . '</td></tr>'); en('<tr style="vertical-align: top;"><td>MySQL User:</td><td>' . $_SESSION['PDO_USER'] . '</td></tr>'); if ($_SESSION['PDO_DATABASE']) { en('<tr style="vertical-align: top;"><td>Connected Database:</td><td>' . $_SESSION['PDO_DATABASE'] . ' (<a href="index.php?onpub=Disconnect">Disconnect</a>)</td></tr>'); } if ($status == ONPUBAPI_SCHEMA_VERSION) { en('<tr style="vertical-align: top;"><td>Onpub Schema:</td><td>Rev. ' . ONPUBAPI_SCHEMA_VERSION . '</td></tr>'); } en('</table>'); en('<table>'); en('<tr><th colspan="2">PHP Configuration</th></tr>'); if (function_exists("gd_info")) { $gdinfo = gd_info(); en('<tr style="vertical-align: top;"><td><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a>:</td><td>Installed: ' . $gdinfo['GD Version'] . '</td></tr>'); } else { en('<tr style="vertical-align: top;"><td><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a>:</td><td><span class="onpub-error">Not installed.</span> <a href="http://php.net/manual/en/image.setup.php" target="_blank">Installing GD</a> is required.</td></tr>'); } if (get_magic_quotes_gpc()) { en('<tr style="vertical-align: top;"><td><a href="http://php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc" target="_blank">Magic Quotes</a>:</td><td><span class="onpub-error">On</span>: <a href="http://php.net/manual/en/security.magicquotes.disabling.php" target="_blank">Disabling Magic Quotes</a> is required.</td></tr>'); } else { en('<tr style="vertical-align: top;"><td><a href="http://php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc" target="_blank">Magic Quotes</a>:</td><td>Off</td></tr>'); } if (ini_get("allow_url_fopen")) { en('<tr style="vertical-align: top;"><td><a href="http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen" target="_blank">Allow URL File Open</a>:</td><td>Yes</td></tr>'); } else { en('<tr style="vertical-align: top;"><td><a href="http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen" target="_blank">Allow URL File Open</a>:</td><td><span class="onpub-error">No</span>: <a href="http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen" target="_blank">Enabling URL File Open</a> is required.</td></tr>'); } if (ini_get("file_uploads")) { en('<tr style="vertical-align: top;"><td><a href="http://php.net/ini.core#ini.file-uploads" target="_blank">Allow File Uploads</a>:</td><td>Yes</td></tr>'); } else { en('<tr style="vertical-align: top;"><td><a href="http://php.net/ini.core#ini.file-uploads" target="_blank">Allow File Uploads</a>:</td><td>No</td></tr>'); } if (ini_get("upload_max_filesize")) { en('<tr style="vertical-align: top;"><td><a href="http://php.net/ini.core#ini.upload-max-filesize" target="_blank">Upload Maximum File Size</a>:</td><td>' . ini_get("upload_max_filesize") . '</td></tr>'); } else { en('<tr style="vertical-align: top;"><td><a href="http://php.net/ini.core#ini.upload-max-filesize" target="_blank">Upload Maximum File Size</a>:</td><td>undefined</td></tr>'); } if (ini_get("date.timezone")) { en('<tr style="vertical-align: top;"><td><a href="http://php.net/ref.datetime" target="_blank">Timezone</a>:</td><td>' . ini_get("date.timezone") . '</td></tr>'); } else { en('<tr style="vertical-align: top;"><td><a href="http://php.net/ref.datetime" target="_blank">Timezone</a>:</td><td>' . ONPUBGUI_DEFAULT_TZ . '</td></tr>'); } en('</table>'); } en('</div>'); en('</div>'); $widget = new OnpubWidgetFooter(); $widget->display(); }
/** * Gets a list of MySQL databases that the logged-in user has access to. * System database names are excluded from the list. * * @return array Array will be empty if user has no database access. * Otherwise array will contain the names of the MySQL databases she has * access to. */ public function listDBs() { $result = $this->pdo->query('SHOW DATABASES'); OnpubDatabase::verifyQuery($this->pdo, $result, FALSE); $rows = $result->fetchAll(PDO::FETCH_ASSOC); $excludes = array('mysql', 'performance_schema', 'information_schema'); $dbs = array(); if ($rows) { foreach ($rows as $row) { if (!in_array($row['Database'], $excludes)) { $dbs[] = $row['Database']; } } } $result->closeCursor(); return $dbs; }
/** * @param mixed $aamaps A single {@link OnpubAAMap} object or an array of {@link OnpubAAMap} objects (to insert multiple maps at a time). * @return mixed The ID(s) of the new map(s). An int will be returned if a single map was inserted. An array of ints will be returned if multiple maps were inserted. * @throws PDOException if there's a database error. */ public function insert($aamaps) { $aamapIDs = array(); $isArray = TRUE; if (!is_array($aamaps)) { $aamaps = array($aamaps); $isArray = FALSE; } if ($this->enableTransactions) { $status = $this->pdo->beginTransaction(); OnpubDatabase::verifyTransaction($this->pdo, $status); } $stmt = $this->pdo->prepare("INSERT INTO OnpubAAMaps (ID, articleID, authorID, created, modified) VALUES (:ID, :articleID, :authorID, :created, :modified)"); OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions); foreach ($aamaps as $aamap) { try { $aamapID = $this->getID($aamap); } catch (PDOException $e) { if ($this->enableTransactions) { $this->pdo->rollBack(); } throw $e; } if ($aamapID) { $aamapIDs[] = $aamapID; $aamap->ID = $aamapID; } else { $ID = $aamap->ID; $articleID = $aamap->articleID; $authorID = $aamap->authorID; $created = $aamap->getCreated()->format('Y-m-d H:i:s'); $modified = $aamap->getModified()->format('Y-m-d H:i:s'); $stmt->bindParam(':ID', $ID); $stmt->bindParam(':articleID', $articleID); $stmt->bindParam(':authorID', $authorID); $stmt->bindParam(':created', $created); $stmt->bindParam(':modified', $modified); $result = $stmt->execute(); OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo()); $aamapIDs[] = $this->pdo->lastInsertId(); $aamap->ID = $this->pdo->lastInsertId(); } } if ($this->enableTransactions) { $status = $this->pdo->commit(); OnpubDatabase::verifyTransaction($this->pdo, $status); } if ($isArray) { return $aamapIDs; } else { return end($aamapIDs); } }
/** * @param OnpubAuthor $author The author to be updated. * @return int 1 if the author was updated. 0 if the author does not exist in the database. */ public function update(OnpubAuthor $author) { $now = new DateTime(); if ($this->enableTransactions) { $status = $this->pdo->beginTransaction(); OnpubDatabase::verifyTransaction($this->pdo, $status); } $stmt = $this->pdo->prepare("UPDATE OnpubAuthors SET imageID = :imageID, givenNames = :givenNames, familyName = :familyName, displayAs = :displayAs, url = :url, modified = :modified WHERE ID = :ID"); OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions); $ID = $author->ID; $imageID = $author->imageID; $givenNames = OnpubDatabase::utf8Decode(trim($author->givenNames)); $familyName = OnpubDatabase::utf8Decode(trim($author->familyName)); $displayAs = OnpubDatabase::utf8Decode(trim($author->displayAs)); $url = OnpubDatabase::utf8Decode(trim($author->url)); $modified = $now->format('Y-m-d H:i:s'); $stmt->bindParam(':ID', $ID); $stmt->bindParam(':imageID', $imageID); $stmt->bindParam(':givenNames', $givenNames); $stmt->bindParam(':familyName', $familyName); $stmt->bindParam(':displayAs', $displayAs); $stmt->bindParam(':url', $url); $stmt->bindParam(':modified', $modified); $result = $stmt->execute(); OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo()); if ($this->enableTransactions) { $status = $this->pdo->commit(); OnpubDatabase::verifyTransaction($this->pdo, $status); } return $stmt->rowCount(); }
/** * @param OnpubWebsite $website The website to be updated. * @return int 1 if the website was updated. 0 if the website does not exist in the database. */ public function update(OnpubWebsite $website) { $owsmaps = new OnpubWSMaps($this->pdo, FALSE); $now = new DateTime(); if ($this->enableTransactions) { $status = $this->pdo->beginTransaction(); OnpubDatabase::verifyTransaction($this->pdo, $status); } $stmt = $this->pdo->prepare("UPDATE OnpubWebsites SET imageID = :imageID, name = :name, url = :url, imagesURL = :imagesURL, imagesDirectory = :imagesDirectory, modified = :modified WHERE ID = :ID"); OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions); $ID = $website->ID; $imageID = $website->imageID; $name = OnpubDatabase::utf8Decode(trim($website->name)); $url = OnpubDatabase::utf8Decode(trim($website->url)); $imagesURL = OnpubDatabase::utf8Decode(trim($website->imagesURL)); $imagesDirectory = OnpubDatabase::utf8Decode(trim($website->imagesDirectory)); $modified = $now->format('Y-m-d H:i:s'); $stmt->bindParam(':ID', $ID); $stmt->bindParam(':imageID', $imageID); $stmt->bindParam(':name', $name); $stmt->bindParam(':url', $url); $stmt->bindParam(':imagesURL', $imagesURL); $stmt->bindParam(':imagesDirectory', $imagesDirectory); $stmt->bindParam(':modified', $modified); $result = $stmt->execute(); OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo()); try { $owsmaps->delete($website->ID, NULL); } catch (PDOException $e) { if ($this->enableTransactions) { $this->pdo->rollBack(); } throw $e; } $sections = $website->sections; $wsmaps = array(); foreach ($sections as $section) { $wsmap = new OnpubWSMap(); $wsmap->websiteID = $section->websiteID; $wsmap->sectionID = $section->ID; $wsmaps[] = $wsmap; } try { $owsmaps->insert($wsmaps); } 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(); }
return; } switch ($_GET['onpub']) { case "Logout": $login = new OnpubLogin("", "", "", "", TRUE); $login->process(); header("Location: index.php"); return; break; case "Disconnect": $_SESSION['PDO_DATABASE'] = ''; header("Location: index.php"); return; break; case "SchemaInstall": $odatabase = new OnpubDatabase($pdo); $owebsites = new OnpubWebsites($pdo); $osections = new OnpubSections($pdo); $oarticles = new OnpubArticles($pdo); try { $odatabase->install(); } catch (PDOException $e) { $widget = new OnpubWidgetPDOException($e); $widget->display(); $pdo = NULL; exit($e->getCode()); } $pdo = NULL; header("Location: index.php"); return; break;