<?php
    
    
    # Prepares posts
    # Must be included in pagep.php.
    # $catg & $tagg are set in ..path/index.php


    if (strpos('set-posts',basename(get_included_files()[0],'.php')) !== false)
        exit;
    

    # $n: results per page, for paginated content only
    # Cases that need to reset to home page: invalid max value, read old link is off (results per page is 0?)
    $n = (string)$cms['results_per_page'];
    
    $nn = substr($n,0,1) == '0' ? true : false;
    $n = '0'.ltrim($n,'0');
    
    if (!isset($_GET['max']) || !ctype_digit($_GET['max']) || $cms['read_old_link'] != 'on')
        $_GET['max'] = $n;
    
    
    
    #########
    
    
    
    # global c
    
    $outside = ['index','catg','tagg','fn','pn'];
    $c=0;
    foreach($outside as $val) {
        if (isset($$val)) {
            $l = $$val;
            break;
        }
        $c++;
    }
    
    
    
    
    # Print content data
    $cnt = simplexml_object('print_content.xml','l',null);
    
    # Users info
    $logfile = simplexml_object('log.xml','l',null);

    # xml post files
    $xmlfiles=[];
    
    
    include $rot.'monofiles/en_code.php';
    
    
    # Get current page path
    /*$pp = '/ ';
    
    if ($c == 3 && is_file($rot.'monofiles/autosaves/'.$fn)) {
        $postpath = getxmlpost($rot.'monofiles/autosaves/'.$fn.'.xml');
        $pp .= str_replace('/',' / ',$postpath['path']).' '.$postpath['title'];
    
    }
    
    else
        if ($c == 4 && is_file($rot.'monofiles/savedpages/'.$pn.'.xml')) {
            $pathofpage = simplexml_object($pn.'.xml','l','page');
            
            if (!is_array($pathofpage))
                $pp .= str_replace('/',' / ',$pathofpage->pageinfo->page->path).' '.$pathofpage->pageinfo->page->title;
            
        }
        
    $fpath = ['','/ category / '.$l,'/ tag / '.$l,$pp,$pp];
    $pagepath = 'Home '.$fpath[$c];
    */
    ###
    
        
    
    # $gts
    # All categories and public categories (merged as well)            
    $gc = get_categories(true);
        
    # Merged categories
    $mc = merged_categories();
    
    $gts=$gtsnames=[];

    if ($gc !== false) {
            
        $gcall = $gc['?']->mainall;
        $gcuncat = $gc['?']->uncat;
        $gcuncatindex = $gc['?']->uncatindex;
        $gcuncatlinks = $gc['?']->uncatlink;
        $gcuncatfold = $gc['?']->uncatfolder;
        
        unset($gc['?']);
            
        foreach($gc as $k=>$v) {
                
            if ($gcall == 'on' || $v[2] == 'on') {
                
                $gts[$k] = [$v[0],$v[1],$v[4],$v[5]];
                $gtsnames[$k] = $v[1];

                if (count($v[3]) > 0)
                    foreach($v[3] as $val)
                        $gts[$val] = [$v[0],$v[1],$v[4],$v[5]];

            }
        }
        
        if ($gcuncat == 'on')
            $gts['uncategorized'] = [(string)$gcuncatfold,'uncategorized',(string)$gcuncatindex,(string)$gcuncatlinks];
            


        

        # $f: total number of posts, $cpg: current subpage. Both for indexes only
    
        $f = 0;
        $cpg = 0;    

        
        
        # INDEXES info
        # $n: results per page, $c: $c[0,1,2] -> index,catg,tagg
        # Needed only in case of INDEXES (home,catg,tagg) & print_posts()
        # Some of the info is used later in paginate.php
        if (!$nn || ($n > 0 && ($c == 2 || $c == 1))) {

        
            $array_xml=$array_ptime=$array_alpha=[];



                        
            # Turbo mode 1 XML file - 2.4v 
            $postinfo=[];
            $heavy = simplexml_object('autosaves.xml','l','post');
            
            
            if (!is_array($heavy)) {
                
                foreach($heavy->savedpost as $file) {
                    foreach($file->postinfo->post->children() as $k=>$v)
                        $postinfo[$k] = (string)$v;
                
                    $xmlfiles[] = $postinfo;
                }
            }
            
        
            else {
            
            
                # Multiple post files
                $ndi = new DirectoryIterator ($rot.'monofiles/autosaves/');
                
                foreach($ndi as $file) {

                    $fext = $file->getExtension();
                    $fname = $file->getFilename(); #i.e 9fr94j.xml

                    if ($fext == 'xml' && $fname != 'autosaves.xml') {
                    
                        $post = getxmlpost($rot.'monofiles/autosaves/'.$fname);
                        
                        $post['file'] = $fname;
                        $xmlfiles[] = $post;

                    }
                }
            }





            
            $cc=0;
            foreach($xmlfiles as $post) {
                
                
                
                $nu = substr($post['file'],-2,2);
                
                if ($post['type'] != 'Draft' && $nu != 'nu' ) {



                    # post's category id
                    $id = $post['catid'];
                    
                    # Tags
                    $alltags = explode(',',$post['tags']);
                    
                    # Adding the filename to the xml data
                    #$post['file'] = $file;
            
                    # merged category
                    if (isset($mc[$id])) {
                    
                        # write the merged id in $gc
                        $gc[$id][1] = $gc[$mc[$id]][1];
                        
                        # change id
                        $id = $mc[$id];
                    }
                    
                    
                    # $p -> category name
                    if (!isset($gc[$id]))
                        $id = $p = 'uncategorized';
                    else
                        $p = $gc[$id][1];


                    # First condition to publish content. For index pages only.
                    # $gc : all categories
                    # $gts : public categories
                    # $c : 0 home page , 1 category index , 2 tag index
                    # Uncategorized posts have their own settings.


                    if (($c == 1 && $gc[$id][1] == $l) || (($c == 0 || ($c == 2 && array_search($l,$alltags,true) !== false)) && isset($gts[$id]))) {
                    
                        # Not public or set in future date
                        if ($post['ptime'] < time()) {
                            
                            $array_xml[] = $cc;
                            $array_ptime[] = (int)$post['ptime'];
                            $array_alpha[] = strtolower($post['title']).$cc;
                            $f++;
                            $cc++;
                            $array_index[] = $post;

                        }
                    }
                }
            }
    


            
            # navinfo calculations
            # transferred from paginate.php 2.4
            
            $paginopt = simplexml_object('paginate.xml','l',null);
            $menutype = is_array($paginopt) ? 2 : $paginopt->websitepagination->type;

            $maxall = $menutype == 3 ? true : is_int($_GET['max']/$n);
            $finallink = ceil($f/$n)*$n;

            if ($maxall && $_GET['max'] > 0) {

                if (abs($_GET['max']) > $f)
                    $_GET['max'] = $finallink;

                $ofp = $_GET['max'];
            }
            
            else
                $ofp = $n;



            # next and previous page values
            $nextlink = $ofp + $n;
            $prevlink = $ofp - $n;
            
            # results on a single page
            $first = $ofp - $n < 0 ? 0 : $ofp - $n;
            $last = $ofp;
            
            # Total number of pages
            $tnp = $finallink/$n;
            
            # Menu size
            $nol = 1;
            
            
            # current page ($cpg)
            $cpg = $ofp/$n;
            if ($cpg == 0)
                $cpg = 1;

            
            
            # The distance to page 1
            $fnl = $cpg-$nol <= 0 ? 1 : $cpg-$nol;

            # Nav items
            $firstpage = $lastpage = $nextpg = $prevpg = '';
            
            $hlp = '&nbsp;&hellip;&nbsp;';
            if ($cpg-$nol == 2)
                $hlp = '';

            ### ###
            
            
            
        }
    
    
    }
    
    
    # Meta data
    $title = $cms['website_title'];
    $meta_description = $cms['website_description'];

    if ($c == 1 || $c == 2) {
        $curtitle = $outside[$c];
        $title .= ' - '.$$curtitle;
    }
    
    
    
    # page_content() - print page content
    # $value = '',title,description,content,path,file
    function page_content($value=null) {
    
    
        global $c;
        
        
        if ($c == 4) {
        
        
            global $pn,$incp;
        
            $xmlfile = simplexml_object($pn.'.xml','l','page');
            $title = load_xml($xmlfile->pageinfo->page->title);
            $description = cut_content((string)$xmlfile->pageinfo->page->description,160,'strip');
            $description = str_replace('"','\'',$description);
            $content = file_get_contents($incp.'monofiles/savedpages/'.$pn.'.htm');
            $path = $xmlfile->pageinfo->page->path;
            $file = $xmlfile->pageinfo->page->filename;
        
            if ($value == null)
                $pginfo = '<h1>'.$title.'</h1>'.$content;
            else
                $pginfo = $$value;
        
            return $pginfo;
        }
    
    }
    

    ####################
    
    # Post
    # $elem = '',title,meta_des,content,date,category,tags,author,file
    function post_elem($elem=null) {
    
        
        global $cms,$c;
        
        
        if ($c == 3) {
            
            global $fn;
                
            $loc = '../../monofiles/';
            $xmlfile = getxmlpost($loc.'autosaves/'.$fn); #support older version without prepost.php
            
            $post = ['title'=>'','meta_des'=>'','content'=>'','date'=>'','category'=>'','tags'=>'','author'=>'','file'=>$xmlfile['filename']];
            
            $title = load_xml($xmlfile['title']);
            $post['title'] = $title;
            #$meta_description = (string)$xmlfile['description'];
            #$meta_description = cut_content($meta_description,160,'strip');
            $htm_file = $loc.'autosaves/content/'.basename($fn,'.xml').'.htm';

            
            
            # content
            if (is_file($htm_file)) {
            
                $content = file_get_contents($htm_file);

                if ($cms['exc'] == 'on')
                    $post['content'] = str_replace('<hr id="monreadmoreHr">','',$content);

                $mdes = cut_content($content,160,'strip');
                $mdes = str_replace('"','\'',$mdes);
                $post['meta_des'] = $mdes;
                $post['content'] = $content;
            }
            
            

            # date
            if (isset($xmlfile['ptime'])) {

                $form = (string)$cms['show_date'];
                $fpdate = (int)$xmlfile['ptime'];
                
                if ($form != 'none(turn off)') {
                    $post_date = date($form,$fpdate);
                    $post['date'] = $post_date;
                }

            }
            
            

            # tags
            if ($cms['show_tags'] == 'on') {
            
                if ($xmlfile['tags'] != '') {

                    $taginfo = load_xml($xmlfile['tags']);
                    $sep = explode(',',$taginfo);
                    
                    $tags = '';
                    foreach($sep as $val) {
                        
                        if ($cms['tagstext'] != 'on')
                            $tags .= '<a href="../../tags/'.str_replace(' ','-',mb_strtolower($val,'UTF-8')).'" class="tagged">'.$val.'</a> '.PHP_EOL;
                        else 
                            $tags .= '<span class="tagged">'.$val.'</span> '.PHP_EOL;
                        
                    }
                    
                    $post['tags'] = $tags;
                }
            }



            # category
            if ($cms['show_category'] == 'on') {
                
                $ctgs = get_categories();
                $cid = $xmlfile['catid'];
                
                if (!isset($ctgs[$cid])) {            
                    $mc = merged_categories();
                    $cid = isset($mc[$cid]) ? $mc[$cid] : 'uncategorized';
                }

                
                if (isset($ctgs[$cid])) {
                    
                    # quick fix
                    $catfold = $ctgs[$cid][0];
                    if (substr($catfold,-1) != '/')
                        $catfold .= '/';
                        
                    if (is_file('../../'.$catfold.'index.php'))
                        $ctgr = $ctgs[$cid][4] == 'on'? '<a href="../../'.$catfold.'" class="catl">'.$ctgs[$cid][1].'</a>' : '<span class="catl">'.$ctgs[$cid][1].'</span>';
                }
                
                else 
                    $ctgr = '';
                    
                $post['category'] = $ctgr;
            }



            # author
            if ($cms['sign_posts'] == 'on') {
                
                $author = '';
                $created = $xmlfile['createdby'];
                $edited = $xmlfile['editedby'];

                global $logfile;
                
                foreach ($logfile->user as $userinfo) {

                    if ((string)$userinfo->userID == $created) {
                        $author = $userinfo->editorname;
                        
                        if ($edited != '' && (string)$edited != (string)$created) {
                            
                            foreach ($logfile->user as $userdata) {
                                
                                if ((string)$userdata->userID == $edited) {
                                    $author .= ' ,&nbsp;'.$userdata->editorname;
                                    break;
                                }
                            }
                        }
                        
                        break;
                    }
                }
                $post['author'] = $author;
            }
            
            if ($elem != null)
                $post = $post[$elem];
            
            return $post;
        }
        
        else
            return false;
    
    }
    
    # END ===
        

    # print post html elements and style
    function post_content() {

        global $c;
        
        if ($c == 3) {
            
            global $postinfo;
            
            $inc = ['date','title','content','category','author','tags'];
            $post='';
            foreach($inc as $v)
                $post .= $postinfo[$v].'&nbsp;';

            return $post;
        }
        
        
        else 
            return false;
    }
    
    
    
    # Post and Page info
    if ($c == 3) {
    
        $postinfo = post_elem();
        
        $title .= ' - '.$postinfo['title'];
        $meta_description = $postinfo['meta_des'];
    }


    if ($c == 4) {
         $title .= ' - '.page_content('title');
        $meta_description = page_content('description');
    }    

    
    
    
    
    
    # =====
    
    # print_posts()
    # xml file : print_content.xml
    
    # =====
    
    function print_posts($content=null) {

        

        global $cms,$rot,$c,$xmlfiles,$gc,$mc,$gts,$cpg,$cnt,$logfile;
        
        # $gc -> [category id => [0=>folder,1=>name,2=>main publish,3=>index page,4=>link to posts]] 
        # $gts -> public categories
        # $content -> print_content.xml -> name
        
        
        
        
        if ($xmlfiles == null ) {
            
            
            $postinfo=$xmlfiles=[];    
            $heavy = simplexml_object('autosaves.xml','l','post');
            
            
            if (!is_array($heavy)) {
                
                foreach($heavy->savedpost as $file) {
                    foreach($file->postinfo->post->children() as $k=>$v) {
                        $postinfo[$k] = (string)$v;
                        $postinfo['nu'] = '';
                    }
                    
                    $xmlfiles[] = $postinfo;
                }
            }
            
            
            else {

                # Multiple xml post files
                $ndi = new DirectoryIterator ($rot.'monofiles/autosaves/');
                
                foreach($ndi as $file) {

                    $fext = $file->getExtension(); # .xml
                    $fname = $file->getFilename(); # 9fr94j.xml

                    if ($fext == 'xml' && $fname != 'autosaves.xml') {
                        
                        $post = getxmlpost($rot.'monofiles/autosaves/'.$fname);
                            
                        $post['nu'] = substr(basename($fname,'.xml'),-2,2);
                        $post['file'] = $fname;
                        $xmlfiles[] = $post;

                    }
                }
            }

            
            $GLOBALS['xmlfiles'];
        
        }
        
        
        
        
        # print_content.xml 
        $cntc=0;
        foreach($cnt->content as $cntv) {
            if ($cntv->name == $content) {
                
                $r = $cntv->attributes();
                if (!isset($r['status']) || $r['status'] != 'off') {
                    $cx = $cnt->content[$cntc];
                    
                    break;
                }
            }
            $cntc++;
                # put in array
                /*$a=[];
                foreach($cntv[$cntc] as $cnnt=>$cnl)
                    if ($cnnt == 'label')
                        foreach($cntv->label->children() as $kl=>$vl)
                            $a['label'][$kl] = (string)$vl;
                    else
                        $a[$cnnt] = (string)$cnl;
                */            
        }
        
        if (isset($cx)) {
        
        
            
        
            $categories = explode(',',$cx->categories);
            $tags = explode(',',$cx->tags);
            $paginc = explode(',',$cx->paginc);
            $inc = explode(',',$cx->inc);
            $cxexc = explode(',',$cx->exc);
            $sign = $cx->sign;
            $udates = $cx->udate;
            $force = $cx->force;
            $cxtlinks = $cms['tagstext'] == 'on' ? 'off' : $cx->tlinks;
            
            
            # explode function can return an array with a single empty value
            if (count($tags) == 1 && $tags[0] == '')
                $tags=[];
                
            if (count($cxexc) == 1)
                $cxexc[1] = '';
            
                
            for($i=0; $i<5; $i++) {
                if (!isset($paginc[$i]))
                    $paginc[$i] = '';
                if (!isset($inc[$i]))
                    $inc[$i] = '';
            }
            
            

            if (count($xmlfiles) > 0) {
        
                
                # Prepare posts
                $arr_pos=[];



                # $paginc depends on $inc in case it is empty
                if ($paginc[$c] == '')
                    $paginc[$c] = $inc[$c];



                ### Second condition to publish content
                # Determine to post or not based on $inc and $paginc values
                if ( ($inc[$c] != 'off' && $cpg < 2) || ($paginc[$c] != 'off' && $cpg > 1) )  {
                
                            
                
                
                
                    # LOOP START ###
                    
                    
                    print '<div id="'.$content.'">'.PHP_EOL;
                    $ca=1;
                    $cb=0;
                    foreach($xmlfiles as $post) {

                        
                        # Ignore Drafts or posts set in future date
                        if ($post['type'] == 'Draft' || $post['ptime'] > time()) {
                            $cb++;
                            continue;
                        }
                        
                        if (!isset($nu))
                            $nu = substr(basename($post['file'],'.xml'),-2,2);
                        
                        
                        # post tags [] 
                        $alltags = explode(',',$post['tags']);


                        # Limit results based on date or age
                        #$datelimit = 01/28/2020;
                        #$maxage = x*60*60*24;// age of a post in days

                            
                        $id = $post['catid'];
                            
                        if (isset($mc[$id])) {
                        
                            # write the merged id in $gc(?)
                            # $gc[$id][1] = $gc[$mc[$id]][1];
                                
                            # change id
                            $id = $mc[$id];
                        }
                        
                        
    
                        # ($p -> category name) 
                        if (!isset($gc[$id]))
                            $id = $p = 'uncategorized';
                        else 
                            $p = $gc[$id][1];
                            
                        


                        # post tags (string)
                        $t = $post['tags'];
     
     
                        ### Last condition to print content - categories and tags
                        # Can be both empty, one empty one found or both found | $force will force the category(-ies) to publish
                        if ((empty($categories) || (in_array($p,$categories) && (isset($gts[$id]) || ($force == 'on' && isset($gc[$id])))) ) && (empty($tags) || array_intersect($tags,$alltags))) {

                            
                            $arr_pos[$p][0][] = $cb;# a position inside an array
                            $arr_pos[$p][1][] = (int)$post['ptime'];
                            $arr_pos[$p][2][] = strtolower($post['title']).$ca;
                                
                            # save in categories
                            # $ar = ['cat312'=>[0=>[1,2,6,12,4,5,... positions of posts inside $xmlfiles ],1=>['ptime1','ptime2'],2=>['title1','title2']], 'cat244'=>[...]];
                            
                                    
                            $ca++;
                        }
                        
                        $cb++;
                    }
                    

                    
                    # if $cx->sortcat is on, categories will be posted one after the other, in the order they are written inside the xml file($categories)            
                    if ($cx->sortcat == 'on') {
                        $array_post=[];
                        foreach($categories as $v)
                            if (isset($arr_pos[$v]))
                                $array_post[] = $arr_pos[$v];
                    }
                    # sorted categories based on xml order look like this
                    # $ar = ['cat1'=>[0=>[1,2],1=>['ptime1','ptime2'],2=>['title1','title2']], 'cat2'=>[...]];

                    else {
                        #print_r($arr_pos);
                        $array_post=[0=>[],1=>[],2=>[]];
                        foreach($arr_pos as $vn)
                            foreach ($vn as $k=>$cvn)
                                $array_post[$k] = array_merge($array_post[$k],$vn[$k]);
                        
                        
                        $array_post = [$array_post];
                        # combined categories for mixed results 
                        #$ar = [0=>[0=>[1,2],1=>['ptime1','ptime2'],2=>['title1','title2']]];
                        
                    }


                    # Sort the given array [0->1,1->ptime,2->title]. works for both $cx->sortcat on | off         
                    $final_posts=[];
                    foreach ($array_post as $vn) {
                        if ($cx->sort != 'alpha') {
                            $arp = array_combine($vn[1],$vn[0]);
                            krsort($arp);
                        }
                        else {
                            $arp = array_combine($vn[2],$vn[0]);
                            ksort($arp);
                        }
                            
                        if ($cx->reverse == 'on')
                            $arp = array_reverse($arp);
                            
                        $final_posts = array_merge($final_posts,$arp);
                    }
                        
                
                        
                    


                    
                    # start print
                
                    $cb=0;
                    foreach($final_posts as $fpost) {

                        
                        $xmlpost = ($xmlfiles[$fpost]);


                        # post info
                        $file = $xmlpost['file'];
                        $cid = $xmlpost['catid'];
                        
                        
                        # merged category
                        if (isset($mc[$cid]))
                            $cid = $mc[$cid];
                        
                        
                        # category id does not exist
                        if (!isset($gc[$cid]))
                            $cid = 'uncategorized';
                        
                        
                        
                        ###
                        
                        
                        $path = $xmlpost['path'];
                        $link = $xmlpost['filename'];

                            
                        # Post title
                        if ($cx->title != 'off') {
        
                            $postl = isset($gc[$cid]) && $gc[$cid][5] != 'off' ? '<a href="'.$rot.$path.$link.'">'.load_xml($xmlpost['title']).'</a>' : load_xml($xmlpost['title']);
                            $ptitle = '<h2>'.$postl.'</h2>';
            
                        }
                        else
                            $ptitle = '';
                        
                        
                        
                        # Post content, excerpt limit
                        $htm_file = $rot.'monofiles/autosaves/content/'.basename($file,'.xml').'.htm';
                        $content = is_file($htm_file) ? file_get_contents($htm_file) : ' ';
                        
                        # An <hr id="monreademoreHr"> element is inserted to indicate the excerpt limit.
                    
                        $xmlexc = $xmlpost['excerpt'];
                        

                        if ($cx->exc != '' && $cx->exc != 'on') {
                            
                            
                            if (is_numeric($cxexc[0]) && $cxexc[0] > 0)
                                $excerpt = cut_content($content,$cxexc[0],'null');

                            
                            elseif (is_numeric($cxexc[0]) && $cxexc[0] == 0)
                                $excerpt = $content;
                            
                            else
                                $excerpt = '';
                            
                        }
                        
                        else
                            $excerpt = $xmlexc == 'none' ? $content : cut_content($content,(int)$xmlexc,'null');
                    

                    
                                    
                        # Find tags
                        if ($cx->stag == 'on') {
                            
                            if ($xmlpost['tags'] != '') {
                            
                                $alltags = explode(',',$xmlpost['tags']);

                                foreach($alltags as $val) {

                                    $tagrot = $rot.'tags/'.str_replace(' ','-',mb_strtolower($val));
                                    $newtg = $cxtlinks != 'off' ? '<a href="'.$tagrot.'" class="tagword">'.$val.'</a> ' : '<span class="tagword">'.$val.'</span> ';
                                    $tgs = isset($tgs) ? $tgs.$newtg : $newtg;
                                    
                                }
                            }
                        }
                    
                    
                    

                        # the author
                        $xmlsign = $sign == '' ? 'off' : $sign; 
                        $author = '';
                        
                        
                         
                        if ($xmlsign == 'on' ) {
                        
                            $created = $xmlpost['createdby'];
                            $edited = $xmlpost['editedby'];

                            foreach ($logfile->user as $userinfo) {
            
                                if ((string)$userinfo->userID == $created) {
                                    $author = $userinfo->editorname;
                                
                                    if ($edited != '' && (string)$edited != (string)$created) {
                                    
                                        foreach ($logfile->user as $userdata) {
                                        
                                            if ((string)$userdata->userID == $edited) {
                                                $author .= ' ,&nbsp;'.$userdata->editorname;
                                                break;
                                            }
                                        }
                                    }
                                
                                    break;
                                }
                            }
                            
                            $author = '<div class="post-author">'.$cx->label->sig.$author.'</div>';
                    
                        }
                    
                    
                    
                    #####
                    
                    
                        # date
                        if (!empty($xmlpost['ptime'])) {
                            
                            $fpdate = (int)$xmlpost['ptime'];
                            if ($cx->date != 'off' && $cx->date != '') {
                                $date = (string)$cx->date;
                                $post_date = '<span class="post-date">'.date($date,$fpdate).'</span>';
                            }
                        
                        }        
                        
                    
                    
                    
                        # category prepare
                        # $gts [id=>[0=>folder,1=>name,2=>indexes,3=>post links]]
                        
                        # Also correct(?) : if (isset($gts[$cid]) || $force == 'on' && isset($gc[$cid]))

                        if (isset($gts[$cid]) || ($force == 'on' && isset($gc[$cid]))) {
                        
                            $category_name = $gc[$cid][1];
                            $catfold = $gc[$cid][0];
                            
                            
                            if ($gc[$cid][4] == 'on' )
                                $category_name = '<a href="'.$rot.$catfold.'">'.$category_name.'</a>';
                    
                        }
                        
                        else
                            $category_name = '';
                    
                        
                        
                        
                        # labels -> cat=>category ,tag=>tag, sign=>sign, read=>read more 
                    
                        # START post
                        # date
                        if (isset($post_date))
                            if ($cb == 0 || ($udates == 'off' || $keepdate != $post_date))
                                echo $post_date.PHP_EOL;
                        
                        # title
                        echo '<div class="post">'.$ptitle.PHP_EOL;
                        
                        #excerpt
                        if ($excerpt != '') {
                        
                            echo '<div class="content-text">'.$excerpt.'</div>';
                        
                            if ($cxexc[1] != 'off' && ($excerpt != $content && $gc[$cid][4] == 'on'))
                                echo '<div><a class="monmore" href="'.$rot.$path.$link.'">'.$cx->label->read.'</a></div>';
                        }
                        
                        if ($cx->scat == 'off' && $sign == 'off' && $cx->stag == 'off')
                            print '</div>';
                        
                        else {
                        
                            # author sign
                            print '<div class="postinfo">'.PHP_EOL.$author.PHP_EOL;
                            
                            # category
                            if ($cx->scat == 'on')
                                echo '<div class="post-category">'.$cx->label->cat.$category_name.'</div>';
                              
                            # tags
                            if (isset($tgs))
                                echo '<div class="post-tags">'.$cx->label->tag.$tgs.'</div>';
                            
                            print '</div>'.PHP_EOL.'</div>';
                        }
                        
                        
                        

                        # END post
                        
                        
                        
                        # unset tags when inside a loop
                        unset($tgs);
                    
                        
                        $keepdate = isset($post_date) ? $post_date : '';
                        
                        $cb++;
                        
                        if ($cx->limit != 0 && $cx->limit == $cb)
                            break;
                    
                    }
                    
                print '</div>';

                return true;
                
                
                }
            }
        }
    }

?>