Jump to content

Safely, Allowing Client To Edit Their Own Content


Elemental

Recommended Posts

Hello Folks, Happy Up-Coming Holidays to All.Some one recently asked me if there was a way to have a “back door” to their website so they, personally, could update certain content (text) and not have to ask some one to do it for them.I know this can be achieved by altering the actual HTML file but this could lead to possible headaches that could end up costing more than hiring someone to make the changes.In Flash, using variables, I can load an external text page so I would think that using JavaScript this could also be done but like ActiveX, JavaScript can be disabled so…What would be the “Best Practice” to achieve this, back door, using HTML/XHTML?Peace,Elemental

Link to comment
Share on other sites

That's just a CMS. Most CMSs just use PHP to fill in the content when the page is loaded, not Javascript.
Justsomeguy, How goes it Amigo? Thank you for the prompt reply, much appreciated.Didn't know that about CMS's, thank you, but I did know that if one use them the updating would not be an issue as I posted. So, reading between the lines, can I say then that I would need to use a CMS application so the "client/person" can personally update their site or can I also create a PHP application that would reside on the server and would do the same without a CMS?Peace,Elemental
Link to comment
Share on other sites

Yeah you can build your own minimal CMS, a CMS is just a name for software that lets people manage the content on their site without needing to change any files. For my own customers I just build my own little system to read and save content in the database. My customers can't really change the layout, only the content, but that's about all they want to do anyway.

Link to comment
Share on other sites

Yeah you can build your own minimal CMS, a CMS is just a name for software that lets people manage the content on their site without needing to change any files. For my own customers I just build my own little system to read and save content in the database. My customers can't really change the layout, only the content, but that's about all they want to do anyway.
Justsomeguy, Thanks again for the reply.Are you using PHP and MyQQL to create this "little system" of yours or some other application(s)?Peace,Elemental
Link to comment
Share on other sites

This may be a little more complicated than what you're looking for, but I built this with ExtJS for the editor frontend:http://manchine.net/steve/files/w3/extcms.zipIn order to install that, make a new directory on the server and extract all of the files. Open the /include/global.conf.php file and fill out the details there, like database details and paths. Make sure to make the error.log file writable by PHP, that's where it will put error messages (make sure to check that file if you think there's an error). Then open the db.sql file, the last line in that file will add the admin user so that's where you can set the username and password to use for the person to edit the page content. Copy and paste the SQL into something like phpMyAdmin to set up the tables. Then open the /include/admin.js file, and change the line near the top where it points to io.php if your path is different.This thing uses a couple classes I wrote, the session, db, and page classes. The page class is a template engine, so all of the templates that it uses for the HTML are in the templates folder. If you open the index.php file in an editor you'll see it's only got these lines:

<?phprequire_once 'include/global.conf.php';$page_content['page_title'] = 'Ext CMS Demo';// get this page's content$page_content = array_merge($page_content, get_page_content('home_'));$page->set_template('home.tpl');$page->process($page_content);$page->output();?>

The $page_content array is defined in global.conf.php, that's the array of content that you send to the template engine, which will load the template and fill out all of the content. So it sets the page title, then gets the content for the page, then loads the template and outputs it. If you open the home.tpl file in the templates directory, you'll see that it includes a header and footer (the page title is used on the header), and then just has this example content on it:

<h2>{*type=if_start show_admin}<a href="java script:void(0);" id="home_head1" class="admin_edit_link"></a>{*type=if_end}{*home_head1} </h2>{*type=if_start show_admin}<a href="java script:void(0);" id="home_image1" class="admin_edit_link"></a>{*type=if_end}<img src="images/{*home_image1}" alt=""><br /><br />{*type=if_start show_admin}<a href="java script:void(0);" id="home_text1" class="admin_edit_link"></a>{*type=if_end}{*home_text1}<br /><br />{*type=if_start show_admin}<a href="java script:void(0);" id="home_image2" class="admin_edit_link"></a>{*type=if_end}<img src="images/{*home_image2}" alt=""><br /><br />

That's both the CMS content and the site content, the things surrounded by {*...} are template tags for the page class. A line like this:{*type=if_start show_admin}<a href="java script:void(0);" id="home_text1" class="admin_edit_link"></a>{*type=if_end}{*home_text1}Will display the page content and also show a little edit box if you're logged in as admin. The thing to pay attention to in that line is the home_text1 string, that's the name of the content to show. The content will be stored in the database with that name. If you want to add 3 paragraphs of text that the user can edit then you would just copy and paste that line and change the names:{*type=if_start show_admin}<a href="java script:void(0);" id="home_text1" class="admin_edit_link"></a>{*type=if_end}{*home_text1} <br>{*type=if_start show_admin}<a href="java script:void(0);" id="home_text2" class="admin_edit_link"></a>{*type=if_end}{*home_text2} <br>{*type=if_start show_admin}<a href="java script:void(0);" id="home_text3" class="admin_edit_link"></a>{*type=if_end}{*home_text3}If you did that, when you initially load the page you wouldn't see anything, because you haven't created those content pieces yet. If you were logged in then you would see 3 blue boxes, those are what you click on to change the content. You could edit that content and then when you loaded the page you would see the content show up. So this gives people a way to edit the content in place on the page, sort of.The content you can edit includes single lines of text, HTML blocks, and images. The home page in the example includes each type. In addition to adding the template tags and changing the names like I showed above, these are the other steps to add a new piece of content:- Open the io.php file. This is the file that the ajax interface communicates with.- Near the top you'll see a switch statement. So far it looks like this:

switch($id){  // single-line strings  case 'header_title':  case 'home_head1':	$form_type = 'string';  break;  // html boxes  case 'home_text1':	$form_type = 'html';  break;  // images  case 'home_image1':  case 'home_image2':	$form_type = 'image';  break;  default:	$form_type = '';  break;}

You need to add your new content ID to the appropriate place. This is where you say whether it's a single line of text, an HTML box, or an image. Add the ID to the appropriate section in the switch statement, e.g.: // html boxes case 'home_text1': case 'home_text2': case 'home_text3': $form_type = 'html'; break;So that would add home_text2 and home_text3 as HTML boxes, where you'll get an HTML editor when you edit the content. The image type gives a thumbnail of the current image and a field to upload a new one, and the single line of text is just that.So I guess that's the only step to add a new piece of content, add the template tags for it and then edit io.php to tell it which type it is. You don't have to edit anything else, it will automatically add new content to the database if necessary or update what's already there.Now, when I was talking about index.php I said it included this line:$page_content = array_merge($page_content, get_page_content('home_'));You'll need to edit that line on each page. All of the content on home.tpl starts with "home_", e.g. home_head1, home_text1, etc. That line of PHP will get all of the content from the database that starts with "home_", so if you are consistent with your naming on each page then you can just edit that one line to retrieve all of the content for the page. But you'll notice that the header.tpl file also includes content called header_title, but home.php doesn't tell it to load that content. So back in global.conf.php, you'll see a config option called "global_content". You can add a list of IDs there for all of the content that you want loaded on each page. e.g.:

'global_content' => "'header_title', 'main_logo', 'footer_content'",

So that would load those three pieces of content for every page...did I cover everything?The template engine has several other features, if you're looking for something specific check the comments at the top of class.page.php or feel free to ask if it can do a certain thing. Likewise with the session and db classes.Also, for the sake of speed, open up the header.tpl file and if you see it including the ext-all-debug.js file, change that to ext-all.js, without the debug. It's the same code, but half the size.

Link to comment
Share on other sites

Dude!?, INSANE. You Rock.More than what I expected and lots and lots of stuff to learn from.THANK YOU, THANK YOU, THANK YOU.Peace,Elemental

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...