Esempio n. 1
0
/**
 * Function to be run periodically according to the moodle cron
 * This function searches for things that need to be done, such 
 * as sending out mail, toggling flags etc ... 
 *
 * @uses $CFG
 * @return boolean
 * @todo Finish documenting this function
 **/
function podcaster_cron()
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/podcaster/locallib.php';
    $modconf = get_record('modules', 'name', 'podcaster');
    $lastcron = $modconf->lastcron * 1;
    $channelupdate = array();
    $repositoryupdate = array();
    $metachannelupdate = array();
    // find channels modified past lastcron
    $channels = get_records_select('podcaster', 'timemodified > ' . $lastcron . ' AND ismeta = 0');
    if ($channels) {
        foreach ($channels as $channel) {
            $channelupdate['' . $channel->id] = PODCASTER_UPDATEREPOSITORY;
        }
    }
    // find items scheduled > lastcron && < now ()
    $items = get_records_select('podcaster_item', '(scheduledtime > ' . $lastcron . ' AND scheduledtime < ' . time() . ')');
    if ($items != false) {
        foreach ($items as $item) {
            $channelupdate['' . $item->channel] = PODCASTER_UPDATESELF;
            // implies update repository
        }
    }
    // update channel rss feeds
    foreach ($channelupdate as $id => $subject) {
        $c = get_record('podcaster', 'id', $id);
        if (!$c) {
            continue;
        }
        $cm = get_coursemodule_from_instance('podcaster', $id);
        if (!$cm) {
            continue;
        }
        $channel = podcaster_channel::create_channel($c, $cm);
        if ($subject == PODCASTER_UPDATESELF) {
            $channel->update_rss();
        }
        $repositoryupdate[$channel->repository] = true;
    }
    //  check for modified meta channels
    $metachannels = get_records('podcaster_metachannel');
    if ($metachannels) {
        foreach ($metachannels as $metachannel) {
            if ($metachannel->timemodified > $lastcron) {
                $metachannelupdate[$metachannel->id . ''] = $metachannel;
            } elseif ($metachannel->target == 'repository') {
                $params = explode(',', $metachannel->params);
                foreach ($params as $p) {
                    if (array_key_exists($p, $repositoryupdate)) {
                        $metachannelupdate[$metachannel->id . ''] = $metachannel;
                    }
                }
            }
        }
    }
    foreach ($metachannelupdate as $metachannel) {
        $channel = podcaster_channel::create_metachannel($metachannel);
        $channel->update_rss();
    }
    return true;
}
Esempio n. 2
0
 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>&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;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;
 }