Menu:

Sponsor

Discover Master of Alchemy, our first iPad/iPhone and iPod touch game!

 

Forum's topics

Latest Files

Archives

Top Rated

Categories

Photo Gallery


Create a calendar for your blog archive

1. Introduction

This tutorial came in order to give a response to the different email asking me how to create a calendar similar to the one in my home page.
Many of you probably have a blog in your sites, and this tutorial will show you how to make a calendar which will show to the users which dates have a post available.

Attention: Because all the different blog system works in different ways for the file organization you may need to change many parts of the PHP code in order to see it work. I'm actually useing the blogger service for my home page blog, so please refer to that system.

 

1.1 What I need ?

  • PHP 4.3.x
  • AMFPHP installed on your server
  • Flash MX 2004
  • An account on blogger.com

 

2. Blog installation and customization

First thing you need to have a blogger.com account. Once created the account you can set up your server settings for the file publishing policy.
Go into Settings->Archiving as shown in the image below:

settings - archiving

Now, make this changes:
blogger settings

In this way every time you create a new blog post a new file on your server will be created with a name similar to "2004_11_04_weekly.html"
All the system we are going to create will be centered on the file names!
Pay attention on the folder path where these files will be created.

 

3. The AMFPHP class

Ok, now it's time to pass to the AMFPHP class installation. It will be a very simple class with just one method for retrieving the avaialble dates.

I don't show you the gateway.php installation because there is already tutorial on this.
You need just to know that the gateway path is set to:
$gateway->setBaseClassPath(realpath("services/") . "/");

and this is my folder organization:
siteroot/flashservices/gateway.php
siteroot/flashservices/services/DateChooser.php
siteroot/blog/{weekly_files.html}

Ok, so create in your services default path a new PHP file DateChooser.php which will be our remoting service:


<?php

    
class DateChooser {
        
// ---------------------------------------------------------------
        // First I set the Folder where all the blog html pages are stored
        // Pasy attention with this. It's fundamental
        // ---------------------------------------------------------------
        
var $base_path "./../../blog";
        
// constructor
        
function DateChooser() {
            
$this->methodTable = array(
                
"findBlogByDatePK" => array(
                    
"description" => "Returns list of images in album",
                    
"access" => "remote",
                    
"arguments" => array ("month","year")
                )
            );
        }

        
// -------------------------------------
        // public method
        // month and year are required arguments
        // -------------------------------------
        
function findBlogByDatePK($month,$year)
        {
            
// create the array for avail dates
            
$availDate = array();
            
// $availDate = new myDate();
            // check arguments
            
if(empty($month) || !is_dir($this->base_path) || empty($year)){
                
// return an error message
                
return array("error" => $_SERVER['PATH_TRANSLATED'] . $name "is not a valid directory");
            }
            
// open the default dir
            
$dir = @opendir($this->base_path);
            if(!
$dir){
                
// return error on fails
                
return array("error" => $_SERVER['PATH_TRANSLATED'] . $name " cannot open selected directory");                
            }
            while(
$file readdir($dir))
            {
                
// get month value from file name
                
$_month substr($file,5,2);
                
// get year value from file name
                
$_year  substr($file,0,4);
                
// compare to arguments passed
                
if(number_format($_month,0) == number_format($month,0) && number_format($year,0) == number_format($_year,0))
                {
                    
$_date number_format(substr($file,8,2),0);
                    
array_push($availDate$_date);
                }
            }
            return 
$availDate;
        }
    }
?>