Beispiel #1
0
/**
 * Get related blogs to this blog
 *
 * @param ElggBlog $entity the blog to relate to
 * @param int      $limit  number of blogs to return
 *
 * @return false|ElggBlog[]
 */
function blog_tools_get_related_blogs(ElggBlog $entity, $limit = 4)
{
    $limit = sanitise_int($limit, false);
    if (!$entity instanceof ElggBlog) {
        return false;
    }
    // transform to values
    $tag_values = $entity->tags;
    if (empty($tag_values)) {
        return false;
    }
    if (!is_array($tag_values)) {
        $tag_values = [$tag_values];
    }
    // find blogs with these metadatavalues
    $options = ['type' => 'object', 'subtype' => 'blog', 'metadata_name' => 'tags', 'metadata_values' => $tag_values, 'wheres' => ["(e.guid <> {$entity->getGUID()})"], 'group_by' => 'e.guid', 'order_by' => 'count(msn.id) DESC', 'limit' => $limit];
    return elgg_get_entities_from_metadata($options);
}
/**
 * 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;
}
Beispiel #3
0
$user = elgg_get_logged_in_user_entity();
// edit or create a new entity
$guid = get_input('guid');
if ($guid) {
    $entity = get_entity($guid);
    if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
        $blog = $entity;
    } else {
        register_error(elgg_echo('blog:error:post_not_found'));
        forward(get_input('forward', REFERER));
    }
    // save some data for revisions once we save the new edit
    $revision_text = $blog->description;
    $new_post = $blog->new_post;
} else {
    $blog = new ElggBlog();
    $blog->subtype = 'blog';
    $new_post = TRUE;
}
// set the previous status for the hooks to update the time_created and river entries
$old_status = $blog->status;
// set defaults and required values.
$values = array('title' => '', 'description' => '', 'status' => 'draft', 'access_id' => ACCESS_DEFAULT, 'comments_on' => 'On', 'excerpt' => '', 'tags' => '', 'container_guid' => (int) get_input('container_guid'));
// fail if a required entity isn't set
$required = array('title', 'description');
// load from POST and do sanity and access checking
foreach ($values as $name => $default) {
    if ($name === 'title') {
        $value = htmlspecialchars(get_input('title', $default, false), ENT_QUOTES, 'UTF-8');
    } else {
        $value = get_input($name, $default);
Beispiel #4
0
$user = elgg_get_logged_in_user_entity();
// edit or create a new entity
$guid = get_input('guid');
if ($guid) {
    $entity = get_entity($guid);
    if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
        $blog = $entity;
    } else {
        register_error(elgg_echo('blog:error:post_not_found'));
        forward(get_input('forward', REFERER));
    }
    // save some data for revisions once we save the new edit
    $revision_text = $blog->description;
    $new_post = $blog->new_post;
} else {
    $blog = new ElggBlog();
    $blog->subtype = 'blog';
    $new_post = TRUE;
}
// set the previous status for the hooks to update the time_created and river entries
$old_status = $blog->status;
// set defaults and required values.
$values = array('title' => '', 'description' => '', 'status' => 'draft', 'access_id' => ACCESS_DEFAULT, 'comments_on' => 'On', 'excerpt' => '', 'tags' => '', 'container_guid' => (int) get_input('container_guid'));
// fail if a required entity isn't set
$required = array('title', 'description');
// load from POST and do sanity and access checking
foreach ($values as $name => $default) {
    $value = get_input($name, $default);
    if (in_array($name, $required) && empty($value)) {
        $error = elgg_echo("blog:error:missing:{$name}");
    }
Beispiel #5
0
$user = elgg_get_logged_in_user_entity();
// edit or create a new entity
$guid = get_input('guid');
if ($guid) {
    $entity = get_entity($guid);
    if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
        $blog = $entity;
    } else {
        register_error(elgg_echo('blog:error:post_not_found'));
        forward(get_input('forward', REFERER));
    }
    // save some data for revisions once we save the new edit
    $revision_text = $blog->description;
    $new_post = $blog->new_post;
} else {
    $blog = new ElggBlog();
    $blog->subtype = 'blog';
    $new_post = TRUE;
}
// set the previous status for the hooks to update the time_created and river entries
$old_status = $blog->status;
// set defaults and required values.
$values = array('title' => '', 'description' => '', 'status' => 'draft', 'access_id' => ACCESS_DEFAULT, 'comments_on' => 'On', 'excerpt' => '', 'tags' => '', 'container_guid' => (int) get_input('container_guid'));
// fail if a required entity isn't set
$required = array('title', 'description');
// load from POST and do sanity and access checking
foreach ($values as $name => $default) {
    if ($name === 'title') {
        $value = htmlspecialchars(get_input('title', $default, false), ENT_QUOTES, 'UTF-8');
    } else {
        $value = get_input($name, $default);
Beispiel #6
0
$count = (int) get_input('count');
$locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
$faker = Factory::create($locale);
$statuses = array('unsaved_draft', 'draft', 'published');
for ($i = 0; $i < $count; $i++) {
    $users = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => 1, 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
    $owner = $users[0];
    $containers = array($owner);
    $groups = $owner->getGroups(array(), 100);
    if ($groups) {
        $containers = array_merge($containers, $groups);
    }
    foreach ($containers as $container) {
        elgg_set_page_owner_guid($container->guid);
        $access_array = get_write_access_array($owner->guid);
        $blog = new ElggBlog();
        $blog->owner_guid = $owner->guid;
        $blog->container_guid = $container->guid;
        $blog->status = $statuses[array_rand($statuses, 1)];
        $access = array_rand($access_array, 1);
        if ($blog->status == 'unsaved_draft' || $blog->status == 'draft') {
            $blog->access_id = ACCESS_PRIVATE;
            $blog->future_access = $access;
        } else {
            $blog->access_id = $access;
        }
        $blog->title = $faker->sentence(6);
        $blog->description = $faker->text(500);
        $blog->excerpt = $faker->sentence(12);
        $blog->tags = $faker->words(5);
        //$blog->new_post = TRUE;
Beispiel #7
0
// because get_input() doesn't use the default if the input is ''
if (empty($excerpt)) {
    $excerpt = $description;
}
// store errors to pass along
$error = FALSE;
if ($title && $description) {
    if ($guid) {
        $entity = get_entity($guid);
        if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
            $blog = $entity;
        } 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
// because get_input() doesn't use the default if the input is ''
if (empty($excerpt)) {
    $excerpt = $description;
}
// store errors to pass along
$error = FALSE;
if ($title && $description) {
    if ($guid) {
        $entity = get_entity($guid);
        if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
            $blog = $entity;
        } 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
Beispiel #9
0
$user = elgg_get_logged_in_user_entity();
// edit or create a new entity
$guid = get_input('guid');
if ($guid) {
    $entity = get_entity($guid);
    if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
        $blog = $entity;
    } else {
        register_error(elgg_echo('blog:error:post_not_found'));
        forward(get_input('forward', REFERER));
    }
    // save some data for revisions once we save the new edit
    $revision_text = $blog->description;
    $new_post = $blog->new_post;
} else {
    $blog = new ElggBlog();
    $blog->subtype = 'blog';
    $new_post = TRUE;
}
// set the previous status for the hooks to update the time_created and river entries
$old_status = $blog->status;
// set defaults and required values.
$values = array('title' => '', 'description' => '', 'status' => 'draft', 'access_id' => ACCESS_DEFAULT, 'comments_on' => 'On', 'excerpt' => '', 'tags' => '', 'container_guid' => (int) get_input('container_guid'));
// fail if a required entity isn't set
$required = array('title', 'description');
// load from POST and do sanity and access checking
foreach ($values as $name => $default) {
    $value = get_input($name, $default);
    //kasper -added in to allow blog posts for non logged in users to work from the widget
    if ($name == "container_guid" && $value == 1) {
        $value = $user->getGUID();
Beispiel #10
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;
}