/** * Save the podcast * * @param array $data File data to upload, if null then we're just setting attribute * @return bool * * @throws InvalidPodcastFileException|IOException */ public function save($data = NULL) { if (!parent::save()) { return FALSE; } // New Podcast File Data if ($data) { $this->simpletype = "audio"; // Get mimetype $mime_type = ElggPodcast::detectMimeType($data['tmp_name'], $data['type']); // Check for valid mime type if (ElggPodcast::checkValidMimeType($mime_type)) { // Set it $this->setMimeType($mime_type); } else { // Invalid, fail $ex = elgg_echo('InvalidPodcastFileException:InvalidMimeType', array($mime_type)); throw new InvalidPodcastFileException($ex); } // Remove old file if it exists $old_file = $this->getFilenameOnFilestore(); if (file_exists($old_file) && !is_dir($old_file)) { unlink($old_file); } // Save the file data $this->savePodcastFile($data); // Populate metadata $this->populatePodcastMetadata(); } return TRUE; }
/** * Format and return the URL for podcasts. * * @param ElggPodcast $podcast Podcast object * @return string URL of podcast. */ function podcasts_url_handler($podcast) { if (!$podcast->getOwnerEntity()) { // default to a standard view if no owner. return FALSE; } $friendly_title = elgg_get_friendly_title($podcast->title); return "podcasts/view/{$podcast->guid}/{$friendly_title}"; }
<?php /** * Elgg Podcasts Download Podcast * * @package Podcasts * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Jeff Tilson * @copyright THINK Global School 2010 - 2013 * @link http://www.thinkglobalschool.com/ * */ // Get the guid $podcast_guid = get_input("guid"); // Get the file $podcast = new ElggPodcast($podcast_guid); // Check for valid podcast if (!$podcast) { register_error(elgg_echo("podcasts:downloadfailed")); forward(REFERER); } // Podcast file info $mime = $podcast->getMimeType(); $podcastname = $podcast->getFileTitle(); $filename = $podcast->getFilenameOnFilestore(); if (!file_exists($filename)) { register_error(elgg_echo("podcasts:notfound")); forward(REFERER); } $size = filesize($filename); // Output file
/** * Get file info using exiftool * * @param ElggPodcast $podcast * * @return mixed - 0 on success or error message */ function podcasts_populate_file_info($podcast) { // Get exiftool command path $cmd_path = elgg_get_plugin_setting('podcasts_exiftool_root', 'podcasts'); // Get podcast filename $filename = $podcast->getFilenameOnFilestore(); // Set up exif tool command $command = $cmd_path . "exiftool -S -Duration -n \"{$filename}\""; $output = array(); $return = 0; // Run command exec($command, $output, $return); // If we have valid output.. if ($return == 0 && count($output) >= 1) { $duration = $output[0]; // This will be something like: Duration: 134.22424 (in seconds) $duration = (int) round((double) trim(substr($duration, strpos($duration, ":") + 1))); // Got a valid number? Set duration. if (is_int($duration)) { $podcast->duration = $duration; } else { // Something wrong $return = 1; } } // Return value return $return; }
if ($comments_count != 0) { $text = elgg_echo("comments") . " ({$comments_count})"; $comments_link = elgg_view('output/url', array('href' => $file->getURL() . '#file-comments', 'text' => $text, 'is_trusted' => true)); } else { $comments_link = ''; } $metadata = elgg_view_menu('entity', array('entity' => $vars['entity'], 'handler' => 'file', 'sort_by' => 'priority', 'class' => 'elgg-menu-hz')); $subtitle = "{$author_text} {$date} {$comments_link} {$categories}"; // do not show the metadata and controls in widget view if (elgg_in_context('widgets')) { $metadata = ''; } // Check if this file is playable with podcast player elgg_load_library('elgg:podcasts'); $mimetype = podcasts_get_mime_type($file->getFilenameOnFilestore()); if (ElggPodcast::checkValidMimeType($mimetype)) { // Load JS/CSS elgg_load_js('elgg.podcasts'); elgg_load_js('soundmanager2'); elgg_load_css('elgg.podcasts'); if (!$file->duration) { podcasts_populate_file_info($file); } $player = elgg_view('podcasts/player', array('entity_guid' => $file->guid)); } if ($full && !elgg_in_context('gallery')) { $extra = ''; if (elgg_view_exists("file/specialcontent/{$mime}")) { $extra = elgg_view("file/specialcontent/{$mime}", $vars); } else { if (elgg_view_exists("file/specialcontent/{$base_type}/default")) {
* */ // Get guid for editing $guid = get_input('guid'); // Set up sticky form elgg_make_sticky_form('podcast'); $error = FALSE; if ($guid) { $podcast = get_entity($guid); if (!elgg_instanceof($podcast, 'object', 'podcast') || !$podcast->canEdit()) { register_error(elgg_echo('podcasts:error:notfound')); forward(get_input('forward', REFERER)); } $new_podcast = FALSE; } else { $podcast = new ElggPodcast(); // New podcasts require a file if (empty($_FILES['upload']['name'])) { $error = TRUE; register_error(elgg_echo('podcasts:error:missing:file')); } $new_podcast = TRUE; } // Check required fields $required = array('title', 'description'); foreach ($required as $field) { $value = get_input($field); if (empty($value)) { register_error(elgg_echo("podcasts:error:missing:{$field}")); $error = TRUE; } else {