Ignore:
Timestamp:
Jan 17, 2013, 12:06:49 AM (11 years ago)
Author:
julien1311
Message:

[piwecard] several changes (almost 2.4.a.b4)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Piwecard/include/piwecard.class.php

    r20180 r20202  
    3434        }
    3535
     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       
    3642        // Save  general configuration to config_database
    3743        function set_config() {
     
    8086        // Get the number of ecard in the database
    8187        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;';
    8389                $result = pwg_query($query);
    8490               
     
    9298        // Get the number of valid ecard in the database
    9399        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();';
    95101                $result = pwg_query($query);
    96102               
     
    106112        function get_ecard($ecard_id = null) {
    107113                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;';
    109115
    110116                        $result = pwg_query($query);
     
    144150        function delete_ecard($ecard_id = null) {
    145151                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  . '";';
    147153                        pwg_query($query);
    148154                } else
     
    294300                                                        return;
    295301                                               
    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                                                
    305302                                                // Initialize the array for image element
    306303                                                $image_element = array();
     
    314311                                                // Generate random number
    315312                                                $next_element_id_random  = $this->random(64);
    316                                                 while (pwg_db_num_rows(pwg_query('SELECT id FROM '.PIWECARD_TABLE.' WHERE id="'.$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) {
    317314                                                        $next_element_id_random  = $this->random(64);
    318315                                                }
     
    348345                                                $recipient_infos = array_combine($_POST['ecard_recipient_name'], $_POST['ecard_recipient_email']);
    349346                                                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                                               
    350350                                                        $parse_list = array(
    351351                                                                                                'ecard_sender_name' => $_POST['ecard_sender_name'],
     
    357357                                                        );
    358358                                               
    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                                                        );
    364365                                                       
     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));
    365368                                                        switch($email_format) {
    366369                                                                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
    372372                                                                        );
    373373                                                                        break;
    374374                                                                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,
    380378                                                                        );
    381379                                                                default:
     
    383381                                                        }
    384382                                                       
     383                                                        $this->mail($email_infos);
     384                                                       
    385385                                                        // Add the copy to expe if param.
    386386                                                        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
    391390                                                        $insert = array(
    392                                                                                 'id'                            => $image_element['next_element_id'],
     391                                                                                'ecard_id'                      => $image_element['next_element_id'],
    393392                                                                                'sender_name'           => $_POST['ecard_sender_name'],
    394393                                                                                'recipient_name'        => $recipient_name,
     
    412411                }
    413412        }
     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        }
    414452}
    415453?>
Note: See TracChangeset for help on using the changeset viewer.