示例#1
0
 /**
  * Builds the composite and returns button markup.
  * @return string
  */
 public function build()
 {
     $environment = $this->builder->getEnvironment();
     $dispatcher = $environment->getDispatcher();
     $this->project = $dispatcher->apply('before_build', array($this->project));
     if ((!array_key_exists('action', $_GET) || $_GET['action'] !== 'getPreviewHtml') && $this->project->isShowOnPosts() && !$this->project->isShowAt('popup')) {
         $current = get_post();
         if ($current === null) {
             return '';
         }
         if (!$this->project->isShortCodeShow() && $current->post_type === 'post' && (!$this->project->isShowOnAllPosts() && !$this->project->isShowOnSpecificPost($current->ID)) && !$this->project->showOnSpecificPostType($current->post_type) && !$this->project->isShowOnAllPostTypes()) {
             return '';
         }
         if ($current->post_type === 'page' && (!$this->project->isShowOnAllPages() && !$this->project->isShowOnSpecificPost($current->ID)) && !$this->project->showOnSpecificPostType($current->post_type) && !$this->project->isShowOnAllPostTypes()) {
             return '';
         }
         if (!$this->project->isShowOnAllPosts() && !$this->project->isShowOnAllPages() && !in_array($current->post_type, array('post', 'page'), false) && !$this->project->showOnSpecificPostType($current->post_type) && !$this->project->isShowOnAllPostTypes()) {
             return '';
         }
     }
     if (!$this->project->isShortCodeShow() && !$this->project->isPopupShow() && $this->project->isShowOnHomepage() && !$this->builder->isHomepage()) {
         return '';
     }
     try {
         $composite = $this->builder->getComposite();
     } catch (Exception $e) {
         if (defined('WP_DEBUG') && WP_DEBUG && (function_exists('is_super_admin') && is_super_admin())) {
             return sprintf($this->environment->translate('Failed to build the project: %s.'), $e->getMessage());
         }
         return '';
     }
     $this->project = $dispatcher->apply('after_build', array($this->project));
     $dispatcher->dispatch('before_html_build');
     return $composite->build();
 }
示例#2
0
 public function build()
 {
     $this->project = $this->dispatcher->apply('before_build', array($this->project));
     $classes = $this->getBaseClasses();
     $buttons = $this->buildButtons();
     $sidebarClasses = array('supsystic-social-sharing-right', 'supsystic-social-sharing-left', 'supsystic-social-sharing-top', 'supsystic-social-sharing-bottom');
     if ((!array_key_exists('action', $_GET) || $_GET['action'] !== 'getPreviewHtml') && $this->project->isShowOnPosts() && !$this->project->isShowAt('popup')) {
         $current = get_post();
         if ($current === null) {
             return '';
         }
         if ($current->post_type === 'post' && (!$this->project->isShowOnAllPosts() && !$this->project->isShowOnSpecificPost($current->ID))) {
             return '';
         }
         if ($current->post_type === 'page' && (!$this->project->isShowOnAllPages() && !$this->project->isShowOnSpecificPost($current->ID))) {
             return '';
         }
         /*For other post types that can't be selected in our list, and if buttons should not be visible on all posts/pages - buttons should be hidden, right?*/
         if (!$this->project->isShowOnAllPosts() && !$this->project->isShowOnAllPages() && !in_array($current->post_type, array('post', 'page'))) {
             return '';
         }
     }
     $container = $this->getBuilder()->createElement('div', array($this->getBuilder()->createAttribute('class', $classes), $this->getBuilder()->createAttribute('data-animation', $this->getProject()->get('buttons_animation', 'no-animation')), $this->getBuilder()->createAttribute('data-icons-animation', $this->getProject()->get('icons_animation', 'no-animation')), $this->getBuilder()->createAttribute('data-overlay', $this->getProject()->get('overlay_with_shadow', false)), $this->getBuilder()->createAttribute('data-change-size', $this->getProject()->get('change_size', false)), $this->getBuilder()->createAttribute('data-buttons-size', $this->getProject()->get('buttons_size', 'normal')), $this->getBuilder()->createAttribute('style', sprintf('font-size: %sem; display: none;', $this->getProject()->get('buttons_size', 1)))));
     if (count($buttons) > 0) {
         foreach ($buttons as $button) {
             $container->addElement($button);
         }
     }
     $settings = $this->project->getSettings();
     $listClasses = array();
     $buttons = $this->buildButtons('all', $listClasses);
     if (isset($settings['show_more']) && $settings['show_more'] == 'on') {
         $this->showMore($container, $buttons, $listClasses);
     }
     foreach ($classes as $class) {
         if (in_array($class, $sidebarClasses) && isset($settings['sidebar_navigation']) && $settings['sidebar_navigation'] == 'on') {
             $navButton = $this->getBuilder()->createElement('div', array($this->getBuilder()->createAttribute('class', 'nav-button hide ' . $settings['where_to_show_extra'])));
             $container->addElement($navButton);
         }
     }
     $this->dispatcher->dispatch('before_html_build');
     return $container->build();
 }