Esempio n. 1
0
 function fbDeletePosts($isMod, $return)
 {
     $app =& JFactory::getApplication();
     $backUrl = $app->getUserState("com_kunena.ActionBulk");
     $kunena_my =& JFactory::getUser();
     $kunena_db =& JFactory::getDBO();
     if (!CKunenaTools::isModOrAdmin() && !$isMod) {
         $app->redirect($return, _POST_NOT_MODERATOR);
     }
     $items = fbGetArrayInts("fbDelete");
     $dellattach = 1;
     // start iterating here
     foreach ($items as $id => $value) {
         $kunena_db->setQuery("SELECT id, catid, parent, thread, subject, userid FROM #__fb_messages WHERE id='{$id}'");
         if (!$kunena_db->query()) {
             return -2;
         }
         $mes = $kunena_db->loadObject();
         $thread = $mes->thread;
         if ($mes->parent == 0) {
             // this is the forum topic; if removed, all children must be removed as well.
             $children = array();
             $userids = array();
             $kunena_db->setQuery("SELECT userid, id, catid FROM #__fb_messages WHERE thread='{$id}' OR id='{$id}'");
             foreach ($kunena_db->loadObjectList() as $line) {
                 $children[] = $line->id;
                 if ($line->userid > 0) {
                     $userids[] = $line->userid;
                 }
             }
             $children = implode(',', $children);
         } else {
             //this is not the forum topic, so delete it and promote the direct children one level up in the hierarchy
             $kunena_db->setQuery('UPDATE #__fb_messages SET parent=\'' . $mes->parent . '\' WHERE parent=\'' . $id . '\'');
             if (!$kunena_db->query()) {
                 return -1;
             }
             $children = $id;
             $userids = $mes->userid > 0 ? $mes->userid : '';
         }
         //Delete the post (and it's children when it's the first post)
         $kunena_db->setQuery('DELETE FROM #__fb_messages WHERE id=' . $id . ' OR thread=' . $id);
         if (!$kunena_db->query()) {
             return -2;
         }
         // now update stats
         CKunenaTools::decreaseCategoryStats($id, $mes->catid);
         //Delete message text(s)
         $kunena_db->setQuery('DELETE FROM #__fb_messages_text WHERE mesid IN (' . $children . ')');
         if (!$kunena_db->query()) {
             return -3;
         }
         //Update user post stats
         if (count($userids) > 0) {
             $userids = implode(',', $userids);
             $kunena_db->setQuery('UPDATE #__fb_users SET posts=posts-1 WHERE userid IN (' . $userids . ')');
             if (!$kunena_db->query()) {
                 return -4;
             }
         }
         //Delete (possible) ghost post
         $kunena_db->setQuery("SELECT mesid FROM #__fb_messages_text WHERE message='catid={$mes->catid}&id={$id}'");
         $int_ghost_id = $kunena_db->loadResult();
         if ($int_ghost_id > 0) {
             $kunena_db->setQuery('DELETE FROM #__fb_messages WHERE id=' . $int_ghost_id);
             $kunena_db->query();
             $kunena_db->setQuery('DELETE FROM #__fb_messages_text WHERE mesid=' . $int_ghost_id);
             $kunena_db->query();
         }
         //Delete attachments
         if ($dellattach) {
             $kunena_db->setQuery("SELECT filelocation FROM #__fb_attachments WHERE mesid IN ({$children})");
             $fileList = $kunena_db->loadObjectList();
             check_dberror("Unable to load attachments.");
             if (count($fileList) > 0) {
                 foreach ($fileList as $fl) {
                     unlink($fl->filelocation);
                 }
                 $kunena_db->setQuery('DELETE FROM #__fb_attachments WHERE mesid IN (' . $children . ')');
                 $kunena_db->query();
             }
         }
     }
     //end foreach
     CKunenaTools::reCountBoards();
     $app->redirect($return, _KUNENA_BULKMSG_DELETED);
 }