| [ Index ] |
PHP Cross Reference of zeList |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * zeList Filters and Actions 4 */ 5 6 /** 7 * It's the main hook on WordPress, starting with $wp_query->get_posts() 8 * It tests if any zelist query var is in the request and (if there are) launch zelist_query 9 */ 10 function zelist_pre_get_posts($wp_query) { 11 12 //$debug = true; 13 if(!is_home() && !is_page() && !is_tax() && !isset($wp_query->query_vars['ls'])) 14 return false; 15 16 //global $wp_rewrite; echo '<pre>'.print_r($wp_rewrite,1).'</pre>'; 17 //if($debug) echo '<pre>'.print_r($wp_query,1).'</pre>'; 18 19 20 // not the main query : if you want to get links outside of the main query, use zelist_get_bookmarks() which calls directly zelist_query 21 global $wp_the_query; 22 if($wp_the_query !== $wp_query) { 23 return false; 24 } 25 26 if(is_page()) { // is page but not zelist_root 27 if($debug) echo " is page ! "; 28 $page_id = ($wp_query->query_vars['page_id']) ? $wp_query->query_vars['page_id'] : $wp_query->queried_object->ID; 29 if($debug) echo " > page id $page_id"; 30 31 if($page_id != get_option('zelist_root')) return false; 32 33 } 34 35 $wp_query->query_vars['page_id'] = $zelist_root = get_option('zelist_root'); 36 $wp_query->is_page = 1; 37 38 39 //$page_id = $wp_query->queried_object_id; 40 //if($page_id && $page_id != $zelist_root) return false; 41 42 if(!$page_id) $page_id = get_option('page_on_front'); 43 $taxonomy = get_query_var('taxonomy'); 44 $link_id = get_query_var('link'); 45 $link_name = get_query_var('link_name'); 46 $link_category = get_query_var('link_category'); 47 $link_category_name = get_query_var('link_category_name'); 48 $link_search = get_query_var('ls'); 49 $tag = get_query_var('tag'); 50 51 //$debug = true; 52 //if($debug) echo '<pre>'.print_r($wp_query,1).'</pre>'; 53 54 //if($debug) { global $wp_rewrite; echo '<pre>'.print_r($wp_rewrite,1).'</pre>'; } 55 //if($debug) { global $wp; echo '<pre>'.print_r($wp,1).'</pre>'; } 56 if($debug) echo "<br />zelist root $zelist_root 57 <br />pageid $page_id 58 <br />taxonomy $taxonomy 59 <br />link_id $link_id 60 <br />link name $link_name 61 <br />link_category $link_category 62 <br />link_category_name $link_category_name 63 <br />link_search $link_search 64 "; 65 if($debug && is_page()) echo "<br />\nis page ! "; 66 if($debug && is_home()) echo "<br />\nis home ! "; 67 68 $it_is_links = false; 69 70 if($debug) echo "<br />\ntaxonomy = '$taxonomy '"; 71 72 if( // link 73 $taxonomy && $taxonomy == 'link' 74 || !empty($link_name) 75 || !empty($link_id) 76 ) { 77 if($debug) echo "<br /> >> link ! "; 78 $it_is_links = true; 79 // reset wp query vars to let the wp page load 80 $wp_query->set('taxonomy',''); 81 $wp_query->is_tax = false; 82 $wp_query->set('page_id',$zelist_root); 83 $wp_query->set('post_type','page'); 84 } 85 elseif( // link tag 86 $taxonomy && $taxonomy == 'link_tag' 87 || !empty($link_tag) 88 ) { 89 if($debug) echo "<br /> >> link tag ! "; 90 $it_is_links = true; 91 // reset wp query vars to let the wp page load 92 $wp_query->set('taxonomy',''); 93 $wp_query->is_tax = false; 94 $wp_query->set('page_id',$zelist_root); 95 $wp_query->set('post_type','page'); 96 } 97 elseif( // link category 98 $taxonomy && $taxonomy == 'link_category' // category id 99 || !empty($link_category_name) // rewrited urls 100 ) { 101 if($debug) echo "<br /> >> link category ! "; 102 $it_is_links = true; 103 } 104 elseif(!empty($link_search)) { 105 $it_is_links = true; 106 } 107 elseif($page_id && $page_id == $zelist_root) { // link home 108 if($debug) echo "<br /> >> link home ! "; 109 $it_is_links = true; 110 } 111 112 113 if($it_is_links) { 114 if($debug) echo "\nit is links ! "; 115 it_is_links(); 116 117 // force 404 on wp query to prevent further 404 header 118 $wp_query->is_404 = 1; 119 120 global $zelist_query,$zelist_the_query; 121 $zelist_query = new zelist_query; 122 $zelist_query->query($wp_query->query_vars); 123 if($debug) echo '<pre>'.print_r($zelist_query,1).'</pre>'; 124 125 if( !isset($zelist_the_query) ) $zelist_the_query = $zelist_query; 126 } 127 } 128 add_action('pre_get_posts','zelist_pre_get_posts'); 129 130 /** 131 * zelist hook on init 132 */ 133 function zelist_action_init() { 134 global $wpdb; 135 $wpdb->linkmeta = $wpdb->prefix.'linkmeta'; 136 zelist_add_taxonomies(); 137 zelist_link_capabilities(); 138 load_plugin_textdomain('zelist',false,'zelist'); 139 do_action('zelist_init'); 140 141 142 } 143 add_action('init','zelist_action_init'); 144 145 function zelist_action_wp_head() { 146 do_action('zelist_wp_head'); 147 } 148 add_action('wp_head','zelist_action_wp_head'); 149 150 151 /** 152 * zelist hook on 'wp'. Load fallback content if needed, add scripts 153 * @return unknown_type 154 */ 155 function zelist_hook_wp_head() { 156 // styles and scripts 157 global $post; 158 if(is_page() && $post->ID == get_option('zelist_submit_page')) { 159 if(!file_exists(TEMPLATEPATH . "/submitform.php")) { 160 // we assume that if the webmaster has set a custom submitform.php, he does not want fallback style 161 wp_enqueue_style('zelist_submit_style',WP_PLUGIN_URL.'/zelist/style/submit.css',false,false,'all'); 162 } 163 if(!file_exists(TEMPLATEPATH . "/submit.js")) { 164 wp_enqueue_script('zelist_submit',WP_PLUGIN_URL.'/zelist/js/submit.js',array('jquery','jquery-form','wp-ajax-response'),ZELIST_CURRENT_VERSION); 165 } 166 wp_localize_script('zelist_submit','submitL10n',array( 167 'checking' => __('Checking...','zelist'), 168 'text_category_not_valid' => __('Please choose a valid category','zelist'), 169 'text_email_not_valid' => __('Not a valid email','zelist'), 170 'text_url_not_valid' => __('Not a valid URL','zelist'), 171 'text_name_not_valid' => __('Not a valid name','zelist'), 172 'text_missing_field' => __('Please fill all required fields','zelist'), 173 'regular_submit' => ZELIST_ADMIN_URL_ADD, 174 'ajax_submit' => get_option('home').'/wp-admin/admin-ajax.php', 175 'admin_images' => admin_url('images/'), 176 'l10n_print_after' => 'try{convertEntities(mailL10n);}catch(e){};', 177 )); 178 } 179 180 // admin zelist style 181 if(is_admin()) wp_enqueue_style('zelist-admin',WP_PLUGIN_URL.'/zelist/style/admin.css'); 182 } 183 add_action('wp_head','zelist_hook_wp_head',8); 184 185 /** 186 * Adding localized strings for Javascript usage 187 * @return unknown_type 188 */ 189 function zelist_submit_localize() { 190 if(is_admin()) return; 191 wp_localize_script( 'zelist-submit', 'zelist_submitL10n', array( 192 'checking' => __('Checking...','zelist'), 193 'text_category_not_valid' => __('Please choose a valid category','zelist'), 194 'text_email_not_valid' => __('Not a valid email','zelist'), 195 'text_url_not_valid' => __('Not a valid URL','zelist'), 196 'ajax_submit' => admin_url('admin-ajax.php'), 197 'regular_submit' => ZELIST_ADMIN_URL_ADD, 198 'l10n_print_after' => 'try{convertEntities(mailL10n);}catch(e){};', 199 )); 200 wp_enqueue_script('zelist-submit'); 201 } 202 add_action('wp_print_scripts','zelist_submit_localize'); 203 204 /** 205 * Filters the link edit link 206 * @param $link 207 * @param $link_id 208 * @return unknown_type 209 */ 210 function zelist_get_edit_bookmark_link($link,$link_id = 0) { 211 $link = parse_url($link); 212 $defaults = array('link_id' => false,'action' => 'edit'); 213 $query = wp_parse_args( html_entity_decode($link['query']), $defaults ); 214 extract($query); 215 216 217 $location = add_query_arg('action','edit',ZELIST_ADMIN_URL_LINK); 218 $location = add_query_arg('link_id',$link_id,$location); 219 // $file = 'link-manager.php?page=zelist/admin/link.php'; 220 //$var = 'link_id'; 221 //admin_url("$file&action={$action}&$var=$link_id",$link_id); 222 return $location; 223 } 224 add_filter( 'get_edit_bookmark_link', 'zelist_get_edit_bookmark_link'); 225 226 227 function all_actions() { 228 if(in_array(current_filter(),array('attribute_escape','gettext','sanitize_title',))) return; 229 if(stripos(current_filter(),'option_') !== false) return; 230 // if(current_filter() == 'parse_query') $debug = true; 231 global $debug; 232 $debug = true; 233 //echo "<br />\n".current_filter(); 234 if($debug) { 235 echo "\nfilter = "; 236 var_dump(current_filter()); 237 if(!in_array(current_filter(),array('get_terms','parse_request'))) 238 echo '<pre>ARGS = '.print_r(func_get_args(),1).'</pre>'; 239 } 240 if(is_404()) echo "\n".current_filter().' is 404 ! '; 241 } 242 //add_action('all','all_actions',1); 243 244 function zelist_remote_request_args($array) { 245 /* Defaults, see wp-includes/http.php 246 $defaults = array( 247 'method' => 'GET', 248 'timeout' => apply_filters( 'http_request_timeout', 5), 249 'redirection' => apply_filters( 'http_request_redirection_count', 5), 250 'httpversion' => apply_filters( 'http_request_version', '1.0'), 251 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version ), 252 'blocking' => true, 253 'headers' => array(), 254 'body' => null 255 ); 256 */ 257 $array['user_agent'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1); URL fetching by zelist (http://www.zelist.net) for '.get_option('blogname').';'; 258 return $array; 259 } 260 add_filter('zelist_remote_request','zelist_remote_request_args'); 261 262 /** 263 * After adding a link, update the link_added date 264 * @param $link_id 265 * @return unknown_type 266 */ 267 function zelist_add_link($link_id) { 268 $link = get_bookmark($link_id); 269 270 global $wpdb; 271 $query = "UPDATE $wpdb->links SET "; 272 $join = ""; 273 $update = array(); 274 $where = "WHERE link_id = $link_id "; 275 if($link->link_added == '0000-00-00 00:00:00') { 276 $update[] = 'link_added = NOW()'; 277 /* $link_added = false; 278 if(isset($_POST['link_added'])) { 279 $link_added = date('Y-m-d H:i:s',strtotime($_POST['link_added'])); 280 $link_added = "'$link_added'"; 281 } 282 if(!$link_added) $link_added = 'NOW()';*/ 283 } 284 if($link->link_status == 'publish') { 285 $update[] = 'link_published = NOW()'; 286 } 287 $update[] = 'link_updated = NOW()'; 288 289 290 $visible = ($link->link_status == 'publish') ? 'Y' : 'N'; 291 $update[] = "link_visible = '$visible' "; 292 293 if(count($update) == 0) return; 294 295 $update = apply_filters('zelist_add_link',$update,$link_id,$link,$query,$join,$where); 296 $query = $query . implode(', ',$update) . $where; 297 $wpdb->query($query); 298 return; 299 } 300 add_action( 'add_link', 'zelist_add_link',10,1); 301 302 function zelist_get_search_query($s) { 303 if(empty($s)) return stripslashes( get_query_var( 'ls' ) ); 304 } 305 add_filter( 'get_search_query', 'zelist_get_search_query'); 306 307 //add_filter('login_headerurl', 'zelist_login_headerurl');
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat May 30 23:51:06 2009 | Cross-referenced by PHPXref 0.7 |