Beispiel #1
0
     } else {
         $error = elgg_echo('blog:error:post_not_found');
     }
 } else {
     $blog = new ElggBlog();
     $blog->subtype = 'blog';
     // force draft and private for autosaves.
     $blog->status = 'unsaved_draft';
     $blog->access_id = ACCESS_PRIVATE;
     $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) {
Beispiel #2
0
if ($values['status'] == 'draft') {
    $values['future_access'] = $values['access_id'];
    $values['access_id'] = ACCESS_PRIVATE;
}
// assign values to the entity, stopping on error.
if (!$error) {
    foreach ($values as $name => $value) {
        if (FALSE === ($blog->{$name} = $value)) {
            $error = elgg_echo('blog:error:cannot_save' . "{$name}={$value}");
            break;
        }
    }
}
// only try to save base entity if no errors
if (!$error) {
    if ($blog->save()) {
        // remove sticky form entries
        elgg_clear_sticky_form('blog');
        // remove autosave draft if exists
        $blog->deleteAnnotations('blog_auto_save');
        // no longer a brand new post.
        $blog->deleteMetadata('new_post');
        // if this was an edit, create a revision annotation
        if (!$new_post && $revision_text) {
            $blog->annotate('blog_revision', $revision_text);
        }
        system_message(elgg_echo('blog:message:saved'));
        $status = $blog->status;
        // add to river if changing status or published, regardless of new post
        // because we remove it for drafts.
        if (($new_post || $old_status == 'draft') && $status == 'published') {
Beispiel #3
0
/**
 * Web service for making a blog post
 *
 * @param string $title the title of blog
 * @param $body
 * @param $comment_status
 * @param string $access Access level of blog
 *
 * @param $status
 * @param $username
 * @param string $tags tags for blog
 * @param string $excerpt the excerpt of blog
 * @return bool
 * @throws InvalidParameterException
 * @internal param $description
 * @internal param $container_guid
 * @internal param string $text the content of blog
 * @internal param string $username username of author
 */
function blog_save_post($title, $body, $comment_status, $access, $status, $username, $tags, $excerpt)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    if ($access == 'ACCESS_FRIENDS') {
        $access_id = -2;
    } elseif ($access == 'ACCESS_PRIVATE') {
        $access_id = 0;
    } elseif ($access == 'ACCESS_LOGGED_IN') {
        $access_id = 1;
    } elseif ($access == 'ACCESS_PUBLIC') {
        $access_id = 2;
    } else {
        $access_id = -2;
    }
    $blog = new ElggBlog();
    $blog->subtype = "blog";
    $blog->owner_guid = $user->guid;
    $blog->container_guid = $user->guid;
    $blog->access_id = $access_id;
    $blog->description = $body;
    $blog->title = elgg_substr(strip_tags($title), 0, 140);
    $blog->status = $status;
    $blog->comments_on = $comment_status;
    $blog->excerpt = strip_tags($excerpt);
    $blog->tags = string_to_tag_array($tags);
    $guid = $blog->save();
    $newStatus = $blog->status;
    if ($guid > 0 && $newStatus == 'published') {
        elgg_create_river_item(array('view' => 'river/object/blog/create', 'action_type' => 'create', 'subject_guid' => $blog->owner_guid, 'object_guid' => $blog->getGUID()));
        elgg_trigger_event('publish', 'object', $blog);
        if ($guid) {
            $blog->time_created = time();
            $blog->save();
        }
        $return['guid'] = $guid;
        $return['message'] = $newStatus;
    } else {
        $return['guid'] = $guid;
        $return['message'] = $status;
    }
    return $return;
}