protected function media($attributes, $text, $tagName, $html, $embed = true) { if ( !isset($attributes['src']) || !isset($attributes['folder']) || !in_array($attributes['folder'], array('audio', 'videos')) ) { throw new MMSynchException(sprintf('Mal formed media tag in core_content %s', $html)); } $ids = array(); if ( $attributes['folder'] == 'audio' && $this->article->source['a_related_inline_audio'] != "" ) { $tableName = 'audio'; $ids = explode(',', $this->article->source['a_related_inline_audio']); } elseif ( $attributes['folder'] == 'videos' && $this->article->source['a_related_inline_video'] != "" ) { $tableName = 'video'; $ids = explode(',', $this->article->source['a_related_inline_video']); } if ( count($ids) > 0 ) { $filenamePos = strrpos($attributes['src'], '/'); $fileName = substr($attributes['src'], $filenamePos ? $filenamePos + 1 : 0); $sql = ' SELECT media.id as id, media.content_id as c_id, media.file as file, media.screen_capture as screen_capture, media.language as language FROM %s as media INNER JOIN content as c ON media.content_id = c.id WHERE media.id IN (%s) AND media.file like "%s"; '; $result = MMSynchronizer::instance()->db->arrayQuery(sprintf($sql, $tableName, implode(',', $ids), '%' . $fileName)); $screen_capture = null; if ( isset($attributes['screen_capture']) && $attributes['screen_capture'] != '' ) { try { $file = MMSynchFileManager::fromFileName($this->article->getOrigin(), $this->article->getPublisher(), MMSynchFileManager::IMAGE_FOLDER, $attributes['screen_capture']); $screen_capture = file_get_contents($file->getFullPath()); $file->setCanArchived(); } catch ( Exception $e ) { $this->article->addWarning($e->getMessage()); } } while ( list(, $row) = each($result) ) { if ( $tableName == 'audio' ) { $media = MMSynchMediaAudio::fetch($row['id']); if($screen_capture) { $media->source['audio_screen_capture'] = $screen_capture; } elseif($row['screen_capture']) { $media->source['audio_screen_capture'] = $row['screen_capture']; } } else { $media = MMSynchMediaVideo::fetch($row['id']); if($screen_capture) { $media->source['video_screen_capture'] = $screen_capture; } elseif($row['screen_capture']) { $media->source['video_screen_capture'] = $row['screen_capture']; } } $content = $media->getContent(); if ( !$content instanceof SQLIContent ) { throw new MMSynchException(sprintf('Media with id %s not synchronized', $row['id'])); } if ( isset($attributes['view']) && $attributes['view'] == 'inline' ) { $replacement = '<embed-inline view="embed-inline" size="medium" id="eZObject_%s" />'; } else { $replacement = '<embed view="embed" size="medium" id="eZObject_%s" />'; } $this->addRelatedMedia($content->attribute('id'), $row['language']); if($embed) { return sprintf($replacement, $content->attribute('id')); } else { return $content->attribute('id'); } } } throw new MMSynchException(sprintf('Media with filename %s not have media table row', $attributes['src'])); }
protected function imgHandler($attributes) { $attributesName = array('alt', 'legend'); foreach ( $attributesName as $attributeName ) { if ( !isset($attributes[$attributeName]) ) { $attributes[$attributeName] = ''; } } $filePath = $attributes['src']; $filenamePos = strrpos($filePath, '/'); $fileName = substr($filePath, $filenamePos ? $filenamePos + 1 : 0); $file = SQLIContent::create( new SQLIContentOptions( array( 'class_identifier' => 'image', 'remote_id' => md5($this->article->remoteId() . $fileName), 'language' => $this->article->getLanguage() ))); $file->fields->headline = $attributes['alt']; //$file->fields->original_size = $attributes['width'] . 'x' . $attributes['height']; $file->fields->alternate_text = $attributes['legend'] ? $attributes['legend'] : $attributes['alt']; $file->fields->language = $this->article->getLanguage(); $img = MMSynchFileManager::fromFileName($this->article->getOrigin(), $this->article->getPublisher(), MMSynchFileManager::IMAGE_FOLDER, $filePath); $fullPath = $img->getFullPath(); $file->fields->file = $fullPath; $file->fields->size = filesize($fullPath); $fileInfo = finfo_open(FILEINFO_MIME_TYPE); $file->fields->media_encoding = finfo_file($fileInfo, $fullPath); finfo_close($fileInfo); $location = $this->article->getPublisher()->getContentMediaImage()->defaultLocation; $file->addLocation($location); MMSynchContentPublisher::getInstance()->publish($file); $img->setCanArchived(); $replacement = '<img src="' . '/newsletter/image/' . $file->id . '/' . $this->article->getLanguage() . '/fmc' . '" alt="' . $attributes['legend'] . '" />'; return sprintf($replacement, $file->id); }