- Timestamp:
- Jun 11, 2012, 10:10:56 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Subscribe_to_comments/include/functions.inc.php
r12702 r15641 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 3 4 include_once(PHPWG_ROOT_PATH .'include/functions_tag.inc.php');4 include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 5 5 6 6 /** 7 7 * Send comment to subscribers 8 * @param array comm8 * @param: array comment (author, content, image_id|category_id) 9 9 */ 10 10 function send_comment_to_subscribers($comm) 11 11 { 12 global $conf, $page, $user;13 14 12 if ( empty($comm) or !is_array($comm) ) 15 13 { 16 trigger_error('send_comment_to_subscribers: undefinided comm', E_USER_WARNING); 17 return false; 18 } 19 20 $type= isset($comm['category_id']) ? 'category' : 'image'; 14 trigger_error('send_comment_to_subscribers: undefineded comm', E_USER_WARNING); 15 return false; 16 } 17 18 global $conf, $page, $user, $template; 19 20 // create search clauses 21 $where_clauses = array(); 22 if (isset($comm['image_id'])) 23 { 24 $element_id = $comm['image_id']; 25 $element_type = 'image'; 26 27 array_push($where_clauses, 'type = "image" AND element_id = '.$element_id.''); 28 if (!empty($page['category']['id'])) array_push($where_clauses, 'type = "album-images" AND element_id = '.$page['category']['id'].''); 29 array_push($where_clauses, 'type = "all-images"'); 30 } 31 else if (isset($comm['category_id'])) 32 { 33 $element_id = $comm['category_id']; 34 $element_type = 'category'; 35 36 array_push($where_clauses, 'type = "album" AND element_id = '.$element_id.''); 37 array_push($where_clauses, 'type = "all-albums"'); 38 } 39 else 40 { 41 return; 42 } 21 43 22 44 // exclude current user 23 45 $exclude = null; 24 if (!empty($_POST['stc_mail'])) $exclude = pwg_db_real_escape_string($_POST['stc_mail']); 25 else if (!is_a_guest()) $exclude = $user['email']; 26 27 // get subscribers emails 46 if (!empty($_POST['stc_mail'])) 47 { 48 $exclude = pwg_db_real_escape_string($_POST['stc_mail']); 49 } 50 else if (!is_a_guest()) 51 { 52 $exclude = $user['email']; 53 } 54 55 // get subscribers datas 28 56 $query = ' 29 SELECT 30 email 57 SELECT 58 id, 59 email, 60 language 31 61 FROM '.SUBSCRIBE_TO_TABLE.' 32 WHERE 33 '.$type.'_id = '.$comm[$type.'_id'].' 62 WHERE ( 63 ('.implode(")\n OR (", $where_clauses).') 64 ) 34 65 AND validated = true 35 66 AND email != "'.$exclude.'" 36 67 '; 37 $ emails = array_from_query($query, 'email');68 $subscriptions = hash_from_query($query, 'email'); 38 69 39 70 set_make_full_url(); 40 if ($type == 'image') 71 72 // get element infos 73 if ($element_type == 'image') 41 74 { 42 75 $element = get_picture_infos($comm['image_id']); 43 76 } 44 else if ($type == 'category')77 else 45 78 { 46 79 $element = get_category_infos($comm['category_id']); 47 80 } 48 81 49 // get author name 50 if ($comm['author'] == 'guest') 51 { 52 $comm['author'] = l10n('guest'); 53 } 82 // format comment 83 if ($comm['author'] == 'guest') $comm['author'] = l10n('guest'); 84 $comm['author'] = trigger_event('render_comment_author', $comm['author']); 85 $comm['content'] = trigger_event('render_comment_content', $comm['content']); 54 86 55 87 // mail content 56 $mail_args = array( 57 'subject' => '['.strip_tags($conf['gallery_title']).'] Re:'.$element['name'], 58 'content_format' => 'text/html', 59 ); 60 61 $generic_content = ' 62 <a href="'.$element['url'].'"><img src="'.$element['thumbnail'].'" alt="'.$element['name'].'"></a> 63 <br> 64 <b>.'.trigger_event('render_comment_author', $comm['author']).'</b> wrote : 65 66 <blockquote>'.trigger_event('render_comment_content', $comm['content']).'</blockquote> 67 68 <a href="'.$element['url'].'#comment-'.$comm['id'].'">Link to comment</a> 69 <br><br> 70 ================================ 71 <br><br>'; 72 73 foreach ($emails as $email) 74 { 75 $mail_args['content'] = $generic_content.' 76 <a href="'.make_stc_url('unsubscribe-'.$type, $email, $element['id']).'">Stop receiving notifications</a><br> 77 <a href="'.make_stc_url('manage', $email).'">Manage my subscribtions</a>'; 78 pwg_mail($email, $mail_args); 79 } 80 88 $subject = '['.strip_tags($conf['gallery_title']).'] Re:'.$element['name']; 89 90 $template->set_filename('stc_mail', dirname(__FILE__).'/../template/mail/notification.tpl'); 91 92 foreach ($subscriptions as $row) 93 { 94 // get subscriber id 95 if ( ($uid = get_userid_by_email($row['email'])) !== false ) 96 { 97 $row['user_id'] = $uid; 98 } 99 else 100 { 101 $row['user_id'] = $conf['guest_id']; 102 } 103 104 // check permissions 105 if (!user_can_view_element($row['user_id'], $element_id, $element_type)) 106 { 107 continue; 108 } 109 110 // send mail 111 switch_lang_to($row['language']); 112 load_language('plugin.lang', SUBSCRIBE_TO_PATH); 113 114 $comm['caption'] = sprintf('<b>%s</b> wrote on <i>%s</i>', $comm['author'], format_date(date('Y-d-m H:i:s'))); 115 116 $template->assign('STC', array( 117 'element' => $element, 118 'comment' => $comm, 119 'UNSUB_URL' => make_stc_url('unsubscribe', $row['email'], $row['id']), 120 'MANAGE_URL' => make_stc_url('manage', $row['email']), 121 'GALLERY_TITLE' => $conf['gallery_title'], 122 )); 123 124 $content = $template->parse('stc_mail', true); 125 126 stc_send_mail($row['email'], $content, $subject); 127 switch_lang_back(); 128 } 129 130 load_language('plugin.lang', SUBSCRIBE_TO_PATH); 81 131 unset_make_full_url(); 82 132 } … … 85 135 /** 86 136 * add an email to subscribers list 87 * @param int (image|category)_id 88 * @param string email 89 * @param string type (image|category) 90 */ 91 function subscribe_to_comments($element_id, $email, $type='image') 92 { 137 * @param: string email 138 * @param: string type (image|album-images|all-images|album|all-albums) 139 * @param: int element_id 140 * @return: bool 141 */ 142 function subscribe_to_comments($email, $type, $element_id='NULL') 143 { 144 if (empty($type)) 145 { 146 trigger_error('subscribe_to_comment: missing type', E_USER_WARNING); 147 return false; 148 } 149 150 if ( !in_array($type, array('all-images','all-albums')) and $element_id == 'NULL' ) 151 { 152 trigger_error('subscribe_to_comment: missing element_id', E_USER_WARNING); 153 return false; 154 } 155 93 156 global $page, $conf, $user, $template, $picture; 94 95 if ( empty($element_id) or empty($type) )96 {97 trigger_error('subscribe_to_comment: missing element_id and/or type', E_USER_WARNING);98 return false;99 }100 157 101 158 // check email 102 159 if ( ( is_a_guest() or empty($user['email']) ) and empty($email) ) 103 160 { 104 return false; 105 } 106 else if (!is_a_guest()) 161 array_push($page['errors'], l10n('Invalid email adress, your are not subscribed to comments.')); 162 return false; 163 } 164 else if ( !is_a_guest() and empty($email) ) 107 165 { 108 166 $email = $user['email']; 109 167 } 110 168 111 // don't care if already registered169 // search if already registered (can use ODKU because we want to get the id of inserted OR updated row) 112 170 $query = ' 171 SELECT id 172 FROM '.SUBSCRIBE_TO_TABLE.' 173 WHERE 174 type = "'.$type.'" 175 AND element_id = '.$element_id.' 176 AND email = "'.pwg_db_real_escape_string($email).'" 177 ;'; 178 $result = pwg_query($query); 179 180 if (pwg_db_num_rows($result)) 181 { 182 list($inserted_id) = pwg_db_fetch_row($result); 183 } 184 else 185 { 186 $query = ' 113 187 INSERT INTO '.SUBSCRIBE_TO_TABLE.'( 188 type, 189 element_id, 190 language, 114 191 email, 115 '.$type.'_id,116 192 registration_date, 117 193 validated 118 194 ) 119 195 VALUES( 196 "'.$type.'", 197 '.$element_id.', 198 "'.$user['language'].'", 120 199 "'.pwg_db_real_escape_string($email).'", 121 '.$element_id.',122 200 NOW(), 123 201 "'.(is_a_guest() ? "false" : "true").'" 124 202 ) 125 ON DUPLICATE KEY UPDATE126 registration_date = IF(validated="true", registration_date, NOW()),127 validated = IF(validated="true", validated, "'.(is_a_guest() ? "false" : "true").'")128 203 ;'; 129 pwg_query($query); 204 pwg_query($query); 205 206 $inserted_id = pwg_db_insert_id(); 207 } 208 209 // notify admins 210 if ( pwg_db_changes(null) != 0 and $conf['Subscribe_to_Comments']['notify_admin_on_subscribe'] ) 211 { 212 stc_mail_notification_admins($email, $type, $element_id, $inserted_id); 213 } 130 214 131 215 // send validation mail 132 216 if ( is_a_guest() and pwg_db_changes(null) != 0 ) 133 217 { 134 $element_name = ($type == 'image') ? $picture['current']['name'] : $page['category']['name']; 135 136 $mail_args = array( 137 'subject' => '['.strip_tags($conf['gallery_title']).'] Please confirm your subscribtion to comments', 138 'content_format' => 'text/html', 139 ); 218 set_make_full_url(); 219 220 $template->set_filename('stc_mail', dirname(__FILE__).'/../template/mail/confirm.tpl'); 221 222 $subject = '['.strip_tags($conf['gallery_title']).'] '.l10n('Confirm your subscribtion to comments'); 140 223 141 $mail_args['content'] = ' 142 You requested to subscribe by email to comments on <b>'.$element_name.'</b>.<br> 143 <br> 144 We care about your inbox, so we want to confirm this request. Please click the confirm link to activate the subscription.<br> 145 <br> 146 <a href="'.make_stc_url('validate-'.$type, $email, $element_id).'">Confirm subscription</a><br> 147 <br> 148 If you did not request this action please disregard this message. 149 '; 150 151 pwg_mail($email, $mail_args); 152 return 'confirm_mail'; 224 switch ($type) 225 { 226 case 'image': 227 $element = get_picture_infos($element_id); 228 $element['on'] = sprintf(l10n('the picture <a href="%s">%s</a>'), $element['url'], $element['name']); 229 break; 230 case 'album-images': 231 $element = get_category_infos($element_id); 232 $element['on'] = sprintf(l10n('all pictures of the album <a href="%s">%s</a>'), $element['url'], $element['name']); 233 break; 234 case 'all-images': 235 $element['thumbnail'] = null; 236 $element['on'] = l10n('all pictures of the gallery'); 237 break; 238 case 'album': 239 $element = get_category_infos($element_id); 240 $element['on'] = sprintf(l10n('the album <a href="%s">%s</a>'), $element['url'], $element['name']); 241 break; 242 case 'all-albums': 243 $element['thumbnail'] = null; 244 $element['on'] = l10n('all albums of the gallery'); 245 break; 246 } 247 248 $template->assign('STC', array( 249 'element' => $element, 250 'VALIDATE_URL' => make_stc_url('validate', $email, $inserted_id), 251 'MANAGE_URL' => make_stc_url('manage', $email), 252 'GALLERY_TITLE' => $conf['gallery_title'], 253 )); 254 255 $content = $template->parse('stc_mail', true); 256 257 stc_send_mail($email, $content, $subject); 258 unset_make_full_url(); 259 260 array_push($page['infos'], l10n('Please check your email inbox to confirm your subscription.')); 261 return true; 153 262 } 154 263 // just display confirmation message 155 264 else if (pwg_db_changes(null) != 0) 156 265 { 266 array_push($page['infos'], l10n('You have been added to the list of subscribers.')); 157 267 return true; 158 268 } 269 270 return false; 159 271 } 160 272 … … 162 274 /** 163 275 * remove an email from subscribers list 164 * @param int (image|category)_id 165 * @param string email 166 * @param string type (image|category) 167 */ 168 function un_subscribe_to_comments($element_id, $email, $type='image') 169 { 276 * @param: string email 277 * @param: int subscription id 278 * @return: bool 279 */ 280 function un_subscribe_to_comments($email, $id) 281 { 282 if (empty($id)) 283 { 284 trigger_error('un_subscribe_to_comment: missing id', E_USER_WARNING); 285 return false; 286 } 287 170 288 global $template, $user; 171 172 if ( empty($element_id) or empty($type) )173 {174 trigger_error('un_subscribe_to_comment: missing element_id and/or type', E_USER_WARNING);175 return false;176 }177 289 178 290 // check email … … 181 293 return false; 182 294 } 183 else if ( !is_a_guest())295 else if ( !is_a_guest() and empty($email) ) 184 296 { 185 297 $email = $user['email']; … … 187 299 188 300 // delete subscription 189 switch ($type) 190 { 191 case 'image' : 192 case 'category' : 193 $where_clause = $type.'_id = '.pwg_db_real_escape_string($element_id); 194 case 'all' : 195 { 196 $query = ' 301 $query = ' 197 302 DELETE FROM '.SUBSCRIBE_TO_TABLE.' 198 303 WHERE 199 304 email = "'.pwg_db_real_escape_string($email).'" 200 '.(!empty($where_clause) ? 'AND '.$where_clause : null).'305 AND id = "'.pwg_db_real_escape_string($id).'" 201 306 ;'; 202 307 pwg_query($query); 203 308 204 return true; 205 break; 206 } 207 } 208 309 if (pwg_db_changes(null) != 0) return true; 209 310 return false; 210 311 } … … 213 314 /** 214 315 * validate a subscription 215 * @param int (image|category)_id 216 * @param string email 217 * @param string type (image|category) 218 */ 219 function validate_subscriptions($element_id, $email, $type='image') 220 { 221 if ( empty($element_id) or empty($email) or empty($type) ) 222 { 223 trigger_error('validate_subscriptions: missing element_id and/or email and/or type', E_USER_WARNING); 224 return false; 225 } 226 227 switch ($type) 228 { 229 case 'image' : 230 case 'category': 231 $where_clause = $type.'_id = '.pwg_db_real_escape_string($element_id); 232 case 'all' : 233 { 234 $query = ' 316 * @param: string email 317 * @param: int subscription id 318 * @return: bool 319 */ 320 function validate_subscriptions($email, $id) 321 { 322 if (empty($email)) 323 { 324 trigger_error('validate_subscriptions: missing email', E_USER_WARNING); 325 return false; 326 } 327 328 if (empty($id)) 329 { 330 trigger_error('validate_subscriptions: missing id', E_USER_WARNING); 331 return false; 332 } 333 334 $query = ' 235 335 UPDATE '.SUBSCRIBE_TO_TABLE.' 236 336 SET validated = "true" 237 337 WHERE 238 338 email = "'.pwg_db_real_escape_string($email).'" 239 '.(!empty($where_clause) ? 'AND '.$where_clause : null).'339 AND id = '.pwg_db_real_escape_string($id).' 240 340 ;'; 241 341 pwg_query($query); 242 342 243 if (pwg_db_changes(null) != 0) return true; 343 if (pwg_db_changes(null) != 0) return true; 344 return false; 345 } 346 347 348 /** 349 * send notification to admins 350 * @param: string email 351 * @param: string type (image|album-images|all-images|album|all-albums) 352 * @param: int element_id 353 * @param: int subscription id 354 */ 355 function stc_mail_notification_admins($email, $type, $element_id, $inserted_id) 356 { 357 global $user, $conf, $template; 358 359 $admins = get_admins_email(); 360 if (empty($admins)) return; 361 362 set_make_full_url(); 363 switch_lang_to(get_default_language()); 364 load_language('plugin.lang', SUBSCRIBE_TO_PATH); 365 366 $template->set_filename('stc_mail', dirname(__FILE__).'/../template/mail/admin.tpl'); 367 368 $subject = '['.strip_tags($conf['gallery_title']).'] '.sprintf(l10n('%s has subscribed to comments on'), is_a_guest()?$email:$user['username']); 369 370 switch ($type) 371 { 372 case 'image': 373 $element = get_picture_infos($element_id, false); 374 $element['on'] = sprintf(l10n('the picture <a href="%s">%s</a>'), $element['url'], $element['name']); 244 375 break; 245 } 246 } 247 248 return false; 376 case 'album-images': 377 $element = get_category_infos($element_id, false); 378 $element['on'] = sprintf(l10n('all pictures of the album <a href="%s">%s</a>'), $element['url'], $element['name']); 379 break; 380 case 'all-images': 381 $element['on'] = l10n('all pictures of the gallery'); 382 break; 383 case 'album': 384 $element = get_category_infos($element_id, false); 385 $element['on'] = sprintf(l10n('the album <a href="%s">%s</a>'), $element['url'], $element['name']); 386 break; 387 case 'all-albums': 388 $element['on'] = l10n('all albums of the gallery'); 389 break; 390 } 391 392 $technical_infos[] = sprintf(l10n('Connected user: %s'), stripslashes($user['username'])); 393 $technical_infos[] = sprintf(l10n('IP: %s'), $_SERVER['REMOTE_ADDR']); 394 $technical_infos[] = sprintf(l10n('Browser: %s'), $_SERVER['HTTP_USER_AGENT']); 395 396 $template->assign('STC', array( 397 'ELEMENT' => $element['on'], 398 'USER' => sprintf(l10n('%s has subscribed to comments on'), is_a_guest() ? '<b>'.$email.'</b>' : '<b>'.$user['username'].'</b> ('.$email.')'), 399 'GALLERY_TITLE' => $conf['gallery_title'], 400 'TECHNICAL' => implode('<br>', $technical_infos), 401 )); 402 403 $content = $template->parse('stc_mail', true); 404 405 stc_send_mail($admins, $content, $subject); 406 407 unset_make_full_url(); 408 switch_lang_back(); 409 load_language('plugin.lang', SUBSCRIBE_TO_PATH); 249 410 } 250 411 … … 252 413 /** 253 414 * create absolute url to subscriptions section 254 * @param string action 255 * @param string email 256 * @return string 257 */ 258 function make_stc_url($action, $email) 415 * @param: string action 416 * @param: string email 417 * @param: int optional 418 * @return: string 419 */ 420 function make_stc_url($action, $email, $id=null) 259 421 { 260 422 if ( empty($action) or empty($email) ) … … 272 434 ); 273 435 274 if ( func_num_args() > 2)275 { 276 $url_params['id'] = func_get_arg(2);436 if (!empty($id)) 437 { 438 $url_params['id'] = $id; 277 439 } 278 440 … … 293 455 294 456 /** 295 * get name and url of a picture 296 * @param int image_id 297 * @return array 298 */ 299 function get_picture_infos($image_id, $absolute=false) 300 { 301 global $page; 302 457 * send mail with STC style 458 * @param: string to 459 * @param: string content 460 * @param: string subject 461 * @return: bool 462 */ 463 function stc_send_mail($to, $content, $subject) 464 { 465 global $conf, $conf_mail, $page, $template; 466 467 // inputs 468 if (empty($to)) 469 { 470 return false; 471 } 472 473 if (empty($content)) 474 { 475 return false; 476 } 477 478 if (empty($subject)) 479 { 480 $subject = 'Piwigo'; 481 } 482 else 483 { 484 $subject = trim(preg_replace('#[\n\r]+#s', '', $subject)); 485 $subject = encode_mime_header($subject); 486 } 487 488 if (!isset($conf_mail)) 489 { 490 $conf_mail = get_mail_configuration(); 491 } 492 493 $args['from'] = $conf_mail['formated_email_webmaster']; 494 495 set_make_full_url(); 496 497 // hearders 498 $headers = 'From: '.$args['from']."\n"; 499 $headers.= 'Content-Type: text/html; charset="'.get_pwg_charset().'";'."\n"; 500 $headers.= 'Content-Transfer-Encoding: 8bit'."\n"; 501 $headers.= 'MIME-Version: 1.0'."\n"; 502 $headers.= 'X-Mailer: Piwigo Mailer'."\n"; 503 504 // template 505 $template->set_filenames(array( 506 'stc_mail_header' => dirname(__FILE__).'/../template/mail/header.tpl', 507 'stc_mail_footer' => dirname(__FILE__).'/../template/mail/footer.tpl', 508 )); 509 $stc_mail_css = file_get_contents(dirname(__FILE__).'/../template/mail/style.css'); 510 511 $template->assign(array( 512 'GALLERY_URL' => get_gallery_home_url(), 513 'PHPWG_URL' => PHPWG_URL, 514 'STC_MAIL_CSS' => str_replace("\n", null, $stc_mail_css), 515 )); 516 517 $content = $template->parse('stc_mail_header', true) . $content . $template->parse('stc_mail_footer', true); 518 $content = wordwrap($content, 70, "\n", true); 519 520 unset_make_full_url(); 521 522 // send mail 523 return 524 trigger_event('send_mail', 525 false, /* Result */ 526 trigger_event('send_mail_to', get_strict_email_list($to)), 527 trigger_event('send_mail_subject', $subject), 528 trigger_event('send_mail_content', $content), 529 trigger_event('send_mail_headers', $headers), 530 $args 531 ); 532 } 533 534 535 /** 536 * get name, url and thumbnail of a picture 537 * @param: int image_id 538 * @param: bool return thumbnail 539 * @return: array (id, name, url, thumbnail) 540 */ 541 function get_picture_infos($image_id, $with_thumb=true) 542 { 303 543 $query = ' 304 544 SELECT 305 545 id, 546 file, 306 547 name, 307 file, 308 path, 309 tn_ext 548 path 310 549 FROM '.IMAGES_TABLE.' 311 550 WHERE id = '.$image_id.' … … 319 558 320 559 $url_params = array('image_id' => $element['id']); 321 if ( !empty($page['category']) and !$absolute )322 {323 $url_params['section'] = 'categories';324 $url_params['category'] = $page['category'];325 }326 560 $element['url'] = make_picture_url($url_params); 327 561 328 $element['thumbnail'] = get_thumbnail_url($element); 562 if ($with_thumb) 563 { 564 $element['thumbnail'] = DerivativeImage::thumb_url($element); 565 } 329 566 330 567 return $element; … … 332 569 333 570 /** 334 * get name and url of a category 335 * @param int cat_id 336 * @return array 337 */ 338 function get_category_infos($cat_id) 571 * get name, url and thumbnail of a category 572 * @param: int cat_id 573 * @param: int return thumbnail 574 * @return: array (id, name, url, thumbnail) 575 */ 576 function get_category_infos($cat_id, $with_thumb=true) 339 577 { 340 578 global $conf; … … 346 584 cat.permalink, 347 585 img.id AS image_id, 348 img.path, 349 img.tn_ext 586 img.path 350 587 FROM '.CATEGORIES_TABLE.' AS cat 351 588 LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc … … 356 593 ;'; 357 594 $element = pwg_db_fetch_assoc(pwg_query($query)); 358 // we use guest_id for user_cache beacause we don't know the status of recipient 359 360 $url_params['section'] = 'categories'; 361 $url_params['category'] = $element; 362 $element['url'] = make_index_url($url_params); 363 364 $element['thumbnail'] = get_thumbnail_url(array( 365 'id' => $element['image_id'], 366 'path' => $element['path'], 367 'tn_ext' => $element['tn_ext'], 595 // we use guest_id for user_cache because we don't know the status of recipient 596 597 $element['url'] = make_index_url(array( 598 'section'=>'categories', 599 'category'=>$element, 368 600 )); 369 601 602 if ($with_thumb) 603 { 604 $element['thumbnail'] = DerivativeImage::thumb_url(array( 605 'id'=>$element['image_id'], 606 'path'=>$element['path'], 607 )); 608 } 609 370 610 return $element; 611 } 612 613 /** 614 * get list of admins email 615 * @return: string 616 */ 617 function get_admins_email() 618 { 619 global $conf, $user; 620 621 $admins = array(); 622 623 $query = ' 624 SELECT 625 u.'.$conf['user_fields']['username'].' AS username, 626 u.'.$conf['user_fields']['email'].' AS email 627 FROM '.USERS_TABLE.' AS u 628 JOIN '.USER_INFOS_TABLE.' AS i 629 ON i.user_id = u.'.$conf['user_fields']['id'].' 630 WHERE i.status IN ("webmaster", "admin") 631 AND '.$conf['user_fields']['email'].' IS NOT NULL 632 AND i.user_id != '.$user['id'].' 633 ORDER BY username 634 ;'; 635 636 $datas = pwg_query($query); 637 if (!empty($datas)) 638 { 639 while ($admin = pwg_db_fetch_assoc($datas)) 640 { 641 array_push($admins, format_email($admin['username'], $admin['email'])); 642 } 643 } 644 645 return implode(',', $admins); 646 } 647 648 649 /** 650 * check if the given user can view the category/image 651 * @param: int user_id 652 * @param: int element_id 653 * @param: string type (image|category) 654 * @return: bool 655 */ 656 function user_can_view_element($user_id, $element_id, $type) 657 { 658 global $conf; 659 660 $old_conf = $conf['external_authentification']; 661 $conf['external_authentification'] = false; 662 $user = getuserdata($user_id, true); 663 $conf['external_authentification'] = $old_conf; 664 665 if ($type == 'image') 666 { 667 return !in_array($element_id, explode(',', $user['image_access_list'])); 668 } 669 else if ($type == 'category') 670 { 671 return !in_array($element_id, explode(',', $user['forbidden_categories'])); 672 } 673 else 674 { 675 return false; 676 } 371 677 } 372 678 … … 375 681 * crypt a string using mcrypt extension or 376 682 * http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php/802957#802957 377 * @param string value to crypt378 * @param string key379 * @return string683 * @param: string value to crypt 684 * @param: string key 685 * @return: string 380 686 */ 381 687 function crypt_value($value, $key) … … 405 711 /** 406 712 * decrypt a string crypted with previous function 407 * @param string value to decrypt408 * @param string key409 * @return string713 * @param: string value to decrypt 714 * @param: string key 715 * @return: string 410 716 */ 411 717 function decrypt_value($value, $key) … … 436 742 /** 437 743 * variant of base64 functions usable into url 438 * http:// fr.php.net/manual/fr/function.base64-encode.php#103849744 * http://php.net/manual/en/function.base64-encode.php#103849 439 745 */ 440 746 function base64url_encode($data)
Note: See TracChangeset
for help on using the changeset viewer.