Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Simple Auto-CMS using HTML pages

Here is an interesting idea of CMS which is managed by HTML files. It is simple php script, that searches specified location and takes all folders and html files and interprets them as pages and content. Basically, you can manage your content with HTML files, and this script will automatically create menu to browse them.

For example, this script looks in the content folder. If there is an HTML file named index.hmtl, it will be outputted as content, if there are any other HTML files, links in menu will be created for them. Folder with HTML files is like a submenu, and folder inside folder - subsubmenu.

So if you have structure in content directory like index.html, contacts.html, folder works, which has index.html and myworks.html, then menu contacts with submenu works, which will include myworks will be automatically created. 

Here is an example of how it works: http://bensmith87.byethost11.com/

And here is a php code snippet:

<html>  
  <head>  
    <title>Some titile</title> 
    <!-- you can use styles -->
    <link rel='stylesheet' type='text/css' href='/style.css' />  
  </head>  
  <body>  
    <div id='header'>  
      <h1>Website title</h1>  
    </div>  
<?php  
   
  // Get the path  
  if(isset($_GET["a"]))  
    $a = $_GET["a"];  
  else  
    $a = "";  
    
  $path = explode("/", $a);  
  $current_path = "";  
    
  // Create the menu   
  echo "<div id='menu'>n";             
  for($i = 0; $i < count($path); $i++)  
  {  
    $contents = scandir("content/".$current_path);  
      
    echo "<ul>n";  
    for($j = 2; $j < count($contents); $j++)  
    {  
      // Do not create a link if its called index.htm, this will be open automatically  
      if($contents[$j] != "index.htm" && $contents[$j] != "index.html")  
      {  
        // This makes it so the active links are a different color  
        if($contents[$j] == $path[$i])  
          $li_class = " class='open'";  
        else  
          $li_class = "";  
            
        $this_path = $current_path.$contents[$j];  
          
        if(is_dir("content/".$this_path))  
          $this_path = $this_path."/";  
     
        // The actual link  
        echo "<li".$li_class."><a href='/".$this_path."'>"
                .$contents[$j]."</a></li>n";   
      }   
    }  
    echo "</ul>n";  
                                              
    $current_path = $current_path.$path[$i]."/";  
  }  
  echo "</div>n";  
    
  // Render the content  
  echo "<div id='content'>n";  
  $file = "content/".$a;  
  if(is_file($file))   
  {               
    $ext = substr($file, strrpos($file, "."));  
    switch($ext)  
    {  
      // If the file is a html file, just copy it  
      case ".htm":  
        $foo = file_get_contents($file);  
        echo $foo."n";  
      break;  
        
      // All other files get a download link  
      default:  
        echo "Download <a href='".$file."'>".$file."</a><br >n";  
    }  
  }  
  else  
  {  
    // If a folder is selected, and it contains an index.htm file, render it  
    if(file_exists($file."index.htm"))  
    {  
      $foo = file_get_contents($file."index.htm");  
      echo $foo."n";  
    } 
    else if(file_exists($file."index.html"))  
    { 
        $foo = file_get_contents($file."index.html");  
        echo $foo."n";  
    } 
  }  
  echo "</div>n";  
?>  

  <div id="footer">  
    Footer credits 
  </div>  
  </body>  
</html>

And here is a mod rewrite to put in .htaccess file for search engine friendly URLs:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.+)$ /index.php?a=$1 [L]

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus