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

/**
* description: encoding fun
* requires:    
* est. | mod:  2003-07-17 | 2003-07-22
*/
function pp_ascii2html($s, $para = '1', $lang) {
    if ($para == 1) {
        #$s = htmlspecialchars($s,ENT_NOQUOTES);
        $s = htmlentities($s);
        $grafs = split("\n\r",$s);
        for ($i = 0, $j = count($grafs); $i < $j; $i++) {
            // Link to what seem to be http or ftp URLs
            #$grafs[$i] = preg_replace('/((ht|f)tp:\/\/[^\s&]+)/','<a href="$1">$1</a>',$grafs[$i]);
            // Link to email addresses
            $grafs[$i] = preg_replace('/[^@\s]+@([^\s&]+)/','<a href="mailto:$1">$1</a>',$grafs[$i]);
            #$grafs[$i] = preg_replace('/[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/i','<a href="mailto:$1">$1</a>',$grafs[$i]);
            // Begin with a new paragraph 
            $grafs[$i] = trim($grafs[$i]);
            $grafs[$i] = '<p>'.$grafs[$i].'</p>';
            $grafs[$i] = trim($grafs[$i]);
            $grafs[$i] = preg_replace('(&lt;)', '<',$grafs[$i]);
            $grafs[$i] = preg_replace('(&gt;)', '>',$grafs[$i]);
            $grafs[$i] = preg_replace('(---)', '&#8212;',$grafs[$i]);
            $grafs[$i] = preg_replace('(--)', '&#8211;',$grafs[$i]);
            $grafs[$i] = preg_replace('(\.\.\.)', '&#8230;',$grafs[$i]);
                $grafs[$i] = str_replace('&quot;','"',$grafs[$i]);
                $grafs[$i] = str_replace('\'',"'",$grafs[$i]);
/*            if ($lang == 'en') {
                $grafs[$i] = str_replace(' \&quot;',' &#8220;',$grafs[$i]);
                $grafs[$i] = str_replace('\&quot; ','&#8221; ',$grafs[$i]);
                $grafs[$i] = str_replace(" \'",' &#8216;',$grafs[$i]);
                $grafs[$i] = str_replace("\' ",'&#8217; ',$grafs[$i]);
                $grafs[$i] = str_replace("\'",'&#8217;',$grafs[$i]);
            } elseif ($lang == 'de') {
                $grafs[$i] = str_replace(' \&quot;',' &#8222;',$grafs[$i]);
                $grafs[$i] = str_replace('\&quot; ','&#8221; ',$grafs[$i]);
                $grafs[$i] = str_replace(" \'",' &#8218;',$grafs[$i]);
                $grafs[$i] = str_replace("\' ",'&#8216; ',$grafs[$i]);
                $grafs[$i] = str_replace("\'",'&#8217;' ,$grafs[$i]);
            }*/
        }
        return join("\n\r",$grafs);
    } elseif ($para == 0) {
        return $s;
    }
}

/**
* description: generates a filename from the title element
* requires:    
* est. | mod:  2003-07-23 | 2003-07-23
*/
function title2url($title, $words) {

$title = split(" ", trim($title));

$title = array_slice ($title, 0, $words);
$title = join (' ',$title);

    $patterns[0] = "/&ouml;/";
    $patterns[1] = "/&auml;/";
    $patterns[2] = "/&uuml;/";
    $patterns[3] = "/&szlig;/";
    $patterns[4] = "/&quot;/";
    $patterns[5] = "/ /";
    $patterns[6] = "/-/";
    $patterns[7] = "/,/";
    $patterns[8] = "/;/";
    $patterns[9] = "/\?/";
    $patterns[10] = "/!/";
    $patterns[11] = "/'/";
    $patterns[12] = "/:/";
    $patterns[13] = "/\./";
    
    $replacements[0] = "oe";
    $replacements[1] = "ae";
    $replacements[2] = "ue";
    $replacements[3] = "ss";
    $replacements[4] = "";
    $replacements[5] = "_";
    $replacements[6] = "_";
    $replacements[7] = "";
    $replacements[8] = "";
    $replacements[9] = "";
    $replacements[10] = "";
    $replacements[11] = "";
    $replacements[12] = "";
    $replacements[13] = "_";

$title = strtolower($title);
$titleurl = preg_replace($patterns, $replacements, ($title));

return $titleurl;
}

/**
* description: get last two segments of host name from URL
* requires:    
* est. | mod:  2003-07-27 | 2003-07-27
*/
function getdomain($url)
{
    // patterns we need to match
    $pattern_hostname = '/^(http:\/\/)?([^\/]+)/i';
    $pattern_domain   = '/[^\.\/]+\.[^\.\/]+(\.[^\.\/]{2})?$/';
    // extract hostname from URL string
    preg_match($pattern_hostname, $url, $matches);
    $hostname = $matches[2];
    // extract sld.tld(.cctld if exists)
    preg_match($pattern_domain, $hostname, $matches);
    $domain = $matches[0];
    return $domain;
}

/**
* description: parsing a stack of whole entries from notes
* requires:    
* est. | mod:  2003-07-21 | 2003-07-21
*/
function entries2items ($tree, $entries, $status = 'publish')
{
    include ("config.php");
    $tCount = count($tree['COLLECTION'][0]['ENTRY']);
    for ($i = 0; $i < $tCount; $i++) {

        if (!empty($tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE']) && ($status == $tree['COLLECTION'][0]['ENTRY'][$i]['STATUS'][0]['VALUE'])) {
            $out = '';
            $out = '<item>'."\n";

            $out .= '<id>';
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['ID'][0]['VALUE'];
            $out .= '</id>'."\n";

            $out .= '<author>';
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['AUTHOR'][0]['VALUE'];
            $out .= '</author>'."\n";
            
            $out .= '<date>';
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['DATE'][0]['VALUE'];
            $out .= '</date>'."\n";

            $out .= '<title><![CDATA[';
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['TITLE'][0]['VALUE'];
            $out .= ']]></title>'."\n";

            $out .= '<description><![CDATA[';
            $out .= $tree['COLLECTION'][0]['ENTRY'][$i]['EXCERPT'][0]['VALUE'];
            $out .= ']]></description>'."\n";

            $out .= '<url>';
            $out .= $CFGglobal['domain'].'/'.$CFGglobal['root'].'/'.$tree['COLLECTION'][0]['ENTRY'][$i]['URL'][0]['VALUE'];
            $out .= '</url>'."\n";
            
            $out .= '</item>'."\n";
            return htmlentities($out);
        }
    }
}



?>
Return current item: Lightning Notes