cvs: php-people-web / index.php styles.css /images shadow.png /js jquery.autocomplete.js jquery.autocomplete.min.js search.js userlisting.php

From: Date: Sun, 07 Jun 2009 12:28:26 +0000
Subject: cvs: php-people-web / index.php styles.css /images shadow.png /js jquery.autocomplete.js jquery.autocomplete.min.js search.js userlisting.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-4986@lists.php.net to get a copy of this message
bjori Sun Jun 7 12:28:26 2009 UTC Added files: /php-people-web/images shadow.png /php-people-web/js jquery.autocomplete.js jquery.autocomplete.min.js search.js userlisting.php Modified files: /php-people-web index.php styles.css Log: Add a simple search functionality

http://cvs.php.net/viewvc.cgi/php-people-web/index.php?r1=1.4&r2=1.5&diff_format=u Index: php-people-web/index.php diff -u php-people-web/index.php:1.4 php-people-web/index.php:1.5 --- php-people-web/index.php:1.4 Fri Jun 5 14:48:54 2009 +++ php-people-web/index.php Sun Jun 7 12:28:26 2009 @@ -97,10 +97,18 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link type="text/css" media="all" rel="stylesheet" href="styles.css" /> <link rel="shortcut icon" href="http://php.net/favicon.ico" /> + <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> + <script type="text/javascript" src="js/jquery.autocomplete.min.js"></script> + <script type="text/javascript" src="js/userlisting.php"></script> </head> <body> <h1 id="header"><a href="http://php.net/index.php">PHP: Hypertext Preprocessor</a> - Profiles</h1> + <div id="searchbox"> + <label for="search">User search</label> + <input type="text" name="q" id="search" /> + </div> + <script type="text/javascript" src="js/search.js"></script> <ul id="mainmenu"> <li><a href="http://php.net/downloads.php">Downloads</a></li> <li><a href="http://php.net/docs.php">Documentation</a></li> http://cvs.php.net/viewvc.cgi/php-people-web/styles.css?r1=1.1&r2=1.2&diff_format=u Index: php-people-web/styles.css diff -u php-people-web/styles.css:1.1 php-people-web/styles.css:1.2 --- php-people-web/styles.css:1.1 Fri May 1 20:15:32 2009 +++ php-people-web/styles.css Sun Jun 7 12:28:26 2009 @@ -3,7 +3,7 @@ font-family: Tahoma, Arial, sans-serif, serif, monospace; background-color: #f8f8f8; } -h1#header { +#header { margin: 0; background: url(/images/php.gif) #5a5993 no-repeat; padding: 20px 0 10px 150px; @@ -12,10 +12,10 @@ font-size: 1em; color: #B5B5E9; } -h1#header a { +#header a { color: #B5B5E9; } -ul#mainmenu { +#mainmenu { margin: 0; background-color: #f3f3f3; font-size: 0.9em; @@ -24,16 +24,16 @@ border-top: 1px solid #000000; border-bottom: 1px solid #D0D0D0; } -ul#mainmenu li { +#mainmenu li { display: inline; padding: 0 1%; border-right: 1px solid #CDCDCD; } -ul#mainmenu li a { +#mainmenu li a { color: #6181B7; } -ul#mainmenu li:last-child { - border: 0px; +#mainmenu li:last-child { + border: 0px; } p.warning, p.warning { padding: 1em; @@ -54,8 +54,8 @@ color: #660000; } -div#profile { - margin: 10px 100px 0 100px; +#profile { + margin: 10px 100px 0 100px; } h2 { margin: 0; @@ -71,3 +71,46 @@ div.note:last-child { border-bottom: 0; } +#searchbox { + color: #B5B5E9; + position: absolute; + top: 20px; + right: 200px; +} + +/* {{{ Stolen from http://www.devbridge.com/projects/autocomplete/jquery/ */ +.autocomplete-w1 { + background: url(images/shadow.png) no-repeat bottom right; + position: absolute; + top: 0px; + left: 0px; + margin: 6px 0 0 6px; + /* IE6 fix: */ + _background:none; _margin:1px 0 0 0; +} +.autocomplete { + border: 1px solid #999; + background: #FFF; + cursor: default; + text-align: left; + max-height: 350px; + overflow: auto; + margin: -6px 6px 6px -6px; + /* IE6 specific: */ + _height:350px; _margin:0; _overflow-x:hidden; +} +.autocomplete .selected { + background:#F0F0F0; +} +.autocomplete div { + padding: 2px 5px; + white-space: nowrap; +} +.autocomplete strong { + font-weight: normal; + color: #3399FF; +} +/* }}} */ + +/* vim: set expandtab shiftwidth=2 softtabstop=2 tabstop=2 : */ + http://cvs.php.net/viewvc.cgi/php-people-web/js/jquery.autocomplete.js?view=markup&rev=1.1 Index: php-people-web/js/jquery.autocomplete.js +++ php-people-web/js/jquery.autocomplete.js /* * Ajax Autocomplete for jQuery, version 1.0.6 * (c) 2009 Tomas Kirda * * Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license. * For details, see the web site: http://www.devbridge.com/projects/autocomplete/jquery/ * * Last Review: 4/24/2009 */ (function($) { $.fn.autocomplete = function(options) { return this.each(function() { return new Autocomplete(this, options); }); }; var reEscape = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'].join('|\\') + ')', 'g'); var fnFormatResult = function(value, data, currentValue) { var pattern = '(' + currentValue.replace(reEscape, '\\$1') + ')'; return value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>'); }; var Autocomplete = function(el, options) { this.el = $(el); this.el.attr('autocomplete', 'off'); this.suggestions = []; this.data = []; this.badQueries = []; this.selectedIndex = -1; this.currentValue = this.el.val(); this.intervalId = 0; this.cachedResponse = []; this.onChangeInterval = null; this.ignoreValueChange = false; this.serviceUrl = options.serviceUrl; this.isLocal = false; this.options = { autoSubmit: false, minChars: 1, maxHeight: 300, deferRequestBy: 0, width: 0, highlight: true, params: {}, fnFormatResult: fnFormatResult, delimiter: null }; if (options) { $.extend(this.options, options); } if(this.options.lookup){ this.isLocal = true; if($.isArray(this.options.lookup)){ this.options.lookup = { suggestions:this.options.lookup, data:[] }; } } this.initialize(); }; Autocomplete.prototype = { killerFn: null, initialize: function() { var me, zindex; me = this; zindex = Math.max.apply(null, $.map($('body > *'), function(e, n) { var pos = $(e).css('position'); if (pos === 'absolute' || pos === 'relative') { return parseInt($(e).css('z-index'), 10) || 1; } })); this.killerFn = function(e) { if ($(e.target).parents('.autocomplete').size() === 0) { me.killSuggestions(); me.disableKillerFn(); } }; var uid = new Date().getTime(); var autocompleteElId = 'Autocomplete_' + uid; if (!this.options.width) { this.options.width = this.el.width(); } this.mainContainerId = 'AutocompleteContainter_' + uid; $('<div id="' + this.mainContainerId + '" style="position:absolute;z-index:' + zindex + '"><div class="autocomplete-w1"><div class="autocomplete" id="' + autocompleteElId + '" style="display:none; width:' + this.options.width + 'px;"></div></div></div>').appendTo('body'); this.container = $('#' + autocompleteElId); this.fixPosition(); if (window.opera) { this.el.keypress(function(e) { me.onKeyPress(e); }); } else { this.el.keydown(function(e) { me.onKeyPress(e); }); } this.el.keyup(function(e) { me.onKeyUp(e); }); this.el.blur(function() { me.enableKillerFn(); }); this.el.focus(function() { me.fixPosition(); }); this.container.css({ maxHeight: this.options.maxHeight + 'px' }); }, fixPosition: function() { var offset = this.el.offset(); $('#' + this.mainContainerId).css({ top: (offset.top + this.el.innerHeight()) + 'px', left: offset.left + 'px' }); }, enableKillerFn: function() { var me = this; $(document).bind('click', me.killerFn); }, disableKillerFn: function() { var me = this; $(document).unbind('click', me.killerFn); }, killSuggestions: function() { var me = this; this.stopKillSuggestions(); this.intervalId = window.setInterval(function() { me.hide(); me.stopKillSuggestions(); }, 300); }, stopKillSuggestions: function() { window.clearInterval(this.intervalId); }, onKeyPress: function(e) { if (!this.enabled) { return; } // return will exit the function // and event will not fire switch (e.keyCode) { case 27: //Event.KEY_ESC: this.el.val(this.currentValue); this.hide(); break; case 9: //Event.KEY_TAB: case 13: //Event.KEY_RETURN: if (this.selectedIndex === -1) { this.hide(); return; } this.select(this.selectedIndex); if (e.keyCode === 9/* Event.KEY_TAB */) { return; } break; case 38: //Event.KEY_UP: this.moveUp(); break; case 40: //Event.KEY_DOWN: this.moveDown(); break; default: return; } e.stopImmediatePropagation(); e.preventDefault(); }, onKeyUp: function(e) { switch (e.keyCode) { case 38: //Event.KEY_UP: case 40: //Event.KEY_DOWN: return; } clearInterval(this.onChangeInterval); if (this.currentValue !== this.el.val()) { if (this.options.deferRequestBy > 0) { // Defer lookup in case when value changes very quickly: var me = this; this.onChangeInterval = setInterval(function() { me.onValueChange(); }, this.options.deferRequestBy); } else { this.onValueChange(); } } }, onValueChange: function() { clearInterval(this.onChangeInterval); this.currentValue = this.el.val(); var q = this.getQuery(this.currentValue); this.selectedIndex = -1; if (this.ignoreValueChange) { this.ignoreValueChange = false; return; } if (q === '' || q.length < this.options.minChars) { this.hide(); } else { this.getSuggestions(q); } }, getQuery: function(val) { var d, arr; d = this.options.delimiter; if (!d) { return $.trim(val); } arr = val.split(d); return $.trim(arr[arr.length - 1]); }, getSuggestionsLocal: function(q) { var ret, arr, len, val; arr = this.options.lookup; len = arr.suggestions.length; ret = { suggestions:[], data:[] }; for(var i=0; i< len; i++){ val = arr.suggestions[i]; if(val.toLowerCase().indexOf(q.toLowerCase()) === 0){ ret.suggestions.push(val); ret.data.push(arr.data[i]); } } return ret; }, getSuggestions: function(q) { var cr, me, ls; cr = this.isLocal ? this.getSuggestionsLocal(q) : this.cachedResponse[q]; if (cr && $.isArray(cr.suggestions)) { this.suggestions = cr.suggestions; this.data = cr.data; this.suggest(); } else if (!this.isBadQuery(q)) { me = this; me.options.params.query = q; $.get(this.serviceUrl, me.options.params, function(txt) { me.processResponse(txt); }, 'text'); } }, isBadQuery: function(q) { var i = this.badQueries.length; while (i--) { if (q.indexOf(this.badQueries[i]) === 0) { return true; } } return false; }, hide: function() { this.enabled = false; this.selectedIndex = -1; this.container.hide(); }, suggest: function() { if (this.suggestions.length === 0) { this.hide(); return; } var me, len, div, f; me = this; len = this.suggestions.length; f = this.options.fnFormatResult; v = this.getQuery(this.currentValue); this.container.hide().empty(); for (var i = 0; i < len; i++) { div = $((me.selectedIndex === i ? '<div class="selected"' : '<div') + ' title="' + this.suggestions[i] + '">' + f(this.suggestions[i], this.data[i], v) + '</div>'); div.mouseover((function(xi) { return function() { me.activate(xi); }; })(i)); div.click((function(xi) { return function() { me.select(xi); }; })(i)); //console.log(div); this.container.append(div); } this.enabled = true; this.container.show(); }, processResponse: function(text) { var response; try { response = eval('(' + text + ')'); } catch (err) { return; } if (!$.isArray(response.data)) { response.data = []; } this.suggestions = response.suggestions; this.data = response.data; this.cachedResponse[response.query] = response; if (response.suggestions.length === 0) { this.badQueries.push(response.query); } if (response.query === this.getQuery(this.currentValue)) { this.suggest(); } }, activate: function(index) { var divs = this.container.children(); var activeItem; // Clear previous selection: if (this.selectedIndex !== -1 && divs.length > this.selectedIndex) { $(divs.get(this.selectedIndex)).attr('class', ''); } this.selectedIndex = index; if (this.selectedIndex !== -1 && divs.length > this.selectedIndex) { activeItem = divs.get(this.selectedIndex); $(activeItem).attr('class', 'selected'); } return activeItem; }, deactivate: function(div, index) { div.className = ''; if (this.selectedIndex === index) { this.selectedIndex = -1; } }, select: function(i) { var selectedValue = this.suggestions[i]; if (selectedValue) { this.el.val(selectedValue); if (this.options.autoSubmit) { var f = this.el.parents('form'); if (f.length > 0) { f.get(0).submit(); } } this.ignoreValueChange = true; this.hide(); this.onSelect(i); } }, moveUp: function() { if (this.selectedIndex === -1) { return; } if (this.selectedIndex === 0) { this.container.children().get(0).className = ''; this.selectedIndex = -1; this.el.val(this.currentValue); return; } this.adjustScroll(this.selectedIndex - 1); }, moveDown: function() { if (this.selectedIndex === (this.suggestions.length - 1)) { return; } this.adjustScroll(this.selectedIndex + 1); }, adjustScroll: function(i) { var activeItem, offsetTop, upperBound, lowerBound; activeItem = this.activate(i); offsetTop = activeItem.offsetTop; upperBound = this.container.scrollTop(); lowerBound = upperBound + this.options.maxHeight - 25; if (offsetTop < upperBound) { this.container.scrollTop(offsetTop); } else if (offsetTop > lowerBound) { this.container.scrollTop(offsetTop - this.options.maxHeight + 25); } //this.el.val(this.suggestions[i]); }, onSelect: function(i) { var me, onSelect, getValue, s, d; me = this; onSelect = me.options.onSelect; getValue = function(value) { var del, currVal; del = me.options.delimiter; currVal = me.currentValue; if (!del) { return value; } var arr = currVal.split(del); if (arr.length === 1) { return value; } return currVal.substr(0, currVal.length - arr[arr.length - 1].length) + value; }; s = me.suggestions[i]; d = me.data[i]; me.el.val(getValue(s)); if ($.isFunction(onSelect)) { onSelect(s, d); } } }; })(jQuery); http://cvs.php.net/viewvc.cgi/php-people-web/js/jquery.autocomplete.min.js?view=markup&rev=1.1 Index: php-people-web/js/jquery.autocomplete.min.js +++ php-people-web/js/jquery.autocomplete.min.js /* * Ajax Autocomplete for jQuery, version 1.0.6 * (c) 2009 Tomas Kirda * * Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license. * For details, see the web site: http://www.devbridge.com/projects/autocomplete/jquery/ * * Last Review: 4/24/2009 */ (function($) { $.fn.autocomplete = function(options) { return this.each(function() { return new Autocomplete(this, options); }); }; var reEscape = new RegExp("(\\" + ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\"].join("|\\") + ")", "g"); var fnFormatResult = function(value, data, currentValue) { var pattern = "(" + currentValue.replace(reEscape, "\\$1") + ")"; return value.replace(new RegExp(pattern, "gi"), "<strong>$1</strong>"); }; var Autocomplete = function(el, options) { this.el = $(el); this.el.attr("autocomplete", "off"); this.suggestions = []; this.data = []; this.badQueries = []; this.selectedIndex = -1; this.currentValue = this.el.val(); this.intervalId = 0; this.cachedResponse = []; this.onChangeInterval = null; this.ignoreValueChange = false; this.serviceUrl = options.serviceUrl; this.isLocal = false; this.options = { autoSubmit: false, minChars: 1, maxHeight: 300, deferRequestBy: 0, width: 0, highlight: true, params: {}, fnFormatResult: fnFor! matResult, delimiter: null }; if (options) { $.extend(this.options, options); } if (this.options.lookup) { this.isLocal = true; if ($.isArray(this.options.lookup)) { this.options.lookup = { suggestions: this.options.lookup, data: [] }; } } this.initialize(); }; Autocomplete.prototype = { killerFn: null, initialize: function() { var me, zindex; me = this; zindex = Math.max.apply(null, $.map($("body > *"), function(e, n) { var pos = $(e).css("position"); if (pos === "absolute" || pos === "relative") { return parseInt($(e).css("z-index"), 10) || 1; } })); this.killerFn = function(e) { if ($(e.target).parents(".autocomplete").size() === 0) { me.killSuggestions(); me.disableKillerFn(); } }; var uid = new Date().getTime(); var autocompleteElId = "Autocomplete_" + uid; if (!this.options.width) { this.options.width = this.el.width(); } this.mainContainerId = "AutocompleteContainter_" + uid; $('<div id="' + this.mainContainerId + '" style="position:absolute;z-index:' + zindex + '"><! div class="autocomplete-w1"><div class="autocomplete" id="' + autocomp leteElId + '" style="display:none; width:' + this.options.width + 'px;"></div></div></div>').appendTo("body"); this.container = $("#" + autocompleteElId); this.fixPosition(); if (window.opera) { this.el.keypress(function(e) { me.onKeyPress(e); }); } else { this.el.keydown(function(e) { me.onKeyPress(e); }); } this.el.keyup(function(e) { me.onKeyUp(e); }); this.el.blur(function() { me.enableKillerFn(); }); this.el.focus(function() { me.fixPosition(); }); this.container.css({ maxHeight: this.options.maxHeight + "px" }); }, fixPosition: function() { var offset = this.el.offset(); $("#" + this.mainContainerId).css({ top: (offset.top + this.el.innerHeight()) + "px", left: offset.left + "px" }); }, enableKillerFn: function() { var me = this; $(document).bind("click", me.killerFn); }, disableKillerFn: function() { var me = this; $(document).unbind("click", me.killerFn); }, killSuggestions: function() { var me = this; this.stopKillSuggestions(); this.intervalId = window.setInterval(! function() { me.hide(); me.stopKillSuggestions(); }, 300); }, stopKillSuggestions: function() { window.clearInterval(this.intervalId); }, onKeyPress: function(e) { if (!this.enabled) { return; } switch (e.keyCode) { case 27: this.el.val(this.currentValue); this.hide(); break; case 9: case 13: if (this.selectedIndex === -1) { this.hide(); return; } this.select(this.selectedIndex); if (e.keyCode === 9) { return; } break; case 38: this.moveUp(); break; case 40: this.moveDown(); break; default: return; } e.stopImmediatePropagation(); e.preventDefault(); }, onKeyUp: function(e) { switch (e.keyCode) { case 38: case 40: return; } clearInterval(this.onChangeInterval); if (this.currentValue !== this.el.val()) { if (this.options.deferRequestBy > 0) { var me = this; this.onChangeInterval = setInterval(function() { me.onValueChange(); }, this.options.deferRequestBy); } else { this.onValueChange(); } } }, onValueChange: function() { clearInterval(this.onChangeInterval); this.currentValu! e = this.el.val(); var q = this.getQuery(this.currentValue); this.sele ctedIndex = -1; if (this.ignoreValueChange) { this.ignoreValueChange = false; return; } if (q === "" || q.length < this.options.minChars) { this.hide(); } else { this.getSuggestions(q); } }, getQuery: function(val) { var d, arr; d = this.options.delimiter; if (!d) { return $.trim(val); } arr = val.split(d); return $.trim(arr[arr.length - 1]); }, getSuggestionsLocal: function(q) { var ret, arr, len, val; arr = this.options.lookup; len = arr.suggestions.length; ret = { suggestions: [], data: [] }; for (var i = 0; i < len; i++) { val = arr.suggestions[i]; if (val.toLowerCase().indexOf(q.toLowerCase()) === 0) { ret.suggestions.push(val); ret.data.push(arr.data[i]); } } return ret; }, getSuggestions: function(q) { var cr, me, ls; cr = this.isLocal ? this.getSuggestionsLocal(q) : this.cachedResponse[q]; if (cr && $.isArray(cr.suggestions)) { this.suggestions = cr.suggestions; this.data = cr.data; this.suggest(); } else { if (!this.isBadQuery(q)) { me = this; me.options.params.quer! y = q; $.get(this.serviceUrl, me.options.params, function(txt) { me.processResponse(txt); }, "text"); } } }, isBadQuery: function(q) { var i = this.badQueries.length; while (i--) { if (q.indexOf(this.badQueries[i]) === 0) { return true; } } return false; }, hide: function() { this.enabled = false; this.selectedIndex = -1; this.container.hide(); }, suggest: function() { if (this.suggestions.length === 0) { this.hide(); return; } var me, len, div, f; me = this; len = this.suggestions.length; f = this.options.fnFormatResult; v = this.getQuery(this.currentValue); this.container.hide().empty(); for (var i = 0; i < len; i++) { div = $((me.selectedIndex === i ? '<div class="selected"' : "<div") + ' title="' + this.suggestions[i] + '">' + f(this.suggestions[i], this.data[i], v) + "</div>"); div.mouseover((function(xi) { return function() { me.activate(xi); }; })(i)); div.click((function(xi) { return function() { me.select(xi); }; })(i)); this.container.append(div); } this.enabled =! true; this.container.show(); }, processResponse: function(text) { var response; try { response = eval("(" + text + ")"); } catch (err) { return; } if (!$.isArray(response.data)) { response.data = []; } this.suggestions = response.suggestions; this.data = response.data; this.cachedResponse[response.query] = response; if (response.suggestions.length === 0) { this.badQueries.push(response.query); } if (response.query === this.getQuery(this.currentValue)) { this.suggest(); } }, activate: function(index) { var divs = this.container.children(); var activeItem; if (this.selectedIndex !== -1 && divs.length > this.selectedIndex) { $(divs.get(this.selectedIndex)).attr("class", ""); } this.selectedIndex = index; if (this.selectedIndex !== -1 && divs.length > this.selectedIndex) { activeItem = divs.get(this.selectedIndex); $(activeItem).attr("class", "selected"); } return activeItem; }, deactivate: function(div, index) { div.className = ""; if (this.selectedIndex === index) { this.selectedIndex = -1; } }, select: function(i) { var selectedValue = this.su! ggestions[i]; if (selectedValue) { this.el.val(selectedValue); if (this.options.autoSubmit) { var f = this.el.parents("form"); if (f.length > 0) { f.get(0).submit(); } } this.ignoreValueChange = true; this.hide(); this.onSelect(i); } }, moveUp: function() { if (this.selectedIndex === -1) { return; } if (this.selectedIndex === 0) { this.container.children().get(0).className = ""; this.selectedIndex = -1; this.el.val(this.currentValue); return; } this.adjustScroll(this.selectedIndex - 1); }, moveDown: function() { if (this.selectedIndex === (this.suggestions.length - 1)) { return; } this.adjustScroll(this.selectedIndex + 1); }, adjustScroll: function(i) { var activeItem, offsetTop, upperBound, lowerBound; activeItem = this.activate(i); offsetTop = activeItem.offsetTop; upperBound = this.container.scrollTop(); lowerBound = upperBound + this.options.maxHeight - 25; if (offsetTop < upperBound) { this.container.scrollTop(offsetTop); } else { if (offsetTop > lowerBound) { this.con! tainer.scrollTop(offsetTop - this.options.maxHeight + 25); } } }, onSe lect: function(i) { var me, onSelect, getValue, s, d; me = this; onSelect = me.options.onSelect; getValue = function(value) { var del, currVal; del = me.options.delimiter; currVal = me.currentValue; if (!del) { return value; } var arr = currVal.split(del); if (arr.length === 1) { return value; } return currVal.substr(0, currVal.length - arr[arr.length - 1].length) + value; }; s = me.suggestions[i]; d = me.data[i]; me.el.val(getValue(s)); if ($.isFunction(onSelect)) { onSelect(s, d); } } }; })(jQuery); http://cvs.php.net/viewvc.cgi/php-people-web/js/search.js?view=markup&rev=1.1 Index: php-people-web/js/search.js +++ php-people-web/js/search.js var reEscape = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'].join('|\\') + ')', 'g'); var fnFormatSearchResult = function(value, data, currentValue) { var pattern = '(' + currentValue.replace(reEscape, '\\$1') + ')'; var listing = users[value]["name"] + " (" + users[value]["username"] + ")"; listing = listing.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>'); return '<img src="https://secure.gravatar.com/avatar.php?gravatar_id=' + users[value]["email"] + '&s=25" /> ' + listing; }; $('#search').autocomplete({ minChars:2, maxHeight:400, width:300, fnFormatResult: fnFormatSearchResult, onSelect: function(value, data){ window.location = "?username=" + users[value]["username"]; }, lookup: lookup }); // vim: set expandtab shiftwidth=4 softtabstop=4 tabstop=4 : http://cvs.php.net/viewvc.cgi/php-people-web/js/userlisting.php?view=markup&rev=1.1 Index: php-people-web/js/userlisting.php +++ php-people-web/js/userlisting.php <?php function getAllUsers() { $opts = array("ignore_errors" => true); $ctx = stream_context_create(array("http" => $opts)); $token = getenv("TOKEN"); $retval = @file_get_contents("https://master.php.net/fetch/allusers.php?&token=" . rawurlencode($token), false, $ctx); if (!$retval) { return; } $json = json_decode($retval, true); if (!is_array($json)) { return; } if (isset($json["error"])) { return; } return $json; } if(!$json = apc_fetch("cvsusers")) { $json = getAllUsers(); if ($json) { apc_store("cvsusers", $json, 3600); apc_store("cvsusers_update", $_SERVER["REQUEST_TIME"], 3600); } } $modified = apc_fetch("cvsusers_update"); if (!$json) { return; } $tsstring = gmdate("D, d M Y H:i:s ", $modified); if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && $_SERVER["HTTP_IF_MODIFIED_SINCE"] == $tsstring) { header("HTTP/1.1 304 Not Modified"); exit; } else { $expires = gmdate("D, d M Y H:i:s ", strtotime("+2 months", $_SERVER["REQUEST_TIME"])) . "GMT"; header("Last-Modified: " . $tsstring); header("Expires: $expires"); } $lookup = $user = array(); foreach($json as $row) { $lookup[] = $row["name"]; $lookup[] = $row["username"]; $data = array( "email" => md5($row["username"] . "@php.net"), "name" => $row["name"], "username" => $row["username"], ); $user[$row["username"]] = $data; $user[$row["name"]] = $data; } echo 'var users = ' . json_encode($user) . ';'; echo 'var lookup = ' . json_encode($lookup) . ';'; // vim: set expandtab shiftwidth=4 softtabstop=4 tabstop=4 :
« previous php.webmaster (#4986) next »