<?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>takien, not taken &#187; PHP</title> <atom:link href="http://takien.com/category/website/php/feed" rel="self" type="application/rss+xml" /><link>http://takien.com</link> <description>Webmaster&#039;s Information and Resource</description> <lastBuildDate>Fri, 03 Feb 2012 16:11:17 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Prevent Spammer to Register Using The Same Gmail Email (Duplicate User Accounts)</title><link>http://takien.com/1010/prevent-spammer-to-register-using-the-same-gmail-email-duplicate-user-accounts.php</link> <comments>http://takien.com/1010/prevent-spammer-to-register-using-the-same-gmail-email-duplicate-user-accounts.php#comments</comments> <pubDate>Sat, 21 Jan 2012 10:28:25 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://takien.com/?p=1010</guid> <description><![CDATA[Gmail,  Gmail is &#8230;, ah I really don&#8217;t need to explain this. So, continue reading The Facts Gmail ignores . (dot) in username If you have Gmail account example@gmail.com, actually you also have ex.ample@gmail.com, exam.ple@gmail.com, and so on until all characters in the username are separated with dot. These all have same inbox, and you can [...]]]></description> <content:encoded><![CDATA[<div
id="attachment_1026" class="wp-caption aligncenter" style="width: 270px"><a
href="http://img.takien.com/2012/01/gmail-new-look-logo.jpg"><img
class="size-full wp-image-1026" title="gmail-new-look-logo" src="http://img.takien.com/2012/01/gmail-new-look-logo.jpg" alt="Gmail logo new look" width="260" height="178" /></a><p
class="wp-caption-text">Gmail logo new look</p></div><p>Gmail,  Gmail is &#8230;, ah I really don&#8217;t need to explain this. So, continue reading <img
src='http://takien.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><h2>The Facts</h2><h3>Gmail ignores . (dot) in username</h3><p>If you have Gmail account <em>example@gmail.com</em>, actually you also have ex.ample@gmail.com, exam.ple@gmail.com, and so on until all characters in the username are separated with dot. These all have same inbox, and you can login using each of them. Also, emails come to that address will be received into one inbox example@gmail.com See: <a
href="http://www.dailytut.com/technology/gmail-dot-trick-bug-or-a-feature.html" target="_blank"><em>Gmail Dot Trick Bug or a Feature ?</em> </a></p><h3>Gmail ignores all character after + (plus sign) in username</h3><p>While you think the dot feature is not enough, Gmail also has another feature; you can add acceptable character in your username, separated by + (plus sign). It can be example+one@gmail.com, example+two@gmail.com, etc. An email sent to example@gmail.com or example+one@gmail.com or example+two@gmail.com will all be redirected to one common email address and that is example@gmail.com.<em> See: <a
href="http://labnol.blogspot.com/2006/09/gmail-easter-eggs-dot-blindess-email.html" target="_blank">GMail Easter Eggs: Dot Blindess &amp; Email Aliases</a></em>.<em><a
href="http://labnol.blogspot.com/2006/09/gmail-easter-eggs-dot-blindess-email.html" target="_blank"><br
/> </a></em></p><p>Gmail does not recognize characters after the PLUS symbol but the gmail search filter can distinguish between the different address and you can therefore redirect these email to separats gmail folders or apply different labels.</p><h3>Gmail user can use @googlemail.com instead of @gmail.com</h3><p>Again, example@gmail.com can be replaced with example@googlemail.com as well as if it combined with <em>dot</em> and <em>plus</em>.</p><h2>The Problem</h2><div
id="attachment_1027" class="wp-caption aligncenter" style="width: 288px"><a
href="http://img.takien.com/2012/01/spammer-in-smf-forum.png"><img
class="size-medium wp-image-1027" title="spammer-in-smf-forum" src="http://img.takien.com/2012/01/spammer-in-smf-forum-278x300.png" alt="Spammer in SMF forum" width="278" height="300" /></a><p
class="wp-caption-text">Spammer in SMF forum</p></div><p>Besides the advantage of filtering, this feature has disadvantage for website owner, eg Community Forum and or website that requires unique membership. Yes, persons with Gmail account could have as many as possible <strong>duplicate accounts</strong> in our website. Of course this is very undesirable. Moreover, this way mostly used by <strong>spammer</strong> to register in our forum as they only need one Gmail account to register their hundreds clone. Imagine this, how many accounts can be generated from one Gmail account? It almost infinite, if I can&#8217;t say unlimited.</p><h2>The Solution</h2><p>If you think Gmail feature is bad for membership website, the only solution is to strip all gmail aliases and leave only original <em>example@gmail.com</em> during member registration process. The following lines of code is a PHP functions for this task.</p><p><iframe
src="http://ngoding.com/54918.embed" frameborder="0" scrolling="no" width="100%" height="161"></p><pre>function strip_gmail_email_aliases($email){
if(preg_match('/gmail|googlemail/i',$email)){ /*detect if email string matches gmail or googlemail using preg_match() regex*/
$emailbody         = explode('@',strtolower($email)); /*separate email at @ sign using explode()*/
$mailusername     = preg_replace('/([\.]+)|((\+)+([\+\.\-_a-z0-9]+))/i','',$emailbody[0]); /*most important part, strip all dot and everything after 'plus' */
$email             = $mailusername.'@gmail.com'; /*rebuild email string, and use only gmail.com*/
}
return $email; /* return the new email string*/
}</pre><p></iframe></p><h2>Implementations</h2><h3>In WordPress</h3><div
id="attachment_1025" class="wp-caption aligncenter" style="width: 295px"><a
href="http://img.takien.com/2012/01/wordpress-logo.jpg"><img
class="size-full wp-image-1025" title="wordpress logo" src="http://img.takien.com/2012/01/wordpress-logo.jpg" alt="wordpress logo" width="285" height="177" /></a><p
class="wp-caption-text">wordpress logo</p></div><p>It&#8217;s easy to call this function in WordPress platform, using <strong>user_registration_email</strong> filter <a
href="http://takien.com/?s=hook" target="_blank">hook</a>. This function will be invoked immediately while user perform registration. Place this code in functions.php in your WordPress theme file or can be packaged into a <a
href="http://takien.com/?s=plugin" target="_blank">plugin</a>.</p><p><iframe
src="http://ngoding.com/2abc1.embed" frameborder="0" scrolling="no" width="100%" height="188"><pre>add_filter( 'user_registration_email', 'strip_gmail_email_aliases'); /* this filter will call strip_gmail_email_aliases functions*/
function strip_gmail_email_aliases($email){
if(preg_match('/gmail|googlemail/i',$email)){
$emailbody         = explode('@',strtolower($email));
$mailusername     = preg_replace('/([\.]+)|((\+)+([\+\.\-_a-z0-9]+))/i','',$emailbody[0]);
$email             = $mailusername.'@gmail.com';
}
return $email;
}</pre><p></iframe></p><h3>In SMF (Simple Machines Forum)</h3><div
id="attachment_1024" class="wp-caption aligncenter" style="width: 310px"><a
href="http://img.takien.com/2012/01/smf-forum.jpg"><img
class="size-medium wp-image-1024" title="smf-forum" src="http://img.takien.com/2012/01/smf-forum-300x158.jpg" alt="SMF Forum Logo" width="300" height="158" /></a><p
class="wp-caption-text">SMF Forum Logo</p></div><p>Unlike WordPress, SMF needs more attention while doing modifications. Yes, you need to hardly editing existing file, so don&#8217;t forget to backup before you do anything with files in SMF.</p><ol><li>The file you will edit located in<strong> /Sources/Register.php</strong></li><li>Open file with code editor, eg. Notepad++</li><li>Find this set of codes:<p><iframe
src="http://ngoding.com/281fc.embed" frameborder="0" scrolling="no" width="100%" height="300"></p><pre>	// Set the options needed for registration.
	$regOptions = array(
		'interface' =&gt; 'guest',
		'username' =&gt; !empty($_POST['user']) ? $_POST['user'] : '',
		'email' =&gt; !empty($_POST['email']) ? $_POST['email'] : '',
		'password' =&gt; !empty($_POST['passwrd1']) ? $_POST['passwrd1'] : '',
		'password_check' =&gt; !empty($_POST['passwrd2']) ? $_POST['passwrd2'] : '',
		'openid' =&gt; !empty($_POST['openid_identifier']) ? $_POST['openid_identifier'] : '',
		'auth_method' =&gt; !empty($_POST['authenticate']) ? $_POST['authenticate'] : '',
		'check_reserved_name' =&gt; true,
		'check_password_strength' =&gt; true,
		'check_email_ban' =&gt; true,
		'send_welcome_email' =&gt; !empty($modSettings['send_welcomeEmail']),
		'require' =&gt; !empty($modSettings['coppaAge']) &amp;&amp; !$verifiedOpenID &amp;&amp; empty($_SESSION['skip_coppa']) ? 'coppa' : (empty($modSettings['registration_method']) ? 'nothing' : ($modSettings['registration_method'] == 1 ? 'activation' : 'approval')),
		'extra_register_vars' =&gt; array(),
		'theme_vars' =&gt; array(),
	);</pre><p></iframe></li><li>DO NOT edit anything inside the code above, yet add this code after it:<p><iframe
src="http://ngoding.com/c28dd.embed" frameborder="0" scrolling="no" width="100%" height="147"></p><pre>/* strip all gmail aliases, comment here is useful when you want to do something in the future*/
if(preg_match('/gmail|googlemail/i',$regOptions['email'])){
	$emailbody 		= explode('@',strtolower($regOptions['email']));
	$mailusername 		= preg_replace('/([\.]+)|((\+)+([\+\.\-_a-z0-9]+))/i','',$emailbody[0]);
	$regOptions['email']= $mailusername.'@gmail.com';
}
/* end strip all gmail aliases*/</pre><p></iframe></p><p>As you see this is a direct code, not a PHP function, since it&#8217;s already in another SMF function, Register2()</li><li>Save file and re-upload it to server.</li></ol><h3>In Custom PHP</h3><p>If you using custom PHP code or CMS other than WordPress and SMF, call<em> strip_gmail_email_aliases()</em> right after registration form is submitted. Example:</p><p><iframe
src="http://ngoding.com/a41dc.embed" frameborder="0" scrolling="no" width="100%" height="258"></p><pre>/* define function*/
function strip_gmail_email_aliases($email){
if(preg_match('/gmail|googlemail/i',$email)){
$emailbody         = explode('@',strtolower($email));
$mailusername     = preg_replace('/([\.]+)|((\+)+([\+\.\-_a-z0-9]+))/i','',$emailbody[0]);
$email             = $mailusername.'@gmail.com';
}
return $email; /* return the new email string*/
}
if(isset($_POST['submit_register'])){ /* It's only an illustration and may differ with your actual code.*/
    $email = strip_gmail_email_aliases($_POST['email']);
    /* do the rest code here */
}
</pre><p></iframe></p><h2>Conclusion</h2><p><div
style="float:right;width:300px;height:250px;margin-left:20px"><script type="text/javascript"><!-- google_ad_client = "pub-3108107609212063"; /* takien-content-300x250, created 12/9/10 */ google_ad_slot = "4897738383"; google_ad_width = 300; google_ad_height = 250; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div>If you put the code correctly and work well, the registration will only record example@gmail.com (without dot, without + and other character after it, and not googlemail.com domain) and all other alias combination will be considered as duplicate (already registered). <img
src='http://takien.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p><p>Your comment are welcome. <img
src='http://takien.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://takien.com/1010/prevent-spammer-to-register-using-the-same-gmail-email-duplicate-user-accounts.php/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Creating a WordPress-Alike Hook For Your Own CMS</title><link>http://takien.com/965/how-to-make-hook-on-your-own-cms-like-on-wordpress.php</link> <comments>http://takien.com/965/how-to-make-hook-on-your-own-cms-like-on-wordpress.php#comments</comments> <pubDate>Thu, 15 Dec 2011 15:48:05 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://takien.com/?p=965</guid> <description><![CDATA[Probably you have known this, WordPress code is pretty good, especially when compared with other CMS or what we ever found on PHP tutorials. The one I like is how WordPress uses hooks.   If you ever created WordPress plugins, you may experienced that you don&#8217;t need to modify any of core code just to add [...]]]></description> <content:encoded><![CDATA[<div
id="attachment_972" class="wp-caption alignleft" style="width: 310px"><a
href="http://img.takien.com/2011/12/hooks.jpg"><img
class="size-medium wp-image-972" title="hooks" src="http://img.takien.com/2011/12/hooks-300x300.jpg" alt="" width="300" height="300" /></a><p
class="wp-caption-text">Hooks ilustration, image courtesy of lookingglassoutfitters.com</p></div><p>Probably you have known this, WordPress code is pretty good, especially when compared with other CMS or what we ever found on PHP tutorials. The one I like is how WordPress uses <a
href="http://codex.wordpress.org/Plugin_API/Hooks" target="_blank">hooks.</a>   If you ever created WordPress <a
href="http://takien.com/category/cms/wordpress/wp-plugins" target="_blank">plugins</a>, you may experienced that you don&#8217;t need to modify any of core code just to add something in the header and footer. Or even for more complex task, add additional menu and page on WordPress admin.</p><p>Things you need to do is to know what hook related to that, and add actions or filter with your own callback function. WordPress hooks divided in to two sections; <em>Action hook</em> and <em>Filter hook</em>. What is the difference? In simple, actions is to add functionality or output, where filter is to manipulate existing output. WordPress hook code stored in <em>wp-includes/plugins.php</em></p><p>Err, I am not going to deeply explain about WordPress hook. But, in case you&#8217;re wondering how it works or may be you want implement it in your own CMS or PHP script, here is the step by step .</p><p><div
style="float:right;width:300px;height:250px;margin-left:20px"><script type="text/javascript"><!-- google_ad_client = "pub-3108107609212063"; /* takien-content-300x250, created 12/9/10 */ google_ad_slot = "4897738383"; google_ad_width = 300; google_ad_height = 250; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div>If WordPress uses global variable <strong>$wp_filter</strong> to store all of the filters, we use <strong>$cms_filter</strong> instead, or name it whatever you like .  This variable contains array of filters where we could modify later. To start, fill it with empty array.</p><pre>$cms_filter = Array();</pre><p>Declare <strong>do_action()</strong> function, the task of this function is to call custom functions stored in $cms_filter, uses  <a
href="http://php.net/manual/en/function.call-user-func-array.php" target="_blank"><em>call_user_func_array()</em></a>;</p><pre>function do_action($tag){
global $cms_filter;
if(isset($cms_filter[$tag]) AND function_exists($cms_filter[$tag])){
call_user_func_array($cms_filter[$tag], array());
}
}</pre><p>Declare <strong>add_action()</strong> function, the task of this function is to store custom function to $cms_filter global variable.</p><pre>function add_action($tag,$callback){
global $cms_filter;
$cms_filter[$tag] = $callback;
}</pre><p>And&#8230;&#8230;&#8230;. you&#8217;re done. What..? Yes, that code is already to use.</p><p>Ok, let&#8217;s go. Place this code in wherever you like, for example in your core CMS file, or in your header&#8217;s template file between &lt;head&gt; and &lt;/head&gt;</p><pre>do_action('cms_head');</pre><p>Whenever you want to add something to the location, just call this function:</p><pre>add_action('cms_head','script_in_my_head');</pre><p><em>cms_head</em> is hook name, and<em> script_in_my_head</em> is must exists callback function that refer to your custom code. See example below:</p><pre>function script_in_my_head(){
echo '&lt;script&gt;alert('Hello world!')&lt;/script&gt;';
}</pre><p><strong>Note</strong>: This is only a simple working code, not a replacement nor has same capability as actual WordPress hooks. You may edit or improve it to meet your need.</p> ]]></content:encoded> <wfw:commentRss>http://takien.com/965/how-to-make-hook-on-your-own-cms-like-on-wordpress.php/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Searching File Within Directory Recursively Using PHP</title><link>http://takien.com/956/searching-file-within-directory-recursively-using-php-scandir.php</link> <comments>http://takien.com/956/searching-file-within-directory-recursively-using-php-scandir.php#comments</comments> <pubDate>Wed, 26 Oct 2011 19:45:04 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://takien.com/?p=956</guid> <description><![CDATA[Recently I had to find my file stored somewhere in my server. Although I can do this easily using the built-in feature in cPanel File Manager, but what I need is to search file programaticallyusing a script. So, I created this function. The function accepts three parameters: $dir (string), absolute path of the directory to [...]]]></description> <content:encoded><![CDATA[<p>Recently I had to find my file stored somewhere in my server. Although I can do this easily using the built-in feature in cPanel File Manager, but what I need is to search file programaticallyusing a script. So, I created this function.</p><pre>function find_file($dirs,$filename,$exact=false){

	$dir = @scandir($dirs);
	if(is_array($dir) AND !empty($dir)){
	foreach($dir as $file){
	if(($file !== '.') AND ($file!=='..')){
	if (is_file($dirs.'/'.$file)){
		$filepath =  realpath($dirs.'/'.$file);

		if(!$exact){
			$pos = strpos($file,$filename);
			if($pos === false) {
			}
			else {
				if(file_exists($filepath) AND is_file($filepath)){
				echo str_replace($filename,'&lt;span style="color:red;font-weight:bold"&gt;'.$filename.'&lt;/span&gt;',$filepath).' ('.round(filesize($filepath)/1024).'kb)&lt;br /&gt;';
				}
			}
		}
		elseif(($file == $filename)){

			if(file_exists($filepath) AND is_file($filepath)){
				echo str_replace($filename,'&lt;span style="color:red;font-weight:bold"&gt;'.$filename.'&lt;/span&gt;',$filepath).' ('.round(filesize($filepath)/1024).'kb)&lt;br /&gt;';
			}
		}
	}
	else{
		find_file($dirs.'/'.$file,$filename,$exact);
	}
	}
	}
	}
}</pre><p>The function accepts three parameters:</p><p><div
style="float:right;width:300px;height:250px;margin-left:20px"><script type="text/javascript"><!-- google_ad_client = "pub-3108107609212063"; /* takien-content-300x250, created 12/9/10 */ google_ad_slot = "4897738383"; google_ad_width = 300; google_ad_height = 250; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div></p><ol><li>$dir (string), absolute path of the directory to start the search, to use current directory use dirname(__FILE__).</li><li>$filename (string), the keyword to search for.</li><li>$exact (bool), true/false, default is false. If you set it to true it will find the exact &#8216;index.php&#8217; not &#8216;anotherindex.php&#8217; for keyword &#8216;index.php&#8217;.</li></ol><h2>How to use this function?</h2><p>This will find all file name contains <strong>content</strong> within current directory and all it&#8217;s sub directories.</p><pre>&lt; ?php find_file(dirname(__FILE__),'content');
?&gt;</pre><p>And the search result will be like this:</p><div
id="attachment_959" class="wp-caption aligncenter" style="width: 310px"><a
href="http://img.takien.com/2011/10/search-file-using-php.png"><img
class="size-medium wp-image-959" title="search-file-using-php" src="http://img.takien.com/2011/10/search-file-using-php-300x186.png" alt="Search file using PHP functions" width="300" height="186" /></a><p
class="wp-caption-text">Search file using PHP functions</p></div><h2>Another Approach</h2><p>Another way to search file in directory is using PHP <a
href="http://php.net/manual/en/function.glob.php" target="_blank"><strong>glob</strong> </a>function, as written <a
href="http://www.electrictoolbox.com/php-glob-find-files/" target="_blank">here</a>.</p> ]]></content:encoded> <wfw:commentRss>http://takien.com/956/searching-file-within-directory-recursively-using-php-scandir.php/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>[PHP] How To Parse Youtube URL to Get Video ID, Thumbnail Image, or Embed Code</title><link>http://takien.com/864/php-how-to-parse-youtube-url-to-get-video-id-thumbnail-image-or-embed-code.php</link> <comments>http://takien.com/864/php-how-to-parse-youtube-url-to-get-video-id-thumbnail-image-or-embed-code.php#comments</comments> <pubDate>Wed, 25 May 2011 03:14:36 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://takien.com/?p=864</guid> <description><![CDATA[Hello, sometime we need to parse Youtube URL to get video ID, thumbnail image, or embed code automatically with PHP. To do so, I have created a function parse_youtube_url(); With this function we can: - Get video ID - Get Embed code - Get Thumbnail or HQ Thumbnail URL Check this out: Note: Please report [...]]]></description> <content:encoded><![CDATA[<div
id="attachment_866" class="wp-caption alignleft" style="width: 160px"><a
href="http://takien.com/wp-content/uploads/2011/05/youtube-screenshot.jpg"><img
class="size-thumbnail wp-image-866" title="youtube-screenshot" src="http://takien.com/wp-content/uploads/2011/05/youtube-screenshot-150x150.jpg" alt="Youtube Screenshot" width="150" height="150" /></a><p
class="wp-caption-text">Youtube Screenshot</p></div><p>Hello, sometime we need to parse Youtube URL to get video ID, thumbnail image, or embed code automatically with PHP. To do so, I have created a function <strong>parse_youtube_url();</strong></p><p>With this function we can:</p><p>- Get video ID<br
/> - Get Embed code<br
/> - Get Thumbnail or HQ Thumbnail URL</p><p>Check this out:<br
/> <span
id="more-864"></span></p><pre>/*
* parse_youtube_url() PHP function
* Author: takien
* URL: http://takien.com
*
* @param string $url URL to be parsed, eg:
* http://youtu.be/zc0s358b3Ys,
* http://www.youtube.com/embed/zc0s358b3Ys
* http://www.youtube.com/watch?v=zc0s358b3Ys
* @param string $return what to return
* - embed, return embed code
* - thumb, return URL to thumbnail image
* - hqthumb, return URL to high quality thumbnail image.
* @param string $width width of embeded video, default 560
* @param string $height height of embeded video, default 349
* @param string $rel whether embeded video to show related video after play or not.

*/

function parse_youtube_url($url,$return='embed',$width='',$height='',$rel=0){
	$urls = parse_url($url);

	//url is http://youtu.be/xxxx
	if($urls['host'] == 'youtu.be'){
		$id = ltrim($urls['path'],'/');
	}
	//url is http://www.youtube.com/embed/xxxx
	else if(strpos($urls['path'],'embed') == 1){
		$id = end(explode('/',$urls['path']));
	}
	 //url is xxxx only
	else if(strpos($url,'/')===false){
		$id = $url;
	}
	//http://www.youtube.com/watch?feature=player_embedded&amp;v=m-t4pcO99gI
	//url is http://www.youtube.com/watch?v=xxxx
	else{
		parse_str($urls['query']);
		$id = $v;
		if(!empty($feature)){
			$id = end(explode('v=',$urls['query']));
		}
	}
	//return embed iframe
	if($return == 'embed'){
		return '&lt;iframe width="'.($width?$width:560).'" height="'.($height?$height:349).'" src="http://www.youtube.com/embed/'.$id.'?rel='.$rel.'" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;';
	}
	//return normal thumb
	else if($return == 'thumb'){
		return 'http://i1.ytimg.com/vi/'.$id.'/default.jpg';
	}
	//return hqthumb
	else if($return == 'hqthumb'){
		return 'http://i1.ytimg.com/vi/'.$id.'/hqdefault.jpg';
	}
	// else return id
	else{
		return $id;
	}
}</pre><pre>&lt;?php
echo parse_youtube_url('http://youtu.be/zc0s358b3Ys','hqthumb'); //return http://i1.ytimg.com/vi/zc0s358b3Ys/hqdefault.jpg
echo parse_youtube_url('http://www.youtube.com/watch?v=zc0s358b3Ys','embed'); //return embed code (iframe)
?&gt;</pre><p>Note:<br
/> Please report if there any error in the code you copied from here, because it might has changed by WordPress during saved/published.<br
/> Thank you.</p> ]]></content:encoded> <wfw:commentRss>http://takien.com/864/php-how-to-parse-youtube-url-to-get-video-id-thumbnail-image-or-embed-code.php/feed</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>jQuery PHP: Facebook Friend Selector Without FBML</title><link>http://takien.com/718/jquery-php-facebook-friend-selector-without-fbml.php</link> <comments>http://takien.com/718/jquery-php-facebook-friend-selector-without-fbml.php#comments</comments> <pubDate>Mon, 16 Aug 2010 15:49:11 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[facebook]]></category> <category><![CDATA[html]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[json]]></category><guid
isPermaLink="false">http://takien.com/?p=718</guid> <description><![CDATA[Facebook friends selector is one of important thing when you develop a Facebook application. It will simplify the way your visitor select their Facebook friend&#8217;s instead of manually find friend&#8217;s user ID. Just type part of the friend&#8217;s name, the matches name will appears below the field and select one you want. This is not [...]]]></description> <content:encoded><![CDATA[<div
id="attachment_719" class="wp-caption alignleft" style="width: 160px"><a
href="http://takien.com/wp-content/uploads/2010/08/friend-selector.png"><img
class="size-medium wp-image-719 " title="friend-selector" src="http://takien.com/wp-content/uploads/2010/08/friend-selector-300x223.png" alt="Facebook Friend Selector, PHP + jQuery without FBML/iframe" width="150" /></a><p
class="wp-caption-text">Facebook Friend Selector</p></div><p>Facebook friends selector is one of important thing when you develop a Facebook application. It will simplify the way your visitor select their Facebook friend&#8217;s instead of manually find friend&#8217;s user ID.</p><p>Just type part of the friend&#8217;s name, the matches name will appears below the field and select one you want.</p><p>This is not just another Facebook friend selector you might found somewhere, because it&#8217;s not using FBML or iframe, there&#8217;s only JavaScript and PHP.<br
/><div
style="float:right;width:300px;height:250px;margin-left:20px"><script type="text/javascript"><!-- google_ad_client = "pub-3108107609212063"; /* takien-content-300x250, created 12/9/10 */ google_ad_slot = "4897738383"; google_ad_width = 300; google_ad_height = 250; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div><br
/> <strong>How it works?</strong></p><ol><li>Once you logged in, the script will ask your permission to access your account (friends list etc).</li><li>If you choose allow, then the script fetchs your friend data from https://graph.facebook.com/me/friends and get your friend lists in JSON format.</li><li>Some PHP function convert it into PHP array and simplify it, do some filtering based on user input, then encode back to JSON format so it will compatible with the jQuery autocomplete plugin.</li></ol><p><strong>Can&#8217;t wait to see it in action? </strong><br
/> Just follow the links below:</p><p><div
class="information"><div
class="box-title">Demo</div><div
class="box-content"><a
href="http://cektkp.com/test/friend/" target="_blank">Demo and Download</a><br
/></div></div><br
/> Credit: <a
target="_blank" href="http://www.codeassembly.com/Unobtrusive-jQuery-autocomplete-plugin-with-json-key-value-support/">jQuery Autocomplete Plugins</a></p> ]]></content:encoded> <wfw:commentRss>http://takien.com/718/jquery-php-facebook-friend-selector-without-fbml.php/feed</wfw:commentRss> <slash:comments>18</slash:comments> </item> <item><title>WordPress Plugin WP Sub Post</title><link>http://takien.com/550/wordpress-plugin-wp-sub-post.php</link> <comments>http://takien.com/550/wordpress-plugin-wp-sub-post.php#comments</comments> <pubDate>Thu, 28 Jan 2010 14:08:08 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Plugins]]></category> <category><![CDATA[child post]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[wordpress plugins]]></category> <category><![CDATA[wordpress sub post]]></category><guid
isPermaLink="false">http://takien.com/?p=550</guid> <description><![CDATA[WP Sub Post is a wordpress plugin that allow you to make your wordpress post has a parent or child post. Notes: Child post is a real post that has a parent. Child post only displayed on it&#8217;s parent post page or when parent page is displayed. Child post can not be viewed individually. Child [...]]]></description> <content:encoded><![CDATA[<p>WP Sub Post is a wordpress plugin that allow you to make your wordpress post has a parent or child post.</p><p><strong>Notes:</strong></p><ul><li>Child post is a real post that has a parent.</li><li>Child post only displayed on it&#8217;s parent post page or when parent page is displayed.</li><li>Child post can not be viewed individually.</li><li>Child post has all possibility <strong>like a normal post</strong>, such as attachment, custom fields etc.<strong><br
/> </strong></li></ul><p><strong>Features:</strong></p><ul><li>Add/edit parent post directly from your post area.</li><li>No need to edit theme file.</li></ul><p><strong>Limitations:</strong></p><ul><li>No setting page</li><li>I don&#8217;t know about it&#8217;s compatibility.</li></ul><p><strong>Bugs:</strong></p><ul><li>Not compatible with my syntax highlight plugin <img
src='http://takien.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></li></ul><div
class="refsect1"><h3 class="title">Screenshot</h3><p>Plugin page:</p><blockquote><p><img
src="http://i48.tinypic.com/66gtg4.png" alt="WP sub post" width="500" /></p></blockquote><p>New/Edit post page:</p><blockquote><p><img
src="http://i50.tinypic.com/2z7mxxv.png" alt="Wp sub post" width="500" /></p></blockquote><p>View Single Post:</p><blockquote><p><img
src="http://i50.tinypic.com/25urubq.png" alt="Wp sub post" width="500" /></p></blockquote><p>RSS:</p><blockquote><p><img
src="http://i46.tinypic.com/e9t9gl.png" alt="Wp sub post" width="500" /></p></blockquote><p></div><br
/> <strong>Code:</strong></p><p>Here is the code of this plugins&#8230;  Hahaha.. little bit messy<strong></strong></p><div
style="clear:both"></div><div
class="refsect1"><h3 class="title">WP Sub Post</h3><div
class="example" style="margin:10px 0"><p><strong>WP Sub Post</strong></p><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;pre&gt;<span
style="color: #0000BB">&lt;?php<br
/></span><span
style="color: #FF8000">/*<br
/>Plugin&nbsp;Name:&nbsp;WP&nbsp;Sub&nbsp;Post<br
/>Plugin&nbsp;URI:&nbsp;http://wordpress.org/#<br
/>Description:&nbsp;You&nbsp;can&nbsp;make&nbsp;a&nbsp;post&nbsp;is&nbsp;a&nbsp;child&nbsp;of&nbsp;another&nbsp;post.<br
/>Author:&nbsp;Takien<br
/>Version:&nbsp;0.1&nbsp;Alpha<br
/>Author&nbsp;URI:&nbsp;http://takien.com<br
/>*/<br
/><br
/>////////////////////////////<br
/><br
/></span><span
style="color: #007700">class&nbsp;</span><span
style="color: #0000BB">Walker_PostDropdown&nbsp;</span><span
style="color: #007700">extends&nbsp;</span><span
style="color: #0000BB">Walker&nbsp;</span><span
style="color: #007700">{<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span
style="color: #0000BB">$tree_type&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">'post'</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span
style="color: #0000BB">$db_fields&nbsp;</span><span
style="color: #007700">=&nbsp;array&nbsp;(</span><span
style="color: #DD0000">'parent'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">'post_parent'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'id'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">'ID'</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span
style="color: #0000BB">start_el</span><span
style="color: #007700">(&amp;</span><span
style="color: #0000BB">$output</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$page</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$depth</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$args</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pad&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">str_repeat</span><span
style="color: #007700">(</span><span
style="color: #DD0000">' '</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$depth&nbsp;</span><span
style="color: #007700">*&nbsp;</span><span
style="color: #0000BB">3</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">"\tID\""</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">$page</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">ID&nbsp;</span><span
style="color: #007700">==&nbsp;</span><span
style="color: #0000BB">$args</span><span
style="color: #007700">[</span><span
style="color: #DD0000">'selected'</span><span
style="color: #007700">]&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">'&nbsp;selected="selected"'</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">'&gt;'</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$title&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">esc_html</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$page</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">post_title</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">"$pad$title"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">"\n"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>}<br
/></span><span
style="color: #FF8000">/////////////<br
/></span><span
style="color: #007700">function&nbsp;&amp;</span><span
style="color: #0000BB">wp_get_posts</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$args&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$defaults&nbsp;</span><span
style="color: #007700">=&nbsp;array(<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'child_of'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">0</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'sort_order'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">'ASC'</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'sort_column'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">'post_title'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'hierarchical'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">1</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'exclude'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'include'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'meta_key'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'meta_value'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'authors'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'parent'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;-</span><span
style="color: #0000BB">1</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'exclude_tree'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'number'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'offset'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">0<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$r&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">wp_parse_args</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">$args</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$defaults&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">extract</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">$r</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">EXTR_SKIP&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$number&nbsp;</span><span
style="color: #007700">=&nbsp;(int)&nbsp;</span><span
style="color: #0000BB">$number</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$offset&nbsp;</span><span
style="color: #007700">=&nbsp;(int)&nbsp;</span><span
style="color: #0000BB">$offset</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$cache&nbsp;</span><span
style="color: #007700">=&nbsp;array();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$key&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">md5</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">serialize</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">compact</span><span
style="color: #007700">(</span><span
style="color: #0000BB">array_keys</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$defaults</span><span
style="color: #007700">))&nbsp;)&nbsp;);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">$cache&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">wp_cache_get</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'wp_get_posts'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'posts'&nbsp;</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">is_array</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$cache</span><span
style="color: #007700">)&nbsp;&amp;&amp;&nbsp;isset(&nbsp;</span><span
style="color: #0000BB">$cache</span><span
style="color: #007700">[&nbsp;</span><span
style="color: #0000BB">$key&nbsp;</span><span
style="color: #007700">]&nbsp;)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">apply_filters</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'wp_get_posts'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$cache</span><span
style="color: #007700">[&nbsp;</span><span
style="color: #0000BB">$key&nbsp;</span><span
style="color: #007700">],&nbsp;</span><span
style="color: #0000BB">$r&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!</span><span
style="color: #0000BB">is_array</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$cache</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$cache&nbsp;</span><span
style="color: #007700">=&nbsp;array();<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$inclusions&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!empty(</span><span
style="color: #0000BB">$include</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$child_of&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">0</span><span
style="color: #007700">;&nbsp;</span><span
style="color: #FF8000">//ignore&nbsp;child_of,&nbsp;parent,&nbsp;exclude,&nbsp;meta_key,&nbsp;and&nbsp;meta_value&nbsp;params&nbsp;if&nbsp;using&nbsp;include<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$parent&nbsp;</span><span
style="color: #007700">=&nbsp;-</span><span
style="color: #0000BB">1</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$exclude&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$meta_key&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$meta_value&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$hierarchical&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">false</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$incpages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">preg_split</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'/[\s,]+/'</span><span
style="color: #007700">,</span><span
style="color: #0000BB">$include</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">count</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$incpages</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(&nbsp;</span><span
style="color: #0000BB">$incpages&nbsp;</span><span
style="color: #007700">as&nbsp;</span><span
style="color: #0000BB">$incpage&nbsp;</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(empty(</span><span
style="color: #0000BB">$inclusions</span><span
style="color: #007700">))<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$inclusions&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'&nbsp;AND&nbsp;(&nbsp;ID&nbsp;=&nbsp;%d&nbsp;'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$incpage</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$inclusions&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'&nbsp;OR&nbsp;ID&nbsp;=&nbsp;%d&nbsp;'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$incpage</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!empty(</span><span
style="color: #0000BB">$inclusions</span><span
style="color: #007700">))<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$inclusions&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">')'</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$exclusions&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!empty(</span><span
style="color: #0000BB">$exclude</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$expages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">preg_split</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'/[\s,]+/'</span><span
style="color: #007700">,</span><span
style="color: #0000BB">$exclude</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">count</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$expages</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(&nbsp;</span><span
style="color: #0000BB">$expages&nbsp;</span><span
style="color: #007700">as&nbsp;</span><span
style="color: #0000BB">$expage&nbsp;</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(empty(</span><span
style="color: #0000BB">$exclusions</span><span
style="color: #007700">))<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$exclusions&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'&nbsp;AND&nbsp;(&nbsp;ID&nbsp;&lt;&gt;&nbsp;%d&nbsp;'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$expage</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$exclusions&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'&nbsp;AND&nbsp;ID&nbsp;&lt;&gt;&nbsp;%d&nbsp;'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$expage</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!empty(</span><span
style="color: #0000BB">$exclusions</span><span
style="color: #007700">))<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$exclusions&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">')'</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$author_query&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!empty(</span><span
style="color: #0000BB">$authors</span><span
style="color: #007700">))&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$post_authors&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">preg_split</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'/[\s,]+/'</span><span
style="color: #007700">,</span><span
style="color: #0000BB">$authors</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">count</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$post_authors</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(&nbsp;</span><span
style="color: #0000BB">$post_authors&nbsp;</span><span
style="color: #007700">as&nbsp;</span><span
style="color: #0000BB">$post_author&nbsp;</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #FF8000">//Do&nbsp;we&nbsp;have&nbsp;an&nbsp;author&nbsp;id&nbsp;or&nbsp;an&nbsp;author&nbsp;login?<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">if&nbsp;(&nbsp;</span><span
style="color: #0000BB">0&nbsp;</span><span
style="color: #007700">==&nbsp;</span><span
style="color: #0000BB">intval</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$post_author</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$post_author&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">get_userdatabylogin</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$post_author</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;empty(</span><span
style="color: #0000BB">$post_author</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;empty(</span><span
style="color: #0000BB">$post_author</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">ID</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$post_author&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$post_author</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">ID</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #DD0000">''&nbsp;</span><span
style="color: #007700">==&nbsp;</span><span
style="color: #0000BB">$author_query&nbsp;</span><span
style="color: #007700">)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$author_query&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'&nbsp;post_author&nbsp;=&nbsp;%d&nbsp;'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$post_author</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$author_query&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'&nbsp;OR&nbsp;post_author&nbsp;=&nbsp;%d&nbsp;'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$post_author</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #DD0000">''&nbsp;</span><span
style="color: #007700">!=&nbsp;</span><span
style="color: #0000BB">$author_query&nbsp;</span><span
style="color: #007700">)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$author_query&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">"&nbsp;AND&nbsp;($author_query)"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$join&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$where&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">"$exclusions&nbsp;$inclusions&nbsp;"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!&nbsp;empty(&nbsp;</span><span
style="color: #0000BB">$meta_key&nbsp;</span><span
style="color: #007700">)&nbsp;||&nbsp;!&nbsp;empty(&nbsp;</span><span
style="color: #0000BB">$meta_value&nbsp;</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$join&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">"&nbsp;LEFT&nbsp;JOIN&nbsp;$wpdb-&gt;postmeta&nbsp;ON&nbsp;(&nbsp;$wpdb-&gt;posts.ID&nbsp;=&nbsp;$wpdb-&gt;postmeta.post_id&nbsp;)"</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;meta_key&nbsp;and&nbsp;meta_value&nbsp;might&nbsp;be&nbsp;slashed<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$meta_key&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">stripslashes</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$meta_key</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$meta_value&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">stripslashes</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$meta_value</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!&nbsp;empty(&nbsp;</span><span
style="color: #0000BB">$meta_key&nbsp;</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$where&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">"&nbsp;AND&nbsp;$wpdb-&gt;postmeta.meta_key&nbsp;=&nbsp;%s"</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$meta_key</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!&nbsp;empty(&nbsp;</span><span
style="color: #0000BB">$meta_value&nbsp;</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$where&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">"&nbsp;AND&nbsp;$wpdb-&gt;postmeta.meta_value&nbsp;=&nbsp;%s"</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$meta_value</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">$parent&nbsp;</span><span
style="color: #007700">&gt;=&nbsp;</span><span
style="color: #0000BB">0&nbsp;</span><span
style="color: #007700">)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$where&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">prepare</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'&nbsp;AND&nbsp;post_parent&nbsp;=&nbsp;%d&nbsp;'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$parent</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$query&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;$wpdb-&gt;posts&nbsp;$join&nbsp;WHERE&nbsp;(post_type&nbsp;=&nbsp;'post'&nbsp;AND&nbsp;post_status&nbsp;=&nbsp;'publish')&nbsp;$where&nbsp;"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$query&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #0000BB">$author_query</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$query&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">"&nbsp;ORDER&nbsp;BY&nbsp;"&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #0000BB">$sort_column&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #DD0000">"&nbsp;"&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #0000BB">$sort_order&nbsp;</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!empty(</span><span
style="color: #0000BB">$number</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$query&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">'&nbsp;LIMIT&nbsp;'&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #0000BB">$offset&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #DD0000">','&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #0000BB">$number</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">get_results</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$query</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;empty(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">apply_filters</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'wp_get_posts'</span><span
style="color: #007700">,&nbsp;array(),&nbsp;</span><span
style="color: #0000BB">$r</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;Sanitize&nbsp;before&nbsp;caching&nbsp;so&nbsp;it'll&nbsp;only&nbsp;get&nbsp;done&nbsp;once<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$num_pages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">count</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(</span><span
style="color: #0000BB">$i&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">0</span><span
style="color: #007700">;&nbsp;</span><span
style="color: #0000BB">$i&nbsp;</span><span
style="color: #007700">&lt;&nbsp;</span><span
style="color: #0000BB">$num_pages</span><span
style="color: #007700">;&nbsp;</span><span
style="color: #0000BB">$i</span><span
style="color: #007700">++)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">[</span><span
style="color: #0000BB">$i</span><span
style="color: #007700">]&nbsp;=&nbsp;</span><span
style="color: #0000BB">sanitize_post</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">[</span><span
style="color: #0000BB">$i</span><span
style="color: #007700">],&nbsp;</span><span
style="color: #DD0000">'raw'</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;Update&nbsp;cache.<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">update_page_cache</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">$child_of&nbsp;</span><span
style="color: #007700">||&nbsp;</span><span
style="color: #0000BB">$hierarchical&nbsp;</span><span
style="color: #007700">)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pages&nbsp;</span><span
style="color: #007700">=&nbsp;&amp;&nbsp;</span><span
style="color: #0000BB">get_page_children</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$child_of</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!empty(</span><span
style="color: #0000BB">$exclude_tree</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$exclude&nbsp;</span><span
style="color: #007700">=&nbsp;(int)&nbsp;</span><span
style="color: #0000BB">$exclude_tree</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$children&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">get_page_children</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$exclude</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$excludes&nbsp;</span><span
style="color: #007700">=&nbsp;array();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(&nbsp;</span><span
style="color: #0000BB">$children&nbsp;</span><span
style="color: #007700">as&nbsp;</span><span
style="color: #0000BB">$child&nbsp;</span><span
style="color: #007700">)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$excludes</span><span
style="color: #007700">[]&nbsp;=&nbsp;</span><span
style="color: #0000BB">$child</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">ID</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$excludes</span><span
style="color: #007700">[]&nbsp;=&nbsp;</span><span
style="color: #0000BB">$exclude</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$num_pages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">count</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(&nbsp;</span><span
style="color: #0000BB">$i&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">0</span><span
style="color: #007700">;&nbsp;</span><span
style="color: #0000BB">$i&nbsp;</span><span
style="color: #007700">&lt;&nbsp;</span><span
style="color: #0000BB">$num_pages</span><span
style="color: #007700">;&nbsp;</span><span
style="color: #0000BB">$i</span><span
style="color: #007700">++&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">in_array</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">[</span><span
style="color: #0000BB">$i</span><span
style="color: #007700">]-&gt;</span><span
style="color: #0000BB">ID</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$excludes</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">[</span><span
style="color: #0000BB">$i</span><span
style="color: #007700">]);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$cache</span><span
style="color: #007700">[&nbsp;</span><span
style="color: #0000BB">$key&nbsp;</span><span
style="color: #007700">]&nbsp;=&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">wp_cache_set</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'wp_get_posts'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$cache</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'posts'&nbsp;</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">apply_filters</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'wp_get_posts'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$r</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">;<br
/>}<br
/></span><span
style="color: #FF8000">//////////////<br
/><br
/></span><span
style="color: #007700">function&nbsp;</span><span
style="color: #0000BB">walk_post_dropdown_tree</span><span
style="color: #007700">()&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$args&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">func_get_args</span><span
style="color: #007700">();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;empty(</span><span
style="color: #0000BB">$args</span><span
style="color: #007700">[</span><span
style="color: #0000BB">2</span><span
style="color: #007700">][</span><span
style="color: #DD0000">'walker'</span><span
style="color: #007700">])&nbsp;)&nbsp;</span><span
style="color: #FF8000">//&nbsp;the&nbsp;user's&nbsp;options&nbsp;are&nbsp;the&nbsp;third&nbsp;parameter<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$walker&nbsp;</span><span
style="color: #007700">=&nbsp;new&nbsp;</span><span
style="color: #0000BB">Walker_PostDropdown</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;else<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$walker&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$args</span><span
style="color: #007700">[</span><span
style="color: #0000BB">2</span><span
style="color: #007700">][</span><span
style="color: #DD0000">'walker'</span><span
style="color: #007700">];<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">call_user_func_array</span><span
style="color: #007700">(array(&amp;</span><span
style="color: #0000BB">$walker</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'walk'</span><span
style="color: #007700">),&nbsp;</span><span
style="color: #0000BB">$args</span><span
style="color: #007700">);<br
/>}<br
/><br
/>function&nbsp;</span><span
style="color: #0000BB">wp_dropdown_posts</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$args&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$defaults&nbsp;</span><span
style="color: #007700">=&nbsp;array(<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'depth'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">0</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'child_of'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">0</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'selected'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">0</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'echo'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">1</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'name'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">'page_id'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'show_option_none'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'show_option_no_change'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'option_none_value'&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">''<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$r&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">wp_parse_args</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">$args</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$defaults&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">extract</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">$r</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">EXTR_SKIP&nbsp;</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$pages&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">wp_get_posts</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$r</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">''</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$name&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">esc_attr</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$name</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!&nbsp;empty(</span><span
style="color: #0000BB">$pages</span><span
style="color: #007700">)&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #DD0000">"<br
/>&lt;select&nbsp;id=""$name\""&nbsp;</span><span
style="color: #0000BB">name</span><span
style="color: #007700">=</span><span
style="color: #DD0000">"\"$name\""</span><span
style="color: #007700">&gt;<br
/>&lt;</span><span
style="color: #0000BB">option&nbsp;value</span><span
style="color: #007700">=</span><span
style="color: #DD0000">"\"-1\""</span><span
style="color: #007700">&gt;</span><span
style="color: #0000BB">$show_option_no_change</span><span
style="color: #007700">&lt;/</span><span
style="color: #0000BB">option</span><span
style="color: #007700">&gt;<br
/>&lt;</span><span
style="color: #0000BB">option&nbsp;value</span><span
style="color: #007700">=</span><span
style="color: #DD0000">"\"""&gt;$show_option_none&lt;/option&gt;<br
/><br
/>\n"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$output&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">apply_filters</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'wp_dropdown_pages'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$output</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span
style="color: #0000BB">$echo&nbsp;</span><span
style="color: #007700">)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #0000BB">$output</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$output</span><span
style="color: #007700">;<br
/>}<br
/></span><span
style="color: #FF8000">/////////////////////////////<br
/><br
/>/*&nbsp;Use&nbsp;the&nbsp;admin_menu&nbsp;action&nbsp;to&nbsp;define&nbsp;the&nbsp;custom&nbsp;boxes&nbsp;*/<br
/></span><span
style="color: #0000BB">add_action</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'admin_menu'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'myplugin_add_custom_box'</span><span
style="color: #007700">);<br
/><br
/></span><span
style="color: #FF8000">/*&nbsp;Use&nbsp;the&nbsp;save_post&nbsp;action&nbsp;to&nbsp;do&nbsp;something&nbsp;with&nbsp;the&nbsp;data&nbsp;entered&nbsp;*/<br
/></span><span
style="color: #0000BB">add_action</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'save_post'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'myplugin_save_postdata'</span><span
style="color: #007700">);<br
/><br
/></span><span
style="color: #FF8000">/*&nbsp;Adds&nbsp;a&nbsp;custom&nbsp;section&nbsp;to&nbsp;the&nbsp;"advanced"&nbsp;Post&nbsp;and&nbsp;Page&nbsp;edit&nbsp;screens&nbsp;*/<br
/></span><span
style="color: #007700">function&nbsp;</span><span
style="color: #0000BB">myplugin_add_custom_box</span><span
style="color: #007700">()&nbsp;{<br
/><br
/>&nbsp;&nbsp;if(&nbsp;</span><span
style="color: #0000BB">function_exists</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'add_meta_box'&nbsp;</span><span
style="color: #007700">))&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">add_meta_box</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'myplugin_sectionid'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">__</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'WP&nbsp;Sub&nbsp;Posts'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'myplugin_textdomain'&nbsp;</span><span
style="color: #007700">),&nbsp;</span><span
style="color: #DD0000">'myplugin_inner_custom_box'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'post'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'side'</span><span
style="color: #007700">,</span><span
style="color: #DD0000">'high'&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #FF8000">//add_meta_box(&nbsp;$id,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$title,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$callback,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$page,&nbsp;$context,&nbsp;$priority&nbsp;);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">add_meta_box</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'myplugin_sectionid'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">__</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'WP&nbsp;Sub&nbsp;Posts'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'myplugin_textdomain'&nbsp;</span><span
style="color: #007700">),&nbsp;</span><span
style="color: #DD0000">'myplugin_inner_custom_box'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'page'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'advanced'&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">add_action</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'dbx_post_advanced'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'myplugin_old_custom_box'&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">add_action</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'dbx_page_advanced'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'myplugin_old_custom_box'&nbsp;</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;}<br
/>}<br
/><br
/>function&nbsp;</span><span
style="color: #0000BB">myplugin_inner_custom_box</span><span
style="color: #007700">()&nbsp;{<br
/>echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;style&nbsp;type="text/css"&gt;<br
/>select#parent_id,&nbsp;select#parent_id&nbsp;option&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;width:250px;<br
/>}<br
/>&lt;/style&gt;<br
/><br
/>'</span><span
style="color: #007700">;<br
/><br
/>echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;input&nbsp;id="myplugin_noncename"&nbsp;name="myplugin_noncename"&nbsp;type="hidden"&nbsp;value="'&nbsp;</span><span
style="color: #007700">.<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">wp_create_nonce</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">plugin_basename</span><span
style="color: #007700">(</span><span
style="color: #0000BB">__FILE__</span><span
style="color: #007700">)&nbsp;)&nbsp;.&nbsp;</span><span
style="color: #DD0000">'"&nbsp;/&gt;'</span><span
style="color: #007700">;&nbsp;&nbsp;</span><span
style="color: #0000BB">?&gt;<br
/></span>&lt;h5&gt;<span
style="color: #0000BB">&lt;?php&nbsp;_e</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'Parent'</span><span
style="color: #007700">)&nbsp;</span><span
style="color: #0000BB">?&gt;</span>&lt;/h5&gt;<br
/><br
/>&lt;label&nbsp;for="post_parent"&gt;Please&nbsp;select&nbsp;the&nbsp;parent&nbsp;of&nbsp;this&nbsp;post&lt;/label&gt;<br
/><br
/><span
style="color: #0000BB">&lt;?php&nbsp;<br
/><br
/>$currentid&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$_GET</span><span
style="color: #007700">[</span><span
style="color: #DD0000">'post'</span><span
style="color: #007700">];<br
/></span><span
style="color: #0000BB">wp_dropdown_posts</span><span
style="color: #007700">(array(</span><span
style="color: #DD0000">'exclude_tree'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">$currentid</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'selected'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">$post</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">post_parent</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'name'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">'parent_id'</span><span
style="color: #007700">,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'show_option_none'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #0000BB">__</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'Main&nbsp;Post&nbsp;(no&nbsp;parent)'</span><span
style="color: #007700">),<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #DD0000">'sort_column'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #007700">=&gt;&nbsp;</span><span
style="color: #DD0000">'menu_order,&nbsp;post_title'</span><span
style="color: #007700">));<br
/>&nbsp;}<br
/><br
/></span><span
style="color: #FF8000">/*&nbsp;Prints&nbsp;the&nbsp;edit&nbsp;form&nbsp;for&nbsp;pre-WordPress&nbsp;2.5&nbsp;post/page&nbsp;*/<br
/></span><span
style="color: #007700">function&nbsp;</span><span
style="color: #0000BB">myplugin_old_custom_box</span><span
style="color: #007700">()&nbsp;{<br
/><br
/>&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;div&nbsp;class="dbx-b-ox-wrapper"&gt;'&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #DD0000">"\n"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;fieldset&nbsp;id="myplugin_fieldsetid"&nbsp;class="dbx-box"&gt;'&nbsp;</span><span
style="color: #007700">.&nbsp;</span><span
style="color: #DD0000">"\n"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;div&nbsp;class="dbx-h-andle-wrapper"&gt;<br
/>&lt;h3&nbsp;class="dbx-handle"&gt;'&nbsp;</span><span
style="color: #007700">.<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">__</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'WP&nbsp;Sub&nbsp;Posts'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #DD0000">'myplugin_textdomain'&nbsp;</span><span
style="color: #007700">)&nbsp;.&nbsp;</span><span
style="color: #DD0000">"&lt;/h3&gt;<br
/>&lt;/div&gt;<br
/><br
/>"</span><span
style="color: #007700">;&nbsp;&nbsp;&nbsp;<br
/><br
/>&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;div&nbsp;class="dbx-c-ontent-wrapper"&gt;<br
/>&lt;div&nbsp;class="dbx-content"&gt;'</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;output&nbsp;editing&nbsp;form<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #0000BB">myplugin_inner_custom_box</span><span
style="color: #007700">();<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;end&nbsp;wrapper<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #007700">echo&nbsp;</span><span
style="color: #DD0000">"&lt;/div&gt;<br
/>&lt;/div&gt;<br
/>&lt;/fieldset&gt;<br
/>&lt;/div&gt;<br
/><br
/>\n"</span><span
style="color: #007700">;<br
/>}<br
/><br
/></span><span
style="color: #FF8000">/*&nbsp;When&nbsp;the&nbsp;post&nbsp;is&nbsp;saved,&nbsp;saves&nbsp;our&nbsp;custom&nbsp;data&nbsp;*/<br
/></span><span
style="color: #007700">function&nbsp;</span><span
style="color: #0000BB">myplugin_save_postdata</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">$post_id&nbsp;</span><span
style="color: #007700">)&nbsp;{<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;verify&nbsp;this&nbsp;came&nbsp;from&nbsp;the&nbsp;our&nbsp;screen&nbsp;and&nbsp;with&nbsp;proper&nbsp;authorization,<br
/>&nbsp;&nbsp;//&nbsp;because&nbsp;save_post&nbsp;can&nbsp;be&nbsp;triggered&nbsp;at&nbsp;other&nbsp;times<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #007700">if&nbsp;(&nbsp;!</span><span
style="color: #0000BB">wp_verify_nonce</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #0000BB">$_POST</span><span
style="color: #007700">[</span><span
style="color: #DD0000">'myplugin_noncename'</span><span
style="color: #007700">],&nbsp;</span><span
style="color: #0000BB">plugin_basename</span><span
style="color: #007700">(</span><span
style="color: #0000BB">__FILE__</span><span
style="color: #007700">)&nbsp;))&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$post_id</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;verify&nbsp;if&nbsp;this&nbsp;is&nbsp;an&nbsp;auto&nbsp;save&nbsp;routine.&nbsp;If&nbsp;it&nbsp;is&nbsp;our&nbsp;form&nbsp;has&nbsp;not&nbsp;been&nbsp;submitted,&nbsp;so&nbsp;we&nbsp;dont&nbsp;want<br
/>&nbsp;&nbsp;//&nbsp;to&nbsp;do&nbsp;anything<br
/>&nbsp;&nbsp;</span><span
style="color: #007700">if&nbsp;(&nbsp;</span><span
style="color: #0000BB">defined</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'DOING_AUTOSAVE'</span><span
style="color: #007700">)&nbsp;&amp;&amp;&nbsp;</span><span
style="color: #0000BB">DOING_AUTOSAVE&nbsp;</span><span
style="color: #007700">)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$post_id</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;Check&nbsp;permissions<br
/>&nbsp;&nbsp;</span><span
style="color: #007700">if&nbsp;(&nbsp;</span><span
style="color: #DD0000">'page'&nbsp;</span><span
style="color: #007700">==&nbsp;</span><span
style="color: #0000BB">$_POST</span><span
style="color: #007700">[</span><span
style="color: #DD0000">'post_type'</span><span
style="color: #007700">]&nbsp;)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!</span><span
style="color: #0000BB">current_user_can</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'edit_page'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$post_id&nbsp;</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$post_id</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;}&nbsp;else&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;!</span><span
style="color: #0000BB">current_user_can</span><span
style="color: #007700">(&nbsp;</span><span
style="color: #DD0000">'edit_post'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">$post_id&nbsp;</span><span
style="color: #007700">)&nbsp;)<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$post_id</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #FF8000">//&nbsp;OK,&nbsp;we're&nbsp;authenticated:&nbsp;we&nbsp;need&nbsp;to&nbsp;find&nbsp;and&nbsp;save&nbsp;the&nbsp;data<br
/><br
/>&nbsp;&nbsp;</span><span
style="color: #0000BB">$mydata&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">$_POST</span><span
style="color: #007700">[</span><span
style="color: #DD0000">'parent_id'</span><span
style="color: #007700">];<br
/><br
/>&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$mydata</span><span
style="color: #007700">;<br
/>}<br
/><br
/></span><span
style="color: #0000BB">add_filter</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'posts_where'</span><span
style="color: #007700">,</span><span
style="color: #DD0000">'where_no_parent'</span><span
style="color: #007700">);<br
/></span><span
style="color: #0000BB">add_filter&nbsp;</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'the_content'</span><span
style="color: #007700">,</span><span
style="color: #DD0000">'subpost_template'</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">1</span><span
style="color: #007700">,&nbsp;</span><span
style="color: #0000BB">2&nbsp;</span><span
style="color: #007700">);<br
/><br
/>function&nbsp;</span><span
style="color: #0000BB">subpost_template</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$content</span><span
style="color: #007700">)&nbsp;{<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span
style="color: #0000BB">is_singular</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">remove_filter</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'posts_where'</span><span
style="color: #007700">,</span><span
style="color: #DD0000">'where_no_parent'</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #0000BB">$content</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$idnya&nbsp;</span><span
style="color: #007700">=&nbsp;</span><span
style="color: #0000BB">get_the_ID</span><span
style="color: #007700">();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$child&nbsp;</span><span
style="color: #007700">=&nbsp;new&nbsp;</span><span
style="color: #0000BB">WP_Query</span><span
style="color: #007700">(</span><span
style="color: #DD0000">"post_type=post&amp;post_parent="</span><span
style="color: #007700">.</span><span
style="color: #0000BB">$idnya</span><span
style="color: #007700">.</span><span
style="color: #DD0000">""</span><span
style="color: #007700">);<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;while(</span><span
style="color: #0000BB">$child</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">have_posts</span><span
style="color: #007700">())&nbsp;:&nbsp;</span><span
style="color: #0000BB">$child</span><span
style="color: #007700">-&gt;</span><span
style="color: #0000BB">the_post</span><span
style="color: #007700">();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;blockquote&gt;<br
/><br
/>'</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'<br
/>&lt;h3&gt;'</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">the_title</span><span
style="color: #007700">();<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'&lt;/h3&gt;<br
/><br
/>'</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$childid&nbsp;</span><span
style="color: #007700">=&nbsp;&nbsp;</span><span
style="color: #0000BB">get_the_ID</span><span
style="color: #007700">();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">the_content</span><span
style="color: #007700">();<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">edit_post_link</span><span
style="color: #007700">(</span><span
style="color: #DD0000">'Edit'</span><span
style="color: #007700">,</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,</span><span
style="color: #DD0000">''</span><span
style="color: #007700">,</span><span
style="color: #0000BB">$childid</span><span
style="color: #007700">);<br
/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span
style="color: #DD0000">'&lt;/blockquote&gt;<br
/><br
/>'</span><span
style="color: #007700">;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;endwhile;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">wp_reset_query</span><span
style="color: #007700">();<br
/>}<br
/><br
/>function&nbsp;</span><span
style="color: #0000BB">where_no_parent</span><span
style="color: #007700">(</span><span
style="color: #0000BB">$where</span><span
style="color: #007700">)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;</span><span
style="color: #0000BB">$wpdb</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="color: #0000BB">$where&nbsp;</span><span
style="color: #007700">.=&nbsp;</span><span
style="color: #DD0000">"&nbsp;AND&nbsp;post_parent&nbsp;&nbsp;=&nbsp;0"</span><span
style="color: #007700">;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span
style="color: #0000BB">$where</span><span
style="color: #007700">;<br
/>}<br
/></span><span
style="color: #0000BB">?&gt;</span>[/raw]</span> </code></div></div></div></div> <strong> Revision by <a
href="http://www.kaskus.us/member.php?u=1202930">polvocdo</a></strong><div
style="clear:both"></div><div
class="refsect1"><h3 class="title">subpost_template()</h3><div
class="example" style="margin:10px 0"><p><strong>subpost_template()</strong></p><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;/pre&gt;<br
/>&lt;pre&gt;function&nbsp;subpost_template($content)&nbsp;{<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;if(is_singular())&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remove_filter('posts_where','where_no_parent');<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;$parentID&nbsp;=&nbsp;get_the_ID();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$childposts&nbsp;=&nbsp;get_posts(array(<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'post_type'&nbsp;=&gt;&nbsp;'post',<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'numberposts'&nbsp;=&gt;&nbsp;-1,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'post_status'&nbsp;=&gt;&nbsp;'publish',<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'post_parent'&nbsp;=&gt;&nbsp;$parentID<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;));<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;=&nbsp;"";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;foreach($childposts&nbsp;as&nbsp;$childpost){<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;"<br
/>&lt;blockquote&gt;<br
/><br
/>";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;"<br
/>&lt;h3&gt;".$childpost-&gt;post_title."&lt;/h3&gt;<br
/><br
/>";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;$childpost-&gt;post_content;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;'<br
/><br
/>&lt;a&nbsp;rel="nofollow"&nbsp;href="'.get_edit_post_link($childpost-&gt;ID).'"&gt;Edit&lt;/a&gt;<br
/><br
/>';<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;"&lt;/blockquote&gt;<br
/><br
/>";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;$subcontent;<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$content;<br
/>}<br
/>&lt;/pre&gt;<br
/>&lt;p&gt;[/raw]</span> </code></div></div></div></div></p><div
style="clear:both"></div><div
class="refsect1"><h3 class="title">WP Dropdown Post</h3><div
class="example" style="margin:10px 0"><p><strong>wp_dropdown_posts()</strong></p><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;/p&gt;<br
/>&lt;pre&gt;global&nbsp;$post;<br
/>$currentid&nbsp;=&nbsp;$_GET['post'];<br
/>wp_dropdown_posts(array('exclude_tree'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;$currentid,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'selected'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;$post-&gt;post_parent,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;'parent_id',<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'show_option_none'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;__('Main&nbsp;Post&nbsp;(no&nbsp;parent)'),<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'sort_column'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt;&nbsp;'menu_order,&nbsp;post_title'));<br
/>&lt;/pre&gt;<br
/>&lt;p&gt;[/raw]</span> </code></div></div></div></div><div
class="information"><div
class="box-title">Download</div><div
class="box-content">You can download alpha version of this plugin here <a
href="http://cektkp.com/wpsubpost">http://cektkp.com/wpsubpost</a><br
/> If it not working please <a
href="http://takien.com/wp-content/plugins/wp-sub-post.zip">Click here </a></div></div><div
class="warning"><strong>Warning</strong><p>This plugin is Alpha version, use it for testing purpose only. Any problem caused by this plugin is not my responsibility.<br
/></p></div><p><strong>Demo: </strong></p><p>See below:<br
/><blockquote
class="sub_post" id="subpost_602"><h3>Code Update WP Sub Post</h3><p>There are some changes to the WP Sub Post:</p><ul><li>Fixed/Added, now child post can be viewed as a single post, with link to the Parent Post instead of displaying blank post with &#8216;Post not found&#8217; title.</li><li>Added, CSS class and id to the blockquote of the child post. It would be useful to make a link like http://example.com/parentpost.html#childpostXXX. while XXX is your child post ID.</li></ul><p>Two functions that are changed <strong>subpost_template()</strong> and <strong>where_no_parent()</strong></p><p><div
style="clear:both"></div><div
class="example" style="margin:10px 0"><p><strong>WP Sub Post</strong></p><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;pre&gt;<br
/>function&nbsp;subpost_template($content)&nbsp;{<br
/>global&nbsp;$post;<br
/><br
/>$parentID&nbsp;=&nbsp;get_the_ID();<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$childposts&nbsp;=&nbsp;get_posts(array(<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'post_type'&nbsp;=&gt;&nbsp;'post',<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'numberposts'&nbsp;=&gt;&nbsp;-1,<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'post_status'&nbsp;=&gt;&nbsp;'publish',<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'post_parent'&nbsp;=&gt;&nbsp;$parentID<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;));<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;=&nbsp;"";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;foreach($childposts&nbsp;as&nbsp;$childpost){<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;"<br
/>&lt;blockquote&nbsp;class=\"sub_post\"&nbsp;id=\"subpost_".$childpost-&gt;ID."\"&gt;";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;"<br
/>&lt;h3&gt;".$childpost-&gt;post_title."&lt;/h3&gt;<br
/><br
/>";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;$childpost-&gt;post_content;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;'<br
/>&lt;p&nbsp;class="postmetadata"&gt;&lt;small&gt;This&nbsp;sub&nbsp;post&nbsp;was&nbsp;added&nbsp;on:&nbsp;'.date('l,&nbsp;dS&nbsp;F,&nbsp;Y',strtotime($childpost-&gt;post_date)).'&nbsp;&lt;a&nbsp;href="'.get_edit_post_link($childpost-&gt;ID).'"&nbsp;rel="nofollow"&gt;Edit&lt;/a&gt;&lt;/small&gt;<br
/><br
/>';<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcontent&nbsp;.=&nbsp;"&lt;/blockquote&gt;<br
/><br
/>";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($post-&gt;post_parent&nbsp;!==&nbsp;0)&nbsp;{<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$parent_info&nbsp;=&nbsp;'<br
/>&lt;blockquote&gt;This&nbsp;post&nbsp;is&nbsp;a&nbsp;child&nbsp;post&nbsp;of&nbsp;&lt;strong&gt;'.get_the_title($post-&gt;post_parent).'&lt;/strong&gt;.&nbsp;To&nbsp;view&nbsp;the&nbsp;parent&nbsp;post,&nbsp;please&nbsp;&lt;a&nbsp;href="'.get_permalink($post-&gt;post_parent).'"&gt;click&nbsp;here.&lt;/a&gt;&lt;/blockquote&gt;<br
/><br
/>';<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;=&nbsp;$parent_info.$content;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br
/><br
/>&nbsp;&nbsp;&nbsp;&nbsp;$content&nbsp;.=&nbsp;$subcontent;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$content;<br
/>}<br
/><br
/>function&nbsp;where_no_parent($where)&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;$wpdb;<br
/>&nbsp;&nbsp;&nbsp;&nbsp;if(!is_single())&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$where&nbsp;.=&nbsp;"&nbsp;AND&nbsp;post_parent&nbsp;&nbsp;=&nbsp;0";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;$where&nbsp;.=&nbsp;"&nbsp;AND&nbsp;post_type&nbsp;=&nbsp;'post'";<br
/>&nbsp;&nbsp;&nbsp;&nbsp;}<br
/>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$where;<br
/>}<br
/>&lt;/pre&gt;<br
/>&lt;p&gt;[/raw]</span> </code></div></div></div><p
class="postmetadata"><small>This sub post was added on: Tuesday, 09th February, 2010 <a
href="" rel="nofollow">Edit</a></small></p></blockquote><blockquote
class="sub_post" id="subpost_575"><h3>Finally you can see the demo here</h3><p>Yesterday, I was failed to add a demo directly in this site because of incompatibility with smart tags (all smart tags are not working when WP Sub Post is activated).</p><p>The problem comes from my old stupid function <code>subpost_template():D </code></p><p>Thanks and sorry to <strong><a
href="http://www.kaskus.us/member.php?u=1202930">polvocdo</a></strong><strong></strong> <img
src='http://takien.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , actually your revision is the answer.<br
/> Ha ha I&#8217;m forget to replace mine with your revision  :hammer: &#8230;.</p><p><strong><br
/> </strong><p
class="postmetadata"><small>This sub post was added on: Friday, 29th January, 2010 <a
href="" rel="nofollow">Edit</a></small></p></blockquote><blockquote
class="sub_post" id="subpost_536"><h3>This is a child post</h3><p>This is an individual post (http://takien.com/536/this-is-a-child-post.php) that attached to the another post ( http://takien.com/550/wordpress-plugin-wp-sub-post.php)</p><div
id="attachment_573" class="wp-caption alignleft" style="width: 160px"><a
href="http://takien.com/wp-content/uploads/2010/01/chimpanzee.jpg"><img
class="size-thumbnail wp-image-573 " title="chimpanzee" src="http://takien.com/wp-content/uploads/2010/01/chimpanzee-150x150.jpg" alt="" width="150" height="150" /></a><p
class="wp-caption-text">image on the child post</p></div><p>Child post could be useful when you want to add an additional information to the main post,  news analysis, or update. Instead of editing the main post, you can now simply Add New post and mark it as child post.</p><p>Child post also has it&#8217;s own functionality, can handle attachment, displaying image. etc.</p><p>But you can&#8217;t see this post in the post editing page (wp-admin/edit.php) because of filter  in the plugin to prevent child post to be displayed individually in the main page, post listing, feed, etc.  Hahaha.. don&#8217;t worry, I will fix it soon.<p
class="postmetadata"><small>This sub post was added on: Wednesday, 27th January, 2010 <a
href="" rel="nofollow">Edit</a></small></p></blockquote> ]]></content:encoded> <wfw:commentRss>http://takien.com/550/wordpress-plugin-wp-sub-post.php/feed</wfw:commentRss> <slash:comments>54</slash:comments> </item> <item><title>PHP: Keep HTML Tags Paired</title><link>http://takien.com/516/php-keep-html-tags-paired.php</link> <comments>http://takien.com/516/php-keep-html-tags-paired.php#comments</comments> <pubDate>Fri, 13 Nov 2009 18:50:40 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[html]]></category><guid
isPermaLink="false">http://takien.com/?p=516</guid> <description><![CDATA[After applying substr to a string that contains HTML tags, usually I found that the result is broken because the closing tags are truncated. To prevent this, I have made a function that keep the closing tags remains and will not break the appearance of my website. Here is the function: Usage/Example: Feedback and comment [...]]]></description> <content:encoded><![CDATA[<p>After applying <a
href="http://id2.php.net/manual/en/function.substr.php">substr </a>to a string that contains HTML tags, usually I found that the result is broken because the closing tags are truncated.</p><p>To prevent this, I have made a function that keep the closing tags remains and will not break the appearance of my website.</p><p><strong>Here is the function:</strong></p><div
style="clear:both"></div><div
class="example" style="margin:10px 0"><p><strong>HTML Pair Tags</strong></p><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;/p&gt;<br
/>&lt;pre&gt;<br
/>function&nbsp;pair_tag($string)&nbsp;{<br
/>$tags&nbsp;=&nbsp;Array('em','i','b','strong','div','span','p');<br
/>//array&nbsp;of&nbsp;tags&nbsp;we&nbsp;will&nbsp;keep&nbsp;paired,&nbsp;you&nbsp;may&nbsp;add&nbsp;another<br
/>foreach($tags&nbsp;as&nbsp;$tag)&nbsp;{<br
/><br
/>$opentag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;substr_count($string,&nbsp;'&lt;'.$tag);<br
/>//&nbsp;I&nbsp;don't&nbsp;put&nbsp;&gt;&nbsp;in&nbsp;the&nbsp;opentag&nbsp;in&nbsp;case&nbsp;they&nbsp;may&nbsp;have&nbsp;an&nbsp;attribute<br
/>$closetag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;substr_count($string,&nbsp;'&lt;/'.$tag.'&gt;');<br
/><br
/>if($opentag&nbsp;!==&nbsp;$closetag)&nbsp;{<br
/>$return&nbsp;.=&nbsp;str_repeat('&lt;/'.$tag.'&gt;',&nbsp;($opentag-$closetag));<br
/>}<br
/>}<br
/>return&nbsp;$return;<br
/>}&lt;/pre&gt;<br
/>&lt;p&gt;[/raw]</span> </code></div></div></div><p><strong>Usage/Example:</strong></p><div
style="clear:both"></div><div
class="example" style="margin:10px 0"><p><strong>Example</strong></p><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;/p&gt;<br
/>&lt;pre&gt;$fullcontent&nbsp;=&nbsp;'&lt;p&gt;This&nbsp;is&nbsp;my&nbsp;first&nbsp;post&nbsp;blah&nbsp;blah&nbsp;blah...&lt;/p&gt;';<br
/>$excerpt&nbsp;=&nbsp;substr($string,&nbsp;0,&nbsp;20);&nbsp;&nbsp;//only&nbsp;display&nbsp;first&nbsp;20&nbsp;character<br
/>$excerpt&nbsp;.=&nbsp;pair_tag($excerpt);&nbsp;//&nbsp;this&nbsp;will&nbsp;count&nbsp;any&nbsp;unclosed&nbsp;tags&nbsp;then&nbsp;close&nbsp;it.<br
/>echo&nbsp;$excerpt;&nbsp;//&nbsp;returns&nbsp;&lt;p&gt;This&nbsp;is&nbsp;my&nbsp;first&nbsp;pos&lt;/p&gt;&lt;/pre&gt;<br
/>&lt;p&gt;[/raw]</span> </code></div></div></div><p>Feedback and comment are welcome. Thanks</p> ]]></content:encoded> <wfw:commentRss>http://takien.com/516/php-keep-html-tags-paired.php/feed</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>How to fix &#8216;Function eregi() is deprecated&#8217; in PHP 5.3.0?</title><link>http://takien.com/513/how-to-fix-function-eregi-is-deprecated-in-php-5-3-0.php</link> <comments>http://takien.com/513/how-to-fix-function-eregi-is-deprecated-in-php-5-3-0.php#comments</comments> <pubDate>Wed, 21 Oct 2009 10:41:18 +0000</pubDate> <dc:creator>takien</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[deprecated functions]]></category> <category><![CDATA[email validation]]></category><guid
isPermaLink="false">http://takien.com/?p=513</guid> <description><![CDATA[I used to use eregi for validating email address input that matches to the regular expression. That would return true if given email address is matches to username@domain.ext pattern. Unfortunately, after upgrading PHP to the earlier version (5.3.0), it wont work properly. This is because eregi is one of several functions that are deprecated in [...]]]></description> <content:encoded><![CDATA[<p>I used to use eregi for validating email address input that matches to the regular expression.</p><div
style="clear:both"></div><div
class="example" style="margin:10px 0"><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;pre&gt;<br
/>if(!eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$",&nbsp;$str))&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;$msg&nbsp;=&nbsp;'email&nbsp;is&nbsp;not&nbsp;valid';<br
/>}<br
/>else&nbsp;{<br
/>$valid&nbsp;=&nbsp;true;<br
/>}&lt;/pre&gt;<br
/>&lt;p&gt;[/raw]</span> </code></div></div></div><p>That would return true if given email address is matches to <em>username@domain.ext</em> pattern. Unfortunately, after upgrading PHP to the earlier version (5.3.0), it wont work properly. This is because <em>eregi </em>is one of several functions that are deprecated in the new version of PHP.</p><h2>Solution how to fix Function Deprecated:</h2><p>Use <em>preg_match</em> with the <em>&#8216;i&#8217;</em> modifier instead. <em>i</em> means that regular expression is case insensitive. So the code become like this:</p><div
style="clear:both"></div><div
class="example" style="margin:10px 0"><div
class="example-contents programlisting"><div
class="phpcode"><code><span
style="color: #000000"> [raw]&lt;pre&gt;<br
/>if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i",&nbsp;$str))&nbsp;{<br
/>&nbsp;&nbsp;&nbsp;&nbsp;$msg&nbsp;=&nbsp;'email&nbsp;is&nbsp;not&nbsp;valid';<br
/>}<br
/>else&nbsp;{<br
/>$valid&nbsp;=&nbsp;true;<br
/>}&lt;/pre&gt;<br
/>&lt;p&gt;[/raw]</span> </code></div></div></div><h2>The list of functions that are deprecated in PHP 5.3.0:</h2><ul><li>call_user_method() (use call_user_func() instead)</li><li> call_user_method_array() (use call_user_func_array() instead)</li><li> define_syslog_variables()</li><li>dl()</li><li>ereg() (use preg_match() instead)</li><li>ereg_replace() (use preg_replace() instead)</li><li>eregi() (use preg_match() with the &#8216;i&#8217; modifier instead)</li><li> eregi_replace() (use preg_replace() with the &#8216;i&#8217; modifier instead)</li><li>set_magic_quotes_runtime() and its alias, magic_quotes_runtime()</li><li>session_register() (use the $_SESSION superglobal instead)</li><li>session_unregister() (use the $_SESSION superglobal instead)</li><li>session_is_registered() (use the $_SESSION superglobal instead)</li><li>set_socket_blocking() (use stream_set_blocking() instead)</li><li>split() (use preg_split() instead)</li><li> spliti() (use preg_split() with the &#8216;i&#8217; modifier instead)</li><li>sql_regcase()</li><li>mysql_db_query() (use mysql_select_db() and mysql_query() instead)</li><li> mysql_escape_string() (use mysql_real_escape_string() instead)</li><li>Passing locale category names as strings is now deprecated. Use the LC_* family of constants instead.</li><li>The is_dst parameter to mktime(). Use the new timezone handling functions instead.</li></ul><p>Ref:</p><p>http://php.net/manual/en/migration53.deprecated.php</p> ]]></content:encoded> <wfw:commentRss>http://takien.com/513/how-to-fix-function-eregi-is-deprecated-in-php-5-3-0.php/feed</wfw:commentRss> <slash:comments>58</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 16/37 queries in 0.017 seconds using disk: basic

Served from: takien.com @ 2012-02-04 16:33:56 -->
