Пример #1
0
        /**
     * The standard tags (typically performance information and validation links,
     * if we are in developer debug mode) that should be output in the footer area
     * of the page. Designed to be called in theme layout.php files.
     * @return string HTML fragment.
     */
    public function standard_footer_html() {
        global $CFG;

        // This function is normally called from a layout.php file in {@link header()}
        // but some of the content won't be known until later, so we return a placeholder
        // for now. This will be replaced with the real content in {@link footer()}.
        $output = self::PERFORMANCE_INFO_TOKEN;
        // Moodle 2.1 uses a magic accessor for $this->page->devicetypeinuse so we need to
        // check for the existence of the function that uses as
        // isset($this->page->devicetypeinuse) returns false
        if (function_exists('get_user_device_type')?($this->page->devicetypeinuse=='legacy'):$this->page->legacythemeinuse) {
            // The legacy theme is in use print the notification
            $output .= html_writer::tag('div', get_string('legacythemeinuse'), array('class'=>'legacythemeinuse'));
        }
       // if (!empty($CFG->debugpageinfo)) {
       //     $output .= '<div class="performanceinfo">This page is: ' . $this->page->debug_summary() . '</div>';
       // }
        if (debugging(null, DEBUG_DEVELOPER)) {  // Only in developer mode
            $output .= '<div class="purgecaches"><a href="'.$CFG->wwwroot.'/admin/purgecaches.php?confirm=1&amp;sesskey='.sesskey().'">'.get_string('purgecaches', 'admin').'</a></div>';
        }
        if (!empty($CFG->debugvalidators)) {
            $output .= '<div class="validators"><ul>
              <li><a href="http://validator.w3.org/check?verbose=1&amp;ss=1&amp;uri=' . urlencode(qualified_me()) . '">Validate HTML</a></li>
              <li><a href="http://www.contentquality.com/mynewtester/cynthia.exe?rptmode=-1&amp;url1=' . urlencode(qualified_me()) . '">Section 508 Check</a></li>
              <li><a href="http://www.contentquality.com/mynewtester/cynthia.exe?rptmode=0&amp;warnp2n3e=1&amp;url1=' . urlencode(qualified_me()) . '">WCAG 1 (2,3) Check</a></li>
            </ul></div>';
        }
        return $output;
    }
 /**
  * Constructor
  *
  * @param string $identifier The key identifier for the localized string
  * @param string $module The module where the key identifier is stored. If none is specified then moodle.php is used.
  * @param mixed $a An object, string or number that can be used within translation strings
  * @param int $code Error code
  * @return void
  **/
 public function __construct($identifier, $module = 'block_gdata', $a = NULL, $code = 0)
 {
     global $CFG;
     $message = get_string($identifier, $module, $a);
     if (debugging()) {
         // Code compliments of /lib/weblib.php :D
         $callers = $this->getTrace();
         $message .= '<p>Debugging Traceback (to hide, turn off debugging):<ul style="text-align: left">';
         foreach ($callers as $caller) {
             if (!isset($caller['line'])) {
                 $caller['line'] = '?';
                 // probably call_user_func()
             }
             if (!isset($caller['file'])) {
                 $caller['file'] = $CFG->dirroot . '/unknownfile';
                 // probably call_user_func()
             }
             $message .= '<li>line ' . $caller['line'] . ' of ' . substr($caller['file'], strlen($CFG->dirroot) + 1);
             if (isset($caller['function'])) {
                 $message .= ': call to ';
                 if (isset($caller['class'])) {
                     $message .= $caller['class'] . $caller['type'];
                 }
                 $message .= $caller['function'] . '()';
             }
             $message .= '</li>';
         }
         $message .= '</ul></p>';
     }
     parent::__construct($message, $code);
 }
Пример #3
0
 /**
  * Processes the message (sends using jabber).
  * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
  * @return true if ok, false if error
  */
 function send_message($eventdata)
 {
     global $CFG;
     if (message_output_jabber::_jabber_configured()) {
         //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once
         static $jabberaddresses = array();
         if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) {
             $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', $eventdata->userto->email, $eventdata->userto->id);
         }
         $jabberaddress = $jabberaddresses[$eventdata->userto->id];
         $jabbermessage = fullname($eventdata->userfrom) . ': ' . $eventdata->smallmessage;
         if (!empty($eventdata->contexturl)) {
             $jabbermessage .= "\n" . get_string('view') . ': ' . $eventdata->contexturl;
         }
         $jabbermessage .= "\n(" . get_string('noreply', 'message') . ')';
         $conn = new XMPPHP_XMPP($CFG->jabberhost, $CFG->jabberport, $CFG->jabberusername, $CFG->jabberpassword, 'moodle', $CFG->jabberserver);
         try {
             //$conn->useEncryption(false);
             $conn->connect();
             $conn->processUntil('session_start');
             $conn->presence();
             $conn->message($jabberaddress, $jabbermessage);
             $conn->disconnect();
         } catch (XMPPHP_Exception $e) {
             debugging($e->getMessage());
             return false;
         }
     }
     //note that we're reporting success if message was sent or if Jabber simply isnt configured
     return true;
 }
Пример #4
0
/**
 * Fetches content of file from Internet (using proxy if defined).
 *
 * @return mixed false if request failed or content of the file as string if ok.
 */
function download_file_content($url)
{
    global $CFG;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    if (!empty($CFG->proxyhost)) {
        // don't CONNECT for non-https connections
        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
        if (empty($CFG->proxyport)) {
            curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost);
        } else {
            curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost . ':' . $CFG->proxyport);
        }
        if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $CFG->proxyuser . ':' . $CFG->proxypassword);
        }
    }
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        $curlerror = "CURL request for \"{$url}\" failed with: " . curl_error($ch);
        debugging($curlerror, DEBUG_DEVELOPER);
    }
    curl_close($ch);
    return $result;
}
 /**
  * Processes the message (sends using jabber).
  * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
  * @return true if ok, false if error
  */
 function send_message($eventdata)
 {
     global $CFG;
     if (!empty($CFG->noemailever)) {
         // hidden setting for development sites, set in config.php if needed
         debugging('$CFG->noemailever active, no jabber message sent.', DEBUG_MINIMAL);
         return true;
     }
     //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once
     static $jabberaddresses = array();
     if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) {
         $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', null, $eventdata->userto->id);
     }
     $jabberaddress = $jabberaddresses[$eventdata->userto->id];
     //calling s() on smallmessage causes Jabber to display things like &lt; Jabber != a browser
     $jabbermessage = fullname($eventdata->userfrom) . ': ' . $eventdata->smallmessage;
     if (!empty($eventdata->contexturl)) {
         $jabbermessage .= "\n" . get_string('view') . ': ' . $eventdata->contexturl;
     }
     $jabbermessage .= "\n(" . get_string('noreply', 'message') . ')';
     $conn = new XMPPHP_XMPP($CFG->jabberhost, $CFG->jabberport, $CFG->jabberusername, $CFG->jabberpassword, 'moodle', $CFG->jabberserver);
     try {
         //$conn->useEncryption(false);
         $conn->connect();
         $conn->processUntil('session_start');
         $conn->presence();
         $conn->message($jabberaddress, $jabbermessage);
         $conn->disconnect();
     } catch (XMPPHP_Exception $e) {
         debugging($e->getMessage());
         return false;
     }
     return true;
 }
Пример #6
0
 /**
  * Returns the document associated with this activity.
  *
  * This default implementation for activities sets the activity name to title and the activity intro to
  * content. Any activity can overwrite this function if it is interested in setting other fields than the
  * default ones, or to fill description optional fields with extra stuff.
  *
  * @param stdClass $record
  * @param array    $options
  * @return \core_search\document
  */
 public function get_document($record, $options = array())
 {
     try {
         $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
         $context = \context_module::instance($cm->id);
     } catch (\dml_missing_record_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     } catch (\dml_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', content_to_text($record->name, false));
     $doc->set('content', content_to_text($record->intro, $record->introformat));
     $doc->set('contextid', $context->id);
     $doc->set('courseid', $record->course);
     $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
     $doc->set('modified', $record->{static::MODIFIED_FIELD_NAME});
     // Check if this document should be considered new.
     if (isset($options['lastindexedtime'])) {
         $createdfield = static::CREATED_FIELD_NAME;
         if (!empty($createdfield) && $options['lastindexedtime'] < $record->{$createdfield}) {
             // If the document was created after the last index time, it must be new.
             $doc->set_is_new(true);
         }
     }
     return $doc;
 }
Пример #7
0
    /**
     * Processes the message (sends by email).
     * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
     */
    function send_message($eventdata) {
        global $CFG;

        if (!empty($CFG->noemailever)) {
            // hidden setting for development sites, set in config.php if needed
            debugging('$CFG->noemailever active, no email message sent.', DEBUG_MINIMAL);
            return true;
        }

        // skip any messaging suspended and deleted users
        if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
            return true;
        }

        //the user the email is going to
        $recipient = null;

        //check if the recipient has a different email address specified in their messaging preferences Vs their user profile
        $emailmessagingpreference = get_user_preferences('message_processor_email_email', null, $eventdata->userto);
        $emailmessagingpreference = clean_param($emailmessagingpreference, PARAM_EMAIL);

        // If the recipient has set an email address in their preferences use that instead of the one in their profile
        // but only if overriding the notification email address is allowed
        if (!empty($emailmessagingpreference) && !empty($CFG->messagingallowemailoverride)) {
            //clone to avoid altering the actual user object
            $recipient = clone($eventdata->userto);
            $recipient->email = $emailmessagingpreference;
        } else {
            $recipient = $eventdata->userto;
        }
        $result = email_to_user($recipient, $eventdata->userfrom, $eventdata->subject, $eventdata->fullmessage, $eventdata->fullmessagehtml);

        return $result;
    }
Пример #8
0
/**
* removes a user's access to a platform in his profile customized data.
* Note that this operation should ONLY be perfomed on a host where the
* user has his master account record (i.e. not MNET).
* @param object $user
* @param string $wwwroot
*/
function user_mnet_host_remove_access($user, $wwwroot)
{
    if (empty($wwwroot)) {
        if (debugging()) {
            echo $OUTPUT->notification('Add access : empty host');
        }
        return;
    }
    if (empty($user)) {
        if (debugging()) {
            echo $OUTPUT->notification('Add access : empty user');
        }
        return;
    }
    preg_match('/https?:\\/\\/([^.]*)/', $wwwroot, $matches);
    $hostprefix = $matches[1];
    $hostfieldname = 'access' . str_replace('-', '', strtoupper($hostprefix));
    // need cleaning name from hyphens
    if ($userfield = $DB->get_record('user_info_field', array('shortname' => $hostfieldname))) {
        if ($accessrec = $DB->get_record('user_info_data', array('fieldid' => $userfield->id, 'userid' => $user->id))) {
            $accessrec->value = 0;
            $DB->update_record('user_info_data', $accessrec);
        } else {
            $accessrec->fieldid = $userfield->id;
            $accessrec->userid = $user->id;
            $accessrec->value = 0;
            $DB->insert_record('user_info_data', $accessrec);
        }
    }
}
 function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     // shortcut -  only for logged in users!
     if (!isloggedin() || isguestuser()) {
         return false;
     }
     // according to start_jump_session,
     // remote users can't on-jump
     // so don't show this block to them
     if (is_mnet_remote_user($USER)) {
         if (debugging() and !empty($CFG->debugdisplay)) {
             $this->content = new stdClass();
             $this->content->footer = html_writer::tag('span', get_string('error_localusersonly', 'block_mnet_hosts'), array('class' => 'error'));
             return $this->content;
         } else {
             return '';
         }
     }
     if (!is_enabled_auth('mnet')) {
         if (debugging() and !empty($CFG->debugdisplay)) {
             $this->content = new stdClass();
             $this->content->footer = html_writer::tag('span', get_string('error_authmnetneeded', 'block_mnet_hosts'), array('class' => 'error'));
             return $this->content;
         } else {
             return '';
         }
     }
     if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
         if (debugging() and !empty($CFG->debugdisplay)) {
             $this->content = new stdClass();
             $this->content->footer = html_writer::tag('span', get_string('error_roamcapabilityneeded', 'block_mnet_hosts'), array('class' => 'error'));
             return $this->content;
         } else {
             return '';
         }
     }
     if ($this->content !== NULL) {
         return $this->content;
     }
     // TODO: Test this query - it's appropriate? It works?
     // get the hosts and whether we are doing SSO with them
     $sql = "\n             SELECT DISTINCT\n                 h.id,\n                 h.name,\n                 h.wwwroot,\n                 a.name as application,\n                 a.display_name\n             FROM\n                 {mnet_host} h,\n                 {mnet_application} a,\n                 {mnet_host2service} h2s_IDP,\n                 {mnet_service} s_IDP,\n                 {mnet_host2service} h2s_SP,\n                 {mnet_service} s_SP\n             WHERE\n                 h.id <> ? AND\n                 h.id <> ? AND\n                 h.id = h2s_IDP.hostid AND\n                 h.deleted = 0 AND\n                 h.applicationid = a.id AND\n                 h2s_IDP.serviceid = s_IDP.id AND\n                 s_IDP.name = 'sso_idp' AND\n                 h2s_IDP.publish = '1' AND\n                 h.id = h2s_SP.hostid AND\n                 h2s_SP.serviceid = s_SP.id AND\n                 s_SP.name = 'sso_idp' AND\n                 h2s_SP.publish = '1'\n             ORDER BY\n                 a.display_name,\n                 h.name";
     $hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id, $CFG->mnet_all_hosts_id));
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if ($hosts) {
         foreach ($hosts as $host) {
             $icon = '<img src="' . $OUTPUT->pix_url('i/' . $host->application . '_host') . '"' . ' class="icon" alt="' . get_string('server', 'block_mnet_hosts') . '" />&nbsp;';
             if ($host->id == $USER->mnethostid) {
                 $this->content->items[] = "<a title=\"" . s($host->name) . "\" href=\"{$host->wwwroot}\">" . $icon . s($host->name) . "</a>";
             } else {
                 $this->content->items[] = "<a title=\"" . s($host->name) . "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . $icon . s($host->name) . "</a>";
             }
         }
     }
     return $this->content;
 }
Пример #10
0
 /**
  * Constructs with course-module details.
  *
  * @param object $cm Moodle course-module object. May have extra fields
  *   ->conditionsgrade, ->conditionscompletion which should come from 
  *   get_fast_modinfo. Should have ->availablefrom, ->availableuntil, 
  *   and ->showavailability, ->course; but the only required thing is ->id.
  * @param int $expectingmissing Used to control whether or not a developer
  *   debugging message (performance warning) will be displayed if some of 
  *   the above data is missing and needs to be retrieved; a 
  *   CONDITION_MISSING_xx constant
  * @param bool $loaddata If you need a 'write-only' object, set this value
  *   to false to prevent database access from constructor
  * @return condition_info Object which can retrieve information about the
  *   activity
  */
 public function __construct($cm, $expectingmissing = CONDITION_MISSING_NOTHING, $loaddata = true)
 {
     global $DB;
     // Check ID as otherwise we can't do the other queries
     if (empty($cm->id)) {
         throw new coding_exception("Invalid parameters; course-module ID not included");
     }
     // If not loading data, don't do anything else
     if (!$loaddata) {
         $this->cm = (object) array('id' => $cm->id);
         $this->gotdata = false;
         return;
     }
     // Missing basic data from course_modules
     if (!isset($cm->availablefrom) || !isset($cm->availableuntil) || !isset($cm->showavailability) || !isset($cm->course)) {
         if ($expectingmissing < CONDITION_MISSING_EVERYTHING) {
             debugging('Performance warning: condition_info constructor is 
                 faster if you pass in $cm with at least basic fields 
                 (availablefrom,availableuntil,showavailability,course). 
                 [This warning can be disabled, see phpdoc.]', DEBUG_DEVELOPER);
         }
         $cm = $DB->get_record('course_modules', array('id' => $cm->id), 'id,course,availablefrom,availableuntil,showavailability');
     }
     $this->cm = clone $cm;
     $this->gotdata = true;
     // Missing extra data
     if (!isset($cm->conditionsgrade) || !isset($cm->conditionscompletion)) {
         if ($expectingmissing < CONDITION_MISSING_EXTRATABLE) {
             debugging('Performance warning: condition_info constructor is 
                 faster if you pass in a $cm from get_fast_modinfo.
                 [This warning can be disabled, see phpdoc.]', DEBUG_DEVELOPER);
         }
         self::fill_availability_conditions($this->cm);
     }
 }
Пример #11
0
    /**
     * Processes the message (sends by email).
     * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
     */
    function send_message($eventdata) {
        global $CFG;

        if (!empty($CFG->noemailever)) {
            // hidden setting for development sites, set in config.php if needed
            debugging('$CFG->noemailever active, no email message sent.', DEBUG_MINIMAL);
            return true;
        }

        //the user the email is going to
        $recipient = null;

        //check if the recipient has a different email address specified in their messaging preferences Vs their user profile
        $emailmessagingpreference = get_user_preferences('message_processor_email_email', null, $eventdata->userto);
        if (!empty($emailmessagingpreference)) {
            //clone to avoid altering the actual user object
            $recipient = clone($eventdata->userto);
            $recipient->email = $emailmessagingpreference;
        } else {
            $recipient = $eventdata->userto;
        }
        $result = email_to_user($recipient, $eventdata->userfrom, $eventdata->subject, $eventdata->fullmessage, $eventdata->fullmessagehtml);

        return $result;
    }
Пример #12
0
 /**
  * Scan file, throws exception in case of infected file.
  *
  * @param string $file Full path to the file.
  * @param string $filename Name of the file (could be different from physical file if temp file is used).
  * @param bool $deleteinfected whether infected file needs to be deleted.
  * @throws moodle_exception If file is infected.
  * @return void
  */
 public function scan_file($file, $filename, $deleteinfected)
 {
     global $CFG;
     if (!is_readable($file)) {
         // This should not happen.
         debugging('File is not readable.');
         return;
     }
     // Execute the scan using preferable method.
     list($return, $notice) = $this->scan_file_execute_commandline($file);
     if ($return == 0) {
         // Perfect, no problem found, file is clean.
         return;
     } else {
         if ($return == 1) {
             // Infection found.
             if ($deleteinfected) {
                 unlink($file);
             }
             throw new \core\antivirus\scanner_exception('virusfounduser', '', array('filename' => $filename));
         } else {
             // Unknown problem.
             $this->message_admins($notice);
             if ($this->get_config('clamfailureonupload') === 'actlikevirus') {
                 if ($deleteinfected) {
                     unlink($file);
                 }
                 throw new \core\antivirus\scanner_exception('virusfounduser', '', array('filename' => $filename));
             } else {
                 return;
             }
         }
     }
 }
Пример #13
0
 /**
  * Returns the document associated with this post id.
  *
  * @param stdClass $record Post info.
  * @return \core_search\document
  */
 public function get_document($record)
 {
     try {
         $cm = $this->get_cm('forum', $record->forumid, $record->courseid);
         $context = \context_module::instance($cm->id);
     } catch (\dml_missing_record_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     } catch (\dml_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', $record->subject);
     $doc->set('content', content_to_text($record->message, $record->messageformat));
     $doc->set('contextid', $context->id);
     $doc->set('type', \core_search\manager::TYPE_TEXT);
     $doc->set('courseid', $record->courseid);
     $doc->set('userid', $record->userid);
     $doc->set('modified', $record->modified);
     return $doc;
 }
 function execute($finalelements, $data)
 {
     $filter_years = optional_param('filter_years', '', PARAM_RAW);
     if (!$filter_years) {
         return $finalelements;
     }
     if ($this->report->type != 'sql') {
         return array($filter_years);
     } else {
         $nYears = count($filter_years);
         if ($nYears > 1) {
             // Multiple years selected
             $aggYears = " REGEXP '";
             for ($i = 0; $i < $nYears; $i++) {
                 $aggYears .= $filter_years[$i] . "|";
             }
             $aggYears = rtrim($aggYears, '|');
             $aggYears .= "'";
         } else {
             // Single year selected
             $aggYears = " LIKE '%" . $filter_years[0] . "' ";
         }
         if (preg_match("/%%FILTER_YEARS:([^%]+)%%/i", $finalelements, $output)) {
             $replace = ' AND ' . $output[1] . $aggYears;
             $temp = str_replace('%%FILTER_YEARS:' . $output[1] . '%%', $replace, $finalelements);
             //echo '<div style="float:left;direction:ltr;">'.$temp.'</div><hr/>';
             debugging('<div style="float:left;direction:ltr;">' . $temp . '</div><hr/>', DEBUG_DEVELOPER);
             return $temp;
         }
     }
     return $finalelements;
 }
Пример #15
0
 /**
  * Translate human readable format name
  * into internal Moodle code number
  * @param string name format name from xml file
  * @return int Moodle format code
  */
 public function trans_format($name)
 {
     $name = trim($name);
     if ($name == 'moodle_auto_format') {
         return FORMAT_MOODLE;
     } else {
         if ($name == 'html') {
             return FORMAT_HTML;
         } else {
             if ($name == 'plain_text') {
                 return FORMAT_PLAIN;
             } else {
                 if ($name == 'wiki_like') {
                     return FORMAT_WIKI;
                 } else {
                     if ($name == 'markdown') {
                         return FORMAT_MARKDOWN;
                     } else {
                         debugging("Unrecognised text format '{$name}' in the import file. Assuming 'html'.");
                         return FORMAT_HTML;
                     }
                 }
             }
         }
     }
 }
Пример #16
0
 public function test_debugging()
 {
     global $CFG;
     $this->resetAfterTest();
     debugging('hokus');
     $this->assertDebuggingCalled();
     debugging('pokus');
     $this->assertDebuggingCalled('pokus');
     debugging('pokus', DEBUG_MINIMAL);
     $this->assertDebuggingCalled('pokus', DEBUG_MINIMAL);
     $this->assertDebuggingNotCalled();
     debugging('a');
     debugging('b', DEBUG_MINIMAL);
     debugging('c', DEBUG_DEVELOPER);
     $debuggings = $this->getDebuggingMessages();
     $this->assertCount(3, $debuggings);
     $this->assertSame('a', $debuggings[0]->message);
     $this->assertSame(DEBUG_NORMAL, $debuggings[0]->level);
     $this->assertSame('b', $debuggings[1]->message);
     $this->assertSame(DEBUG_MINIMAL, $debuggings[1]->level);
     $this->assertSame('c', $debuggings[2]->message);
     $this->assertSame(DEBUG_DEVELOPER, $debuggings[2]->level);
     $this->resetDebugging();
     $this->assertDebuggingNotCalled();
     $debuggings = $this->getDebuggingMessages();
     $this->assertCount(0, $debuggings);
     set_debugging(DEBUG_NONE);
     debugging('hokus');
     $this->assertDebuggingNotCalled();
     set_debugging(DEBUG_DEVELOPER);
 }
Пример #17
0
function scorm_report_list($context)
{
    global $CFG;
    static $reportlist;
    if (!empty($reportlist)) {
        return $reportlist;
    }
    $installed = core_component::get_plugin_list('scormreport');
    foreach ($installed as $reportname => $notused) {
        // Moodle 2.8+ style of autoloaded classes.
        $classname = "scormreport_{$reportname}\\report";
        if (class_exists($classname)) {
            $report = new $classname();
            if ($report->canview($context)) {
                $reportlist[] = $reportname;
            }
            continue;
        }
        // Legacy style of naming classes.
        $pluginfile = $CFG->dirroot . '/mod/scorm/report/' . $reportname . '/report.php';
        if (is_readable($pluginfile)) {
            debugging("Please use autoloaded classnames for your plugin. Refer MDL-46469 for details", DEBUG_DEVELOPER);
            include_once $pluginfile;
            $reportclassname = "scorm_{$reportname}_report";
            if (class_exists($reportclassname)) {
                $report = new $reportclassname();
                if ($report->canview($context)) {
                    $reportlist[] = $reportname;
                }
            }
        }
    }
    return $reportlist;
}
Пример #18
0
    /**
     * Processes the message (sends by email).
     * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
     */
    function send_message($eventdata) {
        global $CFG;

        if (!empty($CFG->noemailever)) {
            // hidden setting for development sites, set in config.php if needed
            debugging('$CFG->noemailever active, no email message sent.', DEBUG_MINIMAL);
            return true;
        }

        //hold onto email preference because /admin/cron.php sends a lot of messages at once
        static $useremailaddresses = array();

        //check user preference for where user wants email sent
        if (!array_key_exists($eventdata->userto->id, $useremailaddresses)) {
            $useremailaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_email_email', $eventdata->userto->email, $eventdata->userto->id);
        }
        $usertoemailaddress = $useremailaddresses[$eventdata->userto->id];

        if ( !empty($usertoemailaddress)) {
            $userto->email = $usertoemailaddress;
        }

        $result = email_to_user($eventdata->userto, $eventdata->userfrom,
            $eventdata->subject, $eventdata->fullmessage, $eventdata->fullmessagehtml);

        return $result;
    }
Пример #19
0
 /**
  * Returns the document associated with this course.
  *
  * @param stdClass $record
  * @param array    $options
  * @return \core_search\document
  */
 public function get_document($record, $options = array())
 {
     try {
         $context = \context_course::instance($record->id);
     } catch (\moodle_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', content_to_text($record->fullname, false));
     $doc->set('content', content_to_text($record->summary, $record->summaryformat));
     $doc->set('contextid', $context->id);
     $doc->set('courseid', $record->id);
     $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
     $doc->set('modified', $record->timemodified);
     $doc->set('description1', $record->shortname);
     // Check if this document should be considered new.
     if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) {
         // If the document was created after the last index time, it must be new.
         $doc->set_is_new(true);
     }
     return $doc;
 }
Пример #20
0
 function moodleform_mod($current, $section, $cm, $course)
 {
     global $CFG;
     $this->current = $current;
     $this->_instance = $current->instance;
     $this->_section = $section;
     $this->_cm = $cm;
     if ($this->_cm) {
         $this->context = context_module::instance($this->_cm->id);
     } else {
         $this->context = context_course::instance($course->id);
     }
     // Set the course format.
     require_once $CFG->dirroot . '/course/format/lib.php';
     $this->courseformat = course_get_format($course);
     // Guess module name
     $matches = array();
     if (!preg_match('/^mod_([^_]+)_mod_form$/', get_class($this), $matches)) {
         debugging('Use $modname parameter or rename form to mod_xx_mod_form, where xx is name of your module');
         print_error('unknownmodulename');
     }
     $this->_modname = $matches[1];
     $this->init_features();
     parent::moodleform('modedit.php');
 }
Пример #21
0
 /**
  * Returns the document associated with this activity.
  *
  * Overwriting base_activity method as page contents field is required,
  * description field is not.
  *
  * @param stdClass $record
  * @param array    $options
  * @return \core_search\document
  */
 public function get_document($record, $options = array())
 {
     try {
         $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
         $context = \context_module::instance($cm->id);
     } catch (\dml_missing_record_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     } catch (\dml_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', content_to_text($record->name, false));
     $doc->set('content', content_to_text($record->content, $record->contentformat));
     $doc->set('contextid', $context->id);
     $doc->set('courseid', $record->course);
     $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
     $doc->set('modified', $record->timemodified);
     $doc->set('description1', content_to_text($record->intro, $record->introformat));
     return $doc;
 }
Пример #22
0
 public static function restore_data($data, $restore)
 {
     $linknamestatus = $linkurlstatus = false;
     foreach ($data as $datum) {
         switch ($datum->name) {
             case 'linkname':
                 // We just want to know that it is there
                 $linknamestatus = true;
                 break;
             case 'linkurl':
                 $content = $datum->value;
                 $result = restore_decode_content_links_worker($content, $restore);
                 if ($result != $content) {
                     $datum->value = addslashes($result);
                     if (debugging() and !defined('RESTORE_SILENTLY')) {
                         echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                     }
                     $linkurlstatus = update_record('pagemenu_link_data', $datum);
                 } else {
                     $linkurlstatus = true;
                 }
                 break;
             default:
                 debugging('Deleting unknown data type: ' . $datum->name);
                 // Not recognized
                 delete_records('pagemenu_link_data', 'id', $datum->id);
                 break;
         }
     }
     return $linkurlstatus and $linknamestatus;
 }
Пример #23
0
/**
 * Reviews criteria and awards badges
 *
 * First find all badges that can be earned, then reviews each badge.
 * (Not sure how efficient this is timewise).
 */
function badge_review_cron()
{
    global $DB, $CFG;
    $total = 0;
    $courseparams = array();
    if (empty($CFG->badges_allowcoursebadges)) {
        $coursesql = '';
    } else {
        $coursesql = ' OR EXISTS (SELECT id FROM {course} WHERE visible = :visible AND startdate < :current) ';
        $courseparams = array('visible' => true, 'current' => time());
    }
    $sql = 'SELECT id
                FROM {badge}
                WHERE (status = :active OR status = :activelocked)
                    AND (type = :site ' . $coursesql . ')';
    $badgeparams = array('active' => BADGE_STATUS_ACTIVE, 'activelocked' => BADGE_STATUS_ACTIVE_LOCKED, 'site' => BADGE_TYPE_SITE);
    $params = array_merge($badgeparams, $courseparams);
    $badges = $DB->get_fieldset_sql($sql, $params);
    mtrace('Started reviewing available badges.');
    foreach ($badges as $bid) {
        $badge = new badge($bid);
        if ($badge->has_criteria()) {
            if (debugging()) {
                mtrace('Processing badge "' . $badge->name . '"...');
            }
            $issued = $badge->review_all_criteria();
            if (debugging()) {
                mtrace('...badge was issued to ' . $issued . ' users.');
            }
            $total += $issued;
        }
    }
    mtrace('Badges were issued ' . $total . ' time(s).');
}
 function execute($finalelements, $data)
 {
     $filter_categories = optional_param('filter_categories', 0, PARAM_INT);
     if (!$filter_categories) {
         return $finalelements;
     }
     if ($this->report->type != 'sql') {
         return array($filter_categories);
     } else {
         $nCategories = count($filter_categories);
         if ($nCategories > 1) {
             // Multiple categories selected
             $aggCategories = ' IN (';
             for ($i = 0; $i < $nCategories; $i++) {
                 $aggCategories .= $filter_categories[$i] . ",";
             }
             $aggCategories = rtrim($aggCategories, ',');
             $aggCategories .= ') ';
         } else {
             // Single category selected
             $aggCategories = ' = ' . $filter_categories[0];
         }
         if (preg_match("/%%FILTER_CATEGORIES:([^%]+)%%/i", $finalelements, $output)) {
             $replace = ' AND ' . $output[1] . $aggCategories;
             $temp = str_replace('%%FILTER_CATEGORIES:' . $output[1] . '%%', $replace, $finalelements);
             //echo '<div style="float:left;direction:ltr;">'.$temp.'</div><hr/>';
             debugging('<div style="float:left;direction:ltr;">' . $temp . '</div><hr/>', DEBUG_DEVELOPER);
             return $temp;
         }
     }
     return $finalelements;
 }
Пример #25
0
 /**
  * Set the specific questions to export. Should not include questions with
  * parents (sub questions of cloze question type).
  * Only used for question export.
  * @param array of question objects
  */
 function setQuestions($questions)
 {
     if ($this->category !== null) {
         debugging('You shouldn\'t call setQuestions after setCategory');
     }
     $this->questions = $questions;
 }
 /**
  * Custom validation.
  *
  * @throws \coding_exception
  * @return void
  */
 protected function validate_data()
 {
     parent::validate_data();
     if (!isset($this->relateduserid)) {
         debugging('The \'relateduserid\' value must be specified in the event.', DEBUG_DEVELOPER);
         $this->relateduserid = $this->objectid;
     }
 }
Пример #27
0
 /**
  * Register self as main shutdown handler.
  *
  * @private to be called from lib/setup.php only!
  */
 public static function initialize()
 {
     if (self::$registered) {
         debugging('Shutdown manager is already initialised!');
     }
     self::$registered = true;
     register_shutdown_function(array('core_shutdown_manager', 'shutdown_handler'));
 }
Пример #28
0
/**
 * This helper function returns a sequence of colours each time it is called.
 * Used for choosing colours for graph data series.
 * @return string colour name.
 * @deprecated since Moodle 3.2
 */
function quiz_statistics_graph_get_new_colour()
{
    debugging('The function quiz_statistics_graph_get_new_colour() is deprecated, please do not use it any more. ' . 'Colours will be handled by the charting library directly.', DEBUG_DEVELOPER);
    static $colourindex = -1;
    $colours = array('red', 'green', 'yellow', 'orange', 'purple', 'black', 'maroon', 'blue', 'ltgreen', 'navy', 'ltred', 'ltltgreen', 'ltltorange', 'olive', 'gray', 'ltltred', 'ltorange', 'lime', 'ltblue', 'ltltblue');
    $colourindex = ($colourindex + 1) % count($colours);
    return $colours[$colourindex];
}
Пример #29
0
 function setAttributes($type, $precision = null, $unsigned = null, $notnull = null, $sequence = null, $enum = null, $enumvalues = null, $default = null, $previous = null)
 {
     debugging('XMLDBField->setAttributes() has been deprecated in Moodle 2.0. Will be out in Moodle 2.1. Please use xmldb_field->set_attributes() instead.', DEBUG_DEVELOPER);
     if ($enum) {
         debugging('Also, ENUMs support has been dropped in Moodle 2.0. Your fields specs are incorrect because you are trying to introduce one new ENUM. Created DB estructures will ignore that.');
     }
     return $this->set_attributes($type, $precision, $unsigned, $notnull, $sequence, $default, $previous);
 }
Пример #30
0
 /**
  * Magic method getter, redirects to read only values.
  *
  * For block plugins pretends the object has 'visible' property for compatibility
  * with plugins developed for Moodle version below 2.4
  *
  * @param string $name
  * @return mixed
  */
 public function __get($name)
 {
     if ($name === 'visible') {
         debugging('This is now an instance of plugininfo_block, please use $block->is_enabled() instead of $block->visible', DEBUG_DEVELOPER);
         return $this->is_enabled() !== false;
     }
     return parent::__get($name);
 }