[Customisation Database Commits] r203 - in /trunk/titania: ./ includes/ includes/core/ includes/objects/ install/ language/en/
Nathan Guse
exreaction at phpbb.com
Mon Jun 8 22:37:52 UTC 2009
Author: exreaction
Date: Mon Jun 8 22:37:52 2009
New Revision: 203
Log:
I was starting to work on the installer, then I got sidetracked to working on a ratings class somehow...
Installer still needs some love before it's finished with everything in the install.sql file
Added:
trunk/titania/includes/functions.php
trunk/titania/includes/objects/rating.php
trunk/titania/install/index.php
trunk/titania/language/en/install.php
Modified:
trunk/titania/common.php
trunk/titania/includes/constants.php
trunk/titania/includes/core/config.php
trunk/titania/includes/core/titania.php
trunk/titania/includes/objects/author.php
trunk/titania/includes/objects/contribution.php
trunk/titania/index.php
Modified: trunk/titania/common.php
==============================================================================
*** trunk/titania/common.php (original)
--- trunk/titania/common.php Mon Jun 8 22:37:52 2009
***************
*** 16,21 ****
--- 16,23 ----
exit;
}
+ define('TITANIA_VERSION', '0.1.0');
+
// Include titania class
require TITANIA_ROOT . 'includes/core/titania.' . PHP_EXT;
require TITANIA_ROOT . 'includes/core/phpbb.' . PHP_EXT;
***************
*** 25,30 ****
--- 27,33 ----
// Include titania constants
require TITANIA_ROOT . 'includes/constants.' . PHP_EXT;
+ require TITANIA_ROOT . 'includes/functions.' . PHP_EXT;
// We need this for compatibility reasons
$phpEx = PHP_EXT;
***************
*** 41,43 ****
--- 44,52 ----
// Start session management etc.
phpbb::initialise();
titania::initialise();
+
+ // If the database is not installed or outdated redirect to the installer
+ if (!defined('IN_TITANIA_INSTALL') && (!isset(phpbb::$config['custom_db_version']) || version_compare(phpbb::$config['custom_db_version'], TITANIA_VERSION, '<')))
+ {
+ //redirect(titania_sid('install/index'));
+ }
\ No newline at end of file
Modified: trunk/titania/includes/constants.php
==============================================================================
*** trunk/titania/includes/constants.php (original)
--- trunk/titania/includes/constants.php Mon Jun 8 22:37:52 2009
***************
*** 36,41 ****
--- 36,42 ----
define('CUSTOMISATION_TAG_TYPES_TABLE', $table_prefix . 'tag_types');
define('CUSTOMISATION_WATCH_TABLE', $table_prefix . 'watch');
define('CUSTOMISATION_CONTRIB_FAQ_TABLE', $table_prefix . 'contrib_faq');
+ define('CUSTOMISATION_RATINGS_TABLE', $table_prefix . 'ratings');
// Customisation (contrib) status
define('STATUS_NEW', 0);
***************
*** 84,88 ****
--- 85,93 ----
// Author constants
define('AUTHOR_HIDDEN', 0);
define('AUTHOR_VISIBLE', 1);
+
+ // Rating Type Constants
+ define('RATING_AUTHOR', 1);
+ define('RATING_CONTRIB', 2);
// Define further contrib types based on the tags, and tag_types tables.
Modified: trunk/titania/includes/core/config.php
==============================================================================
*** trunk/titania/includes/core/config.php (original)
--- trunk/titania/includes/core/config.php Mon Jun 8 22:37:52 2009
***************
*** 42,47 ****
--- 42,49 ----
'table_prefix' => array('default' => 'customisation_'),
'template_path' => array('default' => TITANIA_ROOT . 'template/'),
'theme_path' => array('default' => TITANIA_ROOT . 'theme/'),
+
+ 'max_rating' => array('default' => 5),
));
}
Modified: trunk/titania/includes/core/titania.php
==============================================================================
*** trunk/titania/includes/core/titania.php (original)
--- trunk/titania/includes/core/titania.php Mon Jun 8 22:37:52 2009
***************
*** 27,33 ****
* @var string
*/
public static $page;
!
/**
* Titania configuration member
*
--- 27,33 ----
* @var string
*/
public static $page;
!
/**
* Titania configuration member
*
***************
*** 205,213 ****
* Titania page_footer
*
* @param cron $run_cron
*/
! public static function page_footer($run_cron = true)
{
// admin requested the cache to be purged, ensure they have permission and purge the cache.
if (isset($_GET['cache']) && $_GET['cache'] == 'purge' && phpbb::$auth->acl_get('a_'))
{
--- 205,223 ----
* Titania page_footer
*
* @param cron $run_cron
+ * @param bool|string $template_body For those lazy like me, send the template body name you want to load (or leave default to ignore and assign it yourself)
*/
! public static function page_footer($run_cron = true, $template_body = false)
{
+ // Because I am lazy most of the time...
+ if ($template_body !== false)
+ {
+ global $template;
+ $template->set_filenames(array(
+ 'body' => $template_body,
+ ));
+ }
+
// admin requested the cache to be purged, ensure they have permission and purge the cache.
if (isset($_GET['cache']) && $_GET['cache'] == 'purge' && phpbb::$auth->acl_get('a_'))
{
Added: trunk/titania/includes/functions.php
==============================================================================
*** trunk/titania/includes/functions.php (added)
--- trunk/titania/includes/functions.php Mon Jun 8 22:37:52 2009
***************
*** 0 ****
--- 1,31 ----
+ <?php
+ /**
+ *
+ * @package Titania
+ * @version $Id$
+ * @copyright (c) 2008 phpBB Customisation Database Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+ /**
+ * @ignore
+ */
+ if (!defined('IN_TITANIA'))
+ {
+ exit;
+ }
+
+ /**
+ * Titania append_sid function. Why? Because this is easier. :P
+ *
+ * @param mixed $page What you would put between TITANIA_ROOT and '.' . PHP_EXT (if this doesn't work for you, use append_sid!)
+ * @param mixed $params Same as append_sid
+ * @param mixed $is_amp Same as append_sid
+ * @param mixed $session_id Same as append_sid
+ * @return string Same as append_sid
+ */
+ function titania_sid($page, $params = false, $is_amp = true, $session_id = false)
+ {
+ return append_sid(TITANIA_ROOT . $page . '.' . PHP_EXT, $params = false, $is_amp = true, $session_id = false);
+ }
\ No newline at end of file
Modified: trunk/titania/includes/objects/author.php
==============================================================================
*** trunk/titania/includes/objects/author.php (original)
--- trunk/titania/includes/objects/author.php Mon Jun 8 22:37:52 2009
***************
*** 77,97 ****
}
/**
- * Add rating
- *
- * @return void
- */
- public function add_rating($rating)
- {
- $points_current = $this->author_rating * $this->author_rating_count;
-
- $this->author_rating_count = $this->author_rating_count + 1;
- $this->author_rating = ($points_current + $rating) / $this->author_rating_count;
-
- $this->update();
- }
-
- /**
* Special setter methods overwriting the default magic methods.
*
* @param string $value
--- 77,82 ----
Modified: trunk/titania/includes/objects/contribution.php
==============================================================================
*** trunk/titania/includes/objects/contribution.php (original)
--- trunk/titania/includes/objects/contribution.php Mon Jun 8 22:37:52 2009
***************
*** 189,209 ****
}
/**
- * Add rating
- *
- * @return void
- */
- public function add_rating($rating)
- {
- $points_current = $this->contrib_rating * $this->contrib_rating_count;
-
- $this->contrib_rating_count = $this->contrib_rating_count + 1;
- $this->contrib_rating = ($points_current + $rating) / $this->contrib_rating_count;
-
- $this->update();
- }
-
- /**
* Get the author as an object
*
* @return titania_author
--- 189,194 ----
***************
*** 263,269 ****
static $day_seconds = 86400; // 24 * 60 * 60
// Cannot calculate anything without release date
! // No point in showing this if there were no downloads
if (!$this->contrib_release_date || !$this->contrib_downloads)
{
return '';
--- 248,254 ----
static $day_seconds = 86400; // 24 * 60 * 60
// Cannot calculate anything without release date
! // No point in showing this if there were no downloads
if (!$this->contrib_release_date || !$this->contrib_downloads)
{
return '';
Added: trunk/titania/includes/objects/rating.php
==============================================================================
*** trunk/titania/includes/objects/rating.php (added)
--- trunk/titania/includes/objects/rating.php Mon Jun 8 22:37:52 2009
***************
*** 0 ****
--- 1,230 ----
+ <?php
+ /**
+ *
+ * @package Titania
+ * @version $Id$
+ * @copyright (c) 2008 phpBB Customisation Database Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+ /**
+ * @ignore
+ */
+ if (!defined('IN_TITANIA'))
+ {
+ exit;
+ }
+
+ if (!class_exists('titania_database_object'))
+ {
+ require TITANIA_ROOT . 'includes/core/object_database.' . PHP_EXT;
+ }
+
+ /**
+ * Class to abstract titania ratings.
+ * @package Titania
+ */
+ class titania_rating extends titania_database_object
+ {
+ /**
+ * SQL Table
+ *
+ * @var string
+ */
+ protected $sql_table = CUSTOMISATION_RATINGS_TABLE;
+
+ /**
+ * SQL identifier field
+ *
+ * @var string
+ */
+ protected $sql_id_field = 'rating_id';
+
+ /**
+ * Rating Type
+ * Check Rating Type Constants
+ *
+ * @var int
+ */
+ protected $rating_type_id = 0;
+
+ /**
+ * Cache Table
+ * Rating table where the cache will be stored
+ *
+ * @var string
+ */
+ protected $cache_table = '';
+
+ /**
+ * Cache Rating
+ * The field to update with the rating value cache
+ *
+ * @var string
+ */
+ protected $cache_rating = '';
+
+ /**
+ * Cache Rating Count
+ * The field to update with the rating count cache
+ *
+ * @var string
+ */
+ protected $cache_rating_count = '';
+
+ /**
+ * Object ID
+ * The rating item ID (ex: author_id for rating authors)
+ *
+ * @var int
+ */
+ protected $object_id = 0;
+
+ /**
+ * Rating
+ * The rating of the item
+ *
+ * @var decimal
+ */
+ protected $rating = 0;
+
+ /**
+ * Rating Count
+ * The number of ratings for the item
+ *
+ * @var int
+ */
+ protected $rating_count = 0;
+
+ /**
+ * Constructor class for titania authors
+ *
+ * @param string $type The type of rating
+ * @param object $object The object we will be rating (author/contrib object)
+ */
+ public function __construct($type, $object)
+ {
+ // Configure object properties
+ $this->object_config = array_merge($this->object_config, array(
+ 'rating_id' => array('default' => 0),
+ 'rating_type_id' => array('default' => 0),
+ 'rating_user_id' => array('default' => 0),
+ 'rating_object_id' => array('default' => 0),
+ 'rating_value' => array('default' => 0.0),
+ ));
+
+ switch($type)
+ {
+ case 'author' :
+ $this->rating_type_id = RATING_AUTHOR;
+ $this->cache_table = CUSTOMISATION_AUTHORS_TABLE;
+ $this->cache_rating = 'author_rating';
+ $this->cache_rating_count = 'author_rating_count';
+ $this->object_id = $object->author_id;
+ break;
+
+ case 'contrib' :
+ $this->rating_type_id = RATING_CONTRIB;
+ $this->cache_table = CUSTOMISATION_CONTRIBS_TABLE;
+ $this->cache_rating = 'contrib_rating';
+ $this->cache_rating_count = 'contrib_rating_count';
+ $this->object_id = $object->contrib_id;
+ break;
+ }
+
+ // Get the rating and rating count
+ $this->rating = $object->{$this->cache_rating};
+ $this->rating_count = $object->{$this->cache_rating_count};
+
+ // Get the current user's rating (if any)
+ $this->get_rating();
+ }
+
+ /**
+ * Get the current user's rating
+ */
+ public function get_rating()
+ {
+ if (!phpbb::$user->data['is_registered'])
+ {
+ return;
+ }
+
+ $sql = 'SELECT * FROM ' . $this->sql_table . '
+ WHERE rating_type_id = ' . (int) $this->rating_type . '
+ AND rating_user_id = ' . (int) phpbb::$user->data['user_id'] . '
+ AND rating_object_id = ' . (int) $this->object_id;
+ $result = phpbb::$db->sql_query($sql);
+ $this->sql_data = phpbb::$db->sql_fetchrow($result);
+ phpbb::$db->sql_freeresult($result);
+
+ if ($row)
+ {
+ foreach ($this->sql_data as $key => $value)
+ {
+ $this->$key = $value;
+ }
+ }
+ }
+
+ /**
+ * Get rating string
+ *
+ * @return string The rating string ready for output
+ */
+ public function get_rating_string()
+ {
+ }
+
+ /**
+ * Add a Rating for an item
+ *
+ * @param mixed $rating The rating
+ */
+ public function add_rating($rating)
+ {
+ if (!phpbb::$user->data['is_registered'] || !phpbb::$auth->acl_get('cdb_rate'))
+ {
+ return;
+ }
+
+ if ($rating < 0 || $rating > titania::$config['max_rating'])
+ {
+ return false;
+ }
+
+ $this->rating_value = $rating;
+
+ $this->submit();
+ }
+
+ /**
+ * Delete the user's own rating
+ */
+ public function delete_rating()
+ {
+ if (!phpbb::$user->data['is_registered'] || !$this->rating_id)
+ {
+ return;
+ }
+
+ // delete a rating from this item
+ }
+
+ /**
+ * Reset the rating for this object
+ */
+ public function reset_rating()
+ {
+ if (!phpbb::$auth->acl_get('cdb_rate_reset'))
+ {
+ return;
+ }
+
+ $sql = 'DELETE FROM ' . $this->sql_table . '
+ WHERE rating_type_id = ' . (int) $this->rating_type . '
+ AND rating_object_id = ' . (int) $this->object_id;
+ phpbb::$db->sql_query($sql);
+ }
+ }
\ No newline at end of file
Modified: trunk/titania/index.php
==============================================================================
*** trunk/titania/index.php (original)
--- trunk/titania/index.php Mon Jun 8 22:37:52 2009
***************
*** 37,44 ****
// Output page
titania::page_header($module->get_page_title());
! $template->set_filenames(array(
! 'body' => $module->get_tpl_name(),
! ));
!
! titania::page_footer();
--- 37,40 ----
// Output page
titania::page_header($module->get_page_title());
! titania::page_footer(true, $module->get_tpl_name());
Added: trunk/titania/install/index.php
==============================================================================
*** trunk/titania/install/index.php (added)
--- trunk/titania/install/index.php Mon Jun 8 22:37:52 2009
***************
*** 0 ****
--- 1,92 ----
+ <?php
+ /**
+ *
+ * @package titania
+ * @version $Id$
+ * @copyright (c) 2008 phpBB Customisation Database Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+ /**
+ * @ignore
+ */
+ define('IN_TITANIA', true);
+ define('IN_TITANIA_INSTALL', true);
+ if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', '../');
+ if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
+ require TITANIA_ROOT . 'common.' . PHP_EXT;
+ $titania->add_lang('install');
+
+ if (!file_exists(PHPBB_ROOT_PATH . 'umil/umil_auto.' . PHP_EXT))
+ {
+ trigger_error('Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
+ }
+
+ $mod_name = 'CUSTOMISATION_DATABASE';
+ $version_config_name = 'cdb_version';
+
+
+ $versions = array(
+ '0.1.0' => array(
+ 'table_add' => array(
+ array('customisation_authors', array(
+ 'COLUMNS' => array(
+ 'author_id' => array('UINT', NULL, 'auto_increment'),
+ 'user_id' => array('UINT', 0),
+ 'phpbb_user_id' => array('UINT', 0),
+ 'author_username' => array('VCHAR_CI', ''),
+ 'author_username_clean' => array('VCHAR_CI', ''),
+ 'author_realname' => array('VCHAR_CI', ''),
+ 'author_website' => array('VCHAR_UNI:200', ''),
+ 'author_email' => array('VCHAR_UNI:100', ''),
+ 'author_email_hash' => array('BINT', 0),
+ 'author_rating' => array('DECIMAL:6', 0),
+ 'author_rating_count' => array('UINT', 0),
+ 'author_contribs' => array('UINT', 0), //
+ 'author_snippets' => array('UINT', 0), // Number of snippets
+ 'author_mods' => array('UINT', 0), // Number of mods
+ 'author_styles' => array('UINT', 0), // Number of styles
+ 'author_visible' => array('BOOL', 1),
+ ),
+ 'PRIMARY_KEY' => 'author_id',
+ 'KEYS' => array(
+ 'user_id' => array('INDEX', 'user_id'),
+ 'phpbb_user_id' => array('INDEX', 'phpbb_user_id'),
+ 'author_username_clean' => array('INDEX', 'author_username_clean'),
+ 'author_rating' => array('INDEX', 'author_uauthor_ratingsername_clean'),
+ 'author_contribs' => array('INDEX', 'author_contribs'),
+ 'author_snippets' => array('INDEX', 'author_snippets'),
+ 'author_mods' => array('INDEX', 'author_mods'),
+ 'author_styles' => array('INDEX', 'author_styles'),
+ ),
+ )),
+ array('customisation_ratings', array(
+ 'COLUMNS' => array(
+ 'rating_id' => array('UINT', NULL, 'auto_increment'),
+ 'rating_type_id' => array('UINT', 0),
+ 'rating_user_id' => array('UINT', 0),
+ 'rating_object_id' => array('UINT', 0),
+ 'rating_value' => array('DECIMAL:6', 0), // Not sure if we should allow partial ratings (like 4.5/5) or just integer ratings...
+ ),
+ 'PRIMARY_KEY' => 'rating_id',
+ 'KEYS' => array(
+ 'type_user_object' => array('UNIQUE', array('rating_type_id', 'rating_user_id', 'rating_object_id')),
+ ),
+ )),
+ ),
+
+ 'permission_add' => array(
+ 'cdb_',
+ 'cdb_rate',
+ 'cdb_rate_reset',
+ ),
+ ),
+
+ // IF YOU ADD A NEW VERSION DO NOT FORGET TO INCREMENT THE VERSION NUMBER IN common.php!
+ );
+
+ // Include the UMIF Auto file and everything else will be handled automatically.
+ include(PHPBB_ROOT_PATH . 'umil/umil_auto.' . PHP_EXT);
+
+ ?>
\ No newline at end of file
Added: trunk/titania/language/en/install.php
==============================================================================
*** trunk/titania/language/en/install.php (added)
--- trunk/titania/language/en/install.php Mon Jun 8 22:37:52 2009
***************
*** 0 ****
--- 1,41 ----
+ <?php
+ /**
+ *
+ * mods [English]
+ *
+ * @package Titania
+ * @version $Id$
+ * @copyright (c) 2008 phpBB Customisation Database Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+ /**
+ * DO NOT CHANGE
+ */
+ if (!defined('IN_TITANIA'))
+ {
+ exit;
+ }
+
+ if (empty($lang) || !is_array($lang))
+ {
+ $lang = array();
+ }
+
+ // DEVELOPERS PLEASE NOTE
+ //
+ // All language files should use UTF-8 as their encoding and the files must not contain a BOM.
+ //
+ // Placeholders can now contain order information, e.g. instead of
+ // 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
+ // translators to re-order the output of data while ensuring it remains correct
+ //
+ // You do not need this where single placeholders are used, e.g. 'Message %d' is fine
+ // equally where a string contains only two placeholders which are used to wrap text
+ // in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
+
+ $lang = array_merge($lang, array(
+ 'CUSTOMISATION_DATABASE' => 'Customisation Database',
+ ));
+
More information about the customisationdb-commits
mailing list