Changeset 31852
- Timestamp:
- Jun 12, 2017, 9:31:38 PM (7 years ago)
- Location:
- extensions/MenuRandomPhoto
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/MenuRandomPhoto/admin.php
r31780 r31852 7 7 if (isset($_POST['submit'])) 8 8 { 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 9 $conf['MRP'] = array( 10 'randompicture_preload' => $conf['MRP']['randompicture_preload'], 11 'square' => isset($_POST['square']), 12 ); 13 if (isset($_POST['height'])) 14 $conf['MRP']['height'] = $_POST['height']; 15 else 16 $conf['MRP']['height'] = 0; 17 if (isset($_POST['title'])) 18 $conf['MRP']['title'] = $_POST['title']; 19 else 20 $conf['MRP']['title'] = ''; 21 if (isset($_POST['delay'])) 22 $conf['MRP']['delay'] = $_POST['delay']*1000; 23 else 24 $conf['MRP']['delay'] = 0; 25 25 26 conf_update_param('MRP', serialize($conf['MRP'])); 27 $page['infos'][] = l10n('Information data registered in database'); 26 if (isset($_POST['apply_to_albums']) and in_array($_POST['apply_to_albums'], array('all', 'list'))) 27 { 28 $conf['MRP']['apply_to_albums'] = $_POST['apply_to_albums']; 29 if ($_POST['apply_to_albums'] == 'list') 30 { 31 check_input_parameter('albums', $_POST, true, PATTERN_ID); 32 33 if (empty($_POST['albums'])) 34 $_POST['albums'][] = -1; 35 36 $query = 'UPDATE '.CATEGORIES_TABLE.' SET menurandomphoto_active=\'false\' WHERE id NOT IN ('.implode(',', $_POST['albums']).');'; 37 pwg_query($query); 38 39 $query = 'UPDATE '.CATEGORIES_TABLE.' SET menurandomphoto_active=\'true\' WHERE id IN ('.implode(',', $_POST['albums']).');'; 40 pwg_query($query); 41 } 42 } 43 44 conf_update_param('MRP', serialize($conf['MRP'])); 45 $page['infos'][] = l10n('Information data registered in database'); 28 46 } 29 47 30 $template->assign(array( 31 'MRP' => $conf['MRP'], 32 )); 48 // make sure we have the extra column (update vs copy new version over old one) 49 $result = pwg_query('SHOW COLUMNS FROM `'.CATEGORIES_TABLE.'` LIKE "menurandomphoto_active";'); 50 if (!pwg_db_num_rows($result)) 51 { 52 $page['errors'][] = l10n('MenuRandomPhoto seems not to be installed/configured properly. Please remove and reinstall.'); 53 return; 54 } 55 56 // associate to albums 57 $query = 'SELECT id FROM '.CATEGORIES_TABLE.' WHERE menurandomphoto_active=\'true\';'; 58 $mrp_albums = array_from_query($query, 'id'); 59 60 $query = 'SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.';'; 61 display_select_cat_wrapper($query, $mrp_albums, 'album_options'); 62 63 $template->assign(array('MRP' => $conf['MRP'])); 33 64 34 65 $template->set_filename('plugin_admin_content', realpath(MRP_PATH . 'template/admin.tpl')); 35 66 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); 36 37 ?> -
extensions/MenuRandomPhoto/language/de_DE/plugin.lang.php
r30666 r31852 28 28 $lang['Use square'] = 'Quadrate verwenden'; 29 29 $lang['milliseconds'] = 'Millisekunden'; 30 $lang['seconds'] = 'Sekunden'; 31 $lang['Which albums to use'] = 'Welche Alben sollen verwendet werden'; 32 $lang['all albums'] = 'Alle Alben'; 33 $lang['a list of albums'] = 'Die Alben in der Liste'; 34 $lang['Select albums...'] = 'Alben auswählen...'; 35 $lang['Note: Only the selected albums/categories will be shown. Sub-categories must be selected if they are to be used!'] = 'Hinweis: Nur die ausgewählten Alben/Kategorien werden angezeigt. Unter-Kategorien müssen ausgewählt werden, wenn sie angezeigt werden sollen!'; 36 $lang['No pictures for MenuRandomPhoto found.'] = 'Keine Bilder für MenuRandomPhoto gefunden.'; 37 $lang['MenuRandomPhoto seems not to be installed/configured properly. Please remove and reinstall.'] = 'MenuRandomPhoto scheint nicht korrekt installiert/konfiguriert zu sein. Please entfernen und neu installieren.'; -
extensions/MenuRandomPhoto/language/en_UK/plugin.lang.php
r30050 r31852 8 8 $lang['Delay'] = 'Delay'; 9 9 $lang['milliseconds'] = 'milliseconds'; 10 11 ?> 10 $lang['seconds'] = 'seconds'; 11 $lang['Which albums to use'] = 'Which albums to use'; 12 $lang['all albums'] = 'all albums'; 13 $lang['a list of albums'] = 'a list of albums'; 14 $lang['Select albums...'] = 'Select albums...'; 15 $lang['Note: Only the selected albums/categories will be shown. Sub-categories must be selected if they are to be used!'] = 'Note: Only the selected albums/categories will be shown. Sub-categories must be selected if they are to be used!'; 16 $lang['No pictures for MenuRandomPhoto found.'] = 'No pictures for MenuRandomPhoto found.'; 17 $lang['MenuRandomPhoto seems not to be installed/configured properly. Please remove and reinstall.'] = 'MenuRandomPhoto seems not to be installed/configured properly. Please remove and reinstall.'; -
extensions/MenuRandomPhoto/main.inc.php
r31780 r31852 2 2 /* 3 3 Plugin Name: Menu Random Photo 4 Version: 2. 7.c4 Version: 2.8.0 5 5 Description: Adds a random picture block into menu 6 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=778 7 Author: JanisV 8 Fixes: romanf 7 Authors: JanisV, romanf 9 8 */ 10 9 … … 22 21 if (defined('IN_ADMIN')) 23 22 { 24 23 add_event_handler('get_admin_plugin_menu_links', 'MRP_admin_menu'); 25 24 } 26 25 else 27 26 { 28 29 27 add_event_handler('blockmanager_apply', 'MRP_blockmanager_apply'); 28 add_event_handler('loc_end_page_header', 'MRP_end_page_header'); 30 29 } 31 30 32 31 function MRP_init() 33 32 { 34 35 36 37 38 33 global $conf, $user; 34 35 load_language('plugin.lang', MRP_PATH); 36 37 $conf['MRP'] = unserialize($conf['MRP']); 39 38 } 40 39 41 40 function MRP_register_menubar_blocks($menu_ref_arr) 42 {43 44 45 46 41 { 42 $menu = & $menu_ref_arr[0]; 43 if ($menu->get_id() != 'menubar') 44 return; 45 $menu->register_block( new RegisteredBlock('mbRandomPhoto', 'Menu Random Photo', 'MRP')); 47 46 } 48 47 49 48 function MRP_blockmanager_apply($menu_ref_arr) 50 49 { 51 global $user, $conf; 52 53 $menu = & $menu_ref_arr[0]; 54 55 if(( 56 ($block=$menu->get_block('mbRandomPhoto'))!=null) and 57 ($user['nb_total_images']>0) 58 ) 59 { 60 $block->set_title($conf['MRP']['title']); 61 $block->template=realpath(MRP_PATH.'template/menu_random_photo.tpl'); 62 } 63 } 64 65 function MRP_end_page_header() 66 { 67 global $user, $template, $page, $conf; 68 69 if(!array_key_exists('body_id', $page)) 70 { 71 /* 72 * it seems the error message reported on mantis:1476 is displayed because 73 * the 'body_id' doesn't exist in the $page 74 * 75 * not abble to reproduce the error, but initializing the key to an empty 76 * value if it doesn't exist may be a sufficient solution 77 */ 78 $page['body_id']=""; 79 } 80 81 if($page['body_id'] == 'theCategoryPage') 82 { 83 $randomPictProp = array( 84 'delay' => $conf['MRP']['delay'], 85 'blockHeight' => $conf['MRP']['height'], 86 // 'showname' => $this->config['amm_randompicture_showname'], 87 // 'showcomment' => $this->config['amm_randompicture_showcomment'], 88 'pictures' => getRandomPictures($conf['MRP']['randompicture_preload']), 89 ); 90 91 if (count($randomPictProp['pictures']) > 0) 92 { 93 $local_tpl = new Template(MRP_PATH.'/template', ""); 94 $local_tpl->set_filename('body_page', realpath(MRP_PATH.'/template/menu_random_photo.js.tpl')); 95 96 $local_tpl->assign('data', $randomPictProp); 97 98 $template->append('head_elements', $local_tpl->parse('body_page', true)); 99 } 100 } 101 } 102 103 /** 104 * return a list of thumbnails 105 * each array items is an array 106 * 'imageId' => (integer) 107 * 'imageFile' => (String) 108 * 'comment' => (String) 109 * 'path' => (String) 110 * 'catId' => (String) 111 * 'name' => (String) 112 * 'permalink' => (String) 113 * 'imageName' => (String) 114 * 115 * @param Integer $number : number of returned images 116 * @return Array 117 */ 118 function getRandomPictures($num=25) 119 { 120 global $user, $conf; 121 122 $returned=array(); 123 124 if (preg_match('/(Googlebot|bingbot|Baiduspider|yandex|AhrefsBot|msnbot|NCollector)/', $_SERVER["HTTP_USER_AGENT"])) 125 { 126 return($returned); 127 } 128 129 $sql=array(); 130 131 // because ORDER BY RAND() can be very slow on a big database, let's 132 // make a first query with no join and by security take 5 times 133 // $num. We keep the result in session for 5 minutes. 134 if (!isset($_SESSION['mrp_random_pics']) 135 or !isset($_SESSION['mrp_random_pics_generated_on']) 136 or $_SESSION['mrp_random_pics_generated_on'] < time() - 5*60) // 5 minutes ago 137 { 138 $query = ' 139 SELECT id 140 FROM '.IMAGES_TABLE.' 141 WHERE level <= '.$user['level'].' 142 ORDER BY RAND() LIMIT '.($num*5).' 143 ;'; 144 $_SESSION['mrp_random_pics'] = query2array($query, null, 'id'); 145 $_SESSION['mrp_random_pics_generated_on'] = time(); 146 } 147 148 $sql['select'] = ' 50 global $user, $conf; 51 52 $menu = & $menu_ref_arr[0]; 53 54 if(( 55 ($block=$menu->get_block('mbRandomPhoto'))!=null) and 56 ($user['nb_total_images']>0) 57 ) 58 { 59 $block->set_title($conf['MRP']['title']); 60 $block->template=realpath(MRP_PATH.'template/menu_random_photo.tpl'); 61 } 62 } 63 64 function MRP_end_page_header() 65 { 66 global $user, $template, $page, $conf; 67 68 if(!array_key_exists('body_id', $page)) 69 { 70 /* 71 * it seems the error message reported on mantis:1476 is displayed because 72 * the 'body_id' doesn't exist in the $page 73 * 74 * not abble to reproduce the error, but initializing the key to an empty 75 * value if it doesn't exist may be a sufficient solution 76 */ 77 $page['body_id']=""; 78 } 79 80 if($page['body_id'] == 'theCategoryPage') 81 { 82 $randomPictProp = array( 83 'delay' => $conf['MRP']['delay'], 84 'blockHeight' => $conf['MRP']['height'], 85 // 'showname' => $this->config['amm_randompicture_showname'], 86 // 'showcomment' => $this->config['amm_randompicture_showcomment'], 87 'pictures' => getRandomPictures($conf['MRP']['randompicture_preload']), 88 ); 89 90 if (count($randomPictProp['pictures']) > 0) 91 { 92 $local_tpl = new Template(MRP_PATH.'/template', ""); 93 $local_tpl->set_filename('body_page', realpath(MRP_PATH.'/template/menu_random_photo.js.tpl')); 94 95 $local_tpl->assign('data', $randomPictProp); 96 97 $template->append('head_elements', $local_tpl->parse('body_page', true)); 98 } 99 } 100 } 101 102 /** 103 * return a list of thumbnails 104 * each array items is an array 105 * 'imageId' => (integer) 106 * 'imageFile' => (String) 107 * 'comment' => (String) 108 * 'path' => (String) 109 * 'catId' => (String) 110 * 'name' => (String) 111 * 'permalink' => (String) 112 * 'imageName' => (String) 113 * 114 * @param Integer $number : number of returned images 115 * @return Array 116 */ 117 function getRandomPictures($num=25) 118 { 119 global $user, $conf, $page, $header_msgs; 120 121 $returned=array(); 122 123 if (preg_match('/(Googlebot|bingbot|Baiduspider|yandex|AhrefsBot|msnbot|NCollector)/', $_SERVER["HTTP_USER_AGENT"])) 124 { 125 return($returned); 126 } 127 128 if (!isset($conf['MRP']['apply_to_albums'])) 129 { 130 $page['errors'][] = l10n('MenuRandomPhoto seems not to be installed/configured properly. Please remove and reinstall.'); 131 return ($returned); 132 } 133 134 $sql=array(); 135 136 // If we use all pics for MRP, then we use the pre-fetch, if we only show 137 // some, then we can't use the pre-fetch but will limit to (hopefully) a few albums. 138 139 // pre-fetch: 140 // because ORDER BY RAND() can be very slow on a big database, let's 141 // make a first query with no join and by security take 5 times 142 // $num. We keep the result in session for 5 minutes. 143 if ($conf['MRP']['apply_to_albums'] == "all" && 144 ( 145 !isset($_SESSION['mrp_random_pics']) 146 or !isset($_SESSION['mrp_random_pics_generated_on']) 147 or $_SESSION['mrp_random_pics_generated_on'] < time() - 5*60 // 5 minutes ago 148 ) 149 ) 150 { 151 $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE level <= '.$user['level'].' ORDER BY RAND() LIMIT '.($num*5).';'; 152 153 $mrp = query2array($query, null, 'id'); 154 if (!is_array($mrp) || count($mrp)<1) 155 { 156 $page['errors'][] = l10n('No pictures for MenuRandomPhoto found.'); 157 return ($returned); 158 } 159 160 $_SESSION['mrp_random_pics'] = $mrp; 161 $_SESSION['mrp_random_pics_generated_on'] = time(); 162 } 163 164 $sql['select'] = ' 149 165 SELECT 150 151 152 153 154 155 156 157 166 i.id as image_id, 167 i.file as image_file, 168 i.comment, 169 i.path, 170 c.id as catid, 171 c.name, 172 c.permalink, 173 i.name as imgname 158 174 '; 159 160 161 162 163 175 176 $sql['from'] = ' 177 FROM '.CATEGORIES_TABLE.' c 178 JOIN '.IMAGE_CATEGORY_TABLE.' ic ON ic.category_id = c.id 179 JOIN '.IMAGES_TABLE.' i ON i.id = ic.image_id 164 180 '; 165 166 $sql['where'] = ' 167 WHERE i.id IN ('.implode(',', $_SESSION['mrp_random_pics']).') 168 AND i.level <= '.$user['level'].' 169 '; 170 171 if($user['forbidden_categories']!="") 172 { 173 $sql['where'].=" AND c.id NOT IN (".$user['forbidden_categories'].") "; 174 } 181 182 $sql['where'] = 'WHERE i.level<='.$user['level']; 183 184 if($user['forbidden_categories']!="") 185 $sql['where'].=" AND c.id NOT IN (".$user['forbidden_categories'].") "; 186 187 if ($conf['MRP']['apply_to_albums'] == "all") 188 $sql['where'].= " AND i.id IN (".implode(',', $_SESSION['mrp_random_pics']).")"; 189 else 190 $sql['where'] .= " AND c.menurandomphoto_active='true' "; 191 175 192 /* 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 switch($this->config['amm_randompicture_selectMode']) 194 { 195 case 'f': 196 $sql['from'].=", ".USER_INFOS_TABLE." ui 197 LEFT JOIN ".FAVORITES_TABLE." f ON ui.user_id=f.user_id "; 198 $sql['where'].=" AND ui.status='webmaster' 199 AND f.image_id = i.id "; 200 break; 201 case 'c': 202 $sql['where'].="AND ("; 203 foreach($this->config['amm_randompicture_selectCat'] as $key => $val) 204 { 205 $sql['where'].=($key==0?'':' OR ')." FIND_IN_SET($val, c.uppercats) "; 206 } 207 $sql['where'].=") "; 208 break; 209 } 193 210 */ 194 $sql = $sql['select'].$sql['from'].$sql['where']." ORDER BY RAND() LIMIT $num;"; 195 196 $result = pwg_query($sql); 197 if($result) 198 { 199 if ($conf['MRP']['square']) 200 { 201 $height = $conf['MRP']['height']; 202 if($height == 0) 203 $derivative_params = ImageStdParams::get_by_type(IMG_SQUARE); 204 else 205 $derivative_params = ImageStdParams::get_custom($height, $height, 1, $height, $height); 206 } 207 else 208 { 209 $derivative_params = IMG_THUMB; 210 } 211 212 while($row=pwg_db_fetch_assoc($result)) 213 { 214 $row['section']='categories'; 215 $row['category']=array( 216 'id' => $row['catid'], 217 'name' => $row['name'], 218 'permalink' => $row['permalink'] 219 ); 220 221 $row['link']=make_picture_url($row); 222 $infos = array('id'=>$row['image_id'], 'path'=>$row['path']); 223 $row['thumb']=DerivativeImage::url($derivative_params, $infos); 224 225 $returned[]=$row; 226 } 227 } 228 229 return($returned); 230 } 211 $sql = $sql['select'].$sql['from'].$sql['where']." ORDER BY RAND() LIMIT $num;"; 212 213 $result = pwg_query($sql); 214 if($result) 215 { 216 if ($conf['MRP']['square']) 217 { 218 $height = $conf['MRP']['height']; 219 if($height == 0) 220 $derivative_params = ImageStdParams::get_by_type(IMG_SQUARE); 221 else 222 $derivative_params = ImageStdParams::get_custom($height, $height, 1, $height, $height); 223 } 224 else 225 { 226 $derivative_params = IMG_THUMB; 227 } 228 229 while($row=pwg_db_fetch_assoc($result)) 230 { 231 $row['section']='categories'; 232 $row['category']=array( 233 'id' => $row['catid'], 234 'name' => $row['name'], 235 'permalink' => $row['permalink'] 236 ); 237 238 $row['link']=make_picture_url($row); 239 $infos = array('id'=>$row['image_id'], 'path'=>$row['path']); 240 $row['thumb']=DerivativeImage::url($derivative_params, $infos); 241 242 $returned[]=$row; 243 } 244 } 245 246 if (count($returned)<1) 247 $page['errors'][] = l10n('No pictures for MenuRandomPhoto found.'); 248 249 return($returned); 250 } 231 251 232 252 function MRP_admin_menu($menu) 233 253 { 234 235 236 237 238 239 240 } 254 $menu[] = array( 255 'NAME' => 'Menu Random Photo', 256 'URL' => MRP_ADMIN, 257 ); 258 259 return $menu; 260 } -
extensions/MenuRandomPhoto/maintain.inc.php
r30050 r31852 5 5 class MenuRandomPhoto_maintain extends PluginMaintain 6 6 { 7 private $installed = false; 7 private $installed = false; 8 9 private $default_conf = array( 10 'height' => 150, 11 'square' => true, 12 'randompicture_preload' => 25, // number preloaded random pictures 13 'title' => 'A random photo', 14 'delay' => 4000, 15 'apply_to_albums' => 'all', 16 ); 17 18 function __construct($plugin_id) 19 { 20 parent::__construct($plugin_id); 21 } 22 23 function install($plugin_version, &$errors=array()) 24 { 25 global $conf; 26 27 if (empty($conf['MRP'])) 28 { 29 $conf['MRP'] = serialize($this->default_conf); 30 conf_update_param('MRP', $conf['MRP']); 31 } 32 else 33 { 34 $new_conf = is_string($conf['MRP']) ? unserialize($conf['MRP']) : $conf['MRP']; 35 36 $conf['MRP'] = serialize($new_conf); 37 conf_update_param('MRP', $conf['MRP']); 38 } 8 39 9 private $default_conf = array( 10 'height' => 150, 11 'square' => true, 12 'randompicture_preload' => 25, // number preloaded random pictures 13 'title' => 'A random photo', 14 'delay' => 4000, 15 ); 16 17 function __construct($plugin_id) 18 { 19 parent::__construct($plugin_id); 20 } 21 22 function install($plugin_version, &$errors=array()) 23 { 24 global $conf; 25 26 if (empty($conf['MRP'])) 27 { 28 $conf['MRP'] = serialize($this->default_conf); 29 conf_update_param('MRP', $conf['MRP']); 30 } 31 else 32 { 33 $new_conf = is_string($conf['MRP']) ? unserialize($conf['MRP']) : $conf['MRP']; 34 35 $conf['MRP'] = serialize($new_conf); 36 conf_update_param('MRP', $conf['MRP']); 37 } 38 39 $this->installed = true; 40 } 41 42 function activate($plugin_version, &$errors=array()) 43 { 44 if (!$this->installed) 45 { 46 $this->install($plugin_version, $errors); 47 } 48 } 49 50 function deactivate() 51 { 52 } 53 54 function uninstall() 55 { 56 conf_delete_param('MRP'); 57 } 40 // add a new column to existing CATEGORIES table, if it doesn't already exist 41 $result = pwg_query('SHOW COLUMNS FROM `'.CATEGORIES_TABLE.'` LIKE "menurandomphoto_active";'); 42 if (!pwg_db_num_rows($result)) 43 { 44 pwg_query('ALTER TABLE `'.CATEGORIES_TABLE.'` ADD `menurandomphoto_active` enum(\'true\', \'false\') default \'false\';'); 45 } 46 47 $this->installed = true; 48 } 49 50 function activate($plugin_version, &$errors=array()) 51 { 52 if (!$this->installed) 53 { 54 $this->install($plugin_version, $errors); 55 } 56 } 57 58 function deactivate() 59 { 60 } 61 62 function uninstall() 63 { 64 conf_delete_param('MRP'); 65 // delete field 66 pwg_query('ALTER TABLE `'. CATEGORIES_TABLE .'` DROP COLUMN `menurandomphoto_active`;'); 67 } 58 68 } 59 69 -
extensions/MenuRandomPhoto/template/admin.tpl
r31792 r31852 1 {combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'} 2 {combine_css path="themes/default/js/plugins/chosen.css"} 3 4 {footer_script}{literal} 5 jQuery(document).ready(function() { 6 jQuery(".chzn-select").chosen(); 7 8 function checkStatusOptions() { 9 if (jQuery("input[name=apply_to_albums]:checked").val() == "list") { 10 jQuery("#albumList").show(); 11 } 12 else { 13 jQuery("#albumList").hide(); 14 } 15 } 16 17 checkStatusOptions(); 18 19 jQuery("input[name=apply_to_albums]").change(function() { 20 checkStatusOptions(); 21 }); 22 }); 23 {/literal}{/footer_script} 24 1 25 <div class="titrePage"> 2 26 <h2>Menu Random Photo</h2> … … 41 65 </fieldset> 42 66 67 <fieldset> 68 <legend>{'Which albums to use'|translate}</legend> 69 <p> 70 <label><input type="radio" name="apply_to_albums" value="all"{if $MRP.apply_to_albums eq 'all'} checked="checked"{/if}> <strong>{'all albums'|translate}</strong></label> 71 <label><input type="radio" name="apply_to_albums" value="list"{if $MRP.apply_to_albums eq 'list'} checked="checked"{/if}> <strong>{'a list of albums'|translate}</strong></label> 72 </p> 73 <p id="albumList"> 74 <select data-placeholder="{'Select albums...'|translate}" class="chzn-select" multiple style="width:700px;" name="albums[]"> 75 {html_options options=$album_options selected=$album_options_selected} 76 </select> 77 <br> 78 {'Note: Only the selected albums/categories will be shown. Sub-categories must be selected if they are to be used!'|translate} 79 </p> 80 </fieldset> 81 43 82 <p class="formButtons"> 44 83 <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
Note: See TracChangeset
for help on using the changeset viewer.