コード例 #1
0
ファイル: Matcher.php プロジェクト: gkawka/FMBbCodeBundle
 /**
  * Tries to match a smiley with a set of emoticons.
  *
  * @param string $smiley The smiley
  *
  * @return array An array of parameters
  */
 public function match($smiley)
 {
     $emoticon = $this->emoticons->getEmoticonBySmiley($smiley);
     if (null === $emoticon) {
         return array();
     }
     return array('xHtml' => $emoticon->getXhtml(), 'html' => $emoticon->getHtml());
 }
コード例 #2
0
 public function testGetMatcher()
 {
     $expectEmoticon = new Emoticon();
     $expectEmoticon->setSmiley(':foo:');
     $expectCollection = new EmoticonCollection();
     $expectCollection->add('foo', $expectEmoticon);
     $loader = $this->getMockBuilder('FM\\BbcodeBundle\\Emoticon\\Loader\\FileLoader')->disableOriginalConstructor()->getMockForAbstractClass();
     $loader->expects($this->once())->method('load')->will($this->returnValue($expectCollection));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $result = new EmoticonHook($loader, $container, array('resource' => 'bar'));
     $collection = $result->getEmoticonCollection();
     $matcher = $result->getMatcher();
     $this->assertSame($collection->get('foo'), $expectEmoticon);
     $this->assertContains(':foo:', $matcher->getSmilies());
     $this->assertNotEmpty($matcher->match(':foo:'));
 }
コード例 #3
0
 /**
  * Gets the EmoticonCollection instance associated with this EmoticonHook.
  *
  * @return EmoticonCollection A EmoticonCollection instance
  */
 public function getEmoticonCollection()
 {
     if (null !== $this->collection) {
         return $this->collection;
     }
     $this->collection = new EmoticonCollection();
     // Convert a default decoda emoticons array to an EmoticonCollection
     $collection = new EmoticonCollection();
     if (!$this->getEmoticons()) {
         if (null === $this->getParser()) {
             $this->setParser(new Decoda());
         }
         $this->startup();
     }
     foreach ($this->getEmoticons() as $name => $smilies) {
         $emoticon = new Emoticon();
         foreach ($smilies as $smiley) {
             $emoticon->setSmiley($smiley);
         }
         $collection->add($name, $emoticon);
     }
     $this->collection->addCollection($collection);
     if (null !== $this->options['resource']) {
         $subCollection = $this->loader->load($this->options['resource'], $this->options['resource_type']);
         $this->collection->addCollection($subCollection);
     }
     $this->resolveParameters($this->collection);
     return $this->collection;
 }
コード例 #4
0
 /**
  * Gets the EmoticonCollection instance associated with this EmoticonHook.
  *
  * @return EmoticonCollection A EmoticonCollection instance
  */
 public function getEmoticonCollection()
 {
     if (null !== $this->collection) {
         return $this->collection;
     }
     $this->collection = new EmoticonCollection();
     if (null === $this->_parser) {
         // Gets default decoda emoticons ($this->_emoticons)
         parent::setParser(new Decoda());
     }
     // Convert a default decoda emoticons array to an EmoticonCollection
     $collection = new EmoticonCollection();
     foreach ($this->_emoticons as $name => $smilies) {
         $emoticon = new Emoticon();
         foreach ($smilies as $smiley) {
             $emoticon->setSmiley($smiley);
         }
         $collection->add($name, $emoticon);
     }
     foreach ($this->getParser()->getPaths() as $path) {
         if (!file_exists($path . '/emoticons.json')) {
             continue;
         }
         $collection->addResource(new FileResource($path . '/emoticons.json'));
     }
     $this->collection->addCollection($collection);
     if (null !== $this->options['resource']) {
         $subCollection = $this->loader->load($this->options['resource'], $this->options['resource_type']);
         $this->collection->addCollection($subCollection);
     }
     $this->resolveParameters($this->collection);
     return $this->collection;
 }
コード例 #5
0
 public function testAddOverriddenSmiley()
 {
     $collection = new EmoticonCollection();
     $emoticon = new Emoticon();
     $emoticon->setSmilies(array(':foo:', ':foofoo:'));
     $emoticon1 = new Emoticon();
     $emoticon1->setSmilies(array(':foo:', ':bar:'));
     $collection->add('foo', $emoticon);
     $collection->add('bar', $emoticon1);
     $this->assertSame(array(':foofoo:', ':foo:', ':bar:'), $collection->getSmilies());
     $this->assertSame($emoticon, $collection->getEmoticonBySmiley(':foofoo:'));
     $this->assertSame($emoticon1, $collection->getEmoticonBySmiley(':foo:'));
     $this->assertSame($emoticon1, $collection->getEmoticonBySmiley(':bar:'));
 }
コード例 #6
0
ファイル: Matcher.php プロジェクト: yakobe/FMBbCodeBundle
 /**
  * Returns all smilies.
  *
  * @return string[] An array of smilies
  */
 public function getSmilies()
 {
     return $this->emoticons->getSmilies();
 }
コード例 #7
0
ファイル: simple.php プロジェクト: aeterno00/FMBbCodeBundle
<?php

use FM\BbcodeBundle\Emoticon\EmoticonCollection;
use FM\BbcodeBundle\Emoticon\Emoticon;
$collection = new EmoticonCollection();
$emoticon = new Emoticon();
$emoticon->addSmilies(array(':foo:'));
$collection->add('foo', $emoticon);
return $collection;
コード例 #8
0
 /**
  * Adds an emoticon collection.
  *
  * @param EmoticonCollection $collection  A EmoticonCollection instance
  */
 public function addCollection(EmoticonCollection $collection)
 {
     foreach ($collection->all() as $name => $emoticon) {
         $this->add($name, $emoticon);
     }
     $this->resources = array_merge($this->resources, $collection->getResources());
 }
コード例 #9
0
 /**
  * Parses emoticons.
  *
  * @param EmoticonCollection $collection
  * @param string             $name
  * @param array              $config
  */
 private function parseEmoticon(EmoticonCollection $collection, $name, $config)
 {
     if (!isset($config['smilies']) || !is_array($config['smilies'])) {
         return;
     }
     $emoticon = new Emoticon();
     $emoticon->setSmilies($config['smilies']);
     if (isset($config['url'])) {
         $emoticon->setUrl($config['url']);
     }
     if (isset($config['html'])) {
         $emoticon->setHtml($config['html']);
     }
     if (isset($config['xHtml'])) {
         $emoticon->setXhtml($config['xHtml']);
     }
     $collection->add($name, $emoticon);
 }
コード例 #10
0
<?php

use Decoda\Decoda;
use Decoda\Hook\EmoticonHook;
use FM\BbcodeBundle\Emoticon\EmoticonCollection;
use FM\BbcodeBundle\Emoticon\Emoticon;
// Convert a default decoda emoticons array to an EmoticonCollection
$collection = new EmoticonCollection();
$decoda = new Decoda();
$hook = new EmoticonHook();
$hook->setParser($decoda);
$hook->startup();
$emoticons = $hook->getEmoticons();
foreach ($emoticons as $name => $smilies) {
    $emoticon = new Emoticon();
    foreach ($smilies as $smiley) {
        $emoticon->setSmiley($smiley);
    }
    $collection->add($name, $emoticon);
}
return $collection;