PHP Classes

File: test_freshmeat.php

Recommend this page to a friend!
  Classes of Manuel Lemos   Freshmeat project query class   test_freshmeat.php   Download  
File: test_freshmeat.php
Role: Example script
Content type: text/plain
Description: Freshmeat project query test page script
Class: Freshmeat project query class
Query project information in the Freshmeat site.
Author: By
Last change: - Added options to wait between consecutive requests to not exceed API throttle limits.
- Added support to pass the Freshmeat API token.
- Assured that no more than the allowed number of API requests are sent.
Date: 15 years ago
Size: 2,356 bytes
 

Contents

Class file image Download
<?php
/*
 * test_freshmeat.php
 *
 * @(#) $Header: /home/mlemos/cvsroot/freshmeatquery/test_freshmeat.php,v 1.7 2009/06/23 03:44:42 mlemos Exp $
 *
 */

?><html>
<head>
<title>Test for Manuel Lemos's Freshmeat project query class</title>
</head>
<body>
<h1><center>Test for Manuel Lemos's Freshmeat project query class</center></h1>
<hr />
<?php

   
require("xml_parser.php");
    require(
"http.php");
    require(
"filecacheclass.php");
    require(
"freshmeat.php");

   
$default_project="freshmeatprojectquery";
   
$freshmeat=new freshmeat_class;
   
$freshmeat->cache_directory = "";
   
$freshmeat->debug = 0;
   
$freshmeat->html_debug = 1;
   
$freshmeat->proxy_host_name = "";
   
$freshmeat->proxy_host_port = 80;
   
$freshmeat->api_token = 'your Freshmeat API token here';
   
$freshmeat->api_token = 'uuEKXDGsrxZx6Et2EHKs';
   
$freshmeat->throttle = 1; // wait between consecutive requests to avoid exceeding API throttle limits
   
if(IsSet($_GET["project"]))
       
$project=$_GET["project"];
    if(IsSet(
$project)
    &&
strlen($project)!=0)
    {
        echo
"<center><h2>Project: $project</h2></center>\n";
        if(
$freshmeat->QueryCachedProject($project,$project_data))
        {
            echo
"<center><table border=\"1\">\n";
            for(
Reset($project_data),$item=0;$item<count($project_data);Next($project_data),$item++)
            {
               
$item_name=Key($project_data);
                echo
"<tr>\n";
                echo
"<th align=\"right\" valign=\"top\">".$item_name.":</th>\n";
                echo
"<td><tt>".ereg_replace("(http://[^/]+)(/[^ :\t\r\n]*)","<a href=\"\\1\\2\">\\1\\2</a>",nl2br(HtmlEntities($project_data[$item_name])))."</tt></td>\n";
                echo
"</tr>\n";
            }
            echo
"</table></center>\n";
        }
        else
        {
            switch(
$freshmeat->error_code)
            {
                case
FRESHMEAT_ERROR_INEXISTING_PROJECT:
                    echo
"<center><h3>Project does not exist (".$freshmeat->error.")</h3></center>\n";
                    break;
                default:
                    echo
"<center><h3>Error: ".$freshmeat->error." (".$freshmeat->error_code.")</h3></center>\n";
                    break;
            }
        }
    }
    else
    {
       
$port=(strcmp($port=getenv("SERVER_PORT"),"") ? intval($port) : 80);
       
$site="http://".(strcmp($site=getenv("SERVER_NAME"),"") ? $site : "localhost").($port==80 ? "" : ":".$port).GetEnv("REQUEST_URI");
        echo
"<center><h2>Access this page using a URL like: $site?project=<a href=\"".$site."?project=".$default_project."><tt>".$default_project."</tt></a></h2></center>\n";
    }

?>
<hr />
</body>
</html>