[cc-commits] [CC SVN] r14210 - in cchost/trunk/dig: images lib pages

webmaster at creativecommons.org webmaster at creativecommons.org
Tue Mar 2 16:26:20 EST 2010


Author: fourstones
Date: 2010-03-02 21:26:20 +0000 (Tue, 02 Mar 2010)
New Revision: 14210

Added:
   cchost/trunk/dig/images/logo-black.png
   cchost/trunk/dig/lib/query.php
   cchost/trunk/dig/pages/_canned_query.inc
Log:
first ci

Added: cchost/trunk/dig/images/logo-black.png
===================================================================
(Binary files differ)


Property changes on: cchost/trunk/dig/images/logo-black.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: cchost/trunk/dig/lib/query.php
===================================================================
--- cchost/trunk/dig/lib/query.php	                        (rev 0)
+++ cchost/trunk/dig/lib/query.php	2010-03-02 21:26:20 UTC (rev 14210)
@@ -0,0 +1,161 @@
+<?
+/*
+* Artistech Media has made the contents of this file
+* available under a CC-GNU-GPL license:
+*
+* http://creativecommons.org/licenses/GPL/2.0/
+*
+* A copy of the full license can be found as part of this
+* distribution in the file LICENSE.TXT.
+* 
+* You may use dig.ccMixter software in accordance with the
+* terms of that license. You agree that you are solely 
+* responsible for your use of dig.ccMixter software and you
+* represent and warrant to Artistech Media that your use
+* of dig.ccMixter software will comply with the CC-GNU-GPL.
+*
+* $Id$
+*
+*/
+
+require_once('config.php');
+
+if( !defined('CC_HOST_CMD_LINE') )
+    define('CC_HOST_CMD_LINE', 1 );      // define this exact way
+    
+
+// should be in some kind of common.inc:
+require_once( $MIXTER_ROOT_DIR . '/cchost_lib/zend/json-encoder.php' );
+
+/**
+ * do the actual query with ccHost
+ */
+function _query(&$qi)
+{
+    global $MIXTER_ROOT_DIR;
+    
+    chdir( $MIXTER_ROOT_DIR );           // must be run from the cchost install root dir
+    $NO_EXTRANEOUS_OUTPUT = 1;           // supress tagline of this file (OPTIONAL)
+    require_once( 'cc-cmd-line.inc' );  
+    require_once( 'cchost_lib/cc-query.php');
+
+    if( !empty($qi['query_opts']['paging'] ) )
+    {
+        $query = new CCQuery();
+        $args = $qi['query_args'];    
+        $args['format'] = 'count';
+        $args = $query->ProcessAdminArgs($args);
+        list( $count ) = $query->Query($args);
+        $qi['total'] = trim($count,'[]');
+    }
+    
+    $query = new CCQuery();
+    $args = $qi['query_args'];
+    $args['format'] = 'php';
+    $args = $query->ProcessAdminArgs($args);
+    list( $results, $mime ) = $query->Query($args);
+
+    // dbg($query);
+
+    chdir( dirname(__FILE__) . '/..' );
+
+    $qi['results'] = & $results;
+    $qi['queryObj'] = & $query;
+
+}
+
+function perform_query(&$qi)
+{
+    _query($qi);
+
+    //dbg($qi);
+
+    $args = $qi['queryObj']->args;
+    if( !empty($qi['query_opts']['paging'] ) )
+    {
+        $qi['limit']  = $args['limit'];
+        $qi['offset'] = $args['offset'];
+    }
+
+    $results = & $qi['results'];
+    
+    if( !empty($results[0]['files']) )
+    {
+        $keys = array_keys($qi['results']);
+        foreach( $keys as $K )
+        {
+            $R = & $qi['results'][$K];
+            $R['num_files'] = count($R['files']);
+        }
+    }
+    
+    $qi['json'] = CCZend_Json_Encoder::encode($results);
+    
+}
+
+function dbg(&$obj)
+{
+    $str =& _textize($obj);
+    $html = '<pre style="font-size: 10pt;text-align:left;">' .
+            htmlspecialchars($str) .
+            '</pre>';
+    print("<html><body>$html</body></html>");
+    exit;
+}
+
+function & _textize(&$var)
+{
+    ob_start();
+    if( is_array($var) || is_object($var) || is_resource($var) )
+        print_r($var);
+    else
+        var_dump($var);
+    $t = ob_get_contents();
+    ob_end_clean();
+
+    $r =& $t;
+    return($r);
+}
+
+function no_script_results( &$qi )
+{
+    global $DIG_ROOT_URL ;
+
+    print '<ul>';
+    $recs = & $qi['results'];
+    $keys = array_keys($recs);
+    foreach( $keys as $K )
+    {
+        $R =& $recs[$K];
+        if( !empty($R['file_page_url']) )
+        {
+            print "<li><a href='{$R['file_page_url']}'>" .
+                  "{$R['upload_name']}</a> by " .
+                  "<a href='{$R['artist_page_url']}'>{$R['user_real_name']}</a> {$R['upload_tags']}</li>\n";
+        }
+        elseif( !empty($R['enclosure_url']) )
+        {
+            print "<li><a href='{$R['enclosure_url']}'>{$R['topic_name']}</a> by {$R['user_real_name']}</li>\n";
+        }
+    }
+    print '</ul>';
+    if( !empty($qi['query_opts']['paging']) )
+    {
+        $base = $DIG_ROOT_URL  . $qi['query_opts']['doc'] . '?ns=1';
+        $keys = array_diff( array_keys($qi['query_opts']['calling_args']), array('offset','limit') );
+        $args = $qi['query_opts']['calling_args'];
+        foreach( $keys as $K )
+        {
+            $base .= '&' . $K . '=' . $args[$K];
+        }
+        print '<ul>';
+        $page = 1;
+        for( $i = 0; $i < $qi['total']; $i += $qi['limit'], $page++ )
+        {
+            print "<li><a href='{$base}&offset={$i}'>page: {$page}</a></li>\n";
+        }
+        print '</ul>';
+    }
+}
+
+?>
\ No newline at end of file


Property changes on: cchost/trunk/dig/lib/query.php
___________________________________________________________________
Added: svn:keywords
   + Id

Added: cchost/trunk/dig/pages/_canned_query.inc
===================================================================
--- cchost/trunk/dig/pages/_canned_query.inc	                        (rev 0)
+++ cchost/trunk/dig/pages/_canned_query.inc	2010-03-02 21:26:20 UTC (rev 14210)
@@ -0,0 +1,88 @@
+<?
+/*
+* Artistech Media has made the contents of this file
+* available under a CC-GNU-GPL license:
+*
+* http://creativecommons.org/licenses/GPL/2.0/
+*
+* A copy of the full license can be found as part of this
+* distribution in the file LICENSE.TXT.
+* 
+* You may use dig.ccMixter software in accordance with the
+* terms of that license. You agree that you are solely 
+* responsible for your use of dig.ccMixter software and you
+* represent and warrant to Artistech Media that your use
+* of dig.ccMixter software will comply with the CC-GNU-GPL.
+*
+* $Id$
+*
+*/
+
+require_once('lib/query.php');
+
+$temp = explode('?',$_SERVER['REQUEST_URI']);
+if( count($temp) > 1 )
+{
+    $uri_query_string = $temp[1];
+    parse_str($uri_query_string,$uri_query_args);
+}
+else
+{
+    $uri_query_string = '';
+    $uri_query_args = array();
+}
+
+$query_info = array(
+    
+    'query_args' => $query_args,
+
+    'query_opts' => array (
+        'paging' => true,
+        'doc'    => $doc_page,
+        'calling_args_str' => $uri_query_string,
+        'calling_args' => $uri_query_args,
+        'mode'   => 'server'   // temp flag during tansition from ajax to server
+    ),
+);
+
+$query_info['query_args'] = array_merge($query_info['query_args'],$query_info['query_opts']['calling_args']);
+perform_query($query_info);
+
+if( !empty($query_info['results']) )
+{    
+    $json_params = CCZend_Json_Encoder::encode($query_info['query_opts']['calling_args']);
+    $json_opts   = CCZend_Json_Encoder::encode($query_info['query_opts']);
+    
+    $script_for_head =<<<EOF
+        <script type="text/javascript">
+        queryObj = new ccmQuery({$json_opts},{$json_params},null);
+        queryObj.values = {
+                total: {$query_info['total']},
+                limit: {$query_info['limit']},
+                offset: {$query_info['offset']}
+            };
+        
+        jQuery(document).ready(function() {
+            {$results_func}({$query_info['json']});
+        });
+        </script>
+EOF;
+}
+
+require_once('lib/head.php');
+?>
+	<div id="content">
+		<div class="page full" id="<?= $page_div_id ?>">
+			<h2><?= $h2_title ?></h2>
+			<div id="results">
+			</div>
+			<div class="clearer"></div>
+            <noscript>
+            <? no_script_results( $query_info ); ?>
+            </noscript>
+		</div>
+        <? require_once('lib/footer.php'); ?>
+	</div>
+  </div>
+</body>
+</html>
\ No newline at end of file


Property changes on: cchost/trunk/dig/pages/_canned_query.inc
___________________________________________________________________
Added: svn:keywords
   + Id




More information about the cc-commits mailing list