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

Source for file topic.inc.php

Documentation is available at topic.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            topic
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com/examples/topic.php
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_topic 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            creates a new topic
  25.          * @param    int        $forumID Forum-ID where topic will be created
  26.          * @param    string    $title Topic-Title
  27.          * @param    string    $post Topic-Post
  28.          * @param    string    $desc Topic-Description
  29.          * @param    bool    $useEmo set to true to enable emoticons in post
  30.          * @param    bool    $useSig set to true to enable signature in post
  31.          * @param    bool    $bypassPerms set to true to bypass permissions
  32.          * @param    string    $guestName Author's name for Guest
  33.          * @return    int        topic ID if topic was created, otherwise false
  34.          * @author            Matthias Reuter
  35.          * @sample
  36.          *  <code>
  37.          *  $ipbwi->topic->create(55,'topic title','topic post');
  38.          *  $ipbwi->topic->create(55,'topic title','topic post','topic description',false,false,true,true);
  39.          *  </code>
  40.          * @since            2.0
  41.          */
  42.         public function create($forumID,$title,$post,$desc=false,$useEmo=true,$useSig=true,$bypassPerms=false,$guestName=false){
  43.             if(!$title){
  44.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('topicNoTitle'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  45.                 return false;
  46.             }
  47.             if($this->ipbwi->member->isLoggedIn()){
  48.                 $postName $this->ipbwi->member->myInfo['members_display_name'];
  49.             }else{
  50.                 if($guestName){
  51.                     $postName $this->ipbwi->ips_wrapper->vars['guest_name_pre'].$guestName.$this->ipbwi->ips_wrapper->vars['guest_name_suf'];
  52.                 }else{
  53.                     $postName $this->ipbwi->member->myInfo['members_display_name'];
  54.                 }
  55.             }
  56.             // No Posting
  57.             if($this->ipbwi->member->myInfo['restrict_post']){
  58.                 $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>');
  59.                 return false;
  60.             }
  61.             // Flooding
  62.             if($this->ipbwi->ips_wrapper->vars['flood_control'AND !$this->ipbwi->permissions->has('g_avoid_flood')){
  63.                 if((time($this->ipbwi->member->myInfo['last_post']$this->ipbwi->ips_wrapper->vars['flood_control']){
  64.                     $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>');
  65.                     return false;
  66.                 }
  67.             }
  68.             // Check some Forum Stuff
  69.             $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'forums WHERE id="'.intval($forumID).'"');
  70.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  71.                 // Check User can Post to Forum
  72.                 if($this->ipbwi->forum->isStartable($row['id']OR $bypassPerms){
  73.                     // Queuing
  74.                     if(!$this->ipbwi->permissions->has('g_avoid_q'&& ($row['preview_posts'== OR $row['preview_posts'== OR $this->ipbwi->member->myInfo['mod_posts'])){
  75.                         $preview 1;
  76.                     }else{
  77.                         $preview 0;
  78.                     }
  79.                     $time time();
  80.                     // Insert Topic Bopic
  81.                     $this->ipbwi->ips_wrapper->DB->query('INSERT INTO '.$this->ipbwi->board['sql_tbl_prefix'].'topics (title, description, state, posts, starter_id, start_date, last_poster_id, last_post, starter_name, last_poster_name, views, forum_id, approved, author_mode, pinned) VALUES ("'.$title.'", "'.$desc.'", "open", "0", "'.$this->ipbwi->member->myInfo['member_id'].'", "'.$time.'", "'.$this->ipbwi->member->myInfo['member_id'].'", "'.$time.'", "'.$postName.'", "'.$postName.'", "0", "'.$forumID.'", "'.($preview '0' '1').'", "1", "0")');
  82.                     $topicID $this->ipbwi->ips_wrapper->DB->getInsertId();
  83.                     $this->ipbwi->ips_wrapper->parser->parse_bbcode        $row['use_ibc'];
  84.                     $this->ipbwi->ips_wrapper->parser->strip_quotes        1;
  85.                     $this->ipbwi->ips_wrapper->parser->parse_nl2br        1;
  86.                     $this->ipbwi->ips_wrapper->parser->parse_html        0;
  87.                     $this->ipbwi->ips_wrapper->parser->parse_smilies    ($useEmo 0);
  88.                     $post    $this->ipbwi->ips_wrapper->parser->preDbParse($post);
  89.                     if($useEmo == 0){
  90.                         $post    $this->ipbwi->bbcode->html2bbcode($post);
  91.                     }
  92.                     $post    $this->ipbwi->makeSafe($post);
  93.                     $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, new_topic, icon_id, post_htmlstate) VALUES ("'.$this->ipbwi->member->myInfo['member_id'].'", "'.$postName.'", "'.($useEmo 0).'", "'.($useSig 0).'", "'.$_SERVER['REMOTE_ADDR'].'", "'.$time.'", "'.$post.'", "0", "'.$topicID.'", "1", "0", "'.$this->ipbwi->ips_wrapper->parser->parse_html.'")');
  94.                     // Finally update the forums
  95.                     $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.'", topics=topics+1, last_post="'.$time.'", last_title="'.$title.'", last_id="'.$topicID.'" WHERE id="'.intval($forumID).'"');
  96.                     // Oh yes, any update the post count for the user
  97.                     if($this->ipbwi->member->myInfo['member_id'!= 0){
  98.                         if($row['inc_postcount']){
  99.                             $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');
  100.                         }else{
  101.                             $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');
  102.                         }
  103.                     }
  104.                     // And stats
  105.                     $this->ipbwi->cache->updateForum(intval($forumID),array('topics' => 1));
  106.                     return $topicID;
  107.                 }else{
  108.                     $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>');
  109.                     return false;
  110.                 }
  111.             }else{
  112.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('forumNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  113.                 return false;
  114.             }
  115.         }
  116.         /**
  117.          * @desc            edits a topic
  118.          * @param    int        $topicID Topic-ID which has to be edited
  119.          * @param    string    $title Topic-Title
  120.          * @param    string    $post Topic-Post
  121.          * @param    string    $desc Topic-Description
  122.          * @param    string    $reason reason for editing
  123.          * @param    bool    $close Close the topic
  124.          * @param    bool    $pin Pin the topic
  125.          * @param    bool    $approve Make the topic approved or not
  126.          * @param    bool    $useEmo set to true to enable emoticons in post
  127.          * @param    bool    $useSig set to true to enable signature in post
  128.          * @param    bool    $bypassPerms set to true to bypass permissions
  129.          * @return    bool    true on success, otherwise false
  130.          * @author            Matthias Reuter
  131.          * @sample
  132.          *  <code>
  133.          *  $ipbwi->topic->edit(55,'topic title','topic post');
  134.          *  $ipbwi->topic->edit(55,'topic title','topic post','topic description','Reason',true,true,true,true,false,false,true);
  135.          *  </code>
  136.          * @since            2.0
  137.          */
  138.         public function edit($topicID$title$post$desc=false$reason=false$close=false$pin=false$approve=true$useEmo=true$useSig=true$bypassPerms=false){
  139.             $title    $this->ipbwi->makeSafe($title);
  140.             $post    $this->ipbwi->makeSafe($post);
  141.             $desc    $this->ipbwi->makeSafe($desc);
  142.             $reason    $this->ipbwi->makeSafe($reason);
  143.             // You are logged in, right?
  144.             if($this->ipbwi->member->isLoggedIn()){
  145.                 $postName $this->ipbwi->member->myInfo['name'];
  146.             }else{
  147.                 $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>');
  148.                 return false;
  149.             }
  150.             // Flooding
  151.             if($this->ipbwi->ips_wrapper->vars['flood_control'&& !$this->ipbwi->permissions->has('g_avoid_flood'&& (time($this->ipbwi->member->myInfo['last_post']$this->ipbwi->ips_wrapper->vars['flood_control']){
  152.                 $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>');
  153.                 return false;
  154.             }
  155.             $time time();
  156.             // Let's extract the information.
  157.             $this->ipbwi->ips_wrapper->DB->query('SELECT  f.*,t.*,p.* 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(t.topic_firstpost=p.pid) WHERE t.tid="'.intval($topicID).'"');
  158.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  159.                 if($user $this->ipbwi->member->info()){
  160.                     $forum $this->ipbwi->forum->info($row['forum_id']);
  161.                     $group $this->ipbwi->group->info($user['mgroup']);
  162.                     // Get permissions
  163.                     if(empty($bypassPerms)){
  164.                         // Is the topic closed...?
  165.                         if(($row['state'!= 'open'AND !$group['g_post_closed']){
  166.                             $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>');
  167.                             return false;
  168.                         }elseif(isset($close&& $close == && $group['g_open_close_posts']){
  169.                             // Is the topic being closed?
  170.                             $state 'closed';
  171.                             $closed $time;
  172.                             $opened $row['topic_open_time'];
  173.                         }elseif(empty($closeOR !$group['g_open_close_posts']){
  174.                             $state 'open';
  175.                             $closed $row['topic_close_time'];
  176.                             $opened $time;
  177.                         }elseif($group['g_open_close_posts']){
  178.                             $state 'open';
  179.                             $closed $row['topic_close_time'];
  180.                             $opened $time;
  181.                         }
  182.                         // Now that this has passed by, can they edit?
  183.                         if($row['author_id'== $user['id'&& !$group['g_edit_topic']){
  184.                             $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>');
  185.                             return false;
  186.                         }elseif(!$group['g_is_supmod']){
  187.                             $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>');
  188.                             return false;
  189.                         }
  190.                     }
  191.                     // Is a new title specified...?
  192.                     if(!$title){
  193.                         $ptitle $forum['last_title'];
  194.                     }elseif($title == $forum['last_title']){
  195.                         $ptitle $forum['last_title'];
  196.                     }else{
  197.                         $ptitle $title;
  198.                     }
  199.                     // Is there a new description?
  200.                     if(!$desc){
  201.                         $fdesc $row['description'];
  202.                     }else{
  203.                         $fdesc $desc;
  204.                     }
  205.                     // Has the post been changed in any way?
  206.                     if(!$post){
  207.                         $apost $row['post'];
  208.                     }else{
  209.                         $apost stripslashes($post);
  210.                     }
  211.                     // Should we update the edit settings?
  212.                     if(!$reason){
  213.                         $reason $row['post_edit_reason'];
  214.                         $edit $row['edit_name'];
  215.                     }else{
  216.                         $edit $user['members_display_name'];
  217.                     }
  218.                     $edited $time;
  219.                     // Ah, so everything's gone through okay. Now for the finishing touch.
  220.                     $this->ipbwi->ips_wrapper->parser->parse_bbcode    $row['use_ibc'];
  221.                     $this->ipbwi->ips_wrapper->parser->strip_quotes    1;
  222.                     $this->ipbwi->ips_wrapper->parser->parse_nl2br        1;
  223.                     $this->ipbwi->ips_wrapper->parser->parse_html        $row['use_html'];
  224.                     $this->ipbwi->ips_wrapper->parser->parse_smilies    ($useEmo 0);
  225.                     $post $this->ipbwi->ips_wrapper->parser->pre_db_parse($apost);
  226.                     $post    $this->ipbwi->makeSafe($post);
  227.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET title="'.$ptitle.'", description="'.$fdesc.'", state="'.$state.'", pinned="'.($pin 0).'", topic_open_time="'.$opened.'", topic_close_time="'.$closed.'", approved="'.($approve 0).'" WHERE tid="'.$topicID.'"');
  228.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'posts SET edit_time="'.$edited.'", post="'.$post.'", edit_name="'.$edit.'", post_edit_reason="'.$reason.'", use_emo="'.($useEmo 0).'", use_sig="'.($useSig 0).'" WHERE pid="'.$row['topic_firstpost'].'"');
  229.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'forums SET last_title="'.$ptitle.'", last_id="'.$topicID.'", last_poster_name="'.$user['members_display_name'].'" WHERE id="'.$row['forum_id'].'"');
  230.                     return true;
  231.                 }else{
  232.                     return false;
  233.                 }
  234.             }else{
  235.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('topicsNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  236.                 return false;
  237.             }
  238.         }
  239.         /**
  240.          * @desc            deletes a topic
  241.          * @param    int        $topicID Topic-ID which has to be deleted
  242.          * @return    bool    true on success, otherwise false
  243.          * @author            Matthias Reuter
  244.          * @sample
  245.          *  <code>
  246.          *  $ipbwi->topic->delete(55);
  247.          *  </code>
  248.          * @since            2.0
  249.          */
  250.         public function delete($topicID){
  251.             if($info $this->info($topicID)){
  252.                 $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics WHERE tid = "'.intval($topicID).'"');
  253.                 $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'posts WHERE topic_id = "'.intval($topicID).'"');
  254.                 $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'polls WHERE tid = "'.intval($topicID).'"');
  255.                 if($this->ipbwi->cache->updateForum($info['forum_id'],array('posts' => -$info['posts'],'topics' => -1))){
  256.                     return true;
  257.                 }else{
  258.                     return false;
  259.                 }
  260.             }else{
  261.                 return false;
  262.             }
  263.         }
  264.         /**
  265.          * @desc            get's topic informations
  266.          * @param    int        $topicID Topic-ID
  267.          * @param    bool    $countView set to true to count topic views
  268.          * @param    bool    $replacePostVars replace attachment post vars with attachment-code, default: true
  269.          * @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.
  270.          * @return    array    Topic-Informations as array
  271.          * @author            Matthias Reuter
  272.          * @sample
  273.          *  <code>
  274.          *  $ipbwi->topic->info(55);
  275.          *  $ipbwi->topic->info(55,true,true,download.php?id=%id%');
  276.          *  </code>
  277.          * @since            2.0
  278.          */
  279.         public function info($topicID$countView false,$replacePostVars true$ipbwiLink false$list false){
  280.             if(isset($list['sql'])){
  281.                 // allow SUB SELECT query joins
  282.                 $this->ipbwi->ips_wrapper->DB->allow_sub_select=1;
  283.                 
  284.                 // query list
  285.                 $query $list['sql'];
  286.             }else{
  287.                 // query single topic
  288.                 $query 'SELECT m.*, t.*, p.*, g.g_dohtml AS usedohtml FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics t LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'posts p ON (t.tid=p.topic_id) 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 t.tid="'.intval($topicID).'" AND p.new_topic="1"';
  289.             }
  290.             $sql $this->ipbwi->ips_wrapper->DB->query($query);
  291.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($sql== 0){
  292.                 return false;
  293.             }
  294.             while($row $this->ipbwi->ips_wrapper->DB->fetch($sql)){
  295.                 // remember first array entry
  296.                 if(empty($firstEntry)){
  297.                     $firstEntry $row['topic_id'];
  298.                 }
  299.  
  300.                 $this->ipbwi->ips_wrapper->parser->parse_smilies            $row['use_emo'];
  301.                 $this->ipbwi->ips_wrapper->parser->parse_html                0;
  302.                 $this->ipbwi->ips_wrapper->parser->parse_nl2br                1;
  303.                 $this->ipbwi->ips_wrapper->parser->parse_bbcode                1;
  304.                 $this->ipbwi->ips_wrapper->parser->parsing_section            'topics';
  305.                 $this->ipbwi->ips_wrapper->parser->parsing_mgroup            $row['member_group_id'];
  306.                 $this->ipbwi->ips_wrapper->parser->parsing_mgroup_others    $row['mgroup_others'];
  307.                 
  308.                 // make proper XHTML
  309.                 $topic[$row['topic_id']]                        $row;
  310.                 $topic[$row['topic_id']]['post']                $this->ipbwi->properXHTML($this->ipbwi->ips_wrapper->parser->preDisplayParse($topic[$row['topic_id']]['post']));
  311.                 $topic[$row['topic_id']]['title']                $this->ipbwi->properXHTML($topic[$row['topic_id']]['title']);
  312.                 $topic[$row['topic_id']]['description']            $this->ipbwi->properXHTML($topic[$row['topic_id']]['description']);
  313.                 $topic[$row['topic_id']]['post_edit_reason']    $this->ipbwi->properXHTML($topic[$row['topic_id']]['post_edit_reason']);
  314.                 $topic[$row['topic_id']]['starter_name']        $this->ipbwi->properXHTML($topic[$row['topic_id']]['starter_name']);
  315.                 $topic[$row['topic_id']]['last_poster_name']    $this->ipbwi->properXHTML($topic[$row['topic_id']]['last_poster_name']);
  316.                 $topic[$row['topic_id']]['author_name']            $this->ipbwi->properXHTML($topic[$row['topic_id']]['author_name']);
  317.                 // increase view count
  318.                 if($countView === true){
  319.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET views = views+1 WHERE tid = '.$topicID);
  320.                 }
  321.                 // replace attachment post vars with attachment-code
  322.                 if($replacePostVars === true){
  323.                     $attachInfo $this->ipbwi->attachment->getList($row['topic_id'],array('type' => 'topic''ipbwiLink' => $ipbwiLink));
  324.                     if(is_array($attachInfo&& count($attachInfo0){
  325.                         foreach($attachInfo as $attachList){
  326.                             if(strpos($topic[$row['topic_id']]['post'],'[attachment='.$attachList['attach_id'].':'!= false{
  327.                                 $topic[$row['topic_id']]['AttachmentNotInlineInfo'][$attachList['attach_id']] $this->ipbwi->attachment->info($attachList['attach_id'],array('ipbwiLink' => $ipbwiLink));
  328.                             }
  329.                         }
  330.                         if(isset($attachInfo['defaultHTML'])){
  331.                             $topic[$row['topic_id']]['post'preg_replace('/\[attachment=([!0-9]*):([!a-zA-Z0-9_\-.]*)\]/smeU','$attachInfo["defaultHTML"]',$topic[$row['topic_id']]['post']);
  332.                         }else{
  333.                             $topic[$row['topic_id']]['post'preg_replace('/\[attachment=([!0-9]*):([!a-zA-Z0-9_\-.]*)\]/smeU','$attachInfo["\1"]["defaultHTML"]',$topic[$row['topic_id']]['post']);
  334.                         }
  335.                     }
  336.                 }
  337.                 // Save Topic In Cache and Return
  338.                 $this->ipbwi->cache->save('TopicInfo'$topicID$row);
  339.             }
  340.             if(isset($list['sql'])){
  341.                 return $topic;
  342.             }else{
  343.                 return $topic[$firstEntry];
  344.             }
  345.         }
  346.         /**
  347.          * @desc            array with topic IDs of the given Forums
  348.          * @param    mixed    $forumIDs The forum IDs where the topic IDs should be retrieved from (array-list, int or '*' for topics from all forums)
  349.          * @param    int        $start For performance purposes, you are able to set a start parameter to set a section of the attachment list. This is used for forum-attachment-list only.
  350.          * @param    int        $limit For performance purposes, you are able to set a limit parameter to set a section of the attachment list. This is used for forum-attachment-list only.
  351.          * @param    bool    $bypassPerms set to true, to ignore permissions
  352.          * @return    array    Topic-Informations as array
  353.          * @author            Matthias Reuter
  354.          * @sample
  355.          *  <code>
  356.          *  $ipbwi->topic->getListIDs(55);
  357.          *  $ipbwi->topic->getListIDs(array(55,77,99));
  358.          *  $ipbwi->topic->getListIDs('*',10,20,true);
  359.          *  </code>
  360.          * @since            2.0
  361.          */
  362.         public function getListIDs($forumIDs,$start=false,$limit=false,$bypassPerms=false){
  363.             if($start != '' || $limit != ''){
  364.                 $startLimit ' LIMIT '.intval($start).','.intval($limit);
  365.             }else{
  366.                 $startLimit false;
  367.             }
  368.             // forum permissions
  369.             $expForum array();
  370.             if(is_array($forumIDs)){
  371.                 foreach($forumIDs as $forumID){
  372.                     if($this->ipbwi->forum->isReadable(intval($forumID)) OR $bypassPerms){
  373.                         $expForum[intval($forumID);
  374.                     }
  375.                 }
  376.             }elseif($forumIDs == '*'){
  377.                 // Get readable forums
  378.                 $readable $this->ipbwi->forum->getReadable();
  379.                 foreach($readable as $i){
  380.                     $expForum[intval($i['id']);
  381.                 }
  382.             }elseif($this->ipbwi->forum->isReadable(intval($forumIDs)) OR $bypassPerms){
  383.                 $expForum[intval($forumIDs);
  384.             }
  385.             if(count($expForum1){
  386.                 $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>');
  387.                 return false;
  388.             }
  389.             // get topics
  390.             var_dump($this->ipbwi->board);
  391.             die();
  392.             $query $this->ipbwi->ips_wrapper->DB->query('SELECT tid FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics WHERE forum_id IN ('.implode(','$expForum).') AND topic_hasattach!="0"'.$startLimit);
  393.             if($this->ipbwi->ips_wrapper->DB->getTotalRows(== 0return false;
  394.             while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  395.                 $topicIDs[$row['tid'];
  396.             }
  397.             return $topicIDs;
  398.         }
  399.         /**
  400.          * @desc            lists topics from several forums and get topic-informations
  401.          * @param    mixed    $forumIDs The forum IDs where the topics should be retrieved from (array-list, int or '*' for topics from all forums)
  402.          * @param    array    $settings optional query settings. Settings allowed: order, orderby limit and start
  403.          *  + string order = ASC or DESC, default ASC
  404.          *  + string orderby = 'tid', 'title', 'posts', 'starter_name', 'starter_id', 'start_date', 'last_post', 'views', 'post_date'. Default: start_date
  405.          *  + int start = Default: 0
  406.          *  + int limit = Default: 15
  407.          *  + bool linked = Get moved & linked topics, too. Default: false
  408.          *  + bool ignoreapproval = Do not get topics which need to be approved. Default: false
  409.          *  + int memberid = Default: false. Deliver Member ID to get topics of this member only
  410.          *  + bool allsubs = Default: false. Retrieve topics from all subforums of delivered Forum-IDs
  411.          *  + bool replacePostVars replace attachment post vars with attachment-code, default: true
  412.          *  + 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.
  413.          *  + bool $countView set to true to count topic views
  414.          * @param    bool    $bypassPerms set to true to bypass permissions
  415.          * @return    array    Topic-Informations as multidimensional array
  416.          * @author            Matthias Reuter
  417.          * @sample
  418.          *  <code>
  419.          *  $ipbwi->topic->getList(55);
  420.          *  $ipbwi->topic->getList(55,array('memberid' => 66));
  421.          *  $ipbwi->topic->getList(array(55,22,77,99));
  422.          *  $ipbwi->topic->getList('*');
  423.          *  $ipbwi->topic->getList(55,array('order' => 'DESC', 'orderby' => 'pid', 'start' => 10, 'limit' => 20, 'linked' => true, 'ignoreapproval' => true));
  424.          *  </code>
  425.          * @since            2.0
  426.          */
  427.         public function getList($forumIDs,$settings=array(),$bypassPerms=false){
  428.             if(empty($settings['order'])){
  429.                 $settings['order''desc';
  430.             }
  431.             if(empty($settings['orderby'])){
  432.                 $settings['orderby''start_date';
  433.             }
  434.             if(empty($settings['start'])){
  435.                 $settings['start'0;
  436.             }
  437.             if(empty($settings['limit'])){
  438.                 $settings['limit'15;
  439.             }
  440.             if(empty($settings['linked'])){
  441.                 $settings['linked'false;
  442.             }
  443.             if(empty($settings['ignoreapproval'])){
  444.                 $settings['ignoreapproval'false;
  445.             }
  446.             if(empty($settings['memberid'])){
  447.                 $settings['memberid'false;
  448.             }
  449.             if(empty($settings['allsubs'])){
  450.                 $settings['allsubs'false;
  451.             }
  452.             if(empty($settings['replacePostVars'])){
  453.                 $settings['replacePostVars'true;
  454.             }
  455.             if(empty($settings['ipbwiLink'])){
  456.                 $settings['ipbwiLink'false;
  457.             }
  458.             if(empty($settings['countView'])){
  459.                 $settings['countView'false;
  460.             }
  461.  
  462.             // get all subforums
  463.             if($settings['allsubs'=== true){
  464.                 $forumIDs $this->ipbwi->forum->getAllSubs($forumIDs,'array_ids_only');
  465.             }
  466.             $expforum array();
  467.             if(is_array($forumIDs)){
  468.                 foreach($forumIDs as $i){
  469.                     if($this->ipbwi->forum->isReadable(intval($i)) OR $bypassPerms){
  470.                         $expforum[intval($i);
  471.                     }
  472.                 }
  473.             }elseif($forumIDs == '*'){
  474.                 // Get readable forums
  475.                 $readable $this->ipbwi->forum->getReadable();
  476.                 foreach($readable as $k){
  477.                     $expforum[intval($k['id']);
  478.                 }
  479.             }elseif($this->ipbwi->forum->isReadable(intval($forumIDs)) OR $bypassPerms){
  480.                 $expforum[intval($forumIDs);
  481.             }
  482.             if(count($expforum1){
  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.             }else{
  486.                 // get linked, moved topics too if requested
  487.                 if(isset($settings['linked']&& $settings['linked'=== true){
  488.                     $SQL .= 'SELECT m.*, t.*, p.*, g.g_dohtml AS usedohtml FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics torig LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'topics t ON (IFNULL( (t.tid = LEFT(torig.moved_to, INSTR(torig.moved_to, "&"))),t.tid = torig.tid ))';
  489.                     $tb 't.';
  490.                 }else{
  491.                     // else get all other topics
  492.                     $SQL 'SELECT m.*, torig.*, p.*, g.g_dohtml AS usedohtml FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics torig';
  493.                     $tb 'torig.';
  494.                 }
  495.                 // Grab Posts
  496.                 $limit = isset($settings['limit']intval($settings['limit']'15';
  497.                 $start = isset($settings['start']intval($settings['start']'0';
  498.                 // Forum ID Code
  499.                 if(($forumIDs == '*'&& $bypassPerms){
  500.                     $forums '';
  501.                 }else{
  502.                     $forums ' AND torig.forum_id IN ('.implode(','$expforum).')';
  503.                 }
  504.                 // Are we looking for an approval?
  505.                 if(empty($settings['ignoreapproval'])){
  506.                     $approved ' AND torig.approved="1"';
  507.                 }
  508.                 // get data from a specific user
  509.                 if($settings['memberid']){
  510.                     $specificMember ' AND '.$tb.'starter_id = "'.intval($settings['memberid']).'"';
  511.                 }else{
  512.                     $specificMember false;
  513.                 }
  514.                 // What shall I order it by guv?
  515.                 $allowedorder array('tid''title''posts''starter_name''starter_id''start_date''last_post''views''post_date');
  516.                 if(isset($settings['orderby']&& in_array($settings['orderby']$allowedorder)){
  517.                     $order $tb.$settings['orderby'].' '.(($settings['order'== 'desc''DESC' 'ASC');
  518.                 }elseif(isset($settings['orderby']&& $settings['orderby'== 'random'){
  519.                     $order $tb.'RAND()';
  520.                 }else{
  521.                     $order $tb.'last_post '.((strtolower($settings['order']== 'desc''DESC' 'ASC');
  522.                 }
  523.                 $SQL .= '    LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'posts p ON ('.$tb.'tid=p.topic_id)
  524.                             LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'members m ON (p.author_id=m.member_id)
  525.                             LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'groups g ON (m.member_group_id=g.g_id)
  526.                             WHERE p.new_topic="1"'.$forums.$approved.$specificMember.'
  527.                             ORDER BY '.$order.' LIMIT '.$start.','.$limit;
  528.                 
  529.                 return $this->info(false$settings['countView']$settings['replacePostVars']$settings['ipbwiLink']array('sql' => $SQL));
  530.             }
  531.         }
  532.         /**
  533.          * @desc            rates a topic
  534.          * @param    int        $topicID ID of the topic which has to be rated
  535.          * @param    int        $rating     rating for the topic
  536.          * @param    bool    $bypassPerms set to true to bypass permissions
  537.          * @return    bool    true on success, otherwise false
  538.          * @author            Matthias Reuter
  539.          * @sample
  540.          *  <code>
  541.          *  $ipbwi->topic->rate(55,4);
  542.          *  $ipbwi->topic->rate(55,5,true);
  543.          *  </code>
  544.          * @since            2.0
  545.          */
  546.         public function rate($topicID,$rating,$bypassPerms=false){
  547.             if($rating >= '6'){
  548.                 return false;
  549.             }
  550.             // Flood control, time.
  551.             if(($this->ipbwi->ips_wrapper->vars['flood_control'&& !$this->has_perms('g_avoid_flood')) OR !$bypassPerms){
  552.                 if((time($this->ipbwi->member->myInfo['last_post']$this->ipbwi->ips_wrapper->vars['flood_control']){
  553.                     $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>');
  554.                     return false;
  555.                 }
  556.             }
  557.             // Get the topic information.
  558.             $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics WHERE tid="'.intval($topicID).'"');
  559.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  560.                 if($user $this->ipbwi->member->info()){
  561.                     $forum $this->ipbwi->forum->info($row['forum_id']);
  562.                     $group $this->ipbwi->group->info($user['mgroup']);
  563.                     // Are ratings allowed?
  564.                     if(!$forum['forum_allow_rating']return false;
  565.                     // Can the member vote?
  566.                     if(!$bypassPerms && !$group['g_topic_rate_setting']return false;
  567.                     $userid intval($user['id']);
  568.                     $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topic_ratings WHERE rating_tid="'.$topicID.'" AND rating_member_id="'.$userid.'"');
  569.                     if($rate $this->ipbwi->ips_wrapper->DB->fetch()){
  570.                         if(($group['g_topic_rate_setting'== "2"OR $bypassPerms){
  571.                             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topic_ratings SET rating_value="'.$rating.'" WHERE rating_tid="'.$topicID.'" AND rating_member_id="'.$userid.'"');
  572.                             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET topic_rating_total=topic_rating_total-"'.$rate['rating_value'].'"+"'.$rating.'" WHERE tid="'.$topicID.'"');
  573.                             return true;
  574.                         }else{
  575.                             return false;
  576.                         }
  577.                     }else{
  578.                         $this->ipbwi->ips_wrapper->DB->query('INSERT INTO '.$this->ipbwi->board['sql_tbl_prefix'].'topic_ratings (rating_tid, rating_member_id, rating_value, rating_ip_address) VALUES("'.$topicID.'", "'.$user['id'].'", "'.$rating.'", "'.$_SERVER['REMOTE_ADDR'].'")');
  579.                         $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET topic_rating_total=topic_rating_total+"'.$rating.'", topic_rating_hits=topic_rating_hits+1 WHERE tid="'.$topicID.'"');
  580.                         return true;
  581.                     }
  582.                 }else{
  583.                     return false;
  584.                 }
  585.             }else{
  586.                 return false;
  587.             }
  588.         }
  589.         /**
  590.          * @desc            merges several topics
  591.          * @param    int        $topic1id ID('s) of the topic(s) to be merged
  592.          * @param    int        $topic2id ID of topic that $topic1id will be merged into
  593.          * @param    string    $desc Topic-Description
  594.          * @param    bool    $bypassPerms set to true to bypass permissions
  595.          * @return    bool    true on success, otherwise false
  596.          * @author            Matthias Reuter
  597.          * @sample
  598.          *  <code>
  599.          *  $ipbwi->topic->rate(55,77,'merged topic title', 'merged topic description');
  600.          *  $ipbwi->topic->rate(55,77,'merged topic title', 'merged topic description', true);
  601.          *  </code>
  602.          * @since            2.0
  603.          */
  604.         public function merge($topic1id$topic2id$title$desc$bypassPerms=false){
  605.             // Is the user logged in...?
  606.             if($this->member->isLoggedIn()){
  607.                 $postName $this->ipbwi->member->myInfo['name'];
  608.             }else{
  609.                 $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>');
  610.                 return false;
  611.             }
  612.             // Flood control time.
  613.             if($this->ipbwi->ips_wrapper->vars['flood_control'AND !$this->ipbwi->permissions->has('g_avoid_flood')){
  614.                 if((time($this->ipbwi->member->myInfo['last_post']$this->ipbwi->ips_wrapper->vars['flood_control']){
  615.                     $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>');
  616.                     return false;
  617.                 }
  618.             }
  619.             // Are the id(s) for the topic(s)-to-be-merged set?
  620.             if(!isset($topic1id)){
  621.                 return false;
  622.             }
  623.             // We can't have the second topic id in an array, so...
  624.             if(is_array($topic2id)){
  625.                 return false;
  626.             }
  627.             // Are the id's numeric?
  628.             if(!is_numeric($topic1idOR !is_numeric($topic2id)){
  629.                 // If $topic1id is an array...
  630.                 if(is_array($topic1id)){
  631.                     foreach($topic1id as $k => $v){
  632.                         if(!is_numeric($v)){
  633.                             unset($topic1id[$k]);
  634.                         }
  635.                     }
  636.                 }else{
  637.                     return false;
  638.                 }
  639.             }
  640.             // Are the id's identical?
  641.             if($topic1id == $topic2id){
  642.                 return false;
  643.             }else{
  644.                 // If $topic1id is an array...
  645.                 if(is_array($topic1id)){
  646.                     foreach($topic1id as $k => $v){
  647.                         if($v == $topic2id){
  648.                             unset($topic1id[$k]);
  649.                         }
  650.                     }
  651.                 }
  652.             }
  653.             // Let's get some SQL information.
  654.             $this->ipbwi->ips_wrapper->DB->query('SELECT  f.*,t.*,p.* 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(t.topic_firstpost=p.pid) WHERE t.tid="'.intval($topic2id).'"');
  655.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  656.                 if($user $this->ipbwi->member->info()){
  657.                     $forum $this->ipbwi->forum->info($row['forum_id']);
  658.                     $group $this->ipbwi->group->info($user['mgroup']);
  659.                     if(is_array($topic1id)){
  660.                         foreach($topic1id as $v){
  661.                             $topic[$this->info($v);
  662.                         }
  663.                     }else{
  664.                         $topic[$this->info($topic1id);
  665.                     }
  666.                     $time time();
  667.                     if(!$bypassPerms && is_array($topic)){
  668.                         foreach($topic as $k => $v){
  669.                             if($user['id'== $v['starter_id'&& !$group['g_edit_topic']){
  670.                                 return false;
  671.                             }elseif(!$this->ipbwi->member->isSuperMod()){
  672.                                 $mod $this->ipbwi->forum->getModerators($forum['id']$user['id']);
  673.                                 foreach($mod as $h){
  674.                                     if($h['forum_id'== $user['id'&& !$h['split_merge']){
  675.                                         return false;
  676.                                     }
  677.                                 }
  678.                             }
  679.                         }
  680.                     }
  681.                     // Is a new title specified...?
  682.                     if($title == false){
  683.                         $ltitle $row['title'];
  684.                         $lname $row['last_poster_name'];
  685.                         $laid $row['last_poster_id'];
  686.                         $ptitle $row['title'];
  687.                     }elseif($title == $row['last_title']){
  688.                         $ltitle $row['last_title'];
  689.                         $lname $row['last_poster_name'];
  690.                         $laid $row['last_poster_id'];
  691.                         $ptitle $title;
  692.                     }elseif($title == $forum['last_title']){
  693.                         $ltitle $forum['last_title'];
  694.                         $lname $forum['last_poster_name'];
  695.                         $laid $forum['last_poster_id'];
  696.                         $ptitle $title;
  697.                     }else{
  698.                         $ltitle $forum['last_title'];
  699.                         $lname $forum['last_poster_name'];
  700.                         $laid $forum['last_poster_id'];
  701.                         $ptitle $title;
  702.                     }
  703.                     // Is a new description specified...?
  704.                     if($desc == false){
  705.                         $fdesc $row['description'];
  706.                     }else{
  707.                         $fdesc stripslashes($desc);
  708.                     }
  709.                     // Alright, everything has passed. Time to update the database.
  710.                     $this->ipbwi->ips_wrapper->parser->parse_bbcode $row['use_ibc'];
  711.                     $this->ipbwi->ips_wrapper->parser->strip_quotes 1;
  712.                     $this->ipbwi->ips_wrapper->parser->parse_nl2br 1;
  713.                     $this->ipbwi->ips_wrapper->parser->parse_html $row['use_html'];
  714.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET title="'.$ptitle.'", description="'.$fdesc.'" WHERE tid="'.$topic2id.'"');
  715.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'forums SET last_id="'.$topic2id.'", last_title="'.$ltitle.'", last_poster_name="'.$lname.'", last_poster_id="'.$laid.'" WHERE id="'.$topic['forum_id'].'"');
  716.                     // If $topic is an array, multiple topics will be merged into one.
  717.                     if(is_array($topic)){
  718.                         foreach($topic as $v){
  719.                             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'posts SET topic_id="'.$row['tid'].'", new_topic="0" WHERE pid="'.$v['topic_firstpost'].'"');
  720.                             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'forums SET posts=posts+1, topics=topics-1 WHERE id="'.$v['forum_id'].'"');
  721.                             // With the database updated, we can get rid of the old stuff.
  722.                             $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics WHERE tid="'.$v['tid'].'"');
  723.  
  724.                             // Now to update that post count...
  725.                             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET posts=posts+1 WHERE tid="'.$topic2id.'"');
  726.                         }
  727.                     }
  728.                     return true;
  729.                 }else{
  730.                     $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>');
  731.                     return false;
  732.                 }
  733.             }else{
  734.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('topicsNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  735.                 return false;
  736.             }
  737.         }
  738.         /**
  739.          * @desc            Converts topic title to topic-IDs
  740.          * @param    string    $title Topic Title
  741.          * @return    mixed    int Topic ID, array Topic IDs or false
  742.          * @author            Matthias Reuter
  743.          * @sample
  744.          *  <code>
  745.          *  $ipbwi->topic->title2id('topic title');
  746.          *  </code>
  747.          * @since            2.0
  748.          */
  749.         public function title2id($title){
  750.             $sql $this->ipbwi->ips_wrapper->DB->query('SELECT tid FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics WHERE title="' addslashes(htmlentities($title)) '"');
  751.             $topics $this->ipbwi->ips_wrapper->DB->fetch($sql);
  752.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($sql== 0){
  753.                 return false;
  754.             }elseif(is_array($topics&& count($topics=== 1){
  755.                 return $topics['tid']// return matching topic-id
  756.             }else{
  757.                 return $topics// return array of matched topic-ids
  758.             }
  759.         }
  760.         /**
  761.          * @desc            Converts topic ID to topic-title
  762.          * @param    int        $id Topic ID
  763.          * @return    string    Topic Title
  764.          * @author            Matthias Reuter
  765.          * @sample
  766.          *  <code>
  767.          *  $ipbwi->topic->title2id('topic title');
  768.          *  </code>
  769.          * @since            2.0
  770.          */
  771.         public function id2title($id){
  772.             $sql $this->ipbwi->ips_wrapper->DB->query('SELECT title FROM '.$this->ipbwi->board['sql_tbl_prefix'].'topics WHERE tid="'.intval($id).'"');
  773.             $topics $this->ipbwi->ips_wrapper->DB->fetch($sql);
  774.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($sql== 0){
  775.                 return false;
  776.             }else{
  777.                 return $this->ipbwi->properXHTML($topics['title'])// return matching topic-title
  778.             }
  779.         }
  780.         /**
  781.          * @desc            Moves a topic to a specified destination forum
  782.          * @param    int        $topicID Topic ID
  783.          * @param    int        $destforumid Destination Forum ID
  784.          * @param    int        $bypassPerms set to true to bypass permissions
  785.          * @return    bool    true on success, false on failure
  786.          * @author            Matthias Reuter
  787.          * @sample
  788.          *  <code>
  789.          *  $ipbwi->topic->move(55,33);
  790.          *  $ipbwi->topic->move(55,33,true);
  791.          *  </code>
  792.          * @since            2.0
  793.          */
  794.         public function move($topicID$destForumID$bypassPerms false){
  795.             // Check params and set obvious variables
  796.             if($topicInfo $this->info($topicID)){
  797.                 if($this->ipbwi->forum->info($topicInfo['forum_id'])){
  798.                     if($this->ipbwi->forum->info($destForumID)){
  799.                         if($memberInfo $this->ipbwi->member->info()){
  800.                             // You are logged in, right?
  801.                             if(!$this->ipbwi->member->isLoggedIn()){
  802.                                 // Drat... Sorry, but we can't have guests running around moving topics.
  803.                                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  804.                                 return false;
  805.                             }
  806.                             // Flooding
  807.                             if($this->ipbwi->ips_wrapper->vars['flood_control'AND !$this->has_perms('g_avoid_flood')){
  808.                                 if((time($this->ipbwi->member->myInfo['last_post']$this->ipbwi->ips_wrapper->vars['flood_control']){
  809.                                     $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>');
  810.                                     return false;
  811.                                 }
  812.                             }
  813.                             // Check permissions
  814.                             if(!$bypassPerms && !$topicInfo['author_id'== $memberInfo['id'&& !$group['g_is_supmod']){
  815.                                 // Is the logged in member the topic author? (or are they a supermod?)
  816.                                 $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>');
  817.                                 return false;
  818.                             }
  819.                             // Right, we're finally allowed to move the topic
  820.                             if($this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'topics SET forum_id = "'.$destForumID.'" WHERE tid ="'.$topicID.'" LIMIT 1')){
  821.                                 //Now the topic has been moved, clean up the cache for original forum AND destination forum
  822.                                 $this->ipbwi->cache->updateForum($topicInfo['forum_id'],array('posts' => -$topicInfo['posts'],'topics' => -1));
  823.                                 $this->ipbwi->cache->updateForum($destForumID,array('posts' => $topicInfo['posts'],'topics' => 1));
  824.                                 return true;
  825.                             }else{
  826.                                 return false;
  827.                             }
  828.                         }else{
  829.                             $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  830.                             return false;
  831.                         }
  832.                     }else{
  833.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('forumNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  834.                         return false;
  835.                     }
  836.                 }else{
  837.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('topicsNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  838.                     return false;
  839.                 }
  840.             }else{
  841.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('topicsNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  842.                 return false;
  843.             }
  844.         }
  845.     }
  846. ?>

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