Changeset 20202 for extensions/Piwecard/include/piwecard.class.php
- Timestamp:
- Jan 17, 2013, 12:06:49 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Piwecard/include/piwecard.class.php
r20180 r20202 34 34 } 35 35 36 //Get the default value of a parameter 37 function get_default_config_param($param) { 38 require(PIWECARD_INSTALL_PATH.'default_values.inc.php'); 39 return $ecard_default_values[$param]; 40 } 41 36 42 // Save general configuration to config_database 37 43 function set_config() { … … 80 86 // Get the number of ecard in the database 81 87 function get_nb_ecard() { 82 $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.PIWECARD_TABLE.' ORDER BY date_creation;';88 $query = 'SELECT COUNT(DISTINCT ecard_id) AS nb FROM '.PIWECARD_TABLE.' ORDER BY date_creation;'; 83 89 $result = pwg_query($query); 84 90 … … 92 98 // Get the number of valid ecard in the database 93 99 function get_nb_valid_ecard() { 94 $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.PIWECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();';100 $query = 'SELECT COUNT(DISTINCT ecard_id) AS nb FROM '.PIWECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();'; 95 101 $result = pwg_query($query); 96 102 … … 106 112 function get_ecard($ecard_id = null) { 107 113 if ($ecard_id!== null) { 108 $query = 'SELECT * FROM ' . PIWECARD_TABLE .' WHERE id="' . $ecard_id . '" LIMIT 1;';114 $query = 'SELECT * FROM ' . PIWECARD_TABLE .' WHERE ecard_id="' . $ecard_id . '" LIMIT 1;'; 109 115 110 116 $result = pwg_query($query); … … 144 150 function delete_ecard($ecard_id = null) { 145 151 if (isset($ecard_id)) { 146 $query = 'DELETE FROM ' . PIWECARD_TABLE .' WHERE id="' . $ecard_id . '";';152 $query = 'DELETE FROM ' . PIWECARD_TABLE .' WHERE ecard_id="' . $ecard_id . '";'; 147 153 pwg_query($query); 148 154 } else … … 294 300 return; 295 301 296 foreach ($_POST['ecard_recipient_name'] as $recipient)297 if ($recipient == '')298 return;299 300 foreach ($_POST['ecard_recipient_email'] as $recipient)301 if ($recipient == '' OR !$this->is_valid_email($recipient)) {302 return;303 }304 305 302 // Initialize the array for image element 306 303 $image_element = array(); … … 314 311 // Generate random number 315 312 $next_element_id_random = $this->random(64); 316 while (pwg_db_num_rows(pwg_query('SELECT id FROM '.PIWECARD_TABLE.' WHEREid="'.$next_element_id_random.'";')) != 0) {313 while (pwg_db_num_rows(pwg_query('SELECT ecard_id FROM '.PIWECARD_TABLE.' WHERE ecard_id="'.$next_element_id_random.'";')) != 0) { 317 314 $next_element_id_random = $this->random(64); 318 315 } … … 348 345 $recipient_infos = array_combine($_POST['ecard_recipient_name'], $_POST['ecard_recipient_email']); 349 346 foreach ($recipient_infos as $recipient_name => $recipient_email) { 347 if ($recipient_name == '' OR $recipient_email == '' OR !$this->is_valid_email($recipient_email)) 348 continue; 349 350 350 $parse_list = array( 351 351 'ecard_sender_name' => $_POST['ecard_sender_name'], … … 357 357 ); 358 358 359 $email_subject = htmlspecialchars_decode($this->parse($this->config['email_subject'], $parse_list, $image_element)); 360 $email_message = htmlspecialchars_decode($this->parse($this->config['email_message'][$email_format], $parse_list, $image_element)); 361 $email_arg=array( 'from' => $_POST['ecard_sender_email'], 362 'subject' => $email_subject, 363 ); 359 $email_infos = array( 360 'from_name' => $_POST['ecard_sender_name'], 361 'from_email' => (isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email']), 362 'to' => $recipient_email, 363 'subject' => htmlspecialchars_decode($this->parse($this->config['email_subject'], $parse_list, $image_element)), 364 ); 364 365 366 $email_message_text = stripslashes(strip_tags($this->parse($this->config['email_message']['text'], $parse_list, $image_element))); 367 $email_message_html = stripslashes($this->parse($this->config['email_message']['html'], $parse_list, $image_element)); 365 368 switch($email_format) { 366 369 case 'text': // text 367 $email_arg = array_merge($email_arg, array( 368 'content' => $email_message, 369 'content_format' => "text/html", 370 'email_format' => "text/plain" 371 ) 370 $email_infos['message'] = array( 371 'text' => $email_message_text 372 372 ); 373 373 break; 374 374 case 'html': // html 375 $email_arg = array_merge($email_arg, array( 376 'content' => '<html><head><title>'.$email_subject.'</title></head><body>'.$email_message.'</body></html>', 377 'content_format' => "text/html", 378 'email_format' => array("text/plain", "text/html"), 379 ) 375 $email_infos['message'] = array( 376 'text' => $email_message_text, 377 'html' => $email_message_html, 380 378 ); 381 379 default: … … 383 381 } 384 382 383 $this->mail($email_infos); 384 385 385 // Add the copy to expe if param. 386 386 if (isset($_POST['ecard_copy'])) // send copy to sender 387 $email_arg['Bcc'] = array((isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email'])); 388 389 pwg_mail($recipient_email, $email_arg); 390 387 $email_infos['bcc'] = $email_infos['from_email']; 388 389 //Insert into database 391 390 $insert = array( 392 ' id'=> $image_element['next_element_id'],391 'ecard_id' => $image_element['next_element_id'], 393 392 'sender_name' => $_POST['ecard_sender_name'], 394 393 'recipient_name' => $recipient_name, … … 412 411 } 413 412 } 413 414 //Send an email 415 function mail($email_infos) { 416 $from = $email_infos['from_name']." <".$email_infos['from_email'].">"; 417 $subject = encode_mime_header(trim(preg_replace('#[\n\r]+#s', '', $email_infos['subject']))); 418 $boundary = '_----------='.md5(uniqid(mt_rand())); 419 420 $headers = 'From: '.$from."\n"; 421 $headers .= 'Reply-To: '.$from."\n"; 422 if (!empty($email_infos['bcc'])) 423 $headers .= 'Bcc: '.$email_infos['bcc']."\n"; 424 $headers .= 'X-Sender: <'.get_absolute_root_url().'>'."\n"; 425 $headers .= 'X-Mailer: Piwigo Mailer'."\n"; 426 $headers .= 'X-auth-smtp-user: '.$from."\n"; 427 $headers .= 'X-abuse-contact: '.$from."\n"; 428 $headers .= 'Date: '.date("D, j M Y G:i:s O")."\n"; 429 430 $message = ''; 431 432 if (empty($email_infos['message']['html'])) { //Text plain email 433 $headers .= 'Content-Transfer-Encoding: 8bit'."\n"; 434 $message .= $email_infos['message']['text']; 435 } else { 436 $headers .= 'MIME-Version: 1.0'."\n"; 437 $headers .= 'Content-Type: multipart/alternative; boundary="'.$boundary.'"'; 438 $message .= 'This is a multi-part message in MIME format'."\n\n"; 439 $message .= '--'.$boundary."\n"; 440 $message .= 'Content-Type: text/plain; charset="'.get_pwg_charset().'"'."\n"; 441 $message .= 'Content-Transfer-Encoding: binary'."\n\n"; 442 $message .= $email_infos['message']['text']."\n\n"; 443 $message .= '--'.$boundary."\n"; 444 $message .= 'Content-Type: text/html; charset="'.get_pwg_charset().'"'."\n"; 445 $message .= 'Content-Transfer-Encoding: binary;'."\n\n"; 446 $message .= $email_infos['message']['html']."\n\n"; 447 $message .= '--'.$boundary."--\n"; 448 } 449 450 mail($email_infos['to'], $subject, $message, $headers); 451 } 414 452 } 415 453 ?>
Note: See TracChangeset
for help on using the changeset viewer.