Exemple #1
0
     // remove sticky form entries
     elgg_clear_sticky_form('news');
     // remove autosave draft if exists
     $news->deleteAnnotations('news_auto_save');
     // no longer a brand new post.
     $news->deleteMetadata('new_post');
     // if this was an edit, create a revision annotation
     if (!$new_post && $revision_text) {
         $news->annotate('news_revision', $revision_text);
     }
     system_message(elgg_echo('news:message:saved'));
     $status = $news->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') {
         elgg_create_river_item(array('view' => 'river/object/news/create', 'action_type' => 'create', 'subject_guid' => $news->owner_guid, 'object_guid' => $news->getGUID()));
         elgg_trigger_event('publish', 'news', $news);
         // reset the creation time for news posts that move from draft to published
         if ($guid) {
             $news->time_created = time();
             $news->save();
         }
     } elseif ($old_status == 'published' && $status == 'draft') {
         elgg_delete_river(array('object_guid' => $news->guid, 'action_type' => 'create'));
     }
     if ($news->status == 'published' || $save == false) {
         forward($news->getURL());
     } else {
         forward("news/edit/{$news->guid}");
     }
 } else {
Exemple #2
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;
}
        $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) {
            $error = elgg_echo('news:error:cannot_auto_save');
        }
    }
} else {
    $error = elgg_echo('news:error:missing:description');
}
if ($error) {
    $json = array('success' => false, 'message' => $error);
    echo json_encode($json);
} else {
    $msg = elgg_echo('news:message:saved');
    $json = array('success' => true, 'message' => $msg, 'guid' => $news->getGUID());
    echo json_encode($json);
}
exit;