Blame view

libraries/allediaframework/Framework/Content/Text.php 1.88 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
<?php
/**
 * @package   AllediaFramework
 * @contact   www.alledia.com, hello@alledia.com
 * @copyright 2016 Alledia.com, All rights reserved
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

namespace Alledia\Framework\Content;

use Alledia\Framework\Object;
use Alledia\Framework\Content\Tag;

defined('_JEXEC') or die();

class Text extends Object
{
    public $content = '';

    /**
     * Constructor method, that defines the internal content
     *
     * @param string $content
     */
    public function __construct($content)
    {
        $this->content = $content;
    }

    /**
     * Extract multiple {mytag} tags from the content
     *
     * @todo Recognize unclose tags like {dumbtag param1="12"}
     * @param  string $tagName
     * @return array  An array with all tags {tagName} found on the text
     */
    protected function extractPluginTags($tagName)
    {
        preg_match_all(Tag::getRegex($tagName), $this->content, $matches);

        return $matches[0];
    }

    /**
     * Extract multiple {mytag} tags from the content, returning
     * as Tag instances
     *
     * @param  string $tagName
     * @return array  An array with all tags {tagName} found on the text
     */
    public function getPluginTags($tagName)
    {
        $unparsedTags = $this->extractPluginTags($tagName);

        $tags = array();
        foreach ($unparsedTags as $unparsedTag) {
            $tags[] = new Tag($tagName, $unparsedTag);
        }

        return $tags;
    }

    /**
     * Extract multiple {mytag} tags from the content, returning
     * as Tag instances
     *
     * @param  string $tagName
     * @return array  An array with all tags {tagName} found on the text
     * @deprecated 1.3.1 Use getPluginsTags instead
     */
    public function getTags($tagName)
    {
        // Deprecated. Use getPluginTags instead
        return $this->getPluginTags($tagName);
    }
}