Пример #1
0
 public function onAfterK2Save(&$item, $isNew)
 {
     if ($this->params->get('autosubscribe')) {
         if (!empty($item->id) && !empty($item->created_by) && $isNew) {
             $commentsAPI = JPATH_SITE . '/components/com_jcomments/jcomments.php';
             if (is_file($commentsAPI)) {
                 require_once $commentsAPI;
                 require_once JPATH_SITE . '/components/com_jcomments/jcomments.subscription.php';
                 $manager = JCommentsSubscriptionManager::getInstance();
                 $manager->subscribe($item->id, 'com_k2', $item->created_by);
             }
         }
     }
     return true;
 }
Пример #2
0
 public static function subscribe($formPlugin)
 {
     $formModel = $formPlugin->getModel();
     $jcObjectId = $formModel->formData['rowid'];
     $jcObjectGroup = 'com_fabrik_' . $formModel->getId();
     $lang = JFactory::getLanguage();
     $language = $lang->getTag();
     // Create / update thread
     self::jcUpsertObject($jcObjectId, $jcObjectGroup, $language, $formPlugin);
     // Add subscription
     $manager = JCommentsSubscriptionManager::getInstance();
     $user = JFactory::getUser();
     $manager->subscribe($jcObjectId, $jcObjectGroup, $user->id, $user->email, $user->name, $language);
     self::createJCommentPlugin($jcObjectGroup);
 }
Пример #3
0
 function unsubscribeUser($object_id, $object_group)
 {
     global $my, $mainframe;
     if (!isset($my)) {
         $my = $mainframe->getUser();
     }
     $response =& JCommentsFactory::getAjaxResponse();
     if ($my->id) {
         require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
         $manager =& JCommentsSubscriptionManager::getInstance();
         $result = $manager->unsubscribe($object_id, $object_group, $my->id);
         if ($result) {
             $response->addScript("jcomments.updateSubscription(false, '" . JText::_('Subscribe') . "');");
         } else {
             $errors = $manager->getErrors();
             $response->addAlert(implode('\\n', $errors));
         }
     }
     return $response;
 }
Пример #4
0
 public static function unsubscribe()
 {
     $app = JFactory::getApplication('site');
     $hash = $app->input->get('hash', '');
     $hash = preg_replace('#[^A-Z0-9]#i', '', $hash);
     if ($hash) {
         require_once JCOMMENTS_SITE . '/jcomments.subscription.php';
         $manager = JCommentsSubscriptionManager::getInstance();
         $subscription = $manager->getSubscriptionByHash($hash);
         $result = $manager->unsubscribeByHash($hash);
         if ($result) {
             $link = JCommentsObjectHelper::getLink($subscription->object_id, $subscription->object_group, $subscription->lang);
             if (empty($link)) {
                 $link = JRoute::_('index.php');
             }
             $app->redirect($link, JText::_('SUCCESSFULLY_UNSUBSCRIBED'));
         }
     }
     header('HTTP/1.0 404 Not Found');
     JError::raiseError(404, 'JGLOBAL_RESOURCE_NOT_FOUND');
     exit(404);
 }
Пример #5
0
 function getCommentsTree($object_id, $object_group = 'com_content', $search_text = '')
 {
     global $my;
     $object_id = (int) $object_id;
     $object_group = trim($object_group);
     $acl =& JCommentsFactory::getACL();
     $dbo =& JCommentsFactory::getDBO();
     $config =& JCommentsFactory::getConfig();
     $canPublish = $acl->canPublish();
     $canComment = $acl->canComment();
     $where = '';
     if ($search_text) {
         $words = explode(' ', $search_text);
         $wheres = array();
         foreach ($words as $word) {
             $wheres2 = array();
             $wheres2[] = "LOWER(name) LIKE '%{$word}%'";
             $wheres2[] = "LOWER(comment) LIKE '%{$word}%'";
         }
         if (isset($wheres2) && count($wheres2)) {
             $where .= ' AND (';
             $where .= implode(' OR ', $wheres2);
             $where .= ' )';
         }
     }
     if ($canComment == 0) {
         $total = JLMS_JComments::getCommentsCount($object_id, $object_group, $where);
         if ($total == 0) {
             return '';
         }
     }
     $query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment" . "\n , c.email, c.homepage, c.date as datetime, c.ip, c.published, c.checked_out, c.checked_out_time" . "\n , c.isgood, c.ispoor" . "\n , v.value as voted" . "\n FROM #__jcomments AS c" . "\n LEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($my->id ? " AND  v.userid = " . $my->id : " AND  v.ip = '" . $acl->getUserIP() . "'") . "\n WHERE c.object_id = " . $object_id . "\n AND c.object_group = '" . $object_group . "'" . (JCommentsMultilingual::isEnabled() ? "\nAND c.lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . ($canPublish == 0 ? "\nAND c.published = 1" : "") . $where . "\n ORDER BY c.parent, c.date ASC";
     $dbo->setQuery($query);
     $rows = $dbo->loadObjectList();
     $tmpl =& JCommentsFactory::getTemplate($object_id, $object_group);
     $tmpl->load('tpl_tree');
     $tmpl->load('tpl_comment');
     if (count($rows)) {
         $isLocked = $config->getInt('object_locked', 0) == 1;
         $tmpl->addVar('tpl_tree', 'comments-refresh', intval(!$isLocked));
         $tmpl->addVar('tpl_tree', 'comments-rss', intval($config->getInt('enable_rss') && !$isLocked));
         $tmpl->addVar('tpl_tree', 'comments-can-subscribe', intval($my->id && $acl->check('enable_subscribe') && !$isLocked));
         if ($my->id && $acl->check('enable_subscribe')) {
             require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
             $manager =& JCommentsSubscriptionManager::getInstance();
             $isSubscribed = $manager->isSubscribed($object_id, $object_group, $my->id);
             $tmpl->addVar('tpl_tree', 'comments-user-subscribed', $isSubscribed);
         }
         $i = 1;
         if ($config->getInt('enable_mambots') == 1) {
             require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
             JCommentsPluginHelper::importPlugin('jcomments');
             JCommentsPluginHelper::trigger('onBeforeDisplayCommentsList', array(&$rows));
             if ($acl->check('enable_gravatar')) {
                 JCommentsPluginHelper::trigger('onPrepareAvatars', array(&$rows));
             }
         }
         require_once JCOMMENTS_LIBRARIES . DS . 'joomlatune' . DS . 'tree.php';
         $tree = new JoomlaTuneTree($rows);
         $items = $tree->get();
         foreach ($rows as $row) {
             if ($config->getInt('enable_mambots') == 1) {
                 JCommentsPluginHelper::trigger('onBeforeDisplayComment', array(&$row));
             }
             // run autocensor, replace quotes, smiles and other pre-view processing
             JComments::prepareComment($row);
             // setup toolbar
             if (!$acl->canModerate($row)) {
                 $tmpl->addVar('tpl_comment', 'comments-panel-visible', 0);
             } else {
                 $tmpl->addVar('tpl_comment', 'comments-panel-visible', 1);
                 $tmpl->addVar('tpl_comment', 'button-edit', $acl->canEdit($row));
                 $tmpl->addVar('tpl_comment', 'button-delete', $acl->canDelete($row));
                 $tmpl->addVar('tpl_comment', 'button-publish', $acl->canPublish($row));
                 $tmpl->addVar('tpl_comment', 'button-ip', $acl->canViewIP($row));
             }
             $tmpl->addVar('tpl_comment', 'comment-show-vote', $config->getInt('enable_voting'));
             $tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail($row));
             $tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage($row));
             $tmpl->addVar('tpl_comment', 'comment-show-title', $config->getInt('comment_title'));
             $tmpl->addVar('tpl_comment', 'button-vote', $acl->canVote($row));
             $tmpl->addVar('tpl_comment', 'button-quote', $acl->canQuote($row));
             $tmpl->addVar('tpl_comment', 'button-reply', $acl->canReply($row));
             $tmpl->addVar('tpl_comment', 'avatar', $acl->check('enable_gravatar'));
             if (isset($items[$row->id])) {
                 $tmpl->addVar('tpl_comment', 'comment-number', '');
                 $tmpl->addObject('tpl_comment', 'comment', $row);
                 $items[$row->id]->html = $tmpl->renderTemplate('tpl_comment');
                 $i++;
             }
         }
         $tmpl->addObject('tpl_tree', 'comments-items', $items);
         unset($rows);
     }
     return $tmpl->renderTemplate('tpl_tree');
 }
Пример #6
0
 /**
  * Subscribes user for new comments notifications for an object
  *
  * @param int $object_id	The object identifier
  * @param string $object_group	The object group (component name)
  * @param int $userid	The registered user identifier
  * @param string $email	The user email (for guests only)
  * @param string $name The user name (for guests only)
  * @return boolean True on success, false otherwise.
  */
 function subscribe($object_id, $object_group, $userid, $email = '', $name = '', $lang = '')
 {
     $object_id = (int) $object_id;
     $object_group = trim($object_group);
     $userid = (int) $userid;
     if ($lang == '') {
         $lang = JCommentsMultilingual::getLanguage();
     }
     $dbo =& JCommentsFactory::getDBO();
     if ($userid != 0) {
         $user = JCommentsFactory::getUser($userid);
         $name = $user->name;
         $email = $user->email;
         unset($user);
     }
     $query = "SELECT * " . "\nFROM #__jcomments_subscriptions" . "\nWHERE object_id = " . (int) $object_id . "\nAND object_group = '" . $dbo->getEscaped($object_group) . "'" . "\nAND email = '" . $dbo->getEscaped($email) . "'" . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . $lang . "'" : "");
     $dbo->setQuery($query);
     $rows = $dbo->loadObjectList();
     if (count($rows) == 0) {
         $subscription = new JCommentsSubscriptionsDB($dbo);
         $subscription->object_id = $object_id;
         $subscription->object_group = $object_group;
         $subscription->name = $name;
         $subscription->email = $email;
         $subscription->userid = $userid;
         $subscription->hash = JCommentsSubscriptionManager::getHash($object_id, $object_group, $userid, $email, $lang);
         $subscription->lang = $lang;
         $subscription->published = 1;
         $subscription->store();
         return true;
     } else {
         // if current user is registered, but already exists subscription
         // on same email by guest - update subscription data
         if ($userid > 0 && $rows[0]->userid == 0) {
             $subscription = new JCommentsSubscriptionsDB($dbo);
             $subscription->id = $rows[0]->id;
             $subscription->userid = $userid;
             $subscription->lang = $lang;
             $subscription->hash = JCommentsSubscriptionManager::getHash($object_id, $object_group, $userid, $email, $lang);
             $subscription->store();
             return true;
         } else {
             $this->_errors[] = JText::_('Already subscribed');
         }
     }
     return false;
 }
Пример #7
0
 public static function unsubscribe()
 {
     $app = JCommentsFactory::getApplication('site');
     $hash = JCommentsInput::getVar('hash', '');
     $hash = preg_replace('#[^A-Z0-9]#i', '', $hash);
     if ($hash) {
         require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
         $manager = JCommentsSubscriptionManager::getInstance();
         $result = $manager->unsubscribeByHash($hash);
         if ($result) {
             JCommentsRedirect($app->getCfg('live_site') . '/index.php', JText::_('SUCCESSFULLY_UNSUBSCRIBED'));
         }
     }
     header('HTTP/1.0 404 Not Found');
     if (JCOMMENTS_JVERSION != '1.0') {
         $message = JCOMMENTS_JVERSION == '1.5' ? 'Resource Not Found' : 'JGLOBAL_RESOURCE_NOT_FOUND';
         JError::raiseError(404, $message);
     }
     exit(404);
 }
Пример #8
0
 public static function unsubscribeUser($object_id, $object_group)
 {
     $user = JCommentsFactory::getUser();
     $response = JCommentsFactory::getAjaxResponse();
     if ($user->id) {
         require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
         $manager = JCommentsSubscriptionManager::getInstance();
         $result = $manager->unsubscribe($object_id, $object_group, $user->id);
         if ($result) {
             $response->addScript("jcomments.updateSubscription(false, '" . JText::_('BUTTON_SUBSCRIBE') . "');");
         } else {
             $errors = $manager->getErrors();
             $response->addAlert(implode('\\n', $errors));
         }
     }
     return $response;
 }
Пример #9
0
 function unsubscribe()
 {
     global $mainframe;
     $hash = JCommentsInput::getVar('hash', '');
     $hash = preg_replace('#[^A-Z0-9]#i', '', $hash);
     if ($hash) {
         require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
         $manager =& JCommentsSubscriptionManager::getInstance();
         $result = $manager->unsubscribeByHash($hash);
         if ($result) {
             JCommentsRedirect($mainframe->getCfg('live_site') . '/index.php');
         }
     }
     header('HTTP/1.0 404 Not Found');
     if (JCOMMENTS_JVERSION == '1.5') {
         JError::raiseError(404, JText::_('Resource Not Found'));
     }
     exit(404);
 }