コード例 #1
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;
 }
コード例 #2
0
 function save()
 {
     $task = JCommentsInput::getVar('task');
     $id = (int) JCommentsInput::getVar('id', 0);
     $bbcode =& JCommentsFactory::getBBCode();
     $db =& JCommentsFactory::getDBO();
     require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
     $row = new JCommentsSubscriptionsDB($db);
     if ($id) {
         $row->load($id);
     }
     $row->object_id = (int) JCommentsInput::getVar('object_id');
     $row->object_group = preg_replace('#[^0-9A-Za-z\\-\\_\\,\\.\\*]#is', '', trim(strip_tags(JCommentsInput::getVar('object_group'))));
     $row->name = preg_replace("/[\\'\"\\>\\<\\(\\)\\[\\]]?+/i", '', strip_tags(JCommentsInput::getVar('name')));
     $row->email = trim(strip_tags(JCommentsInput::getVar('email')));
     $row->store();
     JCommentsCache::cleanCache('com_jcomments');
     switch ($task) {
         case 'subscription.apply':
             JCommentsRedirect(JCOMMENTS_INDEX . '?option=com_jcomments&task=subscription.edit&hidemainmenu=1&cid[]=' . $row->id);
             break;
         case 'subscription.save':
         default:
             JCommentsRedirect(JCOMMENTS_INDEX . '?option=com_jcomments&task=subscriptions');
             break;
     }
 }