[cc-commits] [CC SVN] r14211 - in cchost/trunk: . cchost_lib dig dig/js dig/lib dig/pages
webmaster at creativecommons.org
webmaster at creativecommons.org
Tue Mar 2 16:27:07 EST 2010
Author: fourstones
Date: 2010-03-02 21:27:07 +0000 (Tue, 02 Mar 2010)
New Revision: 14211
Modified:
cchost/trunk/cc-cmd-line.inc
cchost/trunk/cchost_lib/cc-query.php
cchost/trunk/dig/.htaccess
cchost/trunk/dig/index.php
cchost/trunk/dig/js/ccm-query.js
cchost/trunk/dig/js/ccmd.js
cchost/trunk/dig/lib/head.php
cchost/trunk/dig/lib/query_proxy.php
cchost/trunk/dig/pages/dig.php
cchost/trunk/dig/pages/featured.php
cchost/trunk/dig/pages/picks.php
cchost/trunk/dig/pages/podcasts.php
cchost/trunk/dig/pages/popular.php
Log:
move queries to server (pt. 1)
Modified: cchost/trunk/cc-cmd-line.inc
===================================================================
--- cchost/trunk/cc-cmd-line.inc 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/cc-cmd-line.inc 2010-03-02 21:27:07 UTC (rev 14211)
@@ -36,6 +36,12 @@
if( !defined('CC_HOST_CMD_LINE') )
die('Welcome to ccHost');
+
+global $CC_GLOBALS;
+global $CC_CFG_ROOT;
+
+$CC_GLOBALS = array();
+$CC_CFG_ROOT = '';
define('IN_CC_HOST',1);
require_once('cchost_lib/cc-debug.php');
@@ -52,6 +58,9 @@
CCConfigs::Init();
}
+// CCDebug::Enable(true);
+// CCDebug::PrintVar($CC_GLOBALS);
+
if( !empty($CC_GLOBALS['extra-lib']) )
{
$cc_extras_dirs = $CC_GLOBALS['extra-lib'];
Modified: cchost/trunk/cchost_lib/cc-query.php
===================================================================
--- cchost/trunk/cchost_lib/cc-query.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/cchost_lib/cc-query.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -70,22 +70,9 @@
function QueryURL()
{
$this->ProcessUriArgs();
-
- list( $value, $mime ) = $this->Query(); // This method MAY exit the session...
-
- if( $value === true ) // handled elsewhere
- return; // return and show the page
-
- if( empty($value) )
- CCUtil::Send404(true); // We didn't find anything, slap back a 404
-
- if( !empty($mime) )
- header( "Content-type: $mime" );
-
- print($value);
- exit;
+ $this->ProcessUri();
}
-
+
/**
* Use this when calling from php (call ProcessAdminArgs first to clean the args)
*
@@ -232,6 +219,29 @@
return $this->args;
}
+ /**
+ * Called after ProcessUriArgs - allows for munging args
+ * in between the that method and this one
+ *
+ */
+ function ProcessUri()
+ {
+ list( $value, $mime ) = $this->Query(); // This method MAY exit the session...
+
+ if( $value === true ) // handled elsewhere
+ return; // return and show the page
+
+ if( empty($value) )
+ CCUtil::Send404(true); // We didn't find anything, slap back a 404
+
+ if( !empty($mime) )
+ header( "Content-type: $mime" );
+
+ print($value);
+ exit;
+ }
+
+
/**
* Helper function for formats during CC_EVENT_QUERY_SETUP
*
Modified: cchost/trunk/dig/.htaccess
===================================================================
--- cchost/trunk/dig/.htaccess 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/.htaccess 2010-03-02 21:27:07 UTC (rev 14211)
@@ -14,6 +14,7 @@
RewriteRule ^popular/?$ index.php?page=popular [L,QSA]
RewriteRule ^podcast_music/?$ index.php?page=dig&search-type=podcasting&title=Podsafe+Music [L,QSA]
RewriteRule ^music_for_film_and_video/?$ index.php?page=dig&search-type=videos&title=Instrumental+Music+for+Film+and+Video [L,QSA]
+RewriteRule ^music_for_games/?$ index.php?page=dig&search-type=games&title=Electro+Instrumental+Music+for+Games [L,QSA]
RewriteRule ^free_music/?$ index.php?page=dig&search-license=open&title=Music+Free+for+Commercial+Use [L,QSA]
RewriteRule ^api/query/?$ lib/query_proxy.php [L,QSA]
Modified: cchost/trunk/dig/index.php
===================================================================
--- cchost/trunk/dig/index.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/index.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -18,6 +18,11 @@
*
*/
+global $DIG_ROOT_URL;
+global $MIXTER_ROOT_DIR;
+global $QUERY_ROOT_URL;
+global $QUERY_PROXY_URL;
+
$page = empty($_REQUEST['page']) ? 'home' : $_REQUEST['page'];
require_once('pages/'.$page.'.php');
Modified: cchost/trunk/dig/js/ccm-query.js
===================================================================
--- cchost/trunk/dig/js/ccm-query.js 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/js/ccm-query.js 2010-03-02 21:27:07 UTC (rev 14211)
@@ -122,21 +122,23 @@
this._options = options;
this._parameters = fields;
this._user_func = func;
+ if( !this._options.mode )
+ this._options.mode = 'ajax';
},
// public
query: function () {
- this._clear_values();
- this.values.num_results = 0;
+ this._clear_values();
+ this.values.num_results = 0;
- this._get_params();
-
- if( this._options.paging && !this._count_fetched )
- this._call_ccm( 'count', this._on_count_return.bind(this) );
- else
- this._call_ccm( 'js', this._on_query_return.bind(this) );
+ this._get_params();
+
+ if( this._options.paging && !this._count_fetched && (this._options.mode == 'ajax') )
+ this._call_ccm( 'count', this._on_count_return.bind(this) );
+ else
+ this._call_ccm( 'js', this._on_query_return.bind(this) );
},
page: function(dir) {
@@ -175,6 +177,10 @@
_flatten_obj: function(obj,target,path)
{
+ // wtf was I thinking ??
+
+ /*
+
var pathChar = path ? '/' : '';
for( field in obj )
@@ -192,7 +198,9 @@
}
return target;
-
+ */
+
+ return obj;
},
_on_count_return: function(data)
@@ -262,23 +270,39 @@
_call_ccm: function( format, func ) {
- var url = this._rootURL + 'f=' + format + this._params;
-
- if( this._proxyURL )
+ switch( this._options.mode )
{
- url = this._proxyURL + escape(url);
+ case 'ajax':
+ {
+ var url = this._rootURL + 'f=' + format + this._params;
+
+ if( this._proxyURL )
+ {
+ url = this._proxyURL + escape(url);
+ }
+
+ if( this._options.debug )
+ dlink(url);
+
+
+ jQuery.ajax({
+ type: "POST",
+ url: url,
+ data: {},
+ dataType: 'html',
+ success: func
+ });
+
+ break;
+ }
+
+ case 'server':
+ case 'remote':
+ {
+ var url = '/' + this._options.doc + '?' + this._params;
+ document.location = url;
+ break;
+ }
}
-
- if( this._options.debug )
- dlink(url);
-
-
- jQuery.ajax({
- type: "POST",
- url: url,
- data: {},
- dataType: 'html',
- success: func
- });
}
}
Modified: cchost/trunk/dig/js/ccmd.js
===================================================================
--- cchost/trunk/dig/js/ccmd.js 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/js/ccmd.js 2010-03-02 21:27:07 UTC (rev 14211)
@@ -27,6 +27,7 @@
defaultalbumart: DIG_ROOT_URL + '/images/default-cover.jpg'
};
+
var str_remove_tag = 'remove tag';
var str_you_already = 'You already have permission…';
var str_more = 'more »';
@@ -47,7 +48,10 @@
var str_attribution = 'Attribution';
var str_back = 'Back';
var str_editors_picks = 'Editors\' Picks';
+var str_podcasts = 'Podcasts';
+var original_search_type = null;
+
/*
ADVANCED UTILITY
*/
@@ -291,15 +295,16 @@
function result_heading(result, num, max_name_length, featured) {
var html = '';
+
if(featured) {
- html += '<h4><a href="'+result['files/0/download_url']+'">'+
+ html += '<h4><a href="'+result.files[0].download_url+'">'+
safe_upload_name(result['upload_name'], max_name_length)+'</a> </h4>';
html += '<span class="result-creator">by <a href="'+result['artist_page_url']+'">'+
result['user_real_name']+'</a></span> <div class="license" id="license-'+num+
'"><a href="'+result['license_url']+'"><img src="'+license_image(result['license_name'])+
'" alt="'+result['license_name']+' Creative Commons License" /></a></div>';
} else {
- html += '<h4><a href="'+result['files/0/download_url']+'">'+
+ html += '<h4><a href="'+result.files[0].download_url+'">'+
safe_upload_name(result['upload_name'], max_name_length)+
'</a> <span class="result-creator">'+str_by+' <a href="'+result['artist_page_url']+'">'+
result['user_real_name']+'</a></span> <div class="license" id="license-'+num+'"><a href="'+
@@ -330,9 +335,10 @@
var file_count = result['num_files'];
var i = 0;
while(i < file_count) {
- html += '<li><a href="'+result['files/'+i+'/download_url']+'">'+
- result['files/'+i+'/file_name']+'</a> (<strong>'+result['files/'+i+'/file_format_info/default-ext']+
- '</strong> '+clean_filesize(result['files/'+i+'/file_filesize'])+')</li>';
+ F = result.files[i];
+ html += '<li><a href="'+F.download_url+'">'+
+ F.file_name +'</a> (<strong>'+ F.file_format_info['default-ext'] +
+ '</strong> '+clean_filesize(F.file_filesize)+')</li>';
i++;
}
html += '</ol>';
@@ -348,10 +354,10 @@
function result_info(result, num) {
var html = '<div class="item">';
-
+
html += '<div class="info-header" style="background-image: url('+result['user_avatar_url']+');">';
html += '<h5><a href="'+result['file_page_url']+'">'+result['upload_name']+
- '</a> <span class="length">'+result['files/0/file_format_info/ps']+'</span></h5>';
+ '</a> <span class="length">'+result.files[0].file_format_info.ps+'</span></h5>';
html += '<h6>by <a href="'+result['artist_page_url']+'">'+result['user_real_name']+'</a></h6>';
html += '<ul class="meta">';
if(result['upload_extra/featuring'] != '') {
@@ -665,7 +671,7 @@
function podcastQueryResults(results) {
var html ='';
- html += '<h3>Podcasts</h3>';
+ html += '<h3>'+str_podcasts+'</h3>';
html += '<p>Subscribe to all by dragging <a href="http://feeds2.feedburner.com/ccMixter_music">this link</a> to your music player</p>';
var result_count = jQuery('.result').length;
var j = (result_count == 0) ? 0 : result_count+1;
@@ -869,7 +875,8 @@
jQuery('#prevlink').click(function(e) { queryObj.page(-1);return false; });
jQuery('#nextlink').click(function(e) { queryObj.page(1);return false; });
- YAHOO.MediaPlayer.addTracks(document.getElementById('results'), null, true);
+ if( YAHOO.MediaPlayer && YAHOO.MediaPlayer.addTracks )
+ YAHOO.MediaPlayer.addTracks(document.getElementById('results'), null, true);
}
function _podcastsPageEvents() {
@@ -1006,7 +1013,8 @@
}
);
- YAHOO.MediaPlayer.addTracks(document.getElementById(target), null, false);
+ if( YAHOO.MediaPlayer && YAHOO.MediaPlayer.addTracks ) // TODO: Why is this null (sometimes)?
+ YAHOO.MediaPlayer.addTracks(document.getElementById(target), null, false);
}
function progress_indicator() {
@@ -1030,11 +1038,38 @@
var search_val = $('#search-query').val();
var search_lic = $('#search-license').val();
var search_type = $('#search-type').val();
+
+ if( original_search_type && (search_type != original_search_type) )
+ {
+ var mapping = {
+ videos: 'music_for_film_and_video',
+ games: 'music_for_games',
+ podcasting: 'podcast_music',
+ entertainment: 'dig'
+ };
+
+ if( search_type )
+ {
+ page = mapping[search_type];
+ }
+ else
+ {
+ page = 'dig';
+ }
+
+
+ url = DIG_ROOT_URL + '/' + page + '?search-query=' + search_val
+ + '&search-license=' + search_lic
+ + '&search-type=' + search_type;
+ document.location = url;
+ return false;
+ }
+
var search_reqtags = 'remix';
var search_tags = '';
var search_param_type = 'all';
- var digging_for = default_digging_for;;
+ var digging_for = default_digging_for;
switch(search_type) {
case 'videos':
@@ -1055,7 +1090,7 @@
break;
case 'entertainment':
digging_for = '<h3 id="diggingfor">You went digging for: Music for Entertainment</h3>';
- break;
+ break;
}
var parameters = get_search_param_defaults();
@@ -1066,25 +1101,8 @@
parameters.reqtags = search_reqtags;
parameters.type = search_param_type;
- return do_param_search(parameters,digging_for);
-}
-
-function get_search_param_defaults()
-{
- var p = {
- dataview: 'diginfo',
- ord: 'desc',
- sort: 'rank',
- offset: 0,
- /* tagexp: '(remix|original)', */
- limit: '10'
- };
+ // generic search starts here ....
- return p;
-}
-
-function do_param_search(parameters,digging_for)
-{
var form_id = "search-utility";
var form = $('#'+form_id);
@@ -1128,6 +1146,21 @@
return false;
}
+function get_search_param_defaults()
+{
+ var p = {
+ dataview: 'diginfo',
+ ord: 'desc',
+ sort: 'rank',
+ offset: 0,
+ /* tagexp: '(remix|original)', */
+ limit: '10'
+ };
+
+ return p;
+}
+
+
function do_advanced_search() {
var today = new Date();
var search_before = prep_date(today);
@@ -1225,7 +1258,7 @@
// populate edpicks
var options = {
- // debug: true,
+ //debug: true,
parent: '#results'
}
var parameters = {
@@ -1394,13 +1427,15 @@
if(jQuery('#dig').length > 0) {
populate_dig();
execute_url();
+ original_search_type = $('#search-type').val();
}
-
+
+/*
// if the featured page
if(jQuery('#featured').length > 0) {
populate_featured();
}
-
+
// if the picks page
if(jQuery('#pickspage').length > 0) {
populate_picks();
@@ -1415,4 +1450,6 @@
if(jQuery('#podcastspage').length > 0) {
populate_podcasts();
}
+*/
+
});
\ No newline at end of file
Modified: cchost/trunk/dig/lib/head.php
===================================================================
--- cchost/trunk/dig/lib/head.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/lib/head.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -50,6 +50,12 @@
<script src="http://mediaplayer.yahoo.com/js" type="text/javascript" charset="utf-8"></script>
<script src="js/ccm-query.js" type="text/javascript" charset="utf-8"></script>
<script src="js/ccmd.js" type="text/javascript" charset="utf-8"></script>
+<?
+if( !empty($script_for_head) )
+{
+ print $script_for_head;
+}
+?>
</head>
<body>
<div class="container">
Modified: cchost/trunk/dig/lib/query_proxy.php
===================================================================
--- cchost/trunk/dig/lib/query_proxy.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/lib/query_proxy.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -18,6 +18,7 @@
*
*/
+
require_once('../config.php');
define('CC_HOST_CMD_LINE', 1 ); // define this exact way
@@ -28,6 +29,15 @@
require_once( 'cchost_lib/cc-query.php');
$query = new CCQuery();
-$query->QueryURL();
+$args = $query->ProcessUriArgs();
+
+if( $args['format'] != 'page' )
+{
+ $query->ProcessUri(); // this will exit
+}
+
+chdir( dirname(__FILE__) . '/..' ); // chdir back to dig
+
+
?>
\ No newline at end of file
Modified: cchost/trunk/dig/pages/dig.php
===================================================================
--- cchost/trunk/dig/pages/dig.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/pages/dig.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -61,7 +61,6 @@
$js =<<<EOF
var parameters = {};
{$params}
- //do_param_search(parameters,default_digging_for);
update_fields(parameters);
{$fields}
do_search();
Modified: cchost/trunk/dig/pages/featured.php
===================================================================
--- cchost/trunk/dig/pages/featured.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/pages/featured.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -17,16 +17,89 @@
* $Id$
*
*/
- $page_title = 'dig.ccmixter Featured Music';
- $featured_class = 'class="current"';
-
- require_once('lib/head.php');
+
+require_once('lib/query.php');
+
+$sections = array(
+ array( // ed picks
+
+ 'query_args' => array(
+ 'dataview' => 'diginfo',
+ 'tags' => 'editorial_pick',
+ 'limit' => 6
+ ),
+
+ 'query_opts' => array (
+ 'doc' => 'featured',
+ 'func' => 'edpickQueryResults',
+ 'mode' => 'server' // temp flag during tansition from ajax to server
+ ),
+ ),
+
+ array( // popular
+
+ 'query_args' => array(
+ 'dataview' => 'diginfo',
+ 'tags' => 'remix',
+ 'sort' => 'rank',
+ 'sinced' => '2 weeks ago',
+ 'limit' => 6
+ ),
+
+ 'query_opts' => array (
+ 'doc' => 'featured',
+ 'func' => 'popchartQueryResults',
+ 'mode' => 'server' // temp flag during tansition from ajax to server
+ ),
+ ),
+
+
+ array( // podcasts
+
+ 'query_args' => array(
+ 'dataview' => 'topics_podinfo',
+ 'type' => 'podcast',
+ 'limit' => 10,
+ 'offset' => 1
+ ),
+
+ 'query_opts' => array (
+ 'doc' => 'featured',
+ 'func' => 'podcastQueryResults',
+ 'mode' => 'server' // temp flag during tansition from ajax to server
+ ),
+ )
+);
+
+
+$script_for_head = "<script type=\"text/javascript\">\n" .
+ " jQuery(document).ready(function() {\n";
+
+foreach( $sections as $S )
+{
+ perform_query($S);
+ $json = CCZend_json_Encoder::encode($S['query_opts']);
+ $script_for_head .=<<<EOF
+ queryObj = new ccmQuery({$json},{},null);
+ {$S['query_opts']['func']}({$S['json']});
+
+EOF;
+}
+
+$script_for_head .= " });\n" .
+ " </script>\n";
+
+
+$page_title = 'dig.ccmixter Featured Music';
+$featured_class = 'class="current"';
+
+require_once('lib/head.php');
?>
<div id="content">
<div class="page full">
<h2>Featured</h2>
<div id="featured">
- <!-- <div id="debug"></div> -->
+ <!-- div id="debug"></div -->
<div id="results">
<div class="block wider first" id="edpicks"></div>
<div class="block wider" id="popchart"></div>
@@ -34,6 +107,16 @@
<div id="podcasts"></div>
</div>
</div>
+ <div id="no_script_results">
+ <noscript>
+<?
+ foreach( $sections as $S ) {
+ no_script_results($S);
+ print "<a href=\"{$DIG_ROOT_URL}/{$S['query_opts']['doc']}\">more</a><br />\n";
+ }
+?>
+ </noscript>
+ </div>
</div>
<? require_once('lib/footer.php'); ?>
</div>
Modified: cchost/trunk/dig/pages/picks.php
===================================================================
--- cchost/trunk/dig/pages/picks.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/pages/picks.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -17,21 +17,20 @@
* $Id$
*
*/
- $page_title = 'dig.ccmixter Editor\'s Picks';
- $featured_class = 'class="current"';
-
- require_once('lib/head.php');
-?>
- <div id="content">
- <div class="page full" id="pickspage">
- <h2>Editors' Picks</h2>
- <div id="results">
- </div>
- <div class="clearer"></div>
- </div>
- <? require_once('lib/footer.php'); ?>
- </div>
- </div>
-</body>
-</html>
\ No newline at end of file
+$query_args = array(
+ 'dataview' => 'diginfo',
+ 'tags' => 'editorial_pick',
+ 'limit' => 10,
+);
+
+$doc_page = 'picks';
+$page_title = 'dig.ccmixter Editor\'s Picks';
+$featured_class = 'class="current"';
+$page_div_id = 'pickspage';
+$h2_title = "Editors' Picks";
+$results_func = 'query_results';
+
+require_once('pages/_canned_query.inc');
+
+?>
\ No newline at end of file
Modified: cchost/trunk/dig/pages/podcasts.php
===================================================================
--- cchost/trunk/dig/pages/podcasts.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/pages/podcasts.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -17,20 +17,22 @@
* $Id$
*
*/
- $page_title = 'dig.ccmixter Podcasts';
- $featured_class = 'class="current"';
-
- require_once('lib/head.php');
-?>
- <div id="content">
- <div class="page full" id="podcastspage">
- <h2>Podcasts</h2>
- <div id="results">
- </div>
- <div class="clearer"></div>
- </div>
- <? require_once('lib/footer.php'); ?>
- </div>
-</body>
-</html>
\ No newline at end of file
+$query_args = array(
+ 'dataview' => 'topics_podinfo',
+ 'datasource' => 'topics',
+ 'type' => 'podcast',
+ 'offset' => 1,
+ 'limit' => 10,
+);
+
+$doc_page = 'podcasts';
+$page_title = 'dig.ccmixter Podcasts';
+$featured_class = 'class="current"';
+$page_div_id = 'podcastspage';
+$h2_title = 'Podcasts';
+$results_func = 'podcastPageQueryResults';
+
+require_once('pages/_canned_query.inc');
+
+?>
\ No newline at end of file
Modified: cchost/trunk/dig/pages/popular.php
===================================================================
--- cchost/trunk/dig/pages/popular.php 2010-03-02 21:26:20 UTC (rev 14210)
+++ cchost/trunk/dig/pages/popular.php 2010-03-02 21:27:07 UTC (rev 14211)
@@ -17,20 +17,22 @@
* $Id$
*
*/
- $page_title = 'dig.ccmixter Popular';
- $featured_class = 'class="current"';
-
- require_once('lib/head.php');
-?>
- <div id="content">
- <div class="page full" id="popularpage">
- <h2>Popular</h2>
- <div id="results">
- </div>
- <div class="clearer"></div>
- </div>
- <? require_once('lib/footer.php'); ?>
- </div>
- </div>
-</body>
-</html>
\ No newline at end of file
+
+$query_args = array(
+ 'dataview' => 'diginfo',
+ 'tags' => 'remix',
+ 'sinced' => '2 weeks ago',
+ 'sort' => 'rank',
+ 'limit' => 10,
+);
+
+$doc_page = 'popular';
+$page_title = 'dig.ccmixter Popular';
+$featured_class = 'class="current"';
+$page_div_id = 'popularpage';
+$h2_title = 'Popular';
+$results_func = 'query_results';
+
+require_once('pages/_canned_query.inc');
+
+?>
\ No newline at end of file
More information about the cc-commits
mailing list