public function __get($var)
 {
     if ($var == 'url') {
         $m = Kwc_Abstract::createModel($this->componentClass);
         $row = $m->getRow($this->dbId);
         if (!$row) {
             return null;
         }
         $fRow = $row->getParentRow('File');
         if (!$fRow) {
             return null;
         }
         $filename = $row->filename;
         if (!$filename) {
             $filename = $fRow->filename;
         }
         $filename .= '.' . $fRow->extension;
         $ret = Kwf_Media::getUrl($this->componentClass, $this->componentId, 'default', $filename);
         $ev = new Kwf_Component_Event_CreateMediaUrl($this->componentClass, $this, $ret);
         Kwf_Events_Dispatcher::fireEvent($ev);
         return $ev->url;
     } else {
         return parent::__get($var);
     }
 }
 public function __get($var)
 {
     if ($var == 'url') {
         $m = Kwc_Abstract::createModel($this->componentClass);
         $row = $m->getRow($this->dbId);
         if (!$row || !$row->own_download) {
             //not own_download but still output thru own url to be ablte to call own isValidMediaOutput
             $row = $this->chained->getComponent()->getRow();
             if (!$row) {
                 return null;
             }
             $fRow = $row->getParentRow('File');
             if (!$fRow) {
                 return null;
             }
             $filename = $row->filename;
             if (!$filename) {
                 $filename = $fRow->filename;
             }
             $filename .= '.' . $fRow->extension;
             return Kwf_Media::getUrl($this->componentClass, $this->componentId, 'default', $filename);
         }
         return $this->getChildComponent('-download')->url;
     } else {
         return parent::__get($var);
     }
 }
 public final function getLinkedData()
 {
     if (!isset($this->_data)) {
         $masterLinkData = $this->chained->getLinkedData(array('ignoreVisible' => true));
         if (!$masterLinkData) {
             $this->_data = false;
         }
         if ($masterLinkData) {
             if (is_null($this->_type)) {
                 throw new Kwf_Exception("_type may not be null");
             }
             if ($this->_type == 'Trl') {
                 $linkComponent = Kwc_Chained_Trl_Component::getChainedByMaster($masterLinkData, $this);
             } else {
                 if ($this->_type == 'Cc') {
                     $linkComponent = Kwc_Chained_Cc_Component::getChainedByMaster($masterLinkData, $this);
                 }
             }
             if (!$linkComponent) {
                 $this->_data = false;
                 //kann offline sein
             } else {
                 $this->_data = $linkComponent;
             }
         }
     }
     $m = Kwc_Abstract::createModel($this->chained->componentClass);
     $result = $m->fetchColumnsByPrimaryId(array('anchor'), $this->chained->dbId);
     if ($result['anchor']) {
         $this->_anchor = $result['anchor'];
     }
     return $this->_data;
 }
 protected function _getData($select = array())
 {
     $m = Kwc_Abstract::createModel($this->componentClass);
     $newsId = $m->fetchColumnByPrimaryId('news_id', $this->dbId);
     if ($newsId) {
         return Kwf_Component_Data_Root::getInstance()->getComponentByDbId('news_' . $newsId, array('subroot' => $this));
     }
     return false;
 }
 public function __get($var)
 {
     if ($var == 'url') {
         $m = Kwc_Abstract::createModel($this->componentClass);
         $row = $m->getRow($this->dbId);
         if (!$row) {
             return null;
         }
         $fRow = $row->getParentRow('File');
         if (!$fRow) {
             return null;
         }
         $filename = $row->filename;
         if (!$filename) {
             $filename = $fRow->filename;
         }
         $filename .= '.' . $fRow->extension;
         return Kwf_Media::getUrl($this->componentClass, $this->componentId, 'default', $filename);
     } else {
         return parent::__get($var);
     }
 }
Exemple #6
0
 protected function _getData($select = array())
 {
     $m = Kwc_Abstract::createModel($this->componentClass);
     $result = $m->fetchColumnsByPrimaryId(array('target', 'anchor'), $this->dbId);
     if ($result) {
         $ret = null;
         $s = $select;
         $s['subroot'] = $this;
         $s['limit'] = 1;
         $components = Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($result['target'], $s);
         if ($components) {
             $ret = $components[0];
         }
         if (!$ret) {
             $ret = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($result['target'], $select);
         }
         if ($result['anchor']) {
             $this->_anchor = $result['anchor'];
         }
         return $ret;
     }
     return false;
 }
 protected function startElement($parser, $element, $attributes)
 {
     $finalHTML = $this->_finalHTML;
     if ($element == 'SPAN') {
         if (isset($attributes['STYLE'])) {
             $style = $attributes['STYLE'];
         } else {
             $style = '';
         }
         if (preg_match('# *font-weight *: *bold *; *#', $style, $matches)) {
             array_push($this->_stack, 'strong');
             $this->_finalHTML .= '<strong>';
         } elseif (preg_match('# *font-style *: *italic *; *#', $style, $matches)) {
             array_push($this->_stack, 'em');
             $this->_finalHTML .= '<em>';
         } elseif (preg_match('# *text-decoration *: *underline *; *#', $style, $matches)) {
             array_push($this->_stack, 'u');
             $this->_finalHTML .= '<u>';
         } elseif (preg_match('# *color *: *[0-9A-Za-z]* *#', $style, $matches) && $this->_enableColor) {
             array_push($this->_stack, 'span');
             $this->_finalHTML .= '<span style="' . $style . '">';
         } elseif (preg_match('# *background-color *: *[0-9A-Za-z]* *#', $style, $matches) && $this->_enableColor) {
             array_push($this->_stack, 'span');
             $this->_finalHTML .= '<span style="' . $style . '">';
         } else {
             $allowedClasses = array();
             foreach ($this->_getMasterStyles() as $s) {
                 if ($s['tagName'] == strtolower($element)) {
                     $allowedClasses[] = $s['className'];
                 }
             }
             if ($this->_enableCursorSpan && isset($attributes['CLASS']) && $attributes['CLASS'] == '_mce_type-bookmark') {
                 array_push($this->_stack, 'span');
                 $this->_finalHTML .= '<span class="' . $attributes['CLASS'] . '"';
                 if (isset($attributes['STYLE'])) {
                     $this->_finalHTML .= ' style="' . $attributes['STYLE'] . '"';
                 }
                 if (isset($attributes['ID'])) {
                     $this->_finalHTML .= ' id="' . $attributes['ID'] . '"';
                 }
                 $this->_finalHTML .= '>';
             } else {
                 if ($this->_enableStyles && isset($attributes['CLASS']) && (preg_match('#^style[0-9]+$#', $attributes['CLASS']) || in_array($attributes['CLASS'], $allowedClasses))) {
                     array_push($this->_stack, 'span');
                     $this->_finalHTML .= '<span class="' . $attributes['CLASS'] . '">';
                 } else {
                     array_push($this->_stack, false);
                 }
             }
         }
     } elseif ($element == 'BODY' || $element == 'O:P') {
         array_push($this->_stack, false);
         //do nothing
     } elseif ($element == 'SCRIPT') {
         array_push($this->_stack, false);
         $this->_deleteContent++;
     } else {
         if ($element == 'IMG') {
             $src = $attributes['SRC'];
             $id = preg_quote($this->_dbId);
             if (preg_match('#/media/([^/]+)/(' . $id . '-i[0-9]+)#', $src, $m)) {
                 //"/media/$class/$id/$type/$checksum/$filename.$extension$random"
                 $class = Kwc_Abstract::getChildComponentClass($this->_model->getComponentClass(), 'child', 'image');
                 $imageRow = Kwc_Abstract::createModel($class)->getRow($m[2]);
                 if (isset($attributes['WIDTH']) && $imageRow) {
                     $imageRow->width = $attributes['WIDTH'];
                 }
                 if (isset($attributes['HEIGHT']) && $imageRow) {
                     $imageRow->height = $attributes['HEIGHT'];
                 }
                 if (isset($attributes['STYLE']) && $imageRow) {
                     if (preg_match('#[^a-zA-Z\\-]*width: *([0-9]+)px#', $attributes['STYLE'], $m)) {
                         $imageRow->width = $m[1];
                     }
                     if (preg_match('#[^a-zA-Z\\-]*height: *([0-9]+)px#', $attributes['STYLE'], $m)) {
                         $imageRow->height = $m[1];
                     }
                 }
                 if ($imageRow) {
                     $imageRow->save();
                     $attributes['WIDTH'] = $imageRow->width;
                     $attributes['HEIGHT'] = $imageRow->height;
                     if (isset($attributes['STYLE'])) {
                         unset($attributes['STYLE']);
                     }
                 }
             }
         }
         if ($this->_enableTagsWhitelist && !in_array(strtolower($element), array_keys($this->_tagsWhitelist))) {
             //ignore this tag
             array_push($this->_stack, false);
         } else {
             $this->_finalHTML .= '<' . strtolower($element);
             foreach ($attributes as $key => $value) {
                 if (in_array(strtolower($key), $this->_tagsWhitelist[strtolower($element)])) {
                     $allowedClasses = array();
                     foreach ($this->_getMasterStyles() as $s) {
                         if ($s['tagName'] == strtolower($element)) {
                             $allowedClasses[] = $s['className'];
                         }
                     }
                     if ($key != 'CLASS' || (preg_match('#^style[0-9]+$#', $value) || in_array($value, $allowedClasses))) {
                         $this->_finalHTML .= ' ' . strtolower($key) . '="' . $value . '"';
                     }
                 }
             }
             if ($element == 'BR' || $element == 'IMG') {
                 $this->_finalHTML .= ' /';
                 array_push($this->_stack, false);
             } else {
                 array_push($this->_stack, strtolower($element));
             }
             $this->_finalHTML .= '>';
         }
     }
     if ($this->_deleteContent) {
         $this->_finalHTML = $finalHTML;
     }
 }
 public function tidy($html, Kwc_Basic_Text_Parser $parser = null)
 {
     //convert umlauts from NFD to NFC
     $html = str_replace('u' . chr(0xcc) . chr(0x88), 'ü', $html);
     $html = str_replace('a' . chr(0xcc) . chr(0x88), 'ä', $html);
     $html = str_replace('o' . chr(0xcc) . chr(0x88), 'ö', $html);
     $html = str_replace('U' . chr(0xcc) . chr(0x88), 'Ü', $html);
     $html = str_replace('A' . chr(0xcc) . chr(0x88), 'Ä', $html);
     $html = str_replace('O' . chr(0xcc) . chr(0x88), 'Ö', $html);
     //delete zero width space, causes problems in Lotus Notes
     $html = str_replace(chr(0xe2) . chr(0x80) . chr(0x8b), '', $html);
     //delete BOM that might have sneaked into the text (at any position)
     $html = str_replace(chr(0xef) . chr(0xbb) . chr(0xbf), '', $html);
     $enableTidy = Kwc_Abstract::getSetting($this->_componentClass, 'enableTidy');
     $enableFontSize = Kwc_Abstract::getSetting($this->_componentClass, 'enableFontSize');
     $config = array();
     if (!$enableFontSize) {
         $config['drop-font-tags'] = true;
     }
     if ($enableTidy) {
         //woraround für tidy bug wo er zwei class-attribute in einen
         //tag schreibt wenn eins davon leer ist
         //siehe Kwc_Basic_Text_ModelContentTest::testTidyRemovesSomeText
         //einfach leere klassen löschen
         $html = preg_replace('#<(.[a-z]+) ([^>]*)class=""([^>]*)>#', '<\\1 \\2 \\3>', $html);
         //html kommentare löschen, löscht auch word schas mit
         $html = preg_replace('#<!--.*?-->#s', '', $html);
         $html = str_replace('data-mce-type="bookmark"', 'class="_mce_type-bookmark"', $html);
         $html = str_replace('&nbsp;', '#nbsp#', $html);
         //einstellungen oben funktionieren nicht richtig
         $html = Kwf_Util_Tidy::repairHtml($html, $config);
         if (!$parser) {
             $parser = new Kwc_Basic_Text_Parser($this->componentId, $this->getModel());
             $parser->setMasterStyles(Kwc_Basic_Text_StylesModel::getMasterStyles());
         }
         $parser->setEnableColor(Kwc_Abstract::getSetting($this->_componentClass, 'enableColors'));
         $parser->setEnableTagsWhitelist(Kwc_Abstract::getSetting($this->_componentClass, 'enableTagsWhitelist'));
         $parser->setEnableStyles(Kwc_Abstract::getSetting($this->_componentClass, 'enableStyles'));
         $html = $parser->parse($html);
         $html = Kwf_Util_Tidy::repairHtml($html, $config);
         $html = str_replace('class="_mce_type-bookmark"', 'data-mce-type="bookmark"', $html);
         $html = str_replace('#nbsp#', '&nbsp;', $html);
     }
     $classes = $this->_classes;
     $newContent = '';
     foreach ($this->getContentParts($html) as $part) {
         if (is_string($part)) {
             $newContent .= $part;
         } else {
             if ($part['type'] == 'invalidImage') {
                 if (isset($part['componentId']) && class_exists($part['componentClass']) && (strtolower($part['componentClass']) == 'kwc_basic_image_component' || is_subclass_of($part['componentClass'], 'Kwc_Basic_Image_Component'))) {
                     $srcRow = Kwc_Abstract::createModel($part['componentClass'])->getRow($part['componentId']);
                     if ($srcRow->imageExists()) {
                         $destRow = Kwc_Abstract::createModel($classes['image'])->createRow($srcRow->toArray());
                         $childComponentRow = $this->addChildComponentRow('image', $destRow);
                         $destRow->save();
                         $imageComponent = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->component_id . '-i' . $childComponentRow->nr)->getComponent();
                         $dimension = $imageComponent->getImageDimensions();
                         $newContent .= "<img src=\"" . $imageComponent->getImageUrl() . "\" " . "width=\"{$dimension['width']}\" " . "height=\"{$dimension['height']}\" />";
                         continue;
                     }
                 }
                 $client = new Zend_Http_Client();
                 try {
                     $client->setUri($part['src']);
                 } catch (Zend_Uri_Exception $e) {
                     //wann relative url mit http_host davor probieren
                     if (isset($_SERVER['HTTP_HOST'])) {
                         $client->setUri('http://' . $_SERVER['HTTP_HOST'] . '/' . $part['src']);
                     }
                 }
                 try {
                     $response = $client->request();
                 } catch (Exception $e) {
                     continue;
                 }
                 if (!$response->isSuccessful()) {
                     continue;
                 }
                 $contentType = $response->getHeader('Content-type');
                 if ($contentType == 'image/jpg' || $contentType == 'image/jpeg') {
                     $extension = 'jpg';
                 } else {
                     if ($contentType == 'image/gif') {
                         $extension = 'gif';
                     } else {
                         if ($contentType == 'image/png') {
                             $extension = 'png';
                         } else {
                             continue;
                         }
                     }
                 }
                 $destFileRow = Kwc_Abstract::createModel($classes['image'])->getReferencedModel('Image')->createRow();
                 $path = explode('?', $part['src']);
                 if (preg_match('#([^/]*)\\.[a-z]+$#U', $path[0], $m)) {
                     $srcFileName = Zend_Filter::filterStatic($m[1], 'Alnum', array(ENT_QUOTES));
                 }
                 if (!isset($srcFileName) || !$srcFileName) {
                     $srcFileName = 'download';
                 }
                 $destFileRow->writeFile($response->getBody(), $srcFileName, $extension, $contentType);
                 $destRow = Kwc_Abstract::createModel($classes['image'])->createRow();
                 $destRow->kwf_upload_id = $destFileRow->id;
                 $size = getimagesize($destFileRow->getFileSource());
                 $destRow->width = $size[0];
                 $destRow->height = $size[1];
                 $destRow->filename = $srcFileName;
                 $destRow->cover = true;
                 $childComponentRow = $this->addChildComponentRow('image', $destRow);
                 $destRow->save();
                 $imageComponent = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->component_id . '-i' . $childComponentRow->nr)->getComponent();
                 $dimension = $imageComponent->getImageDimensions();
                 $newContent .= "<img src=\"" . $imageComponent->getImageUrl() . "\" " . "width=\"{$dimension['width']}\" " . "height=\"{$dimension['height']}\" />";
             } else {
                 if ($part['type'] == 'invalidLink') {
                     $model = Kwc_Abstract::createModel($classes['link']);
                     $destRow = $this->_getChildComponentRow('link', $model);
                     if (isset($part['componentId'])) {
                         try {
                             $srcRow = $model->getRow($part['componentId']);
                         } catch (Kwf_Exception $e) {
                             $srcRow = false;
                         }
                         if (is_instance_of($classes['link'], 'Kwc_Basic_LinkTag_Component')) {
                             $linkClasses = Kwc_Abstract::getChildComponentClasses($classes['link'], 'child');
                             if ($srcRow && class_exists($linkClasses[$srcRow->component])) {
                                 $linkModel = Kwc_Abstract::createModel($linkClasses[$srcRow->component]);
                                 $srcLinkRow = $linkModel->getRow($part['componentId'] . '-child');
                                 if ($srcLinkRow) {
                                     $destRow->component = $srcRow->component;
                                     $destRow->save();
                                     $destLinkRow = $linkModel->getRow($destRow->component_id . '-child');
                                     if (!$destLinkRow) {
                                         $destLinkRow = $linkModel->createRow();
                                         $destLinkRow->component_id = $destRow->component_id . '-child';
                                     }
                                     foreach ($srcLinkRow->toArray() as $k => $i) {
                                         if ($k != 'component_id') {
                                             $destLinkRow->{$k} = $i;
                                         }
                                     }
                                     $destLinkRow->save();
                                     $newContent .= "<a href=\"{$destRow->component_id}\">";
                                     continue;
                                 }
                             }
                         } else {
                             if (is_instance_of($classes['link'], 'Kwc_Basic_LinkTag_Abstract_Component')) {
                                 if ($srcRow) {
                                     foreach ($srcRow->toArray() as $k => $i) {
                                         if ($k != 'component_id') {
                                             $destRow->{$k} = $i;
                                         }
                                     }
                                     $destRow->save();
                                     $newContent .= "<a href=\"{$destRow->component_id}\">";
                                     continue;
                                 }
                             } else {
                                 //Kein link möglich
                                 continue;
                             }
                         }
                     }
                     if (!$destRow) {
                         $destRow = $model->createRow();
                         $this->addChildComponentRow('link', $destRow);
                     }
                     if (is_instance_of($classes['link'], 'Kwc_Basic_LinkTag_Component')) {
                         $linkClasses = Kwc_Abstract::getChildComponentClasses($classes['link'], 'child');
                         $destRow->component = null;
                         if (preg_match('#^mailto:#', $part['href'], $m)) {
                             if (isset($linkClasses['mail']) && $linkClasses['mail']) {
                                 $destRow->component = 'mail';
                             }
                         } else {
                             if (isset($linkClasses['intern']) && $linkClasses['intern'] && Kwf_Config::getValue('server.redirectToDomain')) {
                                 $url = $part['href'];
                                 $parsedUrl = parse_url($url);
                                 if (!isset($parsedUrl['host'])) {
                                     if (isset($_SERVER['HTTP_HOST'])) {
                                         $url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
                                     } else {
                                         $url = 'http://' . Kwf_Registry::get('config')->server->domain . $url;
                                     }
                                 }
                                 $internLinkPage = Kwf_Component_Data_Root::getInstance()->getPageByUrl($url, null);
                                 if ($internLinkPage) {
                                     $destRow->component = 'intern';
                                 }
                             }
                             if (!$destRow->component && isset($linkClasses['extern']) && $linkClasses['extern']) {
                                 $destRow->component = 'extern';
                             }
                         }
                         if (!$destRow->component) {
                             continue;
                         }
                         //kein solcher-link möglich
                         $destRow->save();
                         $destClasses = Kwc_Abstract::getChildComponentClasses($classes['link'], 'child');
                         $row = Kwc_Abstract::createModel($destClasses[$destRow->component])->getRow($destRow->component_id . '-child');
                         if (!$row) {
                             $row = Kwc_Abstract::createModel($destClasses[$destRow->component])->createRow();
                         }
                         $row->component_id = $destRow->component_id . '-child';
                         if ($destRow->component == 'extern') {
                             $row->target = $part['href'];
                         } else {
                             if ($destRow->component == 'intern') {
                                 $row->target = $internLinkPage->dbId;
                             } else {
                                 preg_match('#^mailto:(.*)\\??(.*)#', $part['href'], $m);
                                 $row->mail = $m[1];
                                 $m = parse_str($m[2]);
                                 $row->subject = isset($m['subject']) ? $m['subject'] : '';
                                 $row->text = isset($m['body']) ? $m['body'] : '';
                             }
                         }
                         $row->save();
                     } else {
                         if (is_instance_of($classes['link'], 'Kwc_Basic_LinkTag_Extern_Component')) {
                             $destRow->target = $part['href'];
                             $destRow->save();
                         } else {
                             //Kein link möglich
                             continue;
                         }
                     }
                     $newContent .= "<a href=\"{$destRow->component_id}\">";
                 } else {
                     if ($part['type'] == 'invalidDownload') {
                         $srcRow = Kwc_Abstract::createModel($classes['download'])->getRow($part['componentId']);
                         if ($srcRow->fileExists()) {
                             $destRow = Kwc_Abstract::createModel($classes['download'])->createRow($srcRow->toArray());
                             $this->addChildComponentRow('download', $destRow);
                             $destRow->save();
                             $newContent .= "<a href=\"{$destRow->component_id}\">";
                             continue;
                         }
                     } else {
                         if (is_string($part)) {
                             $newContent .= $part;
                         } else {
                             $newContent .= $part['html'];
                         }
                     }
                 }
             }
         }
     }
     return $newContent;
 }