Location: PHPKode > scripts > Lightning Notes > ln_distro/ln_distro/admin/notesfnc.php
<?php
//error_reporting(E_ALL);
require_once ("parsefnc.php");

/**
* description: parsing <li>entries from notes
* requires:    
* est. | mod:  2003-07-17 | 2003-07-28
*/
function entrieslist ($tree, $id, $category, $entries, $showdate = '1')
{
    $status = 'publish';
    $out = '';
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i <= $tCount; $i++) {
        if (($category == $tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['ATTRIBUTES']['REF'])
        or $category == ($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['ATTRIBUTES']['REF'])
        or $category == ($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['ATTRIBUTES']['REF'])
        or $category == ($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['ATTRIBUTES']['REF'])) {
            $list .= $tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE'].', ';
        }
    }
    $catids = explode (", ", $list);
    $pop = array_pop ($catids);
    if (isset($id)) {
        $exclude[] = $id;
        $catids = array_diff ($catids, $exclude);
    }
    if ($entries == '') {
        $entries = count($tree['COLLECTION'][0]['ENTRY']);
    } else {
        $entries == $entries - 1;
    }
    $catids = array_slice ($catids, 0, $entries);
    $out = '<div class="entry">'."\n".'<ul>'."\n";
    foreach ($catids as $value) {
        for ($h = 0; $h < $tCount; $h++) {
            if ($value == ($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE'])) {
                $out .= '<li>';
                if ($showdate == 1) {
                    $out .= '<span class="date">'.$tree['COLLECTION'][0]['ENTRY'][$h]['DATE'][0]['VALUE'].'</span>'."\n";
                }
                $out .= '<h2><a lang="'.$tree['COLLECTION'][0]['ENTRY'][$h]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$h]['URL'][0]['VALUE'].'" title="Permanent Link: '.$tree['COLLECTION'][0]['ENTRY'][$h]['TITLE'][0]['VALUE'].'">';
                $out .= $tree['COLLECTION'][0]['ENTRY'][$h]['TITLE'][0]['VALUE'].'</a></h2>'."\n";
                $out .= $tree['COLLECTION'][0]['ENTRY'][$h]['EXCERPT'][0]['VALUE'];
                $out .= '</li>'."\n";
            }
        }
    }
    $out .= '</ul>'."\n".'</div>';
    return $out;
}

/**
* description: parsing a stack of whole entries from notes
* requires:    
* est. | mod:  2003-07-17 | 2003-07-28
*/
function entries ($tree, $entries, $showcat = '1', $showsubcat = '1', $body = '1')
{
    $status = 'publish';
    $out = '';
    if ($entries == '') {
        $entries = count($tree['COLLECTION'][0]['ENTRY']);
    } else {
        $entries = $entries - 1;
    }
    for ($i = 0; $i <= $entries; $i++) {
        if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']) && ($status == $tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE'])) {
            $out .= '<div class="entry">'."\n";
            if ($body == 1) {
                $out .= '<p class="date"><a lang="'.$tree['COLLECTION'][0]['ENTRY'][$i]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'" title="Permanent Link: '.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'" rel="bookmark"><span>&#8249;#&#8250;</span></a> '.$tree['COLLECTION'][0]['ENTRY'][$i]['DATE'][0]['VALUE'].'</p>'."\n";
            }
            $out .= '<h2><a lang="'.$tree['COLLECTION'][0]['ENTRY'][$i]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'">';
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'</a></h2>'."\n";
            if ($body == 1) {
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE'];
                if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['EXTBODY'][0]['VALUE'])) {
                    $out .= '<p class="note"><a href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'">';
                    $out .= 'Read more</a> &#187;</p>'."\n";
                }
            } elseif ($body == 0) {
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['EXCERPT'][0]['VALUE']."\n";
            }
            if ($showcat == 1) {
                $out .= '<p class="category">Category: <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['ATTRIBUTES']['REF'].'"><strong>';
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['VALUE'].'</strong></a>';
                
                if ($showsubcat == 1) {
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['VALUE'])) {
                        $out .= ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['ATTRIBUTES']['REF'].'">';
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['VALUE'];
                        $out .= '</a>';
                    }
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['VALUE'])) {
                        $out .= ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['ATTRIBUTES']['REF'].'">';
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['VALUE'];
                        $out .= '</a>';
                    }
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['VALUE'])) {
                        $out .= ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['ATTRIBUTES']['REF'].'">';
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['VALUE'];
                        $out .= '</a>';
                    }
                }
                $out .= '</p>'."\n";
            }
            $out .= '</div>'."\n";
        }
    }
    return $out;
}

/**
* description: parsing entries by categories
* requires:    
* est. | mod:  2003-07-17 | 2003-07-28
*/
function entriesbycat ($tree, $id, $category, $entries, $showdate = '1')
{
    $status = 'publish';
    $out = '';
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i <= $tCount; $i++) {
        if (($category == $tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['ATTRIBUTES']['REF'])
        or $category == ($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['ATTRIBUTES']['REF'])
        or $category == ($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['ATTRIBUTES']['REF'])
        or $category == ($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['ATTRIBUTES']['REF'])) {
            $list .= $tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE'].', ';
        }
    }
    $catids = explode (", ", $list);
    $pop = array_pop ($catids);
    if (isset($id)) {
        $exclude[] = $id;
        $catids = array_diff ($catids, $exclude);
    }
    if ($entries == '') {
        $entries = count($tree['COLLECTION'][0]['ENTRY']);
    } else {
        $entries == $entries - 1;
    }
    $catids = array_slice ($catids, 0, $entries);
    foreach ($catids as $value) {
        for ($h = 0; $h < $tCount; $h++) {
            if ($value == ($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE'])) {
            $out .= '<div class="entry">'."\n".'<p class="date"><a lang="'.$tree['COLLECTION'][0]['ENTRY'][$h]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$h]['URL'][0]['VALUE'].'" title="Permanent Link: '.$tree['COLLECTION'][0]['ENTRY'][$h]['TITLE'][0]['VALUE'].'" rel="bookmark"><span>&#8249;#&#8250;</span></a> '.$tree['COLLECTION'][0]['ENTRY'][$h]['DATE'][0]['VALUE'].'</p>'."\n";
$out .= '<h2>'.$tree['COLLECTION'][0]['ENTRY'][$h]['TITLE'][0]['VALUE'].'</h2>'."\n";
            if (!empty($tree['COLLECTION'][0]['ENTRY'][$h]['BODY'][0]['VALUE'])) {
                $out .= $tree['COLLECTION'][0]['ENTRY'][$h]['BODY'][0]['VALUE'];
            }
            if (!empty($tree['COLLECTION'][0]['ENTRY'][$h]['EXTBODY'][0]['VALUE'])) {
                $out .= '<p class="note"><a href="'.$tree['COLLECTION'][0]['ENTRY'][$h]['URL'][0]['VALUE'].'">';
                $out .= 'Read more</a> &#187;</p>'."\n";
            }
        $out .= '</div>'."\n";
            }
        }
    }
    return $out;
}

/**
* description: parsing one entrytitle by id from notes
* requires:    
* est. | mod:  2003-07-17 | 2003-07-28 | 2011-11-25
*/
function entrytitlebyid ($tree, $id)
{
    $status = 'publish';
    $out = '';
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {
        if ($id == ($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE'])) {
                $out = ': '.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'];
        }
    }
    return $out;
}

/**
* description: parsing one entry by id from notes
* requires:    
* est. | mod:  2003-07-17 | 2003-07-28
*/
function entrybyid ($tree, $id, $dir, $showdate = '1', $showcat = '1', &$category, $query)
{
    $status = 'publish';
    $out = '';
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {
        if ($id == ($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE'])) {
            if ($status == ($tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE'])) {
                $out .= '<div class="entry">'."\n";
                
                $h = $i + 1;
                $j = $i - 1;
                if ($dir == 1 && (isset($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE']) or isset($tree['COLLECTION'][0]['ENTRY'][$j]['ID'][0]['VALUE']))) {
                    $out .= '<p class="dir">';
                    if (isset($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE'])) {
                        $out .= '&#171; <a lang="'.$tree['COLLECTION'][0]['ENTRY'][$h]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$h]['URL'][0]['VALUE'].'" title="'.$tree['COLLECTION'][0]['ENTRY'][$h]['TITLE'][0]['VALUE'].'">previous entry</a>';
                    }
                    if (isset($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE']) && isset($tree['COLLECTION'][0]['ENTRY'][$j]['ID'][0]['VALUE'])) {
                        $out .= ' | ';
                    }
                    if (isset($tree['COLLECTION'][0]['ENTRY'][$j]['ID'][0]['VALUE'])) {
                        $out .= '<a lang="'.$tree['COLLECTION'][0]['ENTRY'][$j]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$j]['URL'][0]['VALUE'].'" title="'.$tree['COLLECTION'][0]['ENTRY'][$j]['TITLE'][0]['VALUE'].'">next entry</a> &#187;';
                    }
                    $out .= '</p>'."\n";
                }
                if (isset($query) && (!empty($query))) {
                    $out .= '<p class="note">These search terms have been highlighted: <span class="query">'.$query.'</span></p>';
                }
                
                if ($showdate == 1) {
                    $out .= '<p class="date"><a lang="'.$tree['COLLECTION'][0]['ENTRY'][$h]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'" title="Permanent Link: '.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'" rel="bookmark"><span>&#8249;#&#8250;</span></a> '.$tree['COLLECTION'][0]['ENTRY'][$i]['DATE'][0]['VALUE'].'</p>'."\n";
                }
                
                if (isset($query) && (!empty($query))) {
                        $out .= '<h2>'.preg_replace ("/$query/i", "<span class=\"query\">$query</span>", ($tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'])).'</h2>'."\n";
                    } else {
                        $out .= '<h2>'.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'</h2>'."\n";
                }
                if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE'])) {
                    if (isset($query) && (!empty($query))) {
                        $out .= preg_replace ("/$query/i", " <span class=\"query\">$query</span>", ($tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE']))."\n";
                    } else {
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE']."\n";
                    }
                }
                if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['EXTBODY'][0]['VALUE'])) {
                    if (isset($query) && (!empty($query))) {
                        $out .= preg_replace ("/$query/i", "<span class=\"query\">$query</span> ", ($tree['COLLECTION'][0]['ENTRY'][$i]['EXTBODY'][0]['VALUE']))."\n";
                    } else {
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['EXTBODY'][0]['VALUE']."\n";
                    }
                }
                if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['KEYWORDS'][0]['VALUE'])) {
                    if (isset($query) && (!empty($query))) {
                        $out .= '<p>Keywords: '.preg_replace ("/$query/i", "<span class=\"query\">$query</span>", ($tree['COLLECTION'][0]['ENTRY'][$i]['KEYWORDS'][0]['VALUE'])).'</p>'."\n";
                    } else {
                        $out .= '<p>Keywords: '.$tree['COLLECTION'][0]['ENTRY'][$i]['KEYWORDS'][0]['VALUE'].'</p>'."\n";
                    }
                }
#                $out .= '<p>&#8212;'.$tree['COLLECTION'][0]['ENTRY'][$i]['AUTHOR'][0]['VALUE'].'</p>'."\n";
                if ($showcat == 1) {
                    $out .= '<p class="category">Category: <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['ATTRIBUTES']['REF'].'"><strong>'.$tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['VALUE'].'</strong></a>';
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['VALUE'])) {
                        $out .= ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['ATTRIBUTES']['REF'].'">';
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['VALUE'];
                        $out .= '</a>';
                    }
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['VALUE'])) {
                        $out .= ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['ATTRIBUTES']['REF'].'">';
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['VALUE'];
                        $out .= '</a>';
                    }
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['VALUE'])) {
                        $out .= ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['ATTRIBUTES']['REF'].'">';
                        $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['VALUE'];
                        $out .= '</a>';
                    }
                    $out .= '</p>'."\n";
                }
                #reference for the category to avoid duplicate entries further down
                $category = $tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['ATTRIBUTES']['REF'];
                $out .= '</div>'."\n";
                return $out;
            }
        }
    }
}

/**
* description: parsing one entry by id from notes
* requires:    
* est. | mod:  2003-08-01 | 2003-08-01
*/
function featurebyid ($tree, $id, &$category)
{
    include ("config.php");
    $status = 'publish';
    global $DOCUMENT_ROOT;
    $path = "$DOCUMENT_ROOT/".$CFGglobal['root']."/features/";
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {
        if ($id == ($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE'])) {
            if ($status == ($tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE'])) {
                echo '<div class="entry">'."\n";
                /*
                if ('Features' == ($tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['VALUE'])) {
                    $h = $i++;
                    $j = $i--;
                    if ((isset($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE']) or isset($tree['COLLECTION'][0]['ENTRY'][$j]['ID'][0]['VALUE']))) {
                        $out .= '<p class="dir">';
                        if (isset($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE'])) {
                            $out .= '&#171; <a lang="'.$tree['COLLECTION'][0]['ENTRY'][$h]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$h]['URL'][0]['VALUE'].'" title="'.$tree['COLLECTION'][0]['ENTRY'][$h]['TITLE'][0]['VALUE'].'">previous entry</a>';
                        }
                        if (isset($tree['COLLECTION'][0]['ENTRY'][$h]['ID'][0]['VALUE']) && isset($tree['COLLECTION'][0]['ENTRY'][$j]['ID'][0]['VALUE'])) {
                            $out .= ' | ';
                        }
                        if (isset($tree['COLLECTION'][0]['ENTRY'][$j]['ID'][0]['VALUE'])) {
                            $out .= '<a lang="'.$tree['COLLECTION'][0]['ENTRY'][$j]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$j]['URL'][0]['VALUE'].'" title="'.$tree['COLLECTION'][0]['ENTRY'][$j]['TITLE'][0]['VALUE'].'">next entry</a> &#187;';
                        }
                        $out .= '</p>'."\n";
                    }
                }
                */
                echo '<p class="date"><a lang="'.$tree['COLLECTION'][0]['ENTRY'][$i]['LANG'][0]['VALUE'].'" href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'" title="Permanent Link: '.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'" rel="bookmark"><span>&#8249;#&#8250;</span></a> '.$tree['COLLECTION'][0]['ENTRY'][$i]['DATE'][0]['VALUE'].'</p>'."\n";
                include($path.$id.'.html');
                    echo'<p class="category">Category: <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['ATTRIBUTES']['REF'].'"><strong>'.$tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['VALUE'].'</strong></a>';
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['VALUE'])) {
                        echo ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['ATTRIBUTES']['REF'].'">';
                        echo $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['VALUE'];
                        echo '</a>';
                    }
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['VALUE'])) {
                        echo ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['ATTRIBUTES']['REF'].'">';
                        echo $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['VALUE'];
                        echo '</a>';
                    }
                    if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['VALUE'])) {
                        echo ', <a href="category.php?'.$tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['ATTRIBUTES']['REF'].'">';
                        echo $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['VALUE'];
                        echo '</a>';
                    }
                    echo '</p>'."\n";
                #reference for the category to avoid duplicate entries further down
                $category = $tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['ATTRIBUTES']['REF'];
                echo '</div>'."\n";
            }
        }
    }
}

/**
* description: dynamical list of categories + subcategories
* requires:    
* est. | mod:  2003-07-19 | 2003-07-28
*/
function categories ($tree, $showsubcat = '0')
{
    include ("config.php");
    $status = 'publish';
    $out = '';
    $list = '';
    $patterns[0] = "/&ouml;/";
    $patterns[1] = "/&auml;/";
    $patterns[2] = "/&uuml;/";
    $patterns[3] = "/&szlig;/";
    $patterns[4] = "/ /";
    $patterns[5] = "/-/";
    $replacements[0] = "oe";
    $replacements[1] = "ae";
    $replacements[2] = "ue";
    $replacements[3] = "ss";
    $replacements[4] = "_";
    $replacements[5] = "_";
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {
        if ($status == $tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE']) {
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['VALUE'].', ';
            if ($showsubcat == 1) {
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][0]['VALUE'].', ';
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][1]['VALUE'].', ';
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['SUBCATEGORIES'][0]['SUBCAT'][2]['VALUE'].', ';
            }
        }
    }
    #now we got all the category names ...
    $out = str_replace(', , , ',', ',$out); #deleting empty strings
    $out = str_replace(', , ',', ',$out); #dele
    $catlist = explode(", ", $out); #create array
    $pop = array_pop ($catlist); #remove last (, )
    $catcount = array_count_values ($catlist); #... uniquely in an array
    #printing a nav list since name =regex=url
    if ($showsubcat == 1) {
        foreach ($catcount as $key => $value) {
            $list .= '<li><a href="/'.$CFGglobal['root'].'/category.php?'.$valueurl = preg_replace($patterns, $replacements, strtolower($key)).'">'.$key.' ['.$value.']</a></li>'."\n";
        }
    } elseif ($showsubcat == 0) {
        foreach ($catcount as $key => $value) {
            $list .= '<li><a href="/'.$CFGglobal['root'].'/category.php?'.$valueurl = preg_replace($patterns, $replacements, strtolower($key)).'">'.$key.' ['.$value.']</a></li>'."\n";
        }
    }
    return $list;
}

/**
* description: calendar
* requires:    $tree
* est. | mod:  2003-07-27 | 2003-07-31
*/
function calendar($tree, $calyear, $calmonth)
{
    $year = $calyear;
    $month = $calmonth;
    #first we get the days w/ entries from the tree
    $status = 'publish';
    $out = '';
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {
        if ($status == $tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE']) {
            if ($year == substr(($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']), 0, 4)) {
                if ($month == substr(($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']), 4, 2)) {
                    $out .= substr(($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']), 6, 2).', ';
                }
            }
        }
    }
    $catlist = explode(", ", $out); #the list of digits drom the entry ids
    $pop = array_pop ($catlist); #remove last (, )
    $catcount = array_count_values ($catlist); #counting
    $entrydays = array_keys($catcount); #array of unique digits

    #now build the calendar
    $first_of_month = mktime (0,0,0, $month, 1, $year);

    static $day_headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
    $maxdays   = date('t', $first_of_month); #number of days in the month
    $date_info = getdate($first_of_month);   #get info about the first day of the month
    $month     = $date_info['mon'];
    $year      = $date_info['year'];

    #previous and next month links
    $month_link = '<span><a href="archive.php?month=%04d%02d" title="%s month">%s</a></span>';
    list($prev_month,$prev_year) =
        split(',',strftime('%m,%Y',mktime(0,0,0,$month-1,1,$year)));
    $prev_month_link = sprintf($month_link,$prev_year,$prev_month,'previous','&#171;');

    list($next_month,$next_year) =
        split(',',strftime('%m,%Y',mktime(0,0,0,$month+1,1,$year)));
    $next_month_link = sprintf($month_link,$next_year,$next_month,'next','&#187;');

    #double digit month w/ leading zero
    if (1 == strlen($month)) {
        $month0 = str_pad($month, 2, '0', STR_PAD_LEFT);
    } else {
        $month0 = $month;
    }

    #today for the marker
    if ($year==gmdate('Y') && $month==gmdate('m')) {
        $today = gmdate('d');
    }

    $calendar  = '<table id="cal" summary="Monthly Calendar with Links to each Day&#8217;s Entries">'."\n";
    $calendar .= '<caption><div>'.$prev_month_link.'<span class="skip"> | </span><span class="this"><a href="archive.php?month='.$year.$month0.'">'.strtoupper($date_info['month']).' '.$year.'</a></span><span class="skip"> | </span>'.$next_month_link.'</div></caption>'."\n";

    #if day_heading_length is 4, the full name of the day will be printed
    $day_heading_length = 2;
    if ($day_heading_length > 0 and $day_heading_length <= 4) {
        $calendar .= '<tr>';
        foreach ($day_headings as $day_heading) {
            $calendar .= '<th abbr="'.$day_heading.'">' . 
                ($day_heading_length != 4 ? substr($day_heading, 0, $day_heading_length) : $day_heading) .
            '</th>';
        }
        $calendar .= '</tr>'."\n";
    }
    $calendar .= '<tr>';

    $weekday = $date_info['wday']; #weekday (zero based) of the first day of the month
    $day = 1; #starting day of the month
    #take care of the first "empty" days of the month
    if($weekday > 0) {
        $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>';
    }
    #print the days of the month
    while ($day <= $maxdays) {
        if ($weekday == 7) { #start a new week
            $calendar .= '</tr>'."\n".'<tr>';
            $weekday = 0;
        }
            if (1 == strlen($day)) {
                $day0 = str_pad($day, 2, '0', STR_PAD_LEFT);
            } else {
                $day0 = $day;
            }
        #open the day cell
        $calendar .= '<td>';
        #open the today marker
        if ($today == $day) {
            $calendar .= '<span title="Today">';
        }
        #look for days w/ entries
        if (in_array($day, $entrydays)) {
            #$calendar .= '<a href="archive.php?day=%04d%02d%02d" >%d</a>';
            $calendar .= '<a href="archive.php?day='.$year.$month0.$day0.'">'.$day.'</a>';
        } else {
            $calendar .= $day;
        }
        #close the today marker
        if ($today == $day) {
            $calendar .= '</span>';
        }
        #close the day cell
        $calendar .= '</td>';
        $day++;
        $weekday++;
    }
    if ($weekday != 7) {
        $calendar .= '<td colspan="' . (7 - $weekday) . '">&nbsp;</td>';
    }
    return $calendar . '</tr>'."\n".'</table>'."\n";
}

/**
* description: get months / years / days with entries
* requires:    
* est. | mod:  2003-07-27 | 2003-07-28
*/
function arclist ($tree, $range = '1')
{
    include ("config.php");
    $status = 'publish';
    $out = '';
    $list = '';
    $months = array (
    '01' => 'January',
    '02' => 'February',
    '03' => 'March',
    '04' => 'April',
    '05' => 'May',
    '06' => 'June',
    '07' => 'July',
    '08' => 'August',
    '09' => 'September',
    '10' => 'October',
    '11' => 'November',
    '12' => 'December',
    );
    
    if ($range == 1) {
        $sstr1 = 0;
        $sstr2 = 6;
        $quest = month; #query string
        $span = Months;
    } elseif ($range == 2) {
        $sstr1 = 0;
        $sstr2 = 4;
        $quest = year;
        $span = Years;
    } elseif ($range == 3) {
        $sstr1 = 6;
        $sstr2 = 2;
        $quest = day;
        $span = Days;
    }

    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {
        if ($status == $tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE']) {
            $out .= substr(($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']), $sstr1, $sstr2).', ';
        }
    }
    #all months / years / days values...
    $catlist = explode(", ", $out);
    $pop = array_pop ($catlist);
    $catcount = array_count_values ($catlist); #uniquely...
    
    $list = '<div class="entry" id="also">'."\n";
    $list .= '<h2>Archived '.$span.'</h2>'."\n";
    $list .= '<ul>'."\n";
    foreach ($catcount as $key => $value) {
        $list .= '<li><a href="/'.$CFGglobal['root'].'/archive.php?'.$quest.'='.$key.'">'.($months[(substr($key, 4, 6))].' '.(substr($key, 0, 4))).'</a> ['.$value.($value == 1 ? ' Entry' : ' Entries').']</li>'."\n";
    }
    $list .= '</ul>'."\n".'</div>'."\n";
    return $list;
}

/**
* description: entries by day in a list w/ excerpt
* requires:    
* est. | mod:  2003-07-19 | 2003-07-28
*/
function dayarc ($tree, $day)
{
    $status = 'publish';
    $out = '';
    $list = '';
    
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    $out = '<h2>Entries for '.date("l, Y-m-d", (strtotime ("$day"))).'</h2>'."\n";
    for ($i = 0; $i < $tCount; $i++) {
        if ($day == substr(($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']), 0, 8)) {
            $out .= '<div class="entry" lang="'.$tree['COLLECTION'][0]['ENTRY'][$i]['LANG'][0]['VALUE'].'">'."\n".'<p class="date"><a href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'" title="Permanent Link: '.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'" lang="'.$tree['COLLECTION'][0]['ENTRY'][$i]['LANG'][0]['VALUE'].'" rel="bookmark"><span>&#8249;#&#8250;</span></a> '.$tree['COLLECTION'][0]['ENTRY'][$i]['DATE'][0]['VALUE'].'</p>'."\n";
$out .= '<h2>'.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'</h2>'."\n";
            if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE'])) {
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE'];
            }
            if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['EXTBODY'][0]['VALUE'])) {
                $out .= '<p class="note"><a href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'">';
                $out .= 'Read more</a> &#187;</p>'."\n";
            }
        $out .= '</div>'."\n";
        }
    }
    return $out;
}

/**
* description: whole entries by month
* requires:    
* est. | mod:  2003-07-19 | 2003-07-28
*/
function montharc ($tree, $month)
{
    $status = 'publish';
    $out = '';
    $list = '';
    $months = array (
    '01' => 'January',
    '02' => 'February',
    '03' => 'March',
    '04' => 'April',
    '05' => 'May',
    '06' => 'June',
    '07' => 'July',
    '08' => 'August',
    '09' => 'September',
    '10' => 'October',
    '11' => 'November',
    '12' => 'December',
    );

    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    $out = '<h2>Entries for '.($months[(substr($month, 4, 6))].' '.(substr($month, 0, 4))).'</h2>'."\n";
    for ($i = 0; $i < $tCount; $i++) {
        if ($month == substr(($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']), 0, 6)) {
            $out .= '<div class="entry" lang="'.$tree['COLLECTION'][0]['ENTRY'][$i]['LANG'][0]['VALUE'].'">'."\n".'<p class="date"><a href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'" title="Permanent Link: '.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'" lang="'.$tree['COLLECTION'][0]['ENTRY'][$i]['LANG'][0]['VALUE'].'" rel="bookmark"><span>&#8249;#&#8250;</span></a> '.$tree['COLLECTION'][0]['ENTRY'][$i]['DATE'][0]['VALUE'].'</p>'."\n";
$out .= '<h2>'.$tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'].'</h2>'."\n";
            if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE'])) {
                $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['BODY'][0]['VALUE'];
            }
            if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['EXTBODY'][0]['VALUE'])) {
                $out .= '<p class="note"><a href="'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'].'">';
                $out .= 'Read more</a> &#187;</p>'."\n";
            }
        $out .= '</div>'."\n";
        }
    }
    return $out;
}

/**
* description: counting entries
* requires:    
* est. | mod:  2003-07-23 | 2003-07-28
*/
function entrycount ($tree)
{
    $status = 'publish';
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {
        if ($status == ($tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE'])) {
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['CATEGORY'][0]['VALUE'].', ';
        }
    }
    $catlist = explode(", ", $out); 
    $pop = array_pop ($catlist); #remove last (, )
    $catcount = array_count_values ($catlist);
    $test = array_sum($catcount); #count all
    return $test;
}

/**
* description: counting externals
* requires:    
* est. | mod:  2003-08-05 | 2003-08-05
*/
function extcount ()
{
    global $DOCUMENT_ROOT;
    include ("config.php");
    $xtree = GetXMLTree("$DOCUMENT_ROOT/".$CFGglobal['root']."/admin/external.xml");
    $count = count($xtree['COLLECTION'][0]['RECORD']);
    $xtree = '';
    return $count;
}

/**
* description: parse titles from xml-records
* requires:    
* est. | mod:  2003-08-05 | 2003-08-05
*/
function external ($xtree, $items, $showdate, $showsubject)
{
    echo  "\n".'<div class="entry">'."\n";
    echo '<ul>'."\n";
    if ($items == '') {
        $items = count($xtree['COLLECTION'][0]['RECORD']);
    }    
    for ($i = 0; $i <= $items; $i++) {

        if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:TITLE'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:TITLE'][0]['VALUE'])) {
            echo '<li>';
            if ($showsubject == 1 && isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:SUBJECT'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:SUBJECT'][0]['VALUE'])) {
                echo '<span class="runin">'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:SUBJECT'][0]['VALUE'].'</span><br />';
            }
            if ($showdate == 1) {
                echo $xtree['COLLECTION'][0]['RECORD'][$i]['DC:DATE'][0]['VALUE'].': ';
            }
            if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:TITLE'][0]['ATTRIBUTES']['URL']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:TITLE'][0]['ATTRIBUTES']['URL'])) {
                echo '<a href="'.htmlentities($xtree['COLLECTION'][0]['RECORD'][$i]['DC:TITLE'][0]['ATTRIBUTES']['URL']);
                if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:PUBLISHER'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:PUBLISHER'][0]['VALUE'])) {
                    echo '" title="'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:PUBLISHER'][0]['VALUE'].', ';
                } elseif (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:CREATOR'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:CREATOR'][0]['VALUE'])) {
                    echo '" title="'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:CREATOR'][0]['VALUE'].', ';
                }
                echo $xtree['COLLECTION'][0]['RECORD'][$i]['DC:DATE'][0]['VALUE'].'">';
            }
            echo '<strong>'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:TITLE'][0]['VALUE'].'</strong></a>';
            if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['SUBTITLE'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['SUBTITLE'][0]['VALUE'])) {
                echo ' '.$xtree['COLLECTION'][0]['RECORD'][$i]['SUBTITLE'][0]['VALUE'];
            }
            if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:DESCRIPTION'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:DESCRIPTION'][0]['VALUE'])) {
                echo '<br />'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:DESCRIPTION'][0]['VALUE'];
            }
            if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][0]['VALUE'])) {
                echo '<ul><li><a href="'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][0]['ATTRIBUTES']['URL'].'">'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][0]['VALUE'].'</a></li>';
                if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][1]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][1]['VALUE'])) {
                    echo '<li><a href="'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][1]['ATTRIBUTES']['URL'].'">'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:RELATION'][1]['VALUE'].'</a></li></ul>';
                } else {
                    echo '</ul>';
                }
            }
            if (isset($xtree['COLLECTION'][0]['RECORD'][$i]['DC:REQUIRES'][0]['VALUE']) && !empty($xtree['COLLECTION'][0]['RECORD'][$i]['DC:REQUIRES'][0]['VALUE'])) {
                echo '<ul><li><a href="'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:REQUIRES'][0]['ATTRIBUTES']['URL'].'">'.$xtree['COLLECTION'][0]['RECORD'][$i]['DC:REQUIRES'][0]['VALUE'].'</a></li></ul>';
            }
            echo '</li>'."\n";
        }
    }
    echo '</ul>'."\n";
    echo '</div>'."\n";
}

/**
* description: parse subscriptions ('blogroll')
* requires:    MySubscriptions.opml
* est. | mod:  2003-09-15 | 2003-09-15
*/

/*
$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['TEXT']
$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['DESCRIPTION']
$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['TITLE']
$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['TYPE']
$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['VERSION']
$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['HTMLURL']
$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['XMLURL']
*/

function blogroll ($opml, $items)
{
    if ($items == '') {
        $items = count($opml['OPML'][0]['BODY'][0]['OUTLINE']);
    } else {
        $items = $items - 1;
    }

    $out ='';
    $out = '<dl>'."\n";
    $out .= '<dt>reading</dt>';
    for ($z = 0; $z <= $items; $z++) {

    $href = $opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['HTMLURL'];
    $test = 'alexanderbecker.net';
    $pos = strpos($href, $test);

        if ($pos === false && isset($opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['HTMLURL']) && !empty($opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['HTMLURL'])) {
            $out .='<dd>';
            $out .= '<a href="'.$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['HTMLURL'].'"';
            if (isset($opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['DESCRIPTION']) && !empty($opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['DESCRIPTION'])) {
                $out .= ' title="'.$opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['DESCRIPTION'].'"';
            }
            $out .='>';
            if (isset($opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['TITLE']) && !empty($opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['TEXT'])) {
                $out .= $opml['OPML'][0]['BODY'][0]['OUTLINE'][$z]['ATTRIBUTES']['TITLE'];
            }
            $out .='</a></dd>';
        }
    }
    $out .= '</dl>';
    return $out;
}

?>
Return current item: Lightning Notes