function display($tpl = null) { $this->mainframe = JFactory::getApplication(); $this->option = JRequest::getCmd('option'); $filter_order = $this->mainframe->getUserStateFromRequest($this->option . '.polls.filter_order', 'filter_order', 'm.title', 'string'); $filter_order_Dir = $this->mainframe->getUserStateFromRequest($this->option . '.polls.filter_order_Dir', 'filter_order_Dir', '', 'word'); $search = $this->mainframe->getUserStateFromRequest($this->option . '.polls.search', 'search', '', 'string'); // table ordering $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; // search filter $lists['search'] = $search; JHTML::_('behavior.tooltip'); if (MijopollsHelper::is15()) { $params = $this->mainframe->getParams(); } else { $menu = JSite::getMenu()->getActive(); $menu_params = new JRegistry($menu->params); $params = clone $this->mainframe->getParams(); $params->merge($menu_params); } $this->lists = $lists; $this->params = $params; $this->items = $this->get('Data'); $this->pagination = $this->get('Pagination'); if (MijopollsHelper::is30()) { $tpl = '30'; } parent::display($tpl); }
function getItemid($poll_id) { $component = JComponentHelper::getComponent('com_mijopolls'); $menus = JApplication::getMenu('site', array()); if (MijopollsHelper::is15()) { $items = $menus->getItems('componentid', $component->id); } else { $items = $menus->getItems('component_id', $component->id); } $match = false; $item_id = ''; if (isset($items)) { foreach ($items as $item) { if (@$item->query['view'] == 'poll' && @$item->query['id'] == $poll_id) { $itemid = $item->id; $match = true; break; } } } if ($match) { $item_id = '&Itemid=' . $itemid; } return $item_id; }
function display($tpl = null) { $document = JFactory::getDocument(); $document->addStyleSheet('components/com_mijopolls/assets/css/mijopolls.css'); $cid = JRequest::getVar('cid', array(0), '', 'array'); $edit = JRequest::getVar('edit', true); $text = $edit ? JText::_('Edit') : JText::_('New'); JToolBarHelper::title(JText::_('COM_MIJOPOLLS_POLL') . ': <small><small>[ ' . $text . ' ]</small></small>', 'mijopolls'); JToolBarHelper::Preview('index.php?option=com_mijopolls&cid[]=' . $cid[0]); JToolBarHelper::save(); JToolBarHelper::apply(); JToolBarHelper::cancel(); $this->mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $row = $this->get('ItemData'); // fail if checked out not by 'me' if ($row->isCheckedOut($user->get('id'))) { $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('COM_MIJOPOLLS_THE_POLL'), $row->title); $this->setRedirect('index.php?option=com_mijopolls', $msg); } if ($row->id == 0) { $row->published = 1; } $options = array(); $ordering = array(); if ($edit) { $options = $row->getOptions($row->id); } else { $row->lag = 24 * 60; } //default colors for slices $colors = array("ff0000", "ffff99", "00ccff", "66ff99", "ffcc00", "d7ebff", "ccffcc", "cccccc", "ffff00", "006699", "660000", "ffddee"); $task = JRequest::getCmd('task'); if (MijopollsHelper::is15()) { $tpl .= '15'; $params = new JParameter($row->params, JPATH_COMPONENT . '/views/poll/poll.xml'); $this->params = $params; } else { if (MijopollsHelper::is30()) { $tpl = '30'; $this->params = $this->get('Form'); } else { if ($task != 'preview') { $tpl = '25'; $this->params = $this->get('Form'); } } } $this->row = $row; $this->options = $options; $this->color = $colors; $this->edit = $edit; parent::display($tpl); }
function display($tpl = null) { // Get data from the model require_once JPATH_COMPONENT . '/models/ajaxvote.php'; $model = new MijopollsModelAjaxvote(); $vote = $model->getVoted(); $data = $model->getData(); $total = $model->getTotal(); $poll_id = JRequest::getInt('id', 0, 'post'); if (MijopollsHelper::is15()) { // create root node $xml = new JSimpleXMLElement('poll', array('id' => $poll_id)); //get total votes $sum = 0; foreach ($data as $row) { $sum += $row->votes; } $number_voters = 0; $options = $xml->addChild('options'); for ($i = 0; $i < $total; $i++) { $option = $options->addChild('option', array('id' => $data[$i]->id, 'percentage' => self::_toPercent($data[$i]->votes, $sum), 'votes' => $data[$i]->votes, 'color' => $data[$i]->color)); $text = $option->addChild('text'); $text->setData($data[$i]->text); $number_voters += $data[$i]->votes; } $voters = $xml->addChild('voters'); $voters->setData($number_voters); $this->assign('xml', $xml->toString()); } else { // create root node $xml = new JXMLElement('<poll></poll>'); $xml->addAttribute('id', $poll_id); //get total votes $sum = 0; foreach ($data as $row) { $sum += $row->votes; } $number_voters = 0; $options = $xml->addChild('options'); for ($i = 0; $i < $total; $i++) { $option = $options->addChild('option'); $option->addAttribute('id', $data[$i]->id); $option->addAttribute('percentage', self::_toPercent($data[$i]->votes, $sum)); $option->addAttribute('color', $data[$i]->color); $option->addChild('text', $data[$i]->text); $number_voters += $data[$i]->votes; } $xml->addChild('voters', $number_voters); $this->assign('xml', $xml->asFormattedXML()); } $this->setLayout('raw'); parent::display($tpl); }
function bind($array, $ignore = '') { if (MijopollsHelper::is15()) { if (key_exists('params', $array) && is_array($array['params'])) { $registry = new JRegistry(); $registry->loadArray($array['params']); $array['params'] = $registry->toString(); } } else { if (isset($array['params']) && is_array($array['params'])) { $registry = new JRegistry(); $registry->loadArray($array['params']); $array['params'] = (string) $registry; } } return parent::bind($array, $ignore); }
function getVoted() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $mainframe = JFactory::getApplication(); $poll_id = JRequest::getInt('id', 0); $option_id = JRequest::getInt('voteid', 0); $poll = JTable::getInstance('Poll', 'Table'); if (!$poll->load($poll_id) || $poll->published != 1) { $mainframe->redirect('index.php', JText::_('ALERTNOTAUTH')); //JError::raiseWarning(404, JText::_('ALERTNOTAUTH')); return; } require_once JPATH_COMPONENT . '/models/poll.php'; $model = new MijopollsModelPoll(); if (MijopollsHelper::is15()) { $params = new JParameter($poll->params); $cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $poll_id); } else { $params = new JRegistry($poll->params); $cookieName = JApplication::getHash($mainframe->getName() . 'poll' . $poll_id); } $voted_cookie = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT'); $voted_ip = $model->ipVoted($poll, $poll_id); if ($params->get('ip_check') and ($voted_cookie or $voted_ip or !$option_id)) { if ($voted_cookie || $voted_ip) { $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); $tom = "error"; } if (!$option_id) { $msg = JText::_('COM_MIJOPOLLS_NO_SELECTED'); $tom = "error"; } $this->_voted = 0; } else { if ($model->vote($poll_id, $option_id)) { $this->_voted = 1; //Set cookie showing that user has voted setcookie($cookieName, '1', time() + 60 * $poll->lag); } else { $this->_voted = 0; } } return $this->_voted = 1; }
public function ipVoted($poll, $poll_id) { if (MijopollsHelper::is15()) { $params = new JParameter($poll->params); } else { $params = new JRegistry($poll->params); } if ($params->get('ip_check') == 0) { return false; } $db = JFactory::getDBO(); $poll_id = (int) $poll_id; $ip = ip2long($_SERVER['REMOTE_ADDR']); $db->setQuery("SELECT poll_id FROM #__mijopolls_votes WHERE poll_id = '{$poll_id}' AND ip = '{$ip}'"); $res = $db->loadResult(); if (!empty($res)) { return true; } else { return false; } }
function __construct() { parent::__construct(); $this->mainframe = JFactory::getApplication(); $this->option = JRequest::getWord('option'); // Get the pagination request variables $config = JFactory::getConfig(); if (MijopollsHelper::is15()) { $config_list_limit = $config->getValue('config.list_limit'); } else { $config_list_limit = $config->get('config.list_limit'); } // Get the pagination request variables $this->setState('limit', $this->mainframe->getUserStateFromRequest('limit', 'limit', $config_list_limit, 'int')); $this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int')); // In case limit has been changed, adjust limitstart accordingly $this->setState('limitstart', $this->getState('limit') != 0 ? floor($this->getState('limitstart') / $this->getState('limit')) * $this->getState('limit') : 0); // Get the filter request variables $this->setState('filter_order', JRequest::getCmd('filter_order', 'ordering')); $this->setState('filter_order_dir', JRequest::getCmd('filter_order_Dir', 'ASC')); }
function MijopollsBuildRoute(&$query) { static $items; $segments = array(); $itemid = null; // Break up the poll id into numeric and alias values. if (isset($query['id']) && strpos($query['id'], ':')) { list($query['id'], $query['alias']) = explode(':', $query['id'], 2); } // Get the menu items for this component. if (!$items) { $component = JComponentHelper::getComponent('com_mijopolls'); $menu = JSite::getMenu(); if (MijopollsHelper::is15()) { $items = $menu->getItems('componentid', $component->id); } else { $items = $menu->getItems('component_id', $component->id); } } // Search for an appropriate menu item. // First we will search for menu item linking to this poll, // if we can't find we will look for a menu item linking to the polls view. if (is_array($items)) { // If only the option and itemid are specified in the query, return that item. if (!isset($query['view']) && !isset($query['id']) && isset($query['Itemid'])) { $itemid = (int) $query['Itemid']; } // Search for a menu that links to the same view and id if (!$itemid) { foreach ($items as $item) { // Check if this menu item links to this view. // menu-view must be equal to the query-view // also menu-id must be equal to the query-id if (isset($item->query['view']) && isset($query['view']) && $item->query['view'] == $query['view'] && isset($item->query['id']) && $item->query['id'] == $query['id']) { $itemid = $item->id; } } } // If no specific link has been found, search for a general one. // Search for a menu linking to polls view if (!$itemid) { foreach ($items as $item) { if (isset($query['view']) && $query['view'] == 'poll' && isset($item->query['view']) && $item->query['view'] == 'polls') { // Check for an undealt with poll id. if (isset($query['id'])) { // This menu item links to the polls view but we need to append the poll id to it. $itemid = $item->id; $segments[] = isset($query['alias']) ? $query['id'] . ':' . $query['alias'] : $query['id']; break; if (MijopollsHelper::is30()) { $url = str_replace('index.php?', '', $item->link); parse_str($url, $vars); JRequest::set($vars, 'get'); } } } } } } // Check if the router found an appropriate itemid. if (!$itemid) { //if item id was not found that means that there is no link to either polls view or poll view // Check if a id was specified. if (isset($query['id'])) { if (isset($query['alias'])) { $query['id'] .= ':' . $query['alias']; } // Push the id onto the stack. $segments[] = 'poll'; $segments[] = $query['id']; unset($query['id']); unset($query['alias']); } unset($query['view']); } else { $query['Itemid'] = $itemid; // Remove the unnecessary URL segments. unset($query['view']); unset($query['id']); unset($query['alias']); } return $segments; }
function display($tpl = null) { $this->mainframe = JFactory::getApplication(); $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $date =& JFactory::getDate(); $document =& JFactory::getDocument(); $pathway =& $this->mainframe->getPathway(); $poll_id = JRequest::getInt('id', 0); $poll =& JTable::getInstance('Poll', 'Table'); $poll->load($poll_id); // if id value is passed and poll not published then exit if ($poll->id > 0 && $poll->published != 1) { JError::raiseError(403, JText::_('Access Forbidden')); return; } if (MijopollsHelper::is15()) { // Adds parameter handling $params =& $this->mainframe->getParams(); $pollParams = new JParameter($poll->params); $params->merge($pollParams, $params); //Set page title information $menus =& JSite::getMenu(); $menu = $menus->getActive(); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new JParameter($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', $poll->title); } } else { $params->set('page_title', $poll->title); } } else { // Adds parameter handling $temp = new JRegistry($poll->params); $params = clone $this->mainframe->getParams(); $params->merge($temp); //Set page title information $menu = JSite::getMenu()->getActive(); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new JRegistry($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', $poll->title); } else { $params->set('page_title', $menu_params->get('page_title')); } } else { $params->set('page_title', $poll->title); } } $document->setTitle($params->get('page_title')); //Set pathway information $pathway->addItem($poll->title, ''); $params->def('show_page_title', 1); $params->def('page_title', $poll->title); // Check if there is a poll corresponding to id and if poll is published if ($poll->id > 0) { if (empty($poll->title)) { $poll->id = 0; $poll->title = JText::_('COM_MIJOPOLLS_SELECT_POLL'); } //get the array of options $options =& $this->get('Options'); } else { $options = array(); } // list of polls for dropdown selection $pList = $this->get('Polls'); foreach ($pList as $k => $p) { $pList[$k]->url = JRoute::_('index.php?option=com_mijopolls&view=poll&id=' . $p->slug); } array_unshift($pList, JHTML::_('select.option', '', JText::_('COM_MIJOPOLLS_SELECT_POLL'), 'url', 'title')); // dropdown output $lists = array(); $lists['polls'] = JHTML::_('select.genericlist', $pList, 'id', 'class="inputbox" size="1" style="width:400px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"', 'url', 'title', JRoute::_('index.php?option=com_mijopolls&view=poll&id=' . $poll->id . ':' . $poll->alias)); //get the number of voters $voters = isset($options[0]) ? $options[0]->voters : 0; $num_of_options = count($options); for ($i = 0; $i < $num_of_options; $i++) { $vote =& $options[$i]; //assign pie color to colors array $colors[$i] = $vote->color; //$links[$i]=$vote->link; if ($voters > 0) { $vote->percent = round(100 * $vote->hits / $voters, 1); } else { //if nobody has voted yet if ($params->get('show_what') == 1) { $vote->percent = round(100 / $num_of_options, 1); } else { $vote->percent = 0; } } } // show_what==1 because 1=show pie, 0=joomla default, 3 may be something else later //Pie chart // pass in two arrays, one of data, the other data labels $title_lenght = $params->get('title_lenght'); foreach ($options as $vote_array) { //if show hits is true if ($params->get('show_hits')) { $hits = " (" . $vote_array->hits . ")"; } else { $hits = ''; } //if show options with zero votes is true if ($params->get('show_zero_votes')) { $text = JString::substr(html_entity_decode($vote_array->text, ENT_QUOTES, "utf-8"), 0, $title_lenght) . $hits; //$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text); $values[] = ' "value":' . $vote_array->percent . ', "label":"' . addslashes($text) . '", "text":"' . addslashes($text) . '" '; } else { //show only options that have hits if ($vote_array->percent) { $text = JString::substr(html_entity_decode($vote_array->text, ENT_QUOTES, "utf-8"), 0, $title_lenght) . $hits; //$values[] = array("value" => $vote_array->percent, "label" => $text, "text" => $text); $values[] = ' "value":' . $vote_array->percent . ', "label":"' . addslashes($text) . '", "text":"' . addslashes($text) . '" '; } } } // prepare the javascript for the pie //colors and values array to json //TODO use json_encode some day $json_colors = '["' . implode('", "', $colors) . '"]'; $json_values = '[{' . implode('}, {', $values) . '}]'; $js = ' function ofc_ready() {} function open_flash_chart_data() { return JSON.stringify(data); } var data = { "title":{ "text" : "", "style" : "font-size: 14px; font-family: Verdana; text-align: center;" }, "bg_colour" : "#' . $params->get("bg_color") . '", "elements" : [{ "type" : "pie", "tip" : "#label# \\n#val#%", "colours" : ' . $json_colors . ', "alpha" : ' . $params->get("opacity") . ', "start-angle" : ' . $params->get("start_angle") . ', "radius" : ' . $params->get("radius") . ', "no-labels" : ' . $params->get("no_labels") . ', "values" : ' . $json_values . ', "gradient-fill" : ' . $params->get("gradient") . ', "font-size" : ' . $params->get("font_size") . ', "label-colour" : "#' . $params->get("font_color") . '", "animate":[{ "distance" : ' . $params->get("bounce_dinstance") . ', "type" : "' . $params->get("animation_type") . '" }] }] }; '; //Check if the user has voted if (MijopollsHelper::is15()) { $cookieName = JUtility::getHash($this->mainframe->getName() . 'poll' . $poll_id); } else { $cookieName = JApplication::getHash($this->mainframe->getName() . 'poll' . $poll_id); } $cookieVoted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT'); $query = "SELECT date FROM #__mijopolls_votes WHERE poll_id=" . (int) $poll_id . " AND user_id=" . (int) $user->id; $db->setQuery($query); $userVoted = $db->loadResult() ? 1 : 0; $ip = ip2long($_SERVER['REMOTE_ADDR']); $query = "SELECT ip FROM #__mijopolls_votes WHERE poll_id=" . (int) $poll_id . " AND ip = '" . $ip . "'"; $db->setQuery($query); $ipVoted = $db->loadResult() ? 1 : 0; //$date->setOffset($this->mainframe->getCfg('offset')); if (MijopollsHelper::is15()) { $now = $date->toFormat(); } else { $now = $date->toSql(); } //Algorithm for shoiwing or not the poll in the component if ($params->get('allow_voting')) { if ($now > $poll->publish_up && $now < $poll->publish_down) { if ($params->get('only_registered')) { if (!$user->guest) { if ($params->get('one_vote_per_user')) { if ($userVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { $allowToVote = 1; } } else { if ($cookieVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { $allowToVote = 1; } } } else { $allowToVote = 0; $return = JRequest::getURI(); $return = base64_encode($return); $user_option = MijopollsHelper::is15() ? 'com_user' : 'com_users'; $link = 'index.php?option=' . $user_option . '&view=login&return=' . $return; $msg = JText::sprintf('COM_MIJOPOLLS_REGISTER_TO_VOTE', '<a href="' . $link . '">', '</a>'); } } else { if ($cookieVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { if ($params->get('ip_check')) { if ($ipVoted) { $allowToVote = 0; $msg = JText::_('COM_MIJOPOLLS_ALREADY_VOTED'); } else { $allowToVote = 1; } } else { $allowToVote = 1; } } } } else { $allowToVote = 0; } if ($now < $poll->publish_up) { $msg = JText::_('COM_MIJOPOLLS_VOTE_NOT_STARTED'); } if ($now > $poll->publish_down) { $msg = JText::_('COM_MIJOPOLLS_VOTE_ENDED'); } } else { $allowToVote = 0; } $this->lists = $lists; $this->params = $params; $this->poll = $poll; $this->options = $options; $this->allowToVote = $allowToVote; $this->msg = $msg; $this->js = $js; if (MijopollsHelper::is30()) { $tpl = '30'; } parent::display($tpl); }
//if user has not voted } else { //display the poll $display_poll = 1; $display_submit = 1; $msg = ""; } } //if the user has not logged in } else { //display message please log in $display_poll = 1; $display_submit = 0; $return = JRequest::getURI(); $return = base64_encode($return); $user_option = MijopollsHelper::is15() ? 'com_user' : 'com_users'; $link = 'index.php?option=' . $user_option . '&view=login&return=' . $return; $msg = JText::sprintf('MOD_MIJOPOLLS_PLEASE_REGISTER_TO_VOTE', '<a href="' . $link . '">', '</a>'); } // if anybody can vote } else { //if user has voted, according to the cookie check if ($voted) { //display the poll with disabled options or the results $display_poll = 0; $display_submit = 0; $msg = JText::_("MOD_MIJOPOLLS_ALREADY_VOTED"); $details = JText::sprintf("MOD_MIJOPOLLS_ONLY_ONE_VOTE_PER_HOUR", $poll->lag / 60); //if user has not voted according to the cookie } else { //hm check the ip please but only if allowed to do that
</td><?php } ?> </tr> </thead> <tbody> <?php $k = 0; $n = count($this->items); for ($i = 0; $i < $n; $i++) { $row =& $this->items[$i]; //find the Itemid that correspondents to the link if any. $component =& JComponentHelper::getComponent('com_mijopolls'); $menus =& JApplication::getMenu('site', array()); if (MijopollsHelper::is15()) { $menu_items = $menus->getItems('componentid', $component->id); } else { $menu_items = $menus->getItems('component_id', $component->id); } $itemid = null; if (isset($menu_items)) { foreach ($menu_items as $item) { if (@$item->query['view'] == 'poll' && @$item->query['id'] == $row->id) { $itemid = '&Itemid=' . $item->id; break; } } } $link = JRoute::_('index.php?option=com_mijopolls&view=poll&id=' . $row->slug . $itemid); ?>