/** * 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(); }
/** * Returns the composite. * * @throws UnexpectedValueException If * SocialSharing_Project_Builder::getButtons() * returned invalid value. * @return \SocialSharing_HtmlBuilder_Element */ public function getComposite() { $composite = $this->builder->getComposite(); if (!$this->builder->getProject()->isShowAtSidebar()) { return $composite; } $composite->addElement($this->getToggleButton()); return $composite; }
/** * Returns the composite. * @throws UnexpectedValueException If * SocialSharing_Project_Builder::getButtons() * returned invalid value. * @return \SocialSharing_HtmlBuilder_Element */ public function getComposite() { if (count($this->networks) === 0) { return $this->builder->getComposite(); } $composite = $this->builder->getComposite(); $container = $this->getPopupContainer(); foreach ($this->networks as $data) { $container->addElement($this->getButton(new SocialSharing_Projects_Builder_Network((array) $data))); } $composite->addElement($this->getPopupButton()); $composite->addElement($container); return $composite; }