post
[ class tree: post ] [ index: post ] [ all elements ]

Source for file post.inc.php

Documentation is available at post.inc.php

  1. <?php
  2.     /**
  3.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  4.      * @version            $LastChangedDate: 2009-08-26 19:19:41 +0200 (Mi, 26 Aug 2009) $
  5.      * @package            post
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com/examples/post.php
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_post extends ipbwi {
  12.         private $ipbwi            null;
  13.         /**
  14.          * @desc            Loads and checks different vars when class is initiating
  15.          * @author            Matthias Reuter
  16.          * @since            2.0
  17.          * @ignore
  18.          */
  19.         public function __construct($ipbwi){
  20.             // loads common classes
  21.             $this->ipbwi $ipbwi;
  22.         }
  23.         /**
  24.          * @desc            Adds a new post.
  25.          * @param    int        $topicID Topic ID of the Post
  26.          * @param    string    $post Message body
  27.          * @param    bool    $disableemos Default: false = disable emoticons, true = enable
  28.          * @param    bool    $disablesig Default: false = disable signatures, true = enable
  29.          * @param    bool    $bypassPerms Default: false = repect board permission, true = bypass permissions
  30.          * @param    string    $guestname Name for Guest user, Default: false
  31.          * @return    int        New post ID or false on failure
  32.          * @author            Matthias Reuter
  33.          * @sample
  34.          *  <code>
  35.          *  $ipbwi->post->create(55,'[b]post[/b]');
  36.          *  $ipbwi->post->create(77,'[i]post[/i]', true, true, true, 'Mr. Guest');
  37.          *  </code>
  38.          * @since            2.0
  39.          */
  40.         public function create($topicid$post$useEmo false$useSig false$bypassPerms false$guestname false){
  41.             if($this->ipbwi->member->isLoggedIn()){
  42.                 $postname $this->ipbwi->member->myInfo['members_display_name'];
  43.             }elseif($guestname){
  44.                 $postname $this->ipbwi->ips_wrapper->vars['guest_name_pre'].$this->makeSafe($guestname).$this->ipbwi->ips_wrapper->vars['guest_name_suf'];
  45.             }else{
  46.                 $postname $this->ipbwi->member->myInfo['members_display_name'];
  47.             }
  48.             // No Posting
  49.             if($this->ipbwi->member->myInfo['restrict_post']){
  50.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  51.                 return false;
  52.             }
  53.             // Flooding
  54.             if($this->ipbwi->ips_wrapper->vars['flood_control'AND !$this->ipbwi->permissions->has('g_avoid_flood')){
  55.                 if((time($this->ipbwi->member->myInfo['last_post']$this->ipbwi->ips_wrapper->vars['flood_control']){
  56.                     $this->ipbwi->addSystemMessage('Error',sprintf($this->ipbwi->getLibLang('floodControl')$this->ipbwi->ips_wrapper->vars['flood_control']),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  57.                     return false;
  58.                 }
  59.             }
  60.             // Check some Topic Stuff
  61.             $this->ipbwi->ips_wrapper->DB->query('SELECT t.*, f.* FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics t LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'forums f ON (t.forum_id=f.id) WHERE t.tid="'.intval($topicid).'"');
  62.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  63.                 // Check User can Post to Forum
  64.                 if($this->ipbwi->forum->isPostable($row['forum_id']OR $bypassPerms){
  65.                     // Post Queue
  66.                     if($row['preview_posts'OR $this->ipbwi->member->myInfo['mod_posts']){
  67.                         $preview 1;
  68.                     }else{
  69.                         $preview 0;
  70.                     }
  71.                     // What if the topic is locked
  72.                     if($row['state'!= 'open' AND !$this->ipbwi->permissions->has('g_post_closed')){
  73.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  74.                         return false;
  75.                     }
  76.                     // Check they can reply
  77.                     if($row['starter_id'== $this->ipbwi->member->myInfo['member_id'&& !$this->ipbwi->permissions->has('g_reply_own_topics')){
  78.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  79.                         return false;
  80.                     }elseif(!$this->ipbwi->permissions->has('g_reply_other_topics')){
  81.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  82.                         return false;
  83.                     }
  84.                     $time time();
  85.                     // If we're still here, we should be ok to add the post
  86.                     $this->ipbwi->ips_wrapper->parser->parse_bbcode        $row['use_ibc'];
  87.                     $this->ipbwi->ips_wrapper->parser->strip_quotes        1;
  88.                     $this->ipbwi->ips_wrapper->parser->parse_nl2br        1;
  89.                     $this->ipbwi->ips_wrapper->parser->parse_html        0;
  90.                     $this->ipbwi->ips_wrapper->parser->parse_smilies    ($useEmo 0);
  91.                     $post $this->ipbwi->ips_wrapper->parser->preDbParse($post);
  92.                     if($useEmo == 0){
  93.                         $post    $this->ipbwi->bbcode->html2bbcode($post);
  94.                     }
  95.                     $post    $this->ipbwi->makeSafe($post);
  96.                     // POST KEY!
  97.                     $this->ipbwi->ips_wrapper->DB->query('INSERT INTO '.$this->ipbwi->board['sql_tbl_prefix'].'posts (author_id, author_name, use_emo, use_sig, ip_address, post_date, post, queued, topic_id, post_key) VALUES ("'.$this->ipbwi->member->myInfo['member_id'].'", "'.$postname.'", "'.($useEmo 0).'", "'.($useSig 0).'", "'.$_SERVER['REMOTE_ADDR'].'", "'.$time.'", "'.$post.'", "'.$preview.'", "'.$row['tid'].'", "'.md5(microtime()).'")');
  98.                     $postID $this->ipbwi->ips_wrapper->DB->getInsertId();
  99.                     // Update the Topics
  100.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET last_poster_id="'.$this->ipbwi->member->myInfo['member_id'].'", last_poster_name="'.$postname.'", posts=posts+1, last_post="'.$time.'" WHERE tid="'.intval($topicid).'"');
  101.                     // Finally update the forums
  102.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'forums SET last_poster_id="'.$this->ipbwi->member->myInfo['member_id'].'", last_poster_name="'.$postname.'", posts=posts+1, last_post="'.$time.'", last_title="'.addslashes($row['title']).'", last_id="'.intval($topicid).'" WHERE id="'.intval($row['forum_id']).'"');
  103.                     // Oh yes, any update the post count for the user
  104.                     if($this->ipbwi->member->myInfo['member_id'!= '0' && $row['inc_postcount']){
  105.                         $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET posts=posts+1, last_post="'.time().'" WHERE member_id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  106.                     }elseif($this->ipbwi->member->myInfo['member_id'!= '0'){
  107.                         $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET last_post="'.time().'" WHERE member_id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  108.                     }
  109.                     $this->ipbwi->cache->updateForum(intval($row['forum_id']),array('posts' => 1));
  110.                     
  111.                     return $postID;
  112.                 }else{
  113.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  114.                     return false;
  115.                 }
  116.             }else{
  117.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('topicNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  118.                 return false;
  119.             }
  120.         }
  121.         /**
  122.          * @desc            Deletes Topic-Post contains delivered post_id
  123.          * @param    int        $postID ID of the Post
  124.          * @return    bool    true on success, otherwise false
  125.          * @author            Matthias Reuter
  126.          * @sample
  127.          *  <code>
  128.          *  $ipbwi->post->delete(55);
  129.          *  </code>
  130.          * @since            2.0
  131.          */
  132.         public function delete($postID){
  133.             $pInfo $this->info($postID);
  134.             $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'posts WHERE pid = "'.intval($postID).'"');
  135.             // Update the Topics
  136.             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET posts=posts-1 WHERE tid="'.$pInfo['topic_id'].'"');
  137.             // Finally update the forums
  138.             if($this->ipbwi->ips_wrapper->update_forum_cache($pInfo['forum_id'],array('posts' => -1))){
  139.                 return true;
  140.             }else{
  141.                 return false;
  142.             }
  143.         }
  144.         /**
  145.          * @desc            Edits a post (adapted from add_post)
  146.          * @param    int        $postID ID of the Post
  147.          * @param    string    $post Message body
  148.          * @param    bool    $disableemos Default: false = disable emoticons, true = enable
  149.          * @param    bool    $disablesig Default: false = disable signatures, true = enable
  150.          * @param    bool    $bypassPerms Default: false = repect board permission, true=bypass permissions
  151.          * @param    bool    $appendedit Default: true = adds the 'edited' line afer the post, false = doesn't add
  152.          * @return    bool    true on success, false on failure
  153.          * @author            Matthias Reuter
  154.          * @sample
  155.          *  <code>
  156.          *  $ipbwi->post->edit(55,'[b]post[/b]');
  157.          *  $ipbwi->post->edit(77,'[i]post[/i]', true, true, false, true);
  158.          *  </code>
  159.          * @since            2.0
  160.          */
  161.         public function edit($postID$post$useEmo false$useSig false$bypassPerms false$appendedit true){
  162.             if(!$this->ipbwi->member->isLoggedIn()){
  163.                 // Oh dear... not sure you can go around having guests editing posts...
  164.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  165.                 return false;
  166.             }
  167.             // No Posting
  168.             if($this->ipbwi->member->myInfo['restrict_post']){
  169.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  170.                 return false;
  171.             }
  172.             // Flooding
  173.             if($this->ipbwi->ips_wrapper->vars['flood_control'AND !$this->ipbwi->permissions->has('g_avoid_flood'&& ((time($this->ipbwi->member->myInfo['last_post']$this->ipbwi->ips_wrapper->vars['flood_control'])){
  174.                 $this->ipbwi->addSystemMessage('Error',sprintf($this->ipbwi->getLibLang('floodControl')$this->ips->vars['flood_control']),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  175.                 return false;
  176.             }
  177.             // Check some Topic Stuff
  178.             $this->ipbwi->ips_wrapper->DB->query('SELECT  f.*,p.*,t.* FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics t LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'forums f ON (t.forum_id=f.id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'posts p ON(p.topic_id=t.tid) WHERE p.pid="'.intval($postID).'"');
  179.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  180.                 // Check User can Post to Forum
  181.                 if($this->ipbwi->forum->isPostable($row['forum_id']OR $bypassPerms){
  182.                     // Post Queue
  183.                     if($row['preview_posts'OR $this->ipbwi->member->myInfo['mod_posts']){
  184.                         $preview 1;
  185.                     }else{
  186.                         $preview 0;
  187.                     }
  188.                     // What if the topic is locked
  189.                     if($row['state'!= 'open' AND !$this->ipbwi->permissions->has('g_post_closed')){
  190.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  191.                         return false;
  192.                     }
  193.                     // Check they can edit posts
  194.                     if($row['author_id'== $this->ipbwi->member->myInfo['member_id'&& !$this->ipbwi->permissions->has('g_edit_posts')){
  195.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  196.                         return false;
  197.                     }elseif($row['author_id'!= $this->ipbwi->member->myInfo['member_id'&& !$this->ipbwi->permissions->has('g_is_supmod')){
  198.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  199.                         return false;
  200.                     }
  201.                     // Append_Edit?
  202.                     if(!$bypassPerms && !$appendedit){
  203.                         $appendedit $this->ipbwi->permissions->has('g_append_edit'1;
  204.                     }
  205.                     $time time();
  206.                     $this->ipbwi->ips_wrapper->parser->parse_bbcode        $row['use_ibc'];
  207.                     $this->ipbwi->ips_wrapper->parser->strip_quotes        1;
  208.                     $this->ipbwi->ips_wrapper->parser->parse_nl2br        0;
  209.                     $this->ipbwi->ips_wrapper->parser->parse_html        0;
  210.                     $this->ipbwi->ips_wrapper->parser->parse_smilies    ($useEmo 0);
  211.                     $post $this->ipbwi->ips_wrapper->parser->preDbParse($post);
  212.                     if($useEmo == 0){
  213.                         $post    $this->ipbwi->bbcode->html2bbcode($post);
  214.                     }
  215.                     $post    $this->ipbwi->makeSafe($post);
  216.                     // updatepost
  217.                     $this->ipbwi->ips_wrapper->DB->query('REPLACE INTO '.$this->ipbwi->board['sql_tbl_prefix'].'posts (pid, author_id, author_name, use_emo, use_sig, ip_address, edit_time, post, queued, topic_id, append_edit, edit_name, post_date,post_parent,post_key,post_htmlstate,new_topic,icon_id) VALUES ("'.$row['pid'].'", "'.$row['author_id'].'", "'.$row['author_name'].'", "'.($useEmo 0).'", "'.($useSig 0).'", "'.$_SERVER['REMOTE_ADDR'].'", "'.$time.'", "'.$post.'", "'.$preview.'", "'.$row['tid'].'", "'.$appendedit.'", "'.$this->ipbwi->member->myInfo['name'].'", "'.$row['post_date'].'", "'.$row['post_parent'].'", "'.$row['post_key'].'", 0, "'.$row['new_topic'].'", "'.$row['icon_id'].'")');
  218.                     // update cache
  219.                     $this->ipbwi->ips_wrapper->DB->query('REPLACE INTO '.$this->ipbwi->board['sql_tbl_prefix'].'content_cache_posts (cache_content_id, cache_content, cache_updated) VALUES ("'.$row['pid'].'", "'.$post.'", "'.time().'")');
  220.                     
  221.                     return true;
  222.                 }else{
  223.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  224.                     return false;
  225.                 }
  226.             }else{
  227.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('postNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  228.                 return false;
  229.             }
  230.         }
  231.         /**
  232.          * @desc            Returns information on a post.
  233.          * @param    int        $postID ID of the Post
  234.          * @param    bool    $replacePostVars replace attachment post vars with attachment-code, default: true
  235.          * @param    string    $ipbwiLink If you want to use IPBWI for attachment-downloading, you are able to define the attachment-link here. The var %id% is required and will be replaced with the attachment-ID.
  236.          * @return    array    Post Information
  237.          * @author            Matthias Reuter
  238.          * @sample
  239.          *  <code>
  240.          *  $ipbwi->post->info(55);
  241.          *  </code>
  242.          * @since            2.0
  243.          */
  244.         public function info($postID$replacePostVars true$ipbwiLink false$list false){
  245.             if(isset($list['sql'])){
  246.                 // allow SUB SELECT query joins
  247.                 $this->ipbwi->ips_wrapper->DB->allow_sub_select=1;
  248.                 
  249.                 // query list
  250.                 $query $list['sql'];
  251.             }else{
  252.                 // Check for Post Cache
  253.                 if($cache $this->ipbwi->cache->get('postInfo'$postID)){
  254.                     return $cache;
  255.                 }else{
  256.                     // query single topic
  257.                     $query 'SELECT m.*, p.*, t.forum_id, t.title AS topic_name, g.g_dohtml AS usedohtml FROM '.$this->ipbwi->board['sql_tbl_prefix'].'posts p LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'topics t ON (p.topic_id=t.tid) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'members m ON (p.author_id=m.member_id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'groups g ON (m.member_group_id=g.g_id) WHERE p.pid="'.intval($postID).'"';
  258.                 }
  259.             }
  260.             $sql $this->ipbwi->ips_wrapper->DB->query($query);
  261.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($sql== 0){
  262.                 return false;
  263.             }
  264.             while($row $this->ipbwi->ips_wrapper->DB->fetch($sql)){
  265.                 // remember first array entry
  266.                 if(empty($firstEntry)){
  267.                     $firstEntry $row['pid'];
  268.                 }
  269.                 
  270.                 $this->ipbwi->ips_wrapper->parser->parse_smilies            $row['use_emo'];
  271.                 $this->ipbwi->ips_wrapper->parser->parse_html                0;
  272.                 $this->ipbwi->ips_wrapper->parser->parse_nl2br                1;
  273.                 $this->ipbwi->ips_wrapper->parser->parse_bbcode                $row['use_ibc'];
  274.                 $this->ipbwi->ips_wrapper->parser->parsing_section            'topics';
  275.                 $this->ipbwi->ips_wrapper->parser->parsing_mgroup            $row['member_group_id'];
  276.                 $this->ipbwi->ips_wrapper->parser->parsing_mgroup_others    $row['mgroup_others'];
  277.                 
  278.                 // make proper XHTML
  279.                 $post[$row['pid']]                                        $row;
  280.                 $post[$row['pid']]['post']                                $this->ipbwi->properXHTML($this->ipbwi->ips_wrapper->parser->preDisplayParse($post[$row['pid']]['post']));
  281.                 $post[$row['pid']]['post_title']                        $this->ipbwi->properXHTML($post[$row['pid']]['post_title']);
  282.                 $post[$row['pid']]['topic_name']                        $this->ipbwi->properXHTML($post[$row['pid']]['topic_name']);
  283.                 $post[$row['pid']]['post_edit_reason']                    $this->ipbwi->properXHTML($post[$row['pid']]['post_edit_reason']);
  284.                 $post[$row['pid']]['author_name']                        $this->ipbwi->properXHTML($post[$row['pid']]['author_name']);
  285.  
  286.                 // replace attachment post vars with attachment-code
  287.                 if($replacePostVars === true){
  288.                     $attachInfo $this->ipbwi->attachment->getList($row['pid'],array('type' => 'post''ipbwiLink' => $ipbwiLink));
  289.                     if(is_array($attachInfo&& count($attachInfo0){
  290.                         foreach($attachInfo as $attachList){
  291.                             if(strpos($post[$row['pid']]['post'],'[attachment='.$attachList['attach_id'].':'!= false){
  292.                                 $post[$row['pid']]['AttachmentNotInlineInfo'][$attachList['attach_id']] $this->ipbwi->attachment->info($attachList['attach_id'],array('ipbwiLink' => $ipbwiLink));
  293.                             }
  294.                         }
  295.                         if(isset($attachInfo['defaultHTML'])){
  296.                             $post[$row['pid']]['post'preg_replace('/\[attachment=([!0-9]*):([!a-zA-Z0-9_\-.]*)\]/smeU','$attachInfo["defaultHTML"]',$post[$row['pid']]['post']);
  297.                         }else{
  298.                             $post[$row['pid']]['post'preg_replace('/\[attachment=([!0-9]*):([!a-zA-Z0-9_\-.]*)\]/smeU','$attachInfo["\1"]["defaultHTML"]',$post[$row['pid']]['post']);
  299.                         }
  300.                     }
  301.                 }
  302.                 // Save Post  In Cache and Return
  303.                 $this->ipbwi->cache->save('postInfo'$postID$row);
  304.             }
  305.             if(isset($list['sql'])){
  306.                 return $post;
  307.             }else{
  308.                 return $post[$firstEntry];
  309.             }
  310.             
  311.         }
  312.         /**
  313.          * @desc            array with post IDs of the given Topics
  314.          * @param    int        $topicIDs The topic IDs where the post IDs should be retrieved from
  315.          * @return    array    Post IDs
  316.          * @author            Matthias Reuter
  317.          * @sample
  318.          *  <code>
  319.          *  $ipbwi->post->getListIDs(array(55,22,77,99));
  320.          *  </code>
  321.          * @since            2.0
  322.          */
  323.         public function getListIDs($topicIDs){
  324.             // posts
  325.             if(is_array($topicIDs)){
  326.                 $topics '';
  327.                 foreach($topicIDs as $topicID){
  328.                     if($topics){
  329.                         $topics .= '" OR "'.intval($topicID).'"';
  330.                     }else{
  331.                         $topics '"'.intval($topicID).'"';
  332.                     }
  333.                 }
  334.             }else{
  335.                 $topics '"'.$topicIDs.'"';
  336.             }
  337.             $query $this->ipbwi->ips_wrapper->DB->query('SELECT pid FROM '.$this->ipbwi->board['sql_tbl_prefix'].'posts WHERE (topic_id = '.$topics.')');
  338.             if($this->ipbwi->ips_wrapper->DB->getTotalRows(== 0){
  339.                 return false;
  340.             }
  341.             while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  342.                 $postIDs[$row['pid'];
  343.             }
  344.             return $postIDs;
  345.         }
  346.         /**
  347.          * @desc            Lists posts in a topic.
  348.          * @param    mixed    $topicID The topic ID (array-list, int or '*' for all board topics)
  349.          * @param    array    $settings optional query settings. Settings allowed: order, orderby limit and start
  350.          *  + string order = ASC or DESC, default ASC
  351.          *  + string orderby = pid, author_id, author_name, post_date, post or random. Default: post_date
  352.          *  + int start = Default: 0
  353.          *  + int limit = Default: 15
  354.          *  + bool replacePostVars replace attachment post vars with attachment-code, default: true
  355.          *  + string ipbwiLink If you want to use IPBWI for attachment-downloading, you are able to define the attachment-link here. The var %id% is required and will be replaced with the attachment-ID.
  356.          * @param    bool    $bypassPerms Default: false = respect board permission, true = bypass permissions
  357.          * @param    bool    $countView Default: false = do not add view count, true = add the view count
  358.          * @return    array    Topic Posts
  359.          * @author            Matthias Reuter
  360.          * @sample
  361.          *  <code>
  362.          *  $ipbwi->post->getList(55);
  363.          *  $ipbwi->post->getList(array(55,22,77,99));
  364.          *  $ipbwi->post->getList('*');
  365.          *  $ipbwi->post->getList(55,array('order' => 'DESC', 'orderby' => 'pid', 'start' => 10, 'limit' => 20),true,true);
  366.          *  </code>
  367.          * @since            2.0
  368.          */
  369.         public function getList($topicID$settings array()$bypassPerms false$countView false){
  370.             if(empty($settings['order'])){
  371.                 $settings['order''asc';
  372.             }else{
  373.                 $settings['order'strtolower($settings['order']);
  374.             }
  375.             if(empty($settings['limit'])){
  376.                 $settings['limit'15;
  377.             }
  378.             if(empty($settings['start'])){
  379.                 $settings['start'0;
  380.             }
  381.             if(empty($settings['orderby'])){
  382.                 $settings['orderby''post_date';
  383.             }
  384.             if(empty($settings['memberid'])){
  385.                 $settings['memberid'false;
  386.             }
  387.             if(empty($settings['replacePostVars'])){
  388.                 $settings['replacePostVars'true;
  389.             }
  390.             if(empty($settings['ipbwiLink'])){
  391.                 $settings['ipbwiLink'false;
  392.             }
  393.             
  394.             // get data from a specific user
  395.             if($settings['memberid']){
  396.                 $specificMember 'p.author_id = "'.intval($settings['memberid']).'" AND ';
  397.             }else{
  398.                 $specificMember false;
  399.             }
  400.             $sqlwhere '';
  401.             if(is_array($topicID)){
  402.                 // get_topic_info() is too inefficent when we have alot of topic ids.
  403.                 $topics '';
  404.                 foreach($topicID as $i){
  405.                     $i intval($i);
  406.                     if($topics){
  407.                         $topics .= ' OR tid="'.$i.'"';
  408.                     }else{
  409.                         $topics ' tid="'.$i.'"';
  410.                     }
  411.                 }
  412.                 // Query
  413.                 $getfid $this->ipbwi->ips_wrapper->DB->query('SELECT tid, forum_id FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics WHERE '.$topics);
  414.                 // Now we should how topic ids and their forum ids.
  415.                 while($row $this->ipbwi->ips_wrapper->DB->fetch($getfid)){
  416.                     if($this->ipbwi->forum->isReadable($row['forum_id']OR $bypassPerms){
  417.                         if(!$sqlwhere){
  418.                             $sqlwhere .= '(topic_id="'$row['tid'].'"';
  419.                         }else{
  420.                             $sqlwhere .= ' OR topic_id="'.$row['tid'].'"';
  421.                         }
  422.                     }
  423.                 }
  424.                 if($sqlwhere){
  425.                     $sqlwhere .= ') AND ';
  426.                     $cando 1;
  427.                 }else{
  428.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  429.                     return false;
  430.                 }
  431.             }elseif($topicID == '*'){
  432.                 if($bypassPerms){
  433.                     // Grab posts from the whole board
  434.                     $sqlwhere false;
  435.                     $cando 1;
  436.                 }else{
  437.                     // All topics. So we can grab them from all readable forums.
  438.                     $readable $this->ipbwi->forum->getReadable();
  439.                     foreach($readable as $j => $k){
  440.                         if(!$sqlwhere){
  441.                             $sqlwhere .= '(forum_id="'.$j.'"';
  442.                         }else{
  443.                             $sqlwhere .= ' OR forum_id="'.$j.'"';
  444.                         }
  445.                     }
  446.                     if($sqlwhere OR isset($cando)){
  447.                         $sqlwhere .= ') AND ';
  448.                         $cando 1;
  449.                     }else{
  450.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  451.                         return false;
  452.                     }
  453.                 }
  454.             }else{
  455.                 // Classic Posts from Topic Export
  456.                 // Grab Topic Info then check whether forum is readable.
  457.                 $topicinfo $this->ipbwi->topic->info($topicID,$countView);
  458.                 if($this->ipbwi->forum->isReadable($topicinfo['forum_id']OR $bypassPerms){
  459.                     $sqlwhere 'topic_id="'.intval($topicID).'" AND ';
  460.                     $cando 1;
  461.                 }else{
  462.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  463.                     return false;
  464.                 }
  465.             }
  466.             if($cando){
  467.                 // What shall I order it by guv?
  468.                 $allowedorder array('pid''author_id''author_name''post_date''post');
  469.                 if(in_array($settings['orderby']$allowedorder)){
  470.                     $order $settings['orderby'].' '.(($settings['order'== 'desc''DESC' 'ASC');
  471.                 }elseif($settings['orderby'== 'random'){
  472.                     $order 'RAND()';
  473.                 }else{
  474.                     $order 'post_date '.(($settings['order'== 'desc''DESC' 'ASC');
  475.                 }
  476.                 // Grab Posts
  477.                 $limit $settings['limit'intval($settings['limit']15;
  478.                 $start $settings['start'intval($settings['start']0;
  479.                 
  480.                 $query 'SELECT m.*, p.*, t.forum_id, t.title AS topic_name, g.g_dohtml AS usedohtml FROM '.$this->ipbwi->board['sql_tbl_prefix'].'posts p LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'members m ON (p.author_id=m.member_id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'groups g ON (m.member_group_id=g.g_id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'topics t ON(p.topic_id=t.tid) WHERE p.pid != topic_firstpost AND '.$specificMember.$sqlwhere.'p.queued="0" ORDER BY '.$order.' LIMIT '.$start.','.$limit;
  481.                 return $this->info(false$settings['replacePostVars']$settings['ipbwiLink']array('sql' => $query));
  482.             }else{
  483.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('noPerms'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  484.                 return false;
  485.             }
  486.         }
  487.     }
  488. ?>

Documentation generated on Sat, 23 Oct 2010 23:36:09 +0200 by phpDocumentor 1.4.3