| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | require_once 'classes/LightPressPlugin.php'; |
|---|
| 4 | |
|---|
| 5 | class PostAdRecursion extends LightPressPlugin { |
|---|
| 6 | |
|---|
| 7 | var $constructor_args = array( |
|---|
| 8 | 'templates'=>'a list of post numbers and templates using the following format 1:ad_template,2:ad_template,3:ad_template', |
|---|
| 9 | 'templates_folder'=>'folder where the templates are, levae empty to use the plugins/ folder and prepend post_ad_recursion_ to the template names'); |
|---|
| 10 | var $default_context = 7; |
|---|
| 11 | var $description = 'Display a template between posts in the index. The template is called post_ad_recursion_n.xml, where n is the index of the post preceding the template, eg post_ad_recursion_3.xml post_ad_recursion_6.xml etc.'; |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | var $active = true; |
|---|
| 15 | var $hooks = array('parse_post'); |
|---|
| 16 | |
|---|
| 17 | var $templates = ''; |
|---|
| 18 | var $templates_folder = ''; |
|---|
| 19 | |
|---|
| 20 | var $_templates; |
|---|
| 21 | |
|---|
| 22 | var $_loop_cycle = 0; |
|---|
| 23 | |
|---|
| 24 | function PostAdRecursion(&$frontend, $args, $dummy_run=false) { |
|---|
| 25 | $this->LightPressPlugin($frontend, $args, $dummy_run); |
|---|
| 26 | |
|---|
| 27 | if (!$dummy_run) { |
|---|
| 28 | |
|---|
| 29 | $templates_folder = $this->templates_folder; |
|---|
| 30 | $s = substr($templates_folder, -1); |
|---|
| 31 | |
|---|
| 32 | if (!empty($s) && $s != DIRECTORY_SEPARATOR && $s != '/') |
|---|
| 33 | $templates_folder .= DIRECTORY_SEPARATOR; |
|---|
| 34 | |
|---|
| 35 | foreach (preg_split('/\s*,\s*/', $this->templates) as $k) { |
|---|
| 36 | $tokens = explode(':', $k); |
|---|
| 37 | if (count($tokens) != 2) |
|---|
| 38 | continue; |
|---|
| 39 | if (empty($templates_folder)) |
|---|
| 40 | $template = "plugins/post_ad_recursion_{$tokens[1]}.xml"; |
|---|
| 41 | else |
|---|
| 42 | $template = "$templates_folder{$tokens[1]}.xml"; |
|---|
| 43 | $this->_templates[(int)$tokens[0]] = $template; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | if (count($this->_templates) == 0) |
|---|
| 47 | $active = false; |
|---|
| 48 | |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | function hide() { |
|---|
| 53 | return; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | function run($hook, &$post) { |
|---|
| 57 | $this->_loop_cycle++; |
|---|
| 58 | if (!isset($this->_templates[$this->_loop_cycle])) |
|---|
| 59 | return; |
|---|
| 60 | $tpl =& $this->_frontend->tpl; |
|---|
| 61 | $template = $this->_templates[$this->_loop_cycle]; |
|---|
| 62 | |
|---|
| 63 | $tpl->setFile("plugin_postadrecursion_{$this->_loop_cycle}", $template); |
|---|
| 64 | $tpl->parse('BLOCK_POST', "plugin_postadrecursion_{$this->_loop_cycle}", true, false); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | ?> |
|---|