/** * 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; }
public function test_strip_links() { $this->assertSame('this is a link', strip_links('this is a <a href="http://someaddress.com/query">link</a>')); }
/** * 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('<', '>'), 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; }
function test_strip_links() { $this->assertEquals(strip_links('this is a <a href="http://someaddress.com/query">link</a>'), 'this is a link'); }
} $arr = explode("\n", $dom->saveXML(), 2); return $arr[1]; } $fullname = str_replace('@', '', $_GET['fullname']); $splitted = explode('/', $fullname); $pkg = $splitted[0]; if (preg_match("/[^+0-9A-Za-z.-]/", $pkg)) { die("invalid"); } $name = $splitted[1]; $namelen = strlen($name); $index = str_replace('.', '', str_replace('-', '', str_replace('+', '', $prefix . $pkg))); $mysqli = new mysqli("p:127.0.0.1", "", "", "", 51413); if ($mysqli->connect_errno) { die("Failed to connect to MySQL: " . $mysqli->connect_error); } $name = str_replace(".", " << . << ", $name); $name = $mysqli->real_escape_string($name); if (!($q = $mysqli->query("SELECT type, name, shortdesc, path, signature, namelen FROM {$index} WHERE MATCH('{$name}') AND namelen={$namelen} LIMIT 1 OPTION max_matches=1,ranker=none"))) { die("Query failed: (" . $mysqli->errno . ") " . $mysqli->error); } $row = $q->fetch_assoc(); if ($row) { echo '<p>' . strip_links($row['signature']) . '</p>'; echo strip_links($row['shortdesc']); } else { echo "no result"; } $q->close(); $mysqli->close();
/** * 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; }