Exemple #1
0
 /**
  * Плагины, использованные в постах
  */
 public function getSnapshot()
 {
     $SNAPSOT = PSCache::POPUPS()->getFromCache('POPUP_PAGES_SNAPSOT', PsUtil::getClassConsts(__CLASS__, 'CACHABLE_'));
     if (!is_array($SNAPSOT)) {
         $this->LOGGER->info('Building plugins SNAPSHOT...');
         //Сначала соберём все плагины, использованные в постах
         $USED = array();
         /* @var $pp PostsProcessor */
         foreach (Handlers::getInstance()->getPostsProcessors() as $pp) {
             $pp->preloadAllPostsContent();
             /* @var $post Post */
             foreach ($pp->getPosts() as $post) {
                 $plugins = $pp->getPostContentProvider($post->getId())->getPostParams()->getUsedPlugins();
                 if (empty($plugins)) {
                     //В посте не используются плагины
                     continue;
                 }
                 $this->LOGGER->info('Plugins [{}] used in post [{}].', implode(',', $plugins), IdHelper::ident($post));
                 $USED = array_merge($USED, $plugins);
             }
         }
         $USED = array_unique($USED);
         $this->LOGGER->info('Full list of used plugins: [{}].', implode(',', $USED));
         //Соберём все видимые попап-страницы и плагины
         $ENTITYS = array();
         foreach (array($this->getVisibleClassInsts(), PluginsManager::inst()->getVisibleClassInsts()) as $popups) {
             foreach ($popups as $ident => $popup) {
                 $visType = $popup->getPopupVisibility();
                 $take = PopupVis::isAllwaysVisible($visType) || $visType == PopupVis::BYPOST && in_array($ident, $USED);
                 if ($take) {
                     $ENTITYS[] = $popup;
                 }
             }
         }
         //Отсортируем собранные сущности по названию
         usort($ENTITYS, function ($e1, $e2) {
             $str1 = $e1 instanceof BasePopupPage ? $e1->getTitle() : $e1->getName();
             $str2 = $e2 instanceof BasePopupPage ? $e2->getTitle() : $e2->getName();
             return strcasecmp($str1, $str2);
         });
         $VISIBLE = array();
         $DEFAULT = array();
         foreach ($ENTITYS as $entity) {
             $visType = $entity->getPopupVisibility();
             if ($entity instanceof BasePopupPage) {
                 $type = self::TYPE_PAGE;
                 $ident = $entity->getIdent();
             }
             if ($entity instanceof BasePlugin) {
                 $type = self::TYPE_PLUGIN;
                 $ident = $entity->getIdent();
             }
             $VISIBLE[$type . '_' . $ident] = array('type' => $type, 'ident' => $ident);
             if ($visType == PopupVis::TRUE_DEFAULT) {
                 $DEFAULT[$type . '_' . $ident] = array('type' => $type, 'ident' => $ident);
             }
         }
         $SNAPSOT = array(self::CACHABLE_VISIBLE => $VISIBLE, self::CACHABLE_DEFAULT => $DEFAULT);
         $SNAPSOT = PSCache::POPUPS()->saveToCache($SNAPSOT, 'POPUP_PAGES_SNAPSOT');
     }
     return $SNAPSOT;
 }