Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Friday, November 30, 2007

Soon my home by Joomla!™

Next step at my home page is to publish my content , I thought in building it from scratch and adding content gradually, but another option that came from my friend Mohamed Saad is to use a CMS like Joomla!™ and only administrate [or may customize in] it

I remember his words when he said that CMS is saying to administrator you can customize every thing with just some clicks and the developer is valueless to your site

So with a CMS I can apply the principle of reusablity and with a CMS I can build a site from a simple home page to any large web solution

And if you are asking Joomla!™ exactly? That is because Joomla! Wins 'Best CMS Award' in 2007!

Saturday, November 10, 2007

phpBB™ an Open Source forum solution

phpBB™ one of the most widely used Open Source forum solution. It has an easy to use administration panel and a user friendly installation process, which allows you to have a forum set up in minutes.

With a large and highly customizable set of key features coupled with a standards compliant interface, phpBB™ will grow with, and compliment your website. With millions of installations worldwide, it is no wonder phpBB™ is one of the most popular ways to create and support a community.

I have installed phpBB™ on my local machine and I really thank the open source community for providing the globe with this great script fro free.

I recommend any one new or old to PHP to install phpBB™ and navigate through the source code so that he can understand the logic of the forum sites.

This is the ACM online judge forum that run phpBB™

Friday, November 2, 2007

Smarty: Functions

Every Smarty tag either prints a variable or invokes some sort of function. These are processed and displayed by enclosing
the function and its attributes within delimiters like so: {funcname attr1='val1' attr2='val2'}.

Example function syntax

{config_load file='colors.conf'}
{include file='header.tpl'}
{insert file='banner_ads.tpl' title='Smarty is cool'}
{if $logged_in}
Welcome, {$name}!
{else}
hi, {$name}
{/if}
{include file='footer.tpl' ad=$random_id}

Smarty: Variables

{$foo} <-- displaying a simple variable (non array/object)
{$foo[4]} <-- display the 5th element of a zero-indexed array
{$foo.bar} <-- display the "bar" key value of an array, similar to PHP $foo['bar']
{$foo.$bar} <-- display variable key value of an array, similar to PHP $foo[$bar]
{$foo->bar} <-- display the object property "bar"
{$foo->bar()} <-- display the return value of object method "bar"
{#foo#} <-- display the config file variable "foo"
{$smarty.config.foo} <-- synonym for {#foo#}
{$foo[bar]} <-- syntax only valid in a section loop, see {section}
{assign var=foo value='baa'}{$foo} <-- displays "baa", see {assign}
Many other combinations are allowed
{$foo.bar.baz}
{$foo.$bar.$baz}
{$foo[4].baz}
{$foo[4].$baz}
{$foo.bar.baz[4]}
{$foo->bar($baz,2,$bar)} <-- passing parameters
{"foo"} <-- static values are allowed
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}

Friday, October 26, 2007

Hello World! Smarty

Smarty is a web template system written in PHP.

Although Smarty is known as a "Template Engine", it would be more accurately described as a "Template/Presentation Framework." That is, it provides the programmer and template designer with a wealth of tools to automate tasks commonly dealt with at the presentation layer of an application. I stress the word Framework because Smarty is not a simple tag-replacing template engine. Although it can be used for such a simple purpose, its focus is on quick and painless development and deployment of your application, while maintaining high-performance, scalability, security and future growth.

I'm using Smarty many months ago, But I didn't build an application from scratch so far and I felt that I need to implement the Hello world demo to satisfy my ambition.

Smarty really was very easy installed and used, and here is my demo.

Code Snippet:

index.php

<?php

// put full path to Smarty.class.php
require('smarty/Smarty.class.php');
$smarty = new Smarty();

$smarty->template_dir = 'templates';
$smarty->compile_dir = 'smarty/templates_c';
$smarty->cache_dir = 'smarty/cache';
$smarty->config_dir = 'smarty/configs';

$smarty->assign('name', 'World');
$smarty->display('index.tpl.html');

?>

index.tpl.html

<html>
<head>
<title>Smarty</title>
</head>
<body>
Hello, {$name}!
</body>
</html>


Download Code 100 KB

Tuesday, May 29, 2007

RSS News Feed Back Reader

Download Source - 44 KB

This sample indicate how to read RSS news feed back using PHP

Sample Code

<?php
require_once('rss/rss_fetch.inc');
error_reporting(E_ERROR);
$rss = fetch_rss ( "http://www.youtube.com/rss/global/top_viewed_today.rss" ) ;
$items = array_slice($rss->items, 0);
$news_feed = ''; 
foreach ($items as $item )
{
       $news_feed .= '' . $item['title'] .'<br>'. $item['link'].'<br>'.$item['summary'] . '<br>' ;
}
echo $news_feed;
?>

This sample uses MagpieRSS library which is attached with the source code and also can be downloaded from the following link
http://magpierss.sourceforge.net

XML Reader

Download Source - 8 KB

This sample indicate how to parse XML file using PHP

Sample Code

<?php
require_once("xmllib.php");
$menufilename= "SampleFile.Xml";
$xml =& new XmlLib_xmlParser($menufilename);
$doc =& $xml->getDocument();
$Maindoc=$doc->children[0];
//$arr = $Maindoc->children[$i]->toArray();
if ($Maindoc->hasChildren())
{
       foreach($Maindoc->children as $group)
      {
            echo'id : '.$group->attributes['id'].' Title :'.$group->attributes['title']."<br>";
           if ($group->hasChildren())
           {
                 foreach($group->children as $menuItem)
                {
                     echo'id : '.$menuItem->attributes['id'].' Title : '.$menuItem->attributes['title']."";
                } echo '<br>';
           }
     }
}
?>