Example #1
0
 public static function updatePost($id, $data)
 {
     if (!blog::postExist("contentID", $id)) {
         system::registerEvent("error", "title", "Новости, которую вы редактируете не существует.", "URL");
     }
     if (!self::checkPostErrors($data)) {
         return false;
     }
     if (isset($data["savePost"])) {
         unset($data["savePost"]);
     }
     if (isset($data["picWidth"])) {
         unset($data["picWidth"]);
     }
     if (isset($data["picHeigth"])) {
         unset($data["picHeigth"]);
     }
     self::handleCats($data["categories"], $id);
     if (!isset($data["showOnSite"])) {
         $data["showOnSite"] = 'N';
         self::$smarty->clearAllCache();
     }
     if (empty($data["short"])) {
         $data["short"] = preg_split("/(?:&lt;|<)!--\\s*more\\s*--(?:&gt;|>)+/i", $data["body"]);
         if (is_array($data["short"])) {
             $data["short"] = array_shift($data["short"]);
         }
     } else {
         $data["short"] = nl2br($data["short"]);
     }
     if (isset($data["catName"])) {
         unset($data["catName"]);
     }
     if (isset($data["catSlug"])) {
         unset($data["catSlug"]);
     }
     if (!empty($data["slug"])) {
         $data["slug"] = core::generateSlug($data["slug"]);
     } else {
         if (!empty($data["title"])) {
             $data["slug"] = core::generateSlug($data["title"]);
         }
     }
     //self::$db->updateTable ("content", $data, "contentID", $id);
     $date = date("d-m-Y", strtotime($data["dt"]));
     self::$smarty->clearCache(null, "{$date}_newsdate|{$data["slug"]}");
     self::clearCommonCache();
     if ($data["poster"]) {
         return self::$db->query("UPDATE `content` SET `dt`=STR_TO_DATE ('?', '%d-%m-%Y'), `title`='?', slug='?', `body`='?', `short`='?',\n\t\t\t\t`showOnSite`='?', `editedByID`=?, `editedByNick`='?', `editedOn`=NOW(), `poster`='?' WHERE `contentID`=?", $data["dt"], $data["title"], $data["slug"], $data["body"], $data["short"], $data["showOnSite"], $_SESSION["user"]["userID"], $_SESSION["user"]["nick"], $data["poster"], $id);
     } else {
         return self::$db->query("UPDATE `content` SET `dt`=STR_TO_DATE ('?', '%d-%m-%Y'), `title`='?', slug='?', `body`='?', `short`='?',\n\t\t\t\t`showOnSite`='?', `editedByID`=?, `editedByNick`='?', `editedOn`=NOW() WHERE `contentID`=?", $data["dt"], $data["title"], $data["slug"], $data["body"], $data["short"], $data["showOnSite"], $_SESSION["user"]["userID"], $_SESSION["user"]["nick"], $id);
     }
 }