$blog->title = $title; $blog->description = $description; $blog->excerpt = elgg_get_excerpt($excerpt); // mark this as a brand new post so we can work out the // river / revision logic in the real save action. $blog->new_post = TRUE; if (!$blog->save()) { $error = elgg_echo('blog:error:cannot_save'); } } // creat draft annotation if (!$error) { // annotations don't have a "time_updated" so // we have to delete everything or the times are wrong. // don't save if nothing changed $auto_save_annotations = $blog->getAnnotations(array('annotation_name' => 'blog_auto_save', 'limit' => 1)); if ($auto_save_annotations) { $auto_save = $auto_save_annotations[0]; } else { $auto_save = FALSE; } if (!$auto_save) { $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value != $description) { $blog->deleteAnnotations('blog_auto_save'); $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value == $description) { // this isn't an error because we have an up to date annotation. $annotation_id = $auto_save->id; } if (!$annotation_id) {
/** * Pull together blog variables for the save form * * @param ElggBlog $post * @param ElggAnnotation $revision * @return array */ function blog_prepare_form_vars($post = NULL, $revision = NULL) { // input names => defaults $values = array('title' => NULL, 'description' => NULL, 'status' => 'published', 'access_id' => ACCESS_DEFAULT, 'comments_on' => 'On', 'excerpt' => NULL, 'tags' => NULL, 'container_guid' => NULL, 'guid' => NULL, 'draft_warning' => ''); if ($post) { foreach (array_keys($values) as $field) { if (isset($post->{$field})) { $values[$field] = $post->{$field}; } } } if (elgg_is_sticky_form('blog')) { $sticky_values = elgg_get_sticky_values('blog'); foreach ($sticky_values as $key => $value) { $values[$key] = $value; } } elgg_clear_sticky_form('blog'); if (!$post) { return $values; } // load the revision annotation if requested if ($revision instanceof ElggAnnotation && $revision->entity_guid == $post->getGUID()) { $values['revision'] = $revision; $values['description'] = $revision->value; } // display a notice if there's an autosaved annotation // and we're not editing it. if ($auto_save_annotations = $post->getAnnotations('blog_auto_save', 1)) { $auto_save = $auto_save_annotations[0]; } else { $auto_save == FALSE; } if ($auto_save && $auto_save->id != $revision->id) { $values['draft_warning'] = elgg_echo('blog:messages:warning:draft'); } return $values; }
$blog->title = $title; $blog->description = $description; $blog->excerpt = elgg_get_excerpt($excerpt); // mark this as a brand new post so we can work out the // river / revision logic in the real save action. $blog->new_post = TRUE; if (!$blog->save()) { $error = elgg_echo('blog:error:cannot_save'); } } // creat draft annotation if (!$error) { // annotations don't have a "time_updated" so // we have to delete everything or the times are wrong. // don't save if nothing changed if ($auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1)) { $auto_save = $auto_save_annotations[0]; } else { $auto_save == FALSE; } if (!$auto_save) { $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value != $description) { $blog->clearAnnotations('blog_auto_save'); $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value == $description) { // this isn't an error because we have an up to date annotation. $annotation_id = $auto_save->id; } if (!$annotation_id) { $error = elgg_echo('blog:error:cannot_auto_save');