예제 #1
0
 /**
  * Takes a chunk of content containing abstracted link references,
  * and expands them to full urls for displaying on the site front-end.
  */
 public static function translateFrom($text)
 {
     $text = preg_replace(array('/{CCM:BASE_URL}/i'), array(\Core::getApplicationURL()), $text);
     // now we add in support for the links
     $text = preg_replace_callback('/{CCM:CID_([0-9]+)}/i', function ($matches) {
         $cID = $matches[1];
         if ($cID > 0) {
             $c = Page::getByID($cID, 'ACTIVE');
             return Loader::helper("navigation")->getLinkToCollection($c);
         }
     }, $text);
     // now we add in support for the files that we view inline
     $dom = new HtmlDomParser();
     $r = $dom->str_get_html($text);
     if (is_object($r)) {
         foreach ($r->find('concrete-picture') as $picture) {
             $fID = $picture->fid;
             $alt = $picture->alt;
             $style = $picture->style;
             $fo = \File::getByID($fID);
             if (is_object($fo)) {
                 if ($style) {
                     $image = new \Concrete\Core\Html\Image($fo, false);
                     $image->getTag()->width(false)->height(false);
                 } else {
                     $image = new \Concrete\Core\Html\Image($fo);
                 }
                 $tag = $image->getTag();
                 if ($alt) {
                     $tag->alt($alt);
                 }
                 if ($style) {
                     $tag->style($style);
                 }
                 $picture->outertext = (string) $tag;
             }
         }
         $text = (string) $r;
     }
     // now files we download
     $text = preg_replace_callback('/{CCM:FID_DL_([0-9]+)}/i', function ($matches) {
         $fID = $matches[1];
         if ($fID > 0) {
             $c = Page::getCurrentPage();
             if (is_object($c)) {
                 return URL::to('/download_file', 'view', $fID, $c->getCollectionID());
             } else {
                 return URL::to('/download_file', 'view', $fID);
             }
         }
     }, $text);
     // snippets
     $snippets = Snippet::getActiveList();
     foreach ($snippets as $sn) {
         $text = $sn->findAndReplace($text);
     }
     return $text;
 }
예제 #2
0
 /**
  * Takes a chunk of content containing abstracted link references,
  * and expands them to full urls for displaying on the site front-end.
  */
 public static function translateFrom($text)
 {
     $text = preg_replace(array('/{CCM:BASE_URL}/i'), array(\Core::getApplicationURL()), $text);
     // now we add in support for the links
     $text = preg_replace_callback('/{CCM:CID_([0-9]+)}/i', function ($matches) {
         $cID = $matches[1];
         if ($cID > 0) {
             $c = Page::getByID($cID, 'ACTIVE');
             return Loader::helper("navigation")->getLinkToCollection($c);
         }
     }, $text);
     // now we add in support for the files that we view inline
     $dom = new HtmlDomParser();
     $r = $dom->str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
     if (is_object($r)) {
         foreach ($r->find('concrete-picture') as $picture) {
             $fID = $picture->fid;
             $fo = \File::getByID($fID);
             if (is_object($fo)) {
                 $style = (string) $picture->style;
                 // move width px to width attribute and height px to height attribute
                 $widthPattern = "/(?:^width|[^-]width):\\s([0-9]+)px;?/i";
                 if (preg_match($widthPattern, $style, $matches)) {
                     $style = preg_replace($widthPattern, '', $style);
                     $picture->width = $matches[1];
                 }
                 $heightPattern = "/(?:^height|[^-]height):\\s([0-9]+)px;?/i";
                 if (preg_match($heightPattern, $style, $matches)) {
                     $style = preg_replace($heightPattern, '', $style);
                     $picture->height = $matches[1];
                 }
                 if ($style === '') {
                     unset($picture->style);
                 } else {
                     $picture->style = $style;
                 }
                 $image = new \Concrete\Core\Html\Image($fo);
                 $tag = $image->getTag();
                 foreach ($picture->attr as $attr => $val) {
                     if (!in_array($attr, self::$blackListImgAttributes)) {
                         //Apply attributes to child img, if using picture tag.
                         if ($tag instanceof \Concrete\Core\Html\Object\Picture) {
                             foreach ($tag->getChildren() as $child) {
                                 if ($child instanceof \HtmlObject\Image) {
                                     $child->{$attr}($val);
                                 }
                             }
                         } elseif (is_callable(array($tag, $attr))) {
                             $tag->{$attr}($val);
                         } else {
                             $tag->setAttribute($attr, $val);
                         }
                     }
                 }
                 if (!in_array('alt', array_keys($picture->attr))) {
                     if ($tag instanceof \Concrete\Core\Html\Object\Picture) {
                         foreach ($tag->getChildren() as $child) {
                             if ($child instanceof \HtmlObject\Image) {
                                 $child->alt('');
                             }
                         }
                     } else {
                         $tag->alt('');
                     }
                 }
                 $picture->outertext = (string) $tag;
             }
         }
         $text = (string) $r->restore_noise($r);
     }
     // now we add in support for the links
     $text = preg_replace_callback('/{CCM:FID_([0-9]+)}/i', function ($matches) {
         $fID = $matches[1];
         if ($fID > 0) {
             $f = File::getByID($fID);
             if (is_object($f)) {
                 return $f->getURL();
             }
         }
     }, $text);
     // now files we download
     $text = preg_replace_callback('/{CCM:FID_DL_([0-9]+)}/i', function ($matches) {
         $fID = $matches[1];
         if ($fID > 0) {
             $c = Page::getCurrentPage();
             if (is_object($c)) {
                 return URL::to('/download_file', 'view', $fID, $c->getCollectionID());
             } else {
                 return URL::to('/download_file', 'view', $fID);
             }
         }
     }, $text);
     // snippets
     $snippets = Snippet::getActiveList();
     foreach ($snippets as $sn) {
         $text = $sn->findAndReplace($text);
     }
     return $text;
 }
예제 #3
0
 function translateFrom($text)
 {
     $text = preg_replace(array('/{CCM:BASE_URL}/i'), array(BASE_URL . DIR_REL), $text);
     // now we add in support for the links
     $text = preg_replace_callback('/{CCM:CID_([0-9]+)}/i', array('static', 'replaceCollectionID'), $text);
     // now we add in support for the files that we view inline
     $dom = new HtmlDomParser();
     $r = $dom->str_get_html($text);
     if (is_object($r)) {
         foreach ($r->find('concrete-picture') as $picture) {
             $fID = $picture->fid;
             $alt = $picture->alt;
             $style = $picture->style;
             $fo = \File::getByID($fID);
             if (is_object($fo)) {
                 $image = new \Concrete\Core\Html\Image($fo);
                 $tag = $image->getTag();
                 if ($alt) {
                     $tag->alt($alt);
                 }
                 if ($style) {
                     $tag->style($style);
                 }
                 $picture->outertext = (string) $tag;
             }
         }
         $text = (string) $r;
     }
     // now files we download
     $text = preg_replace_callback('/{CCM:FID_DL_([0-9]+)}/i', array('static', 'replaceDownloadFileID'), $text);
     // snippets
     $snippets = Snippet::getActiveList();
     foreach ($snippets as $sn) {
         $text = $sn->findAndReplace($text);
     }
     return $text;
 }