function approve($comment_ids) { if (!is_array($comment_ids) || empty($comment_ids)) { $this->setError('COM_JUDIRECTORY_NO_ITEM_SELECTED'); return false; } JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables'); $comment_table = JTable::getInstance("Comment", "JUDirectoryTable"); $count = 0; $comment_ids = (array) $comment_ids; $rootComment = JUDirectoryFrontHelperComment::getRootComment(); $listingIds = array(); foreach ($comment_ids as $comment_id) { $comment_table->reset(); if ($comment_table->load($comment_id) && $comment_table->parent_id == $rootComment->id && $comment_table->approved == 0) { $listingIds[$comment_table->listing_id] = $comment_table->listing_id; } $user = JFactory::getUser(); $date = JFactory::getDate(); $comment_table->approved = 1; $comment_table->published = 1; $comment_table->approved_by = $user->id; $comment_table->approved_time = $date->toSql(); $comment_table->store(); $count++; JUDirectoryFrontHelperMail::sendEmailByEvent('comment.approve', $comment_id); $logData = array('user_id' => $comment_table->user_id, 'event' => 'comment.approve', 'item_id' => $comment_id, 'listing_id' => $comment_table->listing_id, 'value' => 0, 'reference' => ''); JUDirectoryFrontHelperLog::addLog($logData); } foreach ($listingIds as $listingId) { JUDirectoryHelper::rebuildRating($listingId); } return $count; }
public function publish() { JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN')); $cid = JFactory::getApplication()->input->get('id', array(), 'array'); $data = array('publish' => 1, 'unpublish' => 0); $task = $this->getTask(); $value = JArrayHelper::getValue($data, $task, 0, 'int'); if (empty($cid)) { JError::raiseWarning(500, JText::_('COM_JUDIRECTORY_NO_ITEM_SELECTED')); } else { $model = $this->getModel(); JArrayHelper::toInteger($cid); if (!$model->publish($cid, $value)) { JError::raiseWarning(500, $model->getError()); } else { if ($value == 1) { $ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED'; } elseif ($value == 0) { $ntext = $this->text_prefix . '_N_ITEMS_UNPUBLISHED'; } foreach ($cid as $id) { JUDirectoryFrontHelperMail::sendEmailByEvent('listing.editstate', $id); } $this->setMessage(JText::plural($ntext, count($cid))); $user = JFactory::getUser(); foreach ($cid as $id) { $logData = array('user_id' => $user->id, 'event' => 'listing.editstate', 'item_id' => $id, 'listing_id' => $id, 'value' => $value, 'reference' => ''); JUDirectoryFrontHelperLog::addLog($logData); } } } $this->setRedirect(JRoute::_($this->getReturnPage())); }
public function publish(&$pks, $value = 1) { $table = $this->getTable('Comment', 'JUDirectoryTable'); $new_pks = array(); while (!empty($pks)) { $pk = array_shift($pks); $new_pks[] = $pk; $table->reset(); if (!$table->load($pk)) { if ($error = $table->getError()) { $this->setError($error); } return false; } $db = $this->getDbo(); $query = $db->getQuery(true); $query->clear(); $query->select('id'); $query->from('#__judirectory_comments'); $query->where('lft > ' . (int) $table->lft); $query->where('rgt < ' . (int) $table->rgt); $db->setQuery($query); $childIds = $db->loadColumn(); foreach ($childIds as $childId) { if (!in_array($childId, $pks)) { array_push($pks, $childId); } } $commentId = $pk; if (!parent::publish($pk, $value)) { return false; } JUDirectoryFrontHelperMail::sendEmailByEvent('comment.editstate', $commentId); $logData = array('user_id' => $table->user_id, 'event' => 'comment.editstate', 'item_id' => $commentId, 'listing_id' => $table->listing_id, 'value' => $value, 'reference' => ''); JUDirectoryFrontHelperLog::addLog($logData); } $pks = $new_pks; return true; }
public function delete($pk = null, $children = true) { $k = $this->_tbl_key; $pk = is_null($pk) ? $this->{$k} : $pk; if ($this->_trackAssets) { $name = $this->_getAssetName(); $asset = JTable::getInstance('Asset'); if (!$asset->_lock()) { return false; } if ($asset->loadByName($name)) { if (!$asset->delete(null, $children)) { $this->setError($asset->getError()); $asset->_unlock(); return false; } $asset->_unlock(); } else { $this->setError($asset->getError()); $asset->_unlock(); return false; } } if (!($node = $this->_getNode($pk))) { $this->_unlock(); return false; } $commentObjList = array(); if ($children) { $tree = $this->getTree($pk); foreach ($tree as $comment) { $this->_delete($comment); $commentObjList[] = JUDirectoryFrontHelperComment::getCommentObject($comment->id); } if (!$this->_lock()) { return false; } $query = $this->_db->getQuery(true); $query->delete(); $query->from($this->_tbl); $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('lft = lft - ' . (int) $node->width); $query->where('lft > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('rgt = rgt - ' . (int) $node->width); $query->where('rgt > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); } else { $this->_delete($node); if (!$this->_lock()) { return false; } $query = $this->_db->getQuery(true); $query->delete(); $query->from($this->_tbl); $query->where('lft = ' . (int) $node->lft); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('lft = lft - 1'); $query->set('rgt = rgt - 1'); $query->set('level = level - 1'); $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('parent_id = ' . (int) $node->parent_id); $query->where('parent_id = ' . (int) $node->{$k}); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('lft = lft - 2'); $query->where('lft > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('rgt = rgt - 2'); $query->where('rgt > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); } $this->_unlock(); if ($children && !empty($commentObjList)) { foreach ($commentObjList as $commentObj) { if ($commentObj->approved == 0) { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.reject', $commentObj->id, get_object_vars($commentObj)); } elseif (JUDirectoryFrontHelperModerator::isModerator()) { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.moddelete', $commentObj->id, get_object_vars($commentObj)); } else { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.userdelete', $commentObj->id, get_object_vars($commentObj)); } } } else { $commentObj = JUDirectoryFrontHelperComment::getCommentObject($node->id); if ($commentObj->approved == 0) { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.reject', $commentObj->id, get_object_vars($commentObj)); } elseif (JUDirectoryFrontHelperModerator::isModerator()) { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.moddelete', $commentObj->id, get_object_vars($commentObj)); } else { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.userdelete', $commentObj->id, get_object_vars($commentObj)); } } return true; }
public function sendemail() { JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $data = array(); $data['from_name'] = $app->input->post->get('name', '', 'string'); $data['from_email'] = $app->input->post->get('email', '', 'string'); $data['to_email'] = $app->input->post->get('to_email', '', 'string'); $data['listing_id'] = $app->input->getInt('id', 0); JUDirectoryHelper::obCleanData(); if (!JUDirectoryFrontHelperMail::sendEmailByEvent('listing.sendtofriend', $data['listing_id'], $data)) { echo '<label class="control-label"></label><div class="controls"><span class="alert alert-error">' . JText::_('COM_JUDIRECTORY_FAIL_TO_SEND_EMAIL') . '</span></div>'; exit; } else { echo '<label class="control-label"></label><div class="controls"><span class="alert alert-success">' . JText::_('COM_JUDIRECTORY_SEND_EMAIL_SUCCESSFULLY') . '</span></div>'; exit; } }
public function delete($pk = null) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables'); $k = $this->_tbl_key; $pk = is_null($pk) ? $this->{$k} : $pk; $db = JFactory::getDbo(); $query = "DELETE FROM #__judirectory_subscriptions WHERE item_id = {$pk} AND type = 'listing'"; $db->setQuery($query); $db->execute(); $query = "SELECT * FROM #__judirectory_comments WHERE listing_id = " . $pk; $db->setQuery($query); $commentIds = $db->loadColumn(); if ($commentIds) { $commentTable = JTable::getInstance("Comment", "JUDirectoryTable"); foreach ($commentIds as $commentId) { $commentTable->delete($commentId); } } $query = "SELECT id FROM #__judirectory_rating WHERE listing_id = {$pk}"; $db->setQuery($query); $ratingItemIds = $db->loadColumn(); if ($ratingItemIds) { $ratingTable = JTable::getInstance("Rating", "JUDirectoryTable"); foreach ($ratingItemIds as $ratingItemId) { $ratingTable->delete($ratingItemId); } } $query = "DELETE FROM #__judirectory_reports WHERE item_id = {$pk} AND type = 'listing'"; $db->setQuery($query); $db->execute(); $query = "SELECT id FROM #__judirectory_collections_items WHERE listing_id = {$pk}"; $db->setQuery($query); $collectionItemIds = $db->loadColumn(); if ($collectionItemIds) { $collectionItemTable = JTable::getInstance("CollectionItem", "JUDirectoryTable"); foreach ($collectionItemIds as $collectionItemId) { $collectionItemTable->delete($collectionItemId); } } JUDirectoryHelper::deleteLogs('listing', $pk); $query = "DELETE FROM #__judirectory_mailqs\n\t\t\t WHERE item_id =" . $pk . "\n\t\t\t\t\t\tAND email_id IN (SELECT id FROM #__judirectory_emails WHERE (`event` LIKE 'listing.%' AND `event` != 'listing.delete'))"; $db->setQuery($query); $db->execute(); $query = $db->getQuery(true); $query->select('id'); $query->from('#__judirectory_listings'); $query->where('approved=' . -$pk); $db->setQuery($query); $tempListingIds = $db->loadColumn(); if (count($tempListingIds)) { foreach ($tempListingIds as $tempListingId) { $this->deleteMainData($tempListingId, true); } } $cat_id = JUDirectoryFrontHelperCategory::getMainCategoryId($this->id); $this->deleteMainData($pk); if (parent::delete($pk)) { $app = JFactory::getApplication(); if ($app->isSite()) { $registry = new JRegistry(); $registry->loadObject($this); $mailData = $registry->toArray(); $mailData['cat_id'] = $cat_id; if ($this->approved < 1) { JUDirectoryFrontHelperMail::sendEmailByEvent('listing.reject', $this->id, $mailData); } else { JUDirectoryFrontHelperMail::sendEmailByEvent('listing.delete', $this->id, $mailData); } } return true; } else { return false; } }
} $app = JFactory::getApplication(); $task = $app->input->get('task'); switch ($task) { case 'captcha': $namespace = $app->input->getString('captcha_namespace', ''); JUDirectoryFrontHelperCaptcha::captchaSecurityImages($namespace); exit; break; case 'rawdata': $field_id = $app->input->getInt('field_id', 0); $listing_id = $app->input->getInt('listing_id', 0); $fieldObj = JUDirectoryFrontHelperField::getField($field_id, $listing_id); JUDirectoryHelper::obCleanData(); $fieldObj->getRawData(); exit; break; case 'cron': JUDirectoryFrontHelperMail::sendMailq(); exit; break; default: $controller = JControllerLegacy::getInstance('judirectory'); $controller->execute($app->input->get('task')); $controller->redirect(); break; } $params = JUDirectoryHelper::getParams(); if ($params->get('send_mailqs_on_pageload', 0)) { JUDirectoryFrontHelperMail::sendMailq(); }
public function saveListingSendEmail($table, $isNew, $fieldsData, $tableBeforeSave = null) { $app = JFactory::getApplication(); if ($app->isSite()) { if ($isNew) { JUDirectoryFrontHelperMail::sendEmailByEvent('listing.create', $table->id); } else { JUDirectoryFrontHelperMail::sendEmailByEvent('listing.edit', $table->id); } } }
public function saveComment($postData = array()) { $user = JFactory::getUser(); $nowDate = JFactory::getDate()->toSql(); $title = htmlspecialchars($postData['title']); $comment = htmlspecialchars($postData['comment'], ENT_NOQUOTES); if ($user->get('guest')) { $guestName = strip_tags($postData['guest_name']); $guestEmail = strip_tags($postData['guest_email']); } else { $guestName = ''; $guestEmail = ''; } $website = isset($postData['website']) ? strip_tags($postData['website']) : ''; $listingId = (int) $postData['listing_id']; $params = JUDirectoryHelper::getParams(null, $listingId); $totalVotes = 0; $helpfulVotes = 0; $ipAddress = JUDirectoryFrontHelper::getIpAddress(); $parentId = (int) $postData['parent_id']; $rootComment = JUDirectoryFrontHelperComment::getRootComment(); if ($parentId == $rootComment->id) { $approved = JUDirectoryFrontHelperPermission::canAutoApprovalComment($listingId); $level = 1; if ($params->get('filter_comment_language', 0)) { $language = $postData['comment_language']; } else { $language = '*'; } } else { $approved = JUDirectoryFrontHelperPermission::canAutoApprovalReplyComment($listingId); $parentComment = $this->getCommentObject($parentId); $level = $parentComment->level + 1; $language = '*'; } if ($approved) { $approved = 1; $published = 1; } else { $approved = 0; $published = 0; } $dataComment = array('title' => $title, 'comment' => $comment, 'user_id' => $user->id, 'guest_name' => $guestName, 'guest_email' => $guestEmail, 'website' => $website, 'listing_id' => $listingId, 'created' => $nowDate, 'total_votes' => $totalVotes, 'helpful_votes' => $helpfulVotes, 'ip_address' => $ipAddress, 'approved' => $approved, 'published' => $published, 'parent_id' => $parentId, 'level' => $level, 'language' => $language); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables'); $commentTable = JTable::getInstance('Comment', 'JUDirectoryTable'); $commentTable->setLocation($postData['parent_id'], 'last-child'); $commentTable->bind($dataComment); if (!$commentTable->check() || !$commentTable->store()) { $this->setError($commentTable->getError()); return false; } $canRateListing = JUDirectoryFrontHelperPermission::canRateListing($listingId); if ($canRateListing && $params->get('enable_listing_rate_in_comment_form', 1) && $commentTable->parent_id == $rootComment->id) { $postData['approved'] = $approved; $criteriaArray = array(); if (isset($postData['criteria_array'])) { if (JUDirectoryHelper::hasMultiRating()) { $criteriaArray = $postData['criteria_array']; $saveRating = $this->saveRating($postData, $listingId, $criteriaArray, $commentTable->id); } } else { if (isset($postData['ratingValue'])) { $saveRating = $this->saveRating($postData, $listingId, $criteriaArray, $commentTable->id); } } if (!$saveRating) { $this->setError(JText::_('COM_JUDIRECTORY_SAVE_RATING_FAILED')); return false; } } if (JUDIRPROVERSION && isset($postData['subscribe']) && $postData['subscribe']) { $subscriptionData = array(); $subscriptionData['user_id'] = $user->id; $subscriptionData['type'] = 'comment'; $subscriptionData['comment_id'] = $commentTable->id; $subscriptionData['name'] = $user->id == 0 ? $guestName : $user->username; $subscriptionData['email'] = $user->id == 0 ? $guestEmail : $user->email; $subscriptionData['item_id'] = $commentTable->id; $subscriptionData['ip_address'] = $ipAddress; $subscriptionData['created'] = $nowDate; $subscriptionData['published'] = $user->id == 0 && $params->get('activate_subscription_by_email', 1) ? 0 : 1; require_once JPATH_SITE . '/components/com_judirectory/models/subscribe.php'; JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_judirectory/models'); $subscribeModel = JModelLegacy::getInstance('Subscribe', 'JUDirectoryModel'); if (!$subscribeModel->add($subscriptionData)) { $this->setError(JText::_('COM_JUDIRECTORY_SUBSCRIBE_FAILED')); return false; } } if ($commentTable->parent_id == $rootComment->id) { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.create', $commentTable->id); $logData = array('item_id' => $commentTable->id, 'listing_id' => $listingId, 'user_id' => $user->id, 'event' => 'comment.create'); $commentSubmitType = 'create'; } else { JUDirectoryFrontHelperMail::sendEmailByEvent('comment.reply', $commentTable->id); $logData = array('user_id' => $user->id, 'event' => 'comment.reply', 'item_id' => $commentTable->id, 'listing_id' => $listingId, 'value' => 0, 'reference' => $commentTable->parent_id); $commentSubmitType = 'reply'; } JUDirectoryFrontHelperLog::addLog($logData); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('judirectory'); $dispatcher->trigger('onCommentSubmit', array($commentTable, $commentSubmitType)); return $commentTable->id; }