/[drupal]/contributions/modules/fast_gallery/fast_gallery.module
ViewVC logotype

Contents of /contributions/modules/fast_gallery/fast_gallery.module

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


Revision 1.60 - (show annotations) (download) (as text)
Mon Nov 2 20:09:02 2009 UTC (3 weeks, 5 days ago) by rapsli
Branch: MAIN
CVS Tags: DRUPAL-7--1-1-ALPHA1
Changes since 1.59: +59 -2 lines
File MIME type: text/x-php
support for multiple galleries with aliases
1 <?php
2
3 // $Id:
4
5 /**
6 * @file
7 * Fast Gallery allows you to build galleries based on your file
8 * system with folders and subfolders.
9 *
10 * This module is sponsored by Sch�r Webdesign.
11 * Visit www.schaerwebdesign.ch or the Drupal-related blog www.rapsli.ch.
12 *
13 * Original version by Raphael Sch�r - www.schaerwebdesign.ch.
14 *
15 * @author Raphael Sch�r - www.schaerwebdesign.ch
16 */
17
18 define('FG_DEFAULT_STORAGE_ENGINE','default.storage.inc');
19
20 /**
21 * Implementation of hook_menu
22 * @return array
23 */
24 function fast_gallery_menu() {
25 $items['admin/config/fast_gallery'] = array(
26 'title' => 'Fast Gallery',
27 'description' => 'Configure the fast gallery module',
28 'page callback' => 'drupal_get_form',
29 'page arguments' => array('fast_gallery_general_settings_form'),
30 'access arguments' => array('administer fast gallery'),
31 'file' => 'fast_gallery.admin.inc',
32 'file path' => drupal_get_path('module', 'fast_gallery'),
33 );
34
35 $items['fast_gallery/ajax/%op'] = array(
36 'page callback' => 'fast_gallery_ajax_handler',
37 'page arguments' => array(2),
38 'access arguments' => array('administer fast gallery'),
39 'file' => 'fast_gallery.admin.inc',
40 'file path' => drupal_get_path('module', 'fast_gallery'),
41 );
42
43 /*$items['fast_gallery'] = array(
44 'page callback' => 'fast_gallery_page',
45 'access arguments' => array('access content'),
46 'title' => 'Fast Gallery',
47 );*/
48
49 $fg_galleries = variable_get('fg_galleries', array());
50 foreach ($fg_galleries as $gallery) {
51 //print_r($gallery['fg_alias']);
52 $items[$gallery['fg_alias']] = array(
53 'page callback' => 'fast_gallery_page_alias',
54 'page arguments' => array($gallery['fg_path']),
55 'access arguments' => array('access content'),
56 'title' => $gallery['fg_title'],
57 );
58 }
59 //exit();
60 return $items;
61 }
62
63 function _fast_gallery_get_alias_count($path) {
64 $ar = explode("/", $path);
65 if ($ar[count($ar)-1] == '') {
66 array_shift($ar);
67 }
68 return count($ar);
69 }
70
71 function fast_gallery_page_alias($path) {
72 $settings = variable_get('fg_galleries');
73
74 $current_path_alias = check_plain($_GET['q']);
75
76 $start = strlen($settings[$path]['fg_alias']);
77 $path_new = substr($current_path_alias, ++$start);
78 $path_new = $settings[$path]['fg_path'] . $path_new;
79
80 //fetching the needed objects
81 $fg = fast_gallery_get_FastGallery();
82 $storage = $fg->getStorageEngine();
83
84 drupal_set_breadcrumb($fg->buildBreadCrumbs());
85 $current_path = check_plain($_GET['q']);
86
87 $images = $storage->getImages($path_new);
88
89 $html = '';
90 foreach ($images as $image) {
91 if ($image->isDir()) {//incase of a subfolder -> make a different link
92 $image_html = l($image->renderHtml(), $current_path . '/' . $image->getName(), array('html' => TRUE));
93 }
94 else {
95 $image_html = l($image->renderHtml(), $image->getPath(), array('html' => TRUE));
96
97 }
98
99 //use .tpl file to output an image
100 $html .= theme('fast_gallery_image', array('image' => $image_html));
101 }
102 return $html;
103 }
104 /**
105 * Callback function to actually display the page.
106 * @return string html
107 */
108 function fast_gallery_page() {
109 drupal_set_title(variable_get('fast_gallery_title', 'Fast Gallery'));
110
111 //fetching the needed objects
112 $fg = fast_gallery_get_FastGallery();
113 $storage = $fg->getStorageEngine();
114
115 drupal_set_breadcrumb($fg->buildBreadCrumbs());
116 $current_path = check_plain($_GET['q']);
117
118 //getting the path and modifying it
119 $path = check_plain($_GET['q']);
120 $ar_path = explode('/', $path);
121 array_shift($ar_path);
122 $path = implode("/", $ar_path);
123 $images = $storage->getImages($path);
124
125 $html = '';
126 foreach ($images as $image) {
127 if ($image->isDir()) {//incase of a subfolder -> make a different link
128 $image_html = l($image->renderHtml(), $current_path . '/' . $image->getName(), array('html' => TRUE));
129 }
130 else {
131 $image_html = l($image->renderHtml(), $image->getPath(), array('html' => TRUE));
132
133 }
134
135 //use .tpl file to output an image
136 $html .= theme('fast_gallery_image', array('image' => $image_html));
137 }
138 return $html;
139 }
140
141 /**
142 * Implementation of hook_cron() to keep gallery up-to-date.
143 */
144 function fast_gallery_cron() {
145 $fg = fast_gallery_get_FastGallery();
146 $fg->rescanGallery();
147 }
148
149 /**
150 * Implementation of hook_theme
151 * @return array
152 */
153 function fast_gallery_theme() {
154 return array(
155 'fast_gallery_image' => array(
156 'variables' => array(
157 'image' => NULL,
158 ),
159 'template' => 'fast_gallery-image',
160 ),
161 'fg_multiple_galleries' => array(
162 'render element' => 'form',
163 ),
164 );
165 }
166
167 /**
168 * Implementation of hook_init
169 */
170 function fast_gallery_init() {
171 drupal_add_css(drupal_get_path('module', 'fast_gallery') . '/fast_gallery.css');
172 }
173
174
175 /**
176 * helper function to return the controller class
177 * FastGallery
178 * @return FastGallery
179 */
180 function fast_gallery_get_FastGallery() {
181 include_once('fast_gallery.class.php');
182 return FastGallery :: getInstance();
183 }
184
185 /**
186 * helper function to return the Cache
187 * @return FastGalleryCache
188 */
189 function fast_gallery_get_cache() {
190 include_once('fast_gallery.cache.class.php');
191 return FastGalleryCache::getInstance();
192 }
193
194
195 /**
196 * Print a variable to the 'message' area of the page. Uses drupal_set_message()
197 */
198 function d($str) {
199 print '<pre>';
200 print_r($str);
201 print '</pre>';
202 }

  ViewVC Help
Powered by ViewVC 1.1.2