public function onContentPrepare($context, &$article, &$params, $page = 0)
 {
     if (strpos($article->text, "{custompolls_vote}") === false) {
         return false;
     }
     $path = $this->livepath . '/plugins/content/' . $this->_name . '/assets';
     $document = JFactory::getDocument();
     $document->addScript($path . '/js/libs/jquery/jquery-1.8.2.min.js');
     $document->addScript($path . '/js/libs/underscore-min.js');
     $document->addScript($path . '/js/libs/moment.min.js');
     $document->addScript($path . '/js/script.js');
     $document->addStyleSheet($path . '/css/styles.css');
     $mPolls = new CustompollsModelPolls();
     $user =& JFactory::getUser();
     if (!$user->guest) {
         $name = $user->name;
         $region = $mPolls->getUserRegion($user->id);
     } else {
         $name = "";
         $region = "";
     }
     $num = $mPolls->getCountVotes($article->id);
     list($vote, $status) = $mPolls->getVote($article->id);
     $result = file_get_contents(dirname(__FILE__) . "/assets/templates/polls.html");
     $result = str_replace("{articleId}", $article->id, $result);
     $result = str_replace("{countVotes}", $num, $result);
     $result = str_replace("{region}", htmlspecialchars($region), $result);
     $result = str_replace("{name}", htmlspecialchars($name), $result);
     $result = str_replace("{vote}", $vote ? 1 : 0, $result);
     $article->text = str_replace("{custompolls_vote}", $result, $article->text);
 }
예제 #2
0
 public function vote()
 {
     $post = JRequest::get("post");
     $mPolls = new CustompollsModelPolls();
     // validate required fields
     if (trim($post["name"]) == "" || trim($post["region"]) == "") {
         print "requiredfields";
         jexit();
     }
     if (isset($post["article_id"])) {
         list($vote, $status) = $mPolls->getVote($post["article_id"]);
         if (!$vote) {
             if ($mPolls->store($post)) {
                 $mPolls->setVoteState($post["article_id"]);
             }
             $status = $mPolls->getCountVotes($post["article_id"]);
         }
         print $status;
     }
     jexit();
 }