Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit

  • Loading branch information...
commit 755c387edf1d61c1decdb5c58af9121ab122ae1d 0 parents
Masuga Design authored March 07, 2009
2  .gitignore
... ...
@@ -0,0 +1,2 @@
  1
+*.DS_Store
  2
+md-detect-page-type.tmproj
23  README.textile
Source Rendered
... ...
@@ -0,0 +1,23 @@
  1
+h1. MD Detect Page Type
  2
+
  3
+Detect if you are on pagination page, category page, or yearly archive page.
  4
+
  5
+h2. Info
  6
+
  7
+Developed by Ryan Masuga, http://masugadesign.com
  8
+
  9
+Docs: "MD Detect Page Type":http://masugadesign.com/the-lab/scripts/md-detect-page-type/ <br />
  10
+EE Extension Info: http://expressionengine.com/docs/development/extensions.html
  11
+
  12
+Also see the "related forum thread at the EE Forums":http://expressionengine.com/forums/viewthread/92307/.
  13
+
  14
+h2. Changelog
  15
+
  16
+*1.0.1 (Sep 29, 2008)*
  17
+
  18
+* Added ability to check for category page and yearly archive page types
  19
+* Changed name from md_detect_pagination to md_detect_page_type
  20
+
  21
+1.0.0 (Sep 28, 2008)
  22
+
  23
+* Initial release.
90  plugins/pi.md_detect_page_type.php
... ...
@@ -0,0 +1,90 @@
  1
+<?php
  2
+/*
  3
+===============================================================================
  4
+File: pi.md_detect_page_type.php
  5
+Thread: http://expressionengine.com/forums/viewthread/92307/
  6
+Docs: http://www.masugadesign.com/the-lab/scripts/md-detect-page-type/
  7
+Misc Related Links:
  8
+http://expressionengine.com/forums/viewthread/55700/P18/
  9
+-------------------------------------------------------------------------------
  10
+Purpose: Detect if the page you are on is a pagination, category, or yearly 
  11
+         archive page.
  12
+===============================================================================
  13
+*/
  14
+$plugin_info = array(
  15
+						'pi_name'			=> 'MD Detect Page Type',
  16
+						'pi_version'			=> '1.0.1',
  17
+						'pi_author'			=> 'Ryan Masuga',
  18
+						'pi_author_url'		=> 'http://www.masugadesign.com/',
  19
+						'pi_description'		=> 'Detect if the page you are on is a pagination, category, or yearly archive page.',
  20
+						'pi_usage'			=> Md_detect_page_type::usage()
  21
+					);
  22
+
  23
+class Md_detect_page_type {
  24
+
  25
+var $return_data = "";
  26
+	
  27
+	function Md_detect_page_type()
  28
+	{
  29
+			global $TMPL, $IN, $FNS, $PREFS;
  30
+      $tagdata = $TMPL->tagdata;
  31
+			$conds = array();
  32
+			$category_word = $PREFS->ini("reserved_category_word");
  33
+			
  34
+			if ($TMPL->fetch_param('url_segment') !== FALSE)
  35
+			{
  36
+				$url_segment = $TMPL->fetch_param('url_segment');
  37
+			}
  38
+			else
  39
+			{
  40
+				$url_segment = end($IN->SEGS);
  41
+			}
  42
+			
  43
+			$conds['pagination_page'] = (preg_match('/^[P][0-9]+$/i', $url_segment)) ? TRUE : FALSE;
  44
+			$conds['category_page'] = (preg_match("/$category_word/", $url_segment)) ? TRUE : FALSE;
  45
+			$conds['yearly_archive_page'] = (preg_match("/^\d{4}$/", $url_segment)) ? TRUE : FALSE;
  46
+
  47
+		// Prep output
  48
+		$tagdata = $FNS->prep_conditionals($tagdata, $conds);
  49
+
  50
+		// return
  51
+		$this->return_data = $tagdata;
  52
+
  53
+	}
  54
+    
  55
+// ----------------------------------------
  56
+//  Plugin Usage
  57
+// ----------------------------------------
  58
+
  59
+// This function describes how the plugin is used.
  60
+//  Make sure and use output buffering
  61
+
  62
+function usage()
  63
+{
  64
+ob_start(); 
  65
+?>
  66
+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!
  67
+
  68
+PARAMETERS: 
  69
+The tag has one parameter:
  70
+
  71
+1. url_segment - The segment to check. [REQUIRED]
  72
+
  73
+Example usage:
  74
+{exp:md_detect_page_type url_segment="{segment_3}"}
  75
+Pagination Page: {if pagination_page}This is a Paginated Page{/if}<br />
  76
+Category Page: {if category_page}This is a Category Page{/if}<br />
  77
+Yearly Archive Page: {if yearly_archive_page}This is a Yearly Archive Page{/if}
  78
+{/exp:md_detect_page_type}
  79
+
  80
+<?php
  81
+$buffer = ob_get_contents();
  82
+	
  83
+ob_end_clean(); 
  84
+
  85
+return $buffer;
  86
+}
  87
+// END
  88
+
  89
+}
  90
+?>

0 notes on commit 755c387

Please sign in to comment.
Something went wrong with that request. Please try again.