Encodes URLs to the index.php and view.php scripts

@param string $content some HTML text that eventually contains URLs to the activity instance scripts
@return string the content with the URLs encoded
19006
static public function encode_content_links($content) {
        global $CFG, $DB;

        $base = preg_quote($CFG->wwwroot,"/");

        // Link to the list of resources.
        $search="/(".$base."\/mod\/resource\/index.php\?id\=)([0-9]+)/";
        $content= preg_replace($search, '$@RESOURCEINDEX*$2@$', $content);

        // Link to resource view by moduleid.
        $search = "/(".$base."\/mod\/resource\/view.php\?id\=)([0-9]+)/";
        // Link to resource view by recordid
        $search2 = "/(".$base."\/mod\/resource\/view.php\?r\=)([0-9]+)/";

        // Check whether there are contents in the resource old table.
        if (static::$resourceoldexists === null) {
            static::$resourceoldexists = $DB->record_exists('resource_old', array());
        }

        // If there are links to items in the resource_old table, rewrite them to be links to the correct URL
        // for their new module.
        if (static::$resourceoldexists) {
            // Match all of the resources.
            $result = preg_match_all($search, $content, $matches, PREG_PATTERN_ORDER);

            // Course module ID resource links.
            if ($result) {
                list($insql, $params) = $DB->get_in_or_equal($matches[2]);
                $oldrecs = $DB->get_records_select('resource_old', "cmid $insql", $params, '', 'cmid, newmodule');

                for ($i = 0; $i < count($matches[0]); $i++) {
                    $cmid = $matches[2][$i];
                    if (isset($oldrecs[$cmid])) {
                        // Resource_old item, rewrite it
                        $replace = '$@' . strtoupper($oldrecs[$cmid]->newmodule) . 'VIEWBYID*' . $cmid . '@$';
                    } else {
                        // Not in the resource old table, don't rewrite
                        $replace = '$@RESOURCEVIEWBYID*'.$cmid.'@$';
                    }
                    $content = str_replace($matches[0][$i], $replace, $content);
                }
            }

            $matches = null;
            $result = preg_match_all($search2, $content, $matches, PREG_PATTERN_ORDER);

            // No resource links.
            if (!$result) {
                return $content;
            }
            // Resource ID links.
            list($insql, $params) = $DB->get_in_or_equal($matches[2]);
            $oldrecs = $DB->get_records_select('resource_old', "oldid $insql", $params, '', 'oldid, cmid, newmodule');

            for ($i = 0; $i < count($matches[0]); $i++) {
                $recordid = $matches[2][$i];
                if (isset($oldrecs[$recordid])) {
                    // Resource_old item, rewrite it
                    $replace = '$@' . strtoupper($oldrecs[$recordid]->newmodule) . 'VIEWBYID*' . $oldrecs[$recordid]->cmid . '@$';
                    $content = str_replace($matches[0][$i], $replace, $content);
                }
            }
        } else {
            $content = preg_replace($search, '$@RESOURCEVIEWBYID*$2@$', $content);
        }
        return $content;
    }
1016051
public function getShortcodesFromContent($content)
    {
        $content = $this->getContentWithoutIgnoreBlocks($content);

        if (false === strpos($content, '[')) {
            return [];
        }

        $result = [];

        $regex = "\[([A-Za-z_]+[^\ \]]+)";
        preg_match_all('/' . $regex . '/', $content, $matches);

        if (!empty($matches[1])) {
            foreach ($matches[1] as $match) {
                $result[$match] = $match;
            }
        }

        if ($result) {
            return array_keys($result);
        }

        return $result;
    }
715568
public static function shortcodeToEntities($content) {
        $replacements = self::getShortcodeEntities();
        return str_replace(array_keys($replacements), $replacements, $content);
    }
41603
protected function getHtml( $content )
	{
		$site = Route::input( 'site', Input::get( 'site', 'default' ) );
		return View::make( 'shop::jqadm.index', array( 'content' => $content, 'site' => $site ) );
	}
211764
public function append_modules_content( string $content ) : string {

		global $more, $post;
		$flexible_content = '';

		// Remove current filter to avoid recursive loop.
		remove_filter( 'the_content', [ $this, 'append_modules_content' ], $this->_the_content_priority );

		if ( $this->is_current_post_flexible( $post, $more ) ) {
			$flexible_content = $this->get_modules_content( $post );
		}

		// Re-add filter after parsing content.
		add_filter( 'the_content', [ $this, 'append_modules_content' ], $this->_the_content_priority, 1 );

		return $content . $flexible_content;
	}
576383
static public function encode_content_links($content) {

        // Link to the course main page (it also covers "&topic=xx" and "&week=xx"
        // because they don't become transformed (section number) in backup/restore.
        $content = self::encode_links_helper($content, 'COURSEVIEWBYID',       '/course/view.php?id=');

        // A few other key course links.
        $content = self::encode_links_helper($content, 'GRADEINDEXBYID',       '/grade/index.php?id=');
        $content = self::encode_links_helper($content, 'GRADEREPORTINDEXBYID', '/grade/report/index.php?id=');
        $content = self::encode_links_helper($content, 'BADGESVIEWBYID',       '/badges/view.php?type=2&id=');
        $content = self::encode_links_helper($content, 'USERINDEXVIEWBYID',    '/user/index.php?id=');

        return $content;
    }
312853
public function encode(Content $content): string
    {
        $results     = [];
        $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
        foreach ($content->getFields() as $field) {
            $identifier      = $field->fieldDefIdentifier;
            $fieldDefinition = $contentType->getFieldDefinition($identifier);
            if (!$fieldDefinition->isTranslatable) {
                continue;
            }
            $type = \get_class($field->value);
            // Note that TextBlock is a TextLine
            if ($field->value instanceof TextLineValue) {
                $value                = (string) $field->value;
                $results[$identifier] = ['#' => $value, '@type' => $type];
                continue;
            }
            if ($field->value instanceof RichTextValue
                || $field->value instanceof EzPlatformRichTextValue
            ) {
                // we need to remove that to make it a good XML
                $value                = $this->richTextEncode($field->value);
                $results[$identifier] = ['#' => $value, '@type' => $type];
            }
        }

        $encoder = new XmlEncoder();
        $payload = $encoder->encode($results, XmlEncoder::FORMAT);
        // here Encoder has  decorated with CDATA, we don't want the CDATA
        $payload = str_replace(
            ['<![CDATA[', ']]>'],
            ['<' . self::CDATA_FAKER_TAG . '>', '</' . self::CDATA_FAKER_TAG . '>'],
            $payload
        );

        return $payload;
    }
920896
public function compile($content)
    {
        if( ! $this->count()) return $content;

        $pattern = $this->getRegex();

        return preg_replace_callback("/{$pattern}/s", [&$this, 'render'], $content);
    }
626193
public function prepareContent($content)
    {
        if (is_array($content)) {
            $ctt = '';
            foreach ($content as $key=>$ctt) {
                $content .= $ctt;
            }
            $content = $ctt;
        }
        $_escaped_output = strip_tags((string) $content);
        if ($_escaped_output != (string) $content) {
            if (preg_match('/(.*)<body(.*)</body>/i', (string) $content, $matches)) {
                $_output = $matches[0];
            } else {
                $_output = (string) $content;
            }
            $content = Html2Text::convert($_output);
        }
        return (string) $content;
    }
1316060
public function generateSearchText($content)
    {
        $content = $this->_defaultData($content);
        $searchText = $this->_generateSearchText($content->selected, $content->price);
        return parent::generateSearchText($searchText);
    }
161481
private function buildHeader(string $content): string
    {
        $header = "POST " . static::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n";
        $header .= "Host: " . static::FLEEP_HOST . "\r\n";
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $header .= "Content-Length: " . strlen($content) . "\r\n";
        $header .= "\r\n";

        return $header;
    }
915328
public static function encodeHtml($content)
    {
        $content = self::unicodeToShortcode($content);
        $content = self::shortcodeToEntities($content);

        return $content;
    }
18450
@JsonIgnore
    public void encodeAndSetContent(String content) {
        encodeAndSetContent(content != null ? content.getBytes() : null);
    }
1334044
static String encUric(final String content, final Charset charset) {
        return urlEncode(content, charset, URIC, false);
    }
1066021
protected function processVars(string &$content): void
    {
        $pattern = $this->getTagPattern('(\$.+?)');
        $content = preg_replace_callback($pattern, function ($match) {
            return '<?php echo ' . $match[1] . '; ?>';
        }, $content);
    }
1041699
public function generate(string $content = null): string
    {
        if (empty($content)) {
            $guid = Uuid::uuid4();
        } else {
            $guid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $content);
        }

        return $guid->toString();
    }
669287
private function buildHeader(string $content): string
    {
        // needed for rooms with special (spaces, etc) characters in the name
        $room = rawurlencode($this->room);
        $header = "POST /v2/room/{$room}/notification?auth_token={$this->token} HTTP/1.1\r\n";

        $header .= "Host: {$this->host}\r\n";
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $header .= "Content-Length: " . strlen($content) . "\r\n";
        $header .= "\r\n";

        return $header;
    }