/[drupal]/contributions/modules/asset/asset_wizard.module
ViewVC logotype

Contents of /contributions/modules/asset/asset_wizard.module

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


Revision 1.4 - (show annotations) (download) (as text)
Thu Mar 6 05:06:52 2008 UTC (20 months, 3 weeks ago) by rz
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1, DRUPAL-5--2
Changes since 1.3: +217 -21 lines
File MIME type: text/x-php
This commit marks the (near) completion of the initial development of the beta version of asset.
1 <?php
2 // $Id: asset_wizard.module,v 1.3 2008/01/22 02:13:18 rz Exp $
3
4 /**
5 * @file
6 * Wizard-style interface for Asset.
7 */
8
9 /**
10 * @addtogroup asset
11 * @{
12 */
13
14 /**
15 * Implementation of hook_perm().
16 */
17 function asset_wizard_perm(){
18 return array('access asset wizard');
19 }
20
21 /**
22 * Implementation of hook_menu().
23 */
24 function asset_wizard_menu($may_cache){
25 $items = array();
26 if($may_cache){
27 $items[] = array(
28 'path' => 'asset/wizard',
29 'title' => t('Asset Wizard'),
30 'type' => MENU_CALLBACK,
31 'callback' => 'asset_wizard_main',
32 'access' => user_access('access asset wizard'),
33 );
34 foreach (asset_get_types() as $type) {
35 $type_url_str = str_replace('_', '-', $type->type);
36 $items[] = array(
37 'path' => 'asset/wizard/add/'. $type_url_str,
38 'title' => drupal_ucfirst($type->name),
39 'access' => asset_access('create', $type->type),
40 'type' => MENU_CALLBACK,
41 'callback' => 'asset_wizard_add',
42 'callback arguments' => array($type),
43 );
44 }
45 }
46 else{
47 if(arg(0) == 'asset' && arg(1) == 'wizard'){
48 // $items[] = array(
49 // 'path' => 'asset/wizard/browse',
50 // 'title' => t('Asset Wizard - Browse'),
51 // 'type' => MENU_CALLBACK,
52 // 'callback' => 'asset_wizard_browse',
53 // 'callback arguments' => array(),
54 // 'access' => user_access('access asset wizard'),
55 // );
56 foreach(asset_wizard_methods() as $key => $method){
57 $items[] = array(
58 'path' => 'asset/wizard/method/'. $key,
59 'title' => t('Asset Wizard') .' - '. $method['name'],
60 'type' => MENU_CALLBACK,
61 'callback' => $method['callback'],
62 'access' => user_access('access asset wizard'),
63 );
64 }
65
66 if(is_numeric(arg(2))){
67 $aid = arg(2);
68 $asset = asset_load($aid);
69 if(!$asset || $asset->type == 'directory'){
70 $items[] = array(
71 'path' => 'asset/wizard/'. $aid,
72 'title' => t('Asset Wizard - Browse'),
73 'type' => MENU_CALLBACK,
74 'callback' => 'asset_wizard_browse',
75 'callback arguments' => array($asset),
76 'access' => user_access('access asset wizard'),
77 );
78 }
79 else{
80 $items[] = array(
81 'path' => 'asset/wizard/'. $aid,
82 'title' => t('Asset Wizard - Select Format'),
83 'type' => MENU_CALLBACK,
84 'callback' => 'asset_wizard_formats',
85 'callback arguments' => array($asset),
86 'access' => user_access('access asset wizard'),
87 );
88 $format = arg(3);
89 if($format && $asset->formatters[$format]){
90 $attr = array();
91 if($macro = arg(4)){
92 $macros = asset_get_macros($macro);
93 $attr = $macros[$macro];
94 }
95 else{
96 $attr = array('format' => $format);
97 }
98 $items[] = array(
99 'path' => 'asset/wizard/'. $aid .'/'. $format,
100 'title' => t('Asset Wizard - Options'),
101 'type' => MENU_CALLBACK,
102 'callback' => 'asset_wizard_format_options',
103 'callback arguments' => array($asset, $attr),
104 'access' => user_access('access asset wizard'),
105 );
106 }
107 if(arg(3) == 'finish'){
108 $macro = urldecode(arg(4));
109 $items[] = array(
110 'path' => 'asset/wizard/'. $aid .'/finish',
111 'title' => t('Asset Wizard - Finish'),
112 'type' => MENU_CALLBACK,
113 'callback' => 'asset_wizard_preview',
114 'callback arguments' => array($asset, $macro),
115 'access' => user_access('access asset wizard'),
116 );
117 }
118 }
119 }
120 }
121 elseif(arg(0) == 'assetfield' && is_numeric(arg(1))){
122 $asset = asset_load(arg(1));
123 $items[] = array(
124 'path' => 'assetfield/'. $asset->aid,
125 'type' => MENU_CALLBACK,
126 'callback' => 'assetfield_js_callback',
127 'callback arguments' => array($asset),
128 'access' => user_access('access asset wizard'),
129 );
130 }
131 }
132 return $items;
133 }
134
135 /**
136 * Implementation of hook_elements
137 * This is where we add the link to textareas
138 */
139 function asset_wizard_elements() {
140 $type['textarea'] = array ('#process' => array ('asset_wizard_textarea' => array()));
141 $type['textfield'] = array (
142 '#process' => array ('asset_wizard_textfield' => array()),
143 '#asset_return_type' => FALSE,
144 '#asset_config' => 'id',
145 );
146
147 $type['assetfield'] = array(
148 '#input' => TRUE,
149 '#size' => 10,
150 );
151
152 return $type;
153 }
154
155 /**
156 * Format an assetfield.
157 *
158 * @param $element
159 * An associative array containing the properties of the element.
160 * Properties used: title, value, description, size, maxlength, required, attributes autocomplete_path
161 * @return
162 * A themed HTML string representing the assetfield.
163 */
164 function theme_assetfield($element) {
165 $class = array('form-asset');
166 $output = '';
167
168 _form_set_class($element, $class);
169
170 if($element['#value']){
171 $asset = asset_load($element['#value']);
172 $preview = '<span class="icon">' . asset_icon($asset, 64) . '</span>';
173 $title = $asset->title;
174 }
175 else{
176 $preview = '<span class="icon">'. theme('image', drupal_get_path('module', 'asset_Wizard') .'/icons/missing.png', NULL, NULL, array('width' => 64), FALSE). '</span>';
177 $title = '';
178 }
179
180 $output .= '<div class="assetfield-icon">'. theme('asset_wizard_textarea_link', $element, $preview) .'</div>';
181 $output .= '<div class="assetfield-detail">';
182 $output .= '<div class="assetfield-title">'. $title .'</div>';
183 $output .= '<input type="text" maxlength="10" size="10" name="'. $element['#name'] .'" id="'. $element['#id'] .'" value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';
184 $output .= '</div>';
185
186 $output = '<div class="assetfield-container clear-block">'. $output .'</div>';
187
188 return theme('form_element', $element, $output);
189 }
190
191 function assetfield_js_callback($asset){
192 $data = array(
193 'title' => $asset->title,
194 );
195
196 $icon = asset_type_invoke($asset, 'icon');
197 if(!$icon){
198 $icon = drupal_get_path('module', 'asset') . '/icons/file.png';
199 }
200
201 $data['icon'] = base_path() . $icon;
202
203 print drupal_to_js($data);
204 exit();
205 }
206
207
208 /**
209 * The #process callback function for the textareas
210 */
211 function asset_wizard_textarea($element) {
212 if(_asset_wizard_element_match($element) && _asset_wizard_page_match()){
213 $output = theme('asset_wizard_textarea_link', $element);
214 $element['#suffix'] .= $output;
215 }
216 return $element;
217 }
218
219 /**
220 * The #process callback function for the textfield
221 */
222 function asset_wizard_textfield2($element) {
223 $config = asset_wizard_get_config($element['#asset_config']);
224 if($config['return type'] == 'macro'){
225 return asset_wizard_textarea($element);
226 }
227 elseif($config['return type'] == 'id'){
228 // $output = theme('asset_wizard_textarea_link', $element);
229 // $element['#field_suffix'] .= $output;
230
231 $preview = theme('asset_wizard_textfield_preview', $element);
232 $element['#field_prefix'] .= '<div class="clear-block"><div class="asset-textfield-preview">'. $preview .'</div>';
233 $element['#field_suffix'] .= '</div>';
234 }
235 return $element;
236 }
237
238 function theme_asset_wizard_textfield_preview($element){
239 if($element['#value']){
240 $asset = asset_load($element['#value']);
241 $text = theme('asset_icon', $asset);
242 $text = '<span class="icon">' . asset_icon($asset, 100) . '</span><br/>'
243 . '<span class="caption">'. ($asset->link_title ? $asset->link_title : $asset->title) .'</span>';
244 }
245 else{
246 $path = drupal_get_path('module', 'asset_wizard') .'/icons/select.png';
247 $alt = t('Click to start');
248 $icon = theme('image', $path, $alt, $alt);
249
250 $text = '<div class="icon-empty">'. $icon .'</div>'
251 . '<div class="caption">'. t('Click to start') .'</div>';
252 }
253
254 return theme('asset_wizard_textarea_link', $element, $text);
255 }
256
257 /**
258 * Theme the textarea link
259 */
260 function theme_asset_wizard_textarea_link($element, $text = NULL) {
261 $path = drupal_get_path('module', 'asset_wizard');
262 // add thickbox stuff
263 drupal_add_js($path .'/js/thickbox/jquery.thickbox.js');
264 drupal_add_css($path .'/js/thickbox/thickbox.css');
265
266 // provide an accurate loadingAnimation path
267 drupal_add_js('tb_pathToImage = "'.base_path() . $path .'/js/thickbox/loadingAnimation.gif";','inline','footer');
268
269 // jquery form plugin
270 drupal_add_js($path .'/js/form/jquery.form.js');
271
272 // asset wizard stuff
273 drupal_add_css($path .'/asset_wizard.css');
274 drupal_add_js($path .'/js/asset_wizard.js');
275
276 asset_wizard_js_settings();
277
278 if($element['#asset_return_type']){
279 $params = 'return='.$element['#asset_return_type'];
280 $params .= '&config='. ($element['#asset_config'] ? $element['#asset_config'] : 'macro');
281 }
282
283 $text = $text ? $text : t('Asset Wizard');
284 $link = tbl($text, 'asset/wizard', array('id'=>'asset-wizard-'. $element['#id'], 'class'=>'asset-wizard-start', 'title'=>'Asset Wizard'), $params, NULL, FALSE, TRUE);
285
286 return $link;
287 }
288
289 /**
290 * always ignore certain textareas based on element attributes (mainly #id)
291 */
292 function _asset_wizard_element_match($element){
293 $ignore = array(
294 'edit-log',
295 );
296 if(in_array($element['#id'], $ignore)){
297 return false;
298 }
299 return true;
300 }
301
302 /**
303 * Should we show the insert asset link, determined by admin setting
304 * Borrowed from tinymce.module
305 *
306 * @return
307 * TRUE if can render, FALSE if not allowed.
308 */
309 function _asset_wizard_page_match() {
310 $page_match = FALSE;
311 $access_option = variable_get('asset_wizard_access_option',1);
312 $access_pages = variable_get('asset_wizard_access_pages',"node/add/*\nnode/*/edit");
313
314 if ($access_pages) {
315 // If the PHP option wasn't selected
316 if ($access_option < 2) {
317 $path = drupal_get_path_alias($_GET['q']);
318 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($access_pages, '/')) .')$/';
319 $page_match = !($access_option xor preg_match($regexp, $path));
320 }
321 else {
322 $page_match = drupal_eval($access_pages);
323 }
324 }
325 // No pages were specified to block so show on all
326 else {
327 $page_match = TRUE;
328 }
329
330 return $page_match;
331 }
332
333 function asset_wizard_methods(){
334 static $methods;
335
336 if(!isset($methods)){
337 $methods['browse'] = array(
338 'name' => t('Browse'),
339 'callback' => 'asset_wizard_browse',
340 'description' => t('Choose from a list of existing assets.'),
341 );
342 $methods = $methods + module_invoke_all('asset_wizard', 'info');
343 }
344
345 return $methods;
346 }
347
348 /**
349 * Load the current asset wizard config array, passed in throught $_GET['config']
350 * Options for config are 'macro' (default), 'id', or the name of a cck field
351 */
352 function asset_wizard_get_config($cfg_name = NULL){
353 static $configs = array();
354
355 $cfg_name = $cfg_name ? $cfg_name : ($_GET['config'] ? $_GET['config'] : 'default');
356
357 $config = array();
358
359 if(!isset($config[$cfg_name])){
360 // build an array of asset cck fields
361 $asset_fields = array();
362 if(module_exists('content')){
363 $fields = content_fields();
364 foreach($fields as $name => $field){
365 if($field['type'] == 'asset'){
366 $asset_fields[$name] = $field;
367 }
368 }
369 }
370
371 // asset field config
372 if($asset_fields[$cfg_name]){
373 $config = $asset_fields[$cfg_name];
374 $config['return type'] = 'id';
375 }
376 // id type config
377 elseif($cfg_name == 'id'){
378 $config = array(
379 'return type' => 'id',
380 );
381 }
382 // everything else, including 'default', gets the default config
383 else{
384 $config = array(
385 'return type' => 'macro',
386 );
387 }
388
389 $configs[$cfg_name] = $config;
390 }
391
392 return $configs[$cfg_name];
393 }
394
395 function asset_wizard_main(){
396 $config = asset_wizard_get_config();
397
398 $items = array();
399 foreach(asset_wizard_methods() as $key => $method){
400 $items[] = tbl($method['name'], 'asset/wizard/method/'. $key) .'<br/>'. $method['description'];
401 }
402 $create = array();
403 foreach (asset_get_types() as $type) {
404 if(!$config['allowed_types'] ||
405 ($config['allowed_types'][$type->type] && asset_access('create', $type->type))){
406 $type_url_str = str_replace('_', '-', $type->type);
407 $text = t('New !type', array('!type' => drupal_ucfirst($type->name)));
408 $create[] = tbl($text, 'asset/wizard/add/'. $type_url_str, array(), NULL, NULL, FALSE, TRUE)
409 . '<br />'. $type->description;
410 }
411 }
412 $items[] = array('data' => '<h3>'. t('Create...') .'</h3>', 'children' => $create);
413
414 $content = theme('asset_wizard_main', $items);
415 return theme('asset_wizard_page', $content);
416 }
417
418 /**
419 * Step 1: Display a browsable list of assets
420 */
421 function asset_wizard_browse($asset = NULL){
422 $config = asset_wizard_get_config();
423
424 if(!$asset){
425 $asset = asset_load(0);
426 }
427 $items = array();
428 if($asset->aid){
429 $parent = asset_load($asset->pid);
430 $parent->link_title = '..';
431 $items[] = $parent;
432 }
433 $types = array();
434 $query = 'SELECT aid FROM {asset} WHERE pid=%d';
435 $args[] = $asset->aid;
436
437 if($config['allowed_types']){
438 foreach($config['allowed_types'] as $type){
439 if($type){
440 $types[] = $type;
441 }
442 }
443 if($types){
444 $query .= ' AND type IN ("%s")';
445 $args[] = implode('","', $types);
446 }
447 }
448 $result = db_query($query, $args);
449 while($row = db_fetch_object($result)){
450 //$items[$row->aid] = $row->title;
451 $items[] = asset_load($row->aid);
452 }
453 $content = theme('asset_wizard_browse', $items);
454 return theme('asset_wizard_page', $content);
455 }
456
457 /**
458 * Step 2: Display a list of available formats for a given asset
459 */
460 function asset_wizard_formats($asset){
461 // at this point we need to check if we should continue ($_GET['return']=='macro')
462 // or simply return the id
463 if($_GET['return'] == 'id'){
464 return drupal_goto('asset/wizard/'. $asset->aid .'/finish/'. $asset->aid);
465 }
466 $content = theme('asset_wizard_formats', $asset, $asset->formatters);
467 return theme('asset_wizard_page', $content);
468 }
469
470 /**
471 * Step 3: Display the options form
472 */
473 function asset_wizard_format_options($asset, $attr){
474 $content = '<h3>'. $$attr['format'] .'</h3>';
475 $content .= drupal_get_form('asset_wizard_format_options_form', $asset, $attr);
476 return theme('asset_wizard_page', $content);
477 }
478
479 /**
480 * Form Builder for Step 3
481 */
482 function asset_wizard_format_options_form($asset, $attr){
483 $format = $asset->formatters[$attr['format']];
484 $options = module_invoke($format->module, 'asset_formatter', 'form', $asset, $attr);
485 if(!$options){
486 $macro = asset_build_macro(array('aid' => $asset->aid, 'format' => $format->format));
487 drupal_goto('asset/wizard/'. $asset->aid .'/finish/'. $macro);
488 }
489
490 $form = array();
491 $form['options'] = $options;
492 $form['options']['#tree'] = TRUE;
493 $form['options']['aid'] = array('#type' => 'value', '#value' => $asset->aid);
494 $form['options']['format'] = array('#type' => 'value', '#value' => $format->format);
495
496 $form['buttons'] = array('#tree' => FALSE, '#theme' => 'asset_wizard_form_buttons');
497 $form['buttons'][] = array('#type' => 'submit', '#value' => t('Preview'));
498
499 $form['#type'] = 'form';
500 if($_GET['return']){
501 $form['#action'] = url($_GET['q'], 'return='. $_GET['return']);
502 }
503
504 return $form;
505 }
506
507 /**
508 * Sumbit handler for Step 3
509 */
510 function asset_wizard_format_options_form_submit($form_id, $form_values){
511 $aid = $form_values['options']['aid'];
512 $macro = asset_build_macro($form_values['options']);
513 return 'asset/wizard/'. $aid .'/finish/'. urlencode($macro);
514 }
515
516 /**
517 * Step 4: Display a preview of the formatted asset
518 */
519 function asset_wizard_preview($asset, $macro){
520 if(is_numeric($macro)){
521 $preview = asset_view($asset);
522 }
523 else{
524 $macros = asset_get_macros($macro);
525 $format = $macros[$macro];
526 $preview = asset_render_macro($format);
527 }
528 $content = theme('asset_wizard_preview', $asset, $preview, $macro);
529 return theme('asset_wizard_page', $content);
530 }
531
532 function asset_wizard_add($type){
533 $output = asset_add($type->type);
534 return theme('asset_wizard_page', $output);
535 }
536
537 /**
538 * Set breadcrumb based on asset heirarchy
539 */
540 function asset_wizard_set_breadcrumb(){
541 $breadcrumb[] = tbl(t('Step 1: Start'), 'asset/wizard');
542 if(arg(2) && !is_numeric(arg(2))){
543 $breadcrumb[] = tbl(t('Step 2: Selection'), 'asset/wizard/browse');
544 }
545 elseif(is_numeric(arg(2))){
546 $asset = asset_load(arg(2));
547 if($asset->type == 'directory'){
548 $breadcrumb[] = tbl(t('Step 2: Selection'), 'asset/wizard/'. $asset->aid);
549 }
550 else{
551 $breadcrumb[] = tbl(t('Step 2: Selection'), 'asset/wizard/'. $asset->pid);
552 $breadcrumb[] = tbl(t('Step 3: Formatting'), 'asset/wizard/'.$asset->aid);
553 }
554 }
555 drupal_set_breadcrumb($breadcrumb);
556 }
557
558 function asset_wizard_get_path(){
559 $asset = is_numeric(arg(2)) ? asset_load(arg(2), TRUE) : NULL;
560 $breadcrumb = array();
561 // if(in_array(arg(3), array_keys($asset->formatters))){
562 // $breadcrumb[] = tbl(_asset_wizard_truncate($asset->formatters[arg(3)]['name'], 30), 'asset/wizard/'. $asset->aid .'/'. arg(3));
563 // }
564 if($asset->aid){
565 $breadcrumb[] = tbl(_asset_wizard_truncate($asset->title, 30), 'asset/wizard/'. $asset->aid);
566 }
567 while($pid = $asset->pid){
568 $asset = asset_load($pid);
569 $breadcrumb[] = tbl(_asset_wizard_truncate($asset->title, 20), 'asset/wizard/'. $asset->aid);
570 }
571 $breadcrumb[] = tbl(t('Assets'), 'asset/wizard/browse');
572 return join(' / ', array_reverse($breadcrumb));
573 }
574
575 function _asset_wizard_truncate($text, $max_chars){
576 if(strlen($text) > $max_chars){
577 $text = substr($text, 0, $max_chars);
578 $last_word = strrchr($text, ' ');
579 if($last_word == ' '){
580 $text = substr($text, 0, strlen($text)-1) .'...';
581 }
582 else{
583 $text = preg_replace('/'. preg_quote($last_word, '/') .'$/', '...', $text);
584 }
585 }
586 return $text;
587 }
588
589 /*******************************************************************************
590 * thickbox theming
591 ******************************************************************************/
592
593 function theme_asset_wizard_main($items = array()){
594 return '<div class="asset-wizard-main">'. theme('item_list', $items) .'</div>';
595 }
596
597 /**
598 * Wizard Step 1: Display the icon list for browsing
599 */
600 function theme_asset_wizard_browse($items = array()){
601 $size = 64;
602 $links = array();
603 foreach($items as $asset){
604 $icon = theme('asset_icon', $asset, $size);
605 $links[] = tbl($icon, 'asset/wizard/'. $asset->aid, array(), NULL, NULL, FALSE, TRUE);
606 }
607 $output .= '<ul class="asset-wizard-browse clear-block">';
608 foreach($links as $link){
609 $output .= '<li>'. $link .'</li>';
610 }
611 $output .= '</ul>';
612 return $output;
613 }
614
615 /**
616 * Wizard Step 2: Display the list of available formats
617 */
618 function theme_asset_wizard_formats($asset, $formats){
619 $items = array();
620 foreach($formats as $format){
621 $items[] = tbl($format->name, 'asset/wizard/'. $asset->aid .'/'. $format->format)
622 . '<br/>' . $format->description;
623 }
624 $output .= theme('item_list', $items);
625 return $output;
626 }
627
628 /**
629 * Wizard Step 3: Display a preview
630 */
631 function theme_asset_wizard_preview($asset, $preview, $value){
632 $button = '<button value="'. $value .'" onclick="Drupal.assetWizard.insert(\''. $value .'\');">Finish</button>';
633 $output .= '<div class="asset-wizard-preview">'. $preview .'</div>';
634 $output .= theme('asset_wizard_form_buttons', $button);
635
636 return $output;
637 }
638
639 function theme_asset_wizard_form_buttons($form){
640 $output = (is_array($form)) ? drupal_render($form) : $form;
641 return '<div class="wizard-buttons">'. $output .'</div>';
642 }
643
644 function asset_wizard_js_settings(){
645 static $run = FALSE;
646
647 if($run){
648 return;
649 }
650 $settings = array(
651 'height' => 400,
652 'width' => 560,
653 'url' => url('asset/wizard'),
654 'title' => t('Asset Wizard'),
655 'assetUrl' => url('asset'),
656 'noIcon' => base_path() . drupal_get_path('module', 'asset_Wizard') .'/icons/missing.png',
657 );
658
659 drupal_add_js(array('assetWizard' => $settings), 'setting');
660 $run = TRUE;
661 }
662
663 /**
664 * Wrapper for l() function to add thickbox class and query params
665 */
666 function tbl($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE) {
667 if (isset($attributes['class'])) {
668 $attributes['class'] .= ' thickbox';
669 }
670 else {
671 $attributes['class'] = 'thickbox';
672 }
673 if (!isset($attributes['title'])) {
674 $attributes['title'] = t('Asset Wizard');
675 }
676 if($_GET['return']){
677 $query .= ($query ? '&' :'') . 'return='. $_GET['return'];
678 if($_GET['config']){
679 $query .= '&config='. $_GET['config'];
680 }
681 }
682 $query .= '&height=400&width=560&modal=true';
683 return l($text, $path, $attributes, $query, $fragment, $absolute,$html);
684 }
685
686 function theme_asset_wizard_page($content) {
687 $title = drupal_get_title();
688 asset_wizard_set_breadcrumb();
689 $breadcrumb = theme('breadcrumb', drupal_get_breadcrumb());
690 $messages = theme('status_messages');
691 $help = theme('help');
692 $links = theme('asset_wizard_links');
693 $selected = theme('asset_wizard_selected');
694
695 print <<<EOD
696 <div id="asset-wizard">
697
698 <h1>Asset Wizard</h1>
699
700 <div class="wizard-sidebar">
701 $links
702 $selected
703 </div>
704
705 <div class="wizard-main">
706 <h2>$title</h2>
707 <div class="wizard-content">
708 $messages
709 $help
710 $content
711 </div>
712 </div>
713
714 </div>
715
716 EOD;
717
718 exit();
719 }
720
721 function theme_asset_wizard_selected(){
722 if(is_numeric(arg(2))){
723 $asset = asset_load(arg(2));
724 $output = '<div class="wizard-selected"><h2>Selected Asset</h2>'
725 . '<div class="content">'
726 . theme('asset_icon', $asset)
727 . '</div></div>';
728 return $output;
729 }
730 }
731
732 function theme_asset_wizard_links(){
733 // figure out the step we are on
734 $step = 0;
735 if(arg(2) && !is_numeric(arg(2))){
736 $step = 1;
737 }
738 elseif(arg(2)){
739 $asset = asset_load(arg(2));
740 if($asset->type == 'directory'){
741 $step = 1;
742 }
743 else{
744 if(arg(3) == 'finish'){
745 $step = 4;
746 }
747 elseif(arg(3)){
748 $step = 3;
749 }
750 else{
751 $step = 2;
752 }
753 }
754 }
755
756 // build the links/spans based on what step we're on
757 $links = array();
758 $aid = is_numeric(arg(2)) ? arg(2) : 0;
759
760 if($_GET['return'] == 'id'){
761 $steps = array(
762 'asset/wizard' => t('Start'),
763 'asset/wizard/browse' => t('Select an Asset'),
764 'asset/wizard/'. $aid .'/finish/'. arg(4) => t('Preview'),
765 );
766 }
767 else{
768 $steps = array(
769 'asset/wizard' => t('Start'),
770 'asset/wizard/browse' => t('Select an Asset'),
771 'asset/wizard/'. $aid => t('Select a Format'),
772 'asset/wizard/'. $aid .'/'. arg(3) => t('Formatting Options'),
773 'asset/wizard/'. $aid .'/finish/'. arg(4) => t('Preview'),
774 );
775 }
776
777 $i = 0;
778 foreach($steps as $path => $text){
779 if($step == $i){
780 $links[] = '<span class="active">'. $text .'</span>';
781 }
782 elseif($step > $i){
783 $links[] = tbl($text, $path);
784 }
785 else{
786 $links[] = '<span>'. $text .'</span>';
787 }
788 $i++;
789 }
790
791 return '<ul><li>'. join('</li><li>', $links) .'</li></ul>';
792 }
793
794 function asset_wizard_help($section) {
795 $aid = arg(2);
796
797 switch ($section) {
798 case 'asset/wizard':
799 return '<p>'. t('The asset wizard allows you to create and select digital assets to use in the context of this site. To get started, select a method for choosing the appropriate asset.') .'</p>';
800 case 'asset/wizard/'. $aid .'/finish':
801 return '<p>'. t('Here is the preview of your formatted asset. You can click any of the links in the sidebar to make changes, or click Finish to insert this into the document.') .'</p>';
802 case 'asset/wizard/browse':
803 return '<p>'. t('Select the asset you wish to use.') .'</p>';
804 case 'asset/wizard/'. $aid:
805 return '<p>'. t('Select from the list of available formats.') .'</p>';
806 }
807 }
808
809 /**
810 * @} End of "addtogroup asset".
811 */

  ViewVC Help
Powered by ViewVC 1.1.2