예제 #1
0
function data_code($pData, $pParams)
{
    // Pre-Clyde Changes
    global $gBitSystem;
    extract($pParams, EXTR_SKIP);
    if (!empty($colors) and $colors == 'php') {
        $source = 'php';
    }
    if (!empty($in)) {
        $source = $in;
    }
    $source = isset($source) ? strtolower($source) : $gBitSystem->getConfig('liberty_plugin_code_default_source', 'php');
    if (!empty($num) && !is_numeric($num)) {
        switch (strtoupper($num)) {
            case 'TRUE':
            case 'ON':
            case 'YES':
                $num = 1;
                break;
            default:
                $num = 0;
                break;
        }
    }
    $num = isset($num) ? $num : FALSE;
    // trim any trailing spaces
    $code = '';
    $lines = explode("\n", $pData);
    foreach ($lines as $line) {
        $code .= rtrim($line) . "\n";
    }
    $code = unHtmlEntities($code);
    // Trim any leading blank lines
    $code = preg_replace('/^[\\n\\r]+/', "", $code);
    // Trim any trailing blank lines
    if (file_exists(UTIL_PKG_PATH . 'geshi/geshi.php')) {
        $code = preg_replace('/[\\n\\r]+$/', "", $code);
    } else {
        $code = preg_replace('/[\\n\\r]+$/', "\n", $code);
    }
    if (file_exists(UTIL_PKG_PATH . 'geshi/geshi.php')) {
        // Include the GeSHi library
        include_once UTIL_PKG_PATH . 'geshi/geshi.php';
        $geshi = new GeSHi($code, $source, UTIL_PKG_PATH . 'geshi/geshi');
        if ($num) {
            // Line Numbering has been requested
            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
            if (is_numeric($num)) {
                $geshi->start_line_numbers_at($num);
            }
        }
        $code = deCodeHTML(htmlentities($geshi->parse_code()));
    } else {
        // Line Numbering has been requested
        if ($num) {
            $lines = explode("\n", $code);
            $code = '';
            //Line Number
            $i = is_numeric($num) ? $num : 1;
            foreach ($lines as $line) {
                if (strlen($line) > 1) {
                    $code .= sprintf("%3d", $i) . ": " . $line . "\n";
                    $i++;
                }
            }
        }
        switch (strtoupper($source)) {
            case 'HTML':
                $code = highlight_string(deCodeHTML($code), TRUE);
                // Remove the first <code>" tags
                if (substr($code, 0, 6) == '<code>') {
                    $code = substr($code, 6, strlen($code) - 13);
                }
                break;
            case 'PHP':
                // Check it if code starts with PHP tags, if not: add 'em.
                if (!preg_match('/^[ 0-9:]*<\\?/i', $code)) {
                    // The require these tags to function
                    $code = "<?php\n" . $code . "?>";
                }
                $code = highlight_string($code, TRUE);
                // Replacement-map to replace Colors
                $convmap = array('#000000">' => '#004A4A">', '#006600">' => '#2020FF">', '#0000CC">' => '#209020">', '#FF9900">' => '#BB4040">', '#CC0000">' => '#903030">');
                // <-- # Assigned by HighLight_String / --> # Color to be Displayed
                // NOTE: The colors assigned by HighLight_String have changed with different versions of PHP - these are for PHP 4.3.4
                // Change the Colors
                $code = strtr($code, $convmap);
                break;
            default:
                $code = highlight_string($code, TRUE);
                break;
        }
        $code = "<pre>{$code}</pre>";
    }
    return (!empty($title) ? '<p class="codetitle">' . $title . '</p>' : "") . "<div class='codelisting'>" . $code . "</div>";
}
예제 #2
0
/**
 * Send email to administrator to notify a new/changed entry.
 *
 * @param   array   $mail_previous  contains deleted entry data forr email body
 * @return  bool    TRUE or PEAR error object if fails
 */
function notifyAdminOnDelete($mail_previous)
{
    global $typel, $enable_periods, $auth, $tbl_users, $CFG;
    //
    $recipients = '';
    MAIL_ADMIN_ON_BOOKINGS ? $recipients = MAIL_RECIPIENTS : '';
    if (MAIL_AREA_ADMIN_ON_BOOKINGS) {
        if ('' != $mail_previous['area_admin_email']) {
            $recipientlist[] = $mail_previous['area_admin_email'];
        }
    }
    if (MAIL_ROOM_ADMIN_ON_BOOKINGS) {
        if ('' != $mail_previous['room_admin_email']) {
            $recipientlist[] = $mail_previous['room_admin_email'];
        }
    }
    if (MAIL_BOOKER) {
        if ('moodle' == $auth['type']) {
            /* It would be possible to move this query within the query in
               getPreviousEntryData to have all in one central place and to
               reduce database hits by one. However this is a bad idea. If a
               user is deleted from your user database, this will prevent all
               mails to admins when this user previously booked entries will
               be changed, as no user name will match the booker name */
            $sql = "SELECT email FROM ";
            $sql .= $CFG->prefix . 'user WHERE username='******'";
            $sql .= $mail_previous['createdby'];
            $sql .= "'";
            $res = sql_query($sql);
            !$res ? fatal_error(0, sql_error()) : '';
            $row = sql_row($res, 0);
            if (NULL != $row[0]) {
                $recipientlist[] = $row[0];
            }
        } else {
            //this should never be the case with the MRBS Moodle block
            if (!empty($recipients) && '' != $mail_previous['createdby']) {
                if ('' != $mail_previous['createdby']) {
                    $recipientlist[] = str_replace(MAIL_USERNAME_SUFFIX, '', $mail_previous['createdby']) . MAIL_DOMAIN;
                }
            }
        }
    }
    // In case mail is allowed but someone forgot to supply email addresses...
    if (sizeof($recipientlist) == 0) {
        return FALSE;
    }
    //
    $subject = get_string('mail_subject_delete', 'block_mrbs');
    $body = get_string('mail_body_del_entry', 'block_mrbs') . ": \n\n";
    // Displays deleted entry details
    $body .= "\n" . get_string('namebooker', 'block_mrbs') . ': ';
    $body .= removeMailUnicode($mail_previous['namebooker']) . "\n";
    $body .= get_string('description') . ": ";
    $body .= removeMailUnicode($mail_previous['description']) . "\n";
    $body .= get_string('room', 'block_mrbs') . ": ";
    $body .= removeMailUnicode($mail_previous['area_name']);
    $body .= " - " . removeMailUnicode($mail_previous['room_name']) . "\n";
    $body .= get_string('start_date', 'block_mrbs') . ': ';
    if ($enable_periods) {
        $body .= unHtmlEntities($mail_previous['start_date']) . "\n";
    } else {
        $body .= $mail_previous['start_date'] . "\n";
    }
    $body .= get_string('duration', 'block_mrbs') . ': ' . $mail_previous['duration'] . ' ';
    $body .= $mail_previous['dur_units'] . "\n";
    if ($enable_periods) {
        $body .= get_string('end_date', 'block_mrbs') . ": ";
        $body .= unHtmlEntities($mail_previous['end_date']) . "\n";
    } else {
        $body .= get_string('end_date', 'block_mrbs') . ": " . $mail_previous['end_date'];
        $body .= "\n";
    }
    $body .= get_string('type', 'block_mrbs') . ": ";
    $body .= empty($typel[$mail_previous['type']]) ? "?" . $mail_previous['type'] . "?" : $typel[$mail_previous['type']];
    $body .= "\n" . get_string('createdby', 'block_mrbs') . ": ";
    $body .= $mail_previous['createdby'] . "\n";
    $body .= get_string('lastmodified') . ": " . $mail_previous['updated'];
    $body .= "\n" . get_string('rep_type', 'block_mrbs');
    $temp = $mail_previous['rep_type'];
    $body .= ": " . get_string('rep_type_' . $temp, 'block_mrbs');
    if ($mail_previous['rep_type'] > 0) {
        if ($mail_previous['rep_type'] == 6) {
            $body .= "\n" . get_string('rep_num_weeks', 'block_mrbs');
            $body .= ": " . $mail_previous["rep_num_weeks"];
        }
        if ($mail_previous["rep_opt"]) {
            $body .= "\n" . get_string('rep_rep_day', 'block_mrbs');
            $body .= " " . $mail_previous["rep_opt"];
        }
        $body .= "\n" . get_string('rep_end_date', 'block_mrbs');
        $body .= " " . $mail_previous['rep_end_date'] . "\n";
    }
    $body .= "\n";
    // End of mail details
    array_unique($recipientlist);
    $result = 1;
    if (!($fromuser = get_user_by_email(MAIL_FROM))) {
        $result = 0;
    }
    foreach ($recipientlist as $recip) {
        $recipuser = get_user_by_email($recip);
        if ($recipuser && $result) {
            $result = email_to_user($recipuser, $fromuser, $subject, $body);
            if (!$result) {
                notice(get_string('error_send_email', 'block_mrbs', $recip));
            }
        } else {
            if ($recipuser < 1) {
                $result = 0;
                notice(get_string('no_user_with_email', 'block_mrbs', $recip));
            } else {
                notice(get_string('no_user_with_email', 'block_mrbs', MAIL_FROM));
            }
        }
    }
    return $result;
}