Video Corsi Maya e zBrush – Effetti Speciali

This post is pretty out of the line with respect to this blog’s contents, but as you can see this php blog hasn’t been updated for a while.

It will come back, and it will boost some pretty strong new content. I have spent last year developing an eLearning system and it turned out to be a pretty decent cms as well.

Among other things, I plan to write about handling video pseudo streaming in a secure way, voting and discussing posts, creating a content dripping system and an automatic renewal plan.

But for now let me point to a few urls related to the system I developed. One is corso maya and is the placeholder for a forthcoming online course about the popular 3D rendering software. Guess its code is a little more complex than a php script.

The other, corso zbrush is an already active online training on zbrush, a virtual sculpting tool used even to create the monsters in pirates of the caribbeans (go figure!). Both trainings are not in english, nor is this site effetti speciali cinema which is a free resource on history and techniques of visual effects in cinema. This is a non profit site, with an english version currently under developement by yours truly. Or, rather, by my fellow webdesigner, as I am only writing a php wordpress plugin to improve searching.

Again, I will soon update this blog with some real, down to earth, php tutorial worth reading. An rss feed generation system and a sitemap creator, for example. All I have to do is to grab all the notes I took during developement and gather them into a final list of posts. Then it will be php blog time. Honest.

Posted in Uncategorized | Leave a comment

Flatfile PHP simple CMS tutorial Part 2 the code

This is part two of our simple CMS or blog in flatfile format. We’ll see how to structure the flat file, and the code needed to read it in.

This code is not optimized, so it’s easier to understand. As we progress in this series we’ll see how to improve coding style.

First of all we have to define the flat file format.

We will need several fields:

1. Title – mandatory
2. Url – mandatory
3. Content – mandatory
4. Meta keywords – optional
5. Meta description – optional
6. Author – optional
7. Post date – optional, as unix timestamp

The most straightforward way to tackle this in a flat file would be to separate each element with a special character never to be used in titles or content, say a pipe symbol ‘|’.

Then, we would place all content on a single row and use PHP’s fgets() function to read one line at a time.

There are two problems with this approach: sometimes is handy to include newlines in the file, to make it easier to read and edit. And using a special character, whatever it is, prevents us from using it in the text.

A nice and tidy solution would be to use some sort of XML format, but we are aiming for a short, efficient script -not an exercise in Quality Coding.

A good compromise can be to use a complex separator both for articles and for items inside articles. Let’s say something like: #00# between items and #99# between articles.

The “database” file would therefore appear this way:

#00#/#00#This is the Home Page.#00#Micro Flat File CMS#00#Home#00##00##99#
My title#00#my-title.html#00#This is the post.
It can spawn multiple lines. And have html code inside.
#00#Post, article#00#Sample post#00#Admin#00#1251892286#99#
Corporate Home Page#00#corporate.html#00#Our mission is to provide nonsense mission statements no one will ever read.
#00#Mission, corporate#00#We We We We We...#00##00#

Looks like a mess, right? Let’s make a simple entry template:


TITLE#00#URL#00#

[anything here will be the post]

#00#TAGS#00#DESCRIPTION#00#AUTHOR#00#TIMESTAMP#99#

Just copy and paste this block to add an entry, then fill in the fields.

As you can see the home page in the first example is marked with a single slash, as using index.html is usually bad for SEO.

How are we going to parse this flat file database in PHP?

First of all, we’ll have to read the file in memory. Then, explode articles and iterate over them. If an article matches the url the user requested, explode this article contents and fill the “Theme”.

To make everything clean and expandable, we’ll begin defining some config variables. Please note this code is very basic so that it’s easier to understand, and is compatible with PHP4 (BTW, if you are using PHP4 upgrade NOW). Feel free to optmize it if you are an experienced programmer.

$config_db=dirname(__FILE__)."/db.txt";  // location of the database file, change this to something less obvious
$config_site="http://readytousesolutions.com"; // absolute url for your domain here
$config_theme=dirname(__FILE__)."/theme.html";  // location of the "theme" file, a single html page
$config_date="M jS, Y"; // how to format the date function, localize it if you want

$found=false; // defaults to page not found

$u=parse_url($_SERVER['REQUEST_URI']); // this returns the actual file requested by the user
$url=$u[PHP_URL_PATH];
$url=basename ($_SERVER['REQUEST_URI']);

if($url=='') $url='/';                  // force home page to be the single slash

$fp=@fopen($config_db,"rb"); // the @ prevents errors from showing


if(!$fp===false && $url!="404.html") // this check saves time if this is a 404 redirect
{
 $data=fread($fp,filesize($config_db));
 if(! $data===false )
 {// file was read in, we can parse it

     $articles=explode("#99#",$data); // put each article in an array

     foreach($articles as $article)
     {
     /* now loop all articles looking for the one that contains the url
     play it safe including #00# markers before and after the url, so that we can link between pages without problems */
     $pos=strpos($article, "#00#".$url."#00#");
      if($pos !== false)
      {// this is the article we were looking for


          $found=true;
          // now explode the article and exit the loop to save time
          $items=explode("#00#",$article);
          break;
      }
     }
     fclose($fp);
 }
}

else // issue a 404 redirect and die
{
header ("HTTP/1.0 404 Not Found 404.html");
exit;
}

With this code, we’ll have $found set to true and the $items array filled if the page was in the database. We’ll complete the script in the next post, handling 404 errors and implementing the template system.

Posted in Uncategorized | Leave a comment

Simple Flat File PHP CMS or Blog

In this and the next few posts, we’ll see how to create a simple flat file blog or CMS in PHP.

I mean a really simple one, useful when you have just a few pages to manage, and installing WordPress would be an overkill.
Why flat file?

Because you may need to populate many sites with content, using a cheap hosting service where mySql is not available, or has a limit on the number of simultaneous connections.

For a small number of articles, such as a Mini Site with 30/50 articles of 500 words each, the resulting file would be less than 50Kb and allow for immediate deployment of the site wherever you want.

To keep things simple and hacker proof, we’ll not include an admin backend. Adding articles will be done offline in a text editor.

Let’s start outlining the requirements for our blog/cms. It should be able to:

1. Handle SEO friendly urls
This means urls will look like mysite.com/this-is-a-post.html instead of the ugly mysite.com/index.php?m=73.

2. Have SEO friendly page titles
As well as per-page meta tags and meta descriptions.

3. Be able to be used as a Blog or as a CMS
Here we’ll draw a line and state that author and post date are optional items. When present, the page will be considered a blog post. Otherwise a “static” page.

4. Be able to make use of custom or Artisteer templates
If you don’t know Artisteer, it’s a remarkable piece of software, available both for Mac and Windows. It creates great looking cross browser templates for WordPress, Joomla, Drupal and static sites.

Hacking the xhtml template Artisteer provides, we’ll be able to quickly change the look of our Minisite.Of course we can also code the page by hand or using another web design tool.

5. Graceful error handling
Providing a meaningful 404 error code if the url is not in the database is a must.

6. Expandable
Again, the goal is to keep code as short and simple as possible, but with a little pre-planning we can make sure the script is scalable and can easily be expanded to handle more complex tasks.

Interested? then head on to the next post where we’ll start building it.

Posted in Uncategorized | Leave a comment

PHP Mini Sites CMS

In this fourth post we’ll have to actually do something useful with our code. Simply add the following at the end of the previous script.


if($found)
{// set up variables with content
 $title=$items[0];
 $url=$items[1];
 $post=$items[2];
 $tags=$items[3];
 $description=$items[4];
 $author=$items[5];
 $date=$items[6];
}

else

{ // if we get here there was a 404 error either for malformed url or because we couldn't read the file
 $title="Page not found";
 $url="404.html";
 $post='<h1>Ooops! Page not found</h1><p>Don\'t worry, this may happen. Please go back to the <a href="'.$config_site.'">Home Page</a>.';
 $tags="Not found, 404";
 $description="This page could not be found";
 $author="";
 $date="";
}

Now we have everything set up. We only need to populate our theme with the relevant content. We’ll use psuedo tags in the theme, like {title}, {post} and so on.

We’ll place those meta tags in our template, or the Artisteer template. Then save this file as “theme.html” or whatever name you prefer to use.

Here’s an extra simple theme with no styles, just to show the concept:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>{title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="description" content="{description}" />
<meta name="keywords" content="{tags}" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<link href="put-your-css-here.css" type="text/css" rel="stylesheet" />
<link href="i/favicon.ico" rel="SHORTCUT ICON" />
<script type="text/javascript" src="put-your-javascript-here.js"></script>
</head>
<body>
<h1>{title}</h1>
<h2>{blog}</h2>
{post}
</body>
</html>

This approach is slower than echoing the variables in the page itself, as it requires reading the theme and performing string replacements, but gives us a clean separation between the theme and the code, and makes this project easily scalable.

$fp=@fopen($config_theme,"rb");

if($fp!==false)
{
 if( false !== ($data=fread($fp,filesize($config_theme))))
 {// theme was read in, we can fill it with the data

     $data=str_replace("{title}",$title,$data);
     $data=str_replace("{post}",$post,$data);
     $data=str_replace("{tags}",$tags,$data);
     $data=str_replace("{description}",$description,$data);
     $blog='';
     if($author!='' &amp;&amp; $date !='')
     {
      $blog="Posted by ".$author." on ".date($config_date,$date);
     }
     $data=str_replace("{blog}",$blog,$data);
     echo $data;
 }
 fclose($fp);
}

else

{
echo 'Internal error'; // could not read the theme!
}

Makes sense? Hope so, because there’s not much more to be done. Save the script as index.php, then create or edit the .htaccess file. We need a rewrite rule to pass everything the user requests to index.php.
The .htaccess rewrite rule

Now, if there’s something I really don’t like to do it must be writing rewrite rules. I’m no Apache guru and have never studied them formally like I did for programming. But this one is really simple to use and understand.


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

First, we turn on the rewrite engine and say everything is relative to the web root.

Then, there are two rewrite conditions, almost identical. They check if a file (-f) or a directory (-d) exists. If so, the existing file or directory is served.

Otherwise, the rewrite rule is invoked, and points to /index.php, our code. Note that no redirection is performed, so this will return an OK 200 status and the user’s browser will still display the originally requested url.
That’s almost all, folks

Okay that’s all. The simple cms is ready. However it’s still a bit poor, even adding a nice artisteer template it will have no navigation. We may want to add RSS, a sitemap, even some widgets. As long as there’s no user submitted content, like comments, we can do everything without writing to our server. And we’ll see how in the next post.

Feel free to comment, ask questions and suggest how to expand this simple flat file php CMS. I’m not sure it’s worth to add an administrative panel, as this is really meant to be a set and forget script, but will wait for your suggestions.

Thanks for reading so far, have fun!

Posted in Uncategorized | Leave a comment

PHP Tutorial : Validate email address – simple way with filter_var() function

While browsing php.net without any scope I discovered a very cute & nice way to replace the usual regular expression email checking thing.

That way is via filter_var() php function which does the things 10 times faster :

<?php
$email = "someone@example.com";

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email address";
}
?>
Posted in Usefull PHP | Tagged , | Leave a comment

PHP Tutorials : Rename a mysql table

If you want to rename a mysql table via php you just need an extremely simple query like the one it’s following:

<?php
//include db credentials

mysql_query("rename table TheOldName to TheNewName");
?>
Posted in Php & MySQL | Tagged , , , , | Leave a comment

Seo Tips & Tricks : Get indexed in google very fast

I’ve heard this question too many times to stay without telling this amazing unique seo trick / tip.

You may know that doing social bookmarking, forum posting, getting an article to a popular blog, etc. will help getting indexed faster in google.

But, pay attention, no other trick than opening an adwords campaign with your site will make it go into google’s cache faster.

It simply doesn’t matter how much money you put, 1.00$ or 100$, etc.

Enjoy!

Posted in Seo Tips & Tricks | Tagged , , , , , | Leave a comment

PHP Tutorial : Write text and convert into image

The base usage in my mind when I write this tutorial to convert text into image with php is to write email into images dinamically to avoid spammers collecting such addresses from the internet.

To run such a script you must have GD library installed. We’ll take parametres via GET and merge into image:

<?php

if(!isset($_GET['text']))
{
die("No text provided");
}
header ("Content-type: image/png");
$textToConvert = $_GET['text'];
$font   = 4;
$width  = ImageFontWidth($font) * strlen($textToConvert);
$height = ImageFontHeight($font);
$im = @imagecreate ($width,$height);
$background_color = imagecolorallocate ($im, 255, 255, 255); //this means it's white bg
$text_color = imagecolorallocate ($im, 0, 0,0);//and of course black text
imagestring ($im, $font, 0, 0,  $textToConvert, $text_color);
imagepng ($im);
?>

Save this as textToImage.php and then when you want to create the image and read text do it like :

<img src="textToImage.php?text=emailAddress@emailProvider.com">
Posted in Usefull PHP | Tagged , , , , , | Leave a comment

PHP Tutorial : Get Browser Name & It’s Capabilities

To get browser name just use next thing :

<?php
print $_SERVER['HTTP_USER_AGENT'];
?>

And for all the features of browser user :

<?php
print_r(get_browser(null, true));//null for user agent &amp; true to return array

?>
Posted in Usefull PHP | Tagged , , , , , , , | Leave a comment

Ventrilo Server Hosting

Ventrilo is a voice over IP program that allows multiple people to communicate with each other over an internet connection. You have a choice of audio codecs like Speex and GSM, Ventrilo is based on the client-server model, the client will reside on your computer and the server will relay all of the data from the other clients to your computer. Ventrilo server hosting is fairly affordable, starting at $2.91 per month for 10 users.

Ventrilo is a great utility for development teams who like to keep in touch without having to deal with IM programs.

Posted in Uncategorized | Tagged | Leave a comment