[ Index ]

PHP Cross Reference of zeList

title

Body

[close]

/includes/ -> template-hooks.php (source)

   1  <?php
   2  
   3  /**
   4   * Check for properly formated URL on bookmarks pages
   5   * @return unknown_type
   6   */
   7  function zelist_check_request_uri() {
   8    if(!is_links()) return;
   9    if(is_admin()) return;
  10  
  11    global $zelist_query;
  12    $location = false;
  13  
  14    if(is_a_link()) {
  15      //$link_id = $zelist_query->link->link_id;
  16      $link_id = get_zelist_query_var('link_id');
  17      $permalink = get_link_permalink($link_id);
  18      $permalink_parts = parse_url($permalink);
  19      $request_uri = $_SERVER['REQUEST_URI'];
  20      $request_uri_parts = parse_url($request_uri);
  21      do_action('zelist_check_request_uri',$permalink);
  22      //$request_uri_parts['path'] = untrailingslashit($request_uri_parts['path']);
  23      //$permalink_parts['path'] = untrailingslashit($permalink_parts['path']);
  24      if(get_option('zelist_rewrite') && $permalink_parts['path'] != $request_uri_parts['path']
  25      || trailingslashit($permalink_parts['path']) != trailingslashit($request_uri_parts['path'])) {
  26        $location = $permalink;
  27      }
  28    }
  29    elseif(is_link_category() && !is_link_home()) {
  30      //echo '<pre>'.print_r($zelist_query,1).'</pre>';
  31      $link_category_id = get_zelist_query_var('link_category');
  32      $permalink = get_link_category_link($link_category_id);
  33      $permalink_parts = parse_url($permalink);
  34      $request_uri = $_SERVER['REQUEST_URI'];
  35      $request_uri_parts = parse_url($request_uri);
  36  
  37      do_action('zelist_check_request_uri',$permalink);
  38  
  39      if(get_option('zelist_rewrite') && $permalink_parts['path'] != $request_uri_parts['path']
  40      || trailingslashit($permalink_parts['path']) != trailingslashit($request_uri_parts['path'])) {
  41        $location = $permalink;
  42  
  43      }
  44    }
  45  
  46    $location = apply_filters('zelist_redirect_canonical_location',$location);
  47    if($location) {
  48      header("HTTP/1.1 301 Moved Permanently");
  49      header("Redirect-by: zeList");
  50      wp_redirect($location,301);
  51      die();
  52    }
  53  
  54    global $canonical_link;
  55    $canonical_link = true;
  56  
  57    return;
  58  }
  59  add_action('zelist_query_get_links','zelist_check_request_uri');
  60  
  61  function zelist_redirect_canonical($redirect_url, $requested_url = '') {
  62    if(!$redirect_url) return $redirect_url;
  63    global $canonical_link;
  64    if(is_links() && $canonical_link) return false;
  65    return $redirect_url;
  66  }
  67  add_filter('redirect_canonical', 'zelist_redirect_canonical');
  68  
  69  
  70  
  71  /**
  72   * Finds the correct template
  73   * @param $content
  74   * @return unknown_type
  75   */
  76  function zelist_custom_content($content)
  77  {
  78    global $post;
  79  
  80    if(stripos($content,'[zelist_submit]'))     {
  81      // check for option zelist_submit_page
  82      if(!get_option('zelist_submit_page')) add_option('zelist_submit_page',$post->ID);
  83  
  84      $content = str_replace('<!--[zelist_submit]-->','',$content);
  85      if(file_exists(TEMPLATEPATH . "/submitform.php")) include (TEMPLATEPATH . "/submitform.php");
  86      else include  (ZELIST_PATH.'/style/submitform.php');
  87    }
  88    return $content;
  89  }
  90  add_filter('the_content','zelist_custom_content');
  91  
  92  function zelist_add_credits()
  93  {
  94    return;
  95    echo sprintf(
  96    __('<a href="%s">%s</a>','zelist'),
  97      'http://www.zelist.net/',
  98    __('zeList, directory plugin for WordPress','zelist')
  99    );
 100  }
 101  add_filter('wp_footer','zelist_add_credits');
 102  
 103  /**
 104   * Choose the right template for links pages
 105   * @param $template
 106   * @return unknown_type
 107   */
 108  function zelist_taxonomy_template($template) {
 109    //echo "\ntemplate = $template";
 110  
 111    if(!is_links()) $template = $template;
 112    elseif(is_a_link()) {
 113      if(file_exists(TEMPLATEPATH.'/link.php')) $template = TEMPLATEPATH.'/link.php';
 114      else $template = ZELIST_PATH.'/style/link.php';
 115    }
 116    else {
 117      if(file_exists(TEMPLATEPATH.'/link-category.php')) $template = $template = TEMPLATEPATH.'/link-category.php';
 118      else $template = ZELIST_PATH.'/style/link-category.php';
 119    }
 120    return $template;
 121  }
 122  add_filter('taxonomy_template', 'zelist_taxonomy_template');
 123  
 124  function zelist_page_template($template) {
 125    global $post;
 126    if(!$post) return $template;
 127    if($post->ID != get_option('zelist_root')) return $template;
 128  
 129    if(file_exists(TEMPLATEPATH.'/link-category.php')) $template = $template = TEMPLATEPATH.'/link-category.php';
 130    else $template = ZELIST_PATH.'/style/link-category.php';
 131  
 132    return $template;
 133  }
 134  add_filter('page_template', 'zelist_page_template');
 135  
 136  /**
 137   * Forces is_tax = true for links page
 138   * @return unknown_type
 139   */
 140  function zelist_template_redirect() {
 141    //$debug = true;
 142    if($debug) echo "<br />\ntemplate redirect ... 404 ? ".is_404();
 143  
 144    if(is_links()) { // @TODO && !is_link_home() = link_home should use the template given to the page (which might be link-category.php or not)
 145    // force template loader to load custom templates
 146    global $wp_query;
 147    global $zelist_query;
 148  
 149    if($debug) echo " \n found links $zelist_query->found_links";
 150  
 151    // cancel 404 when links are found (bug found in link tags page)
 152    if($wp_query->is_404 && $zelist_query->found_links) {
 153      $wp_query->is_404 = 0;
 154    }
 155    $wp_query->is_tax = true;
 156  
 157    if($debug) echo "\n > is 404 ? ".is_404();
 158  
 159    }
 160  }
 161  add_action('template_redirect','zelist_template_redirect');
 162  
 163  /**
 164   * Hooks in wp_title to display the right title on bookmarks page
 165   * @param $title
 166   * @param $sep
 167   * @param $seplocation
 168   * @return unknown_type
 169   */
 170  function zelist_wp_title($wp_title, $sep = '&raquo;', $seplocation = '') {
 171    if($debug) echo "wp title = $wp_title";
 172    if(!is_links()) return $wp_title;
 173  
 174    if($debug) echo "\ntoujours la ";
 175    $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
 176  
 177    global $zelist_query;
 178    if($debug) echo "\ntoujours la ";
 179    $cat = get_zelist_query_var('link_category');
 180    $tag_id = get_zelist_query_var('link_tag_id');
 181    $category_name = get_zelist_query_var('link_category_name');
 182    $owner = get_query_var('link_owner');
 183    $title = '';
 184  
 185    if($debug) echo "\ntoujours la ";
 186    if($debug) echo "title = $wp_title";
 187    if(is_a_link()) {
 188      if($debug) echo " is a link ";
 189      $link = $zelist_query->link;
 190      $title = strip_tags( apply_filters( 'single_link_title', $link->link_name ) );
 191      $categories = get_the_link_category($link->link_id);
 192      $category = $categories[0];
 193      $title .= $t_sep . $category->name;
 194    }
 195    elseif(is_link_category()) {
 196      if($debug) echo " is a link cat ";
 197      if(!empty($cat) && !stristr($cat,'-') ) {
 198        $title = apply_filters('single_link_cat_title', get_the_link_category_by_ID($cat));
 199      }
 200      elseif ( !empty($category_name) ) {
 201        if($debug) echo " is a link cat name ";
 202        if ( stristr($category_name,'/') ) {
 203          $category_name = explode('/',$category_name);
 204          if ( $category_name[count($category_name)-1] )
 205          $category_name = $category_name[count($category_name)-1]; // no trailing slash
 206          else
 207          $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
 208        }
 209        $cat = get_term_by('slug', $category_name, 'link_category', OBJECT, 'display');
 210        if ( $cat )
 211        $title = apply_filters('single_link_cat_title', $cat->name);
 212      }
 213    }
 214    elseif(is_link_home()) {
 215      if($debug) echo " is a link home ";
 216      if(trim(str_replace($sep,'',$wp_title)) == '')  $wp_title = get_bloginfo('name');
 217      return $wp_title; // the page holding zelist already has a title
 218    }
 219    elseif(is_link_search()) {
 220      if($debug) echo " is a link searc ";
 221      $title = stripslashes( get_query_var( 'ls' ) ) ;
 222    }
 223    elseif(is_link_tag()) {
 224      if($debug) echo " is a link tag ";
 225      $tag = get_term($tag_id, 'link_tag', OBJECT, 'display');
 226      if ( is_wp_error( $tag ) ) return $tag;
 227      if ( ! empty($tag->name) )
 228      $title = apply_filters('single_link_tag_title', $tag->name);
 229    }
 230    else {
 231      if($debug) echo "is a link rien";
 232      $title = '';
 233    }
 234    if($debug) echo " toujours la ";
 235    if($debug) echo "title = $title";
 236  
 237    // Determines position of the separator and direction of the breadcrumb
 238    if ( 'right' == $seplocation ) { // sep on right, so reverse the order
 239      $title_array = explode( $t_sep, $title );
 240  
 241      $title_array = array_reverse( $title_array );
 242      $title_array[] = get_bloginfo('name');
 243      $title = implode( " $sep ", $title_array ) . $prefix;
 244    } else {
 245      $title_array = explode( $t_sep, $title );
 246      $title_array[] = get_bloginfo('name');
 247      $title = $prefix . implode( " $sep ", $title_array );
 248    }
 249    return $title;
 250  }
 251  add_filter('wp_title', 'zelist_wp_title',9);


Generated: Sat May 30 23:51:06 2009 Cross-referenced by PHPXref 0.7