diff options
| author | Savetheinternet <savetheinternet@n0v4.com> | 2010-12-17 02:20:16 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@n0v4.com> | 2010-12-17 02:20:16 +1100 |
| commit | 9554291802cb8ac712ba25d1a59ced31d20b07f0 (patch) | |
| tree | 6861b6ebffe4e2f54573907cc789b34648d59c24 | |
| parent | 4052d6350214e5384cfe15823e29197d2eaf7326 (diff) | |
Mod controls and permissions
| -rw-r--r-- | inc/config.php | 8 | ||||
| -rw-r--r-- | inc/display.php | 116 | ||||
| -rw-r--r-- | inc/mod.php | 8 | ||||
| -rw-r--r-- | mod.php | 25 |
4 files changed, 101 insertions, 56 deletions
diff --git a/inc/config.php b/inc/config.php index 4e48b6d5..8f265a78 100644 --- a/inc/config.php +++ b/inc/config.php @@ -152,6 +152,7 @@ // Permissions // What level of administration you need to: + /* Post Controls */ // View IP addresses define('MOD_SHOW_IP', MOD_MOD, true); // Delete a post @@ -167,6 +168,12 @@ // Sticky a thread define('MOD_STICKY', MOD_MOD, true); + /* Administration */ + // Display the contents of instant-config.php + define('MOD_SHOW_CONFIG', MOD_ADMIN, true); + // Create a new board + define('MOD_NEWBOARD', MOD_ADMIN, true); + // Mod links (full HTML) // Correspond to above permission directives define('MOD_LINK_DELETE', '[D]', true); @@ -175,6 +182,7 @@ define('MOD_LINK_DELETEFILE', '[F]', true); define('MOD_LINK_DELETEBYIP', '[D+]', true); define('MOD_LINK_STICKY', '[Sticky]', true); + define('MOD_LINK_DESTICKY', '[-Sticky]', true); // A small file in the main directory indicating that the script has been ran and the board(s) have been generated. // This keeps the script from querying the database and causing strain when not needed. diff --git a/inc/display.php b/inc/display.php index 8cf4a18e..5dbccc8f 100644 --- a/inc/display.php +++ b/inc/display.php @@ -48,50 +48,6 @@ ))); } - function postControls($id, $thread=false) { - global $mod; - - $built = ''; - if($mod) { - // Mod controls (on posts) - if($thread) { - $built .= '<span class="controls op">'; - } else { - $built .= '<span class="controls">'; - } - - // Delete - if($mod['type'] >= MOD_DELETE) - $built .= ' <a title="Delete" href="?/b/delete/' . $id . '">' . MOD_LINK_DELETE . '</a>'; - - // Delete all posts by IP - if($mod['type'] >= MOD_DELETEBYIP) - $built .= ' <a title="Delete all posts by IP" href="?/b/deletebyip/' . $id . '">' . MOD_LINK_DELETEBYIP . '</a>'; - - // Ban - if($mod['type'] >= MOD_BAN) - $built .= ' <a title="Ban" href="?/b/ban/' . $id . '">' . MOD_LINK_BAN . '</a>'; - - // Ban & Delete - if($mod['type'] >= MOD_BANDELETE) - $built .= ' <a title="Ban & Delete" href="?/b/ban&delete/' . $id . '">' . MOD_LINK_BANDELETE . '</a>'; - - // Delete file (keep post) - if(!$thread && $mod['type'] >= MOD_DELETEFILE) - $built .= ' <a title="Remove file" href="?/b/file/' . $id . '">' . MOD_LINK_DELETEFILE . '</a>'; - - if($thread) { - // Delete file (keep post) - if($mod['type'] >= MOD_STICKY) - $built .= ' <a title="Make thread sticky" href="?/b/sticky/' . $id . '">' . MOD_LINK_STICKY . '</a>'; - - } - - $built .= '</span>'; - } - return $built; - } - class Post { public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT) { $this->id = $id; @@ -113,6 +69,39 @@ $this->ip = $ip; $this->root = $root; } + public function postControls() { + global $mod; + + $built = ''; + if($mod) { + // Mod controls (on posts) + $built .= '<span class="controls">'; + + // Delete + if($mod['type'] >= MOD_DELETE) + $built .= ' <a title="Delete" href="?/b/delete/' . $this->id . '">' . MOD_LINK_DELETE . '</a>'; + + // Delete all posts by IP + if($mod['type'] >= MOD_DELETEBYIP) + $built .= ' <a title="Delete all posts by IP" href="?/b/deletebyip/' . $this->id . '">' . MOD_LINK_DELETEBYIP . '</a>'; + + // Ban + if($mod['type'] >= MOD_BAN) + $built .= ' <a title="Ban" href="?/b/ban/' . $this->id . '">' . MOD_LINK_BAN . '</a>'; + + // Ban & Delete + if($mod['type'] >= MOD_BANDELETE) + $built .= ' <a title="Ban & Delete" href="?/b/ban&delete/' . $this->id . '">' . MOD_LINK_BANDELETE . '</a>'; + + // Delete file (keep post) + if($mod['type'] >= MOD_DELETEFILE) + $built .= ' <a title="Remove file" href="?/b/file/' . $this->id . '">' . MOD_LINK_DELETEFILE . '</a>'; + + $built .= '</span>'; + } + return $built; + } + public function build($index=false) { global $board, $mod; @@ -169,7 +158,7 @@ '<a href="' . ROOT . $board['dir'] . DIR_IMG . $this->file.'"><img src="' . ROOT . $board['dir'] . DIR_THUMB . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>'; } - $built .= postControls($this->id); + $built .= $this->postControls(); // Body $built .= '<p class="body">' . $this->body . '</p></div><br class="clear"/>'; @@ -205,6 +194,41 @@ public function add(Post $post) { $this->posts[] = $post; } + public function postControls() { + global $mod; + + $built = ''; + if($mod) { + // Mod controls (on posts) + $built .= '<span class="controls op">'; + + // Delete + if($mod['type'] >= MOD_DELETE) + $built .= ' <a title="Delete" href="?/b/delete/' . $this->id . '">' . MOD_LINK_DELETE . '</a>'; + + // Delete all posts by IP + if($mod['type'] >= MOD_DELETEBYIP) + $built .= ' <a title="Delete all posts by IP" href="?/b/deletebyip/' . $this->id . '">' . MOD_LINK_DELETEBYIP . '</a>'; + + // Ban + if($mod['type'] >= MOD_BAN) + $built .= ' <a title="Ban" href="?/b/ban/' . $this->id . '">' . MOD_LINK_BAN . '</a>'; + + // Ban & Delete + if($mod['type'] >= MOD_BANDELETE) + $built .= ' <a title="Ban & Delete" href="?/b/ban&delete/' . $this->id . '">' . MOD_LINK_BANDELETE . '</a>'; + + // Delete file (keep post) + if($mod['type'] >= MOD_STICKY) + if($this->sticky) + $built .= ' <a title="Make thread not sticky" href="?/b/unsticky/' . $this->id . '">' . MOD_LINK_DESTICKY . '</a>'; + else + $built .= ' <a title="Make thread sticky" href="?/b/sticky/' . $this->id . '">' . MOD_LINK_STICKY . '</a>'; + + $built .= '</span>'; + } + return $built; + } public function build($index=false) { global $board, $mod; @@ -261,7 +285,7 @@ ($index ? '<a href="' . $this->root . $board['dir'] . DIR_RES . $this->id . '.html">[Reply]</a>' : '') . // Mod controls - postControls($this->id, true) . + $this->postControls() . '</p>'; // Body diff --git a/inc/mod.php b/inc/mod.php index 200ffa20..b5e773f5 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -85,11 +85,11 @@ } // Generates a <ul> element with a list of linked - // boards and their subtitles. + // boards and their subtitles. (without the <ul> opening and ending tags) function ulBoards() { global $mod; - $body = '<ul>'; + $body = ''; // List of boards $boards = listBoards(); @@ -106,10 +106,10 @@ '</li>'; } - if($mod['type'] == MOD_ADMIN) { + if($mod['type'] >= MOD_NEWBOARD) { $body .= '<li style="margin-top:15px;"><a href="?/new"><strong>Create new board</strong></a></li>'; } - return $body . '</ul>'; + return $body; } function form_newBoard() { @@ -56,14 +56,26 @@ if(preg_match('/^\/?$/', $query)) { // Dashboard - $body = ''; + $fieldset = Array( + 'Boards' => '', + 'Administration' => '' + ); - $body .= '<fieldset><legend>Boards</legend>' . - ulBoards() . - '</fieldset>'; + // Boards + $fieldset['Boards'] .= ulBoards(); + + if($mod['type'] >= MOD_SHOW_CONFIG) { + $fieldset['Administration'] .= '<li><a href="?/config">Show configuration</a></li>'; + } // TODO: Statistics, etc, in the dashboard. + $body = ''; + foreach($fieldset as $title => $data) { + if($data) + $body .= "<fieldset><legend>{$title}</legend><ul>{$data}</ul></fieldset>"; + } + echo Element('page.html', Array( 'index'=>ROOT, 'title'=>'Dashboard', @@ -72,7 +84,7 @@ ) ); } elseif(preg_match('/^\/config$/', $query)) { - if($mod['type'] != MOD_ADMIN) error(ERROR_NOACCESS); + if($mod['type'] < MOD_SHOW_CONFIG) error(ERROR_NOACCESS); // Show instance-config.php @@ -92,7 +104,7 @@ ) ); } elseif(preg_match('/^\/new$/', $query)) { - if($mod['type'] != MOD_ADMIN) error(ERROR_NOACCESS); + if($mod['type'] < MOD_NEWBOARD) error(ERROR_NOACCESS); // New board $body = ''; @@ -186,6 +198,7 @@ echo $page; } elseif(preg_match('/^\/' . $regex['board'] . 'delete\/(\d+)$/', $query, $matches)) { + if($mod['type'] < MOD_DELETE) error(ERROR_NOACCESS); // Delete post $boardName = $matches[1]; |
