Example #1
0
function ipb_make_post($forum_id, $forum_subj, $forum_post, $poster_id = 0, $update_old_topic = true)
{
    global $ipb_prefix, $THIS_BASEPATH, $btit_settings, $registry, $DBDT;
    if ($poster_id == 0) {
        if (isset($btit_settings["ipb_autoposter"]) && $btit_settings["ipb_autoposter"] != 0) {
            $poster_id = (int) (0 + $btit_settings["ipb_autoposter"]);
        } else {
            return;
        }
    }
    if (!isset($THIS_BASEPATH) || empty($THIS_BASEPATH)) {
        $THIS_BASEPATH = str_replace(array("\\", "/include"), array("/", ""), dirname(__FILE__));
    }
    if (!defined('IPS_ENFORCE_ACCESS')) {
        define('IPS_ENFORCE_ACCESS', true);
    }
    if (!defined('IPB_THIS_SCRIPT')) {
        define('IPB_THIS_SCRIPT', 'public');
    }
    if (!isset($registry) || empty($registry)) {
        require_once $THIS_BASEPATH . '/ipb/initdata.php';
        require_once IPS_ROOT_PATH . 'sources/base/ipsRegistry.php';
        require_once IPS_ROOT_PATH . 'sources/base/ipsController.php';
        $registry = ipsRegistry::instance();
        $registry->init();
    }
    require_once IPSLib::getAppDir('forums') . '/sources/classes/post/classPost.php';
    $classPost = new classPost($registry);
    $old_topic = false;
    $clean_subj = trim($forum_subj, "'");
    $clean_post = trim($forum_post, "'");
    $forum = ipsRegistry::getClass('class_forums')->forum_by_id[$forum_id];
    $classPost->setForumID($forum_id);
    $classPost->setForumData($forum);
    $classPost->setAuthor($poster_id);
    $classPost->setPostContentPreFormatted($clean_post);
    $classPost->setPublished(TRUE);
    if ($update_old_topic === false) {
        $mycount = 0;
    } else {
        $res = get_result("SELECT `t`.* FROM `{$ipb_prefix}topics` `t` LEFT JOIN `{$ipb_prefix}posts` `p` ON `t`.`tid`=`p`.`topic_id` WHERE `t`.`forum_id`=" . $forum_id . " AND `t`.`title`='" . mysqli_real_escape_string($DBDT, $clean_subj) . "' AND `t`.`last_post`=`p`.`post_date` AND `t`.`last_poster_id`=`p`.`author_id`");
        $mycount = count($res);
    }
    if ($mycount > 0) {
        $topic = $res[0];
        $topicID = $topic["tid"];
        $classPost->setTopicID($topicID);
        $classPost->setTopicData($topic);
        $classPost->addReply();
    } else {
        $topic = get_result("SELECT MAX(`tid`)+1 `tid` FROM `{$ipb_prefix}topics`");
        $topicID = $topic[0]["tid"];
        $classPost->setTopicID($topicID);
        $classPost->setTopicTitle($clean_subj);
        $classPost->addTopic();
    }
    return $topicID;
}
 /**
  * Posts a topic reply
  * 
  * @access	public
  * @param	string  $api_key		Authentication Key
  * @param	string  $api_module		Module
  * @param	string	$member_field	Member field to check (valid: "id", "email", "username", "displayname")
  * @param	string	$member_key		Member key to check for
  * @param	integer	$topic_id		Topic id to post in
  * @param	string	$post_content	Posted content
  * @return	string	xml
  */
 public function postReply($api_key, $api_module, $member_field, $member_key, $topic_id, $post_content)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $api_key = IPSText::md5Clean($api_key);
     $api_module = IPSText::parseCleanValue($api_module);
     $member_field = IPSText::parseCleanValue($member_field);
     $member_key = IPSText::parseCleanValue($member_key);
     $topic_id = intval($topic_id);
     $UNCLEANED_post_content = $post_content;
     //-----------------------------------------
     // Authenticate
     //-----------------------------------------
     if ($this->__authenticate($api_key, $api_module, 'postReply') !== FALSE) {
         //-----------------------------------------
         // Add log
         //-----------------------------------------
         if (ipsRegistry::$settings['xmlrpc_log_type'] != 'failed') {
             $this->registry->DB()->insert('api_log', array('api_log_key' => $api_key, 'api_log_ip' => $_SERVER['REMOTE_ADDR'], 'api_log_date' => time(), 'api_log_query' => $this->classApiServer->raw_request, 'api_log_allowed' => 1));
         }
         //-----------------------------------------
         // Member field...
         //-----------------------------------------
         $member = IPSMember::load($member_key, 'all', $member_field);
         //-----------------------------------------
         // Got a member?
         //-----------------------------------------
         if (!$member['member_id']) {
             $this->classApiServer->apiSendError('10', "IP.Board could not locate a member using {$member_key} / {$member_field}");
         }
         //-----------------------------------------
         // Get some classes
         //-----------------------------------------
         require_once IPSLib::getAppDir('forums') . '/app_class_forums.php';
         $appClass = new app_class_forums($this->registry);
         require_once IPSLib::getAppDir('forums') . '/sources/classes/post/classPost.php';
         $_postClass = new classPost($this->registry);
         //-----------------------------------------
         // Need the topic...
         //-----------------------------------------
         $topic = $this->registry->DB()->buildAndFetch(array('select' => '*', 'from' => 'topics', 'where' => 'tid=' . $topic_id));
         //-----------------------------------------
         // Set the data
         //-----------------------------------------
         $_postClass->setIsPreview(false);
         $_postClass->setForumData($this->registry->getClass('class_forums')->forum_by_id[$topic['forum_id']]);
         $_postClass->setForumID($topic['forum_id']);
         $_postClass->setTopicID($topic_id);
         $_postClass->setTopicData($topic);
         $_postClass->setPostContent($UNCLEANED_post_content);
         $_postClass->setAuthor($member['member_id']);
         $_postClass->setPublished(true);
         $_postClass->setSettings(array('enableSignature' => 1, 'enableEmoticons' => 1, 'post_htmlstatus' => 0, 'enableTracker' => 0));
         /**
          * And post it...
          */
         try {
             if ($_postClass->addReply() === FALSE) {
                 //print $_postClass->_postErrors;
                 $this->classApiServer->apiSendError('10', "IP.Board could not add the reply " . $_postClass->_postErrors);
             }
         } catch (Exception $error) {
             $this->classApiServer->apiSendError('10', "IP.Board post class exception: " . $error->getMessage());
         }
         $this->classApiServer->apiSendReply(array('result' => 'success'));
         exit;
     }
 }
 /**
  * Magic __call method
  *
  * @access	public
  * @param	object	ipsRegistry reference
  * @return void
  */
 public function __call($method, $arguments)
 {
     return parent::__call($method, $arguments);
 }
 /**
  * Bulk remove attachments
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _bulkRemoveAttachments()
 {
     foreach ($_POST as $key => $value) {
         if (preg_match("/^attach_(\\d+)\$/", $key, $match)) {
             if ($this->request[$match[0]]) {
                 $ids[] = $match[1];
             }
         }
     }
     $ids = IPSLib::cleanIntArray($ids);
     $attach_tid = array();
     if (count($ids)) {
         //-----------------------------------------
         // Get attach details?
         //-----------------------------------------
         $this->DB->build(array('select' => 'a.*', 'from' => array('attachments' => 'a'), 'where' => "a.attach_rel_id > 0 AND a.attach_id IN(" . implode(",", $ids) . ")", 'add_join' => array(array('select' => 'p.pid, p.topic_id', 'from' => array('posts' => 'p'), 'where' => "p.pid=a.attach_rel_id AND attach_rel_module='post'", 'type' => 'left'))));
         $this->DB->execute();
         while ($killmeh = $this->DB->fetch()) {
             if ($killmeh['attach_location']) {
                 @unlink($this->settings['upload_dir'] . "/" . $killmeh['attach_location']);
             }
             if ($killmeh['attach_thumb_location']) {
                 @unlink($this->settings['upload_dir'] . "/" . $killmeh['attach_thumb_location']);
             }
             $attach_tid[$killmeh['topic_id']] = $killmeh['topic_id'];
         }
         $this->DB->delete('attachments', "attach_id IN(" . implode(",", $ids) . ")");
         $this->registry->adminFunctions->saveAdminLog(sprintf($this->lang->words['deleted_attachments'], implode(",", $ids)));
         //-----------------------------------------
         // Recount topic upload marker
         //-----------------------------------------
         require_once IPSLib::getAppDir('forums') . '/sources/classes/post/classPost.php';
         $postlib = new classPost($this->registry);
         foreach ($attach_tid as $tid) {
             if ($tid) {
                 $postlib->recountTopicAttachments($tid);
             }
         }
         $this->registry->output->global_message = $this->lang->words['attachments_removed'];
     } else {
         $this->registry->output->global_message = $this->lang->words['noattach_to_remove'];
     }
     if ($this->request['return'] == 'stats') {
         $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . 'module=attachments&section=stats');
     } else {
         if ($_POST['url']) {
             foreach (explode('&', $_POST['url']) as $u) {
                 list($k, $v) = explode('=', $u);
                 $this->request[$k] = $v;
             }
         }
         $this->_searchResults();
     }
 }