Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/url/lib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die;
00028 
00034 function url_supports($feature) {
00035     switch($feature) {
00036         case FEATURE_MOD_ARCHETYPE:           return MOD_ARCHETYPE_RESOURCE;
00037         case FEATURE_GROUPS:                  return false;
00038         case FEATURE_GROUPINGS:               return false;
00039         case FEATURE_GROUPMEMBERSONLY:        return true;
00040         case FEATURE_MOD_INTRO:               return true;
00041         case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
00042         case FEATURE_GRADE_HAS_GRADE:         return false;
00043         case FEATURE_GRADE_OUTCOMES:          return false;
00044         case FEATURE_BACKUP_MOODLE2:          return true;
00045         case FEATURE_SHOW_DESCRIPTION:        return true;
00046 
00047         default: return null;
00048     }
00049 }
00050 
00055 function url_get_extra_capabilities() {
00056     return array('moodle/site:accessallgroups');
00057 }
00058 
00064 function url_reset_userdata($data) {
00065     return array();
00066 }
00067 
00072 function url_get_view_actions() {
00073     return array('view', 'view all');
00074 }
00075 
00080 function url_get_post_actions() {
00081     return array('update', 'add');
00082 }
00083 
00090 function url_add_instance($data, $mform) {
00091     global $CFG, $DB;
00092 
00093     require_once($CFG->dirroot.'/mod/url/locallib.php');
00094 
00095     $parameters = array();
00096     for ($i=0; $i < 100; $i++) {
00097         $parameter = "parameter_$i";
00098         $variable  = "variable_$i";
00099         if (empty($data->$parameter) or empty($data->$variable)) {
00100             continue;
00101         }
00102         $parameters[$data->$parameter] = $data->$variable;
00103     }
00104     $data->parameters = serialize($parameters);
00105 
00106     $displayoptions = array();
00107     if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
00108         $displayoptions['popupwidth']  = $data->popupwidth;
00109         $displayoptions['popupheight'] = $data->popupheight;
00110     }
00111     if (in_array($data->display, array(RESOURCELIB_DISPLAY_AUTO, RESOURCELIB_DISPLAY_EMBED, RESOURCELIB_DISPLAY_FRAME))) {
00112         $displayoptions['printheading'] = (int)!empty($data->printheading);
00113         $displayoptions['printintro']   = (int)!empty($data->printintro);
00114     }
00115     $data->displayoptions = serialize($displayoptions);
00116 
00117     $data->externalurl = url_fix_submitted_url($data->externalurl);
00118 
00119     $data->timemodified = time();
00120     $data->id = $DB->insert_record('url', $data);
00121 
00122     return $data->id;
00123 }
00124 
00131 function url_update_instance($data, $mform) {
00132     global $CFG, $DB;
00133 
00134     require_once($CFG->dirroot.'/mod/url/locallib.php');
00135 
00136     $parameters = array();
00137     for ($i=0; $i < 100; $i++) {
00138         $parameter = "parameter_$i";
00139         $variable  = "variable_$i";
00140         if (empty($data->$parameter) or empty($data->$variable)) {
00141             continue;
00142         }
00143         $parameters[$data->$parameter] = $data->$variable;
00144     }
00145     $data->parameters = serialize($parameters);
00146 
00147     $displayoptions = array();
00148     if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
00149         $displayoptions['popupwidth']  = $data->popupwidth;
00150         $displayoptions['popupheight'] = $data->popupheight;
00151     }
00152     if (in_array($data->display, array(RESOURCELIB_DISPLAY_AUTO, RESOURCELIB_DISPLAY_EMBED, RESOURCELIB_DISPLAY_FRAME))) {
00153         $displayoptions['printheading'] = (int)!empty($data->printheading);
00154         $displayoptions['printintro']   = (int)!empty($data->printintro);
00155     }
00156     $data->displayoptions = serialize($displayoptions);
00157 
00158     $data->externalurl = url_fix_submitted_url($data->externalurl);
00159 
00160     $data->timemodified = time();
00161     $data->id           = $data->instance;
00162 
00163     $DB->update_record('url', $data);
00164 
00165     return true;
00166 }
00167 
00173 function url_delete_instance($id) {
00174     global $DB;
00175 
00176     if (!$url = $DB->get_record('url', array('id'=>$id))) {
00177         return false;
00178     }
00179 
00180     // note: all context files are deleted automatically
00181 
00182     $DB->delete_records('url', array('id'=>$url->id));
00183 
00184     return true;
00185 }
00186 
00195 function url_user_outline($course, $user, $mod, $url) {
00196     global $DB;
00197 
00198     if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'url',
00199                                               'action'=>'view', 'info'=>$url->id), 'time ASC')) {
00200 
00201         $numviews = count($logs);
00202         $lastlog = array_pop($logs);
00203 
00204         $result = new stdClass();
00205         $result->info = get_string('numviews', '', $numviews);
00206         $result->time = $lastlog->time;
00207 
00208         return $result;
00209     }
00210     return NULL;
00211 }
00212 
00220 function url_user_complete($course, $user, $mod, $url) {
00221     global $CFG, $DB;
00222 
00223     if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'url',
00224                                               'action'=>'view', 'info'=>$url->id), 'time ASC')) {
00225         $numviews = count($logs);
00226         $lastlog = array_pop($logs);
00227 
00228         $strmostrecently = get_string('mostrecently');
00229         $strnumviews = get_string('numviews', '', $numviews);
00230 
00231         echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
00232 
00233     } else {
00234         print_string('neverseen', 'url');
00235     }
00236 }
00237 
00246 function url_get_participants($urlid) {
00247     return false;
00248 }
00249 
00260 function url_get_coursemodule_info($coursemodule) {
00261     global $CFG, $DB;
00262     require_once("$CFG->dirroot/mod/url/locallib.php");
00263 
00264     if (!$url = $DB->get_record('url', array('id'=>$coursemodule->instance),
00265             'id, name, display, displayoptions, externalurl, parameters, intro, introformat')) {
00266         return NULL;
00267     }
00268 
00269     $info = new cached_cm_info();
00270     $info->name = $url->name;
00271 
00272     //note: there should be a way to differentiate links from normal resources
00273     $info->icon = url_guess_icon($url->externalurl);
00274 
00275     $display = url_get_final_display_type($url);
00276 
00277     if ($display == RESOURCELIB_DISPLAY_POPUP) {
00278         $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&amp;redirect=1";
00279         $options = empty($url->displayoptions) ? array() : unserialize($url->displayoptions);
00280         $width  = empty($options['popupwidth'])  ? 620 : $options['popupwidth'];
00281         $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
00282         $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
00283         $info->onclick = "window.open('$fullurl', '', '$wh'); return false;";
00284 
00285     } else if ($display == RESOURCELIB_DISPLAY_NEW) {
00286         $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&amp;redirect=1";
00287         $info->onclick = "window.open('$fullurl'); return false;";
00288 
00289     }
00290 
00291     if ($coursemodule->showdescription) {
00292         // Convert intro to html. Do not filter cached version, filters run at display time.
00293         $info->content = format_module_intro('url', $url, $coursemodule->id, false);
00294     }
00295 
00296     return $info;
00297 }
00298 
00310 function url_extend_navigation($navigation, $course, $module, $cm) {
00316     $navigation->nodetype = navigation_node::NODETYPE_LEAF;
00317 }
00318 
00325 function url_page_type_list($pagetype, $parentcontext, $currentcontext) {
00326     $module_pagetype = array('mod-url-*'=>get_string('page-mod-url-x', 'url'));
00327     return $module_pagetype;
00328 }
00329 
00335 function url_export_contents($cm, $baseurl) {
00336     global $CFG, $DB;
00337     require_once("$CFG->dirroot/mod/url/locallib.php");
00338     $contents = array();
00339     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
00340 
00341     $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
00342     $url = $DB->get_record('url', array('id'=>$cm->instance), '*', MUST_EXIST);
00343 
00344     $fullurl = str_replace('&amp;', '&', url_get_full_url($url, $cm, $course));
00345     $isurl = clean_param($fullurl, PARAM_URL);
00346     if (empty($isurl)) {
00347         return null;
00348     }
00349 
00350     $url = array();
00351     $url['type'] = 'url';
00352     $url['filename']     = $url->name;
00353     $url['filepath']     = null;
00354     $url['filesize']     = 0;
00355     $url['fileurl']      = $fullurl;
00356     $url['timecreated']  = null;
00357     $url['timemodified'] = $url->timemodified;
00358     $url['sortorder']    = null;
00359     $url['userid']       = null;
00360     $url['author']       = null;
00361     $url['license']      = null;
00362     $contents[] = $url;
00363 
00364     return $contents;
00365 }
 All Data Structures Namespaces Files Functions Variables Enumerations