| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: gallery_filter.inc,v 1.5.2.4 2008/02/18 23:07:15 profix898 Exp $ 3 4 /** 5 * gallery.module : gallery_filter.inc 6 * Gallery Filter functions 7 */ 8 9 /** 10 * Function gallery_filter_process(). 11 * (implementation of the main filter routine) 12 */ 13 function gallery_filter_process($text) { 14 $prefix = trim(variable_get('gallery_filter_prefix', 'G2')); 15 preg_match_all("/\[$prefix:(\d+)\s*(.*?)\]/i", $text, $matches, PREG_SET_ORDER); 16 17 // Initialize G2 and set default arguments 18 if (count($matches) > 0) { 19 if (!_gallery_init(TRUE)) { 20 return $text; 21 } 22 $default['n'] = variable_get('gallery_filter_n_images', 1); 23 $default['type'] = variable_get('gallery_filter_default_block_type', 'recentImage'); 24 $default['maxsize'] = variable_get('gallery_filter_default_maxsize', GALLERY_FILTER_MAXSIZE_DEFAULT); 25 $default['exactsize'] = variable_get('gallery_filter_default_exactsize', GALLERY_FILTER_EXACTSIZE_DEFAULT); 26 $default['class'] = variable_get('gallery_filter_default_div_class', 'nowrap'); 27 $default['album_frame'] = variable_get('gallery_filter_default_album_frame', 'none'); 28 $default['item_frame'] = variable_get('gallery_filter_default_item_frame', 'none'); 29 $default['show'] = variable_get('gallery_filter_default_show', array('none')); 30 $default['target'] = variable_get('gallery_filter_default_link_target', ''); 31 $default['link'] = variable_get('gallery_filter_default_link', ''); 32 } 33 else { 34 return $text; 35 } 36 37 $head_array = array(); 38 // Loop over all matches 39 foreach ($matches as $match) { 40 // First argument is numeric => valid G2 filter tag 41 if (is_numeric($match[1])) { 42 $args = array_filter(preg_split('/[\s,]+/', $match[2])); 43 $params = array('itemId' => intval($match[1])); 44 // If this item is not an album (e.g. photo, movie, ...) set block type to 'specificItem' 45 $details = gallery_item_details($params['itemId']); 46 if (isset($details['g2type']) && $details['g2type'] != 'GalleryAlbumItem') { 47 $params['n'] = 1; 48 $params['type'] = 'specificItem'; 49 } 50 if (preg_match('/user(:([\d]+))?/i', $params['itemId'], $param_uid)) { 51 require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc'); 52 $params['itemId'] = gallery_user_useralbum(isset($param_uid[2]) ? $param_uid[2] : NULL, FALSE); 53 } 54 // Loop over all (optional) arguments 55 foreach ($args as $arg) { 56 list($key, $value) = array_filter(explode('=', $arg)); 57 if (!empty($value)) { 58 $key = strtolower(preg_replace('/\W/', '', $key)); 59 $params[$key] = _gallery_filter_sanitize($key, $value); 60 } 61 } 62 // Treat 'maxsize' and 'size' as the same 63 if (isset($params['size'])) { 64 $params['maxsize'] = $params['size']; 65 unset($params['size']); 66 } 67 // Carefully treat the default size method (cannot just merge them as the 68 // entered value must take precedence over the default) 69 if (isset($params['maxsize'])) { 70 unset($default['exactsize']); 71 } 72 else if (isset($params['exactsize'])) { 73 unset($default['maxsize']); 74 } 75 // Merge params with default values 76 $params = array_merge($default, $params); 77 // Transform 'type' into a valid parameter 78 if ($params['n'] > 1 && $params['type'] == 'specificItem') { 79 $params['type'] = $default['type']; 80 } 81 if (is_array($params['type'])) { 82 // Ensure 'type' contains 'n' elements (auto-append if necessary) 83 $count = count($params['type']); 84 if (($num = $params['n'] - $count) > 0) { 85 $params['type'] += array_fill($count, $num, end($params['type'])); 86 } 87 } 88 else { 89 $params['type'] = array_fill(0, $params['n'], $params['type']); 90 } 91 // 'frame' overrides 'album_frame' and 'item_frame' 92 if ($params['frame']) { 93 $params['album_frame'] = $params['item_frame'] = $params['frame']; 94 } 95 // Convert into G2-compatible arguments 96 $params['blocks'] = implode('|', $params['type']); 97 if (isset($params['maxsize']) && !empty($params['maxsize'])) { 98 $params['maxSize'] = $params['maxsize']; 99 } 100 else if (isset($params['exactsize']) && !empty($params['exactsize'])) { 101 $params['exactSize'] = $params['exactsize']; 102 } 103 $params['albumFrame'] = $params['album_frame']; 104 $params['itemFrame'] = $params['item_frame']; 105 $params['show'] = implode('|', $params['show']); 106 $params['linkTarget'] = $params['target']; 107 // Unset redundant parameters 108 unset( 109 $params['n'], 110 $params['type'], 111 $params['exactsize'], 112 $params['maxsize'], 113 $params['frame'], 114 $params['album_frame'], 115 $params['item_frame'], 116 $params['target'] 117 ); 118 gallery_debug($params, t('Filter parameters')); 119 // Fetch the images and format output 120 list($ret, $content, $head) = GalleryEmbed::getBlock('imageblock', 'ImageBlock', $params); 121 if ($ret) { 122 gallery_error(t('Error trying to get image block.'), $ret); 123 continue; 124 } 125 $content = trim($content); 126 if (!empty($content)) { 127 $params['class'] = 'giImageBlock'. ($params['class'] ? ' '. $params['class'] : ''); 128 $content = '<div class ="'. $params['class'] .'">'. $content .'</div>'; 129 // Allow other modules to alter the filter output 130 drupal_alter('gallery_filter', $content, array('params' => $params)); 131 } 132 // Replace G2 filter tag with image block html (or at least remove filter tag) 133 $text = str_replace($match[0], $content, $text); 134 if ($head) { 135 $head_array[] = trim($head); 136 } 137 } 138 } 139 140 // Add html head items and css 141 if (count($head_array)) { 142 gallery_set_head(implode("\n", array_unique($head_array))); 143 } 144 GalleryEmbed::done(); 145 146 return $text .'<br class="giImageBlock-clear-both" />'; 147 } 148 149 /** 150 * Function _gallery_filter_sanitize(). 151 * (sanitize filter parameters) 152 */ 153 function _gallery_filter_sanitize($key, $value) { 154 switch ($key) { 155 case 'n': 156 case 'size': 157 case 'maxsize': 158 case 'exactsize': 159 return intval(preg_replace('/\D/', '', $value)); 160 case 'class': 161 case 'frame': 162 case 'album_frame': 163 case 'item_frame': 164 case 'target': 165 case 'link': 166 return preg_replace('/\W/', '', $value); 167 case 'type': 168 case 'show': 169 return explode('|', preg_replace('/[^\w\x7c]/', '', $value)); 170 default : 171 return check_plain($value); 172 } 173 174 return $value; 175 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |