Ejemplo n.º 1
0
 public function addNode($name, $parent_id, $description = FALSE, $suspend = FALSE, $locked = FALSE, $position = FALSE, $is_link = FALSE, $link_href = FALSE, $private = FALSE, $password = FALSE)
 {
     $stack = $this->getForums();
     $name = BB::Open($name, FALSE, TRUE, FALSE)->Execute();
     $description = isset($description) ? BB::Open($description)->Execute() : NULL;
     $suspend = isset($suspend) ? intval($suspend) : 0;
     $lock = isset($locked) ? intval($locked) : 0;
     $link_href = isset($link_href) ? $link_href : '';
     $password = isset($password) ? $password : '';
     $parent = $this->dba->GetRow("SELECT * FROM " . FORUMS . " WHERE id = {$parent_id}");
     if ($parent_id != 1) {
         if (($parent['row_right'] - $parent['row_left'] - 1) / 2 > 0) {
             $left = $parent['row_right'];
         } else {
             if ($this->getNumOnLevel($parent_id) > 0) {
                 $left = $parent['row_right'];
             } else {
                 $left = $parent['row_left'] + 1;
             }
         }
         $depth = $parent['row_level'] + 1;
         $right = $left + 1;
         /* Auto set the order for this node */
         if ($depth > 1) {
             $top = $this->dba->GetRow("SELECT * FROM " . FORUMS . " WHERE row_right <= {$left} ORDER BY row_left ASC LIMIT 1");
             $temp_order = $this->dba->GetValue("SELECT MAX(f_order) FROM " . FORUMS . " WHERE row_left >= " . $top['row_left'] . " AND row_right <= " . $top['row_right']);
         }
         $order = $temp_order == 0 ? 1 : $temp_order + 1;
         $position = $position != FALSE ? intval($position) : $order;
         try {
             @$this->dba->Query("UPDATE " . FORUMS . " SET row_right = row_right+2, subforums = subforums+1 WHERE row_left < {$left} AND row_right >= {$left}");
             // Good
             @$this->dba->Query("UPDATE " . FORUMS . " SET row_left = row_left+2, row_right=row_right+2 WHERE row_left >= {$left}");
             // Good
             @$this->dba->Query("INSERT INTO " . FORUMS . " (row_left, row_right, name, description, parent_id, row_level, f_order, suspend, row_lock, is_link, link_href, private, pass) VALUES ({$left}, {$right}, '{$name}', '{$description}', {$parent_id}, {$depth}, {$position}, {$suspend}, {$lock}, {$is_link}, '{$link_href}', {$private}, '{$password}')");
         } catch (DBA_Exception $e) {
             exit('<pre>' . $e->getMessage() . '</pre>');
         }
     } else {
         $right = $this->dba->GetValue("SELECT row_right FROM " . FORUMS . " WHERE row_left = 1") - 1;
         $last_child = $this->dba->GetRow("SELECT * FROM " . FORUMS . " WHERE row_right = {$right}");
         if (is_array($last_child) && !empty($last_child)) {
             $left = $last_child['row_right'] + 1;
             $right = $left + 1;
         } else {
             $left = 2;
             $right = 3;
         }
         $depth = 1;
         $temp_order = $this->dba->GetValue("SELECT MAX(f_order) FROM " . FORUMS . " WHERE row_level = 1");
         $order = !$temp_order ? 1 : $temp_order + 1;
         $this->dba->Query("UPDATE " . FORUMS . " SET row_right = row_right+2 WHERE row_left = 1");
         $this->dba->Query("INSERT INTO " . FORUMS . " (name, row_left, row_right, parent_id, row_level, f_order) VALUES ('{$name}', {$left}, {$right}, {$parent_id}, {$depth}, {$order})");
     }
     return TRUE;
 }
Ejemplo n.º 2
0
 public function Execute(Template $template, Session $session, $request)
 {
     /* Create the ancestors bar (if we run into any trouble */
     $template = CreateAncestors($template, $template['L_POSTREPLY']);
     /* Open a connection to the database */
     $this->dba = DBA::Open();
     /* Set the a variable to this user's permissions and id */
     $user_perms = isset($session['user']['perms']) ? $session['user']['perms'] : ALL;
     $user_id = $session['user']['id'];
     /* Get our parent forum */
     try {
         @($post = $this->dba->GetRow("SELECT * FROM " . POSTS . " WHERE id = " . intval($request['post_id'])));
         @($thread = $this->dba->GetRow("SELECT * FROM " . POSTS . " WHERE row_left <= " . $post['row_left'] . " AND row_right >= " . $post['row_right']));
     } catch (DBA_Exception $e) {
         return new TplException($e, $template);
     }
     /* Parse the Message */
     $request['message'] = BB::Open($request['message'])->Execute();
     /* Quote all of the REQUEST variables */
     foreach ($request as $key => $val) {
         $request[$key] = $this->dba->Quote($val);
     }
     /* Set the post icon */
     if (isset($request['posticon']) && intval($request['posticon']) != 0 && $request['posticon'] != '-1') {
         try {
             $posticon = $this->dba->GetValue("SELECT image FROM " . POSTICONS . " WHERE id = " . intval($request['posticon']));
         } catch (DBA_Exception $e) {
             return new TplException($e, $template);
         }
     } else {
         $posticon = 'clear.gif';
     }
     if (is_array($post) && !empty($post)) {
         /* Try and get the forum */
         try {
             @($f = new Forum());
             @($forum = $f->getForum($post['forum_id']));
         } catch (DBA_Exception $e) {
             return new TplException($e, $template);
         }
         if ($user_perms >= $forum['can_edit'] && ($session['user']['id'] == $post['poster_id'] || $user_perms & ADMIN)) {
             try {
                 @$this->dba->Query("UPDATE " . POSTS . " SET name = '" . $request['title'] . "', body_text = '" . $request['message'] . "', icon = '" . $posticon . "', edited = " . time() . " WHERE id = " . $post['id']);
             } catch (DBA_Exception $e) {
                 return new TplException($e, $template);
             }
             /* If we've gotten to this point, reload the page to our recently added thread :) */
             return new Error($template['L_UPDATEDPOST'] . '<meta http-equiv="refresh" content="1; url=viewthread.php?id=' . $thread['id'] . '">', $template);
         } else {
             return new Error($template['L_PERMSEDITPOST'], $template);
         }
     } else {
         return new Error($template['L_INVALIDPOSTID'], $template);
     }
 }
Ejemplo n.º 3
0
 public function Current()
 {
     $temp = $this->forums->Current();
     $temp['name'] = BB::Open('')->Revert(stripslashes($temp['name']));
     $temp['description'] = BB::Open('')->Revert(stripslashes($temp['description']));
     return $temp;
 }