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


PHP replace_ampersands_not_followed_by_entity函数代码示例

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


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

示例1: test_replace_ampersands

 public function test_replace_ampersands()
 {
     $this->assertSame("This & that  ", replace_ampersands_not_followed_by_entity("This & that  "));
     $this->assertSame("This &nbsp that  ", replace_ampersands_not_followed_by_entity("This &nbsp that  "));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:5,代码来源:weblib_test.php

示例2: format_string

/**
* Given a simple string, this function returns the string
* processed by enabled string filters if $CFG->filterall is enabled
*
* This function should be used to print short strings (non html) that
* need filter processing e.g. activity titles, post subjects,
* glossary concepts.
*
* @global object
* @global object
* @global object
* @staticvar bool $strcache
* @param string $string The string to be filtered.
* @param boolean $striplinks To strip any link in the result text.
                             Moodle 1.8 default changed from false to true! MDL-8713
* @param array $options options array/object or courseid
* @return string
*/
function format_string($string, $striplinks = true, $options = NULL)
{
    global $CFG, $COURSE, $PAGE;
    //We'll use a in-memory cache here to speed up repeated strings
    static $strcache = false;
    if (empty($CFG->version) or $CFG->version < 2010072800 or during_initial_install()) {
        // do not filter anything during installation or before upgrade completes
        return $string = strip_tags($string);
    }
    if ($strcache === false or count($strcache) > 2000) {
        // this number might need some tuning to limit memory usage in cron
        $strcache = array();
    }
    if (is_numeric($options)) {
        // legacy courseid usage
        $options = array('context' => get_context_instance(CONTEXT_COURSE, $options));
    } else {
        $options = (array) $options;
        // detach object, we can not modify it
    }
    if (empty($options['context'])) {
        // fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-(
        $options['context'] = $PAGE->context;
    } else {
        if (is_numeric($options['context'])) {
            $options['context'] = get_context_instance_by_id($options['context']);
        }
    }
    if (!$options['context']) {
        // we did not find any context? weird
        return $string = strip_tags($string);
    }
    //Calculate md5
    $md5 = md5($string . '<+>' . $striplinks . '<+>' . $options['context']->id . '<+>' . current_language());
    //Fetch from cache if possible
    if (isset($strcache[$md5])) {
        return $strcache[$md5];
    }
    // First replace all ampersands not followed by html entity code
    // Regular expression moved to its own method for easier unit testing
    $string = replace_ampersands_not_followed_by_entity($string);
    if (!empty($CFG->filterall)) {
        $string = filter_manager::instance()->filter_string($string, $options['context']);
    }
    // If the site requires it, strip ALL tags from this string
    if (!empty($CFG->formatstringstriptags)) {
        $string = strip_tags($string);
    } else {
        // Otherwise strip just links if that is required (default)
        if ($striplinks) {
            //strip links in string
            $string = strip_links($string);
        }
        $string = clean_text($string);
    }
    //Store to cache
    $strcache[$md5] = $string;
    return $string;
}
开发者ID:hatone,项目名称:moodle,代码行数:77,代码来源:weblib.php

示例3: format_string

/**
 * Given a simple string, this function returns the string
 * processed by enabled string filters if $CFG->filterall is enabled
 *
 * This function should be used to print short strings (non html) that
 * need filter processing e.g. activity titles, post subjects,
 * glossary concepts.
 *
 * @staticvar bool $strcache
 * @param string $string The string to be filtered. Should be plain text, expect
 * possibly for multilang tags.
 * @param boolean $striplinks To strip any link in the result text. Moodle 1.8 default changed from false to true! MDL-8713
 * @param array $options options array/object or courseid
 * @return string
 */
function format_string($string, $striplinks = true, $options = null)
{
    global $CFG, $PAGE;
    // We'll use a in-memory cache here to speed up repeated strings.
    static $strcache = false;
    if (empty($CFG->version) or $CFG->version < 2013051400 or during_initial_install()) {
        // Do not filter anything during installation or before upgrade completes.
        return $string = strip_tags($string);
    }
    if ($strcache === false or count($strcache) > 2000) {
        // This number might need some tuning to limit memory usage in cron.
        $strcache = array();
    }
    if (is_numeric($options)) {
        // Legacy courseid usage.
        $options = array('context' => context_course::instance($options));
    } else {
        // Detach object, we can not modify it.
        $options = (array) $options;
    }
    if (empty($options['context'])) {
        // Fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-(.
        $options['context'] = $PAGE->context;
    } else {
        if (is_numeric($options['context'])) {
            $options['context'] = context::instance_by_id($options['context']);
        }
    }
    if (!$options['context']) {
        // We did not find any context? weird.
        return $string = strip_tags($string);
    }
    // Calculate md5.
    $md5 = md5($string . '<+>' . $striplinks . '<+>' . $options['context']->id . '<+>' . current_language());
    // Fetch from cache if possible.
    if (isset($strcache[$md5])) {
        return $strcache[$md5];
    }
    // First replace all ampersands not followed by html entity code
    // Regular expression moved to its own method for easier unit testing.
    $string = replace_ampersands_not_followed_by_entity($string);
    if (!empty($CFG->filterall)) {
        $filtermanager = filter_manager::instance();
        $filtermanager->setup_page_for_filters($PAGE, $options['context']);
        // Setup global stuff filters may have.
        $string = $filtermanager->filter_string($string, $options['context']);
    }
    // If the site requires it, strip ALL tags from this string.
    if (!empty($CFG->formatstringstriptags)) {
        $string = str_replace(array('<', '>'), array('&lt;', '&gt;'), strip_tags($string));
    } else {
        // Otherwise strip just links if that is required (default).
        if ($striplinks) {
            // Strip links in string.
            $string = strip_links($string);
        }
        $string = clean_text($string);
    }
    // Store to cache.
    $strcache[$md5] = $string;
    return $string;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:77,代码来源:weblib.php

示例4: test_replace_ampersands

 function test_replace_ampersands() {
     $this->assertEquals(replace_ampersands_not_followed_by_entity("This & that &nbsp;"), "This &amp; that &nbsp;");
     $this->assertEquals(replace_ampersands_not_followed_by_entity("This &nbsp that &nbsp;"), "This &amp;nbsp that &nbsp;");
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:4,代码来源:weblib_test.php

示例5: get_global_concepts

 /**
  * Get all linked global concepts.
  * @return array
  */
 protected static function get_global_concepts()
 {
     global $DB;
     $cache = \cache::make('mod_glossary', 'concepts');
     $data = $cache->get(0);
     if (is_array($data)) {
         list($glossaries, $allconcepts) = $data;
     } else {
         // Find all global glossaries - no access control here.
         $sql = "SELECT g.id, g.name\n                      FROM {glossary} g\n                      JOIN {course_modules} cm ON (cm.instance = g.id)\n                      JOIN {modules} m ON (m.name = 'glossary' AND m.id = cm.module)\n                     WHERE g.usedynalink = 1 AND g.globalglossary = 1 AND cm.visible = 1 AND m.visible = 1\n                  ORDER BY g.globalglossary, g.id";
         $glossaries = $DB->get_records_sql_menu($sql);
         if (!$glossaries) {
             $data = array(array(), array());
             $cache->set(0, $data);
             return $data;
         }
         foreach ($glossaries as $id => $name) {
             $name = str_replace(':', '-', $name);
             $glossaries[$id] = replace_ampersands_not_followed_by_entity(strip_tags($name));
         }
         $allconcepts = self::fetch_concepts(array_keys($glossaries));
         foreach ($glossaries as $gid => $unused) {
             if (!isset($allconcepts[$gid])) {
                 unset($glossaries[$gid]);
             }
         }
         $cache->set(0, array($glossaries, $allconcepts));
     }
     // NOTE: no access control is here because it would be way too expensive to check access
     //       to all courses that contain the global glossaries.
     return array($glossaries, $allconcepts);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:36,代码来源:concept_cache.php

示例6: filter

 public function filter($text, array $options = array())
 {
     global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS;
     // Trivial-cache - keyed on $cachedcontextid
     static $cachedcontextid;
     static $conceptlist;
     static $nothingtodo;
     // To avoid processing if no glossaries / concepts are found
     // Try to get current course.
     $coursectx = $this->context->get_course_context(false);
     if (!$coursectx) {
         $courseid = 0;
     } else {
         $courseid = $coursectx->instanceid;
     }
     // Initialise/invalidate our trivial cache if dealing with a different context
     if (!isset($cachedcontextid) || $cachedcontextid !== $this->context->id) {
         $cachedcontextid = $this->context->id;
         $conceptlist = array();
         $nothingtodo = false;
     }
     if ($nothingtodo === true || !has_capability('mod/glossary:view', $this->context)) {
         return $text;
     }
     // Create a list of all the concepts to search for.  It may be cached already.
     if (empty($conceptlist)) {
         // Find all the glossaries we need to examine
         if (!($glossaries = $DB->get_records_sql_menu('
                 SELECT g.id, g.name
                   FROM {glossary} g, {course_modules} cm, {modules} m
                  WHERE m.name = \'glossary\'
                    AND cm.module = m.id
                    AND cm.visible = 1
                    AND g.id = cm.instance
                    AND g.usedynalink != 0
                    AND (g.course = ? OR g.globalglossary = 1)
               ORDER BY g.globalglossary, g.id', array($courseid)))) {
             $nothingtodo = true;
             return $text;
         }
         // Make a list of glossary IDs for searching
         $glossarylist = implode(',', array_keys($glossaries));
         // Pull out all the raw data from the database for entries, categories and aliases
         $entries = $DB->get_records_select('glossary_entries', 'glossaryid IN (' . $glossarylist . ') AND usedynalink != 0 AND approved != 0 ', null, '', 'id,glossaryid, concept, casesensitive, 0 AS category, fullmatch');
         $categories = $DB->get_records_select('glossary_categories', 'glossaryid IN (' . $glossarylist . ') AND usedynalink != 0', null, '', 'id,glossaryid,name AS concept, 1 AS casesensitive, 1 AS category, 1 AS fullmatch');
         $aliases = $DB->get_records_sql('
                 SELECT ga.id, ge.id AS entryid, ge.glossaryid,
                        ga.alias AS concept, ge.concept AS originalconcept,
                        casesensitive, 0 AS category, fullmatch
                   FROM {glossary_alias} ga,
                        {glossary_entries} ge
                   WHERE ga.entryid = ge.id
                     AND ge.glossaryid IN (' . $glossarylist . ')
                     AND ge.usedynalink != 0
                     AND ge.approved != 0', null);
         // Combine them into one big list
         $concepts = array();
         if ($entries and $categories) {
             $concepts = array_merge($entries, $categories);
         } else {
             if ($categories) {
                 $concepts = $categories;
             } else {
                 if ($entries) {
                     $concepts = $entries;
                 }
             }
         }
         if ($aliases) {
             $concepts = array_merge($concepts, $aliases);
         }
         if (!empty($concepts)) {
             foreach ($concepts as $key => $concept) {
                 // Trim empty or unlinkable concepts
                 $currentconcept = trim(strip_tags($concept->concept));
                 // Concept must be HTML-escaped, so do the same as format_string
                 // to turn ampersands into &amp;.
                 $currentconcept = replace_ampersands_not_followed_by_entity($currentconcept);
                 if (empty($currentconcept)) {
                     unset($concepts[$key]);
                     continue;
                 } else {
                     $concepts[$key]->concept = $currentconcept;
                 }
                 // Rule out any small integers.  See bug 1446
                 $currentint = intval($currentconcept);
                 if ($currentint && strval($currentint) == $currentconcept && $currentint < 1000) {
                     unset($concepts[$key]);
                 }
             }
         }
         if (empty($concepts)) {
             $nothingtodo = true;
             return $text;
         }
         usort($concepts, 'filter_glossary::sort_entries_by_length');
         $strcategory = get_string('category', 'glossary');
         // Loop through all the concepts, setting up our data structure for the filter
         $conceptlist = array();
         // We will store all the concepts here
//.........这里部分代码省略.........
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:101,代码来源:filter.php

示例7: format_string

/**
* Given a simple string, this function returns the string
* processed by enabled string filters if $CFG->filterall is enabled
*
* This function should be used to print short strings (non html) that
* need filter processing e.g. activity titles, post subjects,
* glossary concepts.
*
* @global object
* @global object
* @global object
* @staticvar bool $strcache
* @param string $string The string to be filtered.
* @param boolean $striplinks To strip any link in the result text.
                             Moodle 1.8 default changed from false to true! MDL-8713
* @param int $courseid Current course as filters can, potentially, use it
* @return string
*/
function format_string($string, $striplinks = true, $courseid = NULL)
{
    global $CFG, $COURSE, $PAGE;
    //We'll use a in-memory cache here to speed up repeated strings
    static $strcache = false;
    if ($strcache === false or count($strcache) > 2000) {
        // this number might need some tuning to limit memory usage in cron
        $strcache = array();
    }
    //init course id
    if (empty($courseid)) {
        $courseid = $COURSE->id;
    }
    //Calculate md5
    $md5 = md5($string . '<+>' . $striplinks . '<+>' . $courseid . '<+>' . current_language());
    //Fetch from cache if possible
    if (isset($strcache[$md5])) {
        return $strcache[$md5];
    }
    // First replace all ampersands not followed by html entity code
    // Regular expression moved to its own method for easier unit testing
    $string = replace_ampersands_not_followed_by_entity($string);
    if (!empty($CFG->filterall) && $CFG->version >= 2009040600) {
        // Avoid errors during the upgrade to the new system.
        $context = $PAGE->context;
        $string = filter_manager::instance()->filter_string($string, $context, $courseid);
    }
    // If the site requires it, strip ALL tags from this string
    if (!empty($CFG->formatstringstriptags)) {
        $string = strip_tags($string);
    } else {
        // Otherwise strip just links if that is required (default)
        if ($striplinks) {
            //strip links in string
            $string = strip_links($string);
        }
        $string = clean_text($string);
    }
    //Store to cache
    $strcache[$md5] = $string;
    return $string;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:60,代码来源:weblib.php


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