Exemplo n.º 1
0
 /**
  * Updates an existing post in the posts table
  * @param bool $minor Indicates if this is a major or minor update
  * @return bool True on success
  */
 public function update($minor = true)
 {
     $this->modified = HabariDateTime::date_create();
     if (!$minor && $this->status != Post::status('draft')) {
         $this->updated = $this->modified;
     }
     if (isset($this->fields['guid'])) {
         unset($this->newfields['guid']);
     }
     if ($this->pubdate->int > HabariDateTime::date_create()->int && $this->status == Post::status('published')) {
         $this->status = Post::status('scheduled');
     }
     $allow = true;
     $allow = Plugins::filter('post_update_allow', $allow, $this);
     if (!$allow) {
         return false;
     }
     Plugins::act('post_update_before', $this);
     $this->newfields = Plugins::filter('post_update_change', $this->newfields, $this, $this->fields);
     // Call setslug() only when post slug is changed
     if (isset($this->newfields['slug'])) {
         if ($this->fields['slug'] != $this->newfields['slug']) {
             $this->setslug();
         }
     }
     // invoke plugins for all fields which have been changed
     // For example, a plugin action "post_update_status" would be
     // triggered if the post has a new status value
     foreach ($this->newfields as $fieldname => $value) {
         Plugins::act('post_update_' . $fieldname, $this, $this->fields[$fieldname], $value);
     }
     // invoke plugins for status changes
     if (isset($this->newfields['status']) && $this->fields['status'] != $this->newfields['status']) {
         Plugins::act('post_status_' . self::status_name($this->newfields['status']), $this, $this->fields['status']);
     }
     $result = parent::updateRecord('posts', array('id' => $this->id), post::get_schema_map());
     //scheduled post
     if ($this->fields['status'] == Post::status('scheduled') || $this->status == Post::status('scheduled')) {
         Posts::update_scheduled_posts_cronjob();
     }
     $this->fields = array_merge($this->fields, $this->newfields);
     $this->newfields = array();
     $this->save_tags();
     $this->info->commit();
     Plugins::act('post_update_after', $this);
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Updates an existing post in the posts table
  * @param bool $minor Indicates if this is a major or minor update
  * @return bool True on success
  */
 public function update($minor = true)
 {
     if ($this->id == 0) {
         return $this->insert() !== false;
     }
     $this->modified = DateTime::create();
     if (!$minor && $this->status != Post::status('draft')) {
         $this->updated = $this->modified;
     }
     if (isset($this->fields['guid'])) {
         unset($this->newfields['guid']);
     }
     // if the date is in the future and we are trying to publish the post, actually schedule it for posting later
     if ($this->pubdate > DateTime::create() && $this->status == Post::status('published')) {
         $this->status = Post::status('scheduled');
     } else {
         if ($this->pubdate <= DateTime::create() && $this->status == Post::status('scheduled')) {
             $this->status = Post::status('published');
         }
     }
     $allow = true;
     $allow = Plugins::filter('post_update_allow', $allow, $this);
     if (!$allow) {
         return false;
     }
     Plugins::act('post_update_before', $this);
     $this->newfields = Plugins::filter('post_update_change', $this->newfields, $this, $this->fields);
     // Call setslug() only when post slug is changed
     if (isset($this->newfields['slug'])) {
         if ($this->fields['slug'] != $this->newfields['slug']) {
             $this->setslug();
         }
     }
     // If content has changed, update cached_content with prerendered content
     if (isset($this->newfields['content']) && $this->fields['content'] != $this->newfields['content']) {
         $this->newfields['cached_content'] = Plugins::filter('post_prerender_content', $this->newfields['content'], $this);
     }
     // invoke plugins for all fields which have been changed
     // For example, a plugin action "post_update_status" would be
     // triggered if the post has a new status value
     $change_date = DateTime::create()->sql;
     foreach ($this->newfields as $fieldname => $value) {
         Plugins::act('post_update_' . $fieldname, $this, $this->fields[$fieldname], $value);
         if ($this->fields[$fieldname] != $value) {
             DB::insert('{revisions}', array('post_id' => $this->fields['id'], 'change_field' => $fieldname, 'old_value' => $this->fields[$fieldname], 'user_id' => User::identify()->id, 'change_date' => $change_date));
         }
     }
     // invoke plugins for status changes
     if (isset($this->newfields['status']) && $this->fields['status'] != $this->newfields['status']) {
         Plugins::act('post_status_' . self::status_name($this->newfields['status']), $this, $this->fields['status']);
     }
     $result = parent::updateRecord('posts', array('id' => $this->id), post::get_schema_map());
     //scheduled post
     if ($this->fields['status'] == Post::status('scheduled') || $this->status == Post::status('scheduled')) {
         Posts::update_scheduled_posts_cronjob();
     }
     $this->fields = array_merge($this->fields, $this->newfields);
     $this->newfields = array();
     $this->save_tags();
     $this->info->commit();
     Plugins::act('post_update_after', $this);
     return $result;
 }