/[drupal]/contributions/modules/brilliant_gallery/views.inc
ViewVC logotype

Contents of /contributions/modules/brilliant_gallery/views.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Dec 9 12:53:10 2007 UTC (23 months, 2 weeks ago) by tjfulopp
Branch: MAIN
CVS Tags: DRUPAL-5--2-15, DRUPAL-5--3-2, DRUPAL-5--3-1, DRUPAL-5--3-0, DRUPAL-5--4-0, DRUPAL-5--4-1, DRUPAL-5--4-2, DRUPAL-5--2-16, DRUPAL-5--2-17, DRUPAL-6--1-0, DRUPAL-6--1-1, DRUPAL-6--1-2, DRUPAL-5--3-3, HEAD
Branch point for: DRUPAL-5--3, DRUPAL-6--1, DRUPAL-5--4
Changes since 1.1: +2 -2 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 // $Id: views.inc,v 1.1 2007/12/04 08:25:10 tjfulopp Exp $
3
4 /**
5 * Implementation of hook_views_tables()
6 */
7 function brilliant_gallery_views_tables() {
8 $tables['brilliant_gallery'] = array(
9 'name' => 'brilliant_gallery',
10 /*
11 'join' => array(
12 'left' => array(
13 'table' => 'node',
14 'field' => 'nid',
15 ),
16 'right' => array(
17 'field' => 'nid',
18 ),
19 ),
20 */
21 'fields' => array(
22 'node' => array(
23 'name' => t('Brilliant Gallery: A random image'),
24 'handler' => array(
25 'brilliant_gallery_views_handler_image_img' => t('Random image'),
26 #'brilliant_gallery_views_handler_image_img_link' => t('bgImage with link'),
27 ),
28 /*
29 'option' => array(
30 '#type' => 'select',
31 '#options' => 'brilliant_gallery_views_handler_filter_image_size',
32 ),
33 */
34 'notafield' => true,
35 'sortable' => false,
36 'help' => t('Display one random image from the respective gallery.'),
37 ),
38 ),
39 );
40 return $tables;
41 }
42
43 /**
44 * Views handler for displaying the image.
45 */
46 function brilliant_gallery_views_handler_image_img($fieldinfo, $fielddata, $value, $data) {
47 /*
48 $node = node_load($data->nid);
49 return image_display($node, $fielddata['options']);
50 */
51 /*
52 $tmp = '.1. ' . implode( ' // ', $fieldinfo );
53 $tmp .= '<br>.2. ' . implode( ' // ', $fielddata );
54 $tmp .= '<br>.3. ' . implode( ' // ', $value );
55 $tmp .= '<br>.4. ' . implode( ' // ', $data );
56 $tmp .= '<br>.5. ' . $data->field_gallery_value;
57 #field_gallery_value
58 */
59 $tmp = $data->nid;
60 $query = "SELECT SQL_CACHE `field_gallery_value` FROM `content_type_page` WHERE `nid` = '". $tmp ."' ORDER BY `vid` DESC LIMIT 1";
61 $string = db_result( db_query( $query ), 0 );
62 $string = str_replace( array( '[bg|', ']' ), '', $string );
63 if ( strpos( $string, '|' ) !== false ) {
64 $string = substr( $string, 0, (strpos( $string, '|' )) );
65 }
66 if ( $string == '' ) return;
67 # Now get a list of images and choose one of them.
68 $absolpath = realpath(file_directory_path() . '/' . variable_get('brilliant_gallery_folder', '') . '/' . $string);
69 #$string .= file_directory_path() . '/' . $string;
70 # Load Directory Into Array
71 $poct = -1;
72 $retval = array();
73 $handle = opendir($absolpath);
74 while ( $file = readdir($handle) ) {
75 $poct += 1;
76 $testending = strtolower( substr( $file, -4, 4 ) );
77 if ( strtolower( $testending ) <> '.jpg' and strtolower( $testending ) <> 'jpeg' and strtolower( $testending ) <> '.gif' and strtolower( $testending ) <> '.png' ) { continue; }
78 $retval[$poct] = $file;
79 }
80 closedir( $handle );
81 #print_r( $retval );
82 $randimg = mt_rand( 0, count( $retval ) );
83 $result = $absolpath . '/' . $retval[$randimg];
84 $temp = getimagesize( $result );
85 #$imagewidth = variable_get('brilliant_gallery_maximagewidth', 150);
86 $imgh = 100; # Hard-coded height for this purpose.
87 $imgw = round( ($temp[0]/$temp[1])*$imgh );
88 # Get this module's path:
89 # Patching a possible problem with i18n
90 $langcode = '';
91 if ( function_exists('i18n_get_lang') ) { $langcode = i18n_get_lang(); }
92 $modulepath = url(drupal_get_path('module', 'brilliant_gallery'), NULL, NULL, TRUE);
93 # url() ads i18n codes to the URL ... we need to remove them here...
94 if ( $langcode <> '' ) {
95 $modulepath = str_replace( '/' . $langcode . '/', '/', $modulepath );
96 }
97 # Non-clean URLs need removing ?q=
98 $modulepath = str_replace( "?q=", "", $modulepath );
99 $result = '<a href="' . $modulepath .'/image.php?imgp=' . base64_encode( $absolpath . '/' . $retval[$randimg] ) . '&imgw=' . $imgw*6 . '&imgh=' . $imgh*6 . '"';
100 $setname = mt_rand( 1, 9999999 );
101 $overbrowser = variable_get('brilliant_gallery_overbrowser', 'thickbox');
102 switch( $overbrowser ) {
103 case 'thickbox':
104 $result .= ' class="thickbox"';
105 $result .= ' rel="img_' . $setname . '"';
106 #$attributes['class'] = $link_class;
107 #$attributes['rel'] = 'img_' . ($node->nid? $node->nid: time()); // 'insert' has no $node->nid
108 break;
109 case 'lightbox':
110 $result .= ' rel="lightbox[' . $setname . ']"';
111 #$attributes['rel'] = 'lightbox[' . ($node->nid? $node->nid: time()) . ']'; // 'insert' has no $node->nid
112 break;
113 case 'greyboxr':
114 $result .= ' class="greybox"';
115 #$result .= ' rel="gb_imageset[' . $setname . ']"';
116 break;
117 default:
118 break;
119 }
120
121 if ( $showcaption <> '' ) {
122 $result .= ' title="' . $caption . '"';
123 }
124 $result .= '>';
125 $result .= '<img style="display: block;border:0;align:right" src="' . $modulepath .'/image.php?imgp=' . base64_encode( $absolpath . '/' . $retval[$randimg] ) . '&imgw=' . $imgw . '&imgh=' . $imgh . '" />'; # width="' . $imgw . '"
126 $result .= '</a>';
127 return $result;
128 }
129
130
131 /**
132 * Views - Generate a list of all the valid sizes that are available
133 */
134 /*
135 function brilliant_gallery_views_handler_filter_image_size($op) {
136 foreach (_image_get_sizes() as $key => $size) {
137 $a[$key] = $size['label'];
138 }
139 return $a;
140 }
141 */

  ViewVC Help
Powered by ViewVC 1.1.2