<?php
/**
 * @name:        DescriptionOnIndex <http://jeenaparadies.net/webdesign/jlog/doc/index.php?n=Plugins.DescriptionOnIndex>
 * @author:      Jeena Paradies <jlog@jeenaparadies.net>
 * @version:     1.1
 * @date:        2005-01-12
 */

class DescriptionOnIndex extends JlogPlugin {

    function hook_body($body) {

        $description = "";
        $this->tree = array();

        preg_match_all('/<jlog:([a-z]\w+)\s?([^>]*)\/?>(<\/(\1):(\2)>)?/ims', $body, $this->tree);
        $path_parts = pathinfo($_SERVER['PHP_SELF']);

        if( $path_parts['basename'] === 'index.php' AND (strpos($path_parts['dirname'], 'admin') === false) ) {
            $description = "\n<div".$this->getAttribute('descriptiononindex', 'class').">\n"
                          .stripslashes(JLOG_DESCRIPTION)
                          ."</div>";
        }

        return str_replace($this->tree[0][array_search('descriptiononindex', $this->tree[1])], $description, $body);
    }

    function getAttribute($tag, $attribute) {
        $pattern = '/(?:^|\s)([a-z]\w+)(?:=)(?:(?:\'([^\']+)\')|(?:"([^"]*)")|([^\s,]+))/i';
        preg_match_all($pattern, $this->tree[2][ array_search($tag, $this->tree[1])], $matches, PREG_SET_ORDER);
        $a = count($matches);
        for($i=0;$i<$a;$i++) {
            if($matches[$i][1] == $attribute) return ' class="'.$matches[$i][3].'"';
        }
        return;
    }
}
?>
