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

Contents of /contributions/modules/slideshowpro/slideshowpro.module

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


Revision 1.3 - (show annotations) (download) (as text)
Thu Feb 26 19:40:00 2009 UTC (9 months ago) by alexb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +101 -278 lines
File MIME type: text/x-php
#300810 danielb: upgrade to Drupal 6.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Slideshow Pro integration.
7 *
8 * This module integrates the SlideShowPro slideshow
9 * http://slideshowpro.net/ with image module and views.
10 */
11
12 /**
13 * Implementation of hook_help().
14 */
15 function slideshowpro_help($path, $arg) {
16 switch ($path) {
17 case 'admin/build/modules#description':
18 case 'admin/modules#description':
19 return t('Export SlideShowPro XML documents.');
20 }
21 }
22
23 /**
24 * Implementation of hook_menu().
25 */
26 function slideshowpro_menu() {
27 $items['admin/settings/ssp'] = array(
28 'title' => 'Slideshow Pro integration',
29 'description' => 'Control Slideshow Pro integration behaviour.',
30 'page callback' => 'drupal_get_form',
31 'page arguments' => array('slideshowpro_settings'),
32 'access arguments' => array('administer site configuration'),
33 'type' => MENU_NORMAL_ITEM, // optional
34 );
35 return $items;
36 }
37
38 /**
39 * Implementation of hook_theme.
40 */
41 function slideshowpro_theme($existing, $type, $theme, $path) {
42 return array(
43 'slideshowpro_feed' => array(
44 'file' => 'slideshowpro.theme.inc',
45 'arguments' => array(
46 'view' => NULL,
47 'nodes' => NULL,
48 'type' => NULL,
49 ),
50 ),
51 'slideshowpro_xml_image' => array(
52 'file' => 'slideshowpro.theme.inc',
53 'arguments' => array(
54 'node' => NULL,
55 'size' => NULL,
56 'title_caption' => NULL,
57 ),
58 ),
59 'slideshowpro_embed' => array(
60 'file' => 'slideshowpro.theme.inc',
61 'arguments' => array(
62 'output' => NULL,
63 'id' => NULL,
64 ),
65 ),
66 );
67 }
68
69 /**
70 * Implementation of hook_filter().
71 */
72 function slideshowpro_filter($op, $delta = 0, $format = -1, $text = '') {
73 switch ($op) {
74 case 'list':
75 return array(0 => t('Inline SSP slide shows'));
76
77 case 'description':
78 return t('Add SSP slide shows to your posts.');
79
80 case 'process':
81 foreach (slideshowpro_get_macros($text) as $unexpanded_macro => $macro) {
82 $expanded_macro = slideshowpro_embed($macro);
83 $text = str_replace($unexpanded_macro, $expanded_macro, $text);
84 }
85 return $text;
86 default:
87 return $text;
88 }
89 }
90
91 /**
92 * Implementation of hook_filter_tips().
93 */
94 function slideshowpro_filter_tips($delta, $format, $long = FALSE) {
95 return t('SSP slideshows can be added to this post. Example: [ssp|path=path/to/your/ssp/feed|width=300|height=200].');
96 }
97
98 /**
99 * Implementation of hook_views_api().
100 * @return Array with Views API version.
101 */
102 function slideshowpro_views_api() {
103 return array('api' => 2.0);
104 }
105
106 /**
107 * Form function for SlideShowPro admin settings.
108 */
109 function slideshowpro_settings(&$form_state) {
110 $form = array();
111 $form['#validate'] = array('slideshowpro_settings_validate' => array());
112 $form['slideshowpro_swf'] = array(
113 '#type' => 'textfield',
114 '#title' => t('Path to SSP file'),
115 '#default_value' => slideshowpro_path_to_ssp(),
116 '#description' => t('Path to your Slideshow Pro Flash application (.swf file) relative to your Drupal directory.
117 You can get Slide Show Pro here: http://www.slideshowpro.net.
118 See README.txt on how to create this application.'),
119 );
120
121 return system_settings_form($form);
122 }
123
124 /**
125 * Returns image path with trailing.
126 */
127 function slideshowpro_get_image_path() {
128 static $image_path;
129 if (!$image_path) {
130 $schema = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
131 $image_path = $schema .'://'. $_SERVER['HTTP_HOST'] . base_path() . file_directory_path() .'/'. variable_get('image_default_path', 'images') .'/';
132 }
133 return $image_path;
134 }
135
136 /**
137 * Format an album.
138 */
139 function slideshowpro_xml_album($album, $images) {
140 static $id = 0;
141 $output .= '<album id="%album_id" title="%title" description="%description" lgPath="">'."\n";
142 $output .= implode("\n", $images) ."\n";
143 $output .= "</album>\n";
144 $variables = array('%album_id' => $id, '%title' => check_plain($album->name), '%description' => check_plain($album->description),
145 '%lgPath' => url(variable_get('image_default_path', 'images'), array('absolute' => TRUE)));
146 $id++;
147 return strtr($output, $variables);
148 }
149
150 /**
151 * Returns path to slideshow pro.
152 */
153 function slideshowpro_path_to_ssp() {
154 return variable_get('slideshowpro_swf', drupal_get_path('module', 'slideshowpro') .'/ssp.swf');
155 }
156
157 /**
158 * Return all slideshowpro macros as an array.
159 */
160 function slideshowpro_get_macros($text) {
161 $m = array();
162 preg_match_all('/ \[ ( [^\[\]]+ )* \] /x', $text, $matches);
163 $tag_match = (array) array_unique($matches[1]); // Don't process duplicates.
164
165 foreach ($tag_match as $macro) {
166 $current_macro = '['. $macro .']';
167 $param = array_map('trim', explode('|', $macro));
168 $func_name = array_shift($param); // The first macro param is assumed to be the function name.
169 if ($func_name == 'ssp') {
170 $vars = array();
171 foreach ($param as $p) {
172 $pos = strpos($p, '=');
173 $varname = substr($p, 0, $pos);
174 $varvalue = substr($p, $pos + 1);
175 $vars[$varname] = $varvalue;
176 }
177 // The full unaltered filter string is the key for the array of filter attributes.
178 $m[$current_macro] = $vars;
179 }
180 }
181
182 return $m;
183 }
184
185 /**
186 * Embed function.
187 */
188 function slideshowpro_embed($args) {
189 static $id = 0;
190 $id++;
191 // Path to xml.
192 $flash_vars = 'xmlfilepath='. url($args['path'], array('absolute' => TRUE));
193 // Check, whether parameters available.
194 $flash_vars .= '&parameters=';
195 if (isset($args['params'])) {
196 $params = explode(',', $args['params']);
197 foreach ($params as $param) {
198 if ($var = explode(':', $param)) {
199 // If we use titles as captions, ignore showCaptionHeader.
200 $flash_vars .= $var[0] .':'. check_plain($var[1]) .',';
201 }
202 }
203 }
204 // Hide caption header if we are using titles as captions.
205 if (variable_get('slideshowpro_title_as_caption', 0)) {
206 $flash_vars .= 'showCaptionHeader:False,';
207 }
208 // Width and height.
209 if (isset($args['width'])) {
210 $width = ' width="'. $args['width'] .'" ';
211 }
212 if (isset($args['height'])) {
213 $height = ' height="'. $args['height'] .'" ';
214 }
215
216 return theme('slideshowpro_embed',
217 '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
218 codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" '. $width .' '. $height .' id="ssp-player-'. $id .'" align="middle">
219 <param name="allowScriptAccess" value="sameDomain" />
220 <param name="FlashVars" value="'. $flash_vars .'" />
221 <param name="movie" value="'. base_path() . slideshowpro_path_to_ssp() .'" />
222 <param name="quality" value="high" />
223 <param name="bgcolor" value="#ffffff" />
224 <embed FlashVars="'. $flash_vars .'" src="'. base_path() . slideshowpro_path_to_ssp() .'" quality="high" bgcolor="#ffffff" '. $width .' '. $height .' name="ssp-player-'. $id .'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
225 </object>', $id);
226 }

  ViewVC Help
Powered by ViewVC 1.1.2