Created
September 27, 2012 23:13
-
-
Save GDmac/3797023 to your computer and use it in GitHub Desktop.
test_plugin for conditionals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
$plugin_info = array( | |
'pi_name' => 'Test_plugin', | |
'pi_version' => '1.0', | |
'pi_author' => 'GDmac', | |
'pi_author_url' => '', | |
'pi_description' => 'Testing stuff', | |
'pi_usage' => Test_plugin::usage() | |
); | |
Class Test_plugin { | |
var $return_data; | |
// ------------------------------------------ | |
function __construct() | |
{ | |
$this->EE =& get_instance(); | |
} | |
// ------------------------------------------ | |
function test() | |
{ | |
var_dump('test', $this->EE->TMPL->tagdata, $this->EE->TMPL->tag_data); | |
return $this->EE->TMPL->tagdata; | |
} | |
// ------------------------------------------ | |
function test2() | |
{ | |
// $x = $this->EE->functions->assign_conditional_variables($this->EE->TMPL->tagdata); | |
// var_dump('test2', $x, $this->EE->TMPL->tag_data); | |
// fetch tagdata | |
$this->tagdata = $this->EE->TMPL->tagdata; | |
// main tag-pair loop, replacing tag-pairs with data | |
$var_pairs = $this->EE->TMPL->var_pair; | |
foreach ($var_pairs as $key => $params) | |
{ | |
//var_dump($key, $params); | |
// -------------------- | |
// match tag one | |
if (strncmp($key, 'switch_one', 10) == 0) | |
{ | |
// fetch switch_one tag contents | |
$temp = preg_match("/{".preg_quote($key)."}(.*?){\/switch_one}/s", $this->tagdata, $matches); | |
// fetch any conditionals | |
$conditionals = $this->EE->functions->assign_conditional_variables($matches[1]); | |
var_dump($conditionals, $matches); | |
// str_replace whole match (tag-pair) | |
$this->tagdata = str_replace($matches[0], '<p>String replacing one</p>', $this->tagdata); | |
} | |
// -------------------- | |
// match tag two | |
if (strncmp($key, 'switch_two', 10) == 0) | |
{ | |
// fetch tag contents and remove from tagdata | |
$temp = preg_match("/{".preg_quote($key)."}(.*?){\/switch_two}/s", $this->tagdata, $matches); | |
$this->tagdata = str_replace($matches[0], '<p>String Replacing two</p>', $this->tagdata); | |
} | |
} | |
return $this->tagdata; | |
} | |
// ------------------------------------------ | |
function usage() | |
{ | |
ob_start(); | |
?> | |
#Nothing to see here | |
Jut testing | |
<?php | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Test</p> | |
{exp:test_plugin:test} | |
aa | |
{if no_results} | |
bb | |
{/if} | |
{exp:test_plugin:test2} | |
cc | |
{switch_one hello="world"} | |
xx | |
{if t2_no_results} | |
dd | |
{/if} | |
{/switch_one} | |
{switch_two foo="bar"} | |
yy | |
{if t2_no_results} | |
ee | |
{/if} | |
{/switch_two} | |
{/exp:test_plugin:test2} | |
{/exp:test_plugin:test} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment