Ejemplo n.º 1
0
/**
 * Pull together podcast variables for the save form
 *
 * @param ElggPodcast       $podcast
 *
 * @return array
 */
function podcasts_prepare_form_vars($podcast = NULL)
{
    // input names => defaults
    $values = array('title' => NULL, 'description' => NULL, 'access_id' => ACCESS_PUBLIC, 'tags' => NULL, 'container_guid' => NULL, 'guid' => NULL);
    if ($podcast) {
        foreach (array_keys($values) as $field) {
            if (isset($podcast->{$field})) {
                $values[$field] = $podcast->{$field};
            }
        }
        if ($podcast->status == 'draft') {
            $values['access_id'] = $podcast->future_access;
        }
    }
    if (elgg_is_sticky_form('podcast')) {
        $sticky_values = elgg_get_sticky_values('podcast');
        foreach ($sticky_values as $key => $value) {
            $values[$key] = $value;
        }
    }
    elgg_clear_sticky_form('podcast');
    if (!$podcast) {
        return $values;
    }
    // load the revision annotation if requested
    if ($revision instanceof ElggAnnotation && $revision->entity_guid == $podcast->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 = $podcast->getAnnotations('podcast_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('podcasts:messages:warning:draft');
    }
    return $values;
}
Ejemplo n.º 2
0
$podcast->container_guid = $container_guid;
// We have a new/replacement file for this podcast
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
    $file = $_FILES['upload'];
}
// Try saving
try {
    $result = $podcast->save($file);
    if ($result) {
        // Clear sticky form
        elgg_clear_sticky_form('podcast');
        system_message(elgg_echo('podcasts:success:save'));
        // Add to river if this is a new podcast
        if (!$guid) {
            // River item
            add_to_river('river/object/podcast/create', 'create', $podcast->owner_guid, $podcast->getGUID());
        }
        $fwd = $podcast->getURL();
    } else {
        register_error(elgg_echo('podcasts:error:save'));
    }
} catch (Exception $ex) {
    // At this point the podcast entity could have been saved.. clean it up we don't want missing metadata
    if ($new_podcast && $podcast->guid) {
        // check first..
        $podcast->delete();
    }
    register_error($ex->getMessage());
}
if (!$fwd) {
    $fwd = REFERER;