EasyPHPScripts.com      Free Open Source PHP Scripts and Code Snippet Library

 +Menu
+   Site News
+   Main Pages
+   Other Downloads
 +PHP
+ Arrays (9)
+ Directory And Files (7)
+ Image (3)
+ LDAP (3)
+ MySQL (11)
+ Other (11)
+ Dynamic Content
+ EasyPHPEmail
+ Function Basics
+ Get URL
+ Input Validation
+ RandPass
+ Random Field Name Genorator
+ Random Password
+ Redirect To
+ Set and Delete Cookies
+ Valid IP
+ Regular Expressions (3)
+ String Manipulation (13)
+ Time and Date (6)
 +Snippet Options
+   Printer Friendly
 +Library Options
+   View Other Library
 +General Options
+   Log in
Description for Snippet: Other / Dynamic Content
  Basic start to show how to build a Dynamic Flat File Web Site. CMS. Used on this site, and several others. BecksWelding.com for one.
 
Syntax for: Dynamic Content

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
<?php 
//fix for old site page names.
if($_GET['main_page'])
    
$_GET['Page'] = $_GET['main_page'];

//advatage of this page loader is you dont have to edit themed pages, just the content.
//is not login, no DB, edit, upload via FTP, all done
// no trailing slash , best below http server root.
define('CONTENT_DIR','./static/content'); 
define('DEFAULT_PAGE','Home'); 
define('EDIT_PASSWORD','demo'); 

//added for highlight_file
//?Page=Name_in_conetent_dir = code.Name_in_conetent_dir.txt
//adds to bottom page after page display, content page must exist.


//when calling the get_links('header',' -|- ') function.
//when calling the get_links('left','<br>') function.
//?Page=Name_in_conetent_dir = content.Name_in_conetent_dir.txt
//can also get_links('left','<br>',' |-- ') for sub links
//'display_name'=>'URL'
$LINKS['left'] = array(
'Home'=>'?Page=Home',
'EasyPHPNews'=>'?Page=EasyPHPNews',
'EasyPHPTabs'=>'?Page=EasyPHPTabs',
'EasyPHPTemplate'=>'?Page=EasyPHPTemplate',
'EasyPHPEdit'=>'?Page=EasyPHPEdit',
'Flat_file CMS'=>'?Page=Flat_file_Site',
'EasyPHPCashe'=>'?Page=EasyPHPCashe',
'EasyPHPNews_Discussions'=>'?Page=EasyPHPNews_Discussions'
);
//sub cat of page $LINKS['page_name'], and other links and bottom the page.
//has to be the same name...spaces not prefered, use underscore will change them to a space when displayed.
$LINKS['EasyPHPNews'] = array('EasyPHPNews_Discussions'=>'?Page=EasyPHPNews_Discussions');

$LINKS['header'] = array('Downlaods'=>'http://www.easyphpscripts.com/downloads');
//$LINKS['footer'] = array();


function get_links($links,$EL='',$SUB_beg='',$SUB_end=''){
  global 
$LINKS;
  if(
is_array($LINKS[''.$links.'']))
  foreach (
$LINKS[''.$links.''] as $pagename => $URL){
      if(isset(
$_GET['Edit']) && eregi('Page=',$URL)) $Edit '&Edit';
      
$link_list1 .= '<a href="'.$URL.$Edit.'">'.str_replace('_',' ',$pagename).'</a>'.$EL;
      if(
is_array($LINKS[''.$pagename.'']))
      foreach (
$LINKS[''.$pagename.''] as $subname => $subURL){
      
//echo ' in array=('.$_GET['Page'].','.$pagename.') = '.in_array($_GET['Page'],array_keys($LINKS[''.$pagename.'']));
      
if($_GET['Page'] == $pagename || in_array($_GET['Page'],array_keys($LINKS[''.$pagename.''])))
        
$sub_list .= $SUB_beg.'<a href="'.$subURL.'">'.str_replace('_',' ',$subname).'</a>'.$SUB_end.$EL;
      }
      
$link_list .= $link_list1.$sub_list;
      unset(
$link_list1); unset($sub_list);
  }
  
//return the link list and remove last ocurance of the end line.
  
return(rtrim($link_list,$EL));
}

function 
save_content($content){
  
//clean out everything exept alhpa,numeric,underscore and space.
  // many reasons for this, security is most important.
  
$contenteregi_replace("[^A-Z,0-9_ ]"''urldecode($content));
  if(
eregi_replace("[^A-Z,0-9_ ]"''$_POST['password']) == eregi_replace("[^A-Z,0-9_ ]"''EDIT_PASSWORD)){
    if(
$_POST['post_content'] && $_POST['page_content']){
      
file_put_contents(CONTENT_DIR.'/content.'.$content.'.txt',stripslashes($_POST['page_content']));
    }
    elseif(
$_POST['code_content'] && $_POST['post_code']){
      
file_put_contents(CONTENT_DIR.'/code.'.$content.'.txt',stripslashes($_POST['code_content']));
    }
    
    
  }
}

if(isset(
$_GET['Edit']) && $_POSTsave_content($_GET['Page']);


function 
edit_content($content){
  
//clean out everything exept alhpa,numeric,underscore and space.
  // many reasons for this, security is most important.
  
$contenteregi_replace("[^A-Z,0-9_ ]"''urldecode($content));
  echo 
'<table align="center" width="100%" height="100%" border="1">';
  if(
is_file(CONTENT_DIR.'/code.'.$content.'.txt'))
    echo 
'<tr><td colspan="2" align="center">Do NOT Edit both at the same time, one or the other.</td></tr>';
  echo 
'<tr><form method="post"><td colspan="2" align="center">';
  echo 
'Content<br><textarea name="page_content" rows="50" cols="120">'.htmlentities(@file_get_contents(CONTENT_DIR.'/content.'.$content.'.txt')).'</textarea>
  <br>Password:<input type="password" name="password"> <input type="submit" name="post_content" value="Update Content"></td></form></tr>'
;
  if(
is_file(CONTENT_DIR.'/code.'.$content.'.txt'))
    echo 
'<tr><form method="post"><td colspan="2" align="center">Code<br><textarea name="code_content" rows="80" cols="120">'.htmlentities(@file_get_contents(CONTENT_DIR.'/code.'.$content.'.txt')).'</textarea><br>Password:<input type="password" name="password"> <input type="submit" name="post_code" value="Update Code"></td></form></tr>';
  echo 
'</table>';
}

function 
get_content($content){
  
//clean out everything exept alhpa,numeric,underscore and space.
  // many reasons for this, security is most important.
  
$contenteregi_replace("[^A-Z,0-9_ ]"''urldecode($content));
  
// we have 2 places to add extra stuff, tables, theme
  //here and the 2 functions
  //usually i add a border in table untill debug is completed.
  
echo '<table align="center" width="100%" height="100%" border="0">';
  
// colspan=2 for a left colm
  
echo '<tr><td colspan="2" align="center" height="22"><h2>Main Pages</h2></td></tr>';
  
$header get_links('header',' -|- ');
  if(
$header)
    echo 
'<tr><td colspan=2 align="right" height="22">'.$header.'</td></tr>';
  
//no end table row till after content,but start a table data
  
$left get_links('left','<br>',' |-- ','<br>');
  if(
$left)
    echo 
'<tr><td align="left" width="20%" valign="top"><blockquote>'.$left.'</blockquote></td>';
  
  echo 
'<td align="left" valign="top">';

  
//content pages will run php, they are included.
  //if the file is not found, using custom page name display an error.
  
if(is_file(CONTENT_DIR.'/content.'.$content.'.txt')){
    include 
CONTENT_DIR.'/content.'.$content.'.txt';
  } else  echo 
'<h2>404 Content Not found</h2>';
  
//added for EasyPHPScripts.com site to display code
  
if(is_file(CONTENT_DIR.'/code.'.$content.'.txt')){
    echo 
'<b>Code</b><blockquote><textarea>'.htmlentities(file_get_contents(CONTENT_DIR.'/code.'.$content.'.txt')).'</textarea></blockquote><hr>';
    
highlight_file(CONTENT_DIR.'/code.'.$content.'.txt');
    echo 
'<hr>';
  }  
  
//can even load links based on the page name.$content
  //just add the dir under the links dir same name as the page, put link files their.
  
if($other_links get_links($content,' -|- '))
    echo 
'<br> Other Links '.$other_links.'<br>';
  echo 
'</td></tr>';
  if(isset(
$_GET['Edit']))
    
edit_content($content);
  
  
//add footer or theme end here
  
$footer get_links('footer',' -|- ');
  if(
$footer)
    echo 
'<tr><td align="center" colspan=2 height="22">'.$footer.'</td></tr>';
  echo 
'<tr><td colspan=2 align="center" height="22"><a href="index.php?cat_select=Other&show=Dynamic_Content">Powered By PHP</s></td></tr>';
  
  echo 
'</table>';
}


//page to display by default. or get the page asked for.
//using $_GET['Page'] URL would be ?Page=page name
if(!$_GET['Page']){
  
get_content(DEFAULT_PAGE);
} else {
  
get_content($_GET['Page']);
}

?>
 


 
Powered by: PHP & centOS