Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 755c387edf1d61c1decdb5c58af9121ab122ae1d @mdesign committed Mar 7, 2009
Showing with 115 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +23 −0 README.textile
  3. +90 −0 plugins/pi.md_detect_page_type.php
@@ -0,0 +1,2 @@
+*.DS_Store
+md-detect-page-type.tmproj
@@ -0,0 +1,23 @@
+h1. MD Detect Page Type
+
+Detect if you are on pagination page, category page, or yearly archive page.
+
+h2. Info
+
+Developed by Ryan Masuga, http://masugadesign.com
+
+Docs: "MD Detect Page Type":http://masugadesign.com/the-lab/scripts/md-detect-page-type/ <br />
+EE Extension Info: http://expressionengine.com/docs/development/extensions.html
+
+Also see the "related forum thread at the EE Forums":http://expressionengine.com/forums/viewthread/92307/.
+
+h2. Changelog
+
+*1.0.1 (Sep 29, 2008)*
+
+* Added ability to check for category page and yearly archive page types
+* Changed name from md_detect_pagination to md_detect_page_type
+
+1.0.0 (Sep 28, 2008)
+
+* Initial release.
@@ -0,0 +1,90 @@
+<?php
+/*
+===============================================================================
+File: pi.md_detect_page_type.php
+Thread: http://expressionengine.com/forums/viewthread/92307/
+Docs: http://www.masugadesign.com/the-lab/scripts/md-detect-page-type/
+Misc Related Links:
+http://expressionengine.com/forums/viewthread/55700/P18/
+-------------------------------------------------------------------------------
+Purpose: Detect if the page you are on is a pagination, category, or yearly
+ archive page.
+===============================================================================
+*/
+$plugin_info = array(
+ 'pi_name' => 'MD Detect Page Type',
+ 'pi_version' => '1.0.1',
+ 'pi_author' => 'Ryan Masuga',
+ 'pi_author_url' => 'http://www.masugadesign.com/',
+ 'pi_description' => 'Detect if the page you are on is a pagination, category, or yearly archive page.',
+ 'pi_usage' => Md_detect_page_type::usage()
+ );
+
+class Md_detect_page_type {
+
+var $return_data = "";
+
+ function Md_detect_page_type()
+ {
+ global $TMPL, $IN, $FNS, $PREFS;
+ $tagdata = $TMPL->tagdata;
+ $conds = array();
+ $category_word = $PREFS->ini("reserved_category_word");
+
+ if ($TMPL->fetch_param('url_segment') !== FALSE)
+ {
+ $url_segment = $TMPL->fetch_param('url_segment');
+ }
+ else
+ {
+ $url_segment = end($IN->SEGS);
+ }
+
+ $conds['pagination_page'] = (preg_match('/^[P][0-9]+$/i', $url_segment)) ? TRUE : FALSE;
+ $conds['category_page'] = (preg_match("/$category_word/", $url_segment)) ? TRUE : FALSE;
+ $conds['yearly_archive_page'] = (preg_match("/^\d{4}$/", $url_segment)) ? TRUE : FALSE;
+
+ // Prep output
+ $tagdata = $FNS->prep_conditionals($tagdata, $conds);
+
+ // return
+ $this->return_data = $tagdata;
+
+ }
+
+// ----------------------------------------
+// Plugin Usage
+// ----------------------------------------
+
+// This function describes how the plugin is used.
+// Make sure and use output buffering
+
+function usage()
+{
+ob_start();
+?>
+Useful if you're tying to use a single template to do paginated entries, categories and a single-entry. May have other uses - get creative!
+
+PARAMETERS:
+The tag has one parameter:
+
+1. url_segment - The segment to check. [REQUIRED]
+
+Example usage:
+{exp:md_detect_page_type url_segment="{segment_3}"}
+Pagination Page: {if pagination_page}This is a Paginated Page{/if}<br />
+Category Page: {if category_page}This is a Category Page{/if}<br />
+Yearly Archive Page: {if yearly_archive_page}This is a Yearly Archive Page{/if}
+{/exp:md_detect_page_type}
+
+<?php
+$buffer = ob_get_contents();
+
+ob_end_clean();
+
+return $buffer;
+}
+// END
+
+}
+?>

0 comments on commit 755c387

Please sign in to comment.