/** * Commit changes to a story * @since Version 3.4 * @return boolean */ public function commit() { $this->validate(); if (function_exists("prepare_submit")) { // Format the article blurb try { if (!empty($this->blurb)) { $this->blurb = prepare_submit($this->blurb); } if (!empty($this->lead)) { $this->lead = prepare_submit($this->lead); } } catch (Exception $e) { Debug::SaveError($e); } // Format the article body try { if (!empty($this->body)) { $this->body = prepare_submit($this->body); } if (!empty($this->paragraphs)) { $this->paragraphs = prepare_submit($this->paragraphs); } } catch (Exception $e) { Debug::SaveError($e); } } if ($this->Topic instanceof \Railpage\Forums\Thread) { $this->topic_id = $this->Topic->id; } $dataArray = array(); if (filter_var($this->id, FILTER_VALIDATE_INT)) { $this->Memcached->delete($this->mckey); $this->Memcached->delete(sprintf("json:railpage.news.article=%d", $this->id)); $this->Redis->delete(sprintf("railpage:news.article=%s", $this->id)); $this->Redis->delete(sprintf("railpage:news.article=%s", $this->slug)); $this->Memcached->delete(sprintf(self::CACHE_KEY_FORMAT_LEAD, $this->id)); $this->Memcached->delete(sprintf(self::CACHE_KEY_FORMAT_PARAGRAPHS, $this->id)); } $dataArray['approved'] = $this->approved; $dataArray['title'] = $this->title; $dataArray['hometext'] = is_object($this->blurb) ? $this->blurb->__toString() : $this->blurb; $dataArray['bodytext'] = is_object($this->body) ? $this->body->__toString() : $this->body; $dataArray['lead'] = $this->lead; $dataArray['paragraphs'] = $this->paragraphs; $dataArray['ForumThreadID'] = $this->topic_id; $dataArray['source'] = $this->source; $dataArray['user_id'] = $this->Author instanceof User ? $this->Author->id : $this->user_id; $dataArray['staff_id'] = empty($this->staff_user_id) ? 0 : $this->staff_user_id; $dataArray['geo_lat'] = empty($this->lat) ? 0 : $this->lat; $dataArray['geo_lon'] = empty($this->lon) ? 0 : $this->lon; $dataArray['sent_to_fb'] = (bool) $this->sent_to_fb; $dataArray['time'] = $this->date->format("Y-m-d H:i:s"); $dataArray['slug'] = empty($this->slug) ? $this->createSlug() : $this->slug; $dataArray['topic'] = $this->Topic->id; $dataArray['unique_id'] = $this->unique_id; $dataArray['queued'] = $this->queued; if ($this->featured_image !== false) { $dataArray['featured_image'] = $this->featured_image; } if (!empty($this->username) || $this->Author instanceof User) { $dataArray['informant'] = $this->Author instanceof User ? $this->Author->username : $this->username; } foreach ($dataArray as $key => $val) { $dataArray[$key] = trim($val); } /** * Save changes */ if (!empty($this->id) && $this->id > 0) { $where = array("sid = ?" => $this->id); $this->db->update("nuke_stories", $dataArray, $where); } else { $this->db->insert("nuke_stories", $dataArray); $this->id = $this->db->lastInsertId(); } /** * Update Memcached */ $this->makeJSON(); /** * Update our URLs */ $this->makeURLs(); return true; }