summaryrefslogtreecommitdiffstats
path: root/wp-inst
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-04-07 10:13:03 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-04-07 10:13:03 +0000
commita72266931b88c8fa300d2e29a69a2bb38a70654a (patch)
tree67fed20f180d3cd9e0edce2d46a02415e7cb818d /wp-inst
parent7252768fd218b03ad459fca3289452d447bfe0e2 (diff)
downloadwordpress-mu-a72266931b88c8fa300d2e29a69a2bb38a70654a.tar.gz
wordpress-mu-a72266931b88c8fa300d2e29a69a2bb38a70654a.tar.xz
wordpress-mu-a72266931b88c8fa300d2e29a69a2bb38a70654a.zip
WP Merge - add files (we're not finished yet!)
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@542 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-inst')
-rw-r--r--wp-inst/wp-admin/admin-ajax.php234
-rw-r--r--wp-inst/wp-admin/categories.js5
-rw-r--r--wp-inst/wp-admin/custom-fields.js25
-rw-r--r--wp-inst/wp-admin/link.php128
-rw-r--r--wp-inst/wp-admin/list-manipulation-js.php162
-rw-r--r--wp-inst/wp-admin/users.js20
-rw-r--r--wp-inst/wp-cron.php24
-rw-r--r--wp-inst/wp-includes/cron.php107
-rw-r--r--wp-inst/wp-includes/query.php1016
-rw-r--r--wp-inst/wp-includes/rewrite.php803
-rw-r--r--wp-inst/wp-includes/template-functions-bookmarks.php389
11 files changed, 2913 insertions, 0 deletions
diff --git a/wp-inst/wp-admin/admin-ajax.php b/wp-inst/wp-admin/admin-ajax.php
new file mode 100644
index 0000000..7f7db0b
--- /dev/null
+++ b/wp-inst/wp-admin/admin-ajax.php
@@ -0,0 +1,234 @@
+<?php
+require_once('../wp-config.php');
+require_once('admin-functions.php');
+require_once('admin-db.php');
+
+define('DOING_AJAX', true);
+
+
+check_ajax_referer();
+if ( !is_user_logged_in() )
+ die('-1');
+
+function get_out_now() { exit; }
+add_action( 'shutdown', 'get_out_now', -1 );
+
+function wp_clean_ajax_input( $i ) {
+ global $wpdb;
+ $i = is_array($i) ? array_map('wp_clean_ajax_input', $i) : $wpdb->escape( rawurldecode(stripslashes($i)) );
+ return $i;
+}
+
+function wp_ajax_echo_meta( $pid, $mid, $key, $value ) {
+ $value = wp_specialchars($value, true);
+ $key_js = addslashes(wp_specialchars($key, 'double'));
+ $key = wp_specialchars($key, true);
+ $r = "<meta><id>$mid</id><postid>$pid</postid><newitem><![CDATA[<table><tbody>";
+ $r .= "<tr id='meta-$mid'><td valign='top'>";
+ $r .= "<input name='meta[$mid][key]' tabindex='6' onkeypress='return killSubmit(\"theList.ajaxUpdater(&#039;meta&#039;,&#039;meta-$mid&#039;);\",event);' type='text' size='20' value='$key' />";
+ $r .= "</td><td><textarea name='meta[$mid][value]' tabindex='6' rows='2' cols='30'>$value</textarea></td><td align='center'>";
+ $r .= "<input name='updatemeta' type='button' class='updatemeta' tabindex='6' value='Update' onclick='return theList.ajaxUpdater(&#039;meta&#039;,&#039;meta-$mid&#039;);' /><br />";
+ $r .= "<input name='deletemeta[$mid]' type='submit' onclick=\"return deleteSomething( 'meta', $mid, '";
+ $r .= sprintf(__("You are about to delete the &quot;%s&quot; custom field on this post.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), $key_js);
+ $r .= "' );\" class='deletemeta' tabindex='6' value='Delete' />";
+ $r .= "</td></tr></tbody></table>]]></newitem></meta>";
+ return $r;
+}
+
+$_POST = wp_clean_ajax_input( $_POST );
+$id = (int) $_POST['id'];
+switch ( $_POST['action'] ) :
+case 'delete-comment' :
+ if ( !$comment = get_comment( $id ) )
+ die('0');
+ if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
+ die('-1');
+
+ if ( wp_delete_comment( $comment->comment_ID ) )
+ die('1');
+ else die('0');
+ break;
+case 'delete-comment-as-spam' :
+ if ( !$comment = get_comment( $id ) )
+ die('0');
+ if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
+ die('-1');
+
+ if ( wp_set_comment_status( $comment->comment_ID, 'spam' ) )
+ die('1');
+ else die('0');
+ break;
+case 'delete-cat' :
+ if ( !current_user_can( 'manage_categories' ) )
+ die('-1');
+
+ if ( wp_delete_category( $id ) )
+ die('1');
+ else die('0');
+ break;
+case 'delete-link' :
+ if ( !current_user_can( 'manage_links' ) )
+ die('-1');
+
+ if ( wp_delete_link( $id ) )
+ die('1');
+ else die('0');
+ break;
+case 'delete-meta' :
+ if ( !$meta = get_post_meta_by_id( $id ) )
+ die('0');
+ if ( !current_user_can( 'edit_post', $meta->post_id ) )
+ die('-1');
+ if ( delete_meta( $meta->meta_id ) )
+ die('1');
+ die('0');
+ break;
+case 'delete-post' :
+ if ( !current_user_can( 'delete_post', $id ) )
+ die('-1');
+
+ if ( wp_delete_post( $id ) )
+ die('1');
+ else die('0');
+ break;
+case 'delete-page' :
+ if ( !current_user_can( 'delete_page', $id ) )
+ die('-1');
+
+ if ( wp_delete_post( $id ) )
+ die('1');
+ else die('0');
+ break;
+case 'dim-comment' :
+ if ( !$comment = get_comment( $id ) )
+ die('0');
+ if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
+ die('-1');
+ if ( !current_user_can( 'moderate_comments' ) )
+ die('-1');
+
+ if ( 'unapproved' == wp_get_comment_status($comment->comment_ID) ) {
+ if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
+ die('1');
+ } else {
+ if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
+ die('1');
+ }
+ die('0');
+ break;
+case 'add-category' : // On the Fly
+ if ( !current_user_can( 'manage_categories' ) )
+ die('-1');
+ $names = explode(',', $_POST['newcat']);
+ $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
+ foreach ( $names as $cat_name ) {
+ $cat_name = trim($cat_name);
+ if ( !$category_nicename = sanitize_title($cat_name) )
+ die('0');
+ if ( !$cat_id = category_exists( $cat_name ) )
+ $cat_id = wp_create_category( $cat_name );
+ $cat_name = wp_specialchars(stripslashes($cat_name));
+ $r .= "<category><id>$cat_id</id><newitem><![CDATA[";
+ $r .= "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'>";
+ $r .= "<input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>";
+ $r .= "]]></newitem></category>";
+ }
+ $r .= '</ajaxresponse>';
+ header('Content-type: text/xml');
+ die($r);
+ break;
+case 'add-cat' : // From Manage->Categories
+ if ( !current_user_can( 'manage_categories' ) )
+ die('-1');
+ if ( !$cat = wp_insert_category( $_POST ) )
+ die('0');
+ if ( !$cat = get_category( $cat ) )
+ die('0');
+ $pad = 0;
+ $_cat = $cat;
+ while ( $_cat->category_parent ) {
+ $_cat = get_category( $_cat->category_parent );
+ $pad++;
+ }
+ $pad = str_repeat('&#8212; ', $pad);
+
+ $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
+ $r .= "<cat><id>$cat->cat_ID</id><newitem><![CDATA[<table><tbody>";
+ $r .= "<tr id='cat-$cat->cat_ID'><th scope='row'>$cat->cat_ID</th><td>$pad $cat->cat_name</td>";
+ $r .= "<td>$cat->category_description</td><td>$cat->category_count</td><td>$cat->link_count</td>";
+ $r .= "<td><a href='categories.php?action=edit&amp;cat_ID=$cat->cat_ID' class='edit'>" . __('Edit') . "</a></td>";
+ $r .= "<td><a href='categories.php?action=delete&amp;cat_ID=$cat->cat_ID' onclick='return deleteSomething( \"cat\", $cat->cat_ID, \"";
+ $r .= sprintf(__('You are about to delete the category \"%s\". All of its posts and bookmarks will go to the default categories.\\n\"OK\" to delete, \"Cancel\" to stop.'), addslashes($cat->cat_name));
+ $r .= "\" );' class='delete'>".__('Delete')."</a></td></tr>";
+ $r .= "</tbody></table>]]></newitem></cat></ajaxresponse>";
+ header('Content-type: text/xml');
+ die($r);
+
+ break;
+case 'add-meta' :
+ if ( !current_user_can( 'edit_post', $id ) )
+ die('-1');
+ if ( $id < 0 ) {
+ if ( $pid = write_post() )
+ $meta = has_meta( $pid );
+ else
+ die('0');
+ $key = $meta[0]['meta_key'];
+ $value = $meta[0]['meta_value'];
+ $mid = (int) $meta[0]['meta_id'];
+ } else {
+ if ( $mid = add_meta( $id ) )
+ $meta = get_post_meta_by_id( $mid );
+ else
+ die('0');
+ $key = $meta->meta_key;
+ $value = $meta->meta_value;
+ $pid = (int) $meta->post_id;
+ }
+ $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
+ $r .= wp_ajax_echo_meta( $pid, $mid, $key, $value );
+ $r .= '</ajaxresponse>';
+ header('Content-type: text/xml');
+ die($r);
+ break;
+case 'update-meta' :
+ $mid = (int) array_pop(array_keys($_POST['meta']));
+ $key = $_POST['meta'][$mid]['key'];
+ $value = $_POST['meta'][$mid]['value'];
+ if ( !$meta = get_post_meta_by_id( $mid ) )
+ die('0');
+ if ( !current_user_can( 'edit_post', $meta->post_id ) )
+ die('-1');
+ $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
+ if ( $u = update_meta( $mid, $key, $value ) ) {
+ $key = stripslashes($key);
+ $value = stripslashes($value);
+ $r .= wp_ajax_echo_meta( $meta->post_id, $mid, $key, $value );
+ }
+ $r .= '</ajaxresponse>';
+ header('Content-type: text/xml');
+ die($r);
+ break;
+case 'add-user' :
+ if ( !current_user_can('edit_users') )
+ die('-1');
+ require_once( ABSPATH . WPINC . '/registration-functions.php');
+ $user_id = add_user();
+ if ( is_wp_error( $user_id ) ) {
+ foreach( $user_id->get_error_messages() as $message )
+ echo "$message<br />";
+ exit;
+ } elseif ( !$user_id ) {
+ die('0');
+ }
+ $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse><user><id>$user_id</id><newitem><![CDATA[<table><tbody>";
+ $r .= user_row( $user_id );
+ $r .= "</tbody></table>]]></newitem></user></ajaxresponse>";
+ header('Content-type: text/xml');
+ die($r);
+ break;
+default :
+ die('0');
+ break;
+endswitch;
+?>
diff --git a/wp-inst/wp-admin/categories.js b/wp-inst/wp-admin/categories.js
new file mode 100644
index 0000000..5be5a62
--- /dev/null
+++ b/wp-inst/wp-admin/categories.js
@@ -0,0 +1,5 @@
+addLoadEvent(newCategoryAddIn);
+function newCategoryAddIn() {
+ if (!theList.theList) return false;
+ document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); };
+}
diff --git a/wp-inst/wp-admin/custom-fields.js b/wp-inst/wp-admin/custom-fields.js
new file mode 100644
index 0000000..2e70d6c
--- /dev/null
+++ b/wp-inst/wp-admin/custom-fields.js
@@ -0,0 +1,25 @@
+addLoadEvent(customFieldsAddIn);
+function customFieldsAddIn() {
+ theList.showLink=0;
+ if (!theList.theList) return false;
+ inputs = theList.theList.getElementsByTagName('input');
+ for ( var i=0; i < inputs.length; i++ ) {
+ if ('text' == inputs[i].type) {
+ inputs[i].setAttribute('autocomplete', 'off');
+ inputs[i].onkeypress = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.name.slice(5),10) + '");', e); };
+ }
+ if ('updatemeta' == inputs[i].className) {
+ inputs[i].onclick = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.parentNode.parentNode.id.slice(5),10) + '");', e); };
+ }
+ }
+
+ document.getElementById('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
+ document.getElementById('updatemetasub').onclick = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
+}
+function customFieldsOnComplete() {
+ var pidEl = document.getElementById('post_ID');
+ pidEl.name = 'post_ID';
+ pidEl.value = getNodeValue(theList.ajaxAdd.responseXML, 'postid');
+ var aEl = document.getElementById('hiddenaction')
+ if ( aEl.value == 'post' ) aEl.value = 'postajaxpost';
+}
diff --git a/wp-inst/wp-admin/link.php b/wp-inst/wp-admin/link.php
new file mode 100644
index 0000000..df61692
--- /dev/null
+++ b/wp-inst/wp-admin/link.php
@@ -0,0 +1,128 @@
+<?php
+require_once ('admin.php');
+
+$wpvarstoreset = array ('action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]');
+
+for ($i = 0; $i < count($wpvarstoreset); $i += 1) {
+ $wpvar = $wpvarstoreset[$i];
+ if (!isset ($$wpvar)) {
+ if (empty ($_POST["$wpvar"])) {
+ if (empty ($_GET["$wpvar"])) {
+ $$wpvar = '';
+ } else {
+ $$wpvar = $_GET["$wpvar"];
+ }
+ } else {
+ $$wpvar = $_POST["$wpvar"];
+ }
+ }
+}
+
+if ('' != $_POST['deletebookmarks'])
+ $action = 'deletebookmarks';
+if ('' != $_POST['move'])
+ $action = 'move';
+if ('' != $_POST['linkcheck'])
+ $linkcheck = $_POST[linkcheck];
+
+$this_file = 'link-manager.php';
+
+switch ($action) {
+ case 'deletebookmarks' :
+ check_admin_referer();
+
+ // check the current user's level first.
+ if (!current_user_can('manage_links'))
+ die(__("Cheatin' uh ?"));
+
+ //for each link id (in $linkcheck[]) change category to selected value
+ if (count($linkcheck) == 0) {
+ header('Location: '.$this_file);
+ exit;
+ }
+
+ $deleted = 0;
+ foreach ($linkcheck as $link_id) {
+ $link_id = (int) $link_id;
+
+ if ( wp_delete_link($link_id) )
+ $deleted++;
+ }
+
+ header("Location: $this_file?deleted=$deleted");
+ break;
+
+ case 'move' :
+ check_admin_referer();
+
+ // check the current user's level first.
+ if (!current_user_can('manage_links'))
+ die(__("Cheatin' uh ?"));
+
+ //for each link id (in $linkcheck[]) change category to selected value
+ if (count($linkcheck) == 0) {
+ header('Location: '.$this_file);
+ exit;
+ }
+ $all_links = join(',', $linkcheck);
+ // should now have an array of links we can change
+ //$q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
+
+ header('Location: '.$this_file);
+ break;
+
+ case 'add' :
+ check_admin_referer();
+
+ add_link();
+
+ header('Location: '.$_SERVER['HTTP_REFERER'].'?added=true');
+ break;
+
+ case 'save' :
+ check_admin_referer();
+
+ $link_id = (int) $_POST['link_id'];
+ edit_link($link_id);
+
+ wp_redirect($this_file);
+ exit;
+ break;
+
+ case 'delete' :
+ check_admin_referer();
+
+ if (!current_user_can('manage_links'))
+ die(__("Cheatin' uh ?"));
+
+ $link_id = (int) $_GET['link_id'];
+
+ wp_delete_link($link_id);
+
+ wp_redirect($this_file);
+ break;
+
+ case 'edit' :
+ $xfn_js = true;
+ $editing = true;
+ $parent_file = 'link-manager.php';
+ $submenu_file = 'link-manager.php';
+ $title = __('Edit Bookmark');
+ include_once ('admin-header.php');
+ if (!current_user_can('manage_links'))
+ die(__('You do not have sufficient permissions to edit the bookmarks for this blog.'));
+
+ $link_id = (int) $_GET['link_id'];
+
+ if (!$link = get_link_to_edit($link_id))
+ die(__('Link not found.'));
+
+ include ('edit-link-form.php');
+ break;
+
+ default :
+ break;
+}
+
+include ('admin-footer.php');
+?> \ No newline at end of file
diff --git a/wp-inst/wp-admin/list-manipulation-js.php b/wp-inst/wp-admin/list-manipulation-js.php
new file mode 100644
index 0000000..d87edab
--- /dev/null
+++ b/wp-inst/wp-admin/list-manipulation-js.php
@@ -0,0 +1,162 @@
+<?php
+require_once('admin.php');
+header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
+?>
+addLoadEvent(function(){theList=new listMan();});
+function deleteSomething(what,id,message){if(!message)message="<?php printf(__('Are you sure you want to delete this %s?'),"'+what+'"); ?>";if(confirm(message))return theList.ajaxDelete(what,id);else return false;}
+function dimSomething(what,id,dimClass){return theList.ajaxDimmer(what,id,dimClass);}
+
+function WPAjax(file, responseEl){//class WPAjax extends sack
+ this.getResponseElement=function(r){var p=document.getElementById(r+'-p');if(!p){p=document.createElement('span');p.id=r+'-p';document.getElementById(r).appendChild(p);}this.myResponseElement=p; }
+ this.parseAjaxResponse=function(){
+ if(isNaN(this.response)){this.myResponseElement.innerHTML='<div class="error"><p>'+this.response+'</p></div>';return false;}
+ this.response=parseInt(this.response,10);
+ if(-1==this.response){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("You don't have permission to do that."); ?></p></div>";return false;}
+ else if(0==this.response){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("Something odd happened. Try refreshing the page? Either that or what you tried to change never existed in the first place."); ?></p></div>";return false;}
+ return true;
+ }
+ this.parseAjaxResponseXML=function(){
+ if(this.responseXML&&typeof this.responseXML=='object')return true;
+ if(isNaN(this.response)){this.myResponseElement.innerHTML='<div class="error"><p>'+this.response+'</p></div>';return false;}
+ var r=parseInt(this.response,10);
+ if(-1==r){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("You don't have permission to do that."); ?></p></div>";}
+ else if(0==r){this.myResponseElement.innerHTML="<div class='error'><p><?php _e("Invalid Entry."); ?></p></div>";}
+ return false;
+ }
+ this.init(file,responseEl);
+} WPAjax.prototype=new sack;
+ WPAjax.prototype.init=function(f,r){
+ this.encVar('cookie', document.cookie);
+ this.requestFile=f;this.getResponseElement(r);this.method='POST';
+ this.onLoading=function(){this.myResponseElement.innerHTML="<?php _e('Sending Data...'); ?>";};
+ this.onLoaded=function(){this.myResponseElement.innerHTML="<?php _e('Data Sent...'); ?>";};
+ this.onInteractive=function(){this.myResponseElement.innerHTML="<?php _e('Processing Data...'); ?>";};
+ }
+
+function listMan(theListId){
+ this.theList=null;
+ this.ajaxRespEl=null;
+ this.inputData='';this.clearInputs=new Array();this.showLink=1;
+ this.topAdder=0;this.alt='alternate';this.recolorPos;this.reg_color='#FFFFFF';this.alt_color='#F1F1F1';
+ var listType;var listItems;
+ self.aTrap=0;
+
+ this.ajaxAdder=function(what,where,onComplete,update){//for TR, server must wrap TR in TABLE TBODY. this.makeEl cleans it
+ if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
+ this.ajaxAdd=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
+ if(this.ajaxAdd.failed)return true;
+ this.grabInputs(where);
+ var tempObj=this;
+ this.ajaxAdd.onCompletion=function(){
+ if(!this.parseAjaxResponseXML())return;
+ var newItems=this.responseXML.getElementsByTagName(what);
+ if(tempObj.topAdder)tempObj.recolorPos=0;
+ if(newItems){for (c=0;c<newItems.length;c++){
+ var id=parseInt(getNodeValue(newItems[c],'id'),10);
+ var exists=document.getElementById(what+'-'+id);
+ if(exists)tempObj.replaceListItem(exists.id,getNodeValue(newItems[c],'newitem'),newItems.length,update);
+ else tempObj.addListItem(getNodeValue(newItems[c],'newitem'),newItems.length);
+ }}
+ tempObj.inputData='';
+ if(tempObj.showLink){this.myResponseElement.innerHTML='<div id="jumplink" class="updated fade"><p><a href="#'+what+'-'+id+'"><?php _e('Jump to new item'); ?></a></p></div>';}
+ else this.myResponseElement.innerHTML='';
+ for(var i=0;i<tempObj.clearInputs.length;i++){try{var theI=document.getElementById(tempObj.clearInputs[i]);if(theI.tagName.match(/select/i))theI.selectedIndex=0;else theI.value='';}catch(e){}}
+ if(onComplete&&typeof onComplete=='function')onComplete();
+ tempObj.recolorList(tempObj.recolorPos,1000);
+ }
+ this.ajaxAdd.runAJAX('action='+(update?'update-':'add-')+what+this.inputData);
+ return false;
+ }
+ this.ajaxUpdater=function(what,where,onComplete){return this.ajaxAdder(what,where,onComplete,true);}
+ this.ajaxDelete=function(what,id,onComplete){
+ if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
+ this.ajaxDel=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
+ if(this.ajaxDel.failed)return true;
+ var tempObj=this;
+ this.ajaxDel.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.removeListItem(what.replace('-as-spam','')+'-'+id);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();tempObj.recolorList(tempObj.recolorPos,1000)}};
+ this.ajaxDel.runAJAX('action=delete-'+what+'&id='+id);
+ return false;
+ }
+ this.ajaxDimmer=function(what,id,dimClass,onComplete){
+ if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
+ this.ajaxDim=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
+ if(this.ajaxDim.failed)return true;
+ var tempObj=this;
+ this.ajaxDim.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.dimItem(what+'-'+id,dimClass);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();}};
+ this.ajaxDim.runAJAX('action=dim-'+what+'&id='+id);
+ return false;
+ }
+ this.makeEl=function(h){var fakeItem=document.createElement('div');fakeItem.innerHTML=h;var r=fakeItem.firstChild;while(r.tagName.match(/(table|tbody)/i)){r=r.firstChild;}return r;}
+ this.addListItem=function(h,tot){
+ newItem=this.makeEl(h);
+ if(this.topAdder){var firstItem=this.theList.getElementsByTagName('table'==listType?'tr':'li')[0];listItems.unshift(newItem.id);this.recolorPos++}
+ else{listItems.push(newItem.id);this.recolorPos=listItems.length;}
+ if(this.alt&&!((tot-this.recolorPos)%2))newItem.className+=' '+this.alt;
+ if(firstItem)firstItem.parentNode.insertBefore(newItem,firstItem);
+ else this.theList.appendChild(newItem);
+ Fat.fade_element(newItem.id);
+ }
+ this.removeListItem=function(id,noFade){
+ if(!noFade)Fat.fade_element(id,null,700,'#FF3333');
+ var theItem=document.getElementById(id);
+ if(!noFade){var func=encloseFunc(function(a){a.parentNode.removeChild(a);},theItem);setTimeout(func,705);}
+ else{theItem.parentNode.removeChild(theItem);}
+ var pos=this.getListPos(id);
+ listItems.splice(pos,1);
+ }
+ this.replaceListItem=function(id,h,tot,update){
+ if(!update){this.removeListItem(id,true);this.addListItem(h,tot);return;}
+ var newItem=this.makeEl(h);
+ var oldItem=document.getElementById(id);
+ var pos=this.getListPos(oldItem.id,1);if(this.alt&&!(pos%2))newItem.className+=' '+this.alt;
+ oldItem.parentNode.replaceChild(newItem,oldItem);
+ Fat.fade_element(newItem.id);
+ }
+ this.dimItem=function(id,dimClass,noFade){
+ var theItem=document.getElementById(id);
+ if(theItem.className.match(dimClass)){if(!noFade)Fat.fade_element(id,null,700,null);theItem.className=theItem.className.replace(dimClass,'');}
+ else{if(!noFade)Fat.fade_element(id,null,700,'#FF3333');theItem.className=theItem.className+' '+dimClass;}
+ }
+ this.grabInputs=function(elId){//text,password,hidden,textarea,select
+ var theItem=document.getElementById(elId);
+ var inputs=new Array();
+ inputs.push(theItem.getElementsByTagName('input'),theItem.getElementsByTagName('textarea'),theItem.getElementsByTagName('select'));
+ for(var a=0;a<inputs.length;a++){
+ for(var i=0;i<inputs[a].length;i++){
+ if('action'==inputs[a][i].name)continue;
+ if('text'==inputs[a][i].type||'password'==inputs[a][i].type||'hidden'==inputs[a][i].type||inputs[a][i].tagName.match(/textarea/i)){
+ this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].value);if('hidden'!=inputs[a][i].type)this.clearInputs.push(inputs[a][i].id);
+ }else if(inputs[a][i].tagName.match(/select/i)){
+ this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].options[inputs[a][i].selectedIndex].value);this.clearInputs.push(inputs[a][i].id);
+ }
+ }
+ }
+ }
+ this.getListPos=function(id,n){for(var i=0;i<listItems.length;i++){if(id==listItems[i]){var pos=i;break;}}if(!n){if(pos<this.recolorPos)this.recolorPos=pos;}return pos;}
+ this.getListItems=function(){
+ if(this.theList)return;
+ listItems=new Array();
+ if(theListId){this.theList=document.getElementById(theListId);if(!this.theList)return false;}
+ else{this.theList=document.getElementById('the-list');if(this.theList)theListId='the-list';}
+ if(this.theList){
+ var items=this.theList.getElementsByTagName('tr');listType='table';
+ if(!items[0]){items=this.theList.getElementsByTagName('li');listType='list';}
+ for(var i=0;i<items.length;i++){listItems.push(items[i].id);}
+ this.recolorPos=listItems.length;
+ }
+ }
+ this.recolorList=function(pos,dur){
+ if(!this.alt)return;if(!pos)pos=0;this.recolorPos=listItems.length;
+ for(var i=pos;i<listItems.length;i++){var e=document.getElementById(listItems[i]);if(i%2)e.className=e.className.replace(this.alt,'fade-'+this.alt_color.slice(1));else e.className+=' '+this.alt+' fade-'+this.reg_color.slice(1);e.style.backgroundColor='';}
+ Fat.fade_all(dur);
+ var func=encloseFunc(function(l){for(var i=0;i<l.length;i++){var e=document.getElementById(l[i]);e.className=e.className.replace(/fade-[a-f0-9]{6}/i,'');}},listItems);
+ setTimeout(func,dur+5);
+ }
+ this.getListItems();
+}
+//No submit unless eval(code) returns true.
+function killSubmit(code,e){if(!e){if(window.event)e=window.event;else return;}var t=e.target?e.target:e.srcElement;if(('text'==t.type&&e.keyCode==13)||('submit'==t.type&&'click'==e.type)){if(!eval(code)){e.returnValue=false;e.cancelBubble=true;return false;}}}
+//Pretty func from ALA http://www.alistapart.com/articles/gettingstartedwithajax
+function getNodeValue(tree,el){return tree.getElementsByTagName(el)[0].firstChild.nodeValue;}
+//Generic but lame JS closure
+function encloseFunc(f){var a=arguments[1];return function(){return f(a);}}
diff --git a/wp-inst/wp-admin/users.js b/wp-inst/wp-admin/users.js
new file mode 100644
index 0000000..5e40418
--- /dev/null
+++ b/wp-inst/wp-admin/users.js
@@ -0,0 +1,20 @@
+addLoadEvent(function() {
+ theListEls = document.getElementsByTagName('tbody');
+ theUserLists = new Array();
+ for ( var l = 0; l < theListEls.length; l++ ) {
+ theUserLists[theListEls[l].id] = new listMan(theListEls[l].id);
+ }
+ addUserInputs = document.getElementById('adduser').getElementsByTagName('input');
+ for ( var i = 0; i < addUserInputs.length; i++ ) {
+ addUserInputs[i].onkeypress = function(e) { return killSubmit('addUserSubmit();', e); }
+ }
+ document.getElementById('addusersub').onclick = function(e) { return killSubmit('addUserSubmit();', e); }
+}
+);
+
+function addUserSubmit() {
+ var roleEl = document.getElementById('role');
+ var role = roleEl.options[roleEl.selectedIndex].value;
+ if ( !theUserLists['role-' + role] ) return true;
+ return theUserLists['role-' + role].ajaxAdder('user', 'adduser');
+}
diff --git a/wp-inst/wp-cron.php b/wp-inst/wp-cron.php
new file mode 100644
index 0000000..69a1e94
--- /dev/null
+++ b/wp-inst/wp-cron.php
@@ -0,0 +1,24 @@
+<?php
+ignore_user_abort(true);
+define('DOING_CRON', TRUE);
+require_once('wp-config.php');
+
+if ( $_GET['check'] != md5(DB_PASS . '187425') )
+ exit;
+
+$crons = get_option('cron');
+if (!is_array($crons) || array_shift(array_keys($crons)) > time())
+ return;
+foreach ($crons as $timestamp => $cronhooks) {
+ if ($timestamp > time()) break;
+ foreach($cronhooks as $hook => $args) {
+ do_action($hook, $args['args']);
+ $schedule = $args['schedule'];
+ if($schedule != false) {
+ $args = array_merge( array($timestamp, $schedule, $hook), $args['args']);
+ call_user_func_array('wp_reschedule_event', $args);
+ }
+ wp_unschedule_event($timestamp, $hook);
+ }
+}
+?>
diff --git a/wp-inst/wp-includes/cron.php b/wp-inst/wp-includes/cron.php
new file mode 100644
index 0000000..16cfef1
--- /dev/null
+++ b/wp-inst/wp-includes/cron.php
@@ -0,0 +1,107 @@
+<?php
+
+function wp_schedule_single_event( $timestamp, $hook ) {
+ $args = array_slice( func_get_args(), 2 );
+ $crons = get_option( 'cron' );
+ $crons[$timestamp][$hook] = array( 'schedule' => false, 'args' => $args );
+ ksort( $crons );
+ update_option( 'cron', $crons );
+}
+
+function wp_schedule_event( $timestamp, $recurrence, $hook ) {
+ $args = array_slice( func_get_args(), 3 );
+ $crons = get_option( 'cron' );
+ $schedules = wp_get_schedules();
+ if ( !isset( $schedules[$recurrence] ) )
+ return false;
+ $crons[$timestamp][$hook] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );
+ ksort( $crons );
+ update_option( 'cron', $crons );
+}
+
+function wp_reschedule_event( $timestamp, $recurrence, $hook ) {
+ $args = array_slice( func_get_args(), 3 );
+ $crons = get_option( 'cron' );
+ $schedules = wp_get_schedules();
+ $interval = 0;
+
+ // First we try to get it from the schedule
+ if ( 0 == $interval )
+ $interval = $schedules[$recurrence]['interval'];
+ // Now we try to get it from the saved interval in case the schedule disappears
+ if ( 0 == $interval )
+ $interval = $crons[$timestamp][$hook]['interval'];
+ // Now we assume something is wrong and fail to schedule
+ if ( 0 == $interval )
+ return false;
+
+ while ( $timestamp < time() + 1 )
+ $timestamp += $interval;
+
+ wp_schedule_event( $timestamp, $recurrence, $hook );
+}
+
+function wp_unschedule_event( $timestamp, $hook ) {
+ $crons = get_option( 'cron' );
+ unset( $crons[$timestamp][$hook] );
+ if ( empty($crons[$timestamp]) )
+ unset( $crons[$timestamp] );
+ update_option( 'cron', $crons );
+}
+
+function wp_clear_scheduled_hook( $hook ) {
+ while ( $timestamp = wp_next_scheduled( $hook ) )
+ wp_unschedule_event( $timestamp, $hook );
+}
+
+function wp_next_scheduled( $hook ) {
+ $crons = get_option( 'cron' );
+ if ( empty($crons) )
+ return false;
+ foreach ( $crons as $timestamp => $cron )
+ if ( isset( $cron[$hook] ) )
+ return $timestamp;
+ return false;
+}
+
+function spawn_cron() {
+ if ( array_shift( array_keys( get_option( 'cron' ) ) ) > time() )
+ return;
+
+ $cron_url = get_settings( 'siteurl' ) . '/wp-cron.php';
+ $parts = parse_url( $cron_url );
+
+ $argyle = @ fsockopen( $parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01 );
+ if ( $argyle )
+ fputs( $argyle,
+ "GET {$parts['path']}?check=" . md5(DB_PASS . '187425') . " HTTP/1.0\r\n"
+ . "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n"
+ );
+}
+
+function wp_cron() {
+ $crons = get_option( 'cron' );
+ if ( !is_array($crons) || array_shift( array_keys( $crons ) ) > time() )
+ return;
+
+ $schedules = wp_get_schedules();
+ foreach ( $crons as $timestamp => $cronhooks ) {
+ if ( $timestamp > time() ) break;
+ foreach ( $cronhooks as $hook => $args ) {
+ if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) )
+ continue;
+ spawn_cron();
+ break 2;
+ }
+ }
+}
+
+function wp_get_schedules() {
+ $schedules = array(
+ 'hourly' => array( 'interval' => 3600, 'display' => __('Once Hourly') ),
+ 'daily' => array( 'interval' => 86400, 'display' => __('Once Daily') ),
+ );
+ return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
+}
+
+?> \ No newline at end of file
diff --git a/wp-inst/wp-includes/query.php b/wp-inst/wp-includes/query.php
new file mode 100644
index 0000000..240b51d
--- /dev/null
+++ b/wp-inst/wp-includes/query.php
@@ -0,0 +1,1016 @@
+<?php
+
+/*
+ * The Big Query.
+ */
+
+function get_query_var($var) {
+ global $wp_query;
+
+ return $wp_query->get($var);
+}
+
+function &query_posts($query) {
+ global $wp_query;
+ return $wp_query->query($query);
+}
+
+/*
+ * Query type checks.
+ */
+
+function is_admin () {
+ global $wp_query;
+
+ return ( $wp_query->is_admin || strstr($_SERVER['REQUEST_URI'], 'wp-admin/') );
+}
+
+function is_archive () {
+ global $wp_query;
+
+ return $wp_query->is_archive;
+}
+
+function is_attachment () {
+ global $wp_query;
+
+ return $wp_query->is_attachment;
+}
+
+function is_author ($author = '') {
+ global $wp_query;
+
+ if ( !$wp_query->is_author )
+ return false;
+
+ if ( empty($author) )
+ return true;
+
+ $author_obj = $wp_query->get_queried_object();
+
+ if ( $author == $author_obj->ID )
+ return true;
+ elseif ( $author == $author_obj->nickname )
+ return true;
+ elseif ( $author == $author_obj->user_nicename )
+ return true;
+
+ return false;
+}
+
+function is_category ($category = '') {
+ global $wp_query;
+
+ if ( !$wp_query->is_category )
+ return false;
+
+ if ( empty($category) )
+ return true;
+
+ $cat_obj = $wp_query->get_queried_object();
+
+ if ( $category == $cat_obj->cat_ID )
+ return true;
+ else if ( $category == $cat_obj->cat_name )
+ return true;
+ elseif ( $category == $cat_obj->category_nicename )
+ return true;
+
+ return false;
+}
+
+function is_comments_popup () {
+ global $wp_query;
+
+ return $wp_query->is_comments_popup;
+}
+
+function is_date () {
+ global $wp_query;
+
+ return $wp_query->is_date;
+}
+
+function is_day () {
+ global $wp_query;
+
+ return $wp_query->is_day;
+}
+
+function is_feed () {
+ global $wp_query;
+
+ return $wp_query->is_feed;
+}
+
+function is_home () {
+ global $wp_query;
+
+ return $wp_query->is_home;
+}
+
+function is_month () {
+ global $wp_query;
+
+ return $wp_query->is_month;
+}
+
+function is_page ($page = '') {
+ global $wp_query;
+
+ if ( !$wp_query->is_page )
+ return false;
+
+ if ( empty($page) )
+ return true;
+
+ $page_obj = $wp_query->get_queried_object();
+
+ if ( $page == $page_obj->ID )
+ return true;
+ elseif ( $page == $page_obj->post_title )
+ return true;
+ else if ( $page == $page_obj->post_name )
+ return true;
+
+ return false;
+}
+
+function is_paged () {
+ global $wp_query;
+
+ return $wp_query->is_paged;
+}
+
+function is_plugin_page() {
+ global $plugin_page;
+
+ if ( isset($plugin_page) )
+ return true;
+
+ return false;
+}
+
+function is_preview() {
+ global $wp_query;
+
+ return $wp_query->is_preview;
+}
+
+function is_search () {
+ global $wp_query;
+
+ return $wp_query->is_search;
+}
+
+function is_single ($post = '') {
+ global $wp_query;
+
+ if ( !$wp_query->is_single )
+ return false;
+
+ if ( empty( $post) )
+ return true;
+
+ $post_obj = $wp_query->get_queried_object();
+
+ if ( $post == $post_obj->ID )
+ return true;
+ elseif ( $post == $post_obj->post_title )
+ return true;
+ elseif ( $post == $post_obj->post_name )
+ return true;
+
+ return false;
+}
+
+function is_time () {
+ global $wp_query;
+
+ return $wp_query->is_time;
+}
+
+function is_trackback () {
+ global $wp_query;
+
+ return $wp_query->is_trackback;
+}
+
+function is_year () {
+ global $wp_query;
+
+ return $wp_query->is_year;
+}
+
+function is_404 () {
+ global $wp_query;
+
+ return $wp_query->is_404;
+}
+
+/*
+ * The Loop. Post loop control.
+ */
+
+function have_posts() {
+ global $wp_query;
+
+ return $wp_query->have_posts();
+}
+
+function in_the_loop() {
+ global $wp_query;
+
+ return $wp_query->in_the_loop;
+}
+
+function rewind_posts() {
+ global $wp_query;
+
+ return $wp_query->rewind_posts();
+}
+
+function the_post() {
+ global $wp_query;
+
+ $wp_query->the_post();
+}
+
+/*
+ * WP_Query
+ */
+
+class WP_Query {
+ var $query;
+ var $query_vars;
+ var $queried_object;
+ var $queried_object_id;
+ var $request;
+
+ var $posts;
+ var $post_count = 0;
+ var $current_post = -1;
+ var $in_the_loop = false;
+ var $post;
+
+ var $is_single = false;
+ var $is_preview = false;
+ var $is_page = false;
+ var $is_archive = false;
+ var $is_date = false;
+ var $is_year = false;
+ var $is_month = false;
+ var $is_day = false;
+ var $is_time = false;
+ var $is_author = false;
+ var $is_category = false;
+ var $is_search = false;
+ var $is_feed = false;
+ var $is_trackback = false;
+ var $is_home = false;
+ var $is_404 = false;
+ var $is_comments_popup = false;
+ var $is_admin = false;
+ var $is_attachment = false;
+
+ function init_query_flags() {
+ $this->is_single = false;
+ $this->is_page = false;
+ $this->is_archive = false;
+ $this->is_date = false;
+ $this->is_year = false;
+ $this->is_month = false;
+ $this->is_day = false;
+ $this->is_time = false;
+ $this->is_author = false;
+ $this->is_category = false;
+ $this->is_search = false;
+ $this->is_feed = false;
+ $this->is_trackback = false;
+ $this->is_home = false;
+ $this->is_404 = false;
+ $this->is_paged = false;
+ $this->is_admin = false;
+ $this->is_attachment = false;
+ }
+
+ function init () {
+ unset($this->posts);
+ unset($this->query);
+ unset($this->query_vars);
+ unset($this->queried_object);
+ unset($this->queried_object_id);
+ $this->post_count = 0;
+ $this->current_post = -1;
+ $this->in_the_loop = false;
+
+ $this->init_query_flags();
+ }
+
+ // Reparse the query vars.
+ function parse_query_vars() {
+ $this->parse_query('');
+ }
+
+ // Parse a query string and set query type booleans.
+ function parse_query ($query) {
+ if ( !empty($query) || !isset($this->query) ) {
+ $this->init();
+ parse_str($query, $qv);
+ $this->query = $query;
+ $this->query_vars = $qv;
+ }
+
+ if ('404' == $qv['error']) {
+ $this->is_404 = true;
+ if ( !empty($query) ) {
+ do_action('parse_query', array(&$this));
+ }
+ return;
+ }
+
+ $qv['m'] = (int) $qv['m'];
+ $qv['p'] = (int) $qv['p'];
+
+ // Compat. Map subpost to attachment.
+ if ( '' != $qv['subpost'] )
+ $qv['attachment'] = $qv['subpost'];
+ if ( '' != $qv['subpost_id'] )
+ $qv['attachment_id'] = $qv['subpost_id'];
+
+ if ( ('' != $qv['attachment']) || (int) $qv['attachment_id'] ) {
+ $this->is_single = true;
+ $this->is_attachment = true;
+ } elseif ('' != $qv['name']) {
+ $this->is_single = true;
+ } elseif ( $qv['p'] ) {
+ $this->is_single = true;
+ } elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) {
+ // If year, month, day, hour, minute, and second are set, a single
+ // post is being queried.
+ $this->is_single = true;
+ } elseif ('' != $qv['static'] || '' != $qv['pagename'] || '' != $qv['page_id']) {
+ $this->is_page = true;
+ $this->is_single = false;
+ } elseif (!empty($qv['s'])) {
+ $this->is_search = true;
+ } else {
+ // Look for archive queries. Dates, categories, authors.
+
+ if ( (int) $qv['second']) {
+ $this->is_time = true;
+ $this->is_date = true;
+ }
+
+ if ( (int) $qv['minute']) {
+ $this->is_time = true;
+ $this->is_date = true;
+ }
+
+ if ( (int) $qv['hour']) {
+ $this->is_time = true;
+ $this->is_date = true;
+ }
+
+ if ( (int) $qv['day']) {
+ if (! $this->is_date) {
+ $this->is_day = true;
+ $this->is_date = true;
+ }
+ }
+
+ if ( (int) $qv['monthnum']) {
+ if (! $this->is_date) {
+ $this->is_month = true;
+ $this->is_date = true;
+ }
+ }
+
+ if ( (int) $qv['year']) {
+ if (! $this->is_date) {
+ $this->is_year = true;
+ $this->is_date = true;
+ }
+ }
+
+ if ( (int) $qv['m']) {
+ $this->is_date = true;
+ if (strlen($qv['m']) > 9) {
+ $this->is_time = true;
+ } else if (strlen($qv['m']) > 7) {
+ $this->is_day = true;
+ } else if (strlen($qv['m']) > 5) {
+ $this->is_month = true;
+ } else {
+ $this->is_year = true;
+ }
+ }
+
+ if ('' != $qv['w']) {
+ $this->is_date = true;
+ }
+
+ if (empty($qv['cat']) || ($qv['cat'] == '0')) {
+ $this->is_category = false;
+ } else {
+ if (stristr($qv['cat'],'-')) {
+ $this->is_category = false;
+ } else {
+ $this->is_category = true;
+ }
+ }
+
+ if ('' != $qv['category_name']) {
+ $this->is_category = true;
+ }
+
+ if ((empty($qv['author'])) || ($qv['author'] == '0')) {
+ $this->is_author = false;
+ } else {
+ $this->is_author = true;
+ }
+
+ if ('' != $qv['author_name']) {
+ $this->is_author = true;
+ }
+
+ if ( ($this->is_date || $this->is_author || $this->is_category)) {
+ $this->is_archive = true;
+ }
+ }
+
+ if ('' != $qv['feed']) {
+ $this->is_feed = true;
+ }
+
+ if ('' != $qv['tb']) {
+ $this->is_trackback = true;
+ }
+
+ if ('' != $qv['paged']) {
+ $this->is_paged = true;
+ }
+
+ if ('' != $qv['comments_popup']) {
+ $this->is_comments_popup = true;
+ }
+
+ //if we're previewing inside the write screen
+ if ('' != $qv['preview']) {
+ $this->is_preview = true;
+ }
+
+ if (strstr($_SERVER['PHP_SELF'], 'wp-admin/')) {
+ $this->is_admin = true;
+ }
+
+ if ( ! ($this->is_attachment || $this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) {
+ $this->is_home = true;
+ }
+
+ if ( !empty($query) ) {
+ do_action('parse_query', array(&$this));
+ }
+ }
+
+ function set_404() {
+ $this->init_query_flags();
+ $this->is_404 = true;
+ }
+
+ function get($query_var) {
+ if (isset($this->query_vars[$query_var])) {
+ return $this->query_vars[$query_var];
+ }
+
+ return '';
+ }
+
+ function set($query_var, $value) {
+ $this->query_vars[$query_var] = $value;
+ }
+
+ function &get_posts() {
+ global $wpdb, $pagenow, $user_ID;
+
+ do_action('pre_get_posts', array(&$this));
+
+ // Shorthand.
+ $q = &$this->query_vars;
+
+ // First let's clear some variables
+ $whichcat = '';
+ $whichauthor = '';
+ $whichpage = '';
+ $result = '';
+ $where = '';
+ $limits = '';
+ $join = '';
+
+ if ( !isset($q['post_type']) )
+ $q['post_type'] = 'post';
+ $post_type = $q['post_type'];
+ if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
+ $q['posts_per_page'] = get_settings('posts_per_page');
+ if ( !isset($q['what_to_show']) )
+ $q['what_to_show'] = get_settings('what_to_show');
+ if ( isset($q['showposts']) && $q['showposts'] ) {
+ $q['showposts'] = (int) $q['showposts'];
+ $q['posts_per_page'] = $q['showposts'];
+ }
+ if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) )
+ $q['posts_per_page'] = $q['posts_per_archive_page'];
+ if ( !isset($q['nopaging']) ) {
+ if ($q['posts_per_page'] == -1) {
+ $q['nopaging'] = true;
+ } else {
+ $q['nopaging'] = false;
+ }
+ }
+ if ( $this->is_feed ) {
+ $q['posts_per_page'] = get_settings('posts_per_rss');
+ $q['what_to_show'] = 'posts';
+ }
+
+ if ( $this->is_home && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) {
+ $this->is_page = true;
+ $this->is_home = false;
+ $q['page_id'] = get_option('page_on_front');
+ }
+
+ if (isset($q['page'])) {
+ $q['page'] = trim($q['page'], '/');
+ $q['page'] = (int) $q['page'];
+ }
+
+ $add_hours = intval(get_settings('gmt_offset'));
+ $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
+ $wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)";
+
+ // If a month is specified in the querystring, load that month
+ if ( (int) $q['m'] ) {
+ $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
+ $where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4);
+ if (strlen($q['m'])>5)
+ $where .= ' AND MONTH(post_date)=' . substr($q['m'], 4, 2);
+ if (strlen($q['m'])>7)
+ $where .= ' AND DAYOFMONTH(post_date)=' . substr($q['m'], 6, 2);
+ if (strlen($q['m'])>9)
+ $where .= ' AND HOUR(post_date)=' . substr($q['m'], 8, 2);
+ if (strlen($q['m'])>11)
+ $where .= ' AND MINUTE(post_date)=' . substr($q['m'], 10, 2);
+ if (strlen($q['m'])>13)
+ $where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2);
+ }
+
+ if ( (int) $q['hour'] ) {
+ $q['hour'] = '' . intval($q['hour']);
+ $where .= " AND HOUR(post_date)='" . $q['hour'] . "'";
+ }
+
+ if ( (int) $q['minute'] ) {
+ $q['minute'] = '' . intval($q['minute']);
+ $where .= " AND MINUTE(post_date)='" . $q['minute'] . "'";
+ }
+
+ if ( (int) $q['second'] ) {
+ $q['second'] = '' . intval($q['second']);
+ $where .= " AND SECOND(post_date)='" . $q['second'] . "'";
+ }
+
+ if ( (int) $q['year'] ) {
+ $q['year'] = '' . intval($q['year']);
+ $where .= " AND YEAR(post_date)='" . $q['year'] . "'";
+ }
+
+ if ( (int) $q['monthnum'] ) {
+ $q['monthnum'] = '' . intval($q['monthnum']);
+ $where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'";
+ }
+
+ if ( (int) $q['day'] ) {
+ $q['day'] = '' . intval($q['day']);
+ $where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'";
+ }
+
+ // Compat. Map subpost to attachment.
+ if ( '' != $q['subpost'] )
+ $q['attachment'] = $q['subpost'];
+ if ( '' != $q['subpost_id'] )
+ $q['attachment_id'] = $q['subpost_id'];
+
+ if ('' != $q['name']) {
+ $q['name'] = sanitize_title($q['name']);
+ $where .= " AND post_name = '" . $q['name'] . "'";
+ } else if ('' != $q['pagename']) {
+ $reqpage = get_page_by_path($q['pagename']);
+ if ( !empty($reqpage) )
+ $reqpage = $reqpage->ID;
+ else
+ $reqpage = 0;
+
+ if ( ('page' == get_option('show_on_front') ) && ( $reqpage == get_option('page_for_posts') ) ) {
+ $this->is_page = false;
+ $this->is_home = true;
+ } else {
+ $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
+ $page_paths = '/' . trim($q['pagename'], '/');
+ $q['pagename'] = sanitize_title(basename($page_paths));
+ $q['name'] = $q['pagename'];
+ $where .= " AND (ID = '$reqpage')";
+ }
+ } elseif ('' != $q['attachment']) {
+ $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment'])));
+ $attach_paths = '/' . trim($q['attachment'], '/');
+ $q['attachment'] = sanitize_title(basename($attach_paths));
+ $q['name'] = $q['attachment'];
+ $where .= " AND post_name = '" . $q['attachment'] . "'";
+ }
+
+ if ( (int) $q['w'] ) {
+ $q['w'] = ''.intval($q['w']);
+ $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'";
+ }
+
+ if ( intval($q['comments_popup']) )
+ $q['p'] = intval($q['comments_popup']);
+
+ // If a attachment is requested by number, let it supercede any post number.
+ if ( ($q['attachment_id'] != '') && (intval($q['attachment_id']) != 0) )
+ $q['p'] = (int) $q['attachment_id'];
+
+ // If a post number is specified, load that post
+ if (($q['p'] != '') && intval($q['p']) != 0) {
+ $q['p'] = (int) $q['p'];
+ $where = ' AND ID = ' . $q['p'];
+ }
+
+ if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) {
+ $q['page_id'] = intval($q['page_id']);
+ if ( ('page' == get_option('show_on_front') ) && ( $q['page_id'] == get_option('page_for_posts') ) ) {
+ $this->is_page = false;
+ $this->is_home = true;
+ } else {
+ $q['p'] = $q['page_id'];
+ $where = ' AND ID = '.$q['page_id'];
+ }
+ }
+
+ // If a search pattern is specified, load the posts that match
+ if (!empty($q['s'])) {
+ $q['s'] = addslashes_gpc($q['s']);
+ $search = ' AND (';
+ $q['s'] = preg_replace('/, +/', ' ', $q['s']);
+ $q['s'] = str_replace(',', ' ', $q['s']);
+ $q['s'] = str_replace('"', ' ', $q['s']);
+ $q['s'] = trim($q['s']);
+ if ($q['exact']) {
+ $n = '';
+ } else {
+ $n = '%';
+ }
+ if (!$q['sentence']) {
+ $s_array = explode(' ',$q['s']);
+ $q['search_terms'] = $s_array;
+ $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
+ for ( $i = 1; $i < count($s_array); $i = $i + 1) {
+ $search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
+ }
+ $search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')';
+ $search .= ')';
+ } else {
+ $search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))';
+ }
+ }
+
+ // Category stuff
+
+ if ((empty($q['cat'])) || ($q['cat'] == '0') ||
+ // Bypass cat checks if fetching specific posts
+ ( $this->is_single || $this->is_page )) {
+ $whichcat='';
+ } else {
+ $q['cat'] = ''.urldecode($q['cat']).'';
+ $q['cat'] = addslashes_gpc($q['cat']);
+ if (stristr($q['cat'],'-')) {
+ // Note: if we have a negative, we ignore all the positives. It must
+ // always mean 'everything /except/ this one'. We should be able to do
+ // multiple negatives but we don't :-(
+ $eq = '!=';
+ $andor = 'AND';
+ $q['cat'] = explode('-',$q['cat']);
+ $q['cat'] = intval($q['cat'][1]);
+ } else {
+ $eq = '=';
+ $andor = 'OR';
+ }
+ $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
+ $cat_array = preg_split('/[,\s]+/', $q['cat']);
+ $whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]);
+ $whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
+ for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
+ $whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
+ $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
+ }
+ $whichcat .= ')';
+ if ($eq == '!=') {
+ $q['cat'] = '-'.$q['cat']; // Put back the knowledge that we are excluding a category.
+ }
+ }
+
+ // Category stuff for nice URIs
+
+ global $cache_categories;
+ if ('' != $q['category_name']) {
+ $reqcat = get_category_by_path($q['category_name']);
+ $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
+ $cat_paths = '/' . trim($q['category_name'], '/');
+ $q['category_name'] = sanitize_title(basename($cat_paths));
+
+ $cat_paths = '/' . trim(urldecode($q['category_name']), '/');
+ $q['category_name'] = sanitize_title(basename($cat_paths));
+ $cat_paths = explode('/', $cat_paths);
+ foreach($cat_paths as $pathdir)
+ $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
+
+ //if we don't match the entire hierarchy fallback on just matching the nicename
+ if ( empty($reqcat) )
+ $reqcat = get_category_by_path($q['category_name'], false);
+
+ if ( !empty($reqcat) )
+ $reqcat = $reqcat->cat_ID;
+ else
+ $reqcat = 0;
+
+ $q['cat'] = $reqcat;
+
+ $tables = ", $wpdb->post2cat, $wpdb->categories";
+ $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";
+ $whichcat = " AND (category_id = '" . $q['cat'] . "'";
+ $whichcat .= get_category_children($q['cat'], " OR category_id = ");
+ $whichcat .= ")";
+ }
+
+ // Author/user stuff
+
+ if ((empty($q['author'])) || ($q['author'] == '0')) {
+ $whichauthor='';
+ } else {
+ $q['author'] = ''.urldecode($q['author']).'';
+ $q['author'] = addslashes_gpc($q['author']);
+ if (stristr($q['author'], '-')) {
+ $eq = '!=';
+ $andor = 'AND';
+ $q['author'] = explode('-', $q['author']);
+ $q['author'] = ''.intval($q['author'][1]);
+ } else {
+ $eq = '=';
+ $andor = 'OR';
+ }
+ $author_array = preg_split('/[,\s]+/', $q['author']);
+ $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);
+ for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
+ $whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);
+ }
+ $whichauthor .= ')';
+ }
+
+ // Author stuff for nice URIs
+
+ if ('' != $q['author_name']) {
+ if (stristr($q['author_name'],'/')) {
+ $q['author_name'] = explode('/',$q['author_name']);
+ if ($q['author_name'][count($q['author_name'])-1]) {
+ $q['author_name'] = $q['author_name'][count($q['author_name'])-1];#no trailing slash
+ } else {
+ $q['author_name'] = $q['author_name'][count($q['author_name'])-2];#there was a trailling slash
+ }
+ }
+ $q['author_name'] = sanitize_title($q['author_name']);
+ $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'");
+ $whichauthor .= ' AND (post_author = '.intval($q['author']).')';
+ }
+
+ $where .= $search.$whichcat.$whichauthor;
+
+ if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) {
+ $q['order']='DESC';
+ }
+
+ // Order by
+ if (empty($q['orderby'])) {
+ $q['orderby'] = 'post_date '.$q['order'];
+ } else {
+ // Used to filter values
+ $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order');
+ $q['orderby'] = urldecode($q['orderby']);
+ $q['orderby'] = addslashes_gpc($q['orderby']);
+ $orderby_array = explode(' ',$q['orderby']);
+ if ( empty($orderby_array) )
+ $orderby_array[] = $q['orderby'];
+ $q['orderby'] = '';
+ for ($i = 0; $i < count($orderby_array); $i++) {
+ // Only allow certain values for safety
+ $orderby = $orderby_array[$i];
+ if ( 'menu_order' != $orderby )
+ $orderby = 'post_' . $orderby;
+ if ( in_array($orderby_array[$i], $allowed_keys) )
+ $q['orderby'] .= (($i == 0) ? '' : ',') . "$orderby {$q['order']}";
+ }
+ if ( empty($q['orderby']) )
+ $q['orderby'] = 'post_date '.$q['order'];
+ }
+
+ if ( $this->is_attachment ) {
+ $where .= ' AND (post_type = "attachment")';
+ } elseif ($this->is_page) {
+ $where .= ' AND (post_type = "page")';
+ } elseif ($this->is_single) {
+ $where .= ' AND (post_type = "post")';
+ } else {
+ $where .= " AND (post_type = '$post_type' AND (post_status = 'publish'";
+
+ if ( is_admin() )
+ $where .= " OR post_status = 'future' OR post_status = 'draft'";
+
+ if ( is_user_logged_in() )
+ $where .= " OR post_author = $user_ID AND post_status = 'private'))";
+ else
+ $where .= '))';
+ }
+
+ // Apply filters on where and join prior to paging so that any
+ // manipulations to them are reflected in the paging by day queries.
+ $where = apply_filters('posts_where', $where);
+ $join = apply_filters('posts_join', $join);
+
+ // Paging
+ if (empty($q['nopaging']) && ! $this->is_single && ! $this->is_page) {
+ $page = $q['paged'];
+ if (empty($page)) {
+ $page = 1;
+ }
+
+ if (($q['what_to_show'] == 'posts')) {
+ $pgstrt = '';
+ $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
+ $limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
+ } elseif ($q['what_to_show'] == 'days') {
+ $startrow = $q['posts_per_page'] * (intval($page)-1);
+ $start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1");
+ $endrow = $startrow + $q['posts_per_page'] - 1;
+ $end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1");
+
+ if ($page > 1) {
+ $where .= " AND post_date >= '$end_date' AND post_date <= '$start_date'";
+ } else {
+ $where .= " AND post_date >= '$end_date'";
+ }
+ }
+ }
+
+ // Apply post-paging filters on where and join. Only plugins that
+ // manipulate paging queries should use these hooks.
+ $where = apply_filters('posts_where_paged', $where);
+ $groupby = '';
+ $groupby = apply_filters('posts_groupby', $groupby);
+ if ( ! empty($groupby) )
+ $groupby = 'GROUP BY ' . $groupby;
+ $join = apply_filters('posts_join_paged', $join);
+ $orderby = apply_filters('posts_orderby', $q['orderby']);
+ $request = " SELECT * FROM $wpdb->posts $join WHERE 1=1 $where $groupby ORDER BY $orderby $limits";
+ $this->request = apply_filters('posts_request', $request);
+
+ $this->posts = $wpdb->get_results($this->request);
+
+ // Check post status to determine if post should be displayed.
+ if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
+ $status = get_post_status($this->posts[0]);
+ //$type = get_post_type($this->posts[0]);
+ if ( ('publish' != $status) ) {
+ if ( ! is_user_logged_in() ) {
+ // User must be logged in to view unpublished posts.
+ $this->posts = array();
+ } else {
+ if ('draft' == $status) {
+ // User must have edit permissions on the draft to preview.
+ if (! current_user_can('edit_post', $this->posts[0]->ID)) {
+ $this->posts = array();
+ } else {
+ $this->is_preview = true;
+ $this->posts[0]->post_date = current_time('mysql');
+ }
+ } else if ('future' == $status) {
+ $this->is_preview = true;
+ if (!current_user_can('edit_post', $this->posts[0]->ID)) {
+ $this->posts = array ( );
+ }
+ } else {
+ if (! current_user_can('read_post', $this->posts[0]->ID))
+ $this->posts = array();
+ }
+ }
+ }
+ }
+
+ update_post_caches($this->posts);
+
+ $this->posts = apply_filters('the_posts', $this->posts);
+ $this->post_count = count($this->posts);
+ if ($this->post_count > 0) {
+ $this->post = $this->posts[0];
+ }
+
+ return $this->posts;
+ }
+
+ function next_post() {
+
+ $this->current_post++;
+
+ $this->post = $this->posts[$this->current_post];
+ return $this->post;
+ }
+
+ function the_post() {
+ global $post;
+ $this->in_the_loop = true;
+ $post = $this->next_post();
+ setup_postdata($post);
+
+ if ( $this->current_post == 0 ) // loop has just started
+ do_action('loop_start');
+ }
+
+ function have_posts() {
+ if ($this->current_post + 1 < $this->post_count) {
+ return true;
+ } elseif ($this->current_post + 1 == $this->post_count) {
+ do_action('loop_end');
+ // Do some cleaning up after the loop
+ $this->rewind_posts();
+ }
+
+ $this->in_the_loop = false;
+ return false;
+ }
+
+ function rewind_posts() {
+ $this->current_post = -1;
+ if ($this->post_count > 0) {
+ $this->post = $this->posts[0];
+ }
+ }
+
+ function &query($query) {
+ $this->parse_query($query);
+ return $this->get_posts();
+ }
+
+ function get_queried_object() {
+ if (isset($this->queried_object)) {
+ return $this->queried_object;
+ }
+
+ $this->queried_object = NULL;
+ $this->queried_object_id = 0;
+
+ if ($this->is_category) {
+ $cat = $this->get('cat');
+ $category = &get_category($cat);
+ $this->queried_object = &$category;
+ $this->queried_object_id = $cat;
+ } else if ($this->is_single) {
+ $this->queried_object = $this->post;
+ $this->queried_object_id = $this->post->ID;
+ } else if ($this->is_page) {
+ $this->queried_object = $this->post;
+ $this->queried_object_id = $this->post->ID;
+ } else if ($this->is_author) {
+ $author_id = $this->get('author');
+ $author = get_userdata($author_id);
+ $this->queried_object = $author;
+ $this->queried_object_id = $author_id;
+ }
+
+ return $this->queried_object;
+ }
+
+ function get_queried_object_id() {
+ $this->get_queried_object();
+
+ if (isset($this->queried_object_id)) {
+ return $this->queried_object_id;
+ }
+
+ return 0;
+ }
+
+ function WP_Query ($query = '') {
+ if (! empty($query)) {
+ $this->query($query);
+ }
+ }
+}
+
+?>
diff --git a/wp-inst/wp-includes/rewrite.php b/wp-inst/wp-includes/rewrite.php
new file mode 100644
index 0000000..921a256
--- /dev/null
+++ b/wp-inst/wp-includes/rewrite.php
@@ -0,0 +1,803 @@
+<?php
+
+/* WP_Rewrite API
+*******************************************************************************/
+
+//Add a straight rewrite rule
+function add_rewrite_rule($regex, $redirect) {
+ global $wp_rewrite;
+ $wp_rewrite->add_rule($regex, $redirect);
+}
+
+//Add a new tag (like %postname%)
+//warning: you must call this on init or earlier, otherwise the query var addition stuff won't work
+function add_rewrite_tag($tagname, $regex) {
+ //validation
+ if (strlen($tagname) < 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%') {
+ return;
+ }
+
+ $qv = trim($tagname, '%');
+
+ global $wp_rewrite, $wp;
+ $wp->add_query_var($qv);
+ $wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '=');
+}
+
+//Add a new feed type like /atom1/
+function add_feed($feedname, $function) {
+ global $wp_rewrite;
+ if (!in_array($feedname, $wp_rewrite->feeds)) { //override the file if it is
+ $wp_rewrite->feeds[] = $feedname;
+ }
+ $hook = 'do_feed_' . $feedname;
+ remove_action($hook, $function, 10, 1);
+ add_action($hook, $function, 10, 1);
+ return $hook;
+}
+
+define('EP_PERMALINK', 1 );
+define('EP_ATTACHMENT', 2 );
+define('EP_DATE', 4 );
+define('EP_YEAR', 8 );
+define('EP_MONTH', 16 );
+define('EP_DAY', 32 );
+define('EP_ROOT', 64 );
+define('EP_COMMENTS', 128 );
+define('EP_SEARCH', 256 );
+define('EP_CATEGORIES', 512 );
+define('EP_AUTHORS', 1024);
+define('EP_PAGES', 2048);
+//pseudo-places
+define('EP_NONE', 0 );
+define('EP_ALL', 255);
+
+//and an endpoint, like /trackback/
+function add_rewrite_endpoint($name, $places) {
+ global $wp_rewrite;
+ $wp_rewrite->add_endpoint($name, $places);
+}
+
+/* WP_Rewrite class
+*******************************************************************************/
+
+class WP_Rewrite {
+ var $permalink_structure;
+ var $category_base;
+ var $category_structure;
+ var $author_base = 'author';
+ var $author_structure;
+ var $date_structure;
+ var $page_structure;
+ var $search_base = 'search';
+ var $search_structure;
+ var $comments_base = 'comments';
+ var $feed_base = 'feed';
+ var $comments_feed_structure;
+ var $feed_structure;
+ var $front;
+ var $root = '';
+ var $index = 'index.php';
+ var $matches = '';
+ var $rules;
+ var $extra_rules; //those not generated by the class, see add_rewrite_rule()
+ var $non_wp_rules; //rules that don't redirect to WP's index.php
+ var $endpoints;
+ var $use_verbose_rules = false;
+ var $rewritecode =
+ array(
+ '%year%',
+ '%monthnum%',
+ '%day%',
+ '%hour%',
+ '%minute%',
+ '%second%',
+ '%postname%',
+ '%post_id%',
+ '%category%',
+ '%author%',
+ '%pagename%',
+ '%search%'
+ );
+
+ var $rewritereplace =
+ array(
+ '([0-9]{4})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([^/]+)',
+ '([0-9]+)',
+ '(.+?)',
+ '([^/]+)',
+ '([^/]+)',
+ '(.+)'
+ );
+
+ var $queryreplace =
+ array (
+ 'year=',
+ 'monthnum=',
+ 'day=',
+ 'hour=',
+ 'minute=',
+ 'second=',
+ 'name=',
+ 'p=',
+ 'category_name=',
+ 'author_name=',
+ 'pagename=',
+ 's='
+ );
+
+ var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
+
+ function using_permalinks() {
+ if (empty($this->permalink_structure))
+ return false;
+ else
+ return true;
+ }
+
+ function using_index_permalinks() {
+ if (empty($this->permalink_structure)) {
+ return false;
+ }
+
+ // If the index is not in the permalink, we're using mod_rewrite.
+ if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ function using_mod_rewrite_permalinks() {
+ if ( $this->using_permalinks() && ! $this->using_index_permalinks())
+ return true;
+ else
+ return false;
+ }
+
+ function preg_index($number) {
+ $match_prefix = '$';
+ $match_suffix = '';
+
+ if (! empty($this->matches)) {
+ $match_prefix = '$' . $this->matches . '[';
+ $match_suffix = ']';
+ }
+
+ return "$match_prefix$number$match_suffix";
+ }
+
+ function page_rewrite_rules() {
+ $uris = get_settings('page_uris');
+ $attachment_uris = get_settings('page_attachment_uris');
+
+ $rewrite_rules = array();
+ $page_structure = $this->get_page_permastruct();
+ if( is_array( $attachment_uris ) ) {
+ foreach ($attachment_uris as $uri => $pagename) {
+ $this->add_rewrite_tag('%pagename%', "($uri)", 'attachment=');
+ $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
+ }
+ }
+ if( is_array( $uris ) ) {
+ foreach ($uris as $uri => $pagename) {
+ $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
+ $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
+ }
+ }
+
+ return $rewrite_rules;
+ }
+
+ function get_date_permastruct() {
+ if (isset($this->date_structure)) {
+ return $this->date_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->date_structure = '';
+ return false;
+ }
+
+ // The date permalink must have year, month, and day separated by slashes.
+ $endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%');
+
+ $this->date_structure = '';
+ $date_endian = '';
+
+ foreach ($endians as $endian) {
+ if (false !== strpos($this->permalink_structure, $endian)) {
+ $date_endian= $endian;
+ break;
+ }
+ }
+
+ if ( empty($date_endian) )
+ $date_endian = '%year%/%monthnum%/%day%';
+
+ // Do not allow the date tags and %post_id% to overlap in the permalink
+ // structure. If they do, move the date tags to $front/date/.
+ $front = $this->front;
+ preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
+ $tok_index = 1;
+ foreach ($tokens[0] as $token) {
+ if ( ($token == '%post_id%') && ($tok_index <= 3) ) {
+ $front = $front . 'date/';
+ break;
+ }
+ }
+
+ $this->date_structure = $front . $date_endian;
+
+ return $this->date_structure;
+ }
+
+ function get_year_permastruct() {
+ $structure = $this->get_date_permastruct($this->permalink_structure);
+
+ if (empty($structure)) {
+ return false;
+ }
+
+ $structure = str_replace('%monthnum%', '', $structure);
+ $structure = str_replace('%day%', '', $structure);
+
+ $structure = preg_replace('#/+#', '/', $structure);
+
+ return $structure;
+ }
+
+ function get_month_permastruct() {
+ $structure = $this->get_date_permastruct($this->permalink_structure);
+
+ if (empty($structure)) {
+ return false;
+ }
+
+ $structure = str_replace('%day%', '', $structure);
+
+ $structure = preg_replace('#/+#', '/', $structure);
+
+ return $structure;
+ }
+
+ function get_day_permastruct() {
+ return $this->get_date_permastruct($this->permalink_structure);
+ }
+
+ function get_category_permastruct() {
+ if (isset($this->category_structure)) {
+ return $this->category_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->category_structure = '';
+ return false;
+ }
+
+ if (empty($this->category_base))
+ $this->category_structure = $this->front . 'category/';
+ else
+ $this->category_structure = $this->category_base . '/';
+
+ $this->category_structure .= '%category%';
+
+ return $this->category_structure;
+ }
+
+ function get_author_permastruct() {
+ if (isset($this->author_structure)) {
+ return $this->author_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->author_structure = '';
+ return false;
+ }
+
+ $this->author_structure = $this->front . $this->author_base . '/%author%';
+
+ return $this->author_structure;
+ }
+
+ function get_search_permastruct() {
+ if (isset($this->search_structure)) {
+ return $this->search_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->search_structure = '';
+ return false;
+ }
+
+ $this->search_structure = $this->root . $this->search_base . '/%search%';
+
+ return $this->search_structure;
+ }
+
+ function get_page_permastruct() {
+ if (isset($this->page_structure)) {
+ return $this->page_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->page_structure = '';
+ return false;
+ }
+
+ $this->page_structure = $this->root . '%pagename%';
+
+ return $this->page_structure;
+ }
+
+ function get_feed_permastruct() {
+ if (isset($this->feed_structure)) {
+ return $this->feed_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->feed_structure = '';
+ return false;
+ }
+
+ $this->feed_structure = $this->root . $this->feed_base . '/%feed%';
+
+ return $this->feed_structure;
+ }
+
+ function get_comment_feed_permastruct() {
+ if (isset($this->comment_feed_structure)) {
+ return $this->comment_feed_structure;
+ }
+
+ if (empty($this->permalink_structure)) {
+ $this->comment_feed_structure = '';
+ return false;
+ }
+
+ $this->comment_feed_structure = $this->root . $this->comments_base . '/' . $this->feed_base . '/%feed%';
+
+ return $this->comment_feed_structure;
+ }
+
+ function add_rewrite_tag($tag, $pattern, $query) {
+ // If the tag already exists, replace the existing pattern and query for
+ // that tag, otherwise add the new tag, pattern, and query to the end of
+ // the arrays.
+ $position = array_search($tag, $this->rewritecode);
+ if (FALSE !== $position && NULL !== $position) {
+ $this->rewritereplace[$position] = $pattern;
+ $this->queryreplace[$position] = $query;
+ } else {
+ $this->rewritecode[] = $tag;
+ $this->rewritereplace[] = $pattern;
+ $this->queryreplace[] = $query;
+ }
+ }
+
+ //the main WP_Rewrite function. generate the rules from permalink structure
+ function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
+ //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
+ $feedregex2 = '';
+ foreach ($this->feeds as $feed_name) {
+ $feedregex2 .= $feed_name . '|';
+ }
+ $feedregex2 = '(' . trim($feedregex2, '|') . ')/?$';
+ //$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
+ //and <permalink>/atom are both possible
+ $feedregex = $this->feed_base . '/' . $feedregex2;
+
+ //build a regex to match the trackback and page/xx parts of URLs
+ $trackbackregex = 'trackback/?$';
+ $pageregex = 'page/?([0-9]{1,})/?$';
+
+ //build up an array of endpoint regexes to append => queries to append
+ if ($endpoints) {
+ $ep_query_append = array ();
+ foreach ($this->endpoints as $endpoint) {
+ //match everything after the endpoint name, but allow for nothing to appear there
+ $epmatch = $endpoint[1] . '(/(.*))?/?$';
+ //this will be appended on to the rest of the query for each dir
+ $epquery = '&' . $endpoint[1] . '=';
+ $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
+ }
+ }
+
+ //get everything up to the first rewrite tag
+ $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
+ //build an array of the tags (note that said array ends up being in $tokens[0])
+ preg_match_all('/%.+?%/', $permalink_structure, $tokens);
+
+ $num_tokens = count($tokens[0]);
+
+ $index = $this->index; //probably 'index.php'
+ $feedindex = $index;
+ $trackbackindex = $index;
+ //build a list from the rewritecode and queryreplace arrays, that will look something like
+ //tagname=$matches[i] where i is the current $i
+ for ($i = 0; $i < $num_tokens; ++$i) {
+ if (0 < $i) {
+ $queries[$i] = $queries[$i - 1] . '&';
+ }
+
+ $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
+ $queries[$i] .= $query_token;
+ }
+
+ //get the structure, minus any cruft (stuff that isn't tags) at the front
+ $structure = $permalink_structure;
+ if ($front != '/') {
+ $structure = str_replace($front, '', $structure);
+ }
+ //create a list of dirs to walk over, making rewrite rules for each level
+ //so for example, a $structure of /%year%/%month%/%postname% would create
+ //rewrite rules for /%year%/, /%year%/%month%/ and /%year%/%month%/%postname%
+ $structure = trim($structure, '/');
+ if ($walk_dirs) {
+ $dirs = explode('/', $structure);
+ } else {
+ $dirs[] = $structure;
+ }
+ $num_dirs = count($dirs);
+
+ //strip slashes from the front of $front
+ $front = preg_replace('|^/+|', '', $front);
+
+ //the main workhorse loop
+ $post_rewrite = array();
+ $struct = $front;
+ for ($j = 0; $j < $num_dirs; ++$j) {
+ //get the struct for this dir, and trim slashes off the front
+ $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
+ $struct = ltrim($struct, '/');
+ //replace tags with regexes
+ $match = str_replace($this->rewritecode, $this->rewritereplace, $struct);
+ //make a list of tags, and store how many there are in $num_toks
+ $num_toks = preg_match_all('/%.+?%/', $struct, $toks);
+ //get the 'tagname=$matches[i]'
+ $query = $queries[$num_toks - 1];
+
+ //set up $ep_mask_specific which is used to match more specific URL types
+ switch ($dirs[$j]) {
+ case '%year%': $ep_mask_specific = EP_YEAR; break;
+ case '%monthnum%': $ep_mask_specific = EP_MONTH; break;
+ case '%day%': $ep_mask_specific = EP_DAY; break;
+ }
+
+ //create query for /page/xx
+ $pagematch = $match . $pageregex;
+ $pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1);
+
+ //create query for /feed/(feed|atom|rss|rss2|rdf)
+ $feedmatch = $match . $feedregex;
+ $feedquery = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
+
+ //create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex)
+ $feedmatch2 = $match . $feedregex2;
+ $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
+
+ //if asked to, turn the feed queries into comment feed ones
+ if ($forcomments) {
+ $feedquery .= '&withcomments=1';
+ $feedquery2 .= '&withcomments=1';
+ }
+
+ //start creating the array of rewrites for this dir
+ $rewrite = array();
+ if ($feed) //...adding on /feed/ regexes => queries
+ $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2);
+ if ($paged) //...and /page/xx ones
+ $rewrite = array_merge($rewrite, array($pagematch => $pagequery));
+
+ //if we've got some tags in this dir
+ if ($num_toks) {
+ $post = false;
+ $page = false;
+
+ //check to see if this dir is permalink-level: i.e. the structure specifies an
+ //individual post. Do this by checking it contains at least one of 1) post name,
+ //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
+ //minute all present). Set these flags now as we need them for the endpoints.
+ if (strstr($struct, '%postname%') || strstr($struct, '%post_id%')
+ || strstr($struct, '%pagename%')
+ || (strstr($struct, '%year%') && strstr($struct, '%monthnum%') && strstr($struct, '%day%') && strstr($struct, '%hour%') && strstr($struct, '%minute') && strstr($struct, '%second%'))) {
+ $post = true;
+ if ( strstr($struct, '%pagename%') )
+ $page = true;
+ }
+
+ //do endpoints
+ if ($endpoints) {
+ foreach ($ep_query_append as $regex => $ep) {
+ //add the endpoints on if the mask fits
+ if ($ep[0] & $ep_mask || $ep[0] & $ep_mask_specific) {
+ $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
+ }
+ }
+ }
+
+ //if we're creating rules for a permalink, do all the endpoints like attachments etc
+ if ($post) {
+ $post = true;
+ //create query and regex for trackback
+ $trackbackmatch = $match . $trackbackregex;
+ $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
+ //trim slashes from the end of the regex for this dir
+ $match = rtrim($match, '/');
+ //get rid of brackets
+ $submatchbase = str_replace(array('(',')'),'',$match);
+
+ //add a rule for at attachments, which take the form of <permalink>/some-text
+ $sub1 = $submatchbase . '/([^/]+)/';
+ $sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/...
+ $sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...)
+ $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...)
+ //add an ? as we don't have to match that last slash, and finally a $ so we
+ //match to the end of the URL
+
+ //add another rule to match attachments in the explicit form:
+ //<permalink>/attachment/some-text
+ $sub2 = $submatchbase . '/attachment/([^/]+)/';
+ $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback
+ $sub2feed = $sub2 . $feedregex; //feeds, <permalink>/attachment/feed/(atom|...)
+ $sub2feed2 = $sub2 . $feedregex2; //and feeds again on to this <permalink>/attachment/(feed|atom...)
+
+ //create queries for these extra tag-ons we've just dealt with
+ $subquery = $index . '?attachment=' . $this->preg_index(1);
+ $subtbquery = $subquery . '&tb=1';
+ $subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
+
+ //do endpoints for attachments
+ if ($endpoint) { foreach ($ep_query_append as $regex => $ep) {
+ if ($ep[0] & EP_ATTACHMENT) {
+ $rewrite[$sub1 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
+ $rewrite[$sub2 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
+ }
+ } }
+
+ //now we've finished with endpoints, finish off the $sub1 and $sub2 matches
+ $sub1 .= '?$';
+ $sub2 .= '?$';
+
+ //allow URLs like <permalink>/2 for <permalink>/page/2
+ $match = $match . '(/[0-9]+)?/?$';
+ $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
+ } else { //not matching a permalink so this is a lot simpler
+ //close the match and finalise the query
+ $match .= '?$';
+ $query = $index . '?' . $query;
+ }
+
+ //create the final array for this dir by joining the $rewrite array (which currently
+ //only contains rules/queries for trackback, pages etc) to the main regex/query for
+ //this dir
+ $rewrite = array_merge($rewrite, array($match => $query));
+
+ //if we're matching a permalink, add those extras (attachments etc) on
+ if ($post) {
+ //add trackback
+ $rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite);
+
+ //add regexes/queries for attachments, attachment trackbacks and so on
+ if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages
+ $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery));
+ $rewrite = array_merge($rewrite, array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery));
+ }
+ } //if($num_toks)
+ //add the rules for this dir to the accumulating $post_rewrite
+ $post_rewrite = array_merge($rewrite, $post_rewrite);
+ } //foreach ($dir)
+ return $post_rewrite; //the finished rules. phew!
+ }
+
+ function generate_rewrite_rule($permalink_structure, $walk_dirs = false) {
+ return $this->generate_rewrite_rules($permalink_structure, EP_NONE, false, false, false, $walk_dirs);
+ }
+
+ /* rewrite_rules
+ * Construct rewrite matches and queries from permalink structure.
+ * Returns an associate array of matches and queries.
+ */
+ function rewrite_rules() {
+ $rewrite = array();
+
+ if (empty($this->permalink_structure)) {
+ return $rewrite;
+ }
+
+ // Post
+ $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK);
+ $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite);
+
+ // Date
+ $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
+ $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite);
+
+ // Root
+ $root_rewrite = $this->generate_rewrite_rules($this->root . '/', EP_ROOT);
+ $root_rewrite = apply_filters('root_rewrite_rules', $root_rewrite);
+
+ // Comments
+ $comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, EP_COMMENTS, true, true, true, false);
+ $comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite);
+
+ // Search
+ $search_structure = $this->get_search_permastruct();
+ $search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);
+ $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
+
+ // Categories
+ $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);
+ $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);
+
+ // Authors
+ $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
+ $author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite);
+
+ // Pages
+ $page_rewrite = $this->page_rewrite_rules();
+ $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
+
+ // Put them together.
+ $this->rules = array_merge($page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
+
+ do_action('generate_rewrite_rules', array(&$this));
+ $this->rules = apply_filters('rewrite_rules_array', $this->rules);
+
+ return $this->rules;
+ }
+
+ function wp_rewrite_rules() {
+ $this->rules = get_option('rewrite_rules');
+ if ( empty($this->rules) ) {
+ $this->matches = 'matches';
+ $this->rewrite_rules();
+ update_option('rewrite_rules', $this->rules);
+ }
+
+ return $this->rules;
+ }
+
+ function mod_rewrite_rules() {
+ if ( ! $this->using_permalinks()) {
+ return '';
+ }
+
+ $site_root = parse_url(get_settings('siteurl'));
+ $site_root = trailingslashit($site_root['path']);
+
+ $home_root = parse_url(get_settings('home'));
+ $home_root = trailingslashit($home_root['path']);
+
+ $rules = "<IfModule mod_rewrite.c>\n";
+ $rules .= "RewriteEngine On\n";
+ $rules .= "RewriteBase $home_root\n";
+
+ //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
+ foreach ($this->non_wp_rules as $match => $query) {
+ // Apache 1.3 does not support the reluctant (non-greedy) modifier.
+ $match = str_replace('.+?', '.+', $match);
+
+ // If the match is unanchored and greedy, prepend rewrite conditions
+ // to avoid infinite redirects and eclipsing of real files.
+ if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
+ //nada.
+ }
+
+ $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
+ }
+
+ if ($this->use_verbose_rules) {
+ $this->matches = '';
+ $rewrite = $this->rewrite_rules();
+ $num_rules = count($rewrite);
+ $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
+ "RewriteCond %{REQUEST_FILENAME} -d\n" .
+ "RewriteRule ^.*$ - [S=$num_rules]\n";
+
+ foreach ($rewrite as $match => $query) {
+ // Apache 1.3 does not support the reluctant (non-greedy) modifier.
+ $match = str_replace('.+?', '.+', $match);
+
+ // If the match is unanchored and greedy, prepend rewrite conditions
+ // to avoid infinite redirects and eclipsing of real files.
+ if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
+ //nada.
+ }
+
+ if (strstr($query, $this->index)) {
+ $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
+ } else {
+ $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n";
+ }
+ }
+ } else {
+ $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" .
+ "RewriteCond %{REQUEST_FILENAME} !-d\n" .
+ "RewriteRule . {$home_root}{$this->index} [L]\n";
+ }
+
+ $rules .= "</IfModule>\n";
+
+ $rules = apply_filters('mod_rewrite_rules', $rules);
+ $rules = apply_filters('rewrite_rules', $rules); // Deprecated
+
+ return $rules;
+ }
+
+ //Add a straight rewrite rule
+ function add_rule($regex, $redirect) {
+ //get everything up to the first ?
+ $index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?'));
+ $front = substr($redirect, 0, $index);
+ if ($front != $this->index) { //it doesn't redirect to WP's index.php
+ $this->add_external_rule($regex, $redirect);
+ } else {
+ $this->extra_rules[$regex] = $redirect;
+ }
+ }
+
+ //add a rule that doesn't redirect to index.php
+ function add_external_rule($regex, $redirect) {
+ $this->non_wp_rules[$regex] = $redirect;
+ }
+
+ //add an endpoint, like /trackback/, to be inserted after certain URL types (specified in $places)
+ function add_endpoint($name, $places) {
+ global $wp;
+ $this->endpoints[] = array ( $places, $name );
+ $wp->add_query_var($name);
+ }
+
+ function flush_rules() {
+ generate_page_uri_index();
+ delete_option('rewrite_rules');
+ $this->wp_rewrite_rules();
+ if ( function_exists('save_mod_rewrite_rules') )
+ save_mod_rewrite_rules();
+ }
+
+ function init() {
+ $this->extra_rules = $this->non_wp_rules = $this->endpoints = array();
+ $this->permalink_structure = get_settings('permalink_structure');
+ $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%'));
+ $this->root = '';
+ if ($this->using_index_permalinks()) {
+ $this->root = $this->index . '/';
+ }
+ $this->category_base = get_settings('category_base');
+ unset($this->category_structure);
+ unset($this->author_structure);
+ unset($this->date_structure);
+ unset($this->page_structure);
+ unset($this->search_structure);
+ unset($this->feed_structure);
+ unset($this->comment_feed_structure);
+ }
+
+ function set_permalink_structure($permalink_structure) {
+ if ($permalink_structure != $this->permalink_structure) {
+ update_option('permalink_structure', $permalink_structure);
+ $this->init();
+ }
+ }
+
+ function set_category_base($category_base) {
+ if ($category_base != $this->category_base) {
+ update_option('category_base', $category_base);
+ $this->init();
+ }
+ }
+
+ function WP_Rewrite() {
+ $this->init();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/wp-inst/wp-includes/template-functions-bookmarks.php b/wp-inst/wp-includes/template-functions-bookmarks.php
new file mode 100644
index 0000000..3ec3364
--- /dev/null
+++ b/wp-inst/wp-includes/template-functions-bookmarks.php
@@ -0,0 +1,389 @@
+<?php
+
+/** function wp_get_links()
+ ** Gets the links associated with category n.
+ ** Parameters:
+ ** category (no default) - The category to use.
+ ** or:
+ ** a query string
+ **/
+function wp_get_links($args = '') {
+ global $wpdb;
+
+ if ( empty($args) )
+ return;
+
+ if ( false === strpos($args, '=') ) {
+ $cat_id = $args;
+ $args = add_query_arg('category', $cat_id, $args);
+ }
+
+ parse_str($args);
+
+ if (! isset($category)) $category = -1;
+ if (! isset($before)) $before = '';
+ if (! isset($after)) $after = '<br />';
+ if (! isset($between)) $between = ' ';
+ if (! isset($show_images)) $show_images = true;
+ if (! isset($orderby)) $orderby = 'name';
+ if (! isset($show_description)) $show_description = true;
+ if (! isset($show_rating)) $show_rating = false;
+ if (! isset($limit)) $limit = -1;
+ if (! isset($show_updated)) $show_updated = 1;
+ if (! isset($echo)) $echo = true;
+
+ return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);
+} // end wp_get_links
+
+/** function get_links()
+ ** Gets the links associated with category n.
+ ** Parameters:
+ ** category (default -1) - The category to use. If no category supplied
+ ** uses all
+ ** before (default '') - the html to output before the link
+ ** after (default '<br />') - the html to output after the link
+ ** between (default ' ') - the html to output between the link/image
+ ** and its description. Not used if no image or show_images == true
+ ** show_images (default true) - whether to show images (if defined).
+ ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
+ ** 'url', 'description', or 'rating'. Or maybe owner. If you start the
+ ** name with an underscore the order will be reversed.
+ ** You can also specify 'rand' as the order which will return links in a
+ ** random order.
+ ** show_description (default true) - whether to show the description if
+ ** show_images=false/not defined .
+ ** show_rating (default false) - show rating stars/chars
+ ** limit (default -1) - Limit to X entries. If not specified, all entries
+ ** are shown.
+ ** show_updated (default 0) - whether to show last updated timestamp
+ ** echo (default true) - whether to echo the results, or return them instead
+ */
+function get_links($category = -1,
+ $before = '',
+ $after = '<br />',
+ $between = ' ',
+ $show_images = true,
+ $orderby = 'name',
+ $show_description = true,
+ $show_rating = false,
+ $limit = -1,
+ $show_updated = 1,
+ $echo = true) {
+
+ global $wpdb;
+
+ $order = 'ASC';
+ if (substr($orderby, 0, 1) == '_') {
+ $order = 'DESC';
+ $orderby = substr($orderby, 1);
+ }
+
+ if ($category == -1) { //get_bookmarks uses '' to signify all categories
+ $category = '';
+ }
+
+ $results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=$show_updated&limit=$limit");
+
+ if (!$results) {
+ return;
+ }
+
+
+ $output = '';
+
+ foreach ($results as $row) {
+ if (!isset($row->recently_updated)) $row->recently_updated = false;
+ $output .= $before;
+ if ($show_updated && $row->recently_updated) {
+ $output .= get_settings('links_recently_updated_prepend');
+ }
+
+ $the_link = '#';
+ if (!empty($row->link_url))
+ $the_link = wp_specialchars($row->link_url);
+
+ $rel = $row->link_rel;
+ if ($rel != '') {
+ $rel = ' rel="' . $rel . '"';
+ }
+
+ $desc = wp_specialchars($row->link_description, ENT_QUOTES);
+ $name = wp_specialchars($row->link_name, ENT_QUOTES);
+ $title = $desc;
+
+ if ($show_updated) {
+ if (substr($row->link_updated_f, 0, 2) != '00') {
+ $title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('gmt_offset') * 3600)) . ')';
+ }
+ }
+
+ if ('' != $title) {
+ $title = ' title="' . $title . '"';
+ }
+
+ $alt = ' alt="' . $name . '"';
+
+ $target = $row->link_target;
+ if ('' != $target) {
+ $target = ' target="' . $target . '"';
+ }
+
+ $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
+
+ if (($row->link_image != null) && $show_images) {
+ if (strstr($row->link_image, 'http'))
+ $output .= "<img src=\"$row->link_image\" $alt $title />";
+ else // If it's a relative path
+ $output .= "<img src=\"" . get_settings('siteurl') . "$row->link_image\" $alt $title />";
+ } else {
+ $output .= $name;
+ }
+
+ $output .= '</a>';
+
+ if ($show_updated && $row->recently_updated) {
+ $output .= get_settings('links_recently_updated_append');
+ }
+
+ if ($show_description && ($desc != '')) {
+ $output .= $between . $desc;
+ }
+ $output .= "$after\n";
+ } // end while
+
+ if ($echo) {
+ echo $output;
+ } else {
+ return $output;
+ }
+}
+
+function get_linkrating($link) {
+ return apply_filters('link_rating', $link->link_rating);
+}
+
+/** function get_linkcatname()
+ ** Gets the name of category n.
+ ** Parameters: id (default 0) - The category to get. If no category supplied
+ ** uses 0
+ */
+function get_linkcatname($id = 0) {
+ if ( empty($id) )
+ return '';
+
+ $cats = wp_get_link_cats($id);
+
+ if ( empty($cats) || ! is_array($cats) )
+ return '';
+
+ $cat_id = $cats[0]; // Take the first cat.
+
+ $cat = get_category($cat_id);
+ return $cat->cat_name;
+}
+
+/** function links_popup_script()
+ ** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/
+ ** Show the link to the links popup and the number of links
+ ** Parameters:
+ ** text (default Links) - the text of the link
+ ** width (default 400) - the width of the popup window
+ ** height (default 400) - the height of the popup window
+ ** file (default linkspopup.php) - the page to open in the popup window
+ ** count (default true) - the number of links in the db
+ */
+function links_popup_script($text = 'Links', $width=400, $height=400,
+ $file='links.all.php', $count = true) {
+ if ($count == true) {
+ $counts = $wpdb->get_var("SELECT count(*) FROM $wpdb->links");
+ }
+
+ $javascript = "<a href=\"#\" " .
+ " onclick=\"javascript:window.open('$file?popup=1', '_blank', " .
+ "'width=$width,height=$height,scrollbars=yes,status=no'); " .
+ " return false\">";
+ $javascript .= $text;
+
+ if ($count == true) {
+ $javascript .= " ($counts)";
+ }
+
+ $javascript .="</a>\n\n";
+ echo $javascript;
+}
+
+
+/*
+ * function get_links_list()
+ *
+ * added by Dougal
+ *
+ * Output a list of all links, listed by category, using the
+ * settings in $wpdb->linkcategories and output it as a nested
+ * HTML unordered list.
+ *
+ * Parameters:
+ * order (default 'name') - Sort link categories by 'name' or 'id'
+ * hide_if_empty (default true) - Supress listing empty link categories
+ */
+function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
+ $order = strtolower($order);
+
+ // Handle link category sorting
+ $direction = 'ASC';
+ if (substr($order,0,1) == '_') {
+ $direction = 'DESC';
+ $order = substr($order,1);
+ }
+
+ if (!isset($direction)) $direction = '';
+
+ $cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0");
+
+ // Display each category
+ if ($cats) {
+ foreach ($cats as $cat) {
+ // Handle each category.
+
+ // Display the category name
+ echo ' <li id="linkcat-' . $cat->cat_ID . '"><h2>' . $cat->cat_name . "</h2>\n\t<ul>\n";
+ // Call get_links() with all the appropriate params
+ get_links($cat->cat_ID,
+ '<li>',"</li>","\n");
+
+ // Close the last category
+ echo "\n\t</ul>\n</li>\n";
+ }
+ }
+}
+
+function wp_list_bookmarks($args = '') {
+ if ( is_array($args) )
+ $r = &$args;
+ else
+ parse_str($args, $r);
+
+ $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => 0, 'category' => 0,
+ 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' =>1,
+ 'categorize' => 1, 'title_li' => __('Bookmarks'));
+ $r = array_merge($defaults, $r);
+ extract($r);
+
+ // TODO: The rest of it.
+ // If $categorize, group links by category with the category name being the
+ // title of each li, otherwise just list them with title_li as the li title.
+ // If $categorize and $category or $category_name, list links for the given category
+ // with the category name as the title li. If not $categorize, use title_li.
+ // When using each category's name as a title li, use before and after args for specifying
+ // any markup. We don't want to hardcode h2.
+}
+
+function get_bookmarks($args = '') {
+ global $wpdb;
+
+ if ( is_array($args) )
+ $r = &$args;
+ else
+ parse_str($args, $r);
+
+ $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',
+ 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '');
+ $r = array_merge($defaults, $r);
+ extract($r);
+
+ $inclusions = '';
+ if ( !empty($include) ) {
+ $exclude = ''; //ignore exclude, category, and category_name params if using include
+ $category = '';
+ $category_name = '';
+ $inclinks = preg_split('/[\s,]+/',$include);
+ if ( count($inclinks) ) {
+ foreach ( $inclinks as $inclink ) {
+ if (empty($inclusions))
+ $inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';
+ else
+ $inclusions .= ' OR link_id = ' . intval($inclink) . ' ';
+ }
+ }
+ }
+ if (!empty($inclusions))
+ $inclusions .= ')';
+
+ $exclusions = '';
+ if ( !empty($exclude) ) {
+ $exlinks = preg_split('/[\s,]+/',$exclude);
+ if ( count($exlinks) ) {
+ foreach ( $exlinks as $exlink ) {
+ if (empty($exclusions))
+ $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';
+ else
+ $exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';
+ }
+ }
+ }
+ if (!empty($exclusions))
+ $exclusions .= ')';
+
+ if ( ! empty($category_name) ) {
+ if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") )
+ $category = $cat_id;
+ }
+
+ $category_query = '';
+ $join = '';
+ if ( !empty($category) ) {
+ $incategories = preg_split('/[\s,]+/',$category);
+ if ( count($incategories) ) {
+ foreach ( $incategories as $incat ) {
+ if (empty($category_query))
+ $category_query = ' AND ( category_id = ' . intval($incat) . ' ';
+ else
+ $category_query .= ' OR category_id = ' . intval($incat) . ' ';
+ }
+ }
+ }
+ if (!empty($category_query)) {
+ $category_query .= ')';
+ $join = " LEFT JOIN $wpdb->link2cat ON ($wpdb->links.link_id = $wpdb->link2cat.link_id) ";
+ }
+
+ if (get_settings('links_recently_updated_time')) {
+ $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL " . get_settings('links_recently_updated_time') . " MINUTE) >= NOW(), 1,0) as recently_updated ";
+ } else {
+ $recently_updated_test = '';
+ }
+
+ if ($show_updated) {
+ $get_updated = ", UNIX_TIMESTAMP(link_updated) AS link_updated_f ";
+ }
+
+ $orderby = strtolower($orderby);
+ $length = '';
+ switch ($orderby) {
+ case 'length':
+ $length = ", CHAR_LENGTH(link_name) AS length";
+ break;
+ case 'rand':
+ $orderby = 'rand()';
+ break;
+ default:
+ $orderby = "link_" . $orderby;
+ }
+
+ if ( 'link_id' == $orderby )
+ $orderby = "$wpdb->links.link_id";
+
+ $visible = '';
+ if ( $hide_invisible )
+ $visible = "AND link_visible = 'Y'";
+
+ $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";
+ $query .= " $exclusions $inclusions";
+ $query .= " ORDER BY $orderby $order";
+ if ($limit != -1)
+ $query .= " LIMIT $limit";
+
+ $results = $wpdb->get_results($query);
+ return apply_filters('get_bookmarks', $results, $r);
+}
+?> \ No newline at end of file