public function parse($text, $replaceLinks = true)
    {
        $resources = [];

        // Find media
        $regex = '#[src|href]+="([^"]*file/resource/media/([^\'"]+))"#';

        preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
        if (count($matches) > 0) {
            foreach ($matches as $match) {
                $node = $this->resourceManager->getNode($match[2]);
                if ($node) {
                    $resources = $this->storeResource($resources, $node);

                    if ($replaceLinks) {
                        $text = $this->replaceLink($text, $match[1], '../files/file_'.$match[2]);
                    }
                }
            }
        }

        // Find videos (it's a particular case because the url is not same)
        // We also have the Resource id, not the Node one
        $regex = '#[src|href]+="([^"]*video-player/api/video/([^\'"]+)/stream)"#';

        preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
        if (count($matches) > 0) {
            foreach ($matches as $match) {
                // We have the ID of the Resource, not the Node
                $resource = $this->om->getRepository('ClarolineCoreBundle:Resource\File')->find($match[2]);
                if ($resource) {
                    $node = $resource->getResourceNode();
                    $resources = $this->storeResource($resources, $node);

                    if ($replaceLinks) {
                        $text = $this->replaceLink($text, $match[1], '../files/file_'.$node->getId());
                    }
                }
            }
        }

        // Find resources
        $regex = '#[src|href]+="([^"]*resource/open/([^/]+)/([^\'"]+))"#';

        preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
        if (count($matches) > 0) {
            foreach ($matches as $match) {
                $node = $this->resourceManager->getNode($match[3]);
                if ($node) {
                    $resources = $this->storeResource($resources, $node);

                    if ($replaceLinks) {
                        $text = $this->replaceLink($text, $match[1], '../scos/resource_'.$match[3].'.html');
                    }
                }
            }
        }

        return [
            'text' => $text,
            'resources' => $resources,
        ];
    }
public function parse($text, $replaceLinks = true)
    {
        $resources = [];

        // Find media
        $regex = '#[src|href]+="([^"]*file/resource/media/([^\'"]+))"#';

        preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
        if (count($matches) > 0) {
            foreach ($matches as $match) {
                $node = $this->resourceManager->getNode($match[2]);
                if ($node) {
                    $resources = $this->storeResource($resources, $node);

                    if ($replaceLinks) {
                        $text = $this->replaceLink($text, $match[1], '../files/file_'.$match[2]);
                    }
                }
            }
        }

        // Find videos (it's a particular case because the url is not same)
        // We also have the Resource id, not the Node one
        $regex = '#[src|href]+="([^"]*video-player/api/video/([^\'"]+)/stream)"#';

        preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
        if (count($matches) > 0) {
            foreach ($matches as $match) {
                // We have the ID of the Resource, not the Node
                $resource = $this->om->getRepository('ClarolineCoreBundle:Resource\File')->find($match[2]);
                if ($resource) {
                    $node = $resource->getResourceNode();
                    $resources = $this->storeResource($resources, $node);

                    if ($replaceLinks) {
                        $text = $this->replaceLink($text, $match[1], '../files/file_'.$node->getId());
                    }
                }
            }
        }

        // Find resources
        $regex = '#[src|href]+="([^"]*resource/open/([^/]+)/([^\'"]+))"#';

        preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
        if (count($matches) > 0) {
            foreach ($matches as $match) {
                $node = $this->resourceManager->getNode($match[3]);
                if ($node) {
                    $resources = $this->storeResource($resources, $node);

                    if ($replaceLinks) {
                        $text = $this->replaceLink($text, $match[1], '../scos/resource_'.$match[3].'.html');
                    }
                }
            }
        }

        return [
            'text' => $text,
            'resources' => $resources,
        ];
    }
public function parse ( $ text , $ replaceLinks = true ) { $ resources = [ ] ; // Find media $ regex = '#[src|href]+="([^"]*file/resource/media/([^\'"]+))"#' ; preg_match_all ( $ regex , $ text , $ matches , PREG_SET_ORDER ) ; if ( count ( $ matches ) > 0 ) { foreach ( $ matches as $ match ) { $ node = $ this -> resourceManager -> getNode ( $ match [ 2 ] ) ; if ( $ node ) { $ resources = $ this -> storeResource ( $ resources , $ node ) ; if ( $ replaceLinks ) { $ text = $ this -> replaceLink ( $ text , $ match [ 1 ] , '../files/file_' . $ match [ 2 ] ) ; } } } } // Find videos (it's a particular case because the url is not same) // We also have the Resource id, not the Node one $ regex = '#[src|href]+="([^"]*video-player/api/video/([^\'"]+)/stream)"#' ; preg_match_all ( $ regex , $ text , $ matches , PREG_SET_ORDER ) ; if ( count ( $ matches ) > 0 ) { foreach ( $ matches as $ match ) { // We have the ID of the Resource, not the Node $ resource = $ this -> om -> getRepository ( 'ClarolineCoreBundle:Resource\File' ) -> find ( $ match [ 2 ] ) ; if ( $ resource ) { $ node = $ resource -> getResourceNode ( ) ; $ resources = $ this -> storeResource ( $ resources , $ node ) ; if ( $ replaceLinks ) { $ text = $ this -> replaceLink ( $ text , $ match [ 1 ] , '../files/file_' . $ node -> getId ( ) ) ; } } } } // Find resources $ regex = '#[src|href]+="([^"]*resource/open/([^/]+)/([^\'"]+))"#' ; preg_match_all ( $ regex , $ text , $ matches , PREG_SET_ORDER ) ; if ( count ( $ matches ) > 0 ) { foreach ( $ matches as $ match ) { $ node = $ this -> resourceManager -> getNode ( $ match [ 3 ] ) ; if ( $ node ) { $ resources = $ this -> storeResource ( $ resources , $ node ) ; if ( $ replaceLinks ) { $ text = $ this -> replaceLink ( $ text , $ match [ 1 ] , '../scos/resource_' . $ match [ 3 ] . '.html' ) ; } } } } return [ 'text' => $ text , 'resources' => $ resources , ] ; }
Parses a rich text to extract the resource list.

@param string $text
@param bool   $replaceLinks

@return array
Parses a rich text to extract the resource list .