Esempio n. 1
0
 public function view()
 {
     if (Loader::helper('validation/token')->validate('editor')) {
         $obj = new stdClass();
         $obj->snippets = array();
         $u = new User();
         if ($u->isRegistered()) {
             $snippets = \Concrete\Core\Editor\Snippet::getActiveList();
             foreach ($snippets as $sns) {
                 $menu = new stdClass();
                 $menu->scsHandle = $sns->getSystemContentEditorSnippetHandle();
                 $menu->scsName = $sns->getSystemContentEditorSnippetName();
                 $obj->snippets[] = $menu;
             }
         }
         $c = Page::getByID($_REQUEST['cID']);
         $obj->classes = array();
         if (is_object($c) && !$c->isError()) {
             $cp = new Permissions($c);
             if ($cp->canViewPage()) {
                 $pt = $c->getCollectionThemeObject();
                 if (is_object($pt)) {
                     $obj->classes = $pt->getThemeEditorClasses();
                 }
             }
         }
         print Loader::helper('json')->encode($obj);
         exit;
     }
 }
 public function import(\SimpleXMLElement $sx)
 {
     if (isset($sx->systemcontenteditorsnippets)) {
         foreach ($sx->systemcontenteditorsnippets->snippet as $th) {
             $pkg = static::getPackageObject($th['package']);
             $scs = Snippet::add($th['handle'], $th['name'], $pkg);
             if ($th['activated'] == '1') {
                 $scs->activate();
             }
         }
     }
 }
 public function execute(Batch $batch)
 {
     $snippets = $batch->getObjectCollection('content_editor_snippet');
     if (!$snippets) {
         return;
     }
     foreach ($snippets->getSnippets() as $snippet) {
         if (!$snippet->getPublisherValidator()->skipItem()) {
             $pkg = null;
             if ($snippet->getPackage()) {
                 $pkg = \Package::getByHandle($snippet->getPackage());
             }
             $t = Snippet::add($snippet->getHandle(), $snippet->getNAme(), $pkg);
             if ($snippet->getIsActivated()) {
                 $t->activate();
             }
         }
     }
 }
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * Returns an array of package items (e.g. blocks, themes)
  */
 public function getPackageItems()
 {
     $items = array();
     $items['attribute_categories'] = AttributeKeyCategory::getListByPackage($this);
     $items['permission_categories'] = PermissionKeyCategory::getListByPackage($this);
     $items['permission_access_entity_types'] = PermissionAccessEntityType::getListByPackage($this);
     $items['attribute_keys'] = AttributeKey::getListByPackage($this);
     $items['attribute_sets'] = AttributeSet::getListByPackage($this);
     $items['group_sets'] = GroupSet::getListByPackage($this);
     $items['page_types'] = PageType::getListByPackage($this);
     $items['page_templates'] = PageTemplate::getListByPackage($this);
     $items['mail_importers'] = MailImporter::getListByPackage($this);
     $items['gathering_item_template_types'] = GatheringItemTemplateType::getListByPackage($this);
     $items['gathering_item_templates'] = GatheringItemTemplate::getListByPackage($this);
     $items['gathering_data_sources'] = GatheringDataSource::getListByPackage($this);
     $items['features'] = Feature::getListByPackage($this);
     $items['feature_categories'] = FeatureCategory::getListByPackage($this);
     $btl = new BlockTypeList();
     $btl->filterByPackage($this);
     $blocktypes = $btl->get();
     $items['block_types'] = $blocktypes;
     $items['block_type_sets'] = BlockTypeSet::getListByPackage($this);
     $items['page_themes'] = PageTheme::getListByPackage($this);
     $items['permissions'] = PermissionKey::getListByPackage($this);
     $items['single_pages'] = SinglePage::getListByPackage($this);
     $items['attribute_types'] = AttributeType::getListByPackage($this);
     $items['captcha_libraries'] = SystemCaptchaLibrary::getListByPackage($this);
     $items['content_editor_snippets'] = SystemContentEditorSnippet::getListByPackage($this);
     $items['conversation_editors'] = ConversationEditor::getListByPackage($this);
     $items['conversation_rating_types'] = ConversationRatingType::getListByPackage($this);
     $items['page_type_publish_target_types'] = PageTypePublishTargetType::getListByPackage($this);
     $items['page_type_composer_control_types'] = PageTypeComposerControlType::getListByPackage($this);
     $items['antispam_libraries'] = SystemAntispamLibrary::getListByPackage($this);
     $items['community_point_actions'] = UserPointAction::getListByPackage($this);
     $items['jobs'] = Job::getListByPackage($this);
     $items['workflow_types'] = WorkflowType::getListByPackage($this);
     ksort($items);
     return $items;
 }
 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;
 }
Esempio n. 7
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;
             $fo = \File::getByID($fID);
             if (is_object($fo)) {
                 if ($picture->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();
                 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);
                                 }
                             }
                         } else {
                             $tag->{$attr}($val);
                         }
                     }
                 }
                 $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;
 }
 public function getPackageItems(Package $package)
 {
     return Snippet::getListByPackage($package);
 }
 public function skipItem()
 {
     $snippet = Snippet::getByHandle($this->object->getHandle());
     return is_object($snippet);
 }