Added shared and developer sections.

This commit is contained in:
mike.morgan%oregonstate.edu 2005-12-22 20:34:05 +00:00
Родитель f8c59562c7
Коммит 0458bf8402
11 изменённых файлов: 2482 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,299 @@
<?php
/**
* Addon super class. The class to end all classes.
* @package amo
* @subpackage lib
* @todo properly separate accessors and mutators.
*/
class AddOn extends AMO_Object {
// AddOn metadata.
var $ID;
var $GUID;
var $Name;
var $Type;
var $DateAdded;
var $DateUpdated;
var $Homepage;
var $Description;
var $Rating;
var $downloadcount;
var $TotalDownloads;
var $devcomments;
var $db;
var $tpl;
// AddOn author metadata.
var $UserID;
var $UserName;
var $UserEmail;
var $UserWebsite;
var $UserEmailHide;
// Current version information.
var $vID;
var $Version;
var $MinAppVer;
var $MaxAppVer;
var $Size;
var $URI;
var $Notes;
var $VersionDateAdded;
var $AppName;
var $OSName;
// Preview information.
var $PreviewID;
var $PreviewURI;
var $PreviewHeight;
var $PreviewWidth;
var $Caption;
var $Previews = array(); // Store the information for previews
// Comments.
var $Comments;
// Categories.
var $AddonCats;
// History of releases
var $History;
/**
* Class constructor.
*
* @param int $ID AddOn ID
*/
function AddOn($ID=null) {
// Our DB and Smarty objects are global to save cycles.
global $db, $tpl;
// Pass by reference in order to save memory.
$this->db =& $db;
$this->tpl =& $tpl;
// If $ID is set, attempt to retrieve data.
if (!empty($ID)) {
$this->ID = $ID;
$this->getAddOn();
}
}
/**
* Get all commonly used AddOn information.
*/
function getAddOn() {
$this->getAddonCats();
$this->getComments();
$this->getCurrentVersion();
$this->getMainPreview();
$this->getUserInfo();
}
/**
* Get the "highlight" for the current AddOn.
*/
function getMainPreview() {
// Gather previews information.
$this->db->query("
SELECT
PreviewID,
PreviewURI,
Caption
FROM
previews
WHERE
ID = '{$this->ID}' AND
preview = 'YES'
LIMIT 1
", SQL_INIT, SQL_ASSOC);
if (!empty($this->db->record)) {
$this->setVars($this->db->record);
if (file_exists(ROOT_PATH.$this->PreviewURI)) {
$size = getimagesize(ROOT_PATH.$this->PreviewURI);
$this->setVar('PreviewWidth',$size[0]);
$this->setVar('PreviewHeight',$size[1]);
}
}
}
/**
* Get all preview information attached to the current AddOn.
*/
function getPreviews() {
// Gather preview information
$this->db->query("
SELECT
PreviewURI,
caption
FROM
previews
WHERE
ID = {$this->ID}
ORDER BY
PreviewID ASC
", SQL_NONE);
while ($this->db->next(SQL_ASSOC)) {
$result = $this->db->record;
$uri = $result['PreviewURI'];
list($src_width, $src_height, $type, $attr) = getimagesize(ROOT_PATH.$uri);
$this->Previews[] = array(
'PreviewURI' => $uri,
'caption' => $result['caption'],
'width' => $src_width,
'height' => $src_height
);
}
}
/**
* Get all previous versions of the current AddOn.
*/
function getHistory() {
$this->db->query("
SELECT
TV.vID,
TV.Version,
TV.MinAppVer,
TV.MaxAppVer,
TV.Size,
TV.URI,
TV.Notes,
UNIX_TIMESTAMP(TV.DateAdded) AS VerDateAdded,
TA.AppName,
TOS.OSName
FROM
version TV
INNER JOIN applications TA ON TV.AppID = TA.AppID
INNER JOIN os TOS ON TV.OSID = TOS.OSID
WHERE
TV.ID = {$this->ID} AND
approved = 'YES'
ORDER BY
VerDateAdded DESC
", SQL_ALL, SQL_ASSOC);
$this->History = $this->db->record;
}
/**
* Get information about the most recent verison of the current AddOn.
*/
function getCurrentVersion() {
$this->db->query("
SELECT
version.vID,
version.Version,
version.MinAppVer,
version.MaxAppVer,
version.Size,
version.URI,
version.Notes,
version.DateAdded as VersionDateAdded,
applications.AppName,
os.OSName
FROM
version
INNER JOIN applications ON version.AppID = applications.AppID
INNER JOIN os ON version.OSID = os.OSID
WHERE
version.ID = '{$this->ID}' AND
version.approved = 'YES'
ORDER BY
version.DateAdded DESC
LIMIT 1
", SQL_INIT, SQL_ASSOC);
if (!empty($this->db->record)) {
$this->setVars($this->db->record);
}
}
/**
* Retrieve user information.
*
* @todo have this function set a User object instead
*/
function getUserInfo() {
// Gather addons metadata, user info.
$this->db->query("
SELECT
main.*,
userprofiles.UserID,
userprofiles.UserName,
userprofiles.UserEmail,
userprofiles.UserWebsite,
userprofiles.UserEmailHide
FROM
main
INNER JOIN authorxref ON authorxref.ID = main.ID
INNER JOIN userprofiles ON userprofiles.UserID = authorxref.UserID
WHERE
main.ID = '{$this->ID}'
", SQL_INIT, SQL_ASSOC);
if (!empty($this->db->record)) {
$this->setVars($this->db->record);
}
}
/**
* Get comments attached to this Addon.
*
* @param int $limit number of rows to limit by.
* @todo add left/right limit clauses i.e. LIMIT 10,20 to work with pagination
*/
function getComments($limit=5) {
// Gather 10 latest comments.
$this->db->query("
SELECT
CommentID,
CommentName,
CommentTitle,
CommentNote,
CommentDate,
CommentVote,
`helpful-yes` as helpful_yes,
`helpful-no` as helpful_no,
`helpful-yes` + `helpful-no` as helpful_total
FROM
feedback
WHERE
ID = '{$this->ID}' AND
CommentNote IS NOT NULL
ORDER BY
CommentDate DESC
LIMIT {$limit}
", SQL_ALL, SQL_ASSOC);
$this->setVar('Comments',$this->db->record);
}
/**
* Retrieve all categories attached to the current AddOn.
*/
function getAddonCats() {
// Gather addon categories.
$this->db->query("
SELECT DISTINCT
categories.CatName,
categories.CategoryID
FROM
categoryxref
INNER JOIN categories ON categoryxref.CategoryID = categories.CategoryID
INNER JOIN main ON categoryxref.ID = main.ID
WHERE
categoryxref.ID = {$this->ID}
GROUP BY
categories.CatName
ORDER BY
categories.CatName
", SQL_ALL, SQL_ASSOC);
$this->setVar('AddonCats',$this->db->record);
}
}
?>

Просмотреть файл

@ -0,0 +1,128 @@
<?php
/**
* AMO master class. This class contains global application logic.
* @todo properly separate accessors and mutators.
* @todo don't store data in this superclass -- strip vars except for tpl/db.
*/
class AMO_Object
{
var $cats;
var $apps;
var $platforms;
var $db;
var $tpl;
/**
* AMO_Object constructor.
*/
function AMO_Object() {
// Our DB and Smarty objects are global to save cycles.
global $db, $tpl;
// Pass by reference in order to save memory.
$this->db =& $db;
$this->tpl =& $tpl;
}
/**
* Set var.
*
* @param string $key name of object property to set
* @param mixed $val value to assign
*
* @return bool
*/
function setVar($key,$val)
{
$this->$key = $val;
return true;
}
/**
* Set an array of variables based on a $db record.
*
* @param array $data associative array of data.
*
* @return bool
*/
function setVars($data)
{
if (is_array($data)) {
foreach ($data as $key=>$val) {
$this->setVar($key,$val);
}
return true;
} else {
return false;
}
}
/**
* Get all category names.
*/
function getCats()
{
// Gather categories.
$this->db->query("
SELECT
CategoryID,
CatName
FROM
categories
GROUP BY
CatName
ORDER BY
CatName
", SQL_INIT, SQL_ASSOC);
do {
$this->Cats[$this->db->record['CategoryID']] = $this->db->record['CatName'];
} while ($this->db->next(SQL_ASSOC));
}
/**
* Get all operating system names (platforms). Used to populate forms.
*/
function getPlatforms()
{
// Gather platforms..
$this->db->query("
SELECT
OSID,
OSName
FROM
os
ORDER BY
OSName
", SQL_INIT, SQL_ASSOC);
do {
$this->Platforms[$this->db->record['OSID']] = $this->db->record['OSName'];
} while ($this->db->next(SQL_ASSOC));
}
/**
* Get all application names. Used to populate forms.
*/
function getApps()
{
// Gather aapplications.
$this->db->query("
SELECT DISTINCT
AppID,
AppName
FROM
applications
WHERE
public_ver = 'YES'
GROUP BY
AppName
", SQL_INIT, SQL_ASSOC);
do {
$this->Apps[$this->db->record['AppID']] = $this->db->record['AppName'];
} while ($this->db->next(SQL_ASSOC));
}
}
?>

Просмотреть файл

@ -0,0 +1,28 @@
<?php
/**
* Basic error functions for triggering fatal runtime errors.
* This class is generally called when a page load should be terminated because of bad inputs.
*
* @package amo
* @subpackage lib
*/
/**
* @param string $errorMessage Message to display.
* @param string $errorTemplate Template to call (defaults to error template).
*/
function triggerError($errorMessage=null,$errorTemplate='error.tpl')
{
$tpl =& new AMO_Smarty();
$tpl->assign(
array(
'error'=>$errorMessage,
'content'=>$errorTemplate,
'backtrace'=>debug_backtrace()
)
);
$tpl->display('inc/wrappers/nonav.tpl');
exit;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -0,0 +1,110 @@
<?php
/**
* PEAR::DB wrappers for SQL queries.
* @package amo
* @subpackage lib
* @author Monte Ohrt <monte [AT] ohrt [DOT] com>
*/
// Define query types.
define('SQL_NONE', 1);
define('SQL_ALL', 2);
define('SQL_INIT', 3);
// Define the query formats.
define('SQL_ASSOC', 1);
define('SQL_INDEX', 2);
class SQL {
var $db = null;
var $result = null;
var $error = null;
var $record = null;
/**
* Class constructor.
*/
function SQL() { }
/**
* Connect to the database.
*
* @param string $dsn the data source name
* @return bool
*/
function connect($dsn) {
$this->db =& DB::connect($dsn);
if(PEAR::isError($this->db)) {
$this->error =& $this->db->getMessage();
return false;
}
return true;
}
/**
* Disconnect from the database.
*/
function disconnect() {
$this->db->disconnect();
}
/**
* Query the database.
*
* @param string $query the SQL query
* @param string $type the type of query
* @param string $format the query format
*/
function query($query, $type = SQL_NONE, $format = SQL_INDEX) {
$this->record = array();
$_data = array();
// Determine fetch mode (index or associative).
$_fetchmode = ($format == SQL_ASSOC) ? DB_FETCHMODE_ASSOC : null;
$this->result = $this->db->query($query);
if (DB::isError($this->result)) {
$this->error = $this->result->getMessage();
return false;
}
switch ($type) {
case SQL_ALL:
// Get all the records.
while($_row = $this->result->fetchRow($_fetchmode)) {
$_data[] = $_row;
}
$this->result->free();
$this->record = $_data;
break;
case SQL_INIT:
// Get the first record.
$this->record = $this->result->fetchRow($_fetchmode);
break;
case SQL_NONE:
default:
// Records will be looped over with next().
break;
}
return true;
}
/**
* Select next row in result.
* @param string $format the query format
*/
function next($format = SQL_INDEX) {
// Fetch mode (index or associative).
$_fetchmode = ($format == SQL_ASSOC) ? DB_FETCHMODE_ASSOC : null;
if ($this->record = $this->result->fetchRow($_fetchmode)) {
return true;
} else {
$this->result->free();
return false;
}
}
}
?>

Просмотреть файл

@ -0,0 +1,33 @@
<?php
/**
* systemMessage function -- just a snippet
* @todo incorporate into OO, using $db->query to pull messages (if they exist and are flagged as active)
* @todo add db tables to SQL schema
*/
#define PAGE_TYPE_FRONT_PAGE 1
#define PAGE_TYPE_DEVELOPER_PAGE 2
#define PAGE_TYPE_LIST_PAGE 4
#define PAGE_TYPE_DETAIL_PAGE 8
// these values can be done as a DB table so they can be controlled and edited by site admins without access to the webserver itself
function getSystemMessageData() {
$messageData['header'] = 'Want to get involved?';
$messageData['text'] = 'We are looking for volunteers to help us with UMO. We are in need of PHP developers to help with redesigning the site, and people to review extensions and themes that get submitted to UMO. We especially need Mac and Thunderbird users. If you are interested in being a part of this exciting project, please send information such as your full name, timezone and experience to <a href="mailto:umo-reviewer@mozilla.org?subject=Review%20Application%20for%20[Name Here]">umo-reviewer@mozilla.org</a>. Also, please join us in #umo on irc.mozilla.org to start getting a feeling for what\'s up or for a more informal chat.';
$messageData['pageType'] = 1;
return $messageData;
}
function showSystemMessage($pageType) {
$messageData = getSystemMessageData();
if ($messageData['pageType'] & $pageType) {
$smarty->assign("systemMessage", $messageData);
}
}
// USAGE:
// showSystemMessage(PAGE_TYPE_FRONT_PAGE); should be somewhere in the script, with the
// appropriate page type
?>

Просмотреть файл

@ -0,0 +1,92 @@
<?php
/**
* User class. Contains user methods and metadata.
* @package amo
* @subpackage docs
*/
class User extends AMO_Object
{
// User metadata.
var $UserID;
var $UserEmail;
var $UserWebsite;
var $UserMode;
var $UserTrusted;
var $UserEmailHide;
var $UserLastLogin;
// Addons metadata.
var $AddOns;
/**
* Constructor.
*
* @param int $UserID UserID
*/
function User($UserID=null)
{
// Our DB and Smarty objects are global to save cycles.
global $db, $tpl;
// Pass by reference in order to save memory.
$this->db =& $db;
$this->tpl =& $tpl;
// If $ID is set, attempt to retrieve data.
if (!empty($UserID)) {
$this->setVar('UserID',$UserID);
$this->getUser();
$this->GetAddons();
}
}
/**
* Get user information from singular record.
*/
function getUser()
{
$this->db->query("
SELECT
UserName,
UserEmail,
UserWebsite,
UserMode,
UserTrusted,
UserEmailHide,
UserLastLogin
FROM
userprofiles
WHERE
UserID = {$this->UserID}
", SQL_INIT, SQL_ASSOC);
if (!empty($this->db->record)) {
$this->setVars($this->db->record);
}
}
/**
* Get addons for this author.
*/
function getAddons()
{
// Gather addons metadata, user info.
$this->db->query("
SELECT
main.ID,
main.Name,
main.Description
FROM
main
INNER JOIN authorxref ON authorxref.ID = main.ID
INNER JOIN userprofiles ON userprofiles.UserID = authorxref.UserID
WHERE
userprofiles.UserID = '{$this->UserID}'
", SQL_ALL, SQL_ASSOC);
if (!empty($this->db->record)) {
$this->setVar('AddOns',$this->db->record);
}
}
}
?>

Просмотреть файл

@ -0,0 +1,148 @@
<?php
/**
* Version class. Represents version of app/addon in FVF
* "major[.minor[.release[.build+]]]"
* @package amo
* @subpackage lib
* @link http://www.mozilla.org/projects/firefox/extensions/update.html
*/
class Version
{
var $major;
var $minor;
var $release;
var $build;
var $plus;
/**
* Class constructor.
*
* @param string $aVersionString FVF version conformant string
*/
function Version($aVersionString=NULL) {
if (isset($aVersionString)) {
$this->parseString($aVersionString);
}
}
/**
* Parse a version string into useful chunks.
*
* @param string $aVersionString FVF conformant version string
*/
function parseString($aVersionString) {
assert(strlen($aVersionString));
// in case we're being re-used
$this->major = NULL;
$this->minor = NULL;
$this->release = NULL;
$this->build = NULL;
$this->plus = NULL;
// holder for the chunks, to be filled by preg_match
$matches = array();
if (preg_match('/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+)([a-zA-Z0-9]+)?)?$/', $aVersionString, $matches)) {
if (isset($matches[1])) {
$this->major = intval($matches[1]);
if (isset($matches[2])) {
$this->minor = intval($matches[2]);
if (isset($matches[3])) {
$this->release = intval($matches[3]);
if (isset($matches[4])) {
$this->build = intval($matches[4]);
if (isset($matches[5])) {
$this->plus = $matches[5];
}
}
}
}
}
}
assert($aVersionString == $this->toString());
}
/**
* Is this a valid version
*
* @return boolean TRUE if the instance represents a valid version
* FALSE otherwise
*
* @todo this may or may not be required. it simply relies on the
* fact that major is not optional. any valid string would
* have been parsed, and major set
*/
function isValid() {
return isset($this->major);
}
/**
* Static method to compare one Version to another Version
*
* @param a a Version
* @param a a Version
* @returns < 0 if a < b
* = 0 if a == b
* > 0 if a > b
*/
function compare($a, $b) {
assert(is_a($a, 'Version'));
assert(is_a($b, 'Version'));
assert($a->isValid());
assert($b->isValid());
if ($a->major != $b->major) {
return $a->major - $b->major;
}
if ($a->minor != $b->minor) {
return $a->minor - $b->minor;
}
if ($a->release != $b->release) {
return $a->release - $b->release;
}
if ($a->build != $b->build) {
return $a->build - $b->build;
}
return 0;
}
/**
* Produce a string version
*
* @returns string the version encoded in FVF conformant string
*/
function toString() {
$chunks = array($this->major);
if (isset($this->minor)) {
$chunks[] = $this->minor;
if (isset($this->release)) {
$chunks[] = $this->release;
if (isset($this->build)) {
if (isset($this->plus)) {
$chunks[] = $this->build . $this->plus;
} else {
$chunks[] = $this->build;
}
}
}
}
return implode('.', $chunks);
}
}
?>

Просмотреть файл

@ -0,0 +1,7 @@
CREATE TABLE PHPSESSION (
SESSIONID VARCHAR(32) NOT NULL DEFAULT '',
SESSIONDATA TEXT NOT NULL DEFAULT '',
PRIMARY KEY(SESSIONID)
)
ENGINE=InnoDB;