当前位置: 首页>>代码示例>>PHP>>正文


PHP message_shorten_message函数代码示例

本文整理汇总了PHP中message_shorten_message函数的典型用法代码示例。如果您正苦于以下问题:PHP message_shorten_message函数的具体用法?PHP message_shorten_message怎么用?PHP message_shorten_message使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了message_shorten_message函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: message_post_message

function message_post_message($userfrom, $userto, $message, $format, $messagetype)
{
    global $CFG, $SITE, $USER;
    /// Set up current language to suit the receiver of the message
    $savelang = $USER->lang;
    if (!empty($userto->lang)) {
        $USER->lang = $userto->lang;
    }
    /// Save the new message in the database
    $savemessage = NULL;
    $savemessage->useridfrom = $userfrom->id;
    $savemessage->useridto = $userto->id;
    $savemessage->message = $message;
    $savemessage->format = $format;
    $savemessage->timecreated = time();
    $savemessage->messagetype = 'direct';
    if ($CFG->messaging) {
        if (!($savemessage->id = insert_record('message', $savemessage))) {
            return false;
        }
        $emailforced = false;
    } else {
        // $CFG->messaging is not on, we need to force sending of emails
        $emailforced = true;
        $savemessage->id = true;
    }
    /// Check to see if anything else needs to be done with it
    $preference = (object) get_user_preferences(NULL, NULL, $userto->id);
    if ($emailforced || (!isset($preference->message_emailmessages) || $preference->message_emailmessages)) {
        // Receiver wants mail forwarding
        if (!isset($preference->message_emailtimenosee)) {
            $preference->message_emailtimenosee = 10;
        }
        if (!isset($preference->message_emailformat)) {
            $preference->message_emailformat = FORMAT_HTML;
        }
        if ($emailforced || time() - $userto->lastaccess > (int) $preference->message_emailtimenosee * 60) {
            // Long enough
            $message = stripslashes_safe($message);
            $tagline = get_string('emailtagline', 'message', $SITE->shortname);
            $messagesubject = preg_replace('/\\s+/', ' ', strip_tags($message));
            // make sure it's all on one line
            $messagesubject = message_shorten_message($messagesubject, 30) . '...';
            $messagetext = format_text_email($message, $format) . "\n\n--\n" . $tagline . "\n" . "{$CFG->wwwroot}/message/index.php?popup=1";
            if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) {
                $messagehtml = format_text($message, $format);
                // MDL-10294, do not print link if messaging is disabled
                if ($CFG->messaging) {
                    $messagehtml .= '<hr /><p><a href="' . $CFG->wwwroot . '/message/index.php?popup=1">' . $tagline . '</a></p>';
                }
            } else {
                $messagehtml = NULL;
            }
            if (!empty($preference->message_emailaddress)) {
                $userto->email = $preference->message_emailaddress;
                // Use custom messaging address
            }
            if (email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml)) {
                $CFG->messagewasjustemailed = true;
            }
            sleep(3);
        }
    }
    $USER->lang = $savelang;
    // restore original language
    return $savemessage->id;
}
开发者ID:r007,项目名称:PMoodle,代码行数:67,代码来源:lib.php

示例2: message_get_fragment

/**
 * Given a string and an array of keywords, this function looks
 * for the first keyword in the string, and then chops out a
 * small section from the text that shows that word in context.
 * @param string $message the text to search
 * @param array $keywords array of keywords to find
 */
function message_get_fragment($message, $keywords) {

    $fullsize = 160;
    $halfsize = (int)($fullsize/2);

    $message = strip_tags($message);

    foreach ($keywords as $keyword) {  // Just get the first one
        if ($keyword !== '') {
            break;
        }
    }
    if (empty($keyword)) {   // None found, so just return start of message
        return message_shorten_message($message, 30);
    }

    $leadin = $leadout = '';

/// Find the start of the fragment
    $start = 0;
    $length = strlen($message);

    $pos = strpos($message, $keyword);
    if ($pos > $halfsize) {
        $start = $pos - $halfsize;
        $leadin = '...';
    }
/// Find the end of the fragment
    $end = $start + $fullsize;
    if ($end > $length) {
        $end = $length;
    } else {
        $leadout = '...';
    }

/// Pull out the fragment and format it

    $fragment = substr($message, $start, $end - $start);
    $fragment = $leadin.highlight(implode(' ',$keywords), $fragment).$leadout;
    return $fragment;
}
开发者ID:nfreear,项目名称:moodle,代码行数:48,代码来源:lib.php

示例3: message_post_message

function message_post_message($userfrom, $userto, $message, $format, $messagetype)
{
    global $CFG, $SITE;
    /// Save the new message in the database
    $savemessage = NULL;
    $savemessage->useridfrom = $userfrom->id;
    $savemessage->useridto = $userto->id;
    $savemessage->message = $message;
    $savemessage->format = $format;
    $savemessage->timecreated = time();
    $savemessage->messagetype = 'direct';
    if (!($savemessage->id = insert_record('message', $savemessage))) {
        return false;
    }
    /// Check to see if anything else needs to be done with it
    $preference = (object) get_user_preferences(NULL, NULL, $userto->id);
    if (!isset($preference->message_emailmessages) || $preference->message_emailmessages) {
        // Receiver wants mail forwarding
        if (!isset($preference->message_emailtimenosee)) {
            $preference->message_emailtimenosee = 10;
        }
        if (!isset($preference->message_emailformat)) {
            $preference->message_emailformat = FORMAT_HTML;
        }
        if (time() - $userto->lastaccess > (int) $preference->message_emailtimenosee * 60) {
            // Long enough
            $message = stripslashes_safe($message);
            $tagline = get_string('emailtagline', 'message', $SITE->shortname);
            $messagesubject = message_shorten_message(strip_tags($message), 30) . '...';
            $messagetext = format_text_email($message, $format) . "\n\n--\n" . $tagline . "\n" . "{$CFG->wwwroot}/message/index.php?popup=1";
            if (isset($preference->message_emailformat) and $preference->message_emailformat == FORMAT_HTML) {
                $messagehtml = format_text($message, $format);
                $messagehtml .= '<hr /><p><a href="' . $CFG->wwwroot . '/message/index.php?popup=1">' . $tagline . '</a></p>';
            } else {
                $messagehtml = NULL;
            }
            if (!empty($preference->message_emailaddress)) {
                $userto->email = $preference->message_emailaddress;
                // Use custom messaging address
            }
            if (email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml)) {
                $CFG->messagewasjustemailed = true;
            }
            sleep(3);
        }
    }
    return $savemessage->id;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:48,代码来源:lib.php


注:本文中的message_shorten_message函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。