Location: PHPKode > projects > RAMUI WEBBLOG > fw_blog/include/menu.php
<?php
class clsmenu
{
protected $prefix;
function __construct($prefix){$this->prefix=$prefix;}
protected function topfive()
{
        $menu='';
        $last7=time()-7*24*60*60;
        $query="SELECT ".$this->prefix."webstat.pagename, ".$this->prefix."postinf.title FROM ".$this->prefix."webstat, ".$this->prefix."postinf WHERE ";
        $query.=$this->prefix."postinf.publish = 'Y' AND ".$this->prefix."postinf.addtomenu = 'Y' AND ";
        $query.=$this->prefix."webstat.date > ".$last7." AND ".$this->prefix."postinf.pagename = ".$this->prefix."webstat.pagename GROUP BY ".$this->prefix."webstat.pagename ORDER BY SUM(".$this->prefix."webstat.minutes) DESC LIMIT 0, 5";
        $result = @mysql_query($query);
        while($row = @mysql_fetch_array($result, MYSQL_ASSOC)){$menu.='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
        @mysql_free_result($result);
        return $menu;
}
}
class simplemenu extends clsmenu
{
public function menu()
{
        $folders=array();
        $query="SELECT pagename, title FROM ".$this->prefix."postinf WHERE publish = 'Y' AND addtomenu = 'Y' ORDER BY date Desc LIMIT 0,100";
        $result = @mysql_query($query);
        while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
        {
                if(($pos=strpos($row['pagename'],'/'))!==false){
                   $folder_name=substr($row['pagename'],0,$pos);
                   if(array_key_exists($folder_name,$folders)==false){$folders[$folder_name]='<li class="separator"><span>'.str_replace('_',' ',$folder_name).'</span></li>';}
                   $folders[$folder_name].='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
                else{
                   if(array_key_exists('Document root:',$folders)==false){$folders['Document root:']='<li class="separator"><span>Document root:</span></li>';}
                   $folders['Document root:'].='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
        }
        @mysql_free_result($result);
        $menu='<div id="fw_menu"><ul>';
        foreach($folders as $f){$menu.=$f;}
        return $menu.'</ul></div>';
}
}
class ajaxmenu extends clsmenu
{
public function menu()
{
        $search=(isset($_COOKIE['fw_menu'])? $_COOKIE['fw_menu'] : '');
        $query="SELECT pagename, title FROM ".$this->prefix."postinf WHERE publish = 'Y' AND addtomenu = 'Y' ORDER BY date DESC LIMIT 0, 500";
        $result = @mysql_query($query);
        $folders=array();
        $files=array();
        $recentfiles=array();
        $webroot=array();
        while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
        {
        //Add recent files.
                if(count($recentfiles)<5){$recentfiles[]='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
        //Add directory listing.
                if(($pos=strpos($row['pagename'],'/'))!==false){
                   $folder_name=substr($row['pagename'],0,$pos);
                   if(in_array($folder_name,$folders)==false){$folders[]=$folder_name;}
                }
                else{$webroot[]='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
                if(strpos($row['pagename'],$search.'/')===0){$files[]='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
        }
        $menu=$this->topfive();
        if($menu!=''){$menu='<li><span class="separator">Top five:</span><ul>'.$menu.'</ul></li>';}
        $cell_index=0;
        $open_index=0;
        $submit_url='http://'.getenv('HTTP_HOST').fw_get_docroot().'fw_blog/admin/';
        foreach($folders as $folder){
                $cell_index++;
                $menu.='<li id="fw_ajaxmenuheader'.$cell_index.'" class="'.(($search===$folder)? 'show' : 'hide').'"><div class="root" onmouseover="this.className=\'root_hover\'" onmouseout="this.className=\'root\'" onclick="javascript:fw_getmenu(\''.$submit_url.'\',\''.$folder.'\',\''.$cell_index.'\')">'.str_replace('_',' ',$folder).'</div><div id="fw_ajaxmenucell'.$cell_index.'" style="font-size:1px;clear:both; padding:0;">';
                if($search===$folder){
                   $menu.='<ul>';
                   foreach($files as $file){$menu.=$file;}
                   $menu.='</ul>';
                   $open_index=$cell_index;
                }$menu.='</div></li>';
        }
        $cell_index++;
        if(!empty($webroot)){
                $menu.='<li  class="'.(($search===$folder)? 'show' : 'hide').'" id="fw_ajaxmenuheader'.$cell_index.'"><div class="root"  onmouseover="this.className=\'root_hover\'" onmouseout="this.className=\'root\'" onclick="javascript:fw_getmenu(\''.$submit_url.'\',\'Document root:\',\''.$cell_index.'\')">Document root:</div><div id="fw_ajaxmenucell'.$cell_index.'" style="font-size:1px;clear:both; padding:0;">';
                if($search==='Document root:'){
                   $menu.='<ul>';
                   foreach($webroot as $file){$menu.=$file;}
                   $menu.='</ul>';
                   $open_index=$cell_index;
                }
                $menu.='</div></li>';
        }
        $menu.='<li><span class="separator">Recent files:</span><ul>';
        $menu.='<div style="clear:both; padding:0;">';
        foreach($recentfiles as $file){$menu.=$file;}
        $menu.='</div></ul></li></ul><input type="hidden" id="fw_menuopenindex" name="menuopenindex" value="'.$open_index.'"></input></div>';
        $menu='<div id="fw_ajaxmenu"><ul>'.$menu;
        return $menu;
}
}
class javascriptmenu extends clsmenu
{
private function fw_list_menu(&$parent,$item,$title,$pagename)
{
         $pos=strpos($item,'/');
         if($pos===false){$parent[]='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$pagename.'.html">'.$title.'</a></li>'; return;}
         else{
                $dir=substr($item,0,$pos);
                $newitem=substr($item,$pos+1);
                if(!array_key_exists($dir,$parent)){$parent[$dir]=array();}
                $this->fw_list_menu($parent[$dir],$newitem,$title,$pagename);
         }
}
private function arrange(&$array,$folder)
{
         $str='';
         foreach($array as $key => $item)
         {
              if(!is_array($item)){$str.=$item;}
              else{
                    $str.='<li class="hide" onmouseover="this.className=\'show\'" onmouseout="this.className=\'hide\'"><a class="root" href="http://'.getenv('HTTP_HOST').fw_get_docroot().$folder.'/'.$key.'/index.html">'.$key.'</a><ul>';
                    $str.=$this->arrange($item,$folder.'/'.$key);}
         }
         $str.='</ul></li>';
         return $str;
}
public function menu()
{
        $folders=array();
        $recentfiles='';
        $docroot='';
        $query="SELECT pagename, title FROM ".$this->prefix."postinf WHERE publish = 'Y' AND addtomenu = 'Y' ORDER BY date DESC LIMIT 0,300";
        $result = @mysql_query($query);
        $n=0;
        while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
        {
                if($n<5){$recentfiles.='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
                if(($pos=strpos($row['pagename'],'/'))===false){$docroot.='<li><a href="http://'.getenv('HTTP_HOST').fw_get_docroot().$row['pagename'].'.html">'.$row['title'].'</a></li>';}
                else{$this->fw_list_menu($folders,$row['pagename'],$row['title'],$row['pagename']);}
                $n++;
        }
        $menu=$this->topfive();
        if($menu!=''){$menu='<li class="separator"><span>Top five:</span></li>'.$menu;}
        $menu.='<li class="separator"><span>All post:</span></li>';
        foreach($folders as $key => $f){
                $menu.='<li class="hide" onmouseover="this.className=\'show\'" onmouseout="this.className=\'hide\'"><a class="root" href="http://'.getenv('HTTP_HOST').fw_get_docroot().$key.'/index.html">'.$key.'</a><ul>';
                $menu.=$this->arrange($f,$key);}
        if(!empty($docroot)){$menu.='<li class="hide" onmouseover="this.className=\'show\'" onmouseout="this.className=\'hide\'"><a class="root" href="#">Document root:</a><ul>'.$docroot.'</ul></li>';}
        if(!empty($recentfiles)){$menu.='<li class="separator"><span>Recent post:</span></li>'.$recentfiles;}
        if($menu!=''){$menu='<div id="fw_menu"><ul>'.$menu.'</ul></div>';}
        return $menu;
}
}
?>
Return current item: RAMUI WEBBLOG