Esempio n. 1
0
 /**
  * DOCUMENT ME
  * @param SimpleXMLElement $slot
  * @return mixed
  */
 protected function parseSlotForeignHtml(SimpleXMLElement $slot, $title = null, &$counters = null)
 {
     $n = 1;
     $html = $slot->value->__toString();
     $segments = aString::splitAndCaptureAtEarliestMatch($html, array('/\\<a href=\\"[^\\"]+\\"[^\\>]*>\\s*(?:\\<br \\/\\>|&nbsp;|\\s)*\\<img.*?src="[^\\"]+[^\\>]*\\>(?:\\<br \\/\\>|&nbsp;|\\s)*\\<\\/a\\>/is', '/\\<img.*?src="[^\\"]+".*?\\>/is', '/\\<object.*?\\>.*?\\<\\/object\\>/is', '/\\<iframe.*?\\>.*?\\<\\/iframe\\>/is'));
     foreach ($segments as $segment) {
         $mediaItem = null;
         if (preg_match('/\\<object.*?\\>.*?\\<\\/object\\>|\\<iframe.*?\\>.*?\\<\\/iframe\\>/is', $segment)) {
             $form = new aMediaVideoForm();
             $result = $form->classifyEmbed($segment);
             if ($result['ok']) {
                 $info = array('title' => isset($result['serviceInfo']['title']) ? $result['serviceInfo']['title'] : $title . ' video ' . $n, 'embed' => $result['embed'], 'width' => isset($result['width']) ? $result['width'] : null, 'height' => isset($result['height']) ? $result['height'] : null, 'format' => isset($result['format']) ? $result['format'] : null, 'type' => 'video', 'tags' => isset($result['serviceInfo']['tags']) ? preg_split('/\\s*,\\s*/', $result['serviceInfo']['tags']) : array(), 'service_url' => isset($result['serviceInfo']['url']) ? $result['serviceInfo']['url'] : null);
                 $mediaId = $this->findOrAddVideo($info);
                 $slotInfos[] = array('type' => 'aVideo', 'mediaId' => $mediaId);
                 $n++;
             }
         } elseif (preg_match('/<img.*?src="(.*?)".*?>/is', $segment, $matches)) {
             $src = $matches[1];
             // &amp; won't work if we don't decode it to & before passing it to the server
             $src = html_entity_decode($src);
             $mediaId = $this->findOrAddMediaItem($src, 'id');
             if (preg_match('/href="(.*?)"/', $segment, $matches)) {
                 $url = $matches[1];
             }
             // $mediaItem->save();
             if (!is_null($mediaId)) {
                 $slotInfo = array('type' => 'aImage', 'mediaId' => $mediaId, 'value' => array());
                 if (isset($url)) {
                     $slotInfo = array('type' => 'aButton', 'value' => array('url' => $url, 'title' => ''), 'mediaId' => $mediaId);
                 }
                 $slotInfos[] = $slotInfo;
             }
         } else {
             $slotInfos[] = array('type' => 'aRichText', 'value' => aHtml::simplify($segment));
         }
     }
     return $slotInfos;
 }