function create_metachannel(&$record) { static $metachannels; if (!is_array($metachannels)) { $metachannels = array(); } if (!array_key_exists($record->id . '', $metachannels)) { $channel = get_record('podcaster', 'id', $record->channel); $channel->target = $record->target; $channel->params = $record->params; $channel->path = $record->path; $channel->timemodified = $channel->timemodified > $record->timemodified ? $channel->timemodified : $record->timemodified; $metachannels[$record->id . ''] = podcaster_channel::create_channel($channel); } return $metachannels[$record->id . '']; }
function podcaster_sync_file($repository, $path, $action) { global $CFG; $updatelist = array(); $sql = 'SELECT * FROM ' . $CFG->prefix . 'podcaster WHERE repository = ' . $repository . ' AND image = \'' . $path . '\''; $channels = get_records_sql($sql); if ($channels) { foreach ($channels as $channel) { $channelObj = podcaster_channel::create_channel($channel); $channel->image = $channelObj->image = $action == 'delete' ? '' : $path; $channel->imageurl = $channelObj->imageurl = ''; $channel->imagetype = $channelObj->imagetype = ''; $channel->imagelength = $channelObj->imagelength = 0; $channel->imagewidth = $channelObj->imagewidth = 0; $channel->imageheight = $channelObj->imageheight = 0; update_record('podcaster', $channel); $updatelist[$channel->id . ''] = $channelObj; } } $sql = 'SELECT ' . $CFG->prefix . 'podcaster_item.* FROM ' . $CFG->prefix . 'podcaster,' . $CFG->prefix . 'podcaster_item WHERE ' . $CFG->prefix . 'podcaster.repository = ' . $repository . ' AND ' . $CFG->prefix . 'podcaster.id = ' . $CFG->prefix . 'podcaster_item.channel AND ' . $CFG->prefix . 'podcaster_item.enclosure = \'' . $path . '\''; $items = get_records_sql($sql); if ($items) { foreach ($items as $item) { if (!array_key_exists($item->channel . '', $updatelist)) { $channel = get_record('podcaster', 'id', $item->channel); $channelObj = podcaster_channel::create_channel($channel); $updatelist[$channel->id . ''] = $channelObj; } $item->enclosure = $action == 'delete' ? '' : $path; $item->enclosureurl = ''; $item->enclosuretype = ''; $item->enclosurelength = 0; update_record('podcaster_item', $item); } } foreach ($updatelist as $id => $channelObj) { if (!$channelObj->ismeta) { $channelObj->update_rss(); } } }
error('Course module is incorrect'); } } else { if (!($channel = get_record('podcaster', 'id', $channel))) { error('Course module is incorrect'); } if (!($course = get_record('course', 'id', $channel->course))) { error('Course is misconfigured'); } if (!($cm = get_coursemodule_from_instance('podcaster', $channel->id, $course->id))) { error('Course Module ID was incorrect'); } } require_login($course->id, false, $cm); // load appropriate channel $channel = podcaster_channel::create_channel($channel, $cm); if (!$channel->can_edit()) { print_error('nopermissions'); } // get the item instance if ($id) { $item = $channel->get_item($id); } else { $item = $channel->create_item(); } if (!$item) { error('Item ID was incorrect'); } $mform =& new podcaster_itemform($item, $course, $cm); $mform->set_data($item->get_data()); if ($mform->is_cancelled()) {
function get_items() { if ($this->items == NULL) { foreach ($this->params as $p) { $channels = get_records_select('podcaster', 'repository = ' . $p . ' AND ismeta = 0', 'name,timemodified'); if ($channels) { foreach ($channels as $channel) { $item = podcaster_channel::create_channel($channel); if ($item->coursemodule->visible) { $item->title = $item->name; $item->description = $item->intro; $this->items[] = $item; } } } } } return $this->items; }
function process_toolsform(&$formdata) { global $CFG; $error_reporting = ini_get('error_reporting'); $display_errors = ini_get('display_errors'); ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); if (isset($formdata->updatechannels)) { include_once $CFG->dirroot . '/mod/podcaster/lib/public.php'; include_once $CFG->dirroot . '/mod/podcaster/lib/util.php'; $start = microtime(); echo '<pre>Clearing cache ...</pre>'; flush(); execute_sql('UPDATE ' . $CFG->prefix . 'podcaster_item SET enclosureurl = \'\', enclosurelength = 0, enclosuretype = \'\''); execute_sql('UPDATE ' . $CFG->prefix . 'podcaster SET imageurl = \'\', imagewidth = 0, imageheight = 0, imagetype = \'\', imagelength = 0 WHERE ismeta = 0'); $channels = get_records('podcaster', 'ismeta', '0'); echo '<pre>Updating all channels ...</pre>'; flush(); if ($channels) { foreach ($channels as $channel) { echo '<pre> Updating ' . $channel->id . ': ' . htmlspecialchars($channel->name) . '</pre>'; flush(); $channelstart = microtime(); $channelObj = podcaster_channel::create_channel($channel); $channelObj->update_rss(); echo '<pre><a href="' . $channelObj->get_rss_link() . '">RSS</a> <a href="' . $CFG->wwwroot . '/mod/podcaster/view.php?channel=' . $channelObj->id . '">HTML</a></pre>'; echo '<pre> done in ' . podcaster_util::time_diff($channelstart, microtime()) . '</pre>'; flush(); } } echo '<pre>done in ' . podcaster_util::time_diff($start, microtime()) . '</pre>'; die; } elseif (isset($formdata->updatemetachannels)) { include_once $CFG->dirroot . '/mod/podcaster/lib/public.php'; include_once $CFG->dirroot . '/mod/podcaster/lib/util.php'; $start = microtime(); echo '<pre>Clearing cache ...</pre>'; execute_sql('UPDATE ' . $CFG->prefix . 'podcaster SET imageurl = \'\', imagewidth = 0, imageheight = 0, imagetype = \'\', imagelength = 0 WHERE ismeta = 1'); $channels = get_records('podcaster_metachannel'); echo '<pre>Updating all metachannels ...</pre>'; flush(); if ($channels) { foreach ($channels as $channel) { echo '<pre> Updating ' . $channel->id . ': ' . htmlspecialchars($channel->name) . '</pre>'; flush(); $channelstart = microtime(); $channelObj = podcaster_channel::create_metachannel($channel); $channelObj->update_rss(); echo '<pre><a href="' . $channelObj->get_rss_link() . '">RSS</a> <a href="' . $CFG->wwwroot . '/mod/podcaster/view.php?channel=' . $channelObj->id . '">HTML</a></pre>'; echo '<pre> done in ' . podcaster_util::time_diff($channelstart, microtime()) . '</pre>'; flush(); } } echo '<pre>done in ' . podcaster_util::time_diff($start, microtime()) . '</pre>'; die; } ini_set('error_reporting', $error_reporting); ini_set('display_errors', $display_errors); return PODCASTER_NOERROR; }