Changeset 17010
- Timestamp:
- Jul 25, 2012, 2:51:46 PM (12 years ago)
- Location:
- extensions/ExtendedDescription
- Files:
-
- 9 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/ExtendedDescription/language/en_UK/help.html
r16172 r17010 76 76 <li><b>[random album=yy size=M html=yes link=yes]</b></li> 77 77 </ul> 78 <p>Same thin as above, except that the photo is choosed randomly into <code>album</code></p> 78 <p>Same thing as above, except that the photo is choosed randomly into <code>album</code></p> 79 80 <ul> 81 <li><b>[slider album=xx nb_images=10 random=no list=aa,bb,cc size=M speed=3 title=no effect=fade arrows=yes control=yes elastic=no]</b></li> 82 </ul> 83 <p>This tag allows to insert a slideshow (NivoSlider), with (you must set <code>album</code> OR <code>list</code>):<br><br> 84 - <code>album</code> (optional) source album<br> 85 - <code>nb_images</code> (optional) max number of photos to display in the slideshow<br> 86 - <code>random</code> (optional) choose photos randomly in the album<br> 87 - <code>list</code> (optional) a list of photos ids separated by a comma<br> 88 - <code>size</code> (optional) the size of the photos, among <i>{SQ, TH, XXS, S, M, L, XL, XXL}</i><br> 89 - <code>speed</code> (optional) the slideshow speed (in seconds)<br> 90 - <code>title</code> (optional) display photo title<br> 91 - <code>effect</code> (optional) transition effect (see <a href="http://nivo.dev7studios.com/support/jquery-plugin-usage/">NivoSlider doc</a>)<br> 92 - <code>arrows</code> (optional) display navigation arrows<br> 93 - <code>control</code> (optional) display navigation controls<br> 94 - <code>elastic</code> (optional) adapt slideshow size to each photo</p> 79 95 80 96 -
extensions/ExtendedDescription/language/fr_FR/help.html
r16172 r17010 72 72 <li><b>[photo id=xx album=yy size=M html=yes link=yes]</b></li> 73 73 </ul> 74 <p>Cet etbalise permet d'insérer une photo de n'importe quelle taille, avec:<br><br>74 <p>Cette balise permet d'insérer une photo de n'importe quelle taille, avec:<br><br> 75 75 - <code>id</code> le numéro de la photo<br> 76 - <code>album</code> ( optional) le numéro de l'album parent<br>77 - <code>size</code> ( optional) la taille de la photo, parmi <i>{SQ, TH, XXS, S, M, L, XL, XXL}</i><br>78 - <code>html</code> ( optional) si <i>no</i>, la balise ne retourne que l'URL de la photo, sans HTML<br>79 - <code>link</code> ( optional) si <i>yes</i>, la photo est cliquable, vers sa page</p>76 - <code>album</code> (facultatif) le numéro de l'album parent<br> 77 - <code>size</code> (facultatif) la taille de la photo, parmi <i>{SQ, TH, XXS, S, M, L, XL, XXL}</i><br> 78 - <code>html</code> (facultatif) si <i>no</i>, la balise ne retourne que l'URL de la photo, sans HTML<br> 79 - <code>link</code> (facultatif) si <i>yes</i>, la photo est cliquable, vers sa page</p> 80 80 81 81 <ul> … … 83 83 </ul> 84 84 <p>Même chose, sauf que la photo est prise aléatoirement dans <code>album</code></p> 85 86 <ul> 87 <li><b>[slider album=xx nb_images=10 random=no list=aa,bb,cc size=M speed=3 title=no effect=fade arrows=yes control=yes elastic=no]</b></li> 88 </ul> 89 <p>Permet d'insérer un diaporama (NivoSlider), avec (vous devez renseigner <code>album</code> OU <code>list</code>):<br><br> 90 - <code>album</code> (facultatif) album source<br> 91 - <code>nb_images</code> (facultatif) nombre maximal de photos dans le diaporama<br> 92 - <code>random</code> (facultatif) choisir les photos aléatoirement dans l'album<br> 93 - <code>list</code> (facultatif) une liste de photos séparées par une virgule<br> 94 - <code>size</code> (facultatif) la taille des photos, parmi <i>{SQ, TH, XXS, S, M, L, XL, XXL}</i><br> 95 - <code>speed</code> (facultatif) la vitesse du diaporama (en secondes)<br> 96 - <code>title</code> (facultatif) afficher le nom de la photo<br> 97 - <code>effect</code> (facultatif) effet de transition (voir <a href="http://nivo.dev7studios.com/support/jquery-plugin-usage/">la doc de NivoSlider</a>)<br> 98 - <code>arrows</code> (facultatif) afficher les flèches de navigations<br> 99 - <code>control</code> (facultatif) afficher la barre de navigation<br> 100 - <code>elastic</code> (facultatif) adapter la taille du diaporama à chaque photo</p> 101 85 102 86 103 <h3>Masquer un album</h3> -
extensions/ExtendedDescription/main.inc.php
r16969 r17010 122 122 // Balises [img=xx.yy,xx.yy,xx.yy;left|right|;name|titleName|] 123 123 //$patterns[] = '#\[img=(\d*)\.?(\d*|);?(left|right|);?(name|titleName|)\]#ie'; 124 $patterns[] = '#\[img=([\d\s\. ]*);?(left|right|);?(name|titleName|)\]#ie';124 $patterns[] = '#\[img=([\d\s\.,]*);?(left|right|);?(name|titleName|)\]#ie'; 125 125 $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_img_thumb("$1", "$2", "$3")'; 126 126 127 127 // Balises [photo id=xx album=yy size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] 128 $patterns[] = '#\[photo\s+id=(\d+)(?:\s+album=(\d+))?(?:\s+size=(SQ|TH|XXS|XS|S|M|L|XL|XXL))?(?:\s+html=(yes|no))?(?:\s+link=(yes|no))?\]#ie'; 129 $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1", "$2", "$3", "$4", "$5")'; 128 // $patterns[] = '#\[photo(?:(?:\s+(id)=(\d+))|(?:\s+(album)=(\d+))|(?:\s+(size)=(SQ|TH|XXS|XS|S|M|L|XL|XXL))|(?:\s+(html)=(yes|no))|(?:\s+(link)=(yes|no))){1,5}\s*\]#ie'; //10 129 $patterns[] = '#\[photo ([^\]]+)\]#ie'; 130 $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_photo_sized("$1")'; 130 131 131 132 // Balises [random album=xx size=SQ|TH|XXS|XS|S|M|L|XL|XXL html=yes|no link=yes|no] 132 $patterns[] = '#\[random\s+(?:album|cat)=(\d+)(?:\s+size=(SQ|TH|XXS|XS|S|M|L|XL|XXL))?(?:\s+html=(yes|no))?(?:\s+link=(yes|no))?\]#ie'; 133 $replacements[] = 'extdesc_get_random_photo("$1", "$2", "$3", "$4")'; 133 // $patterns[] = '#\[random(?:(?:\s+(album|cat)=(\d+))|(?:\s+(size)=(SQ|TH|XXS|XS|S|M|L|XL|XXL))|(?:\s+(html)=(yes|no))|(?:\s+(link)=(yes|no))){1,4}\s*\]#ie'; //8 134 $patterns[] = '#\[random ([^\]]+)\]#ie'; 135 $replacements[] = ($param == 'subcatify_category_description') ? '' : 'extdesc_get_random_photo("$1")'; 136 137 // Balises [slider album=xx nb_images=yy random=yes|no list=aa,bb,cc size=SQ|TH|XXS|XS|S|M|L|XL|XXL speed=z title=yes|no effect=... arrows=yes|no control=yes|no elastic=yes|no] 138 // $patterns[] = '#\[slider(?:(?:\s+(album)=(\d+))|(?:\s+(nb_images)=(\d+))|(?:\s+(random)=(yes|no))|(?:\s+(list)=([\d,]+))|(?:\s+(size)=(SQ|TH|XXS|XS|S|M|L|XL|XXL))|(?:\s+(speed)=(\d+))|(?:\s+(title)=(yes|no))|(?:\s+(effect)=([a-zA-Z]+))|(?:\s+(arrows)=(yes|no))|(?:\s+(control)=(yes|no))|(?:\s+(elastic)=(yes|no))){1,11}\s*\]#ie'; //22 139 $patterns[] = '#\[slider ([^\]]+)\]#ie'; 140 $replacements[] = ($param == 'subcatify_category_description') ? '' : 'get_slider("$1")'; 134 141 135 142 // Balises <!--complete-->, <!--more--> et <!--up-down--> … … 371 378 } 372 379 373 // Return html code for a photo 374 function get_photo_sized($image_id, $cat_id, $size, $html, $link) 380 /** 381 * Return html code for a photo 382 * 383 * @int id: picture id 384 * @int album: album to display picture in (default: null) 385 * @string size: picture size (default: M) 386 * @string html: return complete html structure (default: yes) 387 * @string link: add a link to the picture (default: yes) 388 */ 389 function get_photo_sized($param) 375 390 { 376 391 global $template; 377 392 393 $default_params = array( 394 'id' => array('\d+', null), 395 'album' => array('\d+', null), 396 'size' => array('SQ|TH|XXS|XS|S|M|L|XL|XXL', 'M'), 397 'html' => array('yes|no', 'yes'), 398 'link' => array('yes|no', 'yes'), 399 ); 400 401 $params = parse_parameters($param, $default_params); 402 403 // check picture id 404 if (empty($params['id'])) return 'missing picture id'; 405 406 // parameters 407 $params['link'] = $params['link']=='no' ? false : true; 408 $params['html'] = $params['html']=='no' ? false : true; 409 $deriv_type = get_deriv_type($params['size']); 410 411 // get picture 412 $query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = '.$params['id'].';'; 413 $result = pwg_query($query); 414 415 if (pwg_db_num_rows($result)) 416 { 417 $picture = pwg_db_fetch_assoc($result); 418 419 // url 420 if ($params['link']) 421 { 422 if (!empty($params['album'])) 423 { 424 $url = make_picture_url(array( 425 'image_id' => $picture['id'], 426 'category' => array( 427 'id' => $params['album'], 428 'name' => '', 429 'permalink' => '', 430 ))); 431 } 432 else 433 { 434 $url = make_picture_url(array('image_id' => $picture['id'])); 435 } 436 } 437 438 // image 439 $src_image = new SrcImage($picture); 440 $derivatives = DerivativeImage::get_all($src_image); 441 $selected_derivative = $derivatives[$deriv_type]; 442 443 $template->assign(array( 444 'current' => array( 445 'selected_derivative' => $selected_derivative, 446 ), 447 'ALT_IMG' => $picture['file'], 448 )); 449 450 // output 451 if ($params['html']) 452 { 453 $template->set_filename('extended_description_content', dirname(__FILE__).'/template/picture_content.tpl'); 454 $content = $template->parse('extended_description_content', true); 455 if ($params['link']) return '<a href="'.$url.'">'.$content.'</a>'; 456 else return $content; 457 } 458 else 459 { 460 return $selected_derivative->get_url(); 461 } 462 } 463 464 return 'invalid picture id'; 465 } 466 467 /** 468 * Return html code for a random photo 469 * 470 * @int album: select picture from this album 471 * @string size: picture size (default: M) 472 * @string html: return complete html structure (default: yes) 473 * @string link: add a link to the picture (default: no) 474 */ 475 function extdesc_get_random_photo($param) 476 { 477 $default_params = array( 478 'album' => array('\d+', null), 479 'cat' => array('\d+', null), // historical 480 'size' => array('SQ|TH|XXS|XS|S|M|L|XL|XXL', 'M'), 481 'html' => array('yes|no', 'yes'), 482 'link' => array('yes|no', 'no'), 483 ); 484 485 $params = parse_parameters($param, $default_params); 486 487 // check album id 488 if (empty($params['album'])) 489 { 490 if (empty($params['cat'])) return 'missing album id'; 491 $params['album'] = $params['cat']; 492 } 493 494 // get picture id 495 $query = ' 496 SELECT id 497 FROM '.IMAGES_TABLE.' 498 JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 499 WHERE category_id = '.$params['album'].' 500 ORDER BY '.DB_RANDOM_FUNCTION.'() 501 LIMIT 1 502 ;'; 503 $result = pwg_query($query); 504 505 if (pwg_db_num_rows($result)) 506 { 507 list($img_id) = pwg_db_fetch_row($result); 508 return get_photo_sized('id='.$img_id.' album='.$params['album'].' size='.$params['size'].' html='.$params['html'].' link='.$params['link']); 509 } 510 511 return ''; 512 } 513 514 /** 515 * Return html code for a nivo slider (album or list is mandatory) 516 * 517 * @int album: select pictures from this album 518 * @int nb_images: display only x pictures (default: 10) 519 * @string random: random sort order (default: no) 520 * 521 * @string list: pictures id separated by a comma 522 * 523 * @string size: picture size (default: M) 524 * @int speed: slideshow duration (default: 3) 525 * @string title: display picture name (default: no) 526 * @string effect: transition effect (default: fade) 527 * @string arrows: display navigation arrows (default: yes) 528 * @string control: display navigation bar (default: yes) 529 * @string elastic: adapt slider size to each picture (default: no) 530 */ 531 function get_slider($param) 532 { 533 global $template, $conf; 534 535 $default_params = array( 536 'album' => array('\d+', null), 537 'nb_images' => array('\d+', 10), 538 'random' => array('yes|no', 'no'), 539 'list' => array('[\d,]+', null), 540 'size' => array('SQ|TH|XXS|XS|S|M|L|XL|XXL', 'M'), 541 'speed' => array('\d+', 3), 542 'title' => array('yes|no', 'no'), 543 'effect' => array('[a-zA-Z]+', 'fade'), 544 'arrows' => array('yes|no', 'yes'), 545 'control' => array('yes|no', 'yes'), 546 'elastic' => array('yes|no', 'no'), 547 ); 548 549 $params = parse_parameters($param, $default_params); 550 551 // check size 552 $deriv_type = get_deriv_type($params['size']); 553 $enabled = ImageStdParams::get_defined_type_map(); 554 if (empty($enabled[ $deriv_type ])) return 'size disabled'; 555 556 // parameters 557 $params['arrows'] = $params['arrows']==='no' ? 'false' : 'true'; 558 $params['control'] = $params['control']==='no' ? 'false' : 'true'; 559 $params['elastic'] = $params['elastic']==='yes' ? true : false; 560 $params['title'] = $params['title']==='yes' ? true : false; 561 562 // pictures from album... 563 if (!empty($params['album'])) 564 { 565 // parameters 566 $params['random'] = $params['random']==='yes' ? true : false; 567 568 // get image order inside category 569 if ($params['random']) 570 { 571 $order_by = DB_RANDOM_FUNCTION.'()'; 572 } 573 else 574 { 575 $query = ' 576 SELECT image_order 577 FROM '.CATEGORIES_TABLE.' 578 WHERE id = '.$params['album'].' 579 ;'; 580 list($order_by) = pwg_db_fetch_row(pwg_query($query)); 581 if (empty($order_by)) 582 { 583 $order_by = str_replace('ORDER BY ', null, $conf['order_by_inside_category']); 584 } 585 } 586 587 // get pictures ids 588 $query = ' 589 SELECT image_id 590 FROM '.IMAGE_CATEGORY_TABLE.' as ic 591 INNER JOIN '.IMAGES_TABLE.' as i 592 ON i.id = ic.image_id 593 WHERE category_id = '.$params['album'].' 594 ORDER BY '.$order_by.' 595 LIMIT '.$params['nb_images'].' 596 ;'; 597 $params['list'] = implode(',', array_from_query($query, 'image_id')); 598 } 599 // ...or pictures list 600 if (empty($params['list'])) 601 { 602 return 'missing album id or empty picture list'; 603 } 604 605 // get pictures 606 $query = ' 607 SELECT * 608 FROM '.IMAGES_TABLE.' 609 WHERE id IN ('.$params['list'].') 610 ;'; 611 $pictures = hash_from_query($query, 'id'); 612 613 foreach ($pictures as $row) 614 { 615 // url 616 if (!empty($params['album'])) 617 { 618 $url = make_picture_url(array( 619 'image_id' => $row['id'], 620 'category' => array( 621 'id' => $params['album'], 622 'name' => '', 623 'permalink' => '', 624 ))); 625 } 626 else 627 { 628 $url = make_picture_url(array('image_id' => $row['id'])); 629 } 630 631 $name = render_element_name($row); 632 633 $tpl_vars[] = array_merge($row, array( 634 'TN_ALT' => htmlspecialchars(strip_tags($name)), 635 'NAME' => $name, 636 'URL' => $url, 637 'src_image' => new SrcImage($row), 638 )); 639 } 640 641 list($img_size['w'], $img_size['h']) = $enabled[ $deriv_type ]->sizing->ideal_size; 642 643 $template->assign(array( 644 'EXTENDED_DESC_PATH' => EXTENDED_DESC_PATH, 645 'slider_id' => crc32(uniqid($params['list'])), // need a unique id if we have multiple sliders 646 'slider_content' => $tpl_vars, 647 'derivative_params' => ImageStdParams::get_by_type( $deriv_type ), 648 'img_size' => $img_size, 649 'pauseTime' => $params['speed']*1000, 650 'controlNav' => $params['control'], 651 'effect' => $params['effect'], 652 'directionNav' => $params['arrows'], 653 'elastic_size' => $params['elastic'], 654 'show_title' => $params['title'], 655 )); 656 657 $template->set_filename('extended_description_content', dirname(__FILE__).'/template/slider.tpl'); 658 return $template->parse('extended_description_content', true); 659 } 660 661 662 function parse_parameters($param, $default_params) 663 { 664 $params = array(); 665 666 foreach ($default_params as $name => $value) 667 { 668 if (preg_match('#'.$name.'=('.$value[0].')#', $param, $matches)) 669 { 670 $params[$name] = $matches[1]; 671 } 672 else 673 { 674 $params[$name] = $value[1]; 675 } 676 } 677 678 return $params; 679 } 680 681 function get_deriv_type($size) 682 { 378 683 $size_map = array( 379 684 'SQ' => IMG_SQUARE, … … 389 694 390 695 if (!array_key_exists($size, $size_map)) $size = 'M'; 391 $link = $link=='no' ? false: true; 392 $html = $html=='no' ? false: true; 393 394 $deriv_type = $size_map[ strtoupper($size) ]; 395 396 $query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = '.$image_id.';'; 397 $result = pwg_query($query); 398 399 if (pwg_db_num_rows($result)) 400 { 401 $template->set_filename('extended_description_content', dirname(__FILE__).'/template/picture_content.tpl'); 402 403 $picture = pwg_db_fetch_assoc($result); 404 405 // url 406 if (!empty($cat_id)) 407 { 408 $url = make_picture_url(array( 409 'image_id' => $picture['id'], 410 'category' => array( 411 'id' => $cat_id, 412 'name' => '', 413 'permalink' => ''))); 414 } 415 else 416 { 417 $url = make_picture_url(array('image_id' => $picture['id'])); 418 } 419 420 // image 421 $src_image = new SrcImage($picture); 422 $derivatives = DerivativeImage::get_all($src_image); 423 $selected_derivative = $derivatives[$deriv_type]; 424 425 $template->assign(array( 426 'current' => array( 427 'selected_derivative' => $selected_derivative, 428 ), 429 'ALT_IMG' => $picture['file'], 430 )); 431 if (!empty($picture['comment'])) 432 { 433 $template->assign('COMMENT_IMG', trigger_event('render_element_description', $picture['comment'])); 434 } 435 436 437 if ($html) 438 { 439 $content = $template->parse('extended_description_content', true); 440 if ($link) return '<a href="'.$url.'">'.$content.'</a>'; 441 else return $content; 442 } 443 else 444 { 445 return $selected_derivative->get_url(); 446 } 447 } 448 449 return ''; 450 } 451 452 453 454 function extdesc_get_random_photo($category_id, $size, $html, $link) 455 { 456 if ('yes' != $link) 457 { 458 $link = 'no'; 459 } 460 461 include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 462 463 $query = ' 464 SELECT id 465 FROM '.IMAGES_TABLE.' 466 JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id 467 WHERE category_id = '.$category_id.' 468 ORDER BY '.DB_RANDOM_FUNCTION.'() 469 LIMIT 1 470 ;'; 471 $result = pwg_query($query); 472 473 if (pwg_db_num_rows($result)) 474 { 475 list($img_id) = pwg_db_fetch_row($result); 476 return get_photo_sized($img_id, $category_id, $size, $html, $link); 477 } 478 479 return ''; 480 } 696 697 return $size_map[ strtoupper($size) ]; 698 } 699 481 700 482 701 if (script_basename() == 'admin' or script_basename() == 'popuphelp') … … 485 704 } 486 705 487 add_event_handler ('render_page_banner', 'get_ user_language_desc');706 add_event_handler ('render_page_banner', 'get_extended_desc'); 488 707 add_event_handler ('render_category_name', 'get_user_language_desc'); 489 708 add_event_handler ('render_category_description', 'get_extended_desc', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
Note: See TracChangeset
for help on using the changeset viewer.