protected function getInput() { require_once JPATH_SITE . '/components/com_javoice/models/items.php'; require_once JPATH_SITE . '/components/com_javoice/models/forums.php'; $jaVoiceModelItems = new JAVoiceModelItems(); $model_forums = new JAVoiceModelforums(); $class = (string) $this->element['class']; $multiple = $this->element['multiple'] ? 'multiple="multiple"' : ''; $types = $jaVoiceModelItems->getVoiceTypes(" AND vt.published = 1", "vt.ordering"); $forums = array(); $forums[0] = new stdClass(); $forums[0]->id = '1'; $forums[0]->title = JText::_("Select All"); foreach ($types as $type) { array_push($forums, JHTML::_('select.optgroup', $type->title, 'id', 'title')); $where_more = ' and f.published=1 and ft.voice_types_id=' . $type->id; $join = 'INNER JOIN #__jav_forums_has_voice_types as ft ON f.id=ft.forums_id'; $results = $model_forums->getItems($where_more, 100, 0, 'f.ordering', '', $join); //array_push($forums, $optgroup); foreach ($results as $result) { $result->id = $type->id . '_' . $result->id; array_push($forums, $result); } array_push($forums, JHTML::_('select.optgroup', $type->title, 'id', 'title')); } //jexit(); $out = JHTML::_('select.genericlist', $forums, $this->name, 'class="inputbox ' . $class . '" ' . $multiple, 'id', 'title', $this->value); return $out; }
function parseItems_params($items, $type = null) { global $javconfig; //print_r($items);exit; $db = JFactory::getDBO(); $helper = new JAVoiceHelpers(); $Itemid = JRequest::getInt('Itemid'); if ($type) { $types[0] = $type; } else { $types = $this->getVoiceTypes(); } $array_votes = array(); if ($types) { foreach ($types as $type) { $params_type = class_exists('JRegistry') ? new JRegistry($type->vote_option) : new JParameter($type->vote_option); $array_votes[$type->id]['value'] = $params_type->get('votes_value') ? str_replace("###", ',', $params_type->get('votes_value')) : ''; $array_votes[$type->id]['text'] = $params_type->get('votes_text') ? $db->Quote(str_replace("###", ',', $params_type->get('votes_text'))) : ''; $array_votes[$type->id]['description'] = $params_type->get('votes_description') ? $db->Quote(str_replace("###", ',', htmlspecialchars($params_type->get('votes_description')))) : ''; } } $currentUser = JFactory::getUser(); require_once JPATH_SITE . DS . 'components' . DS . 'com_javoice' . DS . 'models' . DS . 'forums.php'; $model_forums = new JAVoiceModelforums(); $searchword = JRequest::getString('key'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php'; if ($items) { $model_status = JAVBModel::getInstance('voicetypesstatus', 'javoiceModel'); foreach ($items as $k => $item) { if (!$item->status_publishded) { $items[$k]->voice_type_status_id = 0; } $items[$k]->content = $helper->showItem($items[$k]->content, 0); //if user use anonymous in this item if (!($javconfig['systems']->get('use_anonymous', 0) && $item->use_anonymous)) { if (isset($item->user_id) && $item->user_id > 0) { $user = JFactory::getUser($item->user_id); if ($javconfig['plugin']->get('displayname', 'username') == "name") { $creat_by = $user->name; } else { if ($javconfig['plugin']->get('displayname', 'username') == "username") { $creat_by = $user->username; } else { $creat_by = JText::_("ANONYMOUS"); } } } elseif (isset($item->guest_name) && $item->guest_name != '') { if ($javconfig['plugin']->get('displayname', 'username') == "anonymous") { $creat_by = JText::_("ANONYMOUS"); } else { $creat_by = $item->guest_name; } } else { $creat_by = JText::_('ANONYMOUS'); } } else { $creat_by = JText::_('ANONYMOUS'); } $link = JRoute::_('index.php?option=com_javoice&view=items&layout=item&cid=' . $item->id . '&type=' . $item->voice_types_id . '&forums=' . $item->forums_id . '&Itemid=' . $Itemid); $items[$k]->create_date_store = $item->create_date; $items[$k]->create_date = $helper->generatTimeStamp($item->create_date); $items[$k]->update_date = $helper->generatTimeStamp($item->update_date); $items[$k]->create_by = $creat_by; $items[$k]->link = $link; $items[$k]->list_vote_value = ''; $items[$k]->list_vote_text = '\'\''; $items[$k]->list_vote_description = '\'\''; $items[$k]->has_down = 0; $check = true; /* Check status has closed */ if ($item->voice_type_status_id && $item->status_allow_voting == 0) { $items[$k]->list_vote_msg = $db->Quote(JText::_('VOTING_IS_CLOSED')); $check = false; } elseif ($item->voice_type_status_id && $item->status_allow_voting == -1) { $parent_status = $model_status->getItem($item->status_parent_id); if ($parent_status->allow_voting == 0) { $items[$k]->list_vote_msg = $db->Quote(JText::_('VOTING_IS_CLOSED')); $check = false; } else { $item->status_allow_voting = $parent_status->allow_voting; } } if ($check) { $user_can_post = $user_can_view = 0; $forum = $model_forums->getItem(array($item->forums_id)); $forum->gids_post = str_replace("\n\n", "\n", $forum->gids_post); $forum->gids_vote = str_replace("\n\n", "\n", $forum->gids_post); $lits_user_can_posts = explode("\n", $forum->gids_post); $lits_user_can_views = explode("\n", $forum->gids_view); $levels = $currentUser->getAuthorisedViewLevels(); $levels[] = 0; foreach ($levels as $gkey => $gVal) { if (in_array($gVal, $lits_user_can_posts)) { $user_can_post = 1; } if (in_array($gVal, $lits_user_can_views)) { $user_can_view = 1; } } if (!$user_can_view) { unset($items[$k]); } else { if ($user_can_post && isset($array_votes[$item->voice_types_id]['value'])) { $items[$k]->list_vote_value = $array_votes[$item->voice_types_id]['value']; $items[$k]->list_vote_text = $array_votes[$item->voice_types_id]['text']; $items[$k]->list_vote_description = $array_votes[$item->voice_types_id]['description']; $items[$k]->list_vote_msg = '\'\''; $values = explode(',', $array_votes[$item->voice_types_id]['value']); foreach ($values as $value) { if (intval($value) < 0) { $items[$k]->has_down = 1; break; } } } else { if ($currentUser->id) { $items[$k]->list_vote_msg = '<span class=error>' . JText::_('YOU_DO_NOT_HAVE_PERMISSION_TO_VOTE') . '<span>'; } else { $items[$k]->list_vote_msg = JText::_('LOGINREGISTER_TO_VOTE'); } $items[$k]->list_vote_msg = $db->Quote($items[$k]->list_vote_msg); } } } if ($searchword && isset($items[$k])) { $searchwords = preg_split("/\\s+/u", $searchword); $needle = $searchwords[0]; $maxchars = $javconfig['systems']->get('maxchars', 100); if ($maxchars == -1) { $maxchars = strlen($item->content); } SearchHelper::prepareSearchContent($item->content, $maxchars, $needle); $searchwords = array_unique($searchwords); $searchRegex = '#('; $x = 0; foreach ($searchwords as $hlword) { $searchRegex .= $x == 0 ? '' : '|'; $searchRegex .= preg_quote($hlword, '#'); $x++; } $searchRegex .= ')#iu'; $items[$k]->content = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $item->content); $items[$k]->title = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $item->title); } } } return $items; }
function parseItems(&$items, $types) { global $javconfig; $db = JFactory::getDBO(); $array_votes = array(); $user = JFactory::getUser(); require_once JPATH_SITE . DS . 'components' . DS . 'com_javoice' . DS . 'models' . DS . 'forums.php'; $model_forums = new JAVoiceModelforums(); $array_votes = array(); if ($types) { foreach ($types as $type) { $params_type = class_exists('JRegistry') ? new JRegistry($type->vote_option) : new JParameter($type->vote_option); $array_votes[$type->id]['value'] = $params_type->get('votes_value') ? str_replace("###", ',', $params_type->get('votes_value')) : ''; } } if ($items) { require_once JPATH_SITE . DS . 'components' . DS . 'com_javoice' . DS . 'models' . DS . 'voicetypesstatus.php'; $model_status = new javoiceModelvoicetypesstatus(); foreach ($items as $k => $item) { $items[$k]->has_down = 0; $check = true; /* Check status has closed */ if ($item->voice_type_status_id && $item->status_allow_voting == 0) { $check = false; } elseif ($item->voice_type_status_id && $item->status_allow_voting == -1) { $parent_status = $model_status->getItems(" and s.id='{$item->status_parent_id}' and s.published=1", '', 0, 1); if ($parent_status) { $parent_status = $parent_status[0]; } if ($parent_status && $parent_status->allow_voting == 0) { $check = false; } } if ($check) { $user_can_post = $user_can_view = 0; $layout = JRequest::getVar('layout', ''); $forum = $model_forums->getItems(' and f.id=' . $item->forums_id); if ($layout == "add" || $layout == "form") { $forum = $forum[1]; } else { $forum = $forum[0]; } $forum->gids_post = str_replace("\n\n", "\n", $forum->gids_post); $forum->gids_vote = str_replace("\n\n", "\n", $forum->gids_post); $lits_user_can_posts = explode("\n", $forum->gids_post); $lits_user_can_views = explode("\n", $forum->gids_view); if (!$user->id) { $user->groups = array_merge(array('Guest' => '0'), $user->groups); } foreach (array_values($user->groups) as $ugid) { if (in_array($ugid, $lits_user_can_posts)) { $user_can_post = 1; } if (in_array($ugid, $lits_user_can_views)) { $user_can_view = 1; } } if (!$user_can_view) { unset($items[$k]); } else { if ($user_can_post && isset($array_votes[$item->voice_types_id]['value'])) { $values = explode(',', $array_votes[$item->voice_types_id]['value']); foreach ($values as $value) { if (intval($value) < 0) { $items[$k]->has_down = 1; break; } } } } } } } }