<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scripts &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Tue, 16 Oct 2012 22:55:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Calculate Local Timestamp (with Summertime) from UTC-Timestamp in PHP</title>
		<link>https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/</link>
					<comments>https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Tue, 16 Oct 2012 22:53:15 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Snippets]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2000</guid>

					<description><![CDATA[As it was a bit tricky to find out how this works, I want to share this script. This is how you can convert a UTC timestamp without offset and summertime into a converted timestamp using PHP. This is especially useful when extending a Calendar Plugin for example, which saves its dates in UTC-timestamps while [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>As it was a bit tricky to find out how this works, I want to share this script. This is how you can convert a UTC timestamp without offset and summertime into a converted timestamp using PHP. This is especially useful when extending a Calendar Plugin for example, which saves its dates in UTC-timestamps while local time is needed.</p>
<pre lang="php">
/** Calculate middle european summertime */
function utc_to_local_time($timestamp,$offset=0,$summertime=true) { 
	 $year = strftime("%Y", $timestamp); 
	$timestamp += (3600*intval($offset)); // add local offset
	
	// Calculate beginning and end of Summertime
	$initTime = mktime(2,0,0,3,31-date('w', mktime(2,0,0,3,31,$year)),$year); 
	$endTime = mktime(2,0,0,10,31-date('w', mktime(2,0,0,10,31,$year)),$year); 

    // Check if summertime, return adequatly
    if (($timestamp > $initTime && $timestamp < $endTime) &#038;&#038; $summertime) { 
        return ($timestamp + 3600); 
    } else { 
        return ($timestamp); 
    } 
}

// example: Austria time
echo date("d.m.Y, H:i",utc_to_local_time($utc_time,1);
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F10%2F17%2Fcalculate-european-summertime-from-utc-timestamp-in-php%2F&#038;title=Calculate%20Local%20Timestamp%20%28with%20Summertime%29%20from%20UTC-Timestamp%20in%20PHP" data-a2a-url="https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/" data-a2a-title="Calculate Local Timestamp (with Summertime) from UTC-Timestamp in PHP"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/10/17/calculate-european-summertime-from-utc-timestamp-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Basic Ajax Skeleton Code</title>
		<link>https://blog.blackbam.at/2012/02/07/basic-ajax-skeleton-code/</link>
					<comments>https://blog.blackbam.at/2012/02/07/basic-ajax-skeleton-code/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Tue, 07 Feb 2012 08:26:01 +0000</pubDate>
				<category><![CDATA[JavaScript / Ajax]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[skeleton]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1848</guid>

					<description><![CDATA[Nothing new, nothing special... just the working code of a basic Ajax skeleton, as this has to be copied and pasted that often. This example shows an application similar to Google suggest, which searches related values, whenever a key is pressed.]]></description>
										<content:encoded><![CDATA[<p>Nothing new, nothing special&#8230; just the working code of a basic Ajax skeleton, as this has to be copied and pasted that often. This example shows an application similar to Google suggest, which searches related values, whenever a key is pressed.</p>
<p>Note: Since jQuery is that popular today, it is possibly better to use this (see <a href="http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Rate_me:_Using_Ajax" title="JQuery Ajax Tutorial">jQuery Ajax Tutorial</a>).</p>
<div class="code_title">index.html &#8211; function call and result representation</div>
<pre lang="html4strict">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax test</title>
<script type="text/javascript" src="ajax.js"></script>
</head>

<body>
<input type="text" onkeyup="AjaxRequest(this.value);" /><br/>
<p id="result"></p>
</body>
</html>
</pre>
<p></p>
<div class="code_title">ajax.js &#8211; request, response and data processing</div>
<pre lang="javascript">
var XMLHTTP = null;

function AjaxRequest(compString) {

// XMLHTTP-Request Objekt erzeugen, dabei auf Browserkonformität achten
	if(window.XMLHttpRequest) {
		XMLHTTP = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		try {
			XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ex) {
			try {
				XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(ex) {
			}
		}
	}
	
	XMLHTTP.open("GET","test.php?compString="+compString);
	XMLHTTP.onreadystatechange = MyRequestExecute;
	XMLHTTP.send(null);
}

// wird jedes mal aufgerufen, wenn der XMLHTTP-Request eine neue Stufe erreicht, bei 4 ist die Antwort des Servers eingetroffen
function MyRequestExecute() {
	// responseText als Javascript-String, responseXML als Javascript XML-DOM-Element, status Statuscode, statusText des. Beschreibung
	if(XMLHTTP.readyState == 4) {
		document.getElementById("result").innerHTML = XMLHTTP.responseText;
	}
}
</pre>
<p></p>
<p>The server side</p>
<p></p>
<div class="code_title">test.php</div>
<pre lang="php">
<?php
require_once('config.inc.php');

// Datenbankverbindung
try {
	$db = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
	
	//mysql-Abfrage
	$sql = "SELECT * FROM tags WHERE username = '".$_GET['compString']."'"; 
	
	$horst = $db->query($sql);
	
} catch (Exception $e) {
    echo 'Verbindungsaufbau fehlgeschlagen: ',  $e->getMessage(), "\n";
}

echo $_GET['compString']."< pre >".$horst."</  pre >";
?>
</pre>
<div class="code_title">config.inc.php</div>
<pre lang="php">
<?php
// Definition der Konstanten
define('DB_USER','****');
define('DB_PASSWORD','****');
define('DB_HOST','****');
define('DB_NAME','****');
?>
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F02%2F07%2Fbasic-ajax-skeleton-code%2F&#038;title=Basic%20Ajax%20Skeleton%20Code" data-a2a-url="https://blog.blackbam.at/2012/02/07/basic-ajax-skeleton-code/" data-a2a-title="Basic Ajax Skeleton Code"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/02/07/basic-ajax-skeleton-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>My todays top 10 most useful Javascript Functions</title>
		<link>https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/</link>
					<comments>https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 30 Jun 2011 22:21:10 +0000</pubDate>
				<category><![CDATA[JavaScript / Ajax]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript functions]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[top 10 javascript]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1308</guid>

					<description><![CDATA[These are my todays top 10 Javascript functions which I gathered in more than 6 months of casually Javascript Development. Almost each of them helped out of more than one problem, so they deserve to be perpetuated here and help again. Most of these are not written by me, but by some other great programmer on the web, and I really would like to mention all of them here if I would know where I have got all of these great scripts. Have fun an use wisely. [...]]]></description>
										<content:encoded><![CDATA[<p>These are my todays top 10 Javascript functions which I gathered in more than 6 months of casually Javascript Development. Almost each of them helped out of more than one problem, so they deserve to be perpetuated here and help again. Most of these are not written by me, but by some other great programmer on the web, and I really would like to mention all of them here if I would know where I have got all of these great scripts.</p>
<p>&nbsp;</p>
<p>Have fun an use wisely.</p>
<h2>1. Get Elements By Class Name (getElementsByClassName)</h2>
<p>This is maybe one of the most used and most needed custom Javascript functions of all time. It provides a way to get all elements in a page with a certain class attribute.</p>
<pre lang="javascript">
function getElementsByClassName(classname, node){
    if (!node) {
        node = document.getElementsByTagName('body')[0];
    }
 
    var a = [], re = new RegExp('\\b' + classname + '\\b');
    els = node.getElementsByTagName('*');
    for (var i = 0, j = els.length; i < j; i++) {
        if (re.test(els[i].className)) {
            a.push(els[i]);
        }
    }
    return a;
}
</pre>
<h2>2. Test if Internet Explorer is used and get its version number</h2>
<p>I do not know how much functions, CSS selectors or whatever - IE so often acts different or just stupid. It always requires extra work. This after all will help you to detect this nasty browser.</p>
<pre lang="javascript">
// use the class
if(Browser.Version() <8) {
	// make crazy IE shit
}
 
var Browser = {
    Version: function(){
        var version = 999; // we assume a sane browser
        if (navigator.appVersion.indexOf("MSIE") != -1) 
            // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        return version;
    }
}
</pre>
<h2>3. Clear input-field onclick, if value is default</h2>
<p>This is not much of javascript, we actually call it dynamic html. It is just the standard way to present the comfortable input fields to users.</p>
<pre lang="javascript">
<input type="text" name="" value="username" onclick="if(this.value=='username') this.value='';" />
</pre>
<h2>4. Test if a String is not empty</h2>
<p>Can help to avoid a lot of common mistakes with javascript.</p>
<pre lang="javascript">
var bpat    = /\S/;
function isNonblank (s) {
   return String (s).search (bpat) != -1
}
</pre>
<h2>5. Function Exists</h2>
<p>This is a possibility in Javascript to test if a function exists (like function_exists in PHP). This can be useful in cases of debugging or when you are not sure if some required script file is loaded, for example.</p>
<pre lang="javascript">
if(typeof yourFunctionName == 'function') {
     yourFunctionName();
}
</pre>
<h2>6. Get scroll width/height of page visitors' browser window</h2>
<p>A browser-safe way to get the number of pixels, which a user scrolled down the webpage currently.</p>
<pre lang="javascript">
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
 
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}
</pre>
<h2>7. Get current size of page visitors' browser window</h2>
<p>A browser-safe way to get the window height and window width of the current viewers browser in pixels.</p>
<pre lang="javascript">
function getWindowSize() {
    var myWidth = 0, myHeight = 0;
 
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [ myWidth, myHeight ];
}
</pre>
<h2>8. Scale images by setting a maximum width/height</h2>
<p>It is not always the best idea to scale images with javascript. But I came to several applications there this was useful though.</p>
<pre lang="javascript">

var images = document.getElementsByTagName("img"); // get your images somehow
scaleImages(imgs,150,150); // call the function
         
// scales the images to a maximum width/height
function scaleImages(images,maxh,maxw) {
  
for(i=0;i<imgs.length;i++) {
	var ratio = maxh/maxw;
	var img = imgs[i];
	  
	if (img.height/img.width > ratio){
		// height is the problem
		if (img.height > maxh){
			img.width = Math.round(img.width*(maxh/img.height));
			img.height = maxh;
		}
	} else {
		// width is the problem
		if (img.width > maxh){
			img.height = Math.round(img.height*(maxw/img.width));
			img.width = maxw;
		}
	  }
	  img.setAttribute("class","showpreview ready");
  }
}
</pre>
<h2>9. Print Javascript Array (like print_r()-in PHP)</h2>
<p>A really useful function for debugging and developing with javascript. Instead of [object Object] or something similar you will see the whole contents of an array in your output.</p>
<pre lang="javascript">
	function dump(arr,level) {
		var dumped_text = "";
		if(!level) level = 0;
		
		//The padding given at the beginning of the line.
		var level_padding = "";
		for(var j=0;j<level+1;j++) level_padding += "    ";
		
		if(typeof(arr) == 'object') { //Array/Hashes/Objects 
			for(var item in arr) {
				var value = arr[item];
				
				if(typeof(value) == 'object') { //If it is an array,
					dumped_text += level_padding + "'" + item + "' ...\n";
					dumped_text += dump(value,level+1);
				} else {
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
				}
			}
		} else { //Stings/Chars/Numbers etc.
			dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
		}
		return dumped_text;
	}
</pre>
<h2>10. XML2Array (parse xml to javascript array)</h2>
<p>For the special case of reading XML with Javascript. But very useful, when it comes to the case. It is much easier to handle a huge array in Javascript than reading lots of data from a complex XML-file. Maybe there is a tiny disadvantage concerning speed, but I think it is worth that.</p>
<pre lang="javascript">
//////////////////////////////////// xml2array() ////////////////////////////////////////
// See http://www.openjs.com/scripts/xml_parser/
var not_whitespace = new RegExp(/[^\s]/); //This can be given inside the funciton - I made it a global variable to make the scipt a little bit faster.
var parent_count;
//Process the xml data
function xml2array(xmlDoc,parent_count) {
	var arr;
	var parent = "";
	parent_count = parent_count || new Object;

	var attribute_inside = 0; /*:CONFIG: Value - 1 or 0
	*	If 1, Value and Attribute will be shown inside the tag - like this...
	*	For the XML string...
	*	<guid isPermaLink="true">http://www.bin-co.com/</guid>
	*	The resulting array will be...
	*	array['guid']['value'] = "http://www.bin-co.com/";
	*	array['guid']['attribute_isPermaLink'] = "true";
	*	
	*	If 0, the value will be inside the tag but the attribute will be outside - like this...	
	*	For the same XML String the resulting array will be...
	*	array['guid'] = "http://www.bin-co.com/";
	*	array['attribute_guid_isPermaLink'] = "true";
	*/

	if(xmlDoc.nodeName && xmlDoc.nodeName.charAt(0) != "#") {
		if(xmlDoc.childNodes.length > 1) { //If its a parent
			arr = new Object;
			parent = xmlDoc.nodeName;
			
		}
	}
	var value = xmlDoc.nodeValue;
	if(xmlDoc.parentNode && xmlDoc.parentNode.nodeName && value) {
		if(not_whitespace.test(value)) {//If its a child
			arr = new Object;
			arr[xmlDoc.parentNode.nodeName] = value;
		}
	}

	if(xmlDoc.childNodes.length) {
		if(xmlDoc.childNodes.length == 1) { //Just one item in this tag.
			arr = xml2array(xmlDoc.childNodes[0],parent_count); //:RECURSION:
		} else { //If there is more than one childNodes, go thru them one by one and get their results.
			var index = 0;

			for(var i=0; i<xmlDoc.childNodes.length; i++) {//Go thru all the child nodes.
				var temp = xml2array(xmlDoc.childNodes[i],parent_count); //:RECURSION:
				if(temp) {
					var assoc = false;
					var arr_count = 0;
					for(key in temp) {
						if(isNaN(key)) assoc = true;
						arr_count++;
						if(arr_count>2) break;//We just need to know wether it is a single value array or not
					}

					if(assoc && arr_count == 1) {
						if(arr[key]) { 	//If another element exists with the same tag name before,
										//		put it in a numeric array.
							//Find out how many time this parent made its appearance
							if(!parent_count || !parent_count[key]) {
								parent_count[key] = 0;

								var temp_arr = arr[key];
								arr[key] = new Object;
								arr[key][0] = temp_arr;
							}
							parent_count[key]++;
							arr[key][parent_count[key]] = temp[key]; //Members of of a numeric array
						} else {
							parent_count[key] = 0;
							arr[key] = temp[key];
							if(xmlDoc.childNodes[i].attributes && xmlDoc.childNodes[i].attributes.length) {
								for(var j=0; j<xmlDoc.childNodes[i].attributes.length; j++) {
									var nname = xmlDoc.childNodes[i].attributes[j].nodeName;
									if(nname) {
										/* Value and Attribute inside the tag */
										if(attribute_inside) {
											var temp_arr = arr[key];
											arr[key] = new Object;
											arr[key]['value'] = temp_arr;
											arr[key]['attribute_'+nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										} else {
										/* Value in the tag and Attribute otside the tag(in parent) */
											arr['attribute_' + key + '_' + nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										}
									}
								} //End of 'for(var j=0; j<xmlDoc. ...'
							} //End of 'if(xmlDoc.childNodes[i] ...'
						}
					} else {
						arr[index] = temp;
						index++;
					}
				} //End of 'if(temp) {'
			} //End of 'for(var i=0; i<xmlDoc. ...'
		}
	}

	if(parent &#038;&#038; arr) {
		var temp = arr;
		arr = new Object;
		
		arr[parent] = temp;
	}
	return arr;
}
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F07%2F01%2Fmy-todays-top-10-most-useful-javascript-functions%2F&#038;title=My%20todays%20top%2010%20most%20useful%20Javascript%20Functions" data-a2a-url="https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/" data-a2a-title="My todays top 10 most useful Javascript Functions"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress improved user search (first name, last name, email) in backend</title>
		<link>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/</link>
					<comments>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 27 Jun 2011 22:35:01 +0000</pubDate>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[search]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1457</guid>

					<description><![CDATA[Recently, when working on a WordPress website for a huge amount of users, a customer was unsatisfyied with the WordPress backend search for users. The default backend search only is searching for your search string in usernames, but not for first name, last name or email of users. &#160; As most WordPress projects are barely [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Recently, when working on a WordPress website for a huge amount of users, a customer was unsatisfyied with the WordPress backend search for users. The default backend search only is searching for your search string in usernames, but not for first name, last name or email of users.</p>
<p>&nbsp;</p>
<p>As most WordPress projects are barely designed to have a huge amoung of users, this is not necessary in most cases. Anyway, the following code will help with this problem &#8211; add this to your functions.php-file and the WordPress user search will scan first name, last name and e-mail of every user.</p>
<p>&nbsp;</p>
<p style="text-align:center;"><a href="http://wordpress.org/extend/plugins/improved-user-search-in-backend/">Download the official WordPress Plugin</a></p>
<div class="code_title">How the Plugin basically works (code overview of Version 1.2)</div>
<pre lang="php">
 
   // the actual improvement of the query
    function user_search_by_multiple_parameters($wp_user_query) {
        if(false === strpos($wp_user_query -> query_where, '@') && !empty($_GET["s"])) {

            global $wpdb;

            $uids=array();

			// get the custom meta fields to search
			$iusib_custom_meta = get_option('iusib_meta_fields');
			$iusib_cma = array_map('trim', explode(",",$iusib_custom_meta));

			$iusib_add = "";
			// the escaped query string
			$qstr = mysql_real_escape_string($_GET["s"]);
			
			// add all custom fields into the query
			if(!empty($iusib_cma)) {
				$iusib_add = " OR meta_key='".implode("' OR meta_key='",$iusib_cma)."'";
			}

            $usermeta_affected_ids = $wpdb -> get_results("SELECT DISTINCT user_id FROM ".$wpdb->base_prefix."usermeta WHERE (meta_key='first_name' OR meta_key='last_name'".$iusib_add.") AND LOWER(meta_value) LIKE '%".$qstr."%'");

            foreach($usermeta_affected_ids as $maf) {
                array_push($uids,$maf->user_id);
            }

            $users_affected_ids = $wpdb -> get_results("SELECT DISTINCT ID FROM ".$wpdb->base_prefix."users WHERE LOWER(user_nicename) LIKE '%".$qstr."%' OR LOWER(user_email) LIKE '%".$qstr."%'");

            foreach($users_affected_ids as $maf) {
                if(!in_array($maf->ID,$uids)) {
                    array_push($uids,$maf->ID);
                }
            }
			
            $id_string = implode(",",$uids);

            $wp_user_query -> query_where = str_replace("user_nicename LIKE '%".$qstr."%'", "ID IN(".$id_string.")", $wp_user_query -> query_where);
        }
        return $wp_user_query;
    }

</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F06%2F27%2Fwordpress-improved-user-search-first-name-last-name-email-in-backend%2F&#038;title=WordPress%20improved%20user%20search%20%28first%20name%2C%20last%20name%2C%20email%29%20in%20backend" data-a2a-url="https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/" data-a2a-title="WordPress improved user search (first name, last name, email) in backend"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/feed/</wfw:commentRss>
			<slash:comments>74</slash:comments>
		
		
			</item>
		<item>
		<title>Scroll a very big database table with Ajax</title>
		<link>https://blog.blackbam.at/2010/10/18/scroll-a-very-big-database-table-with-ajax/</link>
					<comments>https://blog.blackbam.at/2010/10/18/scroll-a-very-big-database-table-with-ajax/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 18 Oct 2010 16:56:41 +0000</pubDate>
				<category><![CDATA[JavaScript / Ajax]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[very big table]]></category>
		<guid isPermaLink="false">http://www.blackbam.at/blog/?p=885</guid>

					<description><![CDATA[This tutorial shows how it is possible to scroll a very big database table using Asynchronous Javascript and JSON with an easy extendable and customizable script. We created four files &#8211; index.html (contains the Ajax table), functions.js (contains all the Ajax work), suggest.php (the server-side work), and entries.php (server-side script for instantiating number of table [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This tutorial shows how it is possible to scroll a very big database table using Asynchronous Javascript and JSON with an easy extendable and customizable script. We created four files &#8211; index.html (contains the Ajax table), functions.js (contains all the Ajax work), suggest.php (the server-side work), and entries.php (server-side script for instantiating number of table values). There is also a dummy file to create and fill the database with values fast, which is called &#8220;createTable.php&#8221;.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><strong><a href="http://www.blackbam.at/examples/ajaxdb/">Watch the example here</a></strong></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Function: When a user types in a certain pattern, the twenty nearest values are fetched from the database. When a user scrolls the table, the values are fetched depending on the position of the cursor or by fetching the next or previous entries from the database.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div class="code_title">index.html</div>
<pre lang="html4strict">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
    <head>
        <title>Scrolling a very big database table</title>
        <script type="text/javascript" src="functions.js">
        </script>
        <style type="text/css">
            #gscr div {
                height: 1px;
                width: 1px;
            }
			
			#result tr td {
				cursor:pointer;
			}
        </style>
    </head>
    <body>
        <h2>Demonstration</h2>
        <p>Shows how to get an fast and precise result from scrolling a big table using Asynchronous Javascript with JSON.</p>
        <br/>
		<div id="loading" style="display:block;"><img decoding="async" src="loader.gif" /></div>
		<div id="container" style="display:none;">
	        <div id="the_table">
	            <div id="result_area" style="float:left; width:200px;">
	                <table id="result"> </table>
	            </div>
	            <div style="float:left;">
	                <a href="javascript:scroll('u')">previous 20</a>
	                <div id="gscr" style="width:40px; height:400px; overflow-y:scroll;" onmouseup="javascript:scrAction();"> </div>
	                <a href="javascript:scroll('d')">next 20</a>
	            </div>
				<div id="collection" style="float:left; padding-left:80px;">
					<h4>Collected values</h4>
				</div>
				<div style="clear:both;"></div>
	        </div><!-- the_table div -->
	        <br/>
			<p>Search for a specific pattern:</p>
			<input type="text" id="suggest_field" onkeyup="javascript:make_suggestion(this.value,'string');"/>
			<input type="hidden" id="allEntries" value="" />
			<input type="hidden" id="mode" value="number" />
			<input type="hidden" id="running" value="no" />
			<input type="hidden" id="current" value="1" />
		</div><!-- container div -->
        <script type="text/javascript">
            make_suggestion("", "entries");
        </script>
    </body>
</html>
</pre>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div class="code_title">functions.js</div>
<pre lang="javascript">
/**
 * @author Blackbam
 */
var XMLHTTP = null;
var onetime = 1;
var onetime2 = 1;

// Server-Request for data depending on parameters
function make_suggestion(compValue, how){

    if (how == "string") {
        document.getElementById("mode").value = "string";
    }

    // instantiate browser-independent XMLHttpRequest
    if (window.XMLHttpRequest) {
        XMLHTTP = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
            try {
                XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (ex) {
                try {
                    XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (ex) {
                }
            }
        }
	
    if (how == "entries") {
		// Get the whole number of entries when loading the page
		var scrHeight = document.getElementById("gscr").style.height;
        XMLHTTP.open("GET", "entries.php?height="+scrHeight);
        XMLHTTP.onreadystatechange = setEntries;
    } else {
        if (how == "string" && compValue == "") {
            document.getElementById("current").value = 1;
			numeric_request();
        } else {
                XMLHTTP.open("GET", "suggest.php?compValue=" + compValue + "&how=" + how);
                XMLHTTP.onreadystatechange = MyRequestExecute;
        }
    }
    XMLHTTP.send(null);
}

// is called when the Server-Request reaches a new state
function MyRequestExecute(){
	// the answer from the server is hier when the XMLHTTP.readyState = 4
    if (XMLHTTP.readyState == 4) {
		
		// remove old entries from the table
		var cell = document.getElementById("result");
		if ( cell.hasChildNodes() ){
		    while ( cell.childNodes.length >= 1 ) {
		        cell.removeChild( cell.firstChild );       
		    } 
		}
		
		// Create a valid table content with the Jason-object
		var obj=eval('('+XMLHTTP.responseText+')');
		for(val in obj){
			var tr = cell.appendChild(document.createElement("tr"));
			var td = tr.appendChild(document.createElement("td"));
			td.setAttribute("onclick","javascript:collect(this.firstChild.nodeValue);");
			td.appendChild(document.createTextNode(obj[val]));
		}
		
		// if first time, display the table to the user now
		if (onetime2 == 1) {
			document.getElementById("loading").style.display = "none";
			document.getElementById("container").style.display = "block";
			onetime2 = 0;
		}
    }
}

// this function is called when the page is loaded first
function setEntries(){
	
	// when the server answers the number of table entries
    if (XMLHTTP.readyState == 4) {
		if (onetime == 1) {
			onetime = 0;
			var entries = XMLHTTP.responseText;
			document.getElementById("allEntries").value = entries;
			
			// a little hack: create as many 1px-divs as there are entries in the database
			for (i = 0; i <= entries; i++) {
				document.getElementById("gscr").appendChild(document.createElement("div"));
			}
			
			// now fill the table
			numeric_request();
		}
    }
}

// is used if a user scrolls the table using the scrollbar
function scrAction() {
	// alert(document.getElementById("gscr").scrollTop+1);
	document.getElementById("current").value=(document.getElementById("gscr").scrollTop+1);
	numeric_request();
}

// is called every time a user scrolls the table
function numeric_request(){
	document.getElementById("mode").value = "number";
	var startentry = document.getElementById("current").value;
	make_suggestion(startentry, "number");
}

// is called if a user scrolls the table by previous and next entries
function scroll(wohin){
	
	var curEntr = document.getElementById("current");
	var scrollbar = document.getElementById("gscr");

	var scrval = parseInt(curEntr.value);
	var allEntries = parseInt(document.getElementById("allEntries").value);
	
	if(wohin == 'u'){
		if(scrval < 20) {
			curEntr.value = 1;
			scrollbar.scrollTop = 1;
		} else {
			curEntr.value = (scrval-19);
			scrollbar.scrollTop = (scrval-19);
		}
	} else {
		var scrHeight = parseInt(document.getElementById("gscr").style.height)-2;
		var whole = parseInt(allEntries-scrHeight);
		if(scrval >= whole) {
			curEntr.value = whole;
			scrollbar.scrollTop = whole;
		} else {
			curEntr.value = (scrval+19);
			scrollbar.scrollTop = (scrval+19);
		}
	}
	numeric_request();
}

// stores the values the user has clicked
function collect(value) {
	document.getElementById("collection").appendChild(document.createTextNode(value));
	document.getElementById("collection").appendChild(document.createElement("br"));
}
</pre>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div class="code_title">suggest.php</div>
<pre lang="php">
<?php
/* Strings 2 compare */
$suggest_string = $_GET["compValue"];
$how = $_GET["how"];

/* MySQL connection */
$hostname = 'localhost';
$username = 'root';
$password = '';

// SQL-Statement
if ($how == "number") {
    $sql = "SELECT * FROM meta ORDER BY random_word LIMIT ".$suggest_string.",20";
} else {
    $sql = "SELECT * FROM meta WHERE random_word LIKE '".$suggest_string."%' ORDER BY random_word LIMIT 20";
}

$result_string = array();
$i = 0;

try {
    // Datenbankverbindung
    $db = new PDO("mysql:host=$hostname;dbname=meta", $username, $password);

    // Ergebnisse holen
    foreach ($db->query($sql) as $row) {
        $result_string[$i] = $row['random_word'];
		$i++;
    }

}
catch(PDOException $e) {
    echo $e->getMessage();
}

echo json_encode($result_string);

?>
</pre>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div class="code_title">entries.php</div>
<pre lang="php">
<?php
/* MySQL connection */
$hostname = 'localhost';
$username = 'root';
$password = '';

// höhe des scrolldivs hinzurechnen
$height = $_GET["height"]-22;

$sql = "SELECT * from meta";

$result_string = "";

try {
    // database connection
    $db = new PDO("mysql:host=$hostname;dbname=meta", $username, $password);

    // get results
    $result_string = count($db->query($sql)->fetchAll())+$height;

}
catch(PDOException $e) {
    echo $e->getMessage();
}

echo $result_string;

?>
</pre>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div class="code_title">The dummy &#8211; createTable.php</div>
<pre lang="php">
/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'root';

/*** mysql password ***/
$password = '';

try {
    $db = new PDO("mysql:host=$hostname;dbname=meta", $username, $password);

    for ($i = 0; $i < 12000; $i++) {
        $random_word = randWord();
        try {
            $db->exec("INSERT INTO meta(random_word) VALUES ('$random_word')");
        }
        catch(PDOException $e) {
            echo "Eintrag ".$random_word." konnte nicht geschrieben werden. <br/>";
        }
    }

}
catch(PDOException $e) {
    echo $e->getMessage();
}

function randWord() {
    $length = rand(5, 15);
    $characters = "abcdefghijklmnopqrstuvwxyz";
    $string = "";

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }

    return $string;
}

echo "It is finally done without crashing the server!";

?>
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2010%2F10%2F18%2Fscroll-a-very-big-database-table-with-ajax%2F&#038;title=Scroll%20a%20very%20big%20database%20table%20with%20Ajax" data-a2a-url="https://blog.blackbam.at/2010/10/18/scroll-a-very-big-database-table-with-ajax/" data-a2a-title="Scroll a very big database table with Ajax"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2010/10/18/scroll-a-very-big-database-table-with-ajax/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
