<commit_before><?php
/**
 * Pimcore
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.pimcore.org/license
 *
 * @copyright  Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
 * @license    http://www.pimcore.org/license     New BSD License
 */


include_once("simple_html_dom.php");

class Pimcore_Tool_Text
{

    public static function removeLineBreaks ($text = "") {

        $text = str_replace(array("\r\n", "\n", "\r", "\t"), " ", $text);
        $text = preg_replace('#[ ]+#', ' ', $text);

        return $text;
    }
    
    public static function wysiwygText($text)
    {
        if(empty($text)) {
            return $text;
        }

        $matches = self::getElementsTagsInWysiwyg($text);

        if(count($matches[2]) > 0) {
            for($i=0; $i<count($matches[2]); $i++) {
                preg_match("/[0-9]+/",$matches[2][$i], $idMatches);
                preg_match("/asset|object|document/",$matches[3][$i], $typeMatches);

                $id = $idMatches[0];
                $type = $typeMatches[0];
                $element = Element_Service::getElementById($type, $id);

                if($element instanceof Element_Interface) {
                    $path = "";
                    $oldTag = $matches[0][$i];

                    if($matches[1][$i] == "a") {
                        $linkAttr = "href";
                        $path = $element->getFullPath();

                        if($element instanceof Document) {
                            // get parameters
                            preg_match("/href=\"([^\"]+)*\"/", $oldTag, $oldHref);
                            if($oldHref[1] && strpos($oldHref[1], "?") !== false) {
                                $parameters = explode("?",$oldHref[1]);
                                if(!empty($parameters[1])) {
                                    $path .= "?" . $parameters[1];
                                }
                            }
                        }
                    } else if ($matches[1][$i] == "img") {<commit_msg>allow fragment in internal wysiwyg link<commit_after><?php
/**
 * Pimcore
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.pimcore.org/license
 *
 * @copyright  Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
 * @license    http://www.pimcore.org/license     New BSD License
 */


include_once("simple_html_dom.php");

class Pimcore_Tool_Text
{

    public static function removeLineBreaks ($text = "") {

        $text = str_replace(array("\r\n", "\n", "\r", "\t"), " ", $text);
        $text = preg_replace('#[ ]+#', ' ', $text);

        return $text;
    }
    
    public static function wysiwygText($text)
    {
        if(empty($text)) {
            return $text;
        }

        $matches = self::getElementsTagsInWysiwyg($text);

        if(count($matches[2]) > 0) {
            for($i=0; $i<count($matches[2]); $i++) {
                preg_match("/[0-9]+/",$matches[2][$i], $idMatches);
                preg_match("/asset|object|document/",$matches[3][$i], $typeMatches);

                $id = $idMatches[0];
                $type = $typeMatches[0];
                $element = Element_Service::getElementById($type, $id);

                if($element instanceof Element_Interface) {
                    $path = "";
                    $oldTag = $matches[0][$i];

                    if($matches[1][$i] == "a") {
                        $linkAttr = "href";
                        $path = $element->getFullPath();

                        if($element instanceof Document) {
                            // get parameters
                            preg_match("/href=\"([^\"]+)*\"/", $oldTag, $oldHref);
                            if($oldHref[1] && (strpos($oldHref[1], "?") !== false || strpos($oldHref[1], "#") !== false)) {
                                $urlParts = parse_url($oldHref[1]);
                                if(array_key_exists("query", $urlParts) && !empty($urlParts["query"])) {
                                    $path .= "?" . $urlParts["query"];
                                }
                                if(array_key_exists("fragment", $urlParts) && !empty($urlParts["fragment"])) {
                                    $path .= "#" . $urlParts["fragment"];
                                }
                            }
                        }
                    } else if ($matches[1][$i] == "img") {
{'fraction_non_alphanumeric': 0.1645357367428212, 'fraction_numerical': 0.010689582896667365, 'mean_word_length': 1.5396487493347526, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7129280', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1332, 'n_words': 264}