[cc-commits] [CC SVN] r12588 - in cchost/trunk/cchost_lib: . ccextras
webmaster at creativecommons.org
webmaster at creativecommons.org
Sat May 9 11:58:04 EDT 2009
Author: fourstones
Date: 2009-05-09 15:58:04 +0000 (Sat, 09 May 2009)
New Revision: 12588
Modified:
cchost/trunk/cchost_lib/cc-user.php
cchost/trunk/cchost_lib/ccextras/cc-playlist.inc
cchost/trunk/cchost_lib/ccextras/cc-playlist.php
Log:
query: playlist_type parameter
Modified: cchost/trunk/cchost_lib/cc-user.php
===================================================================
--- cchost/trunk/cchost_lib/cc-user.php 2009-05-09 12:59:07 UTC (rev 12587)
+++ cchost/trunk/cchost_lib/cc-user.php 2009-05-09 15:58:04 UTC (rev 12588)
@@ -127,9 +127,9 @@
function IDFromName($username)
{
- $users =& CCUsers::GetTable();
- $where = "user_name = '" . strtolower($username) . "'";
- return( $users->QueryKey($where) );
+ return CCDatabase::QueryItem(
+ 'SELECT user_id FROM cc_tbl_user WHERE user_name = \'' .
+ strtolower($username) . '\'' );
}
/**
Modified: cchost/trunk/cchost_lib/ccextras/cc-playlist.inc
===================================================================
--- cchost/trunk/cchost_lib/ccextras/cc-playlist.inc 2009-05-09 12:59:07 UTC (rev 12587)
+++ cchost/trunk/cchost_lib/ccextras/cc-playlist.inc 2009-05-09 15:58:04 UTC (rev 12588)
@@ -103,8 +103,12 @@
'{upload_id},{playlist_id}', _('Add upload to playlist'), CC_AG_PLAYLIST );
+ CCEvents::MapUrl( ccp('api','playlist','type'), array( 'CCPlaylists', 'GetType'), CC_MUST_BE_LOGGED_IN, ccs(__FILE__),
+ '{user_name}/{type}', _('Get a specific type of playlist (e.g. favorites'), CC_AG_PLAYLIST );
+
CCEvents::MapUrl( ccp('api','playlist','getfavorite'), array( 'CCPlaylists', 'GetFavorite'), CC_MUST_BE_LOGGED_IN, ccs(__FILE__),
- '', _('Get the current user\'s favorites playlist'), CC_AG_PLAYLIST );
+ '', _(''), CC_AG_deprecated );
+
CCEvents::MapUrl( ccp('api','playlist','remove'), array( 'CCPlaylists', 'Remove'), CC_MUST_BE_LOGGED_IN, ccs(__FILE__),
'{upload_id},{playlist_id}', _('Remove upload from playlist'), CC_AG_PLAYLIST );
CCEvents::MapUrl( ccp('api','playlist','bump'), array( 'CCPlaylists', 'Bump'), CC_DONT_CARE_LOGGED_IN, ccs(__FILE__) ,
@@ -146,26 +150,25 @@
}
- function GetFavorite()
+ function GetType($user_name,$type,$name='')
{
- $user_id = CCUser::CurrentUser();
- $sql = "SELECT cart_id FROM cc_tbl_cart WHERE cart_user = '{$user_id}' and cart_subtype = 'favorites'";
- $cart_id = CCDatabase::QueryItem($sql);
- if( empty($cart_id) )
- {
- global $CC_GLOBALS;
- require_once('cchost_lib/ccextras/cc-playlist.inc');
- $api = new CCPlaylists();
- $title = sprintf( _("%s's Favorites"), $CC_GLOBALS['user_real_name'] );
- $cart_id = $api->_create_playlist('favorites',$title);
- }
+ $name = empty($name) ? $type : urldecode($name);
+ $user_id = CCUser::IDFromName($user_name);
+ $cart_id = CCPlaylistHV::_get_type_for_user($user_id,$type,true,$name);
$cart_items =& CCPlaylistItems::GetTable();
$w['cart_item_cart'] = $cart_id;
$ids = $cart_items->QueryItems('cart_item_upload',$w);
$obj = array( 'cart_id' => $cart_id, 'upload_ids' => $ids );
CCUtil::ReturnAjaxData($obj); // this will exit
}
-
+
+ function GetFavorite()
+ {
+ $user_name = CCUser::CurrentUserName();
+ $pname = empty($_GET['pname']) ? $user_name . "'s Favorites" : urldecode($_GET['pname']);
+ $this->GetType($user_name,'favorites', $pname); // todo stringize
+ }
+
function Save()
{
require_once('cchost_lib/cc-query.php');
Modified: cchost/trunk/cchost_lib/ccextras/cc-playlist.php
===================================================================
--- cchost/trunk/cchost_lib/ccextras/cc-playlist.php 2009-05-09 12:59:07 UTC (rev 12587)
+++ cchost/trunk/cchost_lib/ccextras/cc-playlist.php 2009-05-09 15:58:04 UTC (rev 12588)
@@ -53,12 +53,25 @@
{
function OnApiQuerySetup( &$args, &$queryObj, $requiresValidation )
{
- if( empty($args['playlist']) )
+ if( !empty($args['dataview']) && ($args['dataview'] == 'passthru') )
return;
- if( !empty($args['dataview']) && ($args['dataview'] == 'passthru') )
+ if( !empty($args['playlist_type']) )
+ {
+ if( !empty($args['user']) )
+ {
+ $user_id = CCUser::IDFromName($args['user']);
+ if( empty($user_id) )
+ return; // er, no error?
+ $args['playlist'] = $this->_get_type_for_user($user_id,$args['playlist_type'],false,null);
+
+ unset($args['user']);
+ }
+ }
+
+ if( empty($args['playlist']) )
return;
-
+
$id = sprintf('0%d',$args['playlist']);
$ok = $id > 0;
if( $ok )
@@ -191,7 +204,6 @@
return;
}
-
require_once('cchost_lib/ccextras/cc-cart-table.inc');
$carts = new CCPlaylist(false);
$w['cart_user'] = $record['user_id'];
@@ -287,7 +299,22 @@
}
}
+ function _get_type_for_user( $user_id, $type, $auto_create, $name )
+ {
+ $sql = "SELECT cart_id FROM cc_tbl_cart WHERE cart_user = '{$user_id}' and cart_subtype = '{$type}'";
+ $cart_id = CCDatabase::QueryItem($sql);
+ if( empty($cart_id) && $auto_create)
+ {
+ require_once('cchost_lib/ccextras/cc-playlist.inc');
+ $api = new CCPlaylists();
+ //global $CC_GLOBALS;
+ //$name = sprintf( _("%s's Favorites"), $CC_GLOBALS['user_real_name'] );
+ $cart_id = $api->_create_playlist($type,$name);
+ }
+ return $cart_id;
+ }
+
}
function cc_playlist_enabled()
@@ -297,4 +324,4 @@
return !empty($CC_GLOBALS['enable_playlists']);
}
-?>
\ No newline at end of file
+?>
More information about the cc-commits
mailing list