public function notification($message, $classes = 'notifyproblem')
 {
     $message = clean_text($message);
     if ($classes == 'notifyproblem') {
         return html_writer::div($message, 'alert alert-danger');
     }
     if ($classes == 'notifywarning') {
         return html_writer::div($message, 'alert alert-warning');
     }
     if ($classes == 'notifysuccess') {
         return html_writer::div($message, 'alert alert-success');
     }
     if ($classes == 'notifymessage') {
         return html_writer::div($message, 'alert alert-info');
     }
     if ($classes == 'redirectmessage') {
         return html_writer::div($message, 'alert alert-block alert-info');
     }
     return html_writer::div($message, $classes);
 }
Пример #2
0
 function edit_load_user_data($user)
 {
     if ($this->data !== NULL) {
         $this->data = clean_text($this->data, $this->dataformat);
         $user->{$this->inputname} = array('text' => $this->data, 'format' => $this->dataformat);
     }
 }
Пример #3
0
function block_advance_print_page($advance, $return = false)
{
    //add page title
    global $OUTPUT, $COURSE;
    $display = $OUTPUT->heading($advance->pagetitle);
    $display .= $OUTPUT->box_start();
    //date display
    if ($advance->displaydate) {
        $display .= html_writer::start_tag('div', array('class' => 'advance displaydate'));
        $display .= userdate($advance->displaydate);
        $display .= html_writer::end_tag('div');
    }
    //display text
    $display .= clean_text($advance->displaytext);
    //close the box
    $display .= $OUTPUT->box_end();
    //display picture
    if ($advance->displaypicture) {
        $display .= $OUTPUT->box_start();
        $images = block_advance_images();
        $display .= $images[$advance->picture];
        $display .= html_writer::start_tag('p');
        $display .= clean_text($advance->description);
        $display .= html_writer::end_tag('p');
        $display .= $OUTPUT->box_end();
    }
    //display it
    if ($return) {
        return $display;
    } else {
        echo $display;
    }
}
Пример #4
0
 function gen_textarea($usehtmleditor, $text = '')
 {
     // MDL-16018: Don't print htmlarea with < 7 lines height, causes visualization problem
     $text = clean_text($text);
     $this->field->param3 = $usehtmleditor && $this->field->param3 < 7 ? 7 : $this->field->param3;
     return print_textarea($usehtmleditor, $this->field->param3, $this->field->param2, '', '', 'field_' . $this->field->id, $text, '', true, 'field_' . $this->field->id);
 }
Пример #5
0
function block_campusclash_print_page($campusclash, $return = false)
{
    //Add Page Title
    global $OUTPUT, $COURSE;
    $display = $OUTPUT->heading($campusclash->pagetitle);
    //Open a box
    $display .= $OUTPUT->box_start();
    //Display the Date
    if ($campusclash->displaydate) {
        $display .= html_writer::start_tag('div', array('class' => 'displaydate'));
        $display .= userdate($campusclash->displaydate);
        $display .= html_writer::end_tag('div');
    }
    //Display Text
    $display .= clean_text($campusclash->displaytext);
    //close the box
    $display .= $OUTPUT->box_end();
    //Display the Picture
    if ($campusclash->displaypicture) {
        $display .= $OUTPUT->box_start();
        $images = block_campusclash_images();
        $display .= $images[$campusclash->picture];
        $display .= html_writer::start_tag('p');
        $display .= clean_text($campusclash->description);
        $display .= html_writer::end_tag('p');
        $display .= $OUTPUT->box_end();
    }
    //Check to ensure that it was set before trying to output it
    if ($return) {
        return $display;
    } else {
        echo $display;
    }
}
Пример #6
0
 protected function display_response_choice_results($rows, $rids, $sort)
 {
     if (is_array($rids)) {
         $prtotal = 1;
     } else {
         if (is_int($rids)) {
             $prtotal = 0;
         }
     }
     if ($rows) {
         foreach ($rows as $idx => $row) {
             if (strpos($idx, 'other') === 0) {
                 $answer = $row->response;
                 $ccontent = $row->content;
                 $content = preg_replace(array('/^!other=/', '/^!other/'), array('', get_string('other', 'questionnaire')), $ccontent);
                 $content .= ' ' . clean_text($answer);
                 $textidx = $content;
                 $this->counts[$textidx] = !empty($this->counts[$textidx]) ? $this->counts[$textidx] + 1 : 1;
             } else {
                 $contents = questionnaire_choice_values($row->content);
                 $this->choice = $contents->text . $contents->image;
                 $textidx = $this->choice;
                 $this->counts[$textidx] = !empty($this->counts[$textidx]) ? $this->counts[$textidx] + 1 : 1;
             }
         }
         \mod_questionnaire\response\display_support::mkrespercent($this->counts, count($rids), $this->question->precise, $prtotal, $sort);
     } else {
         echo '<p class="generaltable">&nbsp;' . get_string('noresponsedata', 'questionnaire') . '</p>';
     }
 }
 function edit_load_course_data(&$course)
 {
     if ($this->data !== NULL) {
         $this->data = clean_text($this->data, $this->dataformat);
         $course->{$this->inputname} = array('text' => $this->data, 'format' => $this->dataformat);
     }
 }
Пример #8
0
 public function display_results($rids = false, $sort = '')
 {
     if (is_array($rids)) {
         $prtotal = 1;
     } else {
         if (is_int($rids)) {
             $prtotal = 0;
         }
     }
     if ($rows = $this->get_results($rids)) {
         // Count identical answers (numeric questions only).
         foreach ($rows as $row) {
             if (!empty($row->response) || $row->response === "0") {
                 $this->text = $row->response;
                 $textidx = clean_text($this->text);
                 $this->counts[$textidx] = !empty($this->counts[$textidx]) ? $this->counts[$textidx] + 1 : 1;
                 $this->userid[$textidx] = !empty($this->counts[$textidx]) ? $this->counts[$textidx] + 1 : 1;
             }
         }
         $isnumeric = $this->question->type_id == QUESNUMERIC;
         if ($isnumeric) {
             \mod_questionnaire\response\display_support::mkreslistnumeric($this->counts, count($rids), $this->question->precise);
         } else {
             \mod_questionnaire\response\display_support::mkreslisttext($rows);
         }
     } else {
         echo '<p class="generaltable">&nbsp;' . get_string('noresponsedata', 'questionnaire') . '</p>';
     }
 }
Пример #9
0
 public function display_results($rids = false, $sort = '')
 {
     if (is_array($rids)) {
         $prtotal = 1;
     } else {
         if (is_int($rids)) {
             $prtotal = 0;
         }
     }
     if ($rows = $this->get_results($rids)) {
         foreach ($rows as $row) {
             // Count identical answers (case insensitive).
             $this->text = $row->response;
             if (!empty($this->text)) {
                 $dateparts = preg_split('/-/', $this->text);
                 $this->text = make_timestamp($dateparts[0], $dateparts[1], $dateparts[2]);
                 // Unix timestamp.
                 $textidx = clean_text($this->text);
                 $this->counts[$textidx] = !empty($this->counts[$textidx]) ? $this->counts[$textidx] + 1 : 1;
             }
         }
         \mod_questionnaire\response\display_support::mkreslistdate($this->counts, count($rids), $this->question->precise, $prtotal);
     } else {
         echo '<p class="generaltable">&nbsp;' . get_string('noresponsedata', 'questionnaire') . '</p>';
     }
 }
Пример #10
0
/**
 * Print a message along with "Ok" link for the user to continue and "Cancel" link to close window.
 *
 * @param string $message The text to display
 * @param string $linkok The link to take the user to if they choose "Ok"
 * TODO Document remaining arguments
 */
function notice_okcancel($message, $linkok, $optionsok = NULL, $methodok = 'post')
{
    global $CFG;
    $message = clean_text($message);
    $linkok = clean_text($linkok);
    print_box_start('generalbox', 'notice');
    echo '<p>' . $message . '</p>';
    echo '<div class="buttons">';
    print_single_button($linkok, $optionsok, get_string('ok'), $methodok, $CFG->framename);
    close_window_button('cancel');
    echo '</div>';
    print_box_end();
}
Пример #11
0
function save_comment()
{
    global $link, $db, $comment, $current_user, $globals, $site_key;
    if (intval($_POST['id']) == $comment->id && $current_user->authenticated && (intval($_POST['user_id']) == $current_user->user_id && $current_user->user_id == $comment->author && time() - $comment->date < $globals['comment_edit_time'] * 1.1 || $current_user->user_level == 'god' && time() - $comment->date < 10800) && $_POST['key'] == md5($comment->randkey . $site_key) && strlen(trim($_POST['comment_content'])) > 2) {
        $comment->content = clean_text($_POST['comment_content'], 0, false, 10000);
        if (strlen($comment->content) > 0) {
            $comment->store();
        }
        header('Location: ' . $link->get_permalink() . '#comment-' . $comment->order);
        die;
    } else {
        echo _('el cabal te castigará');
        die;
    }
}
function update_userinfo($userid, $info)
{
    $returnarray = array('status' => 500, 'content' => 'Update info fail!');
    $userdata = json_decode($info);
    $full_name = clean_text($userdata->{'fullname'});
    $id_pwc = (int) clean_text($userdata->{'pcid'});
    $pcname = clean_text($userdata->{'pcname'});
    $id_investor = (int) clean_text($userdata->{'investorid'});
    $id_sub = (int) clean_text($userdata->{'subid'});
    //$password = clean_text($userdata ->{'password'});
    $office_name = clean_text($userdata->{'officename'});
    //$department_name = clean_text($userdata ->{'fullname'});
    $phone_number = clean_text($userdata->{'phone'});
    $email = clean_text($userdata->{'email'});
    $enable = (int) clean_text($userdata->{'enable'});
    $last_visit = clean_text($userdata->{'lastvisit'});
    $visit_number = (int) clean_text($userdata->{'visitnumber'});
    $register_date = clean_text($userdata->{'regdate'});
    $permission = clean_text($userdata->{'permission'});
    $writable = (int) clean_text($userdata->{'writable'});
    $usertype = (int) clean_text($userdata->{'usertype'});
    $editable = (int) clean_text($userdata->{'editable'});
    //die ($permission);
    $sql = 'UPDATE `user` 
				SET `id_pwc`=' . $id_pwc . ',`id_investor`=' . $id_investor . ',
				`id_sub`=' . $id_sub . ',`full_name`="' . $full_name . '",
				`office_name`="' . $office_name . '",`phone_number`="' . $phone_number . '",
				`email`="' . $email . '",`enable`=' . $enable . ',`last_visit`="' . $last_visit . '",`visit_number`=' . $visit_number . ',
				`register_date`="' . $register_date . '",`permission`="' . $permission . '",
				`writable`=' . $writable . ',`usertype`=' . $usertype . ',`editable`=' . $editable . ',`flag_change`=1 
				WHERE `ID`=' . $userid;
    // $sql = 'UPDATE `user`
    // 		SET `usergroup`=1,`id_pwc`=1,`id_investor`=1,
    // 		`id_sub`=1,`full_name`="Quốc Đông",`user_name`="quocdong",`password`="202cb962ac59075b964b07152d234b70",
    // 		`office_name`="npc",`department_name`="tdh",`phone_number`="0936668484",
    // 		`email`="*****@*****.**",`enable`=1,`last_visit`="02/04/14 10:55:37",`visit_number`=111,
    // 		`register_date`="02/04/14 10:55:37",`currentpos`="",`token`="03224b341e0ab7c5a2",`permission`="",
    // 		`writable`=1,`usertype`=1,`editable`=1,`cache`=1,
    // 		`cacheall`="",`flag_change`=1,`phongban`="tdh"
    // 		WHERE `ID`='.$userid;
    $result = mysql_query($sql) or die(json_encode($returnarray));
    $returnarray = array('status' => 200, 'content' => 'Update info succesfully!');
    $actioncode = 21;
    //update user info profile
    $moredetail = 'update userid : ' . $id;
    useradminlogs($userid, $actioncode, $moredetail);
    echo json_encode($returnarray);
}
Пример #13
0
    /**
     * This renders a notification message.
     * Uses bootstrap compatible html.
     * @param string $message
     * @param string $class
     * @return string $notification
     */
    public function notification($message, $class = 'notifyproblem') {
        $message = clean_text($message);
        $type = '';

        if ($class == 'notifyproblem') {
            $type = 'alert alert-error';
        } else if ($class == 'notifysuccess') {
            $type = 'alert alert-success';
        } else if ($class == 'notifymessage') {
            $type = 'alert alert-info';
        } else if ($class == 'redirectmessage') {
            $type = 'alert alert-block alert-info';
        }
        $notification = "<div class=\"$type\">$message</div>";
        return $notification;
    }
Пример #14
0
 function display_add_field($recordid = 0)
 {
     global $CFG, $DB, $OUTPUT, $PAGE;
     $text = '';
     $format = 0;
     $str = '<div title="' . $this->field->description . '">';
     editors_head_setup();
     $options = array();
     $options['trusttext'] = false;
     $options['forcehttps'] = false;
     $options['subdirs'] = false;
     $options['maxfiles'] = 0;
     $options['maxbytes'] = 0;
     $options['changeformat'] = 0;
     $options['noclean'] = false;
     $itemid = $this->field->id;
     $field = 'field_' . $itemid;
     if ($recordid && ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) {
         $text = $content->content;
         $format = $content->content1;
         $text = clean_text($text, $format);
     } else {
         if (can_use_html_editor()) {
             $format = FORMAT_HTML;
         } else {
             $format = FORMAT_PLAIN;
         }
     }
     $editor = editors_get_preferred_editor($format);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     $editor->use_editor($field, $options);
     $str .= '<div><textarea id="' . $field . '" name="' . $field . '" rows="' . $this->field->param3 . '" cols="' . $this->field->param2 . '">' . s($text) . '</textarea></div>';
     $str .= '<div><select name="' . $field . '_content1">';
     foreach ($formats as $key => $desc) {
         $selected = $format == $key ? 'selected="selected"' : '';
         $str .= '<option value="' . s($key) . '" ' . $selected . '>' . $desc . '</option>';
     }
     $str .= '</select>';
     $str .= '</div>';
     $str .= '</div>';
     return $str;
 }
 public function notification($message, $classes = 'notifyproblem')
 {
     $message = clean_text($message);
     $type = '';
     if ($classes == 'notifyproblem') {
         $type = 'alert alert-error';
     }
     if ($classes == 'notifysuccess') {
         $type = 'alert alert-success';
     }
     if ($classes == 'notifymessage') {
         $type = 'alert alert-info';
     }
     if ($classes == 'redirectmessage') {
         $type = 'alert alert-block alert-info';
     }
     return "<div class=\"{$type}\">{$message}</div>";
 }
Пример #16
0
 function display_add_field($recordid = 0)
 {
     global $CFG, $DB, $OUTPUT, $PAGE, $USER;
     $text = '';
     $format = 0;
     $str = '<div title="' . $this->field->description . '">';
     editors_head_setup();
     $options = $this->get_options();
     $itemid = $this->field->id;
     $field = 'field_' . $itemid;
     if ($recordid && ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) {
         $format = $content->content1;
         $text = clean_text($content->content, $format);
         $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text);
     } else {
         $draftitemid = file_get_unused_draft_itemid();
     }
     $updatecontrol = $field;
     $idcontrol = $field . '_itemid';
     $str .= '<input type="hidden" id="' . $updatecontrol . '" name="' . $updatecontrol . '" value="empty" />';
     $str .= '<input type="hidden"  name="' . $idcontrol . '" value="' . $draftitemid . '" />';
     // $type = DBP_AUDIOMP3;
     $usercontextid = context_user::instance($USER->id)->id;
     switch ($this->field->param4) {
         case DBP_AUDIO:
             $str .= fetchAudioRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid);
             break;
         case DBP_VIDEO:
             $str .= fetchVideoRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid);
             break;
         case DBP_AUDIOMP3:
             $str .= fetchMP3RecorderForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid);
             break;
         case DBP_WHITEBOARDSIMPLE:
         case DBP_WHITEBOARDFULL:
             $str .= fetchWhiteboardForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid);
             break;
         case DBP_SNAPSHOT:
             $str .= fetchSnapshotCameraForSubmission($updatecontrol, 'apic.jpg', 350, 400, $usercontextid, "user", "draft", $draftitemid);
             break;
     }
     return $str;
 }
function csverror($message, $link = '')
{
    global $CFG, $SESSION;
    print_header(get_string('error'));
    echo '<br />';
    $message = clean_text($message);
    print_simple_box('<span style="font-family:monospace;color:#000000;">' . $message . '</span>', 'center', '', '#FFBBBB', 5, 'errorbox');
    if (!$link) {
        if (!empty($SESSION->fromurl)) {
            $link = $SESSION->fromurl;
            unset($SESSION->fromurl);
        } else {
            $link = $CFG->wwwroot . '/';
        }
    }
    print_continue($link);
    print_footer();
    die;
}
function update_userinfo($userid, $info)
{
    $returnarray = array('status' => 500, 'content' => 'Create new user fail!');
    $userdata = json_decode($info);
    $full_name = clean_text($userdata->{'fullname'});
    $id_pwc = (int) clean_text($userdata->{'pcid'});
    $pcname = clean_text($userdata->{'pcname'});
    $id_investor = (int) clean_text($userdata->{'investorid'});
    $id_sub = (int) clean_text($userdata->{'subid'});
    $user_name = clean_text($userdata->{'username'});
    $password = clean_text($userdata->{'password'});
    $office_name = clean_text($userdata->{'officename'});
    //$department_name = clean_text($userdata ->{'fullname'});
    $phone_number = clean_text($userdata->{'phone'});
    $email = clean_text($userdata->{'email'});
    $enable = (int) clean_text($userdata->{'enable'});
    $last_visit = clean_text($userdata->{'lastvisit'});
    $visit_number = (int) clean_text($userdata->{'visitnumber'});
    $register_date = clean_text($userdata->{'regdate'});
    $permission = clean_text($userdata->{'permission'});
    $writable = (int) clean_text($userdata->{'writable'});
    $usertype = (int) clean_text($userdata->{'usertype'});
    $editable = (int) clean_text($userdata->{'editable'});
    $register_date = date("d/m/y H:i:s");
    $currentpos = 'csdl,csct,0,60,96471056,MK,';
    $sql = 'INSERT INTO `user` (`id_pwc`, `id_investor`, `id_sub`, `full_name`, `user_name`, `password`, 
                            `office_name`, `phone_number`, `email`, `currentpos`, `enable`, `register_date`, `permission`, 
                            `writable`, 
                            `usertype`, `editable`, `flag_change`) 
                VALUES (' . $id_pwc . ',' . $id_investor . ',' . $id_sub . ',"' . $full_name . '","' . $user_name . '",
                        "' . MD5($password) . '","' . $office_name . '", "' . $phone_number . '","' . $email . '","' . $currentpos . '",
                        ' . $enable . ',"' . $register_date . '","' . $permission . '", ' . $writable . ',' . $usertype . ',' . $editable . ', 1)';
    $result = mysql_query($sql) or die(json_encode($returnarray));
    $returnarray = array('status' => 200, 'content' => 'Create new user info succesfully!');
    $actioncode = 22;
    //create new user info profile
    $moredetail = 'create username : ' . $user_name;
    useradminlogs($userid, $actioncode, $moredetail);
    echo json_encode($returnarray);
}
Пример #19
0
 public function notification($message, $classes = 'notifyproblem')
 {
     $message = clean_text($message);
     if ($classes == 'notifyproblem') {
         return html_writer::div($message, 'alert alert-danger');
     }
     if ($classes == 'notifywarning') {
         return html_writer::div($message, 'alert alert-warning');
     }
     if ($classes == 'notifysuccess') {
         return html_writer::div($message, 'alert alert-success');
     }
     if ($classes == 'notifymessage') {
         return html_writer::div($message, 'alert alert-info');
     }
     if ($classes == 'redirectmessage') {
         return html_writer::div($message, 'alert alert-block alert-info');
     }
     if ($classes == 'notifytiny') {
         // Not an appropriate semantic alert class!
         return $this->debug_listing($message);
     }
     return html_writer::div($message, $classes);
 }
Пример #20
0
function atom_add_items($items)
{
    global $CFG;
    $result = '';
    $xhtmlattr = array('type' => 'xhtml');
    if (!empty($items)) {
        foreach ($items as $item) {
            $result .= atom_start_tag('entry', 1, true);
            $result .= atom_full_tag('title', 2, false, htmlspecialchars(html_to_text($item->title)));
            $result .= atom_full_tag('link', 2, false, null, array('href' => $item->link, 'rel' => 'alternate'));
            $result .= atom_full_tag('updated', 2, false, date_format_rfc3339($item->pubdate));
            //Include the author if exists
            if (isset($item->author)) {
                $result .= atom_start_tag('author', 2, true);
                $result .= atom_full_tag('name', 3, false, $item->author);
                $result .= atom_end_tag('author', 2, true);
            }
            $result .= atom_full_tag('content', 2, false, '<div xmlns="http://www.w3.org/1999/xhtml">' . clean_text($item->description, FORMAT_HTML) . '</div>', $xhtmlattr);
            $result .= atom_full_tag('id', 2, false, $item->link);
            if (isset($item->tags)) {
                $tagdata = array();
                if (isset($item->tagscheme)) {
                    $tagdata['scheme'] = $item->tagscheme;
                }
                foreach ($item->tags as $tag) {
                    $tagdata['term'] = $tag;
                    $result .= atom_full_tag('category', 2, true, false, $tagdata);
                }
            }
            $result .= atom_end_tag('entry', 1, true);
        }
    } else {
        $result = false;
    }
    return $result;
}
Пример #21
0
function get_ldap($uid, $pw)
{
    // After connecting, you have to set the version to 3.
    $ldap = ldap_connect('geniusroom.local');
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    // Searches based on the entered username and then stores the user info.
    // This works best if the UID passed is "cleaned" via the function above.
    $search = ldap_search($ldap, 'cn=users,dc=geniusroom,dc=local', 'uid=' . clean_text($uid));
    $info = ldap_get_entries($ldap, $search);
    // In order to bind properly, the "distinguished name" (DN) is needed.
    // This gets the DN and then tries to bind with the supplied password.
    // Getting the DN is redundant in *most* cases, but not all.
    $person = ldap_first_entry($ldap, $search);
    $dn = ldap_get_dn($ldap, $person);
    $bind = ldap_bind($ldap, $dn, $pw);
    // If the bind was successful, that means the user authenticated properly.
    // The "relative distinguished name" (CN) is the employee's proper name.
    // NOTE: The 'else' line below can be uncommented for guaranteed login.
    #if( $bind ) { return $info[0]['cn'][0]; }
    #else { return 'WYWO Developer'; }
    if ($bind) {
        return $info;
    }
}
Пример #22
0
/**
 * Returns detailed information about specified exception.
 * @param exception $ex
 * @return object
 */
function get_exception_info($ex)
{
    global $CFG, $DB, $SESSION;
    if ($ex instanceof moodle_exception) {
        $errorcode = $ex->errorcode;
        $module = $ex->module;
        $a = $ex->a;
        $link = $ex->link;
        $debuginfo = $ex->debuginfo;
    } else {
        $errorcode = 'generalexceptionmessage';
        $module = 'error';
        $a = $ex->getMessage();
        $link = '';
        $debuginfo = '';
    }
    // Append the error code to the debug info to make grepping and googling easier
    $debuginfo .= PHP_EOL . "Error code: {$errorcode}";
    $backtrace = $ex->getTrace();
    $place = array('file' => $ex->getFile(), 'line' => $ex->getLine(), 'exception' => get_class($ex));
    array_unshift($backtrace, $place);
    // Be careful, no guarantee moodlelib.php is loaded.
    if (empty($module) || $module == 'moodle' || $module == 'core') {
        $module = 'error';
    }
    // Search for the $errorcode's associated string
    // If not found, append the contents of $a to $debuginfo so helpful information isn't lost
    if (function_exists('get_string_manager')) {
        if (get_string_manager()->string_exists($errorcode, $module)) {
            $message = get_string($errorcode, $module, $a);
        } elseif ($module == 'error' && get_string_manager()->string_exists($errorcode, 'moodle')) {
            // Search in moodle file if error specified - needed for backwards compatibility
            $message = get_string($errorcode, 'moodle', $a);
        } else {
            $message = $module . '/' . $errorcode;
            $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true);
        }
    } else {
        $message = $module . '/' . $errorcode;
        $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true);
    }
    // Be careful, no guarantee weblib.php is loaded.
    if (function_exists('clean_text')) {
        $message = clean_text($message);
    } else {
        $message = htmlspecialchars($message);
    }
    if (!empty($CFG->errordocroot)) {
        $errordoclink = $CFG->errordocroot . '/en/';
    } else {
        $errordoclink = get_docs_url();
    }
    if ($module === 'error') {
        $modulelink = 'moodle';
    } else {
        $modulelink = $module;
    }
    $moreinfourl = $errordoclink . 'error/' . $modulelink . '/' . $errorcode;
    if (empty($link)) {
        if (!empty($SESSION->fromurl)) {
            $link = $SESSION->fromurl;
            unset($SESSION->fromurl);
        } else {
            $link = $CFG->wwwroot . '/';
        }
    }
    // when printing an error the continue button should never link offsite
    if (stripos($link, $CFG->wwwroot) === false && stripos($link, $CFG->httpswwwroot) === false) {
        $link = $CFG->wwwroot . '/';
    }
    $info = new stdClass();
    $info->message = $message;
    $info->errorcode = $errorcode;
    $info->backtrace = $backtrace;
    $info->link = $link;
    $info->moreinfourl = $moreinfourl;
    $info->a = $a;
    $info->debuginfo = $debuginfo;
    return $info;
}
Пример #23
0
    print_error('noguestentry', 'blog');
}
if (!has_capability('moodle/blog:create', $sitecontext) && !has_capability('moodle/blog:manageentries', $sitecontext)) {
    print_error('cannoteditentryorblog');
}
// Make sure that the person trying to edit has access right
if ($id) {
    if (!($entry = new blog_entry($id))) {
        print_error('wrongentryid', 'blog');
    }
    if (!blog_user_can_edit_entry($entry)) {
        print_error('notallowedtoedit', 'blog');
    }
    $userid = $entry->userid;
    $entry->subject = clean_text($entry->subject);
    $entry->summary = clean_text($entry->summary, $entry->format);
} else {
    if (!has_capability('moodle/blog:create', $sitecontext)) {
        print_error('noentry', 'blog');
        // manageentries is not enough for adding
    }
    $entry = new stdClass();
    $entry->id = null;
    $userid = $USER->id;
}
$returnurl->param('userid', $userid);
// Blog renderer.
$output = $PAGE->get_renderer('blog');
$strblogs = get_string('blogs', 'blog');
if ($action === 'delete') {
    if (empty($entry->id)) {
Пример #24
0
/**
 * Redirects the user to another page, after printing a notice
 *
 * This function calls the OUTPUT redirect method, echo's the output
 * and then dies to ensure nothing else happens.
 *
 * <strong>Good practice:</strong> You should call this method before starting page
 * output by using any of the OUTPUT methods.
 *
 * @param moodle_url|string $url A moodle_url to redirect to. Strings are not to be trusted!
 * @param string $message The message to display to the user
 * @param int $delay The delay before redirecting
 * @return void - does not return!
 */
function redirect($url, $message = '', $delay = -1)
{
    global $OUTPUT, $PAGE, $SESSION, $CFG;
    if (CLI_SCRIPT or AJAX_SCRIPT) {
        // this is wrong - developers should not use redirect in these scripts,
        // but it should not be very likely
        throw new moodle_exception('redirecterrordetected', 'error');
    }
    // prevent debug errors - make sure context is properly initialised
    if ($PAGE) {
        $PAGE->set_context(null);
    }
    if ($url instanceof moodle_url) {
        $url = $url->out(false);
    }
    if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) {
        $url = $SESSION->sid_process_url($url);
    }
    $debugdisableredirect = false;
    do {
        if (defined('DEBUGGING_PRINTED')) {
            // some debugging already printed, no need to look more
            $debugdisableredirect = true;
            break;
        }
        if (empty($CFG->debugdisplay) or empty($CFG->debug)) {
            // no errors should be displayed
            break;
        }
        if (!function_exists('error_get_last') or !($lasterror = error_get_last())) {
            break;
        }
        if (!($lasterror['type'] & $CFG->debug)) {
            //last error not interesting
            break;
        }
        // watch out here, @hidden() errors are returned from error_get_last() too
        if (headers_sent()) {
            //we already started printing something - that means errors likely printed
            $debugdisableredirect = true;
            break;
        }
        if (ob_get_level() and ob_get_contents()) {
            // there is something waiting to be printed, hopefully it is the errors,
            // but it might be some error hidden by @ too - such as the timezone mess from setup.php
            $debugdisableredirect = true;
            break;
        }
    } while (false);
    if (!empty($message)) {
        if ($delay === -1 || !is_numeric($delay)) {
            $delay = 3;
        }
        $message = clean_text($message);
    } else {
        $message = get_string('pageshouldredirect');
        $delay = 0;
        // We are going to try to use a HTTP redirect, so we need a full URL.
        if (!preg_match('|^[a-z]+:|', $url)) {
            // Get host name http://www.wherever.com
            $hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot);
            if (preg_match('|^/|', $url)) {
                // URLs beginning with / are relative to web server root so we just add them in
                $url = $hostpart . $url;
            } else {
                // URLs not beginning with / are relative to path of current script, so add that on.
                $url = $hostpart . preg_replace('|\\?.*$|', '', me()) . '/../' . $url;
            }
            // Replace all ..s
            while (true) {
                $newurl = preg_replace('|/(?!\\.\\.)[^/]*/\\.\\./|', '/', $url);
                if ($newurl == $url) {
                    break;
                }
                $url = $newurl;
            }
        }
    }
    if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
        if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) {
            $perf = get_performance_info();
            error_log("PERF: " . $perf['txt']);
        }
    }
    $encodedurl = preg_replace("/\\&(?![a-zA-Z0-9#]{1,8};)/", "&amp;", $url);
    $encodedurl = preg_replace('/^.*href="([^"]*)".*$/', "\\1", clean_text('<a href="' . $encodedurl . '" />'));
    if ($delay == 0 && !$debugdisableredirect && !headers_sent()) {
        // workaround for IIS bug http://support.microsoft.com/kb/q176113/
        if (session_id()) {
            session_get_instance()->write_close();
        }
        //302 might not work for POST requests, 303 is ignored by obsolete clients.
        @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other');
        @header('Location: ' . $url);
        echo bootstrap_renderer::plain_redirect_message($encodedurl);
        exit;
    }
    // Include a redirect message, even with a HTTP redirect, because that is recommended practice.
    $PAGE->set_pagelayout('redirect');
    // No header and footer needed
    $CFG->docroot = false;
    // to prevent the link to moodle docs from being displayed on redirect page.
    echo $OUTPUT->redirect_message($encodedurl, $message, $delay, $debugdisableredirect);
    exit;
}
Пример #25
0
function insert_comment()
{
    global $link, $db, $current_user, $globals;
    $error = '';
    require_once mnminclude . 'ban.php';
    if (check_ban_proxy()) {
        return _('dirección IP no permitida');
    }
    // Check if is a POST of a comment
    if ($link->votes > 0 && $link->date > $globals['now'] - $globals['time_enabled_comments'] && $link->comments < $globals['max_comments'] && intval($_POST['link_id']) == $link->id && $current_user->authenticated && intval($_POST['user_id']) == $current_user->user_id && ($current_user->user_karma > $globals['min_karma_for_comments'] || $current_user->user_id == $link->author) && intval($_POST['randkey']) > 0 && mb_strlen(trim($_POST['comment_content'])) > 2) {
        require_once mnminclude . 'comment.php';
        $comment = new Comment();
        $comment->link = $link->id;
        $comment->randkey = intval($_POST['randkey']);
        $comment->author = intval($_POST['user_id']);
        $comment->karma = round($current_user->user_karma);
        $comment->content = clean_text($_POST['comment_content'], 0, false, 10000);
        // Check if is an admin comment
        if ($current_user->user_level == 'god' && $_POST['type'] == 'admin') {
            $comment->karma = 20;
            $comment->type = 'admin';
        }
        if (mb_strlen($comment->content) > 0 && preg_match('/[a-zA-Z:-]/', $_POST['comment_content'])) {
            // Check there are at least a valid char
            $already_stored = intval($db->get_var("select count(*) from comments where comment_link_id = {$comment->link} and comment_user_id = {$comment->author} and comment_randkey = {$comment->randkey}"));
            // Check the comment wasn't already stored
            if (!$already_stored) {
                if ($comment->type != 'admin') {
                    // Lower karma to comments' spammers
                    $comment_count = (int) $db->get_var("select count(*) from comments where comment_user_id = {$current_user->user_id} and comment_date > date_sub(now(), interval 3 minute)");
                    // Check the text is not the same
                    $same_count = $comment->same_text_count() + $comment->same_links_count();
                } else {
                    $comment_count = $same_count = 0;
                }
                if ($comment_count > 2 || $same_count > 2) {
                    require_once mnminclude . 'user.php';
                    $reduction = 0;
                    if ($comment_count > 3) {
                        $reduction += ($comment_count - 3) * 0.1;
                    }
                    if ($same_count > 1) {
                        $reduction += $same_count * 0.25;
                    }
                    if ($reduction > 0) {
                        $user = new User();
                        $user->id = $current_user->user_id;
                        $user->read();
                        $user->karma = $user->karma - $reduction;
                        syslog(LOG_NOTICE, "Meneame: story decreasing {$reduction} of karma to {$current_user->user_login} (now {$user->karma})");
                        $user->store();
                        $error .= ' ' . 'penalización de karma por texto repetido o abuso de enlaces';
                    }
                }
                $comment->store();
                $comment->insert_vote();
                $link->update_comments();
                // Re read link data
                $link->read();
            } else {
                $error .= ' ' . 'duplicado';
            }
        } else {
            $error .= ' ' . 'caracteres no válidos';
        }
        // We don't redirect, Firefox show cache data instead of the new data since we send lastmodification time.
        //header('Location: '.$link->get_permalink());
        //die;
    } else {
        $error .= ' ' . 'texto muy breve, karma bajo o usuario incorrecto';
    }
    return $error;
}
Пример #26
0
/**
 * Cleans a string to make it suitable for the html description meta tag.
 * It removes any html tag and line breaks and limits its word count to 100 words so Google Webmasters doesn't complain.
 *
 * @param string $string
 * @return string
 */
function clean_meta_description($string)
{
    //clean text
    $string = clean_text($string);
    //limit to 100 words, ~700 characters
    $words = explode(' ', $string);
    if (count($words) > 100) {
        array_splice($words, 100);
        $string = implode(' ', $words) . ' ...';
    }
    return $string;
}
    function print_item_dropdown($item, $value, $info, $align, $showrating, $lines)
    {
        if ($info->horizontal) {
            $hv = 'h';
        } else {
            $hv = 'v';
        }
        echo '<ul>';
        ?>
        <li class="feedback_item_select_<?php 
        echo $hv . '_' . $align;
        ?>
">
            <select name="<?php 
        echo $item->typ . '_' . $item->id;
        ?>
">
                <option value="0">&nbsp;</option>
                <?php 
        $index = 1;
        $checked = '';
        foreach ($lines as $line) {
            if ($value == $index) {
                $selected = 'selected="selected"';
            } else {
                $selected = '';
            }
            $dropdown_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
            if ($showrating) {
                echo '<option value="' . $index . '" ' . $selected . '>' . clean_text('(' . $dropdown_value[0] . ') ' . $dropdown_value[1]) . '</option>';
            } else {
                echo '<option value="' . $index . '" ' . $selected . '>' . clean_text($dropdown_value[1]) . '</option>';
            }
            $index++;
        }
        ?>
            </select>
        </li>
        <?php 
        echo '</ul>';
    }
Пример #28
0
    }
} elseif ($type == 'link') {
    require_once mnminclude . 'link.php';
    $link = new Link();
    $link->id = $id;
    if (!$link->read()) {
        error(_('Artículo inexistente'));
    }
    if (!$link->is_map_editable()) {
        error(_("noticia no modificable"));
    }
} else {
    error(_('tipo incorrecto'));
}
$lat = (double) $_REQUEST['lat'];
$lng = (double) $_REQUEST['lng'];
$text = clean_text($_REQUEST['text'], 0, true, 75);
if (geo_insert($type, $id, $lat, $lng, $text)) {
    echo "OK";
    if ($type == 'link') {
        require_once mnminclude . 'log.php';
        log_conditional_insert('link_geo_edit', $link->id, $current_user->user_id, 60);
    }
} else {
    error(_('no se insertó en la base de datos'));
}
function error($mess)
{
    echo "ERROR: {$mess}\n";
    die;
}
Пример #29
0
    function display_add_field($recordid=0) {
        global $CFG, $DB, $OUTPUT, $PAGE;

        $text   = '';
        $format = 0;

        $str = '<div title="'.$this->field->description.'">';

        editors_head_setup();
        $options = $this->get_options();

        $itemid = $this->field->id;
        $field = 'field_'.$itemid;

        if ($recordid && $content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))){
            $format = $content->content1;
            $text = clean_text($content->content, $format);
            $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text);
        } else {
            $draftitemid = file_get_unused_draft_itemid();
            if (can_use_html_editor()) {
                $format = FORMAT_HTML;
            } else {
                $format = FORMAT_PLAIN;
            }
        }

        // get filepicker info
        //
        $fpoptions = array();
        if ($options['maxfiles'] != 0 ) {
            $args = new stdClass();
            // need these three to filter repositories list
            $args->accepted_types = array('web_image');
            $args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
            $args->context = $this->context;
            $args->env = 'filepicker';
            // advimage plugin
            $image_options = initialise_filepicker($args);
            $image_options->context = $this->context;
            $image_options->client_id = uniqid();
            $image_options->maxbytes = $options['maxbytes'];
            $image_options->env = 'editor';
            $image_options->itemid = $draftitemid;

            // moodlemedia plugin
            $args->accepted_types = array('video', 'audio');
            $media_options = initialise_filepicker($args);
            $media_options->context = $this->context;
            $media_options->client_id = uniqid();
            $media_options->maxbytes  = $options['maxbytes'];
            $media_options->env = 'editor';
            $media_options->itemid = $draftitemid;

            // advlink plugin
            $args->accepted_types = '*';
            $link_options = initialise_filepicker($args);
            $link_options->context = $this->context;
            $link_options->client_id = uniqid();
            $link_options->maxbytes  = $options['maxbytes'];
            $link_options->env = 'editor';
            $link_options->itemid = $draftitemid;

            $fpoptions['image'] = $image_options;
            $fpoptions['media'] = $media_options;
            $fpoptions['link'] = $link_options;
        }

        $editor = editors_get_preferred_editor($format);
        $strformats = format_text_menu();
        $formats =  $editor->get_supported_formats();
        foreach ($formats as $fid) {
            $formats[$fid] = $strformats[$fid];
        }
        $editor->use_editor($field, $options, $fpoptions);
        $str .= '<input type="hidden" name="'.$field.'_itemid" value="'.$draftitemid.'" />';
        $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'">'.s($text).'</textarea></div>';
        $str .= '<div><select name="'.$field.'_content1">';
        foreach ($formats as $key=>$desc) {
            $selected = ($format == $key) ? 'selected="selected"' : '';
            $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>';
        }
        $str .= '</select>';
        $str .= '</div>';

        $str .= '</div>';
        return $str;
    }
Пример #30
0
 function create_value($data)
 {
     $data = clean_text($data);
     return $data;
 }