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; }
/** * Save item record */ function save() { global $javconfig; // Check for request forgeries //JRequest::checkToken() or jexit( 'Invalid Token' ); $Itemid = JRequest::getInt('Itemid'); if (!$Itemid) { $Itemid = JAVoiceHelpers::get_Itemid(array('option' => 'com_javoice', 'view' => 'items')); } $cid = JRequest::getVar('cid', array(), '', 'array'); $model = $this->getModel('items'); $user = JFactory::getUser(); if ($cid) { if (!JAVoiceHelpers::checkPermissionAdmin()) { $isAllowRegisterEdit = 0; if ($javconfig["systems"]->get("is_edit_delete_voice", 0)) { $item = $model->getItem(); $userEId = $user->get('id'); if ($userEId == $item->user_id) { $timeE = $javconfig["systems"]->get("time_for_edit_voice", 900); if ($timeE != -1 || time() < $item->create_date + $timeE) { $isAllowRegisterEdit = 1; } } } if (!$isAllowRegisterEdit) { return; } } } JArrayHelper::toInteger($cid); $helper = new JAVoiceHelpers(); $post = JRequest::get('request'); if ($post['title']) { $post['title'] = trim($post['title']); } $lang = JFactory::getLanguage(); $langName = $lang->getName(); // if(strpos("English", $langName) !== false){ // $post["title"] = $helper->addSpaceInLongTitle($post["title"]); // } // allow name only to contain html if (JRequest::getVar("javNameOfTextarea", "newVoiceContent") == "newVoiceContentReply") { $post['content'] = JRequest::getString('newVoiceContentReply', ''); } else { $post['content'] = JRequest::getString('newVoiceContent', ''); } $post['content'] = $helper->removeEmptyBBCode($post['content']); $post['voice_types_id'] = JRequest::getInt('type'); $post['forums_id'] = JRequest::getInt('forums_id'); $model->setState('request', $post); $objects = array(); if (!$cid) { $this->checkDataPhp($objects); } $row = $model->store(); if (isset($row->id)) { if ($javconfig['plugin']->get("is_attach_image", 0)) { //delete file in store image if remove file jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $listFile = JRequest::getVar('listfile', 0); $file_path = JPATH_ROOT . DS . "images" . DS . "stories" . DS . "ja_voice" . DS . $row->id; $listFileOfComments = JFolder::files($file_path); if ($listFileOfComments) { foreach ($listFileOfComments as $listFileOfComment) { if ($listFile) { if (!in_array($listFileOfComment, $listFile)) { JFile::delete($file_path . DS . $listFileOfComment); } } else { JFile::delete($file_path . DS . $listFileOfComment); } } } if ($listFile) { if (isset($_SESSION['javtemp'])) { $listFileTemp = JFolder::files($_SESSION['javtemp']); if ($listFileTemp) { foreach ($listFileTemp as $file) { if (!in_array($file, $listFile, true)) { JFile::delete($_SESSION['javtemp'] . DS . $file); } } } JRequest::setVar("listfile", implode(',', $listFile)); //move file $target_path = JPATH_ROOT . DS . "images" . DS . "stories" . DS . "ja_voice" . DS . $row->id; if (!is_dir($target_path)) { JFolder::create($target_path); } if ($listFileTemp) { JFolder::copy($_SESSION['javtemp'], $target_path, '', true); } JFolder::delete($_SESSION['javtemp']); unset($_SESSION['javtemp']); unset($_SESSION['javnameFolder']); } } } if ($javconfig["systems"]->get("is_enable_tagging", 0)) { //Insert tag. $javtags = JRequest::getVar("javtag", ""); $modelTags = $this->getModel('tags'); $modelTags->addVoiceToTag($row->id, $javtags); } if (intval($javconfig['systems']->get("is_notify_admin", 0))) { // send mail to administrator or author $helper->sendMailWhenNewVoice($row, $Itemid); } if (!$cid) { $this->vote('', $post['votes']); $model->update_total_items($row->voice_types_id, $row->forums_id); $model->vote($row->id, $post['votes']); if ($row->voice_type_status_id) { $status_is_spam = $this->getModel('voicetypesstatus')->is_spam($row->voice_type_status_id); } if ($row->published && (!$row->voice_type_status_id || !$status_is_spam)) { $object = new stdClass(); $object->id = ''; $object->attr = 'reload'; if (trim($javconfig['systems']->get("page_redirect", 'item')) == 'item') { $object->content = JRoute::_('index.php?option=com_javoice&view=items&layout=item&cid=' . $row->id . '&type=' . $row->voice_types_id . '&forums=' . $row->forums_id . '&Itemid=' . $Itemid . '&' . md5('save_successfull')); } else { $object->content = JURI::current(); } $object->content = str_replace('&', '&', $object->content); $objects[] = $object; $helper = new JAVoiceHelpers(); echo $helper->parse_JSON_new($objects); exit; } if (isset($post['create_full']) && $post['create_full'] == 1) { $url = str_replace('&', '&', JRoute::_('index.php?option=com_javoice&type=' . $post['type'] . '&' . md5('save_successfull'))); return $this->setRedirect($url); } JRequest::setVar('layout', 'after_save'); } else { $object = new stdClass(); $object->id = '#jav-box-item-' . $row->id . ' .jav-item-title'; $object->attr = 'html'; $object->content = $row->title; $objects[] = $object; $row->content = str_replace("\n", '<br/>', $row->content); $object = new stdClass(); $object->id = '#jav-box-item-' . $row->id . ' .jav-item-content'; $object->attr = 'html'; $object->content = html_entity_decode($helper->showItem($row->content)); $objects[] = $object; $dir = JPATH_ROOT . DS . "images" . DS . "stories" . DS . "ja_voice" . DS . $row->id; $files = $model->formatFilesInDir($dir, 'download', $user->id, $row->id); $content = $files; $object = new stdClass(); $object->id = '#jav_file_upload_' . $row->id; $object->attr = 'html'; $object->content = $content; $objects[] = $object; $object = new stdClass(); $object->id = '#jav-box-item-' . $row->id . ' .created-at'; $object->attr = 'html'; $object->content = JText::_('UPDATED_ON') . ' ' . JAVoiceHelpers::generatTimeStamp($row->update_date); $objects[] = $object; if ($javconfig["systems"]->get("is_enable_tagging", 0)) { $object = new stdClass(); $object->id = '#jav_item_tags'; $object->attr = 'html'; $object->content = ""; $tagList = $modelTags->getTagByVoice($row->id); $spaterTags = $javconfig["systems"]->get("characters_separating_tags", ","); $tagContent = "<b>" . JText::_("TAG_LIST") . ':</b>'; foreach ($tagList as $tagItem => $tag) { $tagContent .= ' <a title="' . $tag->name . '" href="' . JRoute::_('index.php?option=com_javoice&view=items&layout=item&tagid=' . $tag->id . '&Itemid=' . $Itemid) . '">' . $tag->name . '</a>'; if ($tagItem <= count($tagList) - 1) { $tagContent .= $spaterTags; } } $objects[] = $object; $object->content = $tagContent; } if ($javconfig["systems"]->get("use_anonymous", 0)) { $object = new stdClass(); $object->id = '#jav-box-item-' . $row->id . ' .jav-createdby'; $object->attr = 'html'; if ($row->use_anonymous) { $object->content = '<small>' . JText::_('BY') . '</small> ' . JText::_("ANONYMOUS"); } else { if (isset($row->user_id) && $row->user_id > 0) { $user = JFactory::getUser($row->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($row->guest_name) && $row->guest_name != '') { if ($javconfig['plugin']->get('displayname', 'username') == "anonymous") { $creat_by = JText::_("ANONYMOUS"); } else { $creat_by = $row->guest_name; } } else { $creat_by = JText::_('ANONYMOUS'); } $object->content = '<small>' . JText::_('BY') . '</small> <a href="' . JRoute::_('index.php?option=com_javoice&view=users&uid=' . $row->user_id . '&Itemid=' . $Itemid) . '" class="user">' . $creat_by . '</a>'; } $objects[] = $object; } $helper = new JAVoiceHelpers(); echo $helper->parse_JSON_new($objects); exit; } } else { $object = new stdClass(); $object->id = '#jav-popup-error-posting'; $object->attr = 'html'; $object->content = JText::_('ERROR_FOUND_FAIL_TO_SAVE_IDEA') . '<br/>' . $row; $objects[] = $object; $object = new stdClass(); $object->id = '#jav-popup-error-posting'; $object->attr = 'css'; $object->content = 'display,block'; $objects[] = $object; $helper = new JAVoiceHelpers(); echo $helper->parse_JSON_new($objects); exit; } return parent::display(); }