inital commit
This commit is contained in:
1068
webroot/forum/admin/inc/class_form.php
Normal file
1068
webroot/forum/admin/inc/class_form.php
Normal file
File diff suppressed because it is too large
Load Diff
1241
webroot/forum/admin/inc/class_page.php
Normal file
1241
webroot/forum/admin/inc/class_page.php
Normal file
File diff suppressed because it is too large
Load Diff
291
webroot/forum/admin/inc/class_table.php
Normal file
291
webroot/forum/admin/inc/class_table.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate a data grid/table.
|
||||
*/
|
||||
class DefaultTable
|
||||
{
|
||||
/**
|
||||
* @var array Array of cells for the current row.
|
||||
*/
|
||||
private $_cells = array();
|
||||
|
||||
/**
|
||||
* @var array Array of rows for the current table.
|
||||
*/
|
||||
private $_rows = array();
|
||||
|
||||
/**
|
||||
* @var array Array of headers for the current table.
|
||||
*/
|
||||
private $_headers = array();
|
||||
|
||||
/**
|
||||
* Construct an individual cell for this table.
|
||||
*
|
||||
* @param string $data The HTML content for this cell.
|
||||
* @param array $extra Array of extra information about this cell (class, id, colspan, rowspan, width)
|
||||
*/
|
||||
function construct_cell($data, $extra=array())
|
||||
{
|
||||
$this->_cells[] = array("data" => $data, "extra" => $extra);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a row from the earlier defined constructed cells for the table.
|
||||
*
|
||||
* @param array $extra Array of extra information about this row (class, id)
|
||||
*/
|
||||
function construct_row($extra = array())
|
||||
{
|
||||
$i = 1;
|
||||
$cells = '';
|
||||
|
||||
// We construct individual cells here
|
||||
foreach($this->_cells as $key => $cell)
|
||||
{
|
||||
$cells .= "\t\t\t<td";
|
||||
|
||||
if(!isset($cell['extra']['class']))
|
||||
{
|
||||
$cell['extra']['class'] = '';
|
||||
}
|
||||
|
||||
if($key == 0)
|
||||
{
|
||||
$cell['extra']['class'] .= " first";
|
||||
}
|
||||
elseif(!isset($this->_cells[$key+1]))
|
||||
{
|
||||
$cell['extra']['class'] .= " last";
|
||||
}
|
||||
if($i == 2)
|
||||
{
|
||||
$cell['extra']['class'] .= " alt_col";
|
||||
$i = 0;
|
||||
}
|
||||
$i++;
|
||||
if($cell['extra']['class'])
|
||||
{
|
||||
$cells .= " class=\"".trim($cell['extra']['class'])."\"";
|
||||
}
|
||||
if(isset($cell['extra']['style']))
|
||||
{
|
||||
$cells .= " style=\"".$cell['extra']['style']."\"";
|
||||
}
|
||||
if(isset($cell['extra']['id']))
|
||||
{
|
||||
$cells .= " id=\"".$cell['extra']['id']."\"";
|
||||
}
|
||||
if(isset($cell['extra']['colspan']) && $cell['extra']['colspan'] > 1)
|
||||
{
|
||||
$cells .= " colspan=\"".$cell['extra']['colspan']."\"";
|
||||
}
|
||||
if(isset($cell['extra']['rowspan']) && $cell['extra']['rowspan'] > 1)
|
||||
{
|
||||
$cells .= " rowspan=\"".$cell['extra']['rowspan']."\"";
|
||||
}
|
||||
if(isset($cell['extra']['width']))
|
||||
{
|
||||
$cells .= " width=\"".$cell['extra']['width']."\"";
|
||||
}
|
||||
$cells .= ">";
|
||||
$cells .= $cell['data'];
|
||||
$cells .= "</td>\n";
|
||||
}
|
||||
$data['cells'] = $cells;
|
||||
$data['extra'] = $extra;
|
||||
$this->_rows[] = $data;
|
||||
|
||||
$this->_cells = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* return the cells of a row for the table based row.
|
||||
*
|
||||
* @param string $row_id The id of the row you want to give it.
|
||||
* @param boolean $return Whether or not to return or echo the resultant contents.
|
||||
* @return string The output of the row cells (optional).
|
||||
*/
|
||||
function output_row_cells($row_id, $return=false)
|
||||
{
|
||||
$row = $this->_rows[$row_id]['cells'];
|
||||
|
||||
if(!$return)
|
||||
{
|
||||
echo $row;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of rows in the table. Useful for displaying a 'no rows' message.
|
||||
*
|
||||
* @return int The number of rows in the table.
|
||||
*/
|
||||
function num_rows()
|
||||
{
|
||||
return count($this->_rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a header cell for this table.
|
||||
*
|
||||
* @param string $data The HTML content for this header cell.
|
||||
* @param array $extra Array of extra information for this header cell (class, style, colspan, width)
|
||||
*/
|
||||
function construct_header($data, $extra=array())
|
||||
{
|
||||
$this->_headers[] = array("data" => $data, "extra" => $extra);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output this table to the browser.
|
||||
*
|
||||
* @param string $heading The heading for this table.
|
||||
* @param int $border The border width for this table.
|
||||
* @param string $class The class for this table.
|
||||
* @param boolean $return Whether or not to return or echo the resultant contents.
|
||||
* @return string The output of the row cells (optional).
|
||||
*/
|
||||
function output($heading="", $border=1, $class="general", $return=false)
|
||||
{
|
||||
if($return == true)
|
||||
{
|
||||
return $this->construct_html($heading, $border, $class);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $this->construct_html($heading, $border, $class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the built HTML for this table.
|
||||
*
|
||||
* @param string $heading The heading for this table.
|
||||
* @param int $border The border width for this table.
|
||||
* @param string $class The class for this table.
|
||||
* @param string $table_id The id for this table.
|
||||
* @return string The built HTML.
|
||||
*/
|
||||
function construct_html($heading="", $border=1, $class=null, $table_id="")
|
||||
{
|
||||
$table = '';
|
||||
if($border == 1)
|
||||
{
|
||||
$table .= "<div class=\"border_wrapper\">\n";
|
||||
if($heading != "")
|
||||
{
|
||||
$table .= " <div class=\"title\">".$heading."</div>\n";
|
||||
}
|
||||
}
|
||||
$table .= "<table";
|
||||
if(!is_null($class))
|
||||
{
|
||||
if(!$class)
|
||||
{
|
||||
$class = "general";
|
||||
}
|
||||
$table .= " class=\"".$class."\"";
|
||||
}
|
||||
if($table_id != "")
|
||||
{
|
||||
$table .= " id=\"".$table_id."\"";
|
||||
}
|
||||
$table .= " cellspacing=\"0\">\n";
|
||||
if($this->_headers)
|
||||
{
|
||||
$table .= "\t<thead>\n";
|
||||
$table .= "\t\t<tr>\n";
|
||||
foreach($this->_headers as $key => $data)
|
||||
{
|
||||
$table .= "\t\t\t<th";
|
||||
if($key == 0)
|
||||
{
|
||||
$data['extra']['class'] .= " first";
|
||||
}
|
||||
elseif(!isset($this->_headers[$key+1]))
|
||||
{
|
||||
$data['extra']['class'] .= " last";
|
||||
}
|
||||
if(isset($data['extra']['class']))
|
||||
{
|
||||
$table .= " class=\"".$data['extra']['class']."\"";
|
||||
}
|
||||
if(isset($data['extra']['style']))
|
||||
{
|
||||
$table .= " style=\"".$data['extra']['style']."\"";
|
||||
}
|
||||
if(isset($data['extra']['width']))
|
||||
{
|
||||
$table .= " width=\"".$data['extra']['width']."\"";
|
||||
}
|
||||
if(isset($data['extra']['colspan']) && $data['extra']['colspan'] > 1)
|
||||
{
|
||||
$table .= " colspan=\"".$data['extra']['colspan']."\"";
|
||||
}
|
||||
$table .= ">".$data['data']."</th>\n";
|
||||
}
|
||||
$table .= "\t\t</tr>\n";
|
||||
$table .= "\t</thead>\n";
|
||||
}
|
||||
$table .= "\t<tbody>\n";
|
||||
$i = 1;
|
||||
foreach($this->_rows as $key => $table_row)
|
||||
{
|
||||
$table .= "\t\t<tr";
|
||||
if(isset($table_row['extra']['id']))
|
||||
{
|
||||
$table .= " id=\"{$table_row['extra']['id']}\"";
|
||||
}
|
||||
|
||||
if(!isset($table_row['extra']['class']))
|
||||
{
|
||||
$table_row['extra']['class'] = '';
|
||||
}
|
||||
|
||||
if($key == 0)
|
||||
{
|
||||
$table_row['extra']['class'] .= " first";
|
||||
}
|
||||
else if(!isset($this->_rows[$key+1]))
|
||||
{
|
||||
$table_row['extra']['class'] .= " last";
|
||||
}
|
||||
if($i == 2 && !isset($table_row['extra']['no_alt_row']))
|
||||
{
|
||||
$table_row['extra']['class'] .= " alt_row";
|
||||
$i = 0;
|
||||
}
|
||||
$i++;
|
||||
if($table_row['extra']['class'])
|
||||
{
|
||||
$table .= " class=\"".trim($table_row['extra']['class'])."\"";
|
||||
}
|
||||
$table .= ">\n";
|
||||
$table .= $table_row['cells'];
|
||||
$table .= "\t\t</tr>\n";
|
||||
}
|
||||
$table .= "\t</tbody>\n";
|
||||
$table .= "</table>\n";
|
||||
// Clean up
|
||||
$this->_cells = $this->_rows = $this->_headers = array();
|
||||
if($border == 1)
|
||||
{
|
||||
$table .= "</div>";
|
||||
}
|
||||
return $table;
|
||||
}
|
||||
}
|
||||
830
webroot/forum/admin/inc/functions.php
Normal file
830
webroot/forum/admin/inc/functions.php
Normal file
@@ -0,0 +1,830 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Logs an administrator action taking any arguments as log data.
|
||||
*/
|
||||
function log_admin_action()
|
||||
{
|
||||
global $db, $mybb;
|
||||
|
||||
$data = func_get_args();
|
||||
|
||||
if(count($data) == 1 && is_array($data[0]))
|
||||
{
|
||||
$data = $data[0];
|
||||
}
|
||||
|
||||
if(!is_array($data))
|
||||
{
|
||||
$data = array($data);
|
||||
}
|
||||
|
||||
$log_entry = array(
|
||||
"uid" => (int)$mybb->user['uid'],
|
||||
"ipaddress" => $db->escape_binary(my_inet_pton(get_ip())),
|
||||
"dateline" => TIME_NOW,
|
||||
"module" => $db->escape_string($mybb->get_input('module')),
|
||||
"action" => $db->escape_string($mybb->get_input('action')),
|
||||
"data" => $db->escape_string(@my_serialize($data))
|
||||
);
|
||||
|
||||
$db->insert_query("adminlog", $log_entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects the current user to a specified URL.
|
||||
*
|
||||
* @param string $url The URL to redirect to
|
||||
*/
|
||||
function admin_redirect($url)
|
||||
{
|
||||
if(!headers_sent())
|
||||
{
|
||||
$url = str_replace("&", "&", $url);
|
||||
header("Location: $url");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<meta http-equiv=\"refresh\" content=\"0; url={$url}\">";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an administration session data array.
|
||||
*
|
||||
* @param string $name The name of the item in the data session to update
|
||||
* @param mixed $value The value
|
||||
*/
|
||||
function update_admin_session($name, $value)
|
||||
{
|
||||
global $db, $admin_session;
|
||||
|
||||
$admin_session['data'][$name] = $value;
|
||||
$updated_session = array(
|
||||
"data" => $db->escape_string(@my_serialize($admin_session['data']))
|
||||
);
|
||||
$db->update_query("adminsessions", $updated_session, "sid='{$admin_session['sid']}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a "flash message" for the current user to be shown on their next page visit.
|
||||
*
|
||||
* @param string $message The message to show
|
||||
* @param string $type The type of message to be shown (success|error)
|
||||
*/
|
||||
function flash_message($message, $type='')
|
||||
{
|
||||
$flash = array('message' => $message, 'type' => $type);
|
||||
update_admin_session('flash_message', $flash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw pagination for pages in the Admin CP.
|
||||
*
|
||||
* @param int $page The current page we're on
|
||||
* @param int $per_page The number of items per page
|
||||
* @param int $total_items The total number of items in this collection
|
||||
* @param string $url The URL for pagination of this collection
|
||||
* @return string The built pagination
|
||||
*/
|
||||
function draw_admin_pagination($page, $per_page, $total_items, $url)
|
||||
{
|
||||
global $mybb, $lang;
|
||||
|
||||
if($total_items <= $per_page)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$pages = ceil($total_items / $per_page);
|
||||
|
||||
$pagination = "<div class=\"pagination\"><span class=\"pages\">{$lang->pages}: </span>\n";
|
||||
|
||||
if($page > 1)
|
||||
{
|
||||
$prev = $page-1;
|
||||
$prev_page = fetch_page_url($url, $prev);
|
||||
$pagination .= "<a href=\"{$prev_page}\" class=\"pagination_previous\">« {$lang->previous}</a> \n";
|
||||
}
|
||||
|
||||
// Maximum number of "page bits" to show
|
||||
if(!$mybb->settings['maxmultipagelinks'])
|
||||
{
|
||||
$mybb->settings['maxmultipagelinks'] = 5;
|
||||
}
|
||||
|
||||
$max_links = $mybb->settings['maxmultipagelinks'];
|
||||
|
||||
$from = $page-floor($mybb->settings['maxmultipagelinks']/2);
|
||||
$to = $page+floor($mybb->settings['maxmultipagelinks']/2);
|
||||
|
||||
if($from <= 0)
|
||||
{
|
||||
$from = 1;
|
||||
$to = $from+$max_links-1;
|
||||
}
|
||||
|
||||
if($to > $pages)
|
||||
{
|
||||
$to = $pages;
|
||||
$from = $pages-$max_links+1;
|
||||
if($from <= 0)
|
||||
{
|
||||
$from = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if($to == 0)
|
||||
{
|
||||
$to = $pages;
|
||||
}
|
||||
|
||||
if($from > 2)
|
||||
{
|
||||
$first = fetch_page_url($url, 1);
|
||||
$pagination .= "<a href=\"{$first}\" title=\"{$lang->page} 1\" class=\"pagination_first\">1</a> ... ";
|
||||
}
|
||||
|
||||
for($i = $from; $i <= $to; ++$i)
|
||||
{
|
||||
$page_url = fetch_page_url($url, $i);
|
||||
if($page == $i)
|
||||
{
|
||||
$pagination .= "<span class=\"pagination_current\">{$i}</span> \n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$pagination .= "<a href=\"{$page_url}\" title=\"{$lang->page} {$i}\">{$i}</a> \n";
|
||||
}
|
||||
}
|
||||
|
||||
if($to < $pages)
|
||||
{
|
||||
$last = fetch_page_url($url, $pages);
|
||||
$pagination .= "... <a href=\"{$last}\" title=\"{$lang->page} {$pages}\" class=\"pagination_last\">{$pages}</a>";
|
||||
}
|
||||
|
||||
if($page < $pages)
|
||||
{
|
||||
$next = $page+1;
|
||||
$next_page = fetch_page_url($url, $next);
|
||||
$pagination .= " <a href=\"{$next_page}\" class=\"pagination_next\">{$lang->next} »</a>\n";
|
||||
}
|
||||
$pagination .= "</div>\n";
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a CSV parent list for a particular forum.
|
||||
*
|
||||
* @param int $fid The forum ID
|
||||
* @param string $navsep Optional separator - defaults to comma for CSV list
|
||||
* @return string The built parent list
|
||||
*/
|
||||
function make_parent_list($fid, $navsep=",")
|
||||
{
|
||||
global $pforumcache, $db;
|
||||
|
||||
if(!$pforumcache)
|
||||
{
|
||||
$query = $db->simple_select("forums", "name, fid, pid", "", array("order_by" => "disporder, pid"));
|
||||
while($forum = $db->fetch_array($query))
|
||||
{
|
||||
$pforumcache[$forum['fid']][$forum['pid']] = $forum;
|
||||
}
|
||||
}
|
||||
|
||||
reset($pforumcache);
|
||||
reset($pforumcache[$fid]);
|
||||
|
||||
foreach($pforumcache[$fid] as $key => $forum)
|
||||
{
|
||||
if($fid == $forum['fid'])
|
||||
{
|
||||
if($pforumcache[$forum['pid']])
|
||||
{
|
||||
$navigation = make_parent_list($forum['pid'], $navsep).$navigation;
|
||||
}
|
||||
|
||||
if($navigation)
|
||||
{
|
||||
$navigation .= $navsep;
|
||||
}
|
||||
$navigation .= $forum['fid'];
|
||||
}
|
||||
}
|
||||
return $navigation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $fid
|
||||
*/
|
||||
function save_quick_perms($fid)
|
||||
{
|
||||
global $db, $inherit, $canview, $canpostthreads, $canpostreplies, $canpostpolls, $canpostattachments, $cache;
|
||||
|
||||
$permission_fields = array();
|
||||
|
||||
$field_list = $db->show_fields_from("forumpermissions");
|
||||
foreach($field_list as $field)
|
||||
{
|
||||
if(strpos($field['Field'], 'can') !== false || strpos($field['Field'], 'mod') !== false)
|
||||
{
|
||||
$permission_fields[$field['Field']] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// "Can Only View Own Threads" and "Can Only Reply Own Threads" permissions are forum permission only options
|
||||
$usergroup_permission_fields = $permission_fields;
|
||||
unset($usergroup_permission_fields['canonlyviewownthreads']);
|
||||
unset($usergroup_permission_fields['canonlyreplyownthreads']);
|
||||
|
||||
$query = $db->simple_select("usergroups", "gid");
|
||||
while($usergroup = $db->fetch_array($query))
|
||||
{
|
||||
$query2 = $db->simple_select("forumpermissions", $db->escape_string(implode(',', array_keys($permission_fields))), "fid='{$fid}' AND gid='{$usergroup['gid']}'", array('limit' => 1));
|
||||
$existing_permissions = $db->fetch_array($query2);
|
||||
|
||||
if(!$existing_permissions)
|
||||
{
|
||||
$query2 = $db->simple_select("usergroups", $db->escape_string(implode(',', array_keys($usergroup_permission_fields))), "gid='{$usergroup['gid']}'", array('limit' => 1));
|
||||
$existing_permissions = $db->fetch_array($query2);
|
||||
}
|
||||
|
||||
// Delete existing permissions
|
||||
$db->delete_query("forumpermissions", "fid='{$fid}' AND gid='{$usergroup['gid']}'");
|
||||
|
||||
// Only insert the new ones if we're using custom permissions
|
||||
if($inherit[$usergroup['gid']] != 1)
|
||||
{
|
||||
if($canview[$usergroup['gid']] == 1)
|
||||
{
|
||||
$pview = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pview = 0;
|
||||
}
|
||||
|
||||
if($canpostthreads[$usergroup['gid']] == 1)
|
||||
{
|
||||
$pthreads = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pthreads = 0;
|
||||
}
|
||||
|
||||
if($canpostreplies[$usergroup['gid']] == 1)
|
||||
{
|
||||
$preplies = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$preplies = 0;
|
||||
}
|
||||
|
||||
if($canpostpolls[$usergroup['gid']] == 1)
|
||||
{
|
||||
$ppolls = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ppolls = 0;
|
||||
}
|
||||
|
||||
if(!$preplies && !$pthreads)
|
||||
{
|
||||
$ppost = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ppost = 1;
|
||||
}
|
||||
|
||||
$insertquery = array(
|
||||
"fid" => (int)$fid,
|
||||
"gid" => (int)$usergroup['gid'],
|
||||
"canview" => (int)$pview,
|
||||
"canpostthreads" => (int)$pthreads,
|
||||
"canpostreplys" => (int)$preplies,
|
||||
"canpostpolls" => (int)$ppolls,
|
||||
);
|
||||
|
||||
foreach($permission_fields as $field => $value)
|
||||
{
|
||||
if(array_key_exists($field, $insertquery))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$insertquery[$db->escape_string($field)] = (int)$existing_permissions[$field];
|
||||
}
|
||||
|
||||
$db->insert_query("forumpermissions", $insertquery);
|
||||
}
|
||||
}
|
||||
$cache->update_forumpermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a particular user has the necessary permissions to access a particular page.
|
||||
*
|
||||
* @param array $action Array containing module and action to check for
|
||||
* @param bool $error
|
||||
* @return bool
|
||||
*/
|
||||
function check_admin_permissions($action, $error = true)
|
||||
{
|
||||
global $mybb, $page, $lang, $modules_dir;
|
||||
|
||||
if(is_super_admin($mybb->user['uid']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
require_once $modules_dir."/".$action['module']."/module_meta.php";
|
||||
if(function_exists($action['module']."_admin_permissions"))
|
||||
{
|
||||
$func = $action['module']."_admin_permissions";
|
||||
$permissions = $func();
|
||||
if($permissions['permissions'][$action['action']] && $mybb->admin['permissions'][$action['module']][$action['action']] != 1)
|
||||
{
|
||||
if($error)
|
||||
{
|
||||
$page->output_header($lang->access_denied);
|
||||
$page->add_breadcrumb_item($lang->access_denied, "index.php?module=home-index");
|
||||
$page->output_error("<b>{$lang->access_denied}</b><ul><li style=\"list-style-type: none;\">{$lang->access_denied_desc}</li></ul>");
|
||||
$page->output_footer();
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the list of administrator permissions for a particular user or group
|
||||
*
|
||||
* @param int $get_uid The user ID to fetch permissions for
|
||||
* @param int $get_gid The (optional) group ID to fetch permissions for
|
||||
* @return array Array of permissions for specified user or group
|
||||
*/
|
||||
function get_admin_permissions($get_uid=0, $get_gid=0)
|
||||
{
|
||||
global $db, $mybb;
|
||||
|
||||
// Set UID and GID if none
|
||||
$uid = $get_uid;
|
||||
$gid = $get_gid;
|
||||
|
||||
$gid_array = array();
|
||||
|
||||
if($uid === 0)
|
||||
{
|
||||
$uid = $mybb->user['uid'];
|
||||
}
|
||||
|
||||
if(!$gid)
|
||||
{
|
||||
// Prepare user's groups since the group isn't specified
|
||||
$gid_array[] = (-1) * (int)$mybb->user['usergroup'];
|
||||
|
||||
if($mybb->user['additionalgroups'])
|
||||
{
|
||||
$additional_groups = explode(',', $mybb->user['additionalgroups']);
|
||||
|
||||
if(!empty($additional_groups))
|
||||
{
|
||||
// Make sure gids are negative
|
||||
foreach($additional_groups as $g)
|
||||
{
|
||||
$gid_array[] = (-1) * abs($g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Group is specified
|
||||
// Make sure gid is negative
|
||||
$gid_array[] = (-1) * abs($gid);
|
||||
}
|
||||
|
||||
// What are we trying to find?
|
||||
if($get_gid && !$get_uid)
|
||||
{
|
||||
// A group only
|
||||
|
||||
$options = array(
|
||||
"order_by" => "uid",
|
||||
"order_dir" => "ASC",
|
||||
"limit" => "1"
|
||||
);
|
||||
$query = $db->simple_select("adminoptions", "permissions", "(uid='-{$get_gid}' OR uid='0') AND permissions != ''", $options);
|
||||
return my_unserialize($db->fetch_field($query, "permissions"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// A user and/or group
|
||||
|
||||
$options = array(
|
||||
"order_by" => "uid",
|
||||
"order_dir" => "DESC"
|
||||
);
|
||||
|
||||
// Prepare user's groups into SQL format
|
||||
$group_sql = '';
|
||||
foreach($gid_array as $gid)
|
||||
{
|
||||
$group_sql .= " OR uid='{$gid}'";
|
||||
}
|
||||
|
||||
$perms_group = array();
|
||||
$query = $db->simple_select("adminoptions", "permissions, uid", "(uid='{$uid}'{$group_sql}) AND permissions != ''", $options);
|
||||
while($perm = $db->fetch_array($query))
|
||||
{
|
||||
$perm['permissions'] = my_unserialize($perm['permissions']);
|
||||
|
||||
// Sorting out which permission is which
|
||||
if($perm['uid'] > 0)
|
||||
{
|
||||
$perms_user = $perm;
|
||||
return $perms_user['permissions'];
|
||||
}
|
||||
elseif($perm['uid'] < 0)
|
||||
{
|
||||
$perms_group[] = $perm['permissions'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$perms_def = $perm['permissions'];
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out group permissions...ugh.
|
||||
foreach($perms_group as $gperms)
|
||||
{
|
||||
if(!isset($final_group_perms))
|
||||
{
|
||||
// Use this group as the base for admin group permissions
|
||||
$final_group_perms = $gperms;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Loop through each specific permission to find the highest permission
|
||||
foreach($gperms as $perm_name => $perm_value)
|
||||
{
|
||||
if($final_group_perms[$perm_name] != '1' && $perm_value == '1')
|
||||
{
|
||||
$final_group_perms[$perm_name] = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send specific user, or group permissions before default.
|
||||
// If user's permission are explicitly set, they've already been returned above.
|
||||
if(isset($final_group_perms))
|
||||
{
|
||||
return $final_group_perms;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $perms_def;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the iconv/mb encoding for a particular MySQL encoding
|
||||
*
|
||||
* @param string $mysql_encoding The MySQL encoding
|
||||
* @return string The iconv/mb encoding
|
||||
*/
|
||||
function fetch_iconv_encoding($mysql_encoding)
|
||||
{
|
||||
$mysql_encoding = explode("_", $mysql_encoding);
|
||||
switch($mysql_encoding[0])
|
||||
{
|
||||
case "utf8":
|
||||
return "utf-8";
|
||||
break;
|
||||
case "latin1":
|
||||
return "iso-8859-1";
|
||||
break;
|
||||
default:
|
||||
return $mysql_encoding[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds/Updates a Page/Tab to the permissions array in the adminoptions table
|
||||
*
|
||||
* @param string $tab The name of the tab that is being affected
|
||||
* @param string $page The name of the page being affected (optional - if not specified, will affect everything under the specified tab)
|
||||
* @param integer $default Default permissions for the page (1 for allowed - 0 for disallowed - -1 to remove)
|
||||
*/
|
||||
function change_admin_permission($tab, $page="", $default=1)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$query = $db->simple_select("adminoptions", "uid, permissions", "permissions != ''");
|
||||
while($adminoption = $db->fetch_array($query))
|
||||
{
|
||||
$adminoption['permissions'] = my_unserialize($adminoption['permissions']);
|
||||
|
||||
if($default == -1)
|
||||
{
|
||||
if(!empty($page))
|
||||
{
|
||||
unset($adminoption['permissions'][$tab][$page]);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($adminoption['permissions'][$tab]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!empty($page))
|
||||
{
|
||||
if($adminoption['uid'] == 0)
|
||||
{
|
||||
$adminoption['permissions'][$tab][$page] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$adminoption['permissions'][$tab][$page] = $default;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($adminoption['uid'] == 0)
|
||||
{
|
||||
$adminoption['permissions'][$tab]['tab'] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$adminoption['permissions'][$tab]['tab'] = $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db->update_query("adminoptions", array('permissions' => $db->escape_string(my_serialize($adminoption['permissions']))), "uid='{$adminoption['uid']}'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we have had too many attempts at logging into the ACP
|
||||
*
|
||||
* @param integer $uid The uid of the admin to check
|
||||
* @param boolean $return_num Return an array of the number of attempts and expiry time? (default false)
|
||||
* @return mixed Return an array if the second parameter is true, boolean otherwise.
|
||||
*/
|
||||
function login_attempt_check_acp($uid=0, $return_num=false)
|
||||
{
|
||||
global $db, $mybb;
|
||||
|
||||
$attempts['loginattempts'] = 0;
|
||||
|
||||
if($uid > 0)
|
||||
{
|
||||
$query = $db->simple_select("adminoptions", "loginattempts, loginlockoutexpiry", "uid='".(int)$uid."'", 1);
|
||||
$attempts = $db->fetch_array($query);
|
||||
}
|
||||
|
||||
if($attempts['loginattempts'] <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($mybb->settings['maxloginattempts'] > 0 && $attempts['loginattempts'] >= $mybb->settings['maxloginattempts'])
|
||||
{
|
||||
// Has the expiry dateline been set yet?
|
||||
if($attempts['loginlockoutexpiry'] == 0 && $return_num == false)
|
||||
{
|
||||
$db->update_query("adminoptions", array("loginlockoutexpiry" => TIME_NOW+((int)$mybb->settings['loginattemptstimeout']*60)), "uid='".(int)$uid."'");
|
||||
}
|
||||
|
||||
// Are we returning the # of login attempts?
|
||||
if($return_num == true)
|
||||
{
|
||||
return $attempts;
|
||||
}
|
||||
// Otherwise are we still locked out?
|
||||
else if($attempts['loginlockoutexpiry'] > TIME_NOW)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the administrator is on a mobile device
|
||||
*
|
||||
* @param string $useragent The useragent to be checked
|
||||
* @return boolean A true/false depending on if the administrator is on a mobile
|
||||
*/
|
||||
function is_mobile($useragent)
|
||||
{
|
||||
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $useragent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether there are any 'security' issues in templates via complex syntax
|
||||
*
|
||||
* @param string $template The template to be scanned
|
||||
* @return boolean A true/false depending on if an issue was detected
|
||||
*/
|
||||
function check_template($template)
|
||||
{
|
||||
// Check to see if our database password is in the template
|
||||
if(preg_match('#\$config\[(([\'|"]database[\'|"])|([^\'"].*?))\]\[(([\'|"](database|hostname|password|table_prefix|username)[\'|"])|([^\'"].*?))\]#i', $template))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// System calls via backtick
|
||||
if(preg_match('#\$\s*\{#', $template))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Any other malicious acts?
|
||||
// Courtesy of ZiNgA BuRgA
|
||||
if(preg_match("~\\{\\$.+?\\}~s", preg_replace('~\\{\\$+[a-zA-Z_][a-zA-Z_0-9]*((?:-\\>|\\:\\:)\\$*[a-zA-Z_][a-zA-Z_0-9]*|\\[\s*\\$*([\'"]?)[a-zA-Z_ 0-9 ]+\\2\\]\s*)*\\}~', '', $template)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a function to entirely delete a user's posts, and find the threads attached to them
|
||||
*
|
||||
* @param integer $uid The uid of the user
|
||||
* @param int $date A UNIX timestamp to delete posts that are older
|
||||
* @return array An array of threads to delete, threads/forums to recount
|
||||
*/
|
||||
function delete_user_posts($uid, $date)
|
||||
{
|
||||
global $db;
|
||||
$uid = (int)$uid;
|
||||
|
||||
// Build an array of posts to delete
|
||||
$postcache = array();
|
||||
$query = $db->simple_select("posts", "pid", "uid = '".$uid."' AND dateline < '".$date."'");
|
||||
while($post = $db->fetch_array($query))
|
||||
{
|
||||
$postcache[] = $post['pid'];
|
||||
}
|
||||
|
||||
if(!$db->num_rows($query))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
elseif(!empty($postcache))
|
||||
{
|
||||
// Let's start deleting posts
|
||||
$user_posts = implode(",", $postcache);
|
||||
$query = $db->query("
|
||||
SELECT p.pid, p.visible, f.usepostcounts, t.tid AS thread, t.firstpost, t.fid AS forum
|
||||
FROM ".TABLE_PREFIX."posts p
|
||||
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
|
||||
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
|
||||
WHERE p.pid IN ({$user_posts})
|
||||
");
|
||||
|
||||
$post_count = 0; // Collect the post number to deduct from the user's postcount
|
||||
$thread_list = array();
|
||||
$forum_list = array();
|
||||
$delete_thread_list = array();
|
||||
if(!$db->num_rows($query))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
while($post = $db->fetch_array($query))
|
||||
{
|
||||
if($post['usepostcounts'] != 0 && $post['visible'] != 0)
|
||||
{
|
||||
++$post_count;
|
||||
}
|
||||
|
||||
if($post['pid'] == $post['firstpost'])
|
||||
{
|
||||
$delete_thread_list[] = $post['thread'];
|
||||
}
|
||||
|
||||
if(!in_array($post['thread'], $thread_list) && !in_array($post['thread'], $delete_thread_list))
|
||||
{
|
||||
$thread_list[] = $post['thread']; // Threads that have been affected by this action, that aren't marked to be deleted
|
||||
}
|
||||
if(!in_array($post['forum'], $forum_list))
|
||||
{
|
||||
$forum_list[] = $post['forum']; // Forums that have been affected, too
|
||||
}
|
||||
|
||||
// Remove the attachments to this post, then delete the post
|
||||
remove_attachments($post['pid']);
|
||||
$db->delete_query("posts", "pid = '".$post['pid']."'");
|
||||
$db->delete_query("pollvotes", "pid = '".$post['pid']."'"); // Delete pollvotes attached to this post
|
||||
}
|
||||
|
||||
$db->update_query("users", array("postnum" => "postnum-".$post_count.""), "uid='".$uid."'", 1, true);
|
||||
|
||||
$to_return = array(
|
||||
'to_delete' => $delete_thread_list,
|
||||
'thread_update' => $thread_list,
|
||||
'forum_update' => $forum_list
|
||||
);
|
||||
|
||||
return $to_return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a selection JavaScript code for selectable groups/forums fields.
|
||||
*/
|
||||
function print_selection_javascript()
|
||||
{
|
||||
static $already_printed = false;
|
||||
|
||||
if($already_printed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$already_printed = true;
|
||||
|
||||
echo "<script type=\"text/javascript\">
|
||||
function checkAction(id)
|
||||
{
|
||||
var checked = '';
|
||||
|
||||
$('.'+id+'_forums_groups_check').each(function(e, val)
|
||||
{
|
||||
if($(this).prop('checked') == true)
|
||||
{
|
||||
checked = $(this).val();
|
||||
}
|
||||
});
|
||||
|
||||
$('.'+id+'_forums_groups').each(function(e)
|
||||
{
|
||||
$(this).hide();
|
||||
});
|
||||
|
||||
if($('#'+id+'_forums_groups_'+checked))
|
||||
{
|
||||
$('#'+id+'_forums_groups_'+checked).show();
|
||||
}
|
||||
}
|
||||
</script>";
|
||||
}
|
||||
|
||||
if(!function_exists('array_column'))
|
||||
{
|
||||
function array_column($input, $column_key)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
if(!is_array($input))
|
||||
{
|
||||
$input = array($input);
|
||||
}
|
||||
|
||||
foreach($input as $val)
|
||||
{
|
||||
if(is_array($val) && isset($val[$column_key]))
|
||||
{
|
||||
$values[] = $val[$column_key];
|
||||
}
|
||||
elseif(is_object($val) && isset($val->$column_key))
|
||||
{
|
||||
$values[] = $val->$column_key;
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
1606
webroot/forum/admin/inc/functions_themes.php
Normal file
1606
webroot/forum/admin/inc/functions_themes.php
Normal file
File diff suppressed because it is too large
Load Diff
674
webroot/forum/admin/inc/functions_view_manager.php
Normal file
674
webroot/forum/admin/inc/functions_view_manager.php
Normal file
@@ -0,0 +1,674 @@
|
||||
<?php
|
||||
/**
|
||||
* MyBB 1.8
|
||||
* Copyright 2014 MyBB Group, All Rights Reserved
|
||||
*
|
||||
* Website: http://www.mybb.com
|
||||
* License: http://www.mybb.com/about/license
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Builds the "view management" interface allowing administrators to edit their custom designed "views"
|
||||
*
|
||||
* @param string $base_url The base URL to this instance of the view manager
|
||||
* @param string $type The internal type identifier for this view
|
||||
* @param array $fields Array of fields this view supports
|
||||
* @param array $sort_options Array of possible sort options this view supports if any
|
||||
* @param string $conditions_callback Optional callback function which generates list of "conditions" for this view
|
||||
*/
|
||||
function view_manager($base_url, $type, $fields, $sort_options=array(), $conditions_callback="")
|
||||
{
|
||||
global $mybb, $db, $page, $lang;
|
||||
|
||||
$sub_tabs['views'] = array(
|
||||
'title' => $lang->views,
|
||||
'link' => "{$base_url}&action=views",
|
||||
'description' => $lang->views_desc
|
||||
);
|
||||
|
||||
$sub_tabs['create_view'] = array(
|
||||
'title' => $lang->create_new_view,
|
||||
'link' => "{$base_url}&action=views&do=add",
|
||||
'description' => $lang->create_new_view_desc
|
||||
);
|
||||
|
||||
$page->add_breadcrumb_item($lang->view_manager, 'index.php?module=user-users&action=views');
|
||||
|
||||
// Lang strings should be in global lang file
|
||||
|
||||
if($mybb->input['do'] == "set_default")
|
||||
{
|
||||
$query = $db->simple_select("adminviews", "vid, uid, visibility", "vid='".$mybb->get_input('vid', MyBB::INPUT_INT)."'");
|
||||
$admin_view = $db->fetch_array($query);
|
||||
|
||||
if(!$admin_view['vid'] || $admin_view['visibility'] == 1 && $mybb->user['uid'] != $admin_view['uid'])
|
||||
{
|
||||
flash_message($lang->error_invalid_admin_view, 'error');
|
||||
admin_redirect($base_url."&action=views");
|
||||
}
|
||||
set_default_view($type, $admin_view['vid']);
|
||||
flash_message($lang->succuss_view_set_as_default, 'success');
|
||||
admin_redirect($base_url."&action=views");
|
||||
}
|
||||
|
||||
if($mybb->input['do'] == "add")
|
||||
{
|
||||
if($mybb->request_method == "post")
|
||||
{
|
||||
if(!trim($mybb->input['title']))
|
||||
{
|
||||
$errors[] = $lang->error_missing_view_title;
|
||||
}
|
||||
if($mybb->input['fields_js'])
|
||||
{
|
||||
$mybb->input['fields'] = explode(",", $mybb->input['fields_js']);
|
||||
}
|
||||
if(is_array($mybb->input['fields']) && count($mybb->input['fields']) <= 0)
|
||||
{
|
||||
$errors[] = $lang->error_no_view_fields;
|
||||
}
|
||||
|
||||
if($mybb->get_input('perpage', MyBB::INPUT_INT) <= 0)
|
||||
{
|
||||
$errors[] = $lang->error_invalid_view_perpage;
|
||||
}
|
||||
|
||||
if(!in_array($mybb->input['sortby'], array_keys($sort_options)))
|
||||
{
|
||||
$errors[] = $lang->error_invalid_view_sortby;
|
||||
}
|
||||
|
||||
if($mybb->input['sortorder'] != "asc" && $mybb->input['sortorder'] != "desc")
|
||||
{
|
||||
$errors[] = $lang->error_invalid_view_sortorder;
|
||||
}
|
||||
|
||||
if($mybb->input['visibility'] == 0)
|
||||
{
|
||||
$mybb->input['visibility'] = 2;
|
||||
}
|
||||
|
||||
if(!$errors)
|
||||
{
|
||||
$new_view = array(
|
||||
"uid" => $mybb->user['uid'],
|
||||
"title" => $db->escape_string($mybb->input['title']),
|
||||
"type" => $type,
|
||||
"visibility" => $mybb->get_input('visibility', MyBB::INPUT_INT),
|
||||
"fields" => $db->escape_string(my_serialize($mybb->input['fields'])),
|
||||
"conditions" => $db->escape_string(my_serialize($mybb->input['conditions'])),
|
||||
"custom_profile_fields" => $db->escape_string(my_serialize($mybb->input['profile_fields'])),
|
||||
"sortby" => $db->escape_string($mybb->input['sortby']),
|
||||
"sortorder" => $db->escape_string($mybb->input['sortorder']),
|
||||
"perpage" => $mybb->get_input('perpage', MyBB::INPUT_INT),
|
||||
"view_type" => $db->escape_string($mybb->input['view_type'])
|
||||
);
|
||||
|
||||
$vid = $db->insert_query("adminviews", $new_view);
|
||||
|
||||
if($mybb->input['isdefault'])
|
||||
{
|
||||
set_default_view($type, $vid);
|
||||
}
|
||||
flash_message($lang->success_view_created, "success");
|
||||
admin_redirect($base_url."&vid={$vid}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mybb->input = array_merge($mybb->input, array('perpage' => 20));
|
||||
}
|
||||
|
||||
// Write in our JS based field selector
|
||||
$page->extra_header .= "<script src=\"jscripts/view_manager.js\" type=\"text/javascript\"></script>\n";
|
||||
|
||||
$page->add_breadcrumb_item($lang->create_new_view);
|
||||
$page->output_header($lang->create_new_view);
|
||||
|
||||
$form = new Form($base_url."&action=views&do=add", "post");
|
||||
|
||||
$page->output_nav_tabs($sub_tabs, 'create_view');
|
||||
|
||||
// If we have any error messages, show them
|
||||
if($errors)
|
||||
{
|
||||
$page->output_inline_error($errors);
|
||||
}
|
||||
|
||||
$form_container = new FormContainer($lang->create_new_view);
|
||||
$form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
|
||||
|
||||
if($mybb->input['visibility'] == 2)
|
||||
{
|
||||
$visibility_public_checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$visibility_private_checked = true;
|
||||
}
|
||||
|
||||
$visibility_options = array(
|
||||
$form->generate_radio_button("visibility", "1", "<strong>{$lang->private}</strong> - {$lang->private_desc}", array("checked" => $visibility_private_checked)),
|
||||
$form->generate_radio_button("visibility", "2", "<strong>{$lang->public}</strong> - {$lang->public_desc}", array("checked" => $visibility_public_checked))
|
||||
);
|
||||
$form_container->output_row($lang->visibility, "", implode("<br />", $visibility_options));
|
||||
|
||||
$form_container->output_row($lang->set_as_default_view, "", $form->generate_yes_no_radio("isdefault", $mybb->input['isdefault'], array('yes' => 1, 'no' => 0)));
|
||||
|
||||
if(count($sort_options) > 0)
|
||||
{
|
||||
$sort_directions = array(
|
||||
"asc" => $lang->ascending,
|
||||
"desc" => $lang->descending
|
||||
);
|
||||
$form_container->output_row($lang->sort_results_by, "", $form->generate_select_box('sortby', $sort_options, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('sortorder', $sort_directions, $mybb->input['sortorder'], array('id' => 'sortorder')), 'sortby');
|
||||
}
|
||||
|
||||
$form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $mybb->input['perpage'], array('id' => 'perpage', 'min' => 1)), 'perpage');
|
||||
|
||||
if($type == "user")
|
||||
{
|
||||
$form_container->output_row($lang->display_results_as, "", $form->generate_radio_button('view_type', 'table', $lang->table, array('checked' => ($mybb->input['view_type'] != "card" ? true : false)))."<br />".$form->generate_radio_button('view_type', 'card', $lang->business_card, array('checked' => ($mybb->input['view_type'] == "card" ? true : false))));
|
||||
}
|
||||
|
||||
$form_container->end();
|
||||
|
||||
$field_select .= "<div class=\"view_fields\">\n";
|
||||
$field_select .= "<div class=\"enabled\"><div class=\"fields_title\">{$lang->enabled}</div><ul id=\"fields_enabled\">\n";
|
||||
if(is_array($mybb->input['fields']))
|
||||
{
|
||||
foreach($mybb->input['fields'] as $field)
|
||||
{
|
||||
if($fields[$field])
|
||||
{
|
||||
$field_select .= "<li id=\"field-{$field}\">• {$fields[$field]['title']}</li>";
|
||||
$active[$field] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$field_select .= "</ul></div>\n";
|
||||
$field_select .= "<div class=\"disabled\"><div class=\"fields_title\">{$lang->disabled}</div><ul id=\"fields_disabled\">\n";
|
||||
foreach($fields as $key => $field)
|
||||
{
|
||||
if($active[$key])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$field_select .= "<li id=\"field-{$key}\">• {$field['title']}</li>";
|
||||
}
|
||||
$field_select .= "</div></ul>\n";
|
||||
$field_select .= $form->generate_hidden_field("fields_js", @implode(",", @array_keys($active)), array('id' => 'fields_js'));
|
||||
$field_select = str_replace("'", "\\'", $field_select);
|
||||
$field_select = str_replace("\n", "", $field_select);
|
||||
|
||||
$field_select = "<script type=\"text/javascript\">
|
||||
//<![CDATA[
|
||||
document.write('".str_replace("/", "\/", $field_select)."');
|
||||
//]]>
|
||||
</script>\n";
|
||||
|
||||
foreach($fields as $key => $field)
|
||||
{
|
||||
$field_options[$key] = $field['title'];
|
||||
}
|
||||
|
||||
$field_select .= "<noscript>".$form->generate_select_box('fields[]', $field_options, $mybb->input['fields'], array('id' => 'fields', 'multiple' => true))."</noscript>\n";
|
||||
|
||||
$form_container = new FormContainer($lang->fields_to_show);
|
||||
$form_container->output_row($lang->fields_to_show_desc, $description, $field_select);
|
||||
$form_container->end();
|
||||
|
||||
// Build the search conditions
|
||||
if(function_exists($conditions_callback))
|
||||
{
|
||||
$conditions_callback($mybb->input, $form);
|
||||
}
|
||||
|
||||
$buttons[] = $form->generate_submit_button($lang->save_view);
|
||||
$form->output_submit_wrapper($buttons);
|
||||
|
||||
$form->end();
|
||||
$page->output_footer();
|
||||
}
|
||||
else if($mybb->input['do'] == "edit")
|
||||
{
|
||||
$query = $db->simple_select("adminviews", "*", "vid='".$mybb->get_input('vid', MyBB::INPUT_INT)."'");
|
||||
$admin_view = $db->fetch_array($query);
|
||||
|
||||
// Does the view not exist?
|
||||
if(!$admin_view['vid'] || $admin_view['visibility'] == 1 && $mybb->user['uid'] != $admin_view['uid'])
|
||||
{
|
||||
flash_message($lang->error_invalid_admin_view, 'error');
|
||||
admin_redirect($base_url."&action=views");
|
||||
}
|
||||
|
||||
if($mybb->request_method == "post")
|
||||
{
|
||||
if(!trim($mybb->input['title']))
|
||||
{
|
||||
$errors[] = $lang->error_missing_view_title;
|
||||
}
|
||||
if($mybb->input['fields_js'])
|
||||
{
|
||||
$mybb->input['fields'] = explode(",", $mybb->input['fields_js']);
|
||||
}
|
||||
|
||||
if(is_array($mybb->input['fields']) && count($mybb->input['fields']) <= 0)
|
||||
{
|
||||
$errors[] = $lang->error_no_view_fields;
|
||||
}
|
||||
|
||||
if($mybb->get_input('perpage', MyBB::INPUT_INT) <= 0)
|
||||
{
|
||||
$errors[] = $lang->error_invalid_view_perpage;
|
||||
}
|
||||
|
||||
if(!in_array($mybb->input['sortby'], array_keys($sort_options)))
|
||||
{
|
||||
$errors[] = $lang->error_invalid_view_sortby;
|
||||
}
|
||||
|
||||
if($mybb->input['sortorder'] != "asc" && $mybb->input['sortorder'] != "desc")
|
||||
{
|
||||
$errors[] = $lang->error_invalid_view_sortorder;
|
||||
}
|
||||
|
||||
if($mybb->input['visibility'] == 0)
|
||||
{
|
||||
$mybb->input['visibility'] = 2;
|
||||
}
|
||||
|
||||
if(!$errors)
|
||||
{
|
||||
$updated_view = array(
|
||||
"title" => $db->escape_string($mybb->input['title']),
|
||||
"type" => $type,
|
||||
"visibility" => $mybb->get_input('visibility', MyBB::INPUT_INT),
|
||||
"fields" => $db->escape_string(my_serialize($mybb->input['fields'])),
|
||||
"conditions" => $db->escape_string(my_serialize($mybb->input['conditions'])),
|
||||
"custom_profile_fields" => $db->escape_string(my_serialize($mybb->input['profile_fields'])),
|
||||
"sortby" => $db->escape_string($mybb->input['sortby']),
|
||||
"sortorder" => $db->escape_string($mybb->input['sortorder']),
|
||||
"perpage" => $mybb->get_input('perpage', MyBB::INPUT_INT),
|
||||
"view_type" => $db->escape_string($mybb->input['view_type'])
|
||||
);
|
||||
$db->update_query("adminviews", $updated_view, "vid='{$admin_view['vid']}'");
|
||||
|
||||
if($mybb->input['isdefault'])
|
||||
{
|
||||
set_default_view($type, $admin_view['vid']);
|
||||
}
|
||||
|
||||
flash_message($lang->success_view_updated, "success");
|
||||
admin_redirect($base_url."&vid={$admin_view['vid']}");
|
||||
}
|
||||
}
|
||||
|
||||
// Write in our JS based field selector
|
||||
$page->extra_header .= "<script src=\"jscripts/view_manager.js\" type=\"text/javascript\"></script>\n";
|
||||
|
||||
$page->add_breadcrumb_item($lang->edit_view);
|
||||
$page->output_header($lang->edit_view);
|
||||
|
||||
$form = new Form($base_url."&action=views&do=edit&vid={$admin_view['vid']}", "post");
|
||||
|
||||
$sub_tabs = array();
|
||||
$sub_tabs['edit_view'] = array(
|
||||
'title' => $lang->edit_view,
|
||||
'link' => $base_url."&action=views&do=edit&vid={$admin_view['vid']}",
|
||||
'description' => $lang->edit_view_desc
|
||||
);
|
||||
|
||||
$page->output_nav_tabs($sub_tabs, 'edit_view');
|
||||
|
||||
// If we have any error messages, show them
|
||||
if($errors)
|
||||
{
|
||||
$page->output_inline_error($errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
$admin_view['conditions'] = my_unserialize($admin_view['conditions']);
|
||||
$admin_view['fields'] = my_unserialize($admin_view['fields']);
|
||||
$admin_view['profile_fields'] = my_unserialize($admin_view['custom_profile_fields']);
|
||||
$mybb->input = array_merge($mybb->input, $admin_view);
|
||||
|
||||
$mybb->input['isdefault'] = 0;
|
||||
$default_view = fetch_default_view($type);
|
||||
|
||||
if($default_view == $admin_view['vid'])
|
||||
{
|
||||
$mybb->input['isdefault'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$form_container = new FormContainer($lang->edit_view);
|
||||
$form_container->output_row($lang->view." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
|
||||
|
||||
if($mybb->input['visibility'] == 2)
|
||||
{
|
||||
$visibility_public_checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$visibility_private_checked = true;
|
||||
}
|
||||
|
||||
$visibility_options = array(
|
||||
$form->generate_radio_button("visibility", "1", "<strong>{$lang->private}</strong> - {$lang->private_desc}", array("checked" => $visibility_private_checked)),
|
||||
$form->generate_radio_button("visibility", "2", "<strong>{$lang->public}</strong> - {$lang->public_desc}", array("checked" => $visibility_public_checked))
|
||||
);
|
||||
$form_container->output_row($lang->visibility, "", implode("<br />", $visibility_options));
|
||||
|
||||
$form_container->output_row($lang->set_as_default_view, "", $form->generate_yes_no_radio("isdefault", $mybb->input['isdefault'], array('yes' => 1, 'no' => 0)));
|
||||
|
||||
if(is_array($sort_options) && count($sort_options) > 0)
|
||||
{
|
||||
$sort_directions = array(
|
||||
"asc" => $lang->ascending,
|
||||
"desc" => $lang->descending
|
||||
);
|
||||
$form_container->output_row($lang->sort_results_by, "", $form->generate_select_box('sortby', $sort_options, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('sortorder', $sort_directions, $mybb->input['sortorder'], array('id' => 'sortorder')), 'sortby');
|
||||
}
|
||||
|
||||
$form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $mybb->input['perpage'], array('id' => 'perpage', 'min' => 1)), 'perpage');
|
||||
|
||||
if($type == "user")
|
||||
{
|
||||
$form_container->output_row($lang->display_results_as, "", $form->generate_radio_button('view_type', 'table', $lang->table, array('checked' => ($mybb->input['view_type'] != "card" ? true : false)))."<br />".$form->generate_radio_button('view_type', 'card', $lang->business_card, array('checked' => ($mybb->input['view_type'] == "card" ? true : false))));
|
||||
}
|
||||
|
||||
$form_container->end();
|
||||
|
||||
$field_select .= "<div class=\"view_fields\">\n";
|
||||
$field_select .= "<div class=\"enabled\"><div class=\"fields_title\">{$lang->enabled}</div><ul id=\"fields_enabled\">\n";
|
||||
if(is_array($mybb->input['fields']))
|
||||
{
|
||||
foreach($mybb->input['fields'] as $field)
|
||||
{
|
||||
if($fields[$field])
|
||||
{
|
||||
$field_select .= "<li id=\"field-{$field}\">• {$fields[$field]['title']}</li>";
|
||||
$active[$field] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$field_select .= "</ul></div>\n";
|
||||
$field_select .= "<div class=\"disabled\"><div class=\"fields_title\">{$lang->disabled}</div><ul id=\"fields_disabled\">\n";
|
||||
if(is_array($fields))
|
||||
{
|
||||
foreach($fields as $key => $field)
|
||||
{
|
||||
if($active[$key])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$field_select .= "<li id=\"field-{$key}\">• {$field['title']}</li>";
|
||||
}
|
||||
}
|
||||
$field_select .= "</div></ul>\n";
|
||||
$field_select .= $form->generate_hidden_field("fields_js", @implode(",", @array_keys($active)), array('id' => 'fields_js'));
|
||||
$field_select = str_replace("'", "\\'", $field_select);
|
||||
$field_select = str_replace("\n", "", $field_select);
|
||||
|
||||
$field_select = "<script type=\"text/javascript\">
|
||||
//<![CDATA[
|
||||
document.write('".str_replace("/", "\/", $field_select)."');
|
||||
//]]></script>\n";
|
||||
|
||||
foreach($fields as $key => $field)
|
||||
{
|
||||
$field_options[$key] = $field['title'];
|
||||
}
|
||||
|
||||
$field_select .= "<noscript>".$form->generate_select_box('fields[]', $field_options, $mybb->input['fields'], array('id' => 'fields', 'multiple' => true))."</noscript>\n";
|
||||
|
||||
$form_container = new FormContainer($lang->fields_to_show);
|
||||
$form_container->output_row($lang->fields_to_show_desc, $description, $field_select);
|
||||
$form_container->end();
|
||||
|
||||
// Build the search conditions
|
||||
if(function_exists($conditions_callback))
|
||||
{
|
||||
$conditions_callback($mybb->input, $form);
|
||||
}
|
||||
|
||||
$buttons[] = $form->generate_submit_button($lang->save_view);
|
||||
$form->output_submit_wrapper($buttons);
|
||||
|
||||
$form->end();
|
||||
$page->output_footer();
|
||||
}
|
||||
|
||||
else if($mybb->input['do'] == "delete")
|
||||
{
|
||||
if($mybb->input['no'])
|
||||
{
|
||||
admin_redirect($base_url."&action=views");
|
||||
}
|
||||
|
||||
$query = $db->simple_select("adminviews", "COUNT(vid) as views");
|
||||
$views = $db->fetch_field($query, "views");
|
||||
|
||||
if($views == 0)
|
||||
{
|
||||
flash_message($lang->error_cannot_delete_view, 'error');
|
||||
admin_redirect($base_url."&action=views");
|
||||
}
|
||||
|
||||
$vid = $mybb->get_input('vid', MyBB::INPUT_INT);
|
||||
$query = $db->simple_select("adminviews", "vid, uid, visibility", "vid = '{$vid}'");
|
||||
$admin_view = $db->fetch_array($query);
|
||||
|
||||
if($vid == 1 || !$admin_view['vid'] || $admin_view['visibility'] == 1 && $mybb->user['uid'] != $admin_view['uid'])
|
||||
{
|
||||
flash_message($lang->error_invalid_view_delete, 'error');
|
||||
admin_redirect($base_url."&action=views");
|
||||
}
|
||||
|
||||
if($mybb->request_method == "post")
|
||||
{
|
||||
$db->delete_query("adminviews", "vid='{$admin_view['vid']}'");
|
||||
flash_message($lang->success_view_deleted, 'success');
|
||||
admin_redirect($base_url."&action=views");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->output_confirm_action($base_url."&action=views&do=delete&vid={$admin_view['vid']}", $lang->confirm_view_deletion);
|
||||
}
|
||||
}
|
||||
|
||||
// Export views
|
||||
else if($mybb->input['do'] == "export")
|
||||
{
|
||||
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?".">\n";
|
||||
$xml = "<adminviews version=\"".$mybb->version_code."\" exported=\"".TIME_NOW."\">\n";
|
||||
|
||||
if($mybb->input['type'])
|
||||
{
|
||||
$type_where = "type='".$db->escape_string($mybb->input['type'])."'";
|
||||
}
|
||||
|
||||
$query = $db->simple_select("adminviews", "*", $type_where);
|
||||
while($admin_view = $db->fetch_array($query))
|
||||
{
|
||||
$fields = my_unserialize($admin_view['fields']);
|
||||
$conditions = my_unserialize($admin_view['conditions']);
|
||||
|
||||
$admin_view['title'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['title']);
|
||||
$admin_view['sortby'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['sortby']);
|
||||
$admin_view['sortorder'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['sortorder']);
|
||||
$admin_view['view_type'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['view_type']);
|
||||
|
||||
$xml .= "\t<view vid=\"{$admin_view['vid']}\" uid=\"{$admin_view['uid']}\" type=\"{$admin_view['type']}\" visibility=\"{$admin_view['visibility']}\">\n";
|
||||
$xml .= "\t\t<title><![CDATA[{$admin_view['title']}]]></title>\n";
|
||||
$xml .= "\t\t<fields>\n";
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$xml .= "\t\t\t<field name=\"{$field}\" />\n";
|
||||
}
|
||||
$xml .= "\t\t</fields>\n";
|
||||
$xml .= "\t\t<conditions>\n";
|
||||
foreach($conditions as $name => $condition)
|
||||
{
|
||||
if(!$conditions) continue;
|
||||
if(is_array($condition))
|
||||
{
|
||||
$condition = my_serialize($condition);
|
||||
$is_serialized = " is_serialized=\"1\"";
|
||||
}
|
||||
$condition = str_replace(']]>', ']]]]><![CDATA[>', $condition);
|
||||
$xml .= "\t\t\t<condition name=\"{$name}\"{$is_serialized}><![CDATA[{$condition}]]></condition>\n";
|
||||
}
|
||||
$xml .= "\t\t</conditions>\n";
|
||||
$xml .= "\t\t<sortby><![CDATA[{$admin_view['sortby']}]]></sortby>\n";
|
||||
$xml .= "\t\t<sortorder><![CDATA[{$admin_view['sortorder']}]]></sortorder>\n";
|
||||
$xml .= "\t\t<perpage><![CDATA[{$admin_view['perpage']}]]></perpage>\n";
|
||||
$xml .= "\t\t<view_type><![CDATA[{$admin_view['view_type']}]]></view_type>\n";
|
||||
$xml .= "\t</view>\n";
|
||||
}
|
||||
$xml .= "</adminviews>\n";
|
||||
$mybb->settings['bbname'] = urlencode($mybb->settings['bbname']);
|
||||
header("Content-disposition: filename=".$mybb->settings['bbname']."-views.xml");
|
||||
header("Content-Length: ".my_strlen($xml));
|
||||
header("Content-type: unknown/unknown");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
echo $xml;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Generate a listing of all current views
|
||||
else
|
||||
{
|
||||
$page->output_header($lang->view_manager);
|
||||
|
||||
$page->output_nav_tabs($sub_tabs, 'views');
|
||||
|
||||
$table = new Table;
|
||||
$table->construct_header($lang->view);
|
||||
$table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
|
||||
|
||||
$default_view = fetch_default_view($type);
|
||||
|
||||
$query = $db->simple_select("adminviews", "COUNT(vid) as views");
|
||||
$views = $db->fetch_field($query, "views");
|
||||
|
||||
$query = $db->query("
|
||||
SELECT v.*, u.username
|
||||
FROM ".TABLE_PREFIX."adminviews v
|
||||
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=v.uid)
|
||||
WHERE v.visibility='2' OR (v.visibility='1' AND v.uid='{$mybb->user['uid']}')
|
||||
ORDER BY title
|
||||
");
|
||||
while($view = $db->fetch_array($query))
|
||||
{
|
||||
$created = "";
|
||||
if($view['uid'] == 0)
|
||||
{
|
||||
$view_type = "default";
|
||||
$default_class = "grey";
|
||||
}
|
||||
else if($view['visibility'] == 2)
|
||||
{
|
||||
$view_type = "group";
|
||||
if($view['username'])
|
||||
{
|
||||
$username = htmlspecialchars_uni($view['username']);
|
||||
$created = "<br /><small>{$lang->created_by} {$username}</small>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$view_type = "user";
|
||||
}
|
||||
|
||||
$default_add = '';
|
||||
if($default_view == $view['vid'])
|
||||
{
|
||||
$default_add = " ({$lang->default})";
|
||||
}
|
||||
|
||||
$title_string = "view_title_{$view['vid']}";
|
||||
|
||||
if($lang->$title_string)
|
||||
{
|
||||
$view['title'] = $lang->$title_string;
|
||||
}
|
||||
|
||||
$table->construct_cell("<div class=\"float_right\"><img src=\"styles/{$page->style}/images/icons/{$view_type}.png\" title=\"".$lang->sprintf($lang->this_is_a_view, $view_type)."\" alt=\"{$view_type}\" /></div><div class=\"{$default_class}\"><strong><a href=\"{$base_url}&action=views&do=edit&vid={$view['vid']}\" >{$view['title']}</a></strong>{$default_add}{$created}</div>");
|
||||
|
||||
$popup = new PopupMenu("view_{$view['vid']}", $lang->options);
|
||||
$popup->add_item($lang->edit_view, "{$base_url}&action=views&do=edit&vid={$view['vid']}");
|
||||
if($view['vid'] != $default_view)
|
||||
{
|
||||
$popup->add_item($lang->set_as_default, "{$base_url}&action=views&do=set_default&vid={$view['vid']}");
|
||||
}
|
||||
|
||||
if($views > 1 && $view['vid'] != 1)
|
||||
{
|
||||
$popup->add_item($lang->delete_view, "{$base_url}&action=views&do=delete&vid={$view['vid']}&my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_view_deletion}')");
|
||||
}
|
||||
$controls = $popup->fetch();
|
||||
$table->construct_cell($controls, array("class" => "align_center"));
|
||||
$table->construct_row();
|
||||
}
|
||||
|
||||
$table->output($lang->view);
|
||||
|
||||
echo <<<LEGEND
|
||||
<br />
|
||||
<fieldset>
|
||||
<legend>{$lang->legend}</legend>
|
||||
<img src="styles/{$page->style}/images/icons/default.png" alt="{$lang->default}" style="vertical-align: middle;" /> {$lang->default_view_desc}<br />
|
||||
<img src="styles/{$page->style}/images/icons/group.png" alt="{$lang->public}" style="vertical-align: middle;" /> {$lang->public_view_desc}<br />
|
||||
<img src="styles/{$page->style}/images/icons/user.png" alt="{$lang->private}" style="vertical-align: middle;" /> {$lang->private_view_desc}</fieldset>
|
||||
LEGEND;
|
||||
$page->output_footer();
|
||||
}
|
||||
}
|
||||
|
||||
function set_default_view($type, $vid)
|
||||
{
|
||||
global $mybb, $db;
|
||||
|
||||
$query = $db->simple_select("adminoptions", "defaultviews", "uid='{$mybb->user['uid']}'");
|
||||
$default_views = my_unserialize($db->fetch_field($query, "defaultviews"));
|
||||
if(!$db->num_rows($query))
|
||||
{
|
||||
$create = true;
|
||||
}
|
||||
$default_views[$type] = $vid;
|
||||
$default_views = my_serialize($default_views);
|
||||
$updated_admin = array("defaultviews" => $db->escape_string($default_views));
|
||||
|
||||
if($create == true)
|
||||
{
|
||||
$updated_admin['uid'] = $mybb->user['uid'];
|
||||
$updated_admin['notes'] = '';
|
||||
$updated_admin['permissions'] = '';
|
||||
$db->insert_query("adminoptions", $updated_admin);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->update_query("adminoptions", $updated_admin, "uid='{$mybb->user['uid']}'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool|array
|
||||
*/
|
||||
function fetch_default_view($type)
|
||||
{
|
||||
global $mybb, $db;
|
||||
$query = $db->simple_select("adminoptions", "defaultviews", "uid='{$mybb->user['uid']}'");
|
||||
$default_views = my_unserialize($db->fetch_field($query, "defaultviews"));
|
||||
if(!is_array($default_views))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $default_views[$type];
|
||||
}
|
||||
8
webroot/forum/admin/inc/index.html
Normal file
8
webroot/forum/admin/inc/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user