function do_fac($theFac, $theWidth, $search = FALSE, $dist = TRUE)
{
    $print = "<TABLE BORDER='0'ID='left' width='" . $theWidth . "'>\n";
    //
    $print .= "<TR CLASS='even'><TD CLASS='td_data' COLSPAN=2 ALIGN='center'><B>Facility: <I>" . highlight($search, $theFac['fac_name']) . "</B></TD></TR>\n";
    $print .= "<TR CLASS='odd'  VALIGN='top'><TD>Description:</TD>\t<TD>" . highlight($search, nl2br($theFac['fac_descr'])) . "</TD></TR>\n";
    $print .= "<TR CLASS='even'  VALIGN='top'><TD>Capability:</TD>\t<TD>" . highlight($search, nl2br($theFac['capab'])) . "</TD></TR>\n";
    $print .= "<TR CLASS='odd'  VALIGN='top'><TD>Status:</TD>\t<TD>" . $theFac['status_val'] . "</TD></TR>\n";
    $print .= "<TR CLASS='even'  VALIGN='top'><TD>Opening Hours:</TD>\t<TD>" . $theFac['opening_hours'] . "</TD></TR>\n";
    $print .= "<TR CLASS='odd'  VALIGN='top'><TD>Access Rules:</TD>\t<TD>" . $theFac['access_rules'] . "</TD></TR>\n";
    $print .= "<TR CLASS='even'  VALIGN='top'><TD>Sec Reqs:</TD>\t<TD>" . $theFac['security_reqs'] . "</TD></TR>\n";
    $print .= "<TR CLASS='odd'  VALIGN='top'><TD>Cont name:</TD>\t<TD>" . $theFac['contact_name'] . "</TD></TR>\n";
    $print .= "<TR CLASS='even'  VALIGN='top'><TD>Cont email:</TD>\t<TD>" . $theFac['contact_email'] . "</TD></TR>\n";
    $print .= "<TR CLASS='odd'  VALIGN='top'><TD>Cont phone:</TD>\t<TD>" . $theFac['contact_phone'] . "</TD></TR>\n";
    $print .= "<TR CLASS='even'  VALIGN='top'><TD>Sec contact:</TD>\t<TD>" . $theFac['security_contact'] . "</TD></TR>\n";
    $print .= "<TR CLASS='odd'  VALIGN='top'><TD>Sec email:</TD>\t<TD>" . $theFac['security_email'] . "</TD></TR>\n";
    $print .= "<TR CLASS='even'  VALIGN='top'><TD>Sec phone:</TD>\t<TD>" . $theFac['security_phone'] . "</TD></TR>\n";
    $print .= "<TR CLASS='odd'  VALIGN='top'><TD>Prim pager:</TD>\t<TD>" . $theFac['pager_p'] . "</TD></TR>\n";
    $print .= "<TR CLASS='even'  VALIGN='top'><TD>Sec pager:</TD>\t<TD>" . $theFac['pager_s'] . "</TD></TR>\n";
    $print .= "<TR CLASS='odd' ><TD>Updated:</TD>\t\t<TD>" . format_date($theFac['updated']) . "</TD></TR>\n";
    //	$print .= "<TR CLASS='even'><TD>Status:</TD>		<TD>" . $theFac['status_id'] . "</TD></TR>\n";
    $print .= "<TR STYLE = 'display:none;'><TD colspan=2><SPAN ID='oldlat'>" . $theFac['lat'] . "</SPAN><SPAN ID='oldlng'>" . $theFac['lng'] . "</SPAN></TD></TR>";
    $print .= "</TABLE>\n";
    return $print;
}
Esempio n. 2
0
 function fetchResults(&$record_count)
 {
     global $AppUI;
     $results = $this->_searchResults();
     if ($results && getPermission($this->table_module, 'access')) {
         $record_count += count($results);
         $outstring = '<tr><th><b>' . $AppUI->_($this->table_title) . ' (' . count($results) . ')' . '</b></th></tr>' . "\n";
         foreach ($results as $records) {
             if (getPermission($this->table_module, 'access', $records[$this->table_key])) {
                 $ii = 0;
                 $display_val = '';
                 foreach ($this->display_fields as $fld) {
                     $ii++;
                     if (!($this->search_options['display_all_flds'] == 'on') && $ii > 2) {
                         break;
                     }
                     $display_val .= ($display_val ? ' ' : '') . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $fld)];
                 }
                 $tmplink = "";
                 if (isset($this->table_link) && isset($this->table_key)) {
                     $tmplink = $this->table_link . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key)];
                 }
                 if (isset($this->table_link2) && isset($this->table_key2)) {
                     $tmplink = $this->table_link . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key)] . $this->table_link2 . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key2)];
                 }
                 $outstring .= '<tr><td>' . "\n" . '<a href="' . $tmplink . '">' . highlight($display_val, $this->keywords) . '</a>' . "\n" . '</td></tr>' . "\n";
             }
         }
     } else {
         if ($this->search_options['show_empty'] == 'on') {
             $outstring = '<tr><th><b>' . $AppUI->_($this->table_title) . ' (' . count($results) . ')' . '</b></th></tr>' . "\n" . '<tr><td>' . $AppUI->_('Empty') . '</td></tr>' . "\n";
         }
     }
     return $outstring;
 }
Esempio n. 3
0
function find($r, $len, $extra)
{
    // $words = file_get_contents("/usr/share/dict/words");
    $words = file_get_contents("dict.txt");
    if (!$words) {
        return "";
    }
    // echo($r);
    preg_match_all("/\\b" . $r . "\\b/", $words, $keys);
    $ret = "";
    $fwords = $keys[0];
    if ($len > 0) {
        foreach ($fwords as $w) {
            if (strlen($w) == $len) {
                $ret .= highlight($w, $extra) . "<br>";
            }
        }
    } else {
        foreach ($fwords as $w) {
            $ret .= highlight($w, $extra) . "<br>";
        }
    }
    if (strlen($ret) > 0) {
        echo $ret;
    } else {
        echo "No matches";
    }
}
Esempio n. 4
0
/**
 * Generate the documentation. The "main loop", so to speak.
 * 
 * @param string $file (the filename)
 * @return void
 */
function generate_documentation($file)
{
    $code = file_get_contents($file);
    $sections = parse($file, $code);
    $sections = highlight($file, $sections);
    generate_html($file, $sections);
}
Esempio n. 5
0
function strhighlight($needle, $haystack)
{
    $ind = stripos($haystack, $needle);
    $len = strlen($needle);
    if ($ind !== false) {
        return substr($haystack, 0, $ind) . "<strong>" . substr($haystack, $ind, $len) . "</strong>" . highlight($needle, substr($haystack, $ind + $len));
    } else {
        return $haystack;
    }
}
Esempio n. 6
0
 function test_highlight() {
     $this->assertEqual(highlight('good', 'This is good'), 'This is <span class="highlight">good</span>');
     $this->assertEqual(highlight('SpaN', 'span'), '<span class="highlight">span</span>');
     $this->assertEqual(highlight('span', 'SpaN'), '<span class="highlight">SpaN</span>');
     $this->assertEqual(highlight('span', '<span>span</span>'), '<span><span class="highlight">span</span></span>');
     $this->assertEqual(highlight('good is', 'He is good'), 'He <span class="highlight">is</span> <span class="highlight">good</span>');
     $this->assertEqual(highlight('+good', 'This is good'), 'This is <span class="highlight">good</span>');
     $this->assertEqual(highlight('-good', 'This is good'), 'This is good');
     $this->assertEqual(highlight('+good', 'This is goodness'), 'This is goodness');
     $this->assertEqual(highlight('good', 'This is goodness'), 'This is <span class="highlight">good</span>ness');
 }
Esempio n. 7
0
 static function highlight($array, $highlight)
 {
     $n = array();
     foreach ($array as $key => $value) {
         if (!in_array($key, array("photo", "ID"))) {
             if (is_array($value)) {
                 $n[$key] = self::highlight($value, $highlight);
             } else {
                 $n[$key] = highlight($highlight, $value);
             }
         } else {
             $n[$key] = $value;
         }
     }
     return $n;
 }
 public function fetchResults(&$permissions, &$record_count)
 {
     global $AppUI;
     $outstring = '';
     $q = $this->_buildQuery();
     $results = null;
     if ($q) {
         $results = $q->loadList();
     }
     if ($results) {
         $outstring = '';
         $subrecord_count = 0;
         foreach ($results as $records) {
             if ($permissions->checkModuleItem($this->table_module, 'view', $records[$this->table_key])) {
                 //Don't count records for which the user does not have permission
                 $record_count += 1;
                 $subrecord_count += 1;
                 // --MSy-
                 $ii = 0;
                 $display_val = '';
                 foreach ($this->display_fields as $fld) {
                     $ii++;
                     if (!($this->search_options['display_all_flds'] == 'on') && $ii > 2) {
                         break;
                     }
                     $display_val = $display_val . ' ' . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $fld)];
                 }
                 //--MSy-
                 $tmplink = '';
                 if (isset($this->table_link) && isset($this->table_key)) {
                     $tmplink = $this->table_link . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key)];
                 }
                 if (isset($this->table_link2) && isset($this->table_key2)) {
                     $tmplink = $this->table_link . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key)] . $this->table_link2 . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key2)];
                 }
                 //--MSy--
                 $outstring .= '<tr><td><a href = "' . $tmplink . '">' . highlight($display_val, $this->keywords) . '</a></td></tr>';
             }
         }
         $outstring = '<tr><th><b>' . $AppUI->_($this->table_title) . ' (' . $subrecord_count . ')' . '</b></th></tr> ' . "\n" . $outstring;
     } else {
         if ($this->search_options['show_empty'] == 'on') {
             $outstring = '<tr><th><b>' . $AppUI->_($this->table_title) . ' (0)' . '</b></th></tr><tr><td>' . $AppUI->_('Empty') . '</td></tr>';
         }
     }
     return $outstring;
 }
Esempio n. 9
0
 function fetchResults(&$permissions, &$record_count)
 {
     global $AppUI;
     $sql = $this->_buildQuery();
     $results = db_loadList($sql);
     if ($results) {
         $record_count += count($results);
         $outstring = "<tr><th><b>" . $AppUI->_($this->table_title) . ' (' . count($results) . ')' . "</b></th></tr> \n";
         foreach ($results as $records) {
             if ($permissions->checkModuleItem($this->table_module, "view", $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key)])) {
                 // --MSy-
                 $ii = 0;
                 $display_val = "";
                 foreach ($this->display_fields as $fld) {
                     $ii++;
                     if (!($this->search_options['display_all_flds'] == "on") && $ii > 2) {
                         break;
                     }
                     $display_val = $display_val . " " . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $fld)];
                 }
                 //--MSy-
                 $tmplink = "";
                 if (isset($this->table_link) && isset($this->table_key)) {
                     $tmplink = $this->table_link . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key)];
                 }
                 if (isset($this->table_link2) && isset($this->table_key2)) {
                     $tmplink = $this->table_link . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key)] . $this->table_link2 . $records[preg_replace('/^.*\\.([^\\.]+)$/', '$1', $this->table_key2)];
                 }
                 //--MSy--
                 $outstring .= "<tr>";
                 $outstring .= "<td>";
                 $outstring .= "<a href = \" " . $tmplink . "\">" . highlight($display_val, $this->keywords) . "</a>\n";
                 $outstring .= "</td>\n";
                 $outstring .= "</tr>";
             }
         }
     } else {
         if ($this->search_options['show_empty'] == "on") {
             $outstring = "<tr><th><b>" . $AppUI->_($this->table_title) . ' (' . count($results) . ')' . "</b></th></tr> \n";
             $outstring .= "<tr>" . "<td>" . $AppUI->_('Empty') . "</td>" . "</tr>";
         }
     }
     return $outstring;
 }
function bat_highlight($message, $words, $color = '#ff0000')
{
    if (!empty($words)) {
        $highlightarray = explode(' ', $words);
        $sppos = strrpos($message, chr(0) . chr(0) . chr(0));
        if ($sppos !== FALSE) {
            $specialextra = substr($message, $sppos + 3);
            $message = substr($message, 0, $sppos);
        }
        $message = preg_replace_callback("/(^|>)([^<]+)(?=<|\$)/siU", function ($matches) use($highlightarray) {
            return highlight($matches[2], $highlightarray, $matches[1]);
        }, $message);
        $message = preg_replace("/<highlight>(.*)<\\/highlight>/siU", "<strong><font color=\"{$color}\">\\1</font></strong>", $message);
        if ($sppos !== FALSE) {
            $message = $message . chr(0) . chr(0) . chr(0) . $specialextra;
        }
    }
    return $message;
}
Esempio n. 11
0
function smartHighlight($code)
{
    // find all php stuff
    preg_match_all('!\\<\\?.*?\\?\\>!i', $code, $array);
    $result = '';
    $php = array();
    // replace php within html with placeholders
    foreach ($array[0] as $key => $found) {
        $key = '____' . $key . '____';
        $php[$key] = highlight($found, 'php');
        $code = str_replace($found, $key, $code);
    }
    // now highlight the plain html
    $code = highlight($code, 'html');
    // put the highlighted php back in
    foreach ($php as $key => $p) {
        $code = str_replace($key, $p, $code);
    }
    return $code;
}
Esempio n. 12
0
 static function code($code)
 {
     $code = @$code[1];
     $lines = explode("\n", $code);
     $first = trim(array_shift($lines));
     $code = implode("\n", $lines);
     $code = trim($code);
     if (function_exists('highlight')) {
         $result = '<pre class="highlight ' . $first . '">';
         $result .= '<code>';
         $result .= highlight($code, empty($first) ? 'php-html' : $first);
         $result .= '</code>';
         $result .= '</pre>';
     } else {
         $result = '<pre class="' . $first . '">';
         $result .= '<code>';
         $result .= htmlspecialchars($code);
         $result .= '</code>';
         $result .= '</pre>';
     }
     return $result;
 }
Esempio n. 13
0
function print_user_entry($user, $keywords, $count)
{
    global $SESSION, $CFG;
    $smalluserobject = new stdClass();
    // All we need to delete them later
    $smalluserobject->id = $user->id;
    $smalluserobject->email = $user->email;
    $smalluserobject->auth = $user->auth;
    $smalluserobject->firstname = $user->firstname;
    $smalluserobject->lastname = $user->lastname;
    $smalluserobject->username = $user->username;
    if (empty($SESSION->users_result[$user->id])) {
        $SESSION->users_result[$user->id] = $smalluserobject;
        $html = '<tr valign="top" id="row-' . $user->id . '" class="result-row">';
        $html .= '<td width="10">' . $count . '</td>';
        $html .= '<td width="30%" align="left"><a href="' . $CFG->wwwroot . "/user/view.php?course=1&amp;id=" . $user->id . '" title="' . s($user->username) . '">' . fullname($user) . '</a>';
        $html .= "<ul>";
        $profile_set = array('city' => true, 'country' => true, 'email' => true);
        foreach ($profile_set as $key => $value) {
            if (isset($user->{$key})) {
                $html .= '<li>' . $user->{$key} . '</li>';
            }
        }
        $html .= "</ul>";
        $html .= '</td>';
        foreach ($keywords as $keyword) {
            $user->description = highlight($keyword, $user->description);
        }
        if (!isset($user->descriptionformat)) {
            $user->descriptionformat = FORMAT_MOODLE;
        }
        $html .= '<td align="left">' . format_text($user->description, $user->descriptionformat, array('overflowdiv' => true)) . '</td>';
        $html .= '<td width="100px" align="center">';
        $html .= '<button onclick="M.tool_spamcleaner.del_user(this,' . $user->id . ')">' . get_string('deleteuser', 'admin') . '</button><br />';
        $html .= '<button onclick="M.tool_spamcleaner.ignore_user(this,' . $user->id . ')">' . get_string('ignore', 'admin') . '</button>';
        $html .= '</td>';
        $html .= '</tr>';
        return $html;
    } else {
        return null;
    }
}
Esempio n. 14
0
/**
 * takes a list of records, the current data, a search string,
 * and mode to display prints the translated template
 *
 * @global object
 * @global object
 * @param string $template
 * @param array $records
 * @param object $data
 * @param string $search
 * @param int $page
 * @param bool $return
 * @return mixed
 */
function data_print_template($template, $records, $data, $search='', $page=0, $return=false) {
    global $CFG, $DB, $OUTPUT;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);

    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;

    if (empty($dataid)) {
        $dataid = $data->id;
    } else if ($dataid != $data->id) {
        $fields = NULL;
    }

    if (empty($fields)) {
        $fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id));
        foreach ($fieldrecords as $fieldrecord) {
            $fields[]= data_get_field($fieldrecord, $data);
        }
        $isteacher = has_capability('mod/data:managetemplates', $context);
    }

    if (empty($records)) {
        return;
    }

    foreach ($records as $record) {   // Might be just one for the single template

    // Replacing tags
        $patterns = array();
        $replacement = array();

    // Then we generate strings to replace for normal tags
        foreach ($fields as $field) {
            $patterns[]='[['.$field->field->name.']]';
            $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
        }

    // Replacing special tags (##Edit##, ##Delete##, ##More##)
        $patterns[]='##edit##';
        $patterns[]='##delete##';
        if (has_capability('mod/data:manageentries', $context) or data_isowner($record->id)) {
            $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d='
                             .$data->id.'&amp;rid='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.get_string('edit').'" title="'.get_string('edit').'" /></a>';
            $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
                             .$data->id.'&amp;delete='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="'.get_string('delete').'" title="'.get_string('delete').'" /></a>';
        } else {
            $replacement[] = '';
            $replacement[] = '';
        }

        $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;rid=' . $record->id;
        if ($search) {
            $moreurl .= '&amp;filter=1';
        }
        $patterns[]='##more##';
        $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('i/search') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>';

        $patterns[]='##moreurl##';
        $replacement[] = $moreurl;

        $patterns[]='##user##';
        $replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid.
                               '&amp;course='.$data->course.'">'.fullname($record).'</a>';

        $patterns[]='##export##';

        if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate')
            && ((has_capability('mod/data:exportentry', $context)
                || (data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))))) {
            require_once($CFG->libdir . '/portfoliolib.php');
            $button = new portfolio_add_button();
            $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), '/mod/data/locallib.php');
            list($formats, $files) = data_portfolio_caller::formats($fields, $record);
            $button->set_formats($formats);
            $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
        } else {
            $replacement[] = '';
        }

        $patterns[] = '##timeadded##';
        $replacement[] = userdate($record->timecreated);

        $patterns[] = '##timemodified##';
        $replacement [] = userdate($record->timemodified);

        $patterns[]='##approve##';
        if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)){
            $replacement[] = '<span class="approve"><a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;approve='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('i/approve') . '" class="icon" alt="'.get_string('approve').'" /></a></span>';
        } else {
            $replacement[] = '';
        }

        $patterns[]='##comments##';
        if (($template == 'listtemplate') && ($data->comments)) {

            if (!empty($CFG->usecomments)) {
                require_once($CFG->dirroot  . '/comment/lib.php');
                list($context, $course, $cm) = get_context_info_array($context->id);
                $cmt = new stdClass();
                $cmt->context = $context;
                $cmt->course  = $course;
                $cmt->cm      = $cm;
                $cmt->area    = 'database_entry';
                $cmt->itemid  = $record->id;
                $cmt->showcount = true;
                $cmt->component = 'mod_data';
                $comment = new comment($cmt);
                $replacement[] = $comment->output(true);
            }
        } else {
            $replacement[] = '';
        }

        // actual replacement of the tags
        $newtext = str_ireplace($patterns, $replacement, $data->{$template});

        // no more html formatting and filtering - see MDL-6635
        if ($return) {
            return $newtext;
        } else {
            echo $newtext;

            // hack alert - return is always false in singletemplate anyway ;-)
            /**********************************
             *    Printing Ratings Form       *
             *********************************/
            if ($template == 'singletemplate') {    //prints ratings options
                data_print_ratings($data, $record);
            }

            /**********************************
             *    Printing Comments Form       *
             *********************************/
            if (($template == 'singletemplate') && ($data->comments)) {
                if (!empty($CFG->usecomments)) {
                    require_once($CFG->dirroot . '/comment/lib.php');
                    list($context, $course, $cm) = get_context_info_array($context->id);
                    $cmt = new stdClass();
                    $cmt->context = $context;
                    $cmt->course  = $course;
                    $cmt->cm      = $cm;
                    $cmt->area    = 'database_entry';
                    $cmt->itemid  = $record->id;
                    $cmt->showcount = true;
                    $cmt->component = 'mod_data';
                    $comment = new comment($cmt);
                    $comment->output(false);
                }
            }
        }
    }
}
Esempio n. 15
0
    function trackTable($tracks, $purpose = false)
    {
        global $media_dir, $jinzora_skin, $hierarchy, $album_name_truncate, $row_colors, $img_more, $img_email, $img_rate, $img_discuss, $num_other_albums, $enable_ratings, $this_site, $allow_clips, $root_dir, $jzUSER, $hide_id3_comments, $max_song_length, $enable_discussion, $max_song_name_length, $show_lyrics_links, $allow_send_email, $handle_compilations, $video_types, $show_track_numbers;
        if (sizeof($tracks) == 0) {
            return;
        }
        // Let's setup the new display object
        $display =& new jzDisplay();
        $tracks_only = array();
        foreach ($tracks as $track) {
            if (is_object($track)) {
                $tracks_only[] = $track;
            }
        }
        // Now let's see if this is a Audio, Video, or Photo node
        $video = true;
        foreach ($tracks_only as $track) {
            if (!preg_match("/\\.({$video_types})\$/i", $track->getDataPath())) {
                $video = false;
            }
        }
        if ($video) {
            $this->videoTable($tracks_only, $purpose);
            return;
        }
        // Let's figure out our settings:
        // First, set the defaults.
        $showNumbers = false;
        if ($show_track_numbers == "true") {
            $showNumbers = true;
        }
        $showArtist = false;
        $showAlbum = false;
        $showCheck = false;
        $showInfo = false;
        $showEmail = false;
        $showRate = false;
        $showDisc = false;
        $showAlbumNames = false;
        $trackTruncate = false;
        $showPlayCount = false;
        if ($enable_discussion == "true") {
            $showDisc = true;
        }
        $trackTruncate = $max_song_name_length;
        // Now adjust as needed:
        switch ($purpose) {
            case "generic":
                $showNumbers = false;
                break;
            case "album":
                $showCheck = true;
                $showInfo = true;
                $showPlayCount = true;
                $showEmail = true;
                break;
            case "search":
                $showCheck = true;
                $showArtist = true;
                $showInfo = true;
                $showEmail = true;
                $trackTruncate = 100;
                break;
            case "sample":
                // We only want to show album thumbs IF this artist has more than 1 album
                $parent = $tracks_only[0]->getParent();
                $gParent = $parent->getParent();
                $nodes = $gParent->getSubNodes("nodes");
                $showNumbers = false;
                $showAlbum = true;
                break;
            case "sample-all":
                $showNumbers = false;
                $showCheck = true;
                $showAlbumNames = true;
                $trackTruncate = 20;
                break;
        }
        if ($allow_send_email == "false") {
            $showEmail = false;
        }
        // Do we need to start the form
        if ($showCheck) {
            $node = $tracks_only[0]->getParent();
            ?>
			<form name="albumForm" action="<?php 
            echo urlize();
            ?>
" method="POST">
			<input type="hidden" name="<?php 
            echo jz_encode("action");
            ?>
" value="<?php 
            echo jz_encode("mediaAction");
            ?>
">
				<?php 
            if ($purpose != "search") {
                ?>
 
			  <input type="hidden" name="<?php 
                echo jz_encode("jz_path");
                ?>
" value="<?php 
                echo htmlentities(jz_encode($node->getPath("String")));
                ?>
">
				<?php 
            }
            ?>
			<input type="hidden" name="<?php 
            echo jz_encode("jz_list_type");
            ?>
" value="<?php 
            echo jz_encode("tracks");
            ?>
">
			<?php 
        }
        // Now let's setup the big table to display everything
        $i = 0;
        ?>
		  <table class="jz_track_table" width="100%" cellpadding="3" cellspacing="0" border="0">
		 <?php 
        $artists = array();
        if ($handle_compilations == "true") {
            foreach ($tracks_only as $child) {
                $a = $child->getMeta();
                if (!isNothing($a['artist'])) {
                    $artists[$a['artist']] = true;
                }
            }
        } else {
            foreach ($tracks_only as $child) {
                $a = $child->getAncestor('artist');
                if ($a !== false) {
                    $artists[strtoupper($a->getName())] = true;
                }
            }
        }
        if (sizeof($artists) > 1) {
            $multiArtist = true;
        } else {
            $multiArtist = false;
        }
        $first_label = true;
        foreach ($tracks as $child) {
            // is it a header?
            if (is_string($child)) {
                if (!$first_label) {
                    echo '<tr><td colspan="100">&nbsp;</td></tr>';
                }
                echo '<tr><td colspan="100">' . $child . '</td></tr>';
                $first_label = false;
                continue;
            }
            // Let's make sure this isn't a lofi track
            if (substr($child->getPath("String"), -9) == ".lofi.mp3" or substr($child->getPath("String"), -9) == ".clip.mp3") {
                continue;
            }
            // First let's grab all the tracks meta data
            $metaData = $child->getMeta();
            $album = $child->getParent();
            if (findPType($album) == "disk") {
                $album = $album->getParent();
            }
            $gParent = $album->getParent();
            $artist = getInformation($album, "artist");
            ?>
		   <tr class="<?php 
            echo $row_colors[$i];
            ?>
">
		   <?php 
            if ($showCheck and $jzUSER->getSetting('stream')) {
                $value = htmlentities(jz_encode($child->getPath("String")));
                ?>
		   <td width="1%" valign="top" class="jz_track_table_songs_td">
		   <input type="checkbox" name="jz_list[]" value="<?php 
                echo $value;
                ?>
">
		   </td>
		   <?php 
            }
            ?>
		   
		   <td width="99%" valign="top" class="jz_track_table_songs_td" nowrap>
		   	<?php 
            echo $display->playButton($child);
            ?>
			 <?php 
            // Now, is there a lofi version?
            $loFile = substr($child->getDataPath("String"), 0, -4) . ".lofi.mp3";
            if (is_file($loFile) and $jzUSER->getSetting('stream')) {
                $lofi = new jzMediaTrack(substr($child->getPath("String"), 0, -4) . ".lofi.mp3");
                //echo '<td width="1%" valign="top" class="jz_track_table_songs_td">';
                echo $display->lofiPlayButton($lofi);
                //echo '</td>';
            }
            ?>
			   <?php 
            // Now, is there a clip version?
            $loFile = substr($child->getDataPath("String"), 0, -4) . ".clip.mp3";
            if (is_file($loFile) || $allow_clips == "true") {
                //echo '<td width="1%" valign="top" class="jz_track_table_songs_td">';
                echo $display->clipPlayButton($child);
                //echo '</td>';
            }
            ?>
			   
		   <?php 
            echo $display->downloadButton($child);
            ?>
		   <?php 
            // Do they want ratings?
            if ($enable_ratings == "true") {
                $display->rateButton($child);
            }
            if ($showInfo) {
                echo " ";
                $display->infoButton($child);
            }
            if ($showEmail and $jzUSER->getSetting('stream')) {
                $display->emailButton($child);
            }
            ?>
		   <?php 
            if ($showDisc) {
                ?>
		   <a class="jz_track_table_songs_href" href=""><?php 
                $display->displayDiscussIcon($child);
                ?>
</a>
		   <?php 
            }
            ?>
		   <?php 
            if ($showArtist !== false) {
                $j = 0;
                while ($j < sizeof($hierarchy) && $hierarchy[$j] != 'artist') {
                    $j++;
                }
                if ($j < sizeof($hierarchy)) {
                    $parent = $child;
                    while ($parent->getLevel() > $j + 1) {
                        $parent = $parent->getParent();
                    }
                    $display->link($parent, $parent->getName(), $parent->getName(), "jz_track_table_songs_href");
                    echo " / ";
                }
            }
            // This is where we display the name
            if ($multiArtist) {
                if ($handle_compilations == "true") {
                    $artistName = $metaData['artist'];
                    if (isNothing($artistName)) {
                        $artist = $child->getAncestor("artist");
                        if ($artist !== false) {
                            $artistName = $artist->getName();
                        }
                    }
                } else {
                    $artist = $child->getAncestor("artist");
                    if ($artist !== false) {
                        $artistName = $artist->getName();
                    }
                }
                if (isset($artistName)) {
                    $tName = $child->getName();
                    unset($artistName);
                } else {
                    $tName = $child->getName();
                }
            } else {
                $tName = $child->getName();
            }
            if ($trackTruncate) {
                $tName = returnItemShortName($tName, $trackTruncate);
            }
            if ($purpose == "search") {
                $album = $child->getAncestor("album");
                $display->link($album, $album->getName(), $album->getName(), "jz_track_table_songs_href");
                echo " / ";
            }
            if ($showNumbers) {
                echo $metaData['number'] . " -&nbsp;";
            }
            if ($jzUSER->getSetting('stream')) {
                if ($showAlbum) {
                    $descName = $album->getName() . " - " . $child->getName();
                } else {
                    $descName = $child->getName();
                }
                // $tName = $child->getName();
                $display->link($child, $tName, $descName, "jz_track_table_songs_href");
            } else {
                echo $tName;
            }
            // Did they want to see lyrics links?
            if ($show_lyrics_links == "true") {
                if ($metaData['lyrics'] != "") {
                    $urlArr = array();
                    $urlArr['jz_path'] = $child->getPath("String");
                    $urlArr['action'] = "popup";
                    $urlArr['ptype'] = "viewlyricsfortrack";
                    echo '<a href="' . urlize($urlArr) . '" onclick="openPopup(this, 450, 450); return false;"> - ' . word("Lyrics") . '</a>';
                }
            }
            // Now let's show the description if there is one
            if ($short_desc = $child->getShortDescription() and $hide_id3_comments == "false") {
                echo "<br>" . $short_desc;
            }
            if ($description = $child->getDescription()) {
                echo "<br>" . $description;
            }
            // Do they want ratings?
            /*if ($enable_ratings == "true"){
               		//$rating = $display->displayRating($child,true);
            		if ($rating){
            			//echo "<br>". $rating;
            		}
            		//unset($rating);
               }*/
            ?>
		   </td>
		   
		   <?php 
            $lyricsSearch = false;
            if (isset($_POST['search_type'])) {
                if ($_POST['search_type'] == "lyrics") {
                    $lyricsSearch = $_POST['search_query'];
                }
            }
            if (isset($_GET['search_type'])) {
                if ($_GET['search_type'] == "lyrics") {
                    $lyricsSearch = $_GET['search_query'];
                }
            }
            if ($lyricsSearch) {
                // Now let's get the lyrics back
                $lyrics = $child->getLyrics();
                // Now let's parse it out
                $lyrics = str_replace("Lyrics Provided by: Leo's Lyrics\nhttp://www.leoslyrics.com", "", $lyrics);
                $start = strpos(strtolower($lyrics), strtolower($lyricsSearch)) - 20;
                if ($start < 0) {
                    $start = 0;
                }
                $lyrics = "&nbsp; &nbsp; &nbsp; &nbsp;(..." . substr($lyrics, $start, strlen($lyricsSearch) + 40) . "...)";
                $lyrics = highlight($lyrics, $lyricsSearch);
                echo '<td width="6%" align="center" valign="top" class="jz_track_table_songs_td" nowrap>';
                echo $lyrics;
                echo '</td>';
            }
            ?>
		   
		   
		   <?php 
            if ($showAlbumNames) {
                echo '<td width="1%" class="jz_track_table_songs_td" nowrap>';
                $display->link($album, returnItemShortName($album->getName(), 20), $album->getName(), "jz_track_table_songs_href");
                echo '</td>';
            }
            ?>
		   
			<?php 
            if ($showPlayCount) {
                echo '<td width="1%" align="center" valign="top" class="jz_track_table_songs_td" nowrap>';
                if ($child->getPlayCount() != 0) {
                    echo $child->getPlayCount() . " " . word("Plays");
                } else {
                    echo " - ";
                }
                echo '</td>';
            }
            ?>
		   
		   
		   <td width="6%" align="center" valign="top" class="jz_track_table_songs_td" nowrap>
		   &nbsp; <?php 
            echo convertSecMins($metaData['length']);
            ?>
 &nbsp;
		   </td>
		   </tr>
		   <?php 
            $i = 1 - $i;
            unset($gParent);
            unset($album);
        }
        // Now let's set a field with the number of checkboxes that were here
        echo "</table>";
        // Now let's show the playlist bar if we should
        if ($showCheck) {
            $this->blockSpacer();
            $this->playlistBar();
            echo "</form>";
        }
    }
Esempio n. 16
0
/**
 * Print a description of a course, suitable for browsing in a list.
 *
 * @param object $course the course object.
 * @param string $highlightterms (optional) some search terms that should be highlighted in the display.
 */
function print_course($course, $highlightterms = '')
{
    global $CFG, $USER, $DB, $OUTPUT;
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    // Rewrite file URLs so that they are correct
    $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
    echo html_writer::start_tag('div', array('class' => 'coursebox clearfix'));
    echo html_writer::start_tag('div', array('class' => 'info'));
    echo html_writer::start_tag('h3', array('class' => 'name'));
    $linkhref = new moodle_url('/course/view.php', array('id' => $course->id));
    $coursename = get_course_display_name_for_list($course);
    $linktext = highlight($highlightterms, format_string($coursename));
    $linkparams = array('title' => get_string('entercourse'));
    if (empty($course->visible)) {
        $linkparams['class'] = 'dimmed';
    }
    echo html_writer::link($linkhref, $linktext, $linkparams);
    echo html_writer::end_tag('h3');
    /// first find all roles that are supposed to be displayed
    if (!empty($CFG->coursecontact)) {
        $managerroles = explode(',', $CFG->coursecontact);
        $namesarray = array();
        $rusers = array();
        if (!isset($course->managers)) {
            $rusers = get_role_users($managerroles, $context, true, 'ra.id AS raid, u.id, u.username, u.firstname, u.lastname,
                 r.name AS rolename, r.sortorder, r.id AS roleid', 'r.sortorder ASC, u.lastname ASC');
        } else {
            //  use the managers array if we have it for perf reasosn
            //  populate the datastructure like output of get_role_users();
            foreach ($course->managers as $manager) {
                $u = new stdClass();
                $u = $manager->user;
                $u->roleid = $manager->roleid;
                $u->rolename = $manager->rolename;
                $rusers[] = $u;
            }
        }
        /// Rename some of the role names if needed
        if (isset($context)) {
            $aliasnames = $DB->get_records('role_names', array('contextid' => $context->id), '', 'roleid,contextid,name');
        }
        $namesarray = array();
        $canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
        foreach ($rusers as $ra) {
            if (isset($namesarray[$ra->id])) {
                //  only display a user once with the higest sortorder role
                continue;
            }
            if (isset($aliasnames[$ra->roleid])) {
                $ra->rolename = $aliasnames[$ra->roleid]->name;
            }
            $fullname = fullname($ra, $canviewfullnames);
            $namesarray[$ra->id] = format_string($ra->rolename) . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $ra->id, 'course' => SITEID)), $fullname);
        }
        if (!empty($namesarray)) {
            echo html_writer::start_tag('ul', array('class' => 'teachers'));
            foreach ($namesarray as $name) {
                echo html_writer::tag('li', $name);
            }
            echo html_writer::end_tag('ul');
        }
    }
    echo html_writer::end_tag('div');
    // End of info div
    echo html_writer::start_tag('div', array('class' => 'summary'));
    $options = new stdClass();
    $options->noclean = true;
    $options->para = false;
    $options->overflowdiv = true;
    if (!isset($course->summaryformat)) {
        $course->summaryformat = FORMAT_MOODLE;
    }
    echo highlight($highlightterms, format_text($course->summary, $course->summaryformat, $options, $course->id));
    if ($icons = enrol_get_course_info_icons($course)) {
        echo html_writer::start_tag('div', array('class' => 'enrolmenticons'));
        foreach ($icons as $icon) {
            echo $OUTPUT->render($icon);
        }
        echo html_writer::end_tag('div');
        // End of enrolmenticons div
    }
    echo html_writer::end_tag('div');
    // End of summary div
    echo html_writer::end_tag('div');
    // End of coursebox div
}
 public function test_highlight()
 {
     $this->assertSame('This is <span class="highlight">good</span>', highlight('good', 'This is good'));
     $this->assertSame('<span class="highlight">span</span>', highlight('SpaN', 'span'));
     $this->assertSame('<span class="highlight">SpaN</span>', highlight('span', 'SpaN'));
     $this->assertSame('<span><span class="highlight">span</span></span>', highlight('span', '<span>span</span>'));
     $this->assertSame('He <span class="highlight">is</span> <span class="highlight">good</span>', highlight('good is', 'He is good'));
     $this->assertSame('This is <span class="highlight">good</span>', highlight('+good', 'This is good'));
     $this->assertSame('This is good', highlight('-good', 'This is good'));
     $this->assertSame('This is goodness', highlight('+good', 'This is goodness'));
     $this->assertSame('This is <span class="highlight">good</span>ness', highlight('good', 'This is goodness'));
     $this->assertSame('<p><b>test</b> <b>1</b></p><p><b>1</b></p>', highlight('test 1', '<p>test 1</p><p>1</p>', false, '<b>', '</b>'));
     $this->assertSame('<p><b>test</b> <b>1</b></p><p><b>1</b></p>', highlight('test +1', '<p>test 1</p><p>1</p>', false, '<b>', '</b>'));
     $this->assertSame('<p><b>test</b> 1</p><p>1</p>', highlight('test -1', '<p>test 1</p><p>1</p>', false, '<b>', '</b>'));
 }
Esempio n. 18
0
/**
 * Print a forum post
 *
 * @global object
 * @global object
 * @uses FORUM_MODE_THREADED
 * @uses PORTFOLIO_FORMAT_PLAINHTML
 * @uses PORTFOLIO_FORMAT_FILE
 * @uses PORTFOLIO_FORMAT_RICHHTML
 * @uses PORTFOLIO_ADD_TEXT_LINK
 * @uses CONTEXT_MODULE
 * @param object $post The post to print.
 * @param object $discussion
 * @param object $forum
 * @param object $cm
 * @param object $course
 * @param boolean $ownpost Whether this post belongs to the current user.
 * @param boolean $reply Whether to print a 'reply' link at the bottom of the message.
 * @param boolean $link Just print a shortened version of the post as a link to the full post.
 * @param string $footer Extra stuff to print after the message.
 * @param string $highlight Space-separated list of terms to highlight.
 * @param int $post_read true, false or -99. If we already know whether this user
 *          has read this post, pass that in, otherwise, pass in -99, and this
 *          function will work it out.
 * @param boolean $dummyifcantsee When forum_user_can_see_post says that
 *          the current user can't see this post, if this argument is true
 *          (the default) then print a dummy 'you can't see this post' post.
 *          If false, don't output anything at all.
 * @param bool|null $istracked
 * @return void
 */
function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost = false, $reply = false, $link = false, $footer = "", $highlight = "", $postisread = null, $dummyifcantsee = true, $istracked = null, $return = false)
{
    global $USER, $CFG, $OUTPUT;
    require_once $CFG->libdir . '/filelib.php';
    // String cache
    static $str;
    // This is an extremely hacky way to ensure we only print the 'unread' anchor
    // the first time we encounter an unread post on a page. Ideally this would
    // be moved into the caller somehow, and be better testable. But at the time
    // of dealing with this bug, this static workaround was the most surgical and
    // it fits together with only printing th unread anchor id once on a given page.
    static $firstunreadanchorprinted = false;
    $modcontext = context_module::instance($cm->id);
    $post->course = $course->id;
    $post->forum = $forum->id;
    $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id);
    if (!empty($CFG->enableplagiarism)) {
        require_once $CFG->libdir . '/plagiarismlib.php';
        $post->message .= plagiarism_get_links(array('userid' => $post->userid, 'content' => $post->message, 'cmid' => $cm->id, 'course' => $post->course, 'forum' => $post->forum));
    }
    // caching
    if (!isset($cm->cache)) {
        $cm->cache = new stdClass();
    }
    if (!isset($cm->cache->caps)) {
        $cm->cache->caps = array();
        $cm->cache->caps['mod/forum:viewdiscussion'] = has_capability('mod/forum:viewdiscussion', $modcontext);
        $cm->cache->caps['moodle/site:viewfullnames'] = has_capability('moodle/site:viewfullnames', $modcontext);
        $cm->cache->caps['mod/forum:editanypost'] = has_capability('mod/forum:editanypost', $modcontext);
        $cm->cache->caps['mod/forum:splitdiscussions'] = has_capability('mod/forum:splitdiscussions', $modcontext);
        $cm->cache->caps['mod/forum:deleteownpost'] = has_capability('mod/forum:deleteownpost', $modcontext);
        $cm->cache->caps['mod/forum:deleteanypost'] = has_capability('mod/forum:deleteanypost', $modcontext);
        $cm->cache->caps['mod/forum:viewanyrating'] = has_capability('mod/forum:viewanyrating', $modcontext);
        $cm->cache->caps['mod/forum:exportpost'] = has_capability('mod/forum:exportpost', $modcontext);
        $cm->cache->caps['mod/forum:exportownpost'] = has_capability('mod/forum:exportownpost', $modcontext);
    }
    if (!isset($cm->uservisible)) {
        $cm->uservisible = \core_availability\info_module::is_user_visible($cm, 0, false);
    }
    if ($istracked && is_null($postisread)) {
        $postisread = forum_tp_is_post_read($USER->id, $post);
    }
    if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) {
        $output = '';
        if (!$dummyifcantsee) {
            if ($return) {
                return $output;
            }
            echo $output;
            return;
        }
        $output .= html_writer::tag('a', '', array('id' => 'p' . $post->id));
        $output .= html_writer::start_tag('div', array('class' => 'forumpost clearfix', 'role' => 'region', 'aria-label' => get_string('hiddenforumpost', 'forum')));
        $output .= html_writer::start_tag('div', array('class' => 'row header'));
        $output .= html_writer::tag('div', '', array('class' => 'left picture'));
        // Picture
        if ($post->parent) {
            $output .= html_writer::start_tag('div', array('class' => 'topic'));
        } else {
            $output .= html_writer::start_tag('div', array('class' => 'topic starter'));
        }
        $output .= html_writer::tag('div', get_string('forumsubjecthidden', 'forum'), array('class' => 'subject', 'role' => 'header'));
        // Subject.
        $output .= html_writer::tag('div', get_string('forumauthorhidden', 'forum'), array('class' => 'author', 'role' => 'header'));
        // Author.
        $output .= html_writer::end_tag('div');
        $output .= html_writer::end_tag('div');
        // row
        $output .= html_writer::start_tag('div', array('class' => 'row'));
        $output .= html_writer::tag('div', '&nbsp;', array('class' => 'left side'));
        // Groups
        $output .= html_writer::tag('div', get_string('forumbodyhidden', 'forum'), array('class' => 'content'));
        // Content
        $output .= html_writer::end_tag('div');
        // row
        $output .= html_writer::end_tag('div');
        // forumpost
        if ($return) {
            return $output;
        }
        echo $output;
        return;
    }
    if (empty($str)) {
        $str = new stdClass();
        $str->edit = get_string('edit', 'forum');
        $str->delete = get_string('delete', 'forum');
        $str->reply = get_string('reply', 'forum');
        $str->parent = get_string('parent', 'forum');
        $str->pruneheading = get_string('pruneheading', 'forum');
        $str->prune = get_string('prune', 'forum');
        $str->displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
        $str->markread = get_string('markread', 'forum');
        $str->markunread = get_string('markunread', 'forum');
    }
    $discussionlink = new moodle_url('/mod/forum/discuss.php', array('d' => $post->discussion));
    // Build an object that represents the posting user
    $postuser = new stdClass();
    $postuserfields = explode(',', user_picture::fields());
    $postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
    $postuser->id = $post->userid;
    $postuser->fullname = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']);
    $postuser->profilelink = new moodle_url('/user/view.php', array('id' => $post->userid, 'course' => $course->id));
    // Prepare the groups the posting user belongs to
    if (isset($cm->cache->usersgroups)) {
        $groups = array();
        if (isset($cm->cache->usersgroups[$post->userid])) {
            foreach ($cm->cache->usersgroups[$post->userid] as $gid) {
                $groups[$gid] = $cm->cache->groups[$gid];
            }
        }
    } else {
        $groups = groups_get_all_groups($course->id, $post->userid, $cm->groupingid);
    }
    // Prepare the attachements for the post, files then images
    list($attachments, $attachedimages) = forum_print_attachments($post, $cm, 'separateimages');
    // Determine if we need to shorten this post
    $shortenpost = $link && strlen(strip_tags($post->message)) > $CFG->forum_longpost;
    // Prepare an array of commands
    $commands = array();
    // Add a permalink.
    $permalink = new moodle_url($discussionlink);
    $permalink->set_anchor('p' . $post->id);
    $commands[] = array('url' => $permalink, 'text' => get_string('permalink', 'forum'));
    // SPECIAL CASE: The front page can display a news item post to non-logged in users.
    // Don't display the mark read / unread controls in this case.
    if ($istracked && $CFG->forum_usermarksread && isloggedin()) {
        $url = new moodle_url($discussionlink, array('postid' => $post->id, 'mark' => 'unread'));
        $text = $str->markunread;
        if (!$postisread) {
            $url->param('mark', 'read');
            $text = $str->markread;
        }
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p' . $post->id);
        }
        $commands[] = array('url' => $url, 'text' => $text);
    }
    // Zoom in to the parent specifically
    if ($post->parent) {
        $url = new moodle_url($discussionlink);
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p' . $post->parent);
        }
        $commands[] = array('url' => $url, 'text' => $str->parent);
    }
    // Hack for allow to edit news posts those are not displayed yet until they are displayed
    $age = time() - $post->created;
    if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
        $age = 0;
    }
    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        if (has_capability('moodle/course:manageactivities', $modcontext)) {
            // The first post in single simple is the forum description.
            $commands[] = array('url' => new moodle_url('/course/modedit.php', array('update' => $cm->id, 'sesskey' => sesskey(), 'return' => 1)), 'text' => $str->edit);
        }
    } else {
        if ($ownpost && $age < $CFG->maxeditingtime || $cm->cache->caps['mod/forum:editanypost']) {
            $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('edit' => $post->id)), 'text' => $str->edit);
        }
    }
    if ($cm->cache->caps['mod/forum:splitdiscussions'] && $post->parent && $forum->type != 'single') {
        $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('prune' => $post->id)), 'text' => $str->prune, 'title' => $str->pruneheading);
    }
    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        // Do not allow deleting of first post in single simple type.
    } else {
        if ($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost'] || $cm->cache->caps['mod/forum:deleteanypost']) {
            $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('delete' => $post->id)), 'text' => $str->delete);
        }
    }
    if ($reply) {
        $commands[] = array('url' => new moodle_url('/mod/forum/post.php#mformforum', array('reply' => $post->id)), 'text' => $str->reply);
    }
    if ($CFG->enableportfolios && ($cm->cache->caps['mod/forum:exportpost'] || $ownpost && $cm->cache->caps['mod/forum:exportownpost'])) {
        $p = array('postid' => $post->id);
        require_once $CFG->libdir . '/portfoliolib.php';
        $button = new portfolio_add_button();
        $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id), 'mod_forum');
        if (empty($attachments)) {
            $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
        } else {
            $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
        }
        $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
        if (!empty($porfoliohtml)) {
            $commands[] = $porfoliohtml;
        }
    }
    // Finished building commands
    // Begin output
    $output = '';
    if ($istracked) {
        if ($postisread) {
            $forumpostclass = ' read';
        } else {
            $forumpostclass = ' unread';
            // If this is the first unread post printed then give it an anchor and id of unread.
            if (!$firstunreadanchorprinted) {
                $output .= html_writer::tag('a', '', array('id' => 'unread'));
                $firstunreadanchorprinted = true;
            }
        }
    } else {
        // ignore trackign status if not tracked or tracked param missing
        $forumpostclass = '';
    }
    $topicclass = '';
    if (empty($post->parent)) {
        $topicclass = ' firstpost starter';
    }
    if (!empty($post->lastpost)) {
        $forumpostclass .= ' lastpost';
    }
    // Flag to indicate whether we should hide the author or not.
    $authorhidden = forum_is_author_hidden($post, $forum);
    $postbyuser = new stdClass();
    $postbyuser->post = $post->subject;
    $postbyuser->user = $postuser->fullname;
    $discussionbyuser = get_string('postbyuser', 'forum', $postbyuser);
    $output .= html_writer::tag('a', '', array('id' => 'p' . $post->id));
    // Begin forum post.
    $output .= html_writer::start_div('forumpost clearfix' . $forumpostclass . $topicclass, ['role' => 'region', 'aria-label' => $discussionbyuser]);
    // Begin header row.
    $output .= html_writer::start_div('row header clearfix');
    // User picture.
    if (!$authorhidden) {
        $picture = $OUTPUT->user_picture($postuser, ['courseid' => $course->id]);
        $output .= html_writer::div($picture, 'left picture');
        $topicclass = 'topic' . $topicclass;
    }
    // Begin topic column.
    $output .= html_writer::start_div($topicclass);
    $postsubject = $post->subject;
    if (empty($post->subjectnoformat)) {
        $postsubject = format_string($postsubject);
    }
    $output .= html_writer::div($postsubject, 'subject', ['role' => 'heading', 'aria-level' => '2']);
    if ($authorhidden) {
        $bytext = userdate($post->modified);
    } else {
        $by = new stdClass();
        $by->date = userdate($post->modified);
        $by->name = html_writer::link($postuser->profilelink, $postuser->fullname);
        $bytext = get_string('bynameondate', 'forum', $by);
    }
    $bytextoptions = ['role' => 'heading', 'aria-level' => '2'];
    $output .= html_writer::div($bytext, 'author', $bytextoptions);
    // End topic column.
    $output .= html_writer::end_div();
    // End header row.
    $output .= html_writer::end_div();
    // Row with the forum post content.
    $output .= html_writer::start_div('row maincontent clearfix');
    // Show if author is not hidden or we have groups.
    if (!$authorhidden || $groups) {
        $output .= html_writer::start_div('left');
        $groupoutput = '';
        if ($groups) {
            $groupoutput = print_group_picture($groups, $course->id, false, true, true);
        }
        if (empty($groupoutput)) {
            $groupoutput = '&nbsp;';
        }
        $output .= html_writer::div($groupoutput, 'grouppictures');
        $output .= html_writer::end_div();
        // Left side.
    }
    $output .= html_writer::start_tag('div', array('class' => 'no-overflow'));
    $output .= html_writer::start_tag('div', array('class' => 'content'));
    $options = new stdClass();
    $options->para = false;
    $options->trusted = $post->messagetrust;
    $options->context = $modcontext;
    if ($shortenpost) {
        // Prepare shortened version by filtering the text then shortening it.
        $postclass = 'shortenedpost';
        $postcontent = format_text($post->message, $post->messageformat, $options);
        $postcontent = shorten_text($postcontent, $CFG->forum_shortpost);
        $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum'));
        $postcontent .= html_writer::tag('div', '(' . get_string('numwords', 'moodle', count_words($post->message)) . ')', array('class' => 'post-word-count'));
    } else {
        // Prepare whole post
        $postclass = 'fullpost';
        $postcontent = format_text($post->message, $post->messageformat, $options, $course->id);
        if (!empty($highlight)) {
            $postcontent = highlight($highlight, $postcontent);
        }
        if (!empty($forum->displaywordcount)) {
            $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)), array('class' => 'post-word-count'));
        }
        $postcontent .= html_writer::tag('div', $attachedimages, array('class' => 'attachedimages'));
    }
    // Output the post content
    $output .= html_writer::tag('div', $postcontent, array('class' => 'posting ' . $postclass));
    $output .= html_writer::end_tag('div');
    // Content
    $output .= html_writer::end_tag('div');
    // Content mask
    $output .= html_writer::end_tag('div');
    // Row
    $output .= html_writer::start_tag('div', array('class' => 'row side'));
    $output .= html_writer::tag('div', '&nbsp;', array('class' => 'left'));
    $output .= html_writer::start_tag('div', array('class' => 'options clearfix'));
    if (!empty($attachments)) {
        $output .= html_writer::tag('div', $attachments, array('class' => 'attachments'));
    }
    // Output ratings
    if (!empty($post->rating)) {
        $output .= html_writer::tag('div', $OUTPUT->render($post->rating), array('class' => 'forum-post-rating'));
    }
    // Output the commands
    $commandhtml = array();
    foreach ($commands as $command) {
        if (is_array($command)) {
            $commandhtml[] = html_writer::link($command['url'], $command['text']);
        } else {
            $commandhtml[] = $command;
        }
    }
    $output .= html_writer::tag('div', implode(' | ', $commandhtml), array('class' => 'commands'));
    // Output link to post if required
    if ($link) {
        if (forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
            $langstring = 'discussthistopic';
        } else {
            $langstring = 'viewthediscussion';
        }
        if ($post->replies == 1) {
            $replystring = get_string('repliesone', 'forum', $post->replies);
        } else {
            $replystring = get_string('repliesmany', 'forum', $post->replies);
        }
        if (!empty($discussion->unread) && $discussion->unread !== '-') {
            $replystring .= ' <span class="sep">/</span> <span class="unread">';
            if ($discussion->unread == 1) {
                $replystring .= get_string('unreadpostsone', 'forum');
            } else {
                $replystring .= get_string('unreadpostsnumber', 'forum', $discussion->unread);
            }
            $replystring .= '</span>';
        }
        $output .= html_writer::start_tag('div', array('class' => 'link'));
        $output .= html_writer::link($discussionlink, get_string($langstring, 'forum'));
        $output .= '&nbsp;(' . $replystring . ')';
        $output .= html_writer::end_tag('div');
        // link
    }
    // Output footer if required
    if ($footer) {
        $output .= html_writer::tag('div', $footer, array('class' => 'footer'));
    }
    // Close remaining open divs
    $output .= html_writer::end_tag('div');
    // content
    $output .= html_writer::end_tag('div');
    // row
    $output .= html_writer::end_tag('div');
    // forumpost
    // Mark the forum post as read if required
    if ($istracked && !$CFG->forum_usermarksread && !$postisread) {
        forum_tp_mark_post_read($USER->id, $post, $forum->id);
    }
    if ($return) {
        return $output;
    }
    echo $output;
    return;
}
Esempio n. 19
0
 private function text_clean($text, $for = 'www_body')
 {
     // this is real crap.
     global $settings, $session;
     // clean only for www. rss uses the CDATA structure which does not require escaping
     if ($for == 'www_body' || $for == 'www_comment') {
         $text = htmlspecialchars($text);
     }
     // mark the search criterium
     if ($session->search && ($for == 'www_body' || $for == 'www_comment')) {
         $text = highlight($text, $session->search);
     }
     // clean special chars from copypasting from irc
     $text = preg_replace('/[\\x00-\\x09\\x0b-\\x1F\\x7F]/', '', $text);
     // delete timestamps
     $text = preg_replace('/^[\\(\\[]?\\d+:\\d+(:\\d+)?[\\)\\]]?\\s/m', '', $text);
     if ($for == 'www_body' || $for == 'rss_body' || $for == 'rss_title' || $for == 'excerpt') {
         // add * to mark actions, joins, parts etc
         $text = preg_replace('/^([a-z0-9\\[\\]\\{\\}_])/smi', '* $1', $text);
         // :D
     }
     // hack for this db. old quotes came this way. so remove this once it's fixed or remove it if you start with a db from scratch.
     $text = preg_replace("/^\n/", '', $text);
     if ($for == 'www_body') {
         // nicks for the website
         $text = preg_replace_callback('/^&lt;[@\\+\\s]?([a-z0-9\\-\\[\\]\\{\\}_`~\\|]+)&gt;/mi', array($this, 'nick_colour'), $text);
     }
     if ($for == 'rss_body' || $for == 'rss_title') {
         // escape the cdata structure (avoid injections) + nicks for rss
         // nicks for rss never use < or &lt; because they DON'T WORK for rss readers
         // < works for some, &lt; for some... so we use ()
         $text = str_replace(']]>', ']]]]><![CDATA[>', $text);
         // http://en.wikipedia.org/wiki/CDATA#Nesting
         $text = preg_replace('/<[@\\+\\s]?([a-z0-9\\-\\[\\]\\{\\}_`~\\|]+)>/msi', '($1)', $text);
     }
     if ($for == 'excerpt') {
         $text = preg_replace('/<[@\\+\\s]?([a-z0-9\\-\\[\\]\\{\\}_`~\\|]+)>/msi', '<$1>', $text);
     }
     if ($for == 'www_body' || $for == 'rss_body' || $for == 'www_comment') {
         // don't add links to rss titles!
         $text = format_link($text);
         $text = str_replace("\n", '<br />', $text);
         // respect \s\s to fix asciis
         $text = format_whitespace($text);
     } else {
         $text = str_replace("\n", ' ', $text);
     }
     // cut long title
     if ($for == 'rss_title' || $for == 'www_tweet' || $for == 'excerpt') {
         if (mb_strlen($text) > 110) {
             $text = sprintf('%s...', mb_substr($text, 0, 110));
         }
     }
     return $text;
 }
Esempio n. 20
0
while ($result && ($row = mysql_fetch_assoc($result))) {
    $contribArray = array();
    $result2 = mysql_query("SELECT tirwContributors.firstname, tirwContributors.lastname, tirwContributors.biography \r\n                            FROM tirwContributors, tirwRelationalArticlesToAuthors\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE tirwRelationalArticlesToAuthors.tirwArticleId = " . $row['tirwArticleId'] . "\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND tirwContributors.tirwContributorId = tirwRelationalArticlesToAuthors.tirwContributorId\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY tirwContributors.tirwContributorId ASC");
    while ($result2 && ($row2 = mysql_fetch_assoc($result2))) {
        $contribArray[] = array("name" => fullName($row2['firstname'], $row2['lastname']), "bio" => $row2['biography']);
    }
    echo '<h4><a href="' . $row['url'] . '">' . highlight($row['title'], $search) . '</a></h4>' . "\n";
    echo '<p>';
    echo '<span style="color:green;">' . $row['url'] . '</span> - ' . highlight($row['year'], $search) . '<br />';
    foreach ($contribArray as $contrib) {
        echo '<strong>' . highlight($contrib['name'], $search) . '</strong>';
        if (!empty($contrib['bio'])) {
            if (substr($contrib['bio'], 0, 7) == 'http://') {
                echo ' (<a href="' . $contrib['bio'] . '" target="_bla nk">' . highlight($contrib['bio'], $search) . '</a>)';
            } else {
                echo '<br />' . highlight($contrib['bio'], $search);
            }
        }
        echo '<br />';
    }
    echo '</p>' . "\n";
}
?>
 </td>
</tr>
<?php 
include 'inc/html_copyright.php';
?>
</table>
<?php 
include 'inc/html_footer.php';
Esempio n. 21
0
function highlight($str, $key)
{
    if (is_array($key)) {
        foreach ($key as $k) {
            $str = highlight($str, trim($k));
        }
        return $str;
    } else {
        if (is_string($key)) {
            if ($key == '') {
                return $str;
            }
            //return(str_ireplace($key,'<span style="color:#f00;font-weight:bold;text-decoration:underline">'.$key.'</span>',$str));
            return preg_replace("/({$key})/isU", "<span style=\"color:#f00;font-weight:bold;text-decoration:underline\">\$1</span>", $str);
        }
    }
    return $str;
}
Esempio n. 22
0
/**
 * takes a list of records, the current data, a search string,
 * and mode to display prints the translated template
 *
 * @global object
 * @global object
 * @param string $template
 * @param array $records
 * @param object $data
 * @param string $search
 * @param int $page
 * @param bool $return
 * @param object $jumpurl a moodle_url by which to jump back to the record list (can be null)
 * @return mixed
 */
function data_print_template($template, $records, $data, $search = '', $page = 0, $return = false, moodle_url $jumpurl = null)
{
    global $CFG, $DB, $OUTPUT;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = context_module::instance($cm->id);
    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;
    if (empty($dataid)) {
        $dataid = $data->id;
    } else {
        if ($dataid != $data->id) {
            $fields = NULL;
        }
    }
    if (empty($fields)) {
        $fieldrecords = $DB->get_records('data_fields', array('dataid' => $data->id));
        foreach ($fieldrecords as $fieldrecord) {
            $fields[] = data_get_field($fieldrecord, $data);
        }
        $isteacher = has_capability('mod/data:managetemplates', $context);
    }
    if (empty($records)) {
        return;
    }
    if (!$jumpurl) {
        $jumpurl = new moodle_url('/mod/data/view.php', array('d' => $data->id));
    }
    $jumpurl = new moodle_url($jumpurl, array('page' => $page, 'sesskey' => sesskey()));
    // Check whether this activity is read-only at present
    $readonly = data_in_readonly_period($data);
    foreach ($records as $record) {
        // Might be just one for the single template
        // Replacing tags
        $patterns = array();
        $replacement = array();
        // Then we generate strings to replace for normal tags
        foreach ($fields as $field) {
            $patterns[] = '[[' . $field->field->name . ']]';
            $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
        }
        $canmanageentries = has_capability('mod/data:manageentries', $context);
        // Replacing special tags (##Edit##, ##Delete##, ##More##)
        $patterns[] = '##edit##';
        $patterns[] = '##delete##';
        if ($canmanageentries || !$readonly && data_isowner($record->id)) {
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id . '&amp;rid=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>';
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;delete=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>';
        } else {
            $replacement[] = '';
            $replacement[] = '';
        }
        $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;rid=' . $record->id;
        if ($search) {
            $moreurl .= '&amp;filter=1';
        }
        $patterns[] = '##more##';
        $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('t/preview') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>';
        $patterns[] = '##moreurl##';
        $replacement[] = $moreurl;
        $patterns[] = '##delcheck##';
        if ($canmanageentries) {
            $replacement[] = html_writer::checkbox('delcheck[]', $record->id, false, '', array('class' => 'recordcheckbox'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##user##';
        $replacement[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->userid . '&amp;course=' . $data->course . '">' . fullname($record) . '</a>';
        $patterns[] = '##userpicture##';
        $ruser = user_picture::unalias($record, null, 'userid');
        $replacement[] = $OUTPUT->user_picture($ruser, array('courseid' => $data->course));
        $patterns[] = '##export##';
        if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') && (has_capability('mod/data:exportentry', $context) || data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))) {
            require_once $CFG->libdir . '/portfoliolib.php';
            $button = new portfolio_add_button();
            $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), 'mod_data');
            list($formats, $files) = data_portfolio_caller::formats($fields, $record);
            $button->set_formats($formats);
            $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##timeadded##';
        $replacement[] = userdate($record->timecreated);
        $patterns[] = '##timemodified##';
        $replacement[] = userdate($record->timemodified);
        $patterns[] = '##approve##';
        if (has_capability('mod/data:approve', $context) && $data->approval && !$record->approved) {
            $approveurl = new moodle_url($jumpurl, array('approve' => $record->id));
            $approveicon = new pix_icon('t/approve', get_string('approve', 'data'), '', array('class' => 'iconsmall'));
            $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($approveurl, $approveicon), array('class' => 'approve'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##disapprove##';
        if (has_capability('mod/data:approve', $context) && $data->approval && $record->approved) {
            $disapproveurl = new moodle_url($jumpurl, array('disapprove' => $record->id));
            $disapproveicon = new pix_icon('t/block', get_string('disapprove', 'data'), '', array('class' => 'iconsmall'));
            $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($disapproveurl, $disapproveicon), array('class' => 'disapprove'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##comments##';
        if ($template == 'listtemplate' && $data->comments) {
            if (!empty($CFG->usecomments)) {
                require_once $CFG->dirroot . '/comment/lib.php';
                list($context, $course, $cm) = get_context_info_array($context->id);
                $cmt = new stdClass();
                $cmt->context = $context;
                $cmt->course = $course;
                $cmt->cm = $cm;
                $cmt->area = 'database_entry';
                $cmt->itemid = $record->id;
                $cmt->showcount = true;
                $cmt->component = 'mod_data';
                $comment = new comment($cmt);
                $replacement[] = $comment->output(true);
            }
        } else {
            $replacement[] = '';
        }
        // actual replacement of the tags
        $newtext = str_ireplace($patterns, $replacement, $data->{$template});
        // no more html formatting and filtering - see MDL-6635
        if ($return) {
            return $newtext;
        } else {
            echo $newtext;
            // hack alert - return is always false in singletemplate anyway ;-)
            /**********************************
             *    Printing Ratings Form       *
             *********************************/
            if ($template == 'singletemplate') {
                //prints ratings options
                data_print_ratings($data, $record);
            }
            /**********************************
             *    Printing Comments Form       *
             *********************************/
            if ($template == 'singletemplate' && $data->comments) {
                if (!empty($CFG->usecomments)) {
                    require_once $CFG->dirroot . '/comment/lib.php';
                    list($context, $course, $cm) = get_context_info_array($context->id);
                    $cmt = new stdClass();
                    $cmt->context = $context;
                    $cmt->course = $course;
                    $cmt->cm = $cm;
                    $cmt->area = 'database_entry';
                    $cmt->itemid = $record->id;
                    $cmt->showcount = true;
                    $cmt->component = 'mod_data';
                    $comment = new comment($cmt);
                    $comment->output(false);
                }
            }
        }
    }
}
Esempio n. 23
0
?>
'>
<?php 
if (ET::$session->user) {
    ?>
<div class='col-star'><?php 
    echo star($conversation["conversationId"], $conversation["starred"]);
    ?>
</div>
<?php 
}
?>
<div class='col-conversation'><?php 
$conversationURL = conversationURL($conversation["conversationId"], $conversation["title"]);
// Output the conversation title, highlighting search keywords.
echo "<strong class='title'><a href='" . URL($conversationURL . ((ET::$session->user and $conversation["unread"]) ? "/unread" : "")) . "'>" . highlight(sanitizeHTML($conversation["title"]), ET::$session->get("highlight")) . "</a></strong> ";
// Output the conversation's labels.
echo "<span class='labels'>";
foreach ($conversation["labels"] as $label) {
    if ($label == "draft") {
        echo "<a href='" . URL($conversationURL . "#reply") . "' class='label label-{$label}'>" . T("label.{$label}") . "</a> ";
    } else {
        echo "<span class='label label-{$label}'>" . T("label.{$label}") . "</span> ";
    }
}
echo "</span> ";
// Output controls which apply to this conversation.
echo "<span class='controls'>";
// If we're highlighting search terms (i.e. if we did a fulltext search), then output a "show matching posts" link.
if (ET::$session->get("highlight")) {
    echo " <a href='" . URL($conversationURL . "/?search=" . urlencode($data["fulltextString"])) . "' class='showMatchingPosts'>" . T("Show matching posts") . "</a>";
            echo $company->getName();
            ?>
</a></div>
    <div class="contactDetails">
      <div class="contactInfo">
  <?php 
            if (trim($contact->getEmail()) != '') {
                ?>
        <div><span><?php 
                echo lang('email address');
                ?>
:</span> <a href="mailto:<?php 
                echo $contact->getEmail();
                ?>
"><?php 
                echo highlight($search_term, $contact->getEmail());
                ?>
</a></div>
  <?php 
            }
            // if
            ?>
  <?php 
            if (trim($contact->getOfficeNumber()) != '') {
                ?>
        <div><span><?php 
                echo lang('office phone number');
                ?>
:</span> <?php 
                echo clean($contact->getOfficeNumber());
                ?>
Esempio n. 25
0
 /**
  * Builds the XHTML to display the control
  *
  * @param string $data Unused
  * @param string $query
  * @return string
  */
 public function output_html($data, $query = '')
 {
     global $CFG, $OUTPUT, $DB, $USER;
     // display strings
     $stroperation = get_string('operation', 'webservice');
     $strtoken = get_string('token', 'webservice');
     $strservice = get_string('service', 'webservice');
     $struser = get_string('user');
     $strcontext = get_string('context', 'webservice');
     $strvaliduntil = get_string('validuntil', 'webservice');
     $striprestriction = get_string('iprestriction', 'webservice');
     $return = $OUTPUT->box_start('generalbox webservicestokenui');
     $table = new html_table();
     $table->head = array($strtoken, $struser, $strservice, $striprestriction, $strvaliduntil, $stroperation);
     $table->align = array('left', 'left', 'left', 'center', 'center', 'center');
     $table->width = '100%';
     $table->data = array();
     $tokenpageurl = "{$CFG->wwwroot}/{$CFG->admin}/webservice/tokens.php?sesskey=" . sesskey();
     //TODO: in order to let the administrator delete obsolete token, split this request in multiple request or use LEFT JOIN
     //here retrieve token list (including linked users firstname/lastname and linked services name)
     $sql = "SELECT t.id, t.token, u.id AS userid, u.firstname, u.lastname, s.name, t.iprestriction, t.validuntil, s.id AS serviceid\n                  FROM {external_tokens} t, {user} u, {external_services} s\n                 WHERE t.creatorid=? AND t.tokentype = ? AND s.id = t.externalserviceid AND t.userid = u.id";
     $tokens = $DB->get_records_sql($sql, array($USER->id, EXTERNAL_TOKEN_PERMANENT));
     if (!empty($tokens)) {
         foreach ($tokens as $token) {
             //TODO: retrieve context
             $delete = "<a href=\"" . $tokenpageurl . "&amp;action=delete&amp;tokenid=" . $token->id . "\">";
             $delete .= get_string('delete') . "</a>";
             $validuntil = '';
             if (!empty($token->validuntil)) {
                 $validuntil = date("F j, Y");
                 //TODO: language support (look for moodle function)
             }
             $iprestriction = '';
             if (!empty($token->iprestriction)) {
                 $iprestriction = $token->iprestriction;
             }
             $userprofilurl = new moodle_url('/user/profile.php?id=' . $token->userid);
             $useratag = html_writer::start_tag('a', array('href' => $userprofilurl));
             $useratag .= $token->firstname . " " . $token->lastname;
             $useratag .= html_writer::end_tag('a');
             //check user missing capabilities
             require_once $CFG->dirroot . '/webservice/lib.php';
             $webservicemanager = new webservice();
             $usermissingcaps = $webservicemanager->get_missing_capabilities_by_users(array(array('id' => $token->userid)), $token->serviceid);
             if (!is_siteadmin($token->userid) and key_exists($token->userid, $usermissingcaps)) {
                 $missingcapabilities = implode(', ', $usermissingcaps[$token->userid]);
                 if (!empty($missingcapabilities)) {
                     $useratag .= html_writer::tag('div', get_string('usermissingcaps', 'webservice', $missingcapabilities) . '&nbsp;' . $OUTPUT->help_icon('missingcaps', 'webservice'), array('class' => 'missingcaps'));
                 }
             }
             $table->data[] = array($token->token, $useratag, $token->name, $iprestriction, $validuntil, $delete);
         }
         $return .= html_writer::table($table);
     } else {
         $return .= get_string('notoken', 'webservice');
     }
     $return .= $OUTPUT->box_end();
     // add a token to the table
     $return .= "<a href=\"" . $tokenpageurl . "&amp;action=create\">";
     $return .= get_string('add') . "</a>";
     return highlight($query, $return);
 }
Esempio n. 26
0
/**
 * Format a message for display in the message history
 *
 * @param object $message the message object
 * @param string $format optional date format
 * @param string $keywords keywords to highlight
 * @param string $class CSS class to apply to the div around the message
 * @return string the formatted message
 */
function message_format_message($message, $format='', $keywords='', $class='other') {

    static $dateformat;

    //if we haven't previously set the date format or they've supplied a new one
    if ( empty($dateformat) || (!empty($format) && $dateformat != $format) ) {
        if ($format) {
            $dateformat = $format;
        } else {
            $dateformat = get_string('strftimedatetimeshort');
        }
    }
    $time = userdate($message->timecreated, $dateformat);

    $messagetext = message_format_message_text($message, false);

    if ($keywords) {
        $messagetext = highlight($keywords, $messagetext);
    }

    $messagetext .= message_format_contexturl($message);

    $messagetext = clean_text($messagetext, FORMAT_HTML);

    return <<<TEMPLATE
<div class='message $class'>
    <a name="m{$message->id}"></a>
    <span class="message-meta"><span class="time">$time</span></span>: <span class="text">$messagetext</span>
</div>
TEMPLATE;
}
Esempio n. 27
0
?>
'>
<?php 
if (ET::$session->user) {
    ?>
<div class='col-star'><?php 
    echo star($conversation["conversationId"], $conversation["starred"]);
    ?>
</div>
<?php 
}
?>
<div class='col-conversation'><?php 
$conversationURL = conversationURL($conversation["conversationId"], $conversation["title"]);
// Output the conversation title, highlighting search keywords.
echo "<strong class='title'><a href='" . URL($conversationURL) . "'>" . highlight(sanitizeHTML($conversation["title"]), ET::$session->get("highlight")) . "</a></strong> ";
// Output the conversation's labels.
echo "<span class='labels'>";
foreach ($conversation["labels"] as $label) {
    echo "<span class='label label-{$label}'>" . T("label.{$label}") . "</span> ";
}
echo "</span> ";
// Output an "unread indicator", showing the number of unread posts.
if (ET::$session->user and $conversation["unread"]) {
    echo "<a href='" . URL("conversation/markAsRead/" . $conversation["conversationId"] . "?token=" . ET::$session->token . "&return=" . urlencode(ET::$controller->selfURL)) . "' class='unreadIndicator' title='" . T("Mark as read") . "'>" . $conversation["unread"] . "</a> ";
}
// Output controls which apply to this conversation.
echo "<span class='controls'>";
// A Jump to last/unread link, depending on the user and the unread state.
if (ET::$session->user and $conversation["unread"]) {
    echo "<a href='" . URL($conversationURL . "/unread") . "' class='jumpToUnread'>" . T("Jump to unread") . "</a>";
Esempio n. 28
0
/**
 * Format a message for display in the message history
 * @param object $message the message object
 * @param string $format optional date format
 * @param string $keywords keywords to highlight
 * @param string $class CSS class to apply to the div around the message
 * @return string the formatted message
 */
function message_format_message($message, $format='', $keywords='', $class='other') {

    static $dateformat;

    //if we haven't previously set the date format or they've supplied a new one
    if ( empty($dateformat) || (!empty($format) && $dateformat != $format) ) {
        if ($format) {
            $dateformat = $format;
        } else {
            $dateformat = get_string('strftimedatetimeshort');
        }
    }
    $time = userdate($message->timecreated, $dateformat);
    $options = new stdClass();
    $options->para = false;

    //if supplied display small messages as fullmessage may contain boilerplate text that shouldnt appear in the messaging UI
    if (!empty($message->smallmessage)) {
        $messagetext = format_text(s($message->smallmessage), FORMAT_MOODLE, $options);
    } else {
        $messagetext = format_text(s($message->fullmessage), $message->fullmessageformat, $options);
    }

    $messagetext .= message_format_contexturl($message);

    if ($keywords) {
        $messagetext = highlight($keywords, $messagetext);
    }

    return '<div class="message '.$class.'"><a name="m'.$message->id.'"></a> <span class="time">'.$time.'</span>: <span class="content">'.$messagetext.'</span></div>';
}
Esempio n. 29
0
/**
 * Print a forum post
 *
 * @global object
 * @global object
 * @uses FORUM_MODE_THREADED
 * @uses PORTFOLIO_FORMAT_PLAINHTML
 * @uses PORTFOLIO_FORMAT_FILE
 * @uses PORTFOLIO_FORMAT_RICHHTML
 * @uses PORTFOLIO_ADD_TEXT_LINK
 * @uses CONTEXT_MODULE
 * @param object $post The post to print.
 * @param object $discussion
 * @param object $forum
 * @param object $cm
 * @param object $course
 * @param boolean $ownpost Whether this post belongs to the current user.
 * @param boolean $reply Whether to print a 'reply' link at the bottom of the message.
 * @param boolean $link Just print a shortened version of the post as a link to the full post.
 * @param string $footer Extra stuff to print after the message.
 * @param string $highlight Space-separated list of terms to highlight.
 * @param int $post_read true, false or -99. If we already know whether this user
 *          has read this post, pass that in, otherwise, pass in -99, and this
 *          function will work it out.
 * @param boolean $dummyifcantsee When forum_user_can_see_post says that
 *          the current user can't see this post, if this argument is true
 *          (the default) then print a dummy 'you can't see this post' post.
 *          If false, don't output anything at all.
 * @param bool|null $istracked
 * @return void
 */
function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=false, $reply=false, $link=false,
                          $footer="", $highlight="", $postisread=null, $dummyifcantsee=true, $istracked=null, $return=false) {
    global $USER, $CFG, $OUTPUT;

    require_once($CFG->libdir . '/filelib.php');

    // String cache
    static $str;

    $modcontext = context_module::instance($cm->id);

    $post->course = $course->id;
    $post->forum  = $forum->id;
    $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id);
    if (!empty($CFG->enableplagiarism)) {
        require_once($CFG->libdir.'/plagiarismlib.php');
        $post->message .= plagiarism_get_links(array('userid' => $post->userid,
            'content' => $post->message,
            'cmid' => $cm->id,
            'course' => $post->course,
            'forum' => $post->forum));
    }

    // caching
    if (!isset($cm->cache)) {
        $cm->cache = new stdClass;
    }

    if (!isset($cm->cache->caps)) {
        $cm->cache->caps = array();
        $cm->cache->caps['mod/forum:viewdiscussion']   = has_capability('mod/forum:viewdiscussion', $modcontext);
        $cm->cache->caps['moodle/site:viewfullnames']  = has_capability('moodle/site:viewfullnames', $modcontext);
        $cm->cache->caps['mod/forum:editanypost']      = has_capability('mod/forum:editanypost', $modcontext);
        $cm->cache->caps['mod/forum:splitdiscussions'] = has_capability('mod/forum:splitdiscussions', $modcontext);
        $cm->cache->caps['mod/forum:deleteownpost']    = has_capability('mod/forum:deleteownpost', $modcontext);
        $cm->cache->caps['mod/forum:deleteanypost']    = has_capability('mod/forum:deleteanypost', $modcontext);
        $cm->cache->caps['mod/forum:viewanyrating']    = has_capability('mod/forum:viewanyrating', $modcontext);
        $cm->cache->caps['mod/forum:exportpost']       = has_capability('mod/forum:exportpost', $modcontext);
        $cm->cache->caps['mod/forum:exportownpost']    = has_capability('mod/forum:exportownpost', $modcontext);
    }

    if (!isset($cm->uservisible)) {
        $cm->uservisible = coursemodule_visible_for_user($cm);
    }

    if ($istracked && is_null($postisread)) {
        $postisread = forum_tp_is_post_read($USER->id, $post);
    }

    if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) {
        $output = '';
        if (!$dummyifcantsee) {
            if ($return) {
                return $output;
            }
            echo $output;
            return;
        }
        $output .= html_writer::tag('a', '', array('id'=>'p'.$post->id));
        $output .= html_writer::start_tag('div', array('class'=>'forumpost clearfix'));
        $output .= html_writer::start_tag('div', array('class'=>'row header'));
        $output .= html_writer::tag('div', '', array('class'=>'left picture')); // Picture
        if ($post->parent) {
            $output .= html_writer::start_tag('div', array('class'=>'topic'));
        } else {
            $output .= html_writer::start_tag('div', array('class'=>'topic starter'));
        }
        $output .= html_writer::tag('div', get_string('forumsubjecthidden','forum'), array('class'=>'subject')); // Subject
        $output .= html_writer::tag('div', get_string('forumauthorhidden','forum'), array('class'=>'author')); // author
        $output .= html_writer::end_tag('div');
        $output .= html_writer::end_tag('div'); // row
        $output .= html_writer::start_tag('div', array('class'=>'row'));
        $output .= html_writer::tag('div', '&nbsp;', array('class'=>'left side')); // Groups
        $output .= html_writer::tag('div', get_string('forumbodyhidden','forum'), array('class'=>'content')); // Content
        $output .= html_writer::end_tag('div'); // row
        $output .= html_writer::end_tag('div'); // forumpost

        if ($return) {
            return $output;
        }
        echo $output;
        return;
    }

    if (empty($str)) {
        $str = new stdClass;
        $str->edit         = get_string('edit', 'forum');
        $str->delete       = get_string('delete', 'forum');
        $str->reply        = get_string('reply', 'forum');
        $str->parent       = get_string('parent', 'forum');
        $str->pruneheading = get_string('pruneheading', 'forum');
        $str->prune        = get_string('prune', 'forum');
        $str->displaymode     = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
        $str->markread     = get_string('markread', 'forum');
        $str->markunread   = get_string('markunread', 'forum');
    }

    $discussionlink = new moodle_url('/mod/forum/discuss.php', array('d'=>$post->discussion));

    // Build an object that represents the posting user
    $postuser = new stdClass;
    $postuser->id        = $post->userid;
    $postuser->firstname = $post->firstname;
    $postuser->lastname  = $post->lastname;
    $postuser->imagealt  = $post->imagealt;
    $postuser->picture   = $post->picture;
    $postuser->email     = $post->email;
    // Some handy things for later on
    $postuser->fullname    = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']);
    $postuser->profilelink = new moodle_url('/user/view.php', array('id'=>$post->userid, 'course'=>$course->id));

    // Prepare the groups the posting user belongs to
    if (isset($cm->cache->usersgroups)) {
        $groups = array();
        if (isset($cm->cache->usersgroups[$post->userid])) {
            foreach ($cm->cache->usersgroups[$post->userid] as $gid) {
                $groups[$gid] = $cm->cache->groups[$gid];
            }
        }
    } else {
        $groups = groups_get_all_groups($course->id, $post->userid, $cm->groupingid);
    }

    // Prepare the attachements for the post, files then images
    list($attachments, $attachedimages) = forum_print_attachments($post, $cm, 'separateimages');

    // Determine if we need to shorten this post
    $shortenpost = ($link && (strlen(strip_tags($post->message)) > $CFG->forum_longpost));


    // Prepare an array of commands
    $commands = array();

    // SPECIAL CASE: The front page can display a news item post to non-logged in users.
    // Don't display the mark read / unread controls in this case.
    if ($istracked && $CFG->forum_usermarksread && isloggedin()) {
        $url = new moodle_url($discussionlink, array('postid'=>$post->id, 'mark'=>'unread'));
        $text = $str->markunread;
        if (!$postisread) {
            $url->param('mark', 'read');
            $text = $str->markread;
        }
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p'.$post->id);
        }
        $commands[] = array('url'=>$url, 'text'=>$text);
    }

    // Zoom in to the parent specifically
    if ($post->parent) {
        $url = new moodle_url($discussionlink);
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p'.$post->parent);
        }
        $commands[] = array('url'=>$url, 'text'=>$str->parent);
    }

    // Hack for allow to edit news posts those are not displayed yet until they are displayed
    $age = time() - $post->created;
    if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
        $age = 0;
    }

    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        if (has_capability('moodle/course:manageactivities', $modcontext)) {
            // The first post in single simple is the forum description.
            $commands[] = array('url'=>new moodle_url('/course/modedit.php', array('update'=>$cm->id, 'sesskey'=>sesskey(), 'return'=>1)), 'text'=>$str->edit);
        }
    } else if (($ownpost && $age < $CFG->maxeditingtime) || $cm->cache->caps['mod/forum:editanypost']) {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('edit'=>$post->id)), 'text'=>$str->edit);
    }

    if ($cm->cache->caps['mod/forum:splitdiscussions'] && $post->parent && $forum->type != 'single') {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('prune'=>$post->id)), 'text'=>$str->prune, 'title'=>$str->pruneheading);
    }

    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        // Do not allow deleting of first post in single simple type.
    } else if (($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost']) || $cm->cache->caps['mod/forum:deleteanypost']) {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('delete'=>$post->id)), 'text'=>$str->delete);
    }

    if ($reply) {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php#mformforum', array('reply'=>$post->id)), 'text'=>$str->reply);
    }

    if ($CFG->enableportfolios && ($cm->cache->caps['mod/forum:exportpost'] || ($ownpost && $cm->cache->caps['mod/forum:exportownpost']))) {
        $p = array('postid' => $post->id);
        require_once($CFG->libdir.'/portfoliolib.php');
        $button = new portfolio_add_button();
        $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id), 'mod_forum');
        if (empty($attachments)) {
            $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
        } else {
            $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
        }

        $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
        if (!empty($porfoliohtml)) {
            $commands[] = $porfoliohtml;
        }
    }
    // Finished building commands


    // Begin output

    $output  = '';

    if ($istracked) {
        if ($postisread) {
            $forumpostclass = ' read';
        } else {
            $forumpostclass = ' unread';
            $output .= html_writer::tag('a', '', array('name'=>'unread'));
        }
    } else {
        // ignore trackign status if not tracked or tracked param missing
        $forumpostclass = '';
    }

    $topicclass = '';
    if (empty($post->parent)) {
        $topicclass = ' firstpost starter';
    }

    $output .= html_writer::tag('a', '', array('id'=>'p'.$post->id));
    $output .= html_writer::start_tag('div', array('class'=>'forumpost clearfix'.$forumpostclass.$topicclass));
    $output .= html_writer::start_tag('div', array('class'=>'row header clearfix'));
    $output .= html_writer::start_tag('div', array('class'=>'left picture'));
    $output .= $OUTPUT->user_picture($postuser, array('courseid'=>$course->id));
    $output .= html_writer::end_tag('div');


    $output .= html_writer::start_tag('div', array('class'=>'topic'.$topicclass));

    $postsubject = $post->subject;
    if (empty($post->subjectnoformat)) {
        $postsubject = format_string($postsubject);
    }
    $output .= html_writer::tag('div', $postsubject, array('class'=>'subject'));

    $by = new stdClass();
    $by->name = html_writer::link($postuser->profilelink, $postuser->fullname);
    $by->date = userdate($post->modified);
    $output .= html_writer::tag('div', get_string('bynameondate', 'forum', $by), array('class'=>'author'));

    $output .= html_writer::end_tag('div'); //topic
    $output .= html_writer::end_tag('div'); //row

    $output .= html_writer::start_tag('div', array('class'=>'row maincontent clearfix'));
    $output .= html_writer::start_tag('div', array('class'=>'left'));

    $groupoutput = '';
    if ($groups) {
        $groupoutput = print_group_picture($groups, $course->id, false, true, true);
    }
    if (empty($groupoutput)) {
        $groupoutput = '&nbsp;';
    }
    $output .= html_writer::tag('div', $groupoutput, array('class'=>'grouppictures'));

    $output .= html_writer::end_tag('div'); //left side
    $output .= html_writer::start_tag('div', array('class'=>'no-overflow'));
    $output .= html_writer::start_tag('div', array('class'=>'content'));
    if (!empty($attachments)) {
        $output .= html_writer::tag('div', $attachments, array('class'=>'attachments'));
    }

    $options = new stdClass;
    $options->para    = false;
    $options->trusted = $post->messagetrust;
    $options->context = $modcontext;
    if ($shortenpost) {
        // Prepare shortened version
        $postclass    = 'shortenedpost';
        $postcontent  = format_text(forum_shorten_post($post->message), $post->messageformat, $options, $course->id);
        $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum'));
        $postcontent .= html_writer::tag('div', '('.get_string('numwords', 'moodle', count_words($post->message)).')',
            array('class'=>'post-word-count'));
    } else {
        // Prepare whole post
        $postclass    = 'fullpost';
        $postcontent  = format_text($post->message, $post->messageformat, $options, $course->id);
        if (!empty($highlight)) {
            $postcontent = highlight($highlight, $postcontent);
        }
        if (!empty($forum->displaywordcount)) {
            $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)),
                array('class'=>'post-word-count'));
        }
        $postcontent .= html_writer::tag('div', $attachedimages, array('class'=>'attachedimages'));
    }

    // Output the post content
    $output .= html_writer::tag('div', $postcontent, array('class'=>'posting '.$postclass));
    $output .= html_writer::end_tag('div'); // Content
    $output .= html_writer::end_tag('div'); // Content mask
    $output .= html_writer::end_tag('div'); // Row

    $output .= html_writer::start_tag('div', array('class'=>'row side'));
    $output .= html_writer::tag('div','&nbsp;', array('class'=>'left'));
    $output .= html_writer::start_tag('div', array('class'=>'options clearfix'));

    // Output ratings
    if (!empty($post->rating)) {
        $output .= html_writer::tag('div', $OUTPUT->render($post->rating), array('class'=>'forum-post-rating'));
    }

    // Output the commands
    $commandhtml = array();
    foreach ($commands as $command) {
        if (is_array($command)) {
            $commandhtml[] = html_writer::link($command['url'], $command['text']);
        } else {
            $commandhtml[] = $command;
        }
    }
    $output .= html_writer::tag('div', implode(' | ', $commandhtml), array('class'=>'commands'));

    // Output link to post if required
    if ($link) {
        if ($post->replies == 1) {
            $replystring = get_string('repliesone', 'forum', $post->replies);
        } else {
            $replystring = get_string('repliesmany', 'forum', $post->replies);
        }

        $output .= html_writer::start_tag('div', array('class'=>'link'));
        $output .= html_writer::link($discussionlink, get_string('discussthistopic', 'forum'));
        $output .= '&nbsp;('.$replystring.')';
        $output .= html_writer::end_tag('div'); // link
    }

    // Output footer if required
    if ($footer) {
        $output .= html_writer::tag('div', $footer, array('class'=>'footer'));
    }

    // Close remaining open divs
    $output .= html_writer::end_tag('div'); // content
    $output .= html_writer::end_tag('div'); // row
    $output .= html_writer::end_tag('div'); // forumpost

    // Mark the forum post as read if required
    if ($istracked && !$CFG->forum_usermarksread && !$postisread) {
        forum_tp_mark_post_read($USER->id, $post, $forum->id);
    }

    if ($return) {
        return $output;
    }
    echo $output;
    return;
}
Esempio n. 30
0
 $goto = ($page - 1) * $limit;
 $Color = 0;
 $rank = 1;
 $BoardResult = $db->select_query("SELECT * FROM " . TB_WEBBOARD . " {$SQLwhere2} ORDER BY id DESC");
 //$BoardResult = $db->select_query("SELECT *, MATCH(topic, detail,post_name) AGAINST('". $keyword ."') as score FROM pages WHERE MATCH (topic, detail,post_name) AGAINST('". $term ."') ORDER BY score DESC");
 while ($WebBoard = $db->fetch($BoardResult)) {
     if ($Color == 0) {
         $Color = 1;
         $ColorFill = "#FFFFFF";
     } else {
         $Color = 0;
         $ColorFill = "#FFFFFF";
     }
     $topics = highlight("{$keyword}", '<span>' . $WebBoard[topic] . '</span>');
     $details = highlight("{$keyword}", '<span>' . $WebBoard[detail] . '</span>');
     $postnames = highlight("{$keyword}", '<span>' . $WebBoard[post_name] . '</span>');
     $SumComm = $db->num_rows(TB_WEBBOARD_COMMENT, "id", " topic_id='" . $WebBoard[id] . "' ");
     echo "<tr height=\"20\">";
     echo "<td bgcolor=\"" . $ColorFill . "\" width='70%' class='content'><IMG SRC=\"images/icon/dok.gif\" BORDER=\"0\" ALIGN=\"absmiddle\"> <B>" . sprintf("%0" . _NUM_ID . "d", $WebBoard[id]) . " : </B> <A HREF=\"?name=webboard&file=read&id=" . $WebBoard[id] . "\" target=\"_blank\">" . $topics . "</A> ";
     echo "<FONT FACE=\"tahoma\" COLOR=\"#808080\">(" . number_format($WebBoard[pageview]) . "/" . number_format($SumComm) . ")</FONT></td>\n";
     echo "<td bgcolor=\"" . $ColorFill . "\" width=\"15%\"><CENTER><B><FONT COLOR=\"#6600FF\">";
     echo "" . $postnames . "</FONT></B></CENTER></td>\n";
     echo "<td bgcolor=\"" . $ColorFill . "\" width=\"15%\"><CENTER><FONT COLOR=\"#339900\">" . ThaiTimeConvert($WebBoard[post_date], "", "2") . "</FONT></CENTER></td>\n";
     echo "<tr><td colspan=\"4\" height=1 class=\"dotline\"></td></tr>\n";
     $rank++;
 }
 // àÃÔèÁ comment
 $db->connectdb(DB_NAME, DB_USERNAME, DB_PASSWORD);
 //áÊ´§¼Å¡ÃзÙé
 $limit = 20;
 $SUMPAGE = $db->num_rows(TB_WEBBOARD_COMMENT, "id", "(detail like '%{$keyword}%') or (post_name like '%{$keyword}%')");