Hello
I have written a plugin which simply returns the first segment of a URL. Yes I know that {segment_1} would do this, but it would appear it returns the true first segment and not the first segment viewed in a browser window when using a certain RewriteRule. Anyhow, I have written a plugin which returns successfully the first segment.
The URL in my browser window is such:
http://example.com/military/blogs/test
Here is a pared down version of my page:
{assign_variable:section="blogs"}
{assign_variable:template_group="blogs"}
{assign_variable:prod_division="{exp:ooc_eeurl}"}
{exp:weblog:entries limit="1"}
{prod_division}
{/exp:weblog:entries}
{prod_division}
This outputs the following:
military military
However, if I call the variable {prod_division} before the exp:weblog:entry, the output is broken while in the loop:
Here is a pared down version of my page:
[code]{assign_variable:section="blogs"}
{assign_variable:template_group="blogs"}
{assign_variable:prod_division="{exp:ooc_eeurl}"}
{prod_division}
{exp:weblog:entries limit="1"}
{prod_division}
{/exp:weblog:entries}
{prod_division}
This now outputs:
http://dev.whitesdiving.com/military/blogs/test
The code in my plugin is:
<?php
/* ============================================================================
pi.ooc_eeurl.php
Returns the visual url segment and not the true url segment
INFO --------------------------------------------------------------------------
Developed by: James Riordon, Out of Control
Created: July 17th 2009
CHANGELOG & OTHER INFO --------------------------------------------------------
See README.textile
=============================================================================== */
$plugin_info = array(
'pi_name' => 'OOC Eeurl',
'pi_version' => '0.1.0',
'pi_author' => 'James Riordon',
'pi_author_url' => 'http://outofcontrol.ca/',
'pi_description' => 'Pulls the visual URL segments instead of the real ones',
'pi_usage' => Ooc_eeurl::usage()
);
Class Ooc_eeurl {
var $return_data;
// ----------------------------------------
// eexcerpt
// ----------------------------------------
function ooc_eeurl()
{
global $TMPL;
$segment = ( ! $TMPL->fetch_param('segment')) ? '1' : $TMPL->fetch_param('segment');
if ( ! is_numeric($segment) || $segment > 10 ) $segment = 1;
$this->return_data = $this->_pull_url_segments($segment);
}
function _pull_url_segments($segment = 1)
{
$url_array = explode("/",rtrim($_SERVER["REQUEST_URI"],"/"));
$theCount = count($url_array);
// $clean_url = array_map(array($this, "_clean_url"), $url_array);
$clean_url = $url_array;
return trim($clean_url[$segment]);
}
function _clean_url($data)
{
return $data;
}
// END
// ----------------------------------------
// Plugin Usage
// ----------------------------------------
// This function describes how the plugin is used.
// Make sure and use output buffering
function usage()
{
ob_start();
?>
how to use it
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// END
}
// END CLASS
?>
Most likely something I am totally breaking in my plugin, but if someone could point me to a possible solution, it would be REALLY useful, and would save what little hair I do have left on my head.
Many thanks!
