Changeset 23177 for extensions/Back2Front/include/Back2Front.php
- Timestamp:
- Jun 13, 2013, 2:01:34 PM (11 years ago)
- Location:
- extensions/Back2Front/include
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
extensions/Back2Front/include/Back2Front.php
r23167 r23177 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 3 4 include_once(B2F_PATH.' functions.inc.php');4 include_once(B2F_PATH.'include/functions.inc.php'); 5 5 6 6 /* 7 7 * Add verso link on picture page 8 8 */ 9 function Back2Front_picture_content($content, $element_info)9 function back2front_picture_content($content, $element_info) 10 10 { 11 11 global $template, $user, $conf; 12 12 13 13 /* search for a verso picture */ 14 $query = "15 16 FROM ".IMAGES_TABLE."as i17 INNER JOIN ".B2F_TABLE."as v18 19 AND v.image_id = ".$element_info['id']."20 ;";14 $query = ' 15 SELECT i.* 16 FROM '.IMAGES_TABLE.' as i 17 INNER JOIN '.B2F_TABLE.' as v 18 ON i.id = v.verso_id 19 AND v.image_id = '.$element_info['id'].' 20 ;'; 21 21 $result = pwg_query($query); 22 22 … … 24 24 { 25 25 $verso = pwg_db_fetch_assoc($result); 26 $conf['back2front'] = explode(',',$conf['back2front']);27 26 $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']); 28 27 … … 42 41 { 43 42 $template->assign('VERSO_U_ADMIN', get_root_url().'admin.php?page=photo-'.$verso['id']); 44 $template->set_filename('B2F_admin_button', dirname(__FILE__).'/template/admin_button.tpl');43 $template->set_filename('B2F_admin_button', realpath(B2F_PATH.'template/admin_button.tpl')); 45 44 $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('B2F_admin_button', true)); 46 45 } 47 46 48 47 /* link name */ 49 $conf['back2front'][4] = unserialize($conf['back2front'][4]); 50 if (!empty($conf['back2front'][4][$user['language']])) 51 { 52 if (strpos($conf['back2front'][4][$user['language']], '|') !== false) 53 { 54 $conf['back2front'][4] = explode('|', $conf['back2front'][4][$user['language']]); 48 if (!empty($conf['back2front']['link_name'][$user['language']])) 49 { 50 if (strpos($conf['back2front']['link_name'][$user['language']], '|') !== false) 51 { 52 $conf['back2front']['link_name'] = explode('|', $conf['back2front']['link_name'][$user['language']]); 55 53 } 56 54 else 57 55 { 58 $conf['back2front'][ 4] = array($conf['back2front'][4][$user['language']], $conf['back2front'][4][$user['language']]);59 } 60 } 61 else if (!empty($conf['back2front'][ 4]['default']))62 { 63 if (strpos($conf['back2front'][ 4]['default'], '|') != false)64 { 65 $conf['back2front'][ 4] = explode('|', $conf['back2front'][4]['default']);56 $conf['back2front']['link_name'] = array_fill(0, 2, $conf['back2front']['link_name'][$user['language']]); 57 } 58 } 59 else if (!empty($conf['back2front']['link_name']['default'])) 60 { 61 if (strpos($conf['back2front']['link_name']['default'], '|') != false) 62 { 63 $conf['back2front']['link_name'] = explode('|', $conf['back2front']['link_name']['default']); 66 64 } 67 65 else 68 66 { 69 $conf['back2front'][ 4] = array($conf['back2front'][4]['default'], $conf['back2front'][4]['default']);67 $conf['back2front']['link_name'] = array_fill(0, 2, $conf['back2front']['link_name']['default']); 70 68 } 71 69 } 72 70 else 73 71 { 74 $conf['back2front'][ 4] = array(l10n('See back'), l10n('See front'));75 } 76 77 if ($conf['back2front'][ 2] == 'fade' and $conf['back2front'][3] =='bottom')78 { 79 $conf['back2front'][ 3] = 'top';72 $conf['back2front']['link_name'] = array(l10n('See back'), l10n('See front')); 73 } 74 75 if ($conf['back2front']['transition'] == 'fade' && $conf['back2front']['position'] == 'bottom') 76 { 77 $conf['back2front']['position'] = 'top'; 80 78 } 81 79 82 80 83 81 /* template & output */ 84 $template->set_filename('B2F_picture_content', dirname(__FILE__).'/template/picture_content.tpl');82 $template->set_filename('B2F_picture_content', realpath(B2F_PATH.'template/picture_content.tpl')); 85 83 $template->assign(array( 86 'b2f_switch_mode' => $conf['back2front'][ 1],87 'b2f_transition' => $conf['back2front'][ 2],88 'b2f_position' => $conf['back2front'][ 3],89 'b2f_see_back' => $conf['back2front'][ 4][0],90 'b2f_see_front' => $conf['back2front'][ 4][1],84 'b2f_switch_mode' => $conf['back2front']['switch_mode'], 85 'b2f_transition' => $conf['back2front']['transition'], 86 'b2f_position' => $conf['back2front']['position'], 87 'b2f_see_back' => $conf['back2front']['link_name'][0], 88 'b2f_see_front' => $conf['back2front']['link_name'][1], 91 89 )); 92 90 93 switch ($conf['back2front'][ 3])91 switch ($conf['back2front']['position']) 94 92 { 95 93 case 'toolbar': … … 97 95 break; 98 96 case 'top': 99 return$template->parse('B2F_picture_content', true)."\n".$content;97 $content = $template->parse('B2F_picture_content', true)."\n".$content; 100 98 break; 101 99 case 'bottom': 102 return$content."\n".$template->parse('B2F_picture_content', true);100 $content = $content."\n".$template->parse('B2F_picture_content', true); 103 101 break; 104 102 } … … 112 110 * Add field on picture modify page 113 111 */ 114 function Back2Front_picture_modify()112 function back2front_picture_modify() 115 113 { 116 114 global $page, $template, $conf; … … 118 116 if ($page['page'] != 'photo') return; 119 117 if (isset($_GET['tab']) && $_GET['tab']!='properties') return; 120 121 122 $conf['back2front'] = explode(',',$conf['back2front']);123 118 124 119 /* SAVE VALUES */ … … 126 121 { 127 122 /* catch all verso and recto ids and original categories */ 128 $query = "SELECT image_id, verso_id, categories 129 FROM ".B2F_TABLE.";"; 130 $rectos = array_from_query($query, 'image_id'); 131 $versos = array_from_query($query, 'verso_id'); 132 $cats = array_from_query($query, 'categories'); 123 $query = 'SELECT * FROM '.B2F_TABLE.';'; 124 $result = pwg_query($query); 125 126 $rectos = $versos = $cats = array(); 127 while ($row = pwg_db_fetch_assoc($result)) 128 { 129 $rectos[] = $row['image_id']; 130 $versos[] = $row['verso_id']; 131 $cats[] = $row['categories']; 132 } 133 133 134 134 if (count($rectos) != 0) … … 140 140 { 141 141 $all_recto_verso = array(0=>0); 142 $verso_cats = array(0=> NULL);142 $verso_cats = array(0=>null); 143 143 } 144 144 unset($rectos, $versos, $cats); … … 150 150 if (!picture_exists($_POST['b2f_front_id'])) 151 151 { 152 array_push( 153 $page['errors'], 154 sprintf( 155 l10n('Unknown id %d for frontside picture'), 156 $_POST['b2f_front_id'] 157 ) 158 ); 152 array_push($page['errors'], sprintf( 153 l10n('Unknown id %d for frontside picture'), 154 $_POST['b2f_front_id'] 155 )); 159 156 } 160 157 /* verso same as recto */ … … 164 161 } 165 162 /* recto has already a verso */ 166 else if (in_array($_POST['b2f_front_id'], array_keys($all_recto_verso)) AND $all_recto_verso[$_POST['b2f_front_id']] != $_GET['image_id']) 167 { 168 $recto_current_verso['id'] = $all_recto_verso[$_POST['b2f_front_id']]; 169 $recto_current_verso['link'] = get_root_url().'admin.php?page=photo-'.$recto_current_verso['id']; 170 array_push( 171 $page['errors'], 172 sprintf( 173 l10n('The picture n°%d has already a backside : %s'), 174 $_POST['b2f_front_id'], 175 '<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>' 176 ) 177 ); 163 else if (in_array($_POST['b2f_front_id'], array_keys($all_recto_verso)) && $all_recto_verso[$_POST['b2f_front_id']] != $_GET['image_id']) 164 { 165 $recto_current_verso['id'] = $all_recto_verso[$_POST['b2f_front_id']]; 166 $recto_current_verso['link'] = get_root_url().'admin.php?page=photo-'.$recto_current_verso['id']; 167 168 array_push($page['errors'], sprintf( 169 l10n('The picture n°%d has already a backside : %s'), 170 $_POST['b2f_front_id'], 171 '<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>' 172 )); 178 173 } 179 174 /* recto is already a verso */ 180 175 else if (in_array($_POST['b2f_front_id'], array_values($all_recto_verso))) 181 176 { 182 $recto_is_verso['id'] = $_POST['b2f_front_id']; 183 $recto_is_verso['link'] = get_root_url().'admin.php?page=picture_modify&image_id='.$recto_is_verso['id']; 184 array_push( 185 $page['errors'], 186 sprintf( 187 l10n('The picture n°%s is already a backside'), 188 '<a href="'.$recto_is_verso['link'].'">'.$recto_is_verso['id'].'</a>' 189 ) 190 ); 177 $recto_is_verso['id'] = $_POST['b2f_front_id']; 178 $recto_is_verso['link'] = get_root_url().'admin.php?page=picture_modify&image_id='.$recto_is_verso['id']; 179 180 array_push($page['errors'], sprintf( 181 l10n('The picture n°%s is already a backside'), 182 '<a href="'.$recto_is_verso['link'].'">'.$recto_is_verso['id'].'</a>' 183 )); 191 184 } 192 185 /* everything is fine */ … … 194 187 { 195 188 // move the verso - if first save 196 if (isset($_POST['b2f_move_verso']) AND (!array_key_exists($_GET['image_id'], $verso_cats) OR $verso_cats[$_GET['image_id']] == NULL))189 if (isset($_POST['b2f_move_verso']) && (!array_key_exists($_GET['image_id'], $verso_cats) || $verso_cats[$_GET['image_id']] == null)) 197 190 { 198 191 // get current categories 199 $query = "SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$_GET['image_id'].";";192 $query = 'SELECT category_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$_GET['image_id'].';'; 200 193 $verso_categories = array_from_query($query, 'category_id'); 201 194 202 pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." 203 WHERE image_id = ".$_GET['image_id'].";"); 204 pwg_query("INSERT INTO ".IMAGE_CATEGORY_TABLE."(image_id, category_id) 205 VALUES(".$_GET['image_id'].", ".$conf['back2front'][0].");"); 195 pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$_GET['image_id'].';'); 196 pwg_query('INSERT INTO '.IMAGE_CATEGORY_TABLE.'(image_id, category_id) VALUES('.$_GET['image_id'].', '.$conf['back2front']['versos_cat'].');'); 206 197 207 198 // random representant for each categories … … 212 203 } 213 204 // restore the verso - if precedently moved 214 else if (!isset($_POST['b2f_move_verso']) AND array_key_exists($_GET['image_id'], $verso_cats) AND $verso_cats[$_GET['image_id']] != NULL)205 else if (!isset($_POST['b2f_move_verso']) && array_key_exists($_GET['image_id'], $verso_cats) && $verso_cats[$_GET['image_id']] != null) 215 206 { 216 207 $item['verso_id'] = $_GET['image_id']; … … 229 220 230 221 // insert or update verso associations 231 pwg_query("INSERT INTO ".B2F_TABLE." 232 VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", '".$verso_categories."') 233 ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].", categories = '".$verso_categories."';"); 234 222 $query = ' 223 INSERT INTO '.B2F_TABLE.' 224 VALUES( 225 '.$_POST['b2f_front_id'].', 226 '.$_GET['image_id'].', 227 "'.$verso_categories.'" 228 ) 229 ON DUPLICATE KEY UPDATE 230 image_id = '.$_POST['b2f_front_id'].', 231 categories = "'.$verso_categories.'" 232 ;'; 233 pwg_query($query); 234 235 235 $template->assign(array( 236 236 'B2F_IS_VERSO' => 'checked="checked"', … … 240 240 $verso['id'] = $_POST['b2f_front_id']; 241 241 $verso['link'] = get_root_url().'admin.php?page=photo-'.$verso['id']; 242 array_push($page['infos'], l10n_args(get_l10n_args('This picture is now the backside of the picture n°%s', '<a href="'.$verso['link'].'">'.$verso['id'].'</a>'))); 242 243 array_push($page['infos'], sprintf( 244 l10n('This picture is now the backside of the picture n°%s'), 245 '<a href="'.$verso['link'].'">'.$verso['id'].'</a>' 246 )); 243 247 } 244 248 } … … 247 251 { 248 252 /* search if it was a verso */ 249 $query = "SELECT categories 250 FROM ".B2F_TABLE." 251 WHERE verso_id = ".$_GET['image_id'].";"; 253 $query = ' 254 SELECT categories 255 FROM '.B2F_TABLE.' 256 WHERE verso_id = '.$_GET['image_id'].' 257 ;'; 252 258 $result = pwg_query($query); 253 259 254 /* it must be restored to its original categories (see criteria on maintain.inc)*/260 /* it must be restored to its original categories */ 255 261 if (pwg_db_num_rows($result)) 256 262 { 257 263 $item['verso_id'] = $_GET['image_id']; 258 264 list($item['categories']) = pwg_db_fetch_row($result); 265 259 266 back2front_restaure_categories($item); 260 261 pwg_query("DELETE FROM ".B2F_TABLE." 262 WHERE verso_id = ".$_GET['image_id'].";"); 263 267 pwg_query('DELETE FROM '.B2F_TABLE.' WHERE verso_id = '.$_GET['image_id'].';'); 264 268 array_push($page['infos'], l10n('This picture is no longer a backside')); 265 269 } … … 273 277 274 278 /* is the picture a verso ? */ 275 $query = "276 277 FROM ".B2F_TABLE."278 WHERE verso_id = ".$_GET['image_id']."279 ;";279 $query = ' 280 SELECT image_id, categories 281 FROM '.B2F_TABLE.' 282 WHERE verso_id = '.$_GET['image_id'].' 283 ;'; 280 284 $result = pwg_query($query); 281 285 … … 283 287 { 284 288 list($recto_id, $cats) = pwg_db_fetch_row($result); 289 285 290 $template->assign(array( 286 291 'B2F_IS_VERSO' => 'checked="checked"', … … 292 297 else 293 298 { 294 $query = "SELECT verso_id 295 FROM ".B2F_TABLE." 296 WHERE image_id = ".$_GET['image_id'].";"; 299 $query = ' 300 SELECT verso_id 301 FROM '.B2F_TABLE.' 302 WHERE image_id = '.$_GET['image_id'].' 303 ;'; 297 304 $result = pwg_query($query); 298 305 … … 309 316 } 310 317 311 $template->set_prefilter('picture_modify', ' Back2front_picture_modify_prefilter');318 $template->set_prefilter('picture_modify', 'back2front_picture_modify_prefilter'); 312 319 } 313 320 314 321 315 function Back2front_picture_modify_prefilter($content, &$smarty)322 function back2front_picture_modify_prefilter($content, &$smarty) 316 323 { 317 324 $search = '</form>'; … … 324 331 * Add mark on thumbnails list 325 332 */ 326 function Back2Front_thumbnails($tpl_thumbnails_var)333 function back2front_thumbnails($tpl_thumbnails_var) 327 334 { 328 335 global $conf, $selection; 329 336 330 $conf['back2front'] = explode(',',$conf['back2front']); 331 if (!$conf['back2front'][5]) return $tpl_thumbnails_var; 337 if (!$conf['back2front']['show_thumbnail']) return $tpl_thumbnails_var; 332 338 if (empty($tpl_thumbnails_var)) return $tpl_thumbnails_var; 333 339 334 340 /* has the pictures a verso ? */ 335 $query = "SELECT image_id 336 FROM ".B2F_TABLE." 337 WHERE image_id IN(".implode(',', $selection).");"; 341 $query = ' 342 SELECT image_id 343 FROM '.B2F_TABLE.' 344 WHERE image_id IN('.implode(',', $selection).') 345 ;'; 338 346 $ids = array_from_query($query, 'image_id'); 339 347
Note: See TracChangeset
for help on using the changeset viewer.