plugins/description-on-index: DescriptionOnIndex.jplug.php

File DescriptionOnIndex.jplug.php, 1.4 KB (added by driehle, 6 years ago)
Line 
1<?php
2/**
3 * @name:        DescriptionOnIndex <http://jeenaparadies.net/webdesign/jlog/doc/index.php?n=Plugins.DescriptionOnIndex>
4 * @author:      Jeena Paradies <jlog@jeenaparadies.net>
5 * @version:     1.1
6 * @date:        2005-01-12
7 */
8
9class DescriptionOnIndex extends JlogPlugin {
10
11    function hook_body($body) {
12
13        $description = "";
14        $this->tree = array();
15
16        preg_match_all('/<jlog:([a-z]\w+)\s?([^>]*)\/?>(<\/(\1):(\2)>)?/ims', $body, $this->tree);
17        $path_parts = pathinfo($_SERVER['PHP_SELF']);
18
19        if( $path_parts['basename'] === 'index.php' AND (strpos($path_parts['dirname'], 'admin') === false) ) {
20            $description = "\n<div".$this->getAttribute('descriptiononindex', 'class').">\n"
21                          .stripslashes(JLOG_DESCRIPTION)
22                          ."</div>";
23        }
24
25        return str_replace($this->tree[0][array_search('descriptiononindex', $this->tree[1])], $description, $body);
26    }
27
28    function getAttribute($tag, $attribute) {
29        $pattern = '/(?:^|\s)([a-z]\w+)(?:=)(?:(?:\'([^\']+)\')|(?:"([^"]*)")|([^\s,]+))/i';
30        preg_match_all($pattern, $this->tree[2][ array_search($tag, $this->tree[1])], $matches, PREG_SET_ORDER);
31        $a = count($matches);
32        for($i=0;$i<$a;$i++) {
33            if($matches[$i][1] == $attribute) return ' class="'.$matches[$i][3].'"';
34        }
35        return;
36    }
37}
38?>