Esempio n. 1
0
 /**
  * Method to follow a project.
  *
  * @throws Exception
  * @return  void
  */
 public function follow()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_USER'))->failure();
         echo $response;
         $app->close();
     }
     // Get project ID.
     $projectId = $this->input->post->getInt('pid', 0);
     if (!$projectId) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'))->failure();
         echo $response;
         $app->close();
     }
     $state = $this->input->post->getInt('state', 0);
     $state = !$state ? Prism\Constants::UNFOLLOWED : Prism\Constants::FOLLOWED;
     try {
         $user = new Crowdfunding\User\User(JFactory::getDbo());
         $user->setId($userId);
         if (!$state) {
             $user->unfollow($projectId);
         } else {
             $user->follow($projectId);
         }
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'));
     }
     $responseData = array("state" => $state);
     $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setData($responseData)->success();
     echo $response;
     $app->close();
 }
 /**
  * @param object $item
  * @param Joomla\Registry\Registry $params
  * @param string $url
  *
  * @return string
  */
 private function getEmbeded($item, $params, $url)
 {
     $html = "";
     if (!$params->get("display_embed_link", 1) and !$params->get("display_embed_button", 1) and !$params->get("display_embed_email", 1)) {
         return $html;
     }
     $html = '<div class="clearfix"></div>';
     $html .= '<div class="crowdf-embeded">';
     if ($params->get("display_embed_link", 1)) {
         $html .= '<input type="text" name="share_url" value="' . html_entity_decode($url, ENT_COMPAT, 'UTF-8') . '" class="crowdf-embeded-input" />';
     }
     if ($params->get("display_embed_button", 1)) {
         $link = JRoute::_(CrowdfundingHelperRoute::getEmbedRoute($item->slug, $item->catslug), false);
         $html .= '<a href="' . $link . '" class="btn btn-default" role="button"><span class="glyphicon glyphicon-th-large"></span> ' . JText::_("PLG_CONTENT_CROWDFUNDINGSOCIALSHARE_EMBED") . '</a>';
     }
     if ($params->get("display_embed_email", 1)) {
         $link = JRoute::_(CrowdfundingHelperRoute::getEmbedRoute($item->slug, $item->catslug, "email"), false);
         $html .= '<a class="btn btn-default" href="' . $link . '" role="button"><span class="glyphicon glyphicon-envelope"></span> ' . JText::_("PLG_CONTENT_CROWDFUNDINGSOCIALSHARE_EMAIL") . '</a>';
     }
     if ($params->get("display_follow", 0)) {
         $userId = JFactory::getUser()->get("id");
         $state = Prism\Constants::UNFOLLOWED;
         $projectId = (int) $item->id;
         $text = JText::_("PLG_CONTENT_CROWDFUNDINGSOCIALSHARE_FOLLOW");
         $class = " btn-default";
         // Load scripts.
         JHtml::_('jquery.framework');
         $doc = JFactory::getDocument();
         $doc->addScript(JUri::root() . "plugins/content/crowdfundingsocialshare/script.js");
         if ($userId) {
             $user = new Crowdfunding\User\User(JFactory::getDbo());
             $user->setId($userId);
             $followed = $user->getFollowed();
             if (in_array($projectId, $followed)) {
                 $state = Prism\Constants::FOLLOWED;
                 $text = JText::_("PLG_CONTENT_CROWDFUNDINGSOCIALSHARE_FOLLOWING");
                 $class = " btn-primary";
             }
             JText::script('PLG_CONTENT_CROWDFUNDINGSOCIALSHARE_FOLLOW');
             JText::script('PLG_CONTENT_CROWDFUNDINGSOCIALSHARE_UNFOLLOW');
             JText::script('PLG_CONTENT_CROWDFUNDINGSOCIALSHARE_FOLLOWING');
         }
         $html .= '<a href="javascript: void(0);" class="btn ' . $class . '" id="js-plgsocialshare-btn-follow" role="button" data-uid="' . (int) $userId . '" data-state="' . (int) $state . '" data-pid="' . $projectId . '">
         <span class="glyphicon glyphicon-heart"></span>
         <span id="js-plgsocialshare-btn-text">' . $text . '</span></a>';
     }
     $html .= '</div>';
     return $html;
 }