# HG changeset patch # User Dan # Date 1209952668 14400 # Node ID acb7e23b6ffadbc9a14d3eebd2d0e7e08bb19eb4 # Parent 1e4b759da33641fa293299c390ce333673c455d0 Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons. diff -r 1e4b759da336 -r acb7e23b6ffa cron.php --- a/cron.php Sat Apr 26 17:25:28 2008 -0400 +++ b/cron.php Sun May 04 21:57:48 2008 -0400 @@ -29,8 +29,9 @@ foreach ( $cron_tasks as $interval => $tasks ) { + $interval = doubleval($interval); $last_run = intval(getConfig("cron_lastrun_ivl_$interval")); - $last_run_threshold = time() - ( 3600 * $interval ); + $last_run_threshold = doubleval(time()) - ( 3600.0 * $interval ); if ( $last_run_threshold >= $last_run ) { foreach ( $tasks as $task ) diff -r 1e4b759da336 -r acb7e23b6ffa images/prompt-body.png Binary file images/prompt-body.png has changed diff -r 1e4b759da336 -r acb7e23b6ffa includes/clientside/css/enano-shared.css --- a/includes/clientside/css/enano-shared.css Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/clientside/css/enano-shared.css Sun May 04 21:57:48 2008 -0400 @@ -749,6 +749,7 @@ div.miniprompt { position: absolute; + z-index: 999; } div.miniprompt div.mp-top, div.miniprompt div.mp-bottom { diff -r 1e4b759da336 -r acb7e23b6ffa includes/clientside/static/acl.js --- a/includes/clientside/static/acl.js Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/clientside/static/acl.js Sun May 04 21:57:48 2008 -0400 @@ -695,7 +695,35 @@ closer = document.createElement('input'); closer.type = 'button'; closer.value = $lang.get('etc_cancel_changes'); - closer.onclick = function() { if(!confirm($lang.get('acl_msg_closeacl_confirm'))) return false; killACLManager(); return false; } + closer.onclick = function() + { + miniPromptMessage({ + title: $lang.get('acl_msg_closeacl_confirm_title'), + message: $lang.get('acl_msg_closeacl_confirm_body'), + buttons: [ + { + text: $lang.get('acl_btn_close'), + color: 'red', + style: { + fontWeight: 'bold' + }, + onclick: function(e) + { + killACLManager(); + miniPromptDestroy(this); + } + }, + { + text: $lang.get('etc_cancel'), + onclick: function(e) + { + miniPromptDestroy(this); + } + } + ] + }); + return false; + } spacer1 = document.createTextNode(' '); spacer2 = document.createTextNode(' '); diff -r 1e4b759da336 -r acb7e23b6ffa includes/clientside/static/comments.js --- a/includes/clientside/static/comments.js Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/clientside/static/comments.js Sun May 04 21:57:48 2008 -0400 @@ -130,13 +130,13 @@ html+=' ' + $lang.get('comment_postform_blurb_unapp'); html += ' ' + $lang.get('comment_postform_blurb_link') + '
'; html += '' + $lang.get('comment_postform_field_name') + ' | '; if ( data.user_id > 1 ) html += data.username + ''; - else html += ''; + else html += ''; html += ' |
' + $lang.get('comment_postform_field_subject') + ' | |
' + $lang.get('comment_postform_field_comment') + ' | |
' + $lang.get('comment_postform_field_subject') + ' | |
' + $lang.get('comment_postform_field_comment') + ' | |
' + $lang.get('comment_postform_field_captcha_title') + ' ' + $lang.get('comment_postform_field_captcha_blurb') + ' | ';
@@ -181,21 +181,24 @@
// Name
tplvars.NAME = this_comment.name;
if ( this_comment.user_id > 1 )
- tplvars.NAME = '' + this_comment.name + '';
+ tplvars.NAME = '' + this_comment.name + '';
// Avatar
if ( this_comment.user_has_avatar == '1' )
{
- tplvars.AVATAR_URL = scriptPath + '/' + data.avatar_directory + '/' + this_comment.user_id + '.' + this_comment.avatar_type;
+ tplvars.AVATAR_URL = this_comment.avatar_path;
tplvars.USERPAGE_LINK = makeUrlNS('User', this_comment.name);
tplvars.AVATAR_ALT = $lang.get('usercp_avatar_image_alt', { username: this_comment.name });
}
// User level
- tplvars.USER_LEVEL = $lang.get('user_type_guest');
- if ( this_comment.user_level >= data.user_level.member ) tplvars.USER_LEVEL = $lang.get('user_type_member');
- if ( this_comment.user_level >= data.user_level.mod ) tplvars.USER_LEVEL = $lang.get('user_type_mod');
- if ( this_comment.user_level >= data.user_level.admin ) tplvars.USER_LEVEL = $lang.get('user_type_admin');
+ tplvars.USER_LEVEL = '';
+ if ( this_comment.user_title )
+ tplvars.USER_LEVEL += this_comment.user_title;
+ if ( this_comment.rank_title && this_comment.user_title )
+ tplvars.USER_LEVEL += ' '; + if ( this_comment.rank_title ) + tplvars.USER_LEVEL += $lang.get(this_comment.rank_title); // Send PM link tplvars.SEND_PM_LINK=(this_comment.user_id>1)?'' + $lang.get('comment_btn_send_privmsg') + ' ':''; @@ -279,6 +282,7 @@ var ta = document.createElement('textarea'); ta.rows = '10'; ta.cols = '40'; + ta.style.width = '98%'; ta.value = src; ta.id = 'comment_edit_'+id; cmt.appendChild(ta); diff -r 1e4b759da336 -r acb7e23b6ffa includes/clientside/static/editor.js --- a/includes/clientside/static/editor.js Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/clientside/static/editor.js Sun May 04 21:57:48 2008 -0400 @@ -366,11 +366,11 @@ var img = document.createElement('img'); img.src = makeUrlNS('Special', 'Captcha/' + captcha_hash); - img._captchaHash = captcha_hash; + img.setAttribute('enano:captcha_hash', captcha_hash); img.id = 'enano_editor_captcha_img'; img.onclick = function() { - this.src = makeUrlNS('Special', 'Captcha/' + this._captchaHash + '/' + Math.floor(Math.random() * 100000)); + this.src = makeUrlNS('Special', 'Captcha/' + this.getAttribute('enano:captcha_hash') + '/' + Math.floor(Math.random() * 100000)); } img.style.cursor = 'pointer'; td4_2.appendChild(img); @@ -379,7 +379,7 @@ var input = document.createElement('input'); input.type = 'text'; input.id = 'enano_editor_field_captcha'; - input._captchaHash = captcha_hash; + input.setAttribute('enano:captcha_hash', captcha_hash); input.size = '9'; td4_2.appendChild(input); @@ -622,7 +622,7 @@ }; // Do we need to add captcha info? - if ( document.getElementById('enano_editor_field_captcha') ) + if ( document.getElementById('enano_editor_field_captcha') && !is_draft ) { var captcha_field = document.getElementById('enano_editor_field_captcha'); if ( captcha_field.value == '' ) @@ -632,7 +632,7 @@ return false; } json_packet.captcha_code = captcha_field.value; - json_packet.captcha_id = captcha_field._captchaHash; + json_packet.captcha_id = captcha_field.getAttribute('enano:captcha_hash'); } json_packet = ajaxEscape(toJSONString(json_packet)); diff -r 1e4b759da336 -r acb7e23b6ffa includes/clientside/static/faders.js --- a/includes/clientside/static/faders.js Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/clientside/static/faders.js Sun May 04 21:57:48 2008 -0400 @@ -153,7 +153,7 @@ document.getElementById('specialLayer_darkener').style.zIndex = '5'; } var master_div = document.createElement('div'); - master_div.style.zIndex = '6'; + master_div.style.zIndex = String(getHighestZ() + 5); var mydiv = document.createElement('div'); mydiv.style.height = '200px'; w = getWidth(); @@ -431,7 +431,16 @@ function miniPrompt(call_on_create) { - darken(false, 40); + if ( document.getElementById('specialLayer_darkener') ) + { + var opac = parseFloat(document.getElementById('specialLayer_darkener')); + opac = opac * 100; + darken(false, opac); + } + else + { + darken(false, 40); + } var wrapper = document.createElement('div'); wrapper.className = 'miniprompt'; diff -r 1e4b759da336 -r acb7e23b6ffa includes/comment.php --- a/includes/comment.php Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/comment.php Sun May 04 21:57:48 2008 -0400 @@ -71,6 +71,8 @@ function process_json($json) { global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + $data = enano_json_decode($json); $data = decode_unicode_array($data); if ( !isset($data['mode']) ) @@ -87,7 +89,6 @@ } $ret = Array(); $ret['mode'] = $data['mode']; - $ret['avatar_directory'] = getConfig('avatar_directory'); switch ( $data['mode'] ) { case 'fetch': @@ -102,6 +103,8 @@ ON (u.user_id=c.user_id) LEFT JOIN '.table_prefix.'buddies AS b ON ( ( b.user_id=' . $session->user_id.' AND b.buddy_user_id=c.user_id ) OR b.user_id IS NULL) + LEFT JOIN '.table_prefix.'ranks AS r + ON ( ( u.user_rank = r.rank_id ) ) WHERE page_id=\'' . $this->page_id . '\' AND namespace=\'' . $this->namespace . '\' GROUP BY c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,c.ip_address,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend @@ -123,6 +126,9 @@ if ( !$this->perms->get_permissions('mod_comments') && $row['approved'] == 0 ) continue; + // Localize the rank + $row = array_merge($row, $session->get_user_rank(intval($row['user_id']))); + // Send the source $row['comment_source'] = $row['comment_data']; @@ -150,6 +156,9 @@ // Do we have the IP? $row['have_ip'] = ( $row['have_ip'] == 1 ); + // Avatar URL + $row['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']); + // Add the comment to the list $ret['comments'][] = $row; @@ -322,6 +331,7 @@ $ret['auth_post_comments'] = $this->perms->get_permissions('post_comments'); $ret['auth_edit_comments'] = $this->perms->get_permissions('edit_comments'); $ret['user_id'] = $session->user_id; + $ret['rank_data'] = $session->get_user_rank($session->user_id); $ret['username'] = $session->username; $ret['logged_in'] = $session->user_logged_in; $ret['signature'] = RenderMan::render($row['signature']); @@ -331,7 +341,7 @@ $ret['user_level_list']['member'] = USER_LEVEL_MEMBER; $ret['user_level_list']['mod'] = USER_LEVEL_MOD; $ret['user_level_list']['admin'] = USER_LEVEL_ADMIN; - $ret['avatar_directory'] = getConfig('avatar_directory'); + $ret['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']); } break; diff -r 1e4b759da336 -r acb7e23b6ffa includes/common.php --- a/includes/common.php Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/common.php Sun May 04 21:57:48 2008 -0400 @@ -415,6 +415,10 @@ profiler_log('Ran disabled-site checks and common_post'); + load_rank_data(); + + profiler_log('Loaded user rank data'); + if ( isset($_GET['noheaders']) ) $template->no_headers = true; } diff -r 1e4b759da336 -r acb7e23b6ffa includes/common_cli.php --- a/includes/common_cli.php Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/common_cli.php Sun May 04 21:57:48 2008 -0400 @@ -244,6 +244,10 @@ profiler_log('Ran disabled-site checks and common_post'); + load_rank_data(); + + profiler_log('Loaded user rank data'); + if ( isset($_GET['noheaders']) ) $template->no_headers = true; } diff -r 1e4b759da336 -r acb7e23b6ffa includes/constants.php --- a/includes/constants.php Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/constants.php Sun May 04 21:57:48 2008 -0400 @@ -40,9 +40,16 @@ define('ACL_ALWAYS_ALLOW_ADMIN_EDIT_ACL', 1); // System groups +define('GROUP_ID_EVERYONE', 1); define('GROUP_ID_ADMIN', 2); define('GROUP_ID_MOD', 3); +// System ranks +define('RANK_ID_MEMBER', 1); +define('RANK_ID_MOD', 2); +define('RANK_ID_ADMIN', 3); +define('RANK_ID_GUEST', 4); + // Page group types define('PAGE_GRP_CATLINK', 1); define('PAGE_GRP_TAGGED', 2); @@ -52,6 +59,11 @@ // Identifier for the default pseudo-language define('LANG_DEFAULT', 0); +// Image types +define('IMAGE_TYPE_PNG', 1); +define('IMAGE_TYPE_GIF', 2); +define('IMAGE_TYPE_JPG', 3); + // // User types - don't touch these // diff -r 1e4b759da336 -r acb7e23b6ffa includes/functions.php --- a/includes/functions.php Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/functions.php Sun May 04 21:57:48 2008 -0400 @@ -3344,6 +3344,7 @@ function register_cron_task($func, $hour_interval = 24) { global $cron_tasks; + $hour_interval = strval($hour_interval); if ( !isset($cron_tasks[$hour_interval]) ) $cron_tasks[$hour_interval] = array(); $cron_tasks[$hour_interval][] = $func; @@ -3985,11 +3986,30 @@ function make_avatar_url($user_id, $avi_type) { + static $img_types = array( + 'png' => IMAGE_TYPE_PNG, + 'gif' => IMAGE_TYPE_GIF, + 'jpg' => IMAGE_TYPE_JPG + ); + if ( !is_int($user_id) ) return false; - if ( !in_array($avi_type, array('png', 'gif', 'jpg')) ) + if ( !isset($img_types[$avi_type]) ) return false; - return scriptPath . '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type; + $avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type; + if ( !file_exists(ENANO_ROOT . $avi_relative_path) ) + { + return ''; + } + + $img_type = $img_types[$avi_type]; + + $dateline = @filemtime(ENANO_ROOT . $avi_relative_path); + $avi_id = pack('VVv', $dateline, $user_id, $img_type); + $avi_id = hexencode($avi_id, '', ''); + + // return scriptPath . $avi_relative_path; + return makeUrlNS('Special', "Avatar/$avi_id"); } /** @@ -4312,6 +4332,91 @@ } } +/** + * Grabs and processes all rank information directly from the database. + */ + +function fetch_rank_data() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + + $sql = $session->generate_rank_sql(); + $q = $db->sql_query($sql); + if ( !$q ) + $db->_die(); + + $GLOBALS['user_ranks'] = array(); + global $user_ranks; + + while ( $row = $db->fetchrow($q) ) + { + $user_id = $row['user_id']; + $username = $row['username']; + $row = $session->calculate_user_rank($row); + $user_ranks[$username] = $row; + $user_ranks[$user_id] =& $user_ranks[$username]; + } +} + +/** + * Caches the computed user rank information. + */ + +function generate_ranks_cache() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + global $user_ranks; + + fetch_rank_data(); + + $user_ranks_stripped = array(); + foreach ( $user_ranks as $key => $value ) + { + if ( is_int($key) ) + $user_ranks_stripped[$key] = $value; + } + + $ranks_exported = "var_export_string($user_ranks_stripped) . ';'; + $uid_map = array(); + foreach ( $user_ranks as $id => $row ) + { + if ( !is_int($id) ) + { + $username = $id; + continue; + } + + $un_san = addslashes($username); + $ranks_exported .= "\n\$user_ranks['$un_san'] =& \$user_ranks[{$row['user_id']}];"; + } + $ranks_exported .= "\n\ndefine('ENANO_RANKS_CACHE_LOADED', 1); \n?>"; + + // open ranks cache file + $fh = @fopen( ENANO_ROOT . '/cache/cache_ranks.php', 'w' ); + if ( !$fh ) + return false; + fwrite($fh, $ranks_exported); + fclose($fh); +} + +/** + * Loads the rank data, first attempting the cache file and then the database. + */ + +function load_rank_data() +{ + if ( file_exists( ENANO_ROOT . '/cache/cache_ranks.php' ) ) + { + @include(ENANO_ROOT . '/cache/cache_ranks.php'); + } + if ( !defined('ENANO_RANKS_CACHE_LOADED') ) + { + fetch_rank_data(); + } +} + //die(' Original: 01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).''); ?> diff -r 1e4b759da336 -r acb7e23b6ffa includes/pageprocess.php --- a/includes/pageprocess.php Sat Apr 26 17:25:28 2008 -0400 +++ b/includes/pageprocess.php Sun May 04 21:57:48 2008 -0400 @@ -1307,6 +1307,9 @@ } } + // get the user's rank + $rank_data = $session->get_user_rank(intval($userdata['authoritative_uid'])); + $this->header(); // if ( $send_headers ) @@ -1331,10 +1334,20 @@ // Basic user info echo ' |
' . $lang->get('userpage_heading_basics', array('username' => htmlspecialchars($target_username))) . ' | |
---|---|
'; if ( $userdata['user_has_avatar'] == '1' ) { - echo ' | |
' . $lang->get('userpage_lbl_joined') . ' ' . enano_date('F d, Y h:i a', $userdata['reg_time']) . ' | |
' . $lang->get('userpage_lbl_num_comments') . ' ' . $userdata['n_comments'] . ' | get('usercp_publicinfo_field_timezone'); ?> get('usercp_publicinfo_field_timezone_hint'); ?> |
+ get_permissions('custom_user_title') ): + ?> + |
+ get('usercp_publicinfo_field_usertitle_title'); ?> + get('usercp_publicinfo_field_usertitle_hint'); ?> + |
+ + + | +
get('usercp_publicinfo_th_im'); ?>
diff -r 1e4b759da336 -r acb7e23b6ffa plugins/admin/GroupManager.php
--- a/plugins/admin/GroupManager.php Sat Apr 26 17:25:28 2008 -0400
+++ b/plugins/admin/GroupManager.php Sun May 04 21:57:48 2008 -0400
@@ -236,6 +236,7 @@
}
else
{
+
echo '
' . $lang->get('acpug_msg_user_added', array('username' => htmlspecialchars($_POST['edit_add_username']))) . '
';
@@ -244,6 +245,7 @@
else
echo '' . $lang->get('acpug_err_username_not_exist', array('username' => htmlspecialchars($_POST['edit_add_username']))) . ' ';
}
+ generate_ranks_cache();
}
$sg_disabled = ( $row['system_group'] == 1 ) ?
' value="' . $lang->get('acpug_btn_cant_delete') . '" disabled="disabled" style="color: #FF9773" ' :
diff -r 1e4b759da336 -r acb7e23b6ffa plugins/admin/UserManager.php
--- a/plugins/admin/UserManager.php Sat Apr 26 17:25:28 2008 -0400
+++ b/plugins/admin/UserManager.php Sun May 04 21:57:48 2008 -0400
@@ -389,6 +389,9 @@
}
}
+ // user level updated, regenerate the ranks cache
+ generate_ranks_cache();
+
echo '' . $lang->get('acpum_msg_save_success') . ' ';
}
}
|