Example #1
0
 /**
  * adds the link for the connect param
  * @since 1.7.3
  * @param  $user pass-by-reference
  * @return void
  */
 private function getUserLink(&$user)
 {
     $username = KunenaFactory::getUser($user['userid'])->getName();
     if ($user['leapcorrection'] == $this->timeo->format('z', true) + 1) {
         $subject = getSubject($username);
         $db = JFactory::getDBO();
         $query = "SELECT id,catid,subject,time as year FROM #__kunena_messages WHERE subject='{$subject}'";
         $db->setQuery($query, 0, 1);
         $post = $db->loadAssoc();
         if ($db->getErrorMsg()) {
             KunenaError::checkDatabaseError();
         }
         $catid = $this->params->get('bcatid');
         $postyear = new JDate($post['year'], $this->soffset);
         if (empty($post) && !empty($catid) || !empty($post) && !empty($catid) && $postyear->format('Y', true) < $this->timeo->format('Y', true)) {
             $botname = $this->params->get('swkbbotname', JText::_('SW_KBIRTHDAY_FORUMPOST_BOTNAME_DEF'));
             $botid = $this->params->get('swkbotid');
             $time = CKunenaTimeformat::internalTime();
             //Insert the birthday thread into DB
             $query = "INSERT INTO #__kunena_messages (catid,name,userid,email,subject,time, ip)\n\t\t    \t\tVALUES({$catid},'{$botname}',{$botid}, '','{$subject}', {$time}, '')";
             $db->setQuery($query);
             $db->query();
             if ($db->getErrorMsg()) {
                 KunenaError::checkDatabaseError();
             }
             //What ID get our thread?
             $messid = (int) $db->insertID();
             //Insert the thread message into DB
             $message = getMessage($username);
             $query = "INSERT INTO #__kunena_messages_text (mesid,message)\n                    VALUES({$messid},'{$message}')";
             $db->setQuery($query);
             $db->query();
             if ($db->getErrorMsg()) {
                 KunenaError::checkDatabaseError();
             }
             //We know the thread ID so we can update the parent thread id with it's own ID because we know it's
             //the first post
             $query = "UPDATE #__kunena_messages SET thread={$messid} WHERE id={$messid}";
             $db->setQuery($query);
             $db->query();
             if ($db->getErrorMsg()) {
                 KunenaError::checkDatabaseError();
             }
             // now increase the #s in categories
             CKunenaTools::modifyCategoryStats($messid, 0, $time, $catid);
             $user['link'] = CKunenaLink::GetViewLink('view', $messid, $catid, '', $username);
             $uri = JFactory::getURI();
             if ($uri->getVar('option') == 'com_kunena') {
                 $app =& JFactory::getApplication();
                 $app->redirect($uri->toString());
             }
         } elseif (!empty($post)) {
             $user['link'] = CKunenaLink::GetViewLink('view', $post['id'], $post['catid'], '', $username);
         }
     } else {
         $user['link'] = CKunenaLink::GetProfileLink($user['userid']);
     }
 }
Example #2
0
 public function ApproveMessage()
 {
     if ($this->_checkToken()) {
         return false;
     }
     $array = JRequest::getVar('cb', array(0), 'post', 'array');
     $backUrl = JRequest::getVar('HTTP_REFERER', JURI::base(true), 'server');
     $success = 0;
     require_once KUNENA_PATH_LIB . '/kunena.posting.class.php';
     foreach ($array as $id => $value) {
         if (!$value) {
             continue;
         }
         $message = new CKunenaPosting();
         $message->action($id);
         if (!$message->canApprove()) {
             $errors = $message->getErrors();
             foreach ($errors as $field => $error) {
                 $this->_app->enqueueMessage($field . ': ' . $error, 'error');
             }
             continue;
         }
         $this->_db->setQuery("UPDATE `#__kunena_messages` SET hold='0' WHERE id={$this->_db->Quote($id)}");
         $this->_db->query();
         if (KunenaError::checkDatabaseError()) {
             return;
         }
         CKunenaTools::modifyCategoryStats($message->get('id'), $message->get('parent'), $message->get('time'), $message->get('catid'));
         $message->emailToSubscribers(null, $this->config->allowsubscriptions, false, false);
         $success++;
     }
     //end foreach
     if ($success) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_MODERATE_APPROVE_SUCCESS'), 'notice');
     }
     while (@ob_end_clean()) {
     }
     $this->app->redirect($backUrl);
 }
Example #3
0
 $duplicatetimewindow = $posttime - $fbConfig->fbsessiontimeout;
 unset($existingPost);
 $kunena_db->setQuery("SELECT m.id FROM #__fb_messages AS m JOIN #__fb_messages_text AS t ON m.id=t.mesid WHERE m.userid='{$kunena_my->id}' AND m.name='{$fb_authorname}' AND m.email='{$email}' AND m.subject='{$subject}' AND m.ip='{$ip}' AND t.message='{$message}' AND m.time>='{$duplicatetimewindow}'");
 $kunena_db->query() or trigger_dberror('Unable to load post.');
 $existingPost = $kunena_db->loadObject();
 unset($pid);
 if ($existingPost !== null) {
     $pid = $existingPost->id;
 }
 if (!isset($pid)) {
     $kunena_db->setQuery("INSERT INTO #__fb_messages\r\n                                    \t\t\t\t\t\t(parent,thread,catid,name,userid,email,subject,time,ip,topic_emoticon,hold)\r\n                                    \t\t\t\t\t\tVALUES('{$parent}','{$thread}','{$catid}'," . $kunena_db->quote($fb_authorname) . ",'{$kunena_my->id}'," . $kunena_db->quote($email) . "," . $kunena_db->quote($subject) . ",'{$posttime}','{$ip}','{$topic_emoticon}','{$holdPost}')");
     if ($kunena_db->query()) {
         $pid = $kunena_db->insertId();
         // now increase the #s in categories only case approved
         if ($holdPost == 0) {
             CKunenaTools::modifyCategoryStats($pid, $parent, $posttime, $catid);
         }
         $kunena_db->setQuery("INSERT INTO #__fb_messages_text (mesid,message) VALUES('{$pid}'," . $kunena_db->quote($message) . ")");
         $kunena_db->query();
         if ($thread == 0) {
             //if thread was zero, we now know to which id it belongs, so we can determine the thread and update it
             $kunena_db->setQuery("UPDATE #__fb_messages SET thread='{$pid}' WHERE id='{$pid}'");
             $kunena_db->query();
         }
         //update the user posts count
         if ($kunena_my->id) {
             $kunena_db->setQuery("UPDATE #__fb_users SET posts=posts+1 WHERE userid={$kunena_my->id}");
             $kunena_db->query();
         }
         //Update the attachments table if an image has been attached
         if (!empty($imageLocation) && file_exists($imageLocation)) {
 protected function savePost()
 {
     if (!$this->check()) {
         return false;
     }
     // Update rest of the information
     $this->setOption('allowed', null);
     // Fill user related information
     if ($this->getOption('anonymous')) {
         // Anonymous post: Just in case remove userid, email and IP address - name is already anonymous
         $this->set('ip', '');
         $this->set('userid', 0);
         $this->set('email', '');
     } else {
         // Regular post: Fill missing fields
         if (!$this->get('ip')) {
             $this->set('ip', $_SERVER["REMOTE_ADDR"]);
         }
         if (!$this->get('userid')) {
             $this->set('userid', $this->_my->id);
         }
         if (!$this->get('name')) {
             $this->set('name', $this->_myuser->getName());
         }
         if (!$this->get('email')) {
             $this->set('email', $this->_my->email);
         }
     }
     // Fill thread/post related information
     $this->set('parent', $this->parent->id);
     $this->set('thread', $this->parent->thread);
     $this->set('catid', $this->parent->catid);
     if (!$this->get('time')) {
         $this->set('time', CKunenaTimeformat::internalTime());
     }
     // On reviewed forum, require approval if user is not a moderator
     $this->set('hold', CKunenaTools::isModerator($this->_my, $this->parent->catid) ? 0 : (int) $this->parent->review);
     // Activity integration
     $activity = KunenaFactory::getActivityIntegration();
     if ($this->parent->hold == 0) {
         if ($this->parent->thread == 0) {
             $activity->onBeforePost($this);
         } else {
             $activity->onBeforeReply($this);
         }
     }
     if (!empty($this->errors)) {
         return false;
     }
     if ($this->isAlreadyPosted()) {
         return $this->setError('-post-', JText::_('COM_KUNENA_POST_DUPLICATE_IGNORED'));
     }
     $meskeys = array();
     $mesvalues = array();
     $txtkeys = array('mesid');
     $txtvalues = array(0);
     foreach ($this->message as $field => $value) {
         if ($field != 'message') {
             $meskeys[] = $this->_db->nameQuote($field);
             $mesvalues[] = $this->_db->quote($value);
         } else {
             $txtkeys[] = $this->_db->nameQuote($field);
             $txtvalues[] = $this->_db->quote($value);
         }
     }
     if (empty($mesvalues) || count($txtvalues) < 2) {
         return $this->setError('-post-', JText::_('COM_KUNENA_POST_ERROR_SAVE'));
     }
     $meskeys = implode(', ', $meskeys);
     $mesvalues = implode(', ', $mesvalues);
     $query = "INSERT INTO #__kunena_messages ({$meskeys}) VALUES({$mesvalues})";
     $this->_db->setQuery($query);
     $this->_db->query();
     $dberror = $this->checkDatabaseError();
     if ($dberror) {
         return $this->setError('-post-', JText::_('COM_KUNENA_POST_ERROR_SAVE'));
     }
     $id = (int) $this->_db->insertId();
     $txtvalues[0] = $this->_db->quote($id);
     $txtkeys = implode(', ', $txtkeys);
     $txtvalues = implode(', ', $txtvalues);
     $query = "INSERT INTO #__kunena_messages_text ({$txtkeys}) VALUES({$txtvalues})";
     $this->_db->setQuery($query);
     $this->_db->query();
     $dberror = $this->checkDatabaseError();
     if ($dberror) {
         // Delete partial message on error
         $query = "DELETE FROM #__kunena_messages WHERE mesid={$this->_db->quote($id)}";
         $this->_db->setQuery($query);
         $this->_db->query();
         return $this->setError('-post-', JText::_('COM_KUNENA_POST_ERROR_SAVE'));
     }
     $this->set('id', $id);
     if ($this->parent->thread == 0) {
         // For new thread, we now know to where the message belongs
         $this->set('thread', $id);
         $query = "UPDATE #__kunena_messages SET thread={$this->_db->quote($id)} WHERE id={$this->_db->quote($id)}";
         $this->_db->setQuery($query);
         $this->_db->query();
         $dberror = $this->checkDatabaseError();
         if ($dberror) {
             return $this->setError('-post-', JText::_('COM_KUNENA_POST_ERROR_SAVE'));
         }
     }
     //update the user posts count
     $userid = (int) $this->get('userid');
     if ($userid) {
         $userprofile = KunenaFactory::getUser($userid);
         if (!$userprofile->exists()) {
             $userprofile->save();
         }
         $query = "UPDATE #__kunena_users SET posts=posts+1 WHERE userid={$this->_db->quote($userid)}";
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     // now increase the #s in categories only case approved
     if (!$this->get('hold')) {
         CKunenaTools::modifyCategoryStats($id, $this->get('parent'), $this->get('time'), $this->get('catid'));
     }
     // Add attachments if there are any
     // TODO: find better way
     if ($this->getOption('attachments')) {
         require_once KUNENA_PATH_LIB . '/kunena.attachments.class.php';
         $attachments = CKunenaAttachments::getInstance();
         $message = $this->get('message');
         $fileinfos = $attachments->multiupload($id, $message);
         foreach ($fileinfos as $fileinfo) {
             if (!$fileinfo['status']) {
                 $this->_app->enqueueMessage(JText::sprintf('COM_KUNENA_UPLOAD_FAILED', $fileinfo['name']) . ': ' . $fileinfo['error'], 'error');
             }
         }
         $this->_db->setQuery("UPDATE #__kunena_messages_text SET message={$this->_db->quote($message)} WHERE mesid={$this->_db->Quote($id)}");
         $this->_db->query();
     }
     // Mark topic read for me
     CKunenaTools::markTopicRead($this->get('thread'), $this->_my->id);
     // Mark topic unread for others
     // First take care of old sessions to make our job easier and faster
     $lasttime = $this->get('time') - max(intval(JFactory::getConfig()->getValue('config.lifetime')) * 60, intval(KunenaFactory::getConfig()->fbsessiontimeout)) - 60;
     $query = "UPDATE #__kunena_sessions SET readtopics='0' WHERE currvisit<{$this->_db->quote($lasttime)}";
     $this->_db->setQuery($query);
     $this->_db->query();
     $dberror = $this->checkDatabaseError();
     if ($dberror) {
         return $this->setError('-post-', JText::_('COM_KUNENA_POST_ERROR_SESSIONS'));
     }
     // Then look at users who have read the thread
     $thread = $this->get('thread');
     $query = "SELECT userid, readtopics FROM #__kunena_sessions WHERE readtopics LIKE '%{$thread}%' AND userid!={$this->_db->quote($userid)}";
     $this->_db->setQuery($query);
     $sessions = $this->_db->loadObjectList();
     $dberror = $this->checkDatabaseError();
     if ($dberror) {
         return $this->setError('-post-', JText::_('COM_KUNENA_POST_ERROR_SESSIONS'));
     }
     // And clear current thread
     $errcount = 0;
     foreach ($sessions as $session) {
         $readtopics = $session->readtopics;
         $rt = explode(",", $readtopics);
         $key = array_search($thread, $rt);
         if ($key !== false) {
             unset($rt[$key]);
             $readtopics = implode(",", $rt);
             $query = "UPDATE #__kunena_sessions SET readtopics={$this->_db->quote($readtopics)} WHERE userid={$this->_db->quote($session->userid)}";
             $this->_db->setQuery($query);
             $this->_db->query();
             $dberror = $this->checkDatabaseError();
             if ($dberror) {
                 $errcount++;
             }
         }
     }
     if ($errcount) {
         return $this->setError('-post-', JText::_('COM_KUNENA_POST_ERROR_SESSIONS'));
     }
     // Get the event dispatcher
     $dispatcher = JDispatcher::getInstance();
     // Load the JXFinder plug-in group
     JPluginHelper::importPlugin('finder');
     // Fire after post save event
     $dispatcher->trigger('onAfterSaveKunenaPost', array($id));
     // Activity integration
     $activity = KunenaFactory::getActivityIntegration();
     if ($this->parent->thread == 0) {
         $activity->onAfterPost($this);
     } else {
         $activity->onAfterReply($this);
     }
     return $id;
 }
Example #5
0
 protected function approve()
 {
     if ($this->tokenProtection('get')) {
         return false;
     }
     if (!$this->load()) {
         return false;
     }
     if ($this->moderatorProtection()) {
         return false;
     }
     if ($this->isUserBanned()) {
         return false;
     }
     if ($this->isIPBanned()) {
         return false;
     }
     require_once KUNENA_PATH_LIB . '/kunena.posting.class.php';
     $message = new CKunenaPosting();
     $message->action($this->id);
     if ($message->canApprove()) {
         $success_msg = JText::_('COM_KUNENA_MODERATE_1APPROVE_FAIL');
         $this->_db->setQuery("UPDATE #__kunena_messages SET hold=0 WHERE id={$this->_db->Quote($this->id)}");
         if ($this->id && $this->_db->query() && $this->_db->getAffectedRows() == 1) {
             $success_msg = JText::_('COM_KUNENA_MODERATE_APPROVE_SUCCESS');
             $this->_db->setQuery("SELECT COUNT(*) AS totalmessages FROM #__kunena_messages WHERE thread={$this->_db->Quote($this->msg_cat->thread)}");
             $result = $this->_db->loadObject();
             KunenaError::checkDatabaseError();
             $threadPages = ceil($result->totalmessages / $this->config->messages_per_page);
             //construct a useable URL (for plaintext - so no &amp; encoding!)
             jimport('joomla.environment.uri');
             $uri =& JURI::getInstance(JURI::base());
             $LastPostUrl = $uri->toString(array('scheme', 'host', 'port')) . str_replace('&amp;', '&', CKunenaLink::GetThreadPageURL('view', $this->catid, $this->msg_cat->thread, $threadPages, $this->config->messages_per_page, $this->id));
             $message->emailToSubscribers($LastPostUrl, $this->config->allowsubscriptions, $this->config->mailmod, $this->config->mailadmin);
             CKunenaTools::modifyCategoryStats($this->id, $this->msg_cat->parent, $this->msg_cat->time, $this->msg_cat->catid);
         }
     }
     while (@ob_end_clean()) {
     }
     $this->_app->redirect(CKunenaLink::GetMessageURL($this->id, $this->catid, 0, false), $success_msg);
 }
Example #6
0
/**
 * approve selected messages
 * @param object database
 * @param array cid post ids
 */
function jbApprovePosts($kunena_db, $cid)
{
    if (count($cid) == 0) {
        return 0;
    }
    $ret = 1;
    reset($cid);
    foreach ($cid as $id) {
        $id = (int) $id;
        $newQuery = "SELECT * FROM #__fb_messages WHERE id='{$id}'";
        $kunena_db->setQuery($newQuery, 0, 1);
        $msg = null;
        $msg = $kunena_db->loadObject();
        if (!$msg) {
            continue;
        }
        // continue stats
        $kunena_db->setQuery("UPDATE `#__fb_messages` SET hold='0' WHERE id='{$id}'");
        if (!$kunena_db->query()) {
            $ret = 0;
            // mark error
        }
        CKunenaTools::modifyCategoryStats($id, $msg->parent, $msg->time, $msg->catid);
    }
    return $ret;
}