Пример #1
0
/**
 * Pull together news variables for the save form
 *
 * @param ElggNews       $post
 * @param ElggAnnotation $revision
 * @return array
 */
function news_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 ($post->status == 'draft') {
            $values['access_id'] = $post->future_access;
        }
    }
    if (elgg_is_sticky_form('news')) {
        $sticky_values = elgg_get_sticky_values('news');
        foreach ($sticky_values as $key => $value) {
            $values[$key] = $value;
        }
    }
    elgg_clear_sticky_form('news');
    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.
    $auto_save_annotations = $post->getAnnotations(array('annotation_name' => 'news_auto_save', 'limit' => 1));
    if ($auto_save_annotations) {
        $auto_save = $auto_save_annotations[0];
    } else {
        $auto_save = false;
    }
    /* @var ElggAnnotation|false $auto_save */
    if ($auto_save && $revision && $auto_save->id != $revision->id) {
        $values['draft_warning'] = elgg_echo('news:messages:warning:draft');
    }
    return $values;
}
Пример #2
0
     $news->title = $title;
     $news->description = $description;
     $news->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.
     $news->new_post = true;
     if (!$news->save()) {
         $error = elgg_echo('news:error:cannot_save');
     }
 }
 // create 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 = $news->getAnnotations(array('annotation_name' => 'news_auto_save', 'limit' => 1));
     if ($auto_save_annotations) {
         $auto_save = $auto_save_annotations[0];
     } else {
         $auto_save = false;
     }
     if (!$auto_save) {
         $annotation_id = $news->annotate('news_auto_save', $description);
     } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value != $description) {
         $news->deleteAnnotations('news_auto_save');
         $annotation_id = $news->annotate('news_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) {