@ 2014-09-03T20:46:42Z <?
require './shared_lib/core.php';
$admin = ($_SERVER['REMOTE_ADDR'] !== '82.19.119.31') ?false:true; //stderr('Error','Access Denied');
init();
$actions = array('/index.php?action=new'=>'New');
if (isset($_REQUEST['id']) && is_valid_id($_REQUEST['id'])) $actions = array_merge($actions, array('/index.php?action=edit&id='.$_REQUEST['id']=>'Edit','/index.php?action=delete&id='.$_REQUEST['id']=>'Delete'));
$action = isset($_REQUEST['action']) && in_array(ucfirst($_REQUEST['action']),$actions) ? ucfirst($_REQUEST['action']) : '';
$opts = array('js'=>array('jquery.markitup','bbcode'));
$form = array('news','id,userid,added,body,title', 'WHERE class >= ', // for permissions for edit/new ... will be done via permissions system so in php
array('id'=>'primary|int',
'userid'=>'int|validid',
'added'=>'now',
'title'=>'trim|htmlspecialchars|sqlesc',
'body'=>'bbcode'),
array('',array(
8=>array('title','text')))
);
// convert datetime to unixtimestamp
/* comments_torrents, requests etc // parent just id of parent, in php put as subarray when doing query (sort by id desc) and then in displaying
use media object <li> for proper nesting display... done ;)
$form = array('comments_*','id,userid,pid,added,body,editedby,editdat,parent',
array('id'=>'primary','userid'=>'int|validid','pid'=>'int|validid','added'=>'new_now','body'=>'bbcode','editedby'=>'curuser','editdat'=>'now',
'parent'=>'id|validid'),
// look array
....
);
*/
// manage_form($form)
// if we have bbcode parsing
if ($action) {
if ($_SERVER['REQUEST_METHOD'] === 'POST')
require './shared_lib/bb/bbparse.php';
if ($_SERVER['REQUEST_METHOD'] === 'GET' || $action === 'Edit')
require './shared_lib/bb/bbinput.php';
}
$exclude = array('id','userid');
$arr = explode(',',$form[1]);
$table = $form[0];
if ($action === 'New') {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $admin) {
foreach ($arr as $r) {
if (!in_array($r,$exclude)) {
$tmp = isset($_REQUEST[$r]) ? $_REQUEST[$r] : -1;
/*
if (isset($checks[$r])) {
$chk = explode('|', $checks[$r]);
$tmp = validate(array($r,$tmp), $chk);
if (is_array($tmp) && count($tmp['errors']))
$errors[] = $tmp['errors'];
else $q[$r] = $tmp['value'];
}
else*/
switch ($r) { // temp
case 'added': $tmp = 'NOW()';$q[$r] = $tmp; break;
case 'body': $tmp = bb2html($tmp);
default: $q[$r] = sqlesc($tmp);
}
}
}
$f = array_keys($q);
$r = do_mysql_query('INSERT INTO '.$table.' ('.implode(', ',$f).') VALUES ('.implode(', ',$q).')') or sqlerr(__FILE__,__LINE__,$actions);
if (mysql_affected_rows()) stderr('Success','Well done');
else stderr('Error','Failed');
}
stdhead('New Blog Post',$actions, $opts);
start_container('new_blog');
// form functions
// 'horizontal', 'post','action'
// title=>text, bbcode, button=>submit
$content = print_form('new');
grid(array(array('',array(12=>$content))));
end_container();
stdfoot();
}
else if ($action === 'Edit' && $admin) {
$id = isset($_REQUEST['id']) ? (int)$_REQUEST['id'] : 0;
if (!$id) stderr('Error','Invalid ID');
$res = do_mysql_query('SELECT '.$form[1].',UNIX_TIMESTAMP(added) uadded FROM '.$table.' WHERE id='.$id) or sqlerr(__FILE__,__LINE__, $actions);
if (mysql_num_rows($res) == 0) stderr('Error','Not Found!');
$vars = mysql_fetch_array($res);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$q = array();
foreach ($arr as $r) {
if (!in_array($r,$exclude)) {
$tmp = isset($_REQUEST[$r]) ? $_REQUEST[$r] : -1;
/*
if (isset($checks[$r])) {
$chk = explode('|', $checks[$r]);
$tmp = validate(array($r,$tmp), $chk);
if (is_array($tmp) && count($tmp['errors']))
$errors[] = $tmp['errors'];
else $q[$r] = $tmp['value'];
}
else*/
switch ($r) { // temp
case 'added': break; /*$tmp = 'NOW()';$q[$r] = $tmp; break;*/
case 'body': if ($vars['body'] === $tmp) break; $tmp = bb2html($tmp,$table.$id);
default: if ($vars[$r] === $tmp) break; $q[$r] = sqlesc($tmp);
}
}
}
if (sizeof($q) === 0) stderr('Error','No Changes found!');
$f = '';
foreach ($q as $r => $v) $f .= ($f?',':'').$r.'='.$v;
$r = do_mysql_query('UPDATE '.$table.' SET '.$f.' WHERE id='.$id) or sqlerr(__FILE__,__LINE__,$actions);
if (mysql_affected_rows()) stderr('Success','Well done');
else stderr('Error','Failed');
}
$vars['body'] = html2bb($vars['body'],$table.$id);
stdhead('Edit Blog Post',$actions, $opts);
start_container('new_blog');
// form functions
// 'horizontal', 'post','action'
// title=>text, bbcode, button=>submit
$content = print_form('edit',$vars);
grid(array(array('',array(12=>$content))));
end_container();
stdfoot();
}
else if ($action === 'Delete') {
// have to add mkd5 key to prevent replay attacks etc
if (isset($_REQUEST['id']) && is_valid_id($_REQUEST['id'])) {
$r = do_mysql_query('SELECT '.$form[1].' FROM '.$table.' WHERE id='.$_REQUEST['id']) or sqlerr(__FILE__,__LINE__);
if (!mysql_num_rows($r))
stderr('Error','Not Found!',$actions);
else {
$r = mysql_fetch_array($r);
if (isset($_REQUEST['sure']) && $_REQUEST['sure'] == 1) {
do_mysql_query('DELETE FROM '.$table.' WHERE id='.(int)$_REQUEST['id']) or sqlerr(__FILE__,__LINE__);
stderr('Success',$table.' was deleted',$actions);
}
else stderr('Are you sure? ','Click <a href="?q='.$table.'&action=delete&sure=1&id='.(int)$_REQUEST['id'].'">HERE</a> if you are certain you wnat to delete \'<strong>'.$r['title'].'</strong>\'',$actions);
}
}
}
$main = $side = '';
$res = do_mysql_query('SELECT '.$form[1].',UNIX_TIMESTAMP(added) uadded FROM '.$table.' ORDER BY added DESC') or sqlerr(__FILE__,__LINE__, $actions);
if (mysql_num_rows($res) === 0) $main = alert('Error','No News','warning');
else while ($arr= mysql_fetch_array($res)) {
$main .= '<div class="blog-post" id="bpp'.$arr['id'].'">'.
h(
make_links(array('#bpp'.$arr['id']=>array($arr['title'],array('id'=>'bl'.$arr['id'],'data-toggle'=>'collapse','data-target'=>'#bp'.$arr['id']))),' '),
2,array('class'=>'blog-post-title','id'=>'bt'.$arr['id'])
).
'<div class="blog-post-meta">'.$arr['added'].' ('.get_elapsed_time($arr['uadded']).' ago} by '.$arr['userid'].
'<span class="blog-controls">'.
make_links(array('index.php?action=edit&id='.$arr['id']=>array(icon('edit','',array('class'=>'control')),array('class'=>'url','title'=>'Edit Post')),'index.php?action=delete&id='.$arr['id']=>array(icon('remove','',array('class'=>'control')),array('title'=>'Remove Post','class'=>'url'))),' ').
'</span></div><div id="bp'.$arr['id'].'" class="collapse in">'.
$arr['body'].
'</div></div>';
}
$page = array(array('',array(8=>$main),array(4=>$side)));
stdhead('Welcome', $actions);
start_container('blog');
grid($page);
end_container();
/*
start_container('table');
drawtable(do_mysql_query('SELECT * FROM news'));
end_container();
*/
stdfoot();
function print_form($action, $vars = array()) {
$form_id = 'body';
$ex = ($action === 'edit' && ($id = $vars['id'])) ? '<input type="hidden" name="id" value="'.$id.'">' : '';
$content = '<form role="form" class="form-horizontal" action="?" method="post">'.$ex.'<input type="hidden" name="action" value="'.$action.'">
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="title" name="title" placeholder="Blog Title" value="'.(isset($vars['title'])?$vars['title']:'').'">
</div>
</div>
<div class="form-group">
<label for="bbcode-body" class="col-sm-2 control-label">Body</label>
<div class="col-sm-10">
'.textbbcode('',$form_id,isset($vars['body'])?$vars['body']:'').
'</div></div>
<span id="emoticons" class="col-sm-offset-2 pull-left">'.emoticon_rand(20,1).'</span>
<button id="random_emot" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-refresh"></span></button>
<button id="more_bb" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-plus"></span></button>
<div id="controls-'.$form_id.'" class="pull-right"> '.button(($action === 'edit' ? 'Save':'Post'),'i','primary').'</div></form>';
return $content;
}
// textbbcode will handle emoticon printing.. always print control div but button are from form!
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.011 0.011 16.25 8.3.5 0.011 0.010 22.87 8.3.4 0.011 0.003 18.71 8.3.3 0.007 0.007 18.92 8.3.2 0.005 0.003 20.38 8.3.1 0.000 0.008 23.53 8.3.0 0.004 0.004 19.13 8.2.18 0.011 0.004 16.38 8.2.17 0.010 0.006 22.96 8.2.16 0.003 0.010 20.43 8.2.15 0.008 0.000 24.18 8.2.14 0.008 0.000 24.66 8.2.13 0.004 0.004 26.16 8.2.12 0.003 0.005 20.91 8.2.11 0.003 0.005 20.35 8.2.10 0.010 0.006 17.78 8.2.9 0.009 0.000 17.75 8.2.8 0.003 0.005 18.73 8.2.7 0.005 0.005 17.63 8.2.6 0.003 0.005 17.59 8.2.5 0.004 0.004 17.93 8.2.4 0.003 0.005 17.90 8.2.3 0.002 0.005 17.87 8.2.2 0.004 0.004 17.68 8.2.1 0.003 0.006 18.08 8.2.0 0.002 0.005 17.58 8.1.28 0.017 0.003 25.92 8.1.27 0.009 0.000 23.97 8.1.26 0.004 0.004 26.35 8.1.25 0.009 0.000 28.09 8.1.24 0.006 0.003 20.66 8.1.23 0.011 0.000 17.70 8.1.22 0.003 0.005 17.74 8.1.21 0.004 0.004 18.77 8.1.20 0.003 0.007 17.10 8.1.19 0.000 0.008 17.10 8.1.18 0.003 0.005 18.10 8.1.17 0.004 0.004 17.62 8.1.16 0.000 0.007 21.86 8.1.15 0.004 0.004 18.68 8.1.14 0.004 0.004 17.30 8.1.13 0.003 0.003 17.81 8.1.12 0.000 0.008 17.39 8.1.11 0.000 0.007 17.34 8.1.10 0.003 0.006 17.38 8.1.9 0.005 0.004 17.31 8.1.8 0.005 0.002 17.30 8.1.7 0.003 0.003 17.29 8.1.6 0.007 0.000 17.40 8.1.5 0.000 0.008 17.43 8.1.4 0.000 0.007 17.40 8.1.3 0.003 0.005 17.46 8.1.2 0.004 0.004 17.54 8.1.1 0.000 0.007 17.35 8.1.0 0.000 0.008 17.32 8.0.30 0.000 0.008 18.77 8.0.29 0.008 0.004 16.63 8.0.28 0.004 0.004 18.46 8.0.27 0.000 0.007 17.21 8.0.26 0.008 0.000 17.19 8.0.25 0.007 0.000 16.86 8.0.24 0.006 0.003 16.84 8.0.23 0.003 0.005 16.78 8.0.22 0.003 0.003 16.81 8.0.21 0.003 0.003 16.78 8.0.20 0.006 0.000 16.71 8.0.19 0.003 0.006 16.91 8.0.18 0.006 0.006 16.82 8.0.17 0.000 0.007 16.80 8.0.16 0.000 0.007 16.81 8.0.15 0.004 0.004 16.72 8.0.14 0.003 0.006 16.65 8.0.13 0.006 0.000 13.59 8.0.12 0.004 0.004 16.68 8.0.11 0.004 0.004 16.69 8.0.10 0.003 0.005 16.60 8.0.9 0.000 0.007 16.66 8.0.8 0.003 0.018 16.79 8.0.7 0.004 0.004 16.76 8.0.6 0.004 0.004 16.85 8.0.5 0.007 0.000 16.60 8.0.3 0.012 0.007 17.01 8.0.2 0.009 0.009 17.40 8.0.1 0.004 0.004 16.72 8.0.0 0.010 0.007 16.73 7.4.33 0.000 0.005 15.15 7.4.32 0.003 0.003 16.45 7.4.30 0.000 0.006 16.41 7.4.29 0.004 0.004 16.41 7.4.28 0.006 0.003 16.41 7.4.27 0.000 0.006 16.38 7.4.26 0.009 0.000 16.30 7.4.25 0.007 0.000 16.41 7.4.24 0.005 0.002 16.49 7.4.23 0.003 0.003 16.59 7.4.22 0.003 0.014 16.48 7.4.21 0.003 0.010 16.57 7.4.20 0.003 0.003 16.38 7.4.16 0.003 0.012 16.49 7.4.15 0.005 0.014 17.40 7.4.14 0.013 0.005 17.86 7.4.13 0.010 0.011 16.30 7.4.12 0.012 0.005 16.44 7.4.11 0.013 0.007 16.29 7.4.10 0.007 0.010 16.51 7.4.9 0.014 0.003 16.39 7.4.8 0.004 0.015 19.39 7.4.7 0.007 0.010 16.23 7.4.6 0.010 0.007 16.27 7.4.5 0.004 0.000 16.00 7.4.4 0.003 0.013 16.48 7.4.3 0.007 0.014 16.60 7.4.0 0.003 0.013 14.88 7.3.33 0.005 0.000 13.41 7.3.32 0.003 0.003 13.48 7.3.31 0.003 0.003 16.11 7.3.30 0.007 0.000 16.00 7.3.29 0.011 0.003 16.11 7.3.28 0.010 0.007 16.16 7.3.27 0.011 0.007 17.40 7.3.26 0.011 0.007 16.26 7.3.25 0.005 0.011 16.38 7.3.24 0.015 0.004 16.48 7.3.23 0.004 0.012 16.39 7.3.21 0.012 0.006 16.46 7.3.20 0.010 0.010 19.39 7.3.19 0.014 0.012 16.25 7.3.18 0.004 0.012 16.12 7.3.17 0.008 0.008 16.27 7.3.16 0.010 0.007 16.21 7.2.33 0.017 0.000 16.31 7.2.32 0.013 0.003 16.55 7.2.31 0.016 0.003 16.41 7.2.30 0.006 0.016 16.36 7.2.29 0.007 0.010 16.53 7.2.6 0.009 0.006 16.91 7.2.0 0.007 0.007 19.11 7.1.20 0.007 0.004 15.81 7.1.10 0.000 0.012 18.11 7.1.7 0.004 0.007 17.02 7.1.6 0.007 0.010 19.40 7.1.5 0.026 0.010 34.23 7.1.0 0.000 0.080 22.32 7.0.20 0.028 0.006 14.51 7.0.14 0.020 0.060 22.04 7.0.10 0.013 0.067 20.04 7.0.9 0.010 0.047 20.13 7.0.8 0.010 0.080 20.05 7.0.7 0.020 0.067 20.02 7.0.6 0.003 0.067 20.12 7.0.5 0.003 0.083 20.43 7.0.4 0.013 0.053 20.13 7.0.3 0.007 0.080 20.00 7.0.2 0.010 0.077 20.08 7.0.1 0.010 0.077 20.04 7.0.0 0.007 0.073 20.10 5.6.28 0.010 0.067 21.15 5.6.25 0.000 0.090 20.84 5.6.24 0.010 0.087 20.65 5.6.23 0.003 0.047 20.66 5.6.22 0.003 0.080 20.66 5.6.21 0.000 0.087 20.64 5.6.20 0.020 0.073 21.16 5.6.19 0.010 0.070 21.21 5.6.18 0.007 0.083 21.12 5.6.17 0.003 0.060 21.16 5.6.16 0.007 0.083 21.07 5.6.15 0.007 0.087 21.04 5.6.14 0.013 0.080 21.21 5.6.13 0.003 0.057 21.01 5.6.12 0.010 0.070 21.18 5.6.11 0.007 0.087 21.21 5.6.10 0.010 0.037 21.07 5.6.9 0.010 0.047 21.02 5.6.8 0.013 0.057 20.57 5.6.7 0.023 0.083 20.39 5.6.6 0.010 0.077 20.38 5.6.5 0.007 0.063 20.55 5.6.4 0.013 0.073 20.48 5.6.3 0.000 0.077 20.48 5.6.2 0.010 0.080 20.38 5.6.1 0.007 0.047 20.46 5.6.0 0.010 0.077 20.48 5.5.38 0.007 0.083 20.48 5.5.37 0.013 0.033 20.59 5.5.36 0.010 0.073 20.44 5.5.35 0.003 0.077 20.49 5.5.34 0.003 0.093 20.81 5.5.33 0.010 0.083 20.95 5.5.32 0.010 0.080 20.96 5.5.31 0.013 0.043 20.98 5.5.30 0.013 0.073 20.98 5.5.29 0.017 0.047 20.95 5.5.28 0.003 0.090 20.99 5.5.27 0.020 0.063 20.95 5.5.26 0.017 0.050 20.69 5.5.25 0.010 0.067 20.53 5.5.24 0.017 0.067 20.35 5.5.23 0.003 0.087 20.38 5.5.22 0.003 0.053 20.23 5.5.21 0.023 0.057 20.39 5.5.20 0.013 0.073 20.17 5.5.19 0.003 0.077 20.23 5.5.18 0.023 0.070 20.33 5.5.16 0.020 0.067 20.30 5.5.15 0.027 0.040 20.14 5.5.14 0.010 0.073 20.19 5.5.13 0.003 0.080 20.32 5.5.12 0.013 0.067 20.21 5.5.11 0.010 0.077 20.06 5.5.10 0.013 0.073 20.20 5.5.9 0.020 0.077 20.15 5.5.8 0.007 0.073 20.23 5.5.7 0.010 0.060 20.22 5.5.6 0.003 0.080 20.01 5.5.5 0.003 0.047 20.07 5.5.4 0.010 0.077 20.18 5.5.3 0.013 0.077 20.23 5.5.2 0.010 0.063 20.14 5.5.1 0.010 0.043 20.17 5.5.0 0.020 0.073 20.14 5.4.45 0.007 0.050 19.55 5.4.44 0.017 0.057 19.22 5.4.43 0.003 0.050 19.20 5.4.42 0.003 0.043 19.48 5.4.41 0.010 0.080 19.42 5.4.40 0.003 0.080 19.17 5.4.39 0.003 0.077 19.05 5.4.38 0.017 0.067 18.91 5.4.37 0.013 0.070 19.07 5.4.36 0.007 0.077 19.13 5.4.35 0.020 0.067 19.17 5.4.34 0.010 0.073 19.22 5.4.32 0.010 0.040 18.93 5.4.31 0.007 0.073 19.16 5.4.30 0.010 0.053 18.86 5.4.29 0.010 0.073 19.07 5.4.28 0.013 0.077 19.05 5.4.27 0.003 0.080 19.05 5.4.26 0.010 0.067 19.13 5.4.25 0.010 0.073 18.90 5.4.24 0.017 0.070 19.18 5.4.23 0.007 0.050 18.90 5.4.22 0.007 0.077 19.16 5.4.21 0.003 0.050 19.04 5.4.20 0.010 0.050 18.91 5.4.19 0.007 0.073 19.11 5.4.18 0.000 0.043 19.13 5.4.17 0.010 0.080 18.97 5.4.16 0.013 0.070 19.15 5.4.15 0.000 0.087 18.89 5.4.14 0.000 0.080 16.55 5.4.13 0.007 0.067 16.50 5.4.12 0.010 0.067 16.52 5.4.11 0.020 0.063 16.50 5.4.10 0.007 0.077 16.48 5.4.9 0.013 0.067 16.34 5.4.8 0.010 0.047 16.31 5.4.7 0.007 0.073 16.38 5.4.6 0.010 0.047 16.43 5.4.5 0.010 0.070 16.54 5.4.4 0.017 0.063 16.54 5.4.3 0.013 0.050 16.46 5.4.2 0.003 0.070 16.41 5.4.1 0.013 0.067 16.50 5.4.0 0.003 0.043 15.93
preferences:dark mode live preview
55.67 ms | 401 KiB | 5 Q