[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_Form.class.php (source)

   1  <?php
   2  class MP_Form
   3  {
   4      const prefix = MailPress_form::prefix;
   5  
   6  	public static function get($form, $output = OBJECT) 
   7      {
   8          global $wpdb;
   9  
  10          switch (true)
  11          {
  12              case ( empty($form) ) :
  13                  if ( isset($GLOBALS['mp_form']) )     $_form = & $GLOBALS['mp_form'];
  14                  else                    $_form = null;
  15              break;
  16              case ( is_object($form) ) :
  17                  wp_cache_add($form->id, $form, 'mp_form');
  18                  $_form = $form;
  19              break;
  20              default :
  21                  if ( isset($GLOBALS['mp_form']) && ($GLOBALS['mp_form']->id == $form) ) 
  22                  {
  23                      $_form = & $GLOBALS['mp_form'];
  24                  } 
  25                  elseif ( ! $_form = wp_cache_get($form, 'mp_form') ) 
  26                  {
  27                      $_form = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->mp_forms WHERE id = %d LIMIT 1", $form));
  28                      if ($_form) wp_cache_add($_form->id, $_form, 'mp_form');
  29                  }
  30              break;
  31          }
  32  
  33          if ($_form && isset($_form->settings)) $_form->settings = unserialize($_form->settings);
  34  
  35          if ( $output == OBJECT ) {
  36              return $_form;
  37          } elseif ( $output == ARRAY_A ) {
  38              return get_object_vars($_form);
  39          } elseif ( $output == ARRAY_N ) {
  40              return array_values(get_object_vars($_form));
  41          } else {
  42              return $_form;
  43          }
  44      }
  45  
  46  	public static function get_all() 
  47      {
  48          global $wpdb;
  49  
  50          $forms= $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->mp_forms a ORDER BY label" ) );
  51  
  52          if ($forms) foreach ($forms as $k => $form) if (!is_array($form->settings)) $forms[$k]->settings = unserialize($form->settings);
  53  
  54          return $forms;        
  55      }
  56  
  57  	public static function exists($label) 
  58      {
  59          global $wpdb;
  60          return $wpdb->get_var($wpdb->prepare("SELECT id FROM $wpdb->mp_forms WHERE label = %s LIMIT 1", $label));
  61      }
  62  
  63  	public static function get_template($id) 
  64      {
  65          $form = self::get($id);
  66          if ($form) return $form->template;
  67          return false;
  68      }
  69  
  70  	public static function insert($_post_form) 
  71      {
  72          $_post_defaults = array('id' => 0);
  73          $_post_form = wp_parse_args(stripslashes_deep($_post_form), $_post_defaults);
  74          extract($_post_form, EXTR_SKIP);
  75  
  76          if ( trim( $label ) == '' )
  77          {
  78              if ( ! $wp_error )    return 0;
  79              else                return new WP_Error( 'label', __('You did not enter a valid label.', MP_TXTDOM) );
  80          }
  81  
  82      // theme/template
  83          $settings['recipient']['template'] = $settings['recipient']['th'][$settings['recipient']['theme']]['tm'];
  84          $settings['visitor']  ['template'] = $settings['visitor']  ['th'][$settings['visitor']  ['theme']]['tm'];
  85          unset($settings['recipient']['th'], $settings['visitor']['th']);
  86      // is visitor
  87          $has_visitor = $tbc_visitor = false;
  88          if ( (isset($settings['visitor']['mail']) && $settings['visitor']['mail']) || ($settings['visitor']['subscription']))     $has_visitor = true;
  89          if (!$has_visitor) unset($settings['visitor']);
  90          if ( (isset($settings['visitor']['mail']) && ( '1' == $settings['visitor']['mail']) ))                         $tbc_visitor = true;
  91  
  92          $data = $format = $where = $where_format = array();
  93  
  94          $data['label']         = $label;            $format[] = '%s';
  95          $data['description']     = $description;        $format[] = '%s';
  96          $data['template']        = $template;        $format[] = '%s';
  97          $data['settings']     = serialize($settings);    $format[] = '%s';
  98  
  99          // Are we updating or creating?
 100          global $wpdb;
 101          $update = (!empty ($id) ) ? true : false;
 102          if ( $update )
 103          {
 104              $where['id']     = (int) $id;        $where_format[] = '%d';
 105              $wpdb->update( $wpdb->mp_forms, $data, $where, $format, $where_format );
 106          }
 107          else
 108          {
 109              $wpdb->insert( $wpdb->mp_forms, $data, $format );
 110              $id = $wpdb->insert_id;
 111          }
 112  
 113          if (!$id) return $id;
 114  
 115          MP_Form_field::check_visitor($id, $has_visitor, $tbc_visitor);
 116  
 117          return $id;
 118      }
 119  
 120  	public static function duplicate($id)
 121      {
 122          $form = self::get($id);
 123          if (!$form) return false;
 124  
 125          do 
 126          {
 127              $sep = '_x';
 128              $label = explode($sep, $form->label);
 129              $num = array_pop($label);
 130              $label[] = (is_numeric($num)) ? $num + 1 : $num . $sep . '2';
 131              $form->label = implode($sep, $label);
 132          } while (self::exists($form->label));
 133  
 134          $data = $format         = array();
 135  
 136          $data['label']         = $form->label;            $format[] = '%s';
 137          $data['description']     = $form->description;        $format[] = '%s';
 138          $data['template']        = $form->template;        $format[] = '%s';
 139          $data['settings']     = serialize($form->settings);    $format[] = '%s';    
 140          global $wpdb;
 141          $wpdb->insert( $wpdb->mp_forms, $data, $format );
 142          $dup_id = $wpdb->insert_id;
 143  
 144          if ($dup_id)
 145          {
 146              $fields = MP_Form_field::get_all($id);
 147              if ($fields) foreach($fields as $field) MP_Form_field::duplicate($field->id, $dup_id);
 148          }
 149  
 150          return $dup_id;
 151      }
 152  
 153  	public static function delete($id)
 154      {
 155          global $wpdb;
 156          $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->mp_forms WHERE id = %d;", $id) );
 157          MP_Form_field::delete_all($id);
 158          return true;
 159      }
 160  
 161  //// the form /building/resetting/controlling 
 162  
 163  	public static function form( $id )
 164      {
 165          $form = self::get($id);
 166          if (!$form) return '<!-- MailPress_form  ERROR : unknown form #' . $id . ' ! -->';
 167  
 168          $fields = MP_Form_field::get_all($form->id);
 169          if (!$fields) return '<!-- MailPress_form  WARNING : form #' . $form->id . ' is empty ! -->';
 170  
 171          $form_templates = new MP_Form_templates();
 172          $xform_template = $form_templates->get_all();
 173          if (!isset($xform_template[$form->template]))
 174              if (!isset($xform_template['default'])) return '<!-- MailPress_form  ERROR : form #' . $form->id . ', template : ' . $form->template . ' unknown ! -->';
 175  
 176          new MP_Form_field_types();
 177  
 178          $processed = $on_error = false;
 179          $submitted = ((isset($_POST[self::prefix][$id])));
 180          foreach($fields as $k => $field) 
 181          {
 182              $field =  MP_Form_field::get($field->id);
 183              $fields[$k] = ($submitted) ? MP_Form_field_types::submitted( $field ) : $field;
 184              if (isset($fields[$k]->submitted['on_error'])) $on_error = true;
 185          }
 186  
 187          if ($submitted)
 188          {
 189              if (!$on_error)    $processed = self::process($form, $fields, $form_templates);
 190              else            unset($form->settings['options']['reset']);
 191          }
 192  
 193          if ($processed && isset($form->settings['options']['reset'])) unset($_POST[self::prefix][$id]);
 194  
 195          return self::get_form($form, $fields, $form_templates, $submitted, $processed);
 196      }
 197  
 198  
 199  //// Processing form
 200  	public static function process( $form, $fields, $form_templates)
 201      {
 202          $array = new stdClass();
 203          $mail  = new stdClass();
 204          $attachements = array();
 205  
 206          $mail->id = $mail_main_id = MP_Mail::get_id('MP_Form::process');
 207  
 208          $array->form['id']     = $form->id;
 209          $array->form['label']     = $form->label;
 210          $array->form['description']     = $form->description;
 211  
 212          $recipient_content = $visitor_content = '';
 213          foreach($fields as $k => $field)
 214          {
 215              if (!isset($field->submitted) || empty($field->submitted)) continue;
 216              $incopy = (isset($field->settings['options']['incopy']) && $field->settings['options']['incopy']);
 217  
 218              $img = (!isset($field->submitted['map'])) ? '' : "<img align='center' style='border:none;margin:0;padding:0' src='" . $field->submitted['map'] . "' alt='' /></br>\r\n";
 219  
 220              $recipient_content .= sprintf('<p>' . "\r\n" . '<b>%1$s : </b>' . "\t\t" . ' %2$s %4$s %3$s</p>' . "\r\n",             $field->label, ( ($field->submitted['value']) ? $field->submitted['text'] : ((empty($field->submitted['text'])) ? '' : '<small>[ ' . $field->submitted['text'] . ' ]</small> ') ), ( (!empty($field->description)) && (!empty($field->submitted['text'])) ? ' <small>[ ' . $field->description . ' ]</small> ' : ' ' ), (empty($img)) ? $img : "<div>$img</div>" ) ;
 221              $visitor_content   .= (!$incopy) ? '' : sprintf('<p>' . "\r\n" . '<b>%1$s : </b>' . "\t\t" . ' %3$s %2$s</p>' . "\r\n", $field->label, ( ($field->submitted['value']) ? $field->submitted['text'] : ((empty($field->submitted['text'])) ? '' : '<small>[ ' . $field->submitted['text'] . ' ]</small> ') ), (empty($img)) ? $img : "<div>$img</div>" );
 222  
 223              if (isset($field->settings['options']['visitor_email'])) { $visitor_toemail = $field->submitted['value'];     $array->field[$field->id]['options']['visitor']['email'] = true; }
 224              if (isset($field->settings['options']['visitor_name']))  { $visitor_toname  = $field->submitted['value'];     $array->field[$field->id]['options']['visitor']['name']  = true; }
 225              if (isset($field->settings['options']['visitor_mail']))  { $visitor_mail    = $field->submitted['value'];     $array->field[$field->id]['options']['visitor']['mail']  = true; }
 226  
 227              $array->field[$field->id]['label']         = $field->label;
 228              $array->field[$field->id]['description']     = $field->description;
 229              $array->field[$field->id]['value']         = (isset($field->submitted['value'])) ? $field->submitted['value'] : false;
 230              if (isset($field->submitted['map'])) 
 231                  $array->field[$field->id]['map']    = $field->submitted['map'];
 232  
 233              if (isset($field->submitted['file'])) $attachements[] = self::handle_upload($field->submitted['file'], $mail->id);
 234          }
 235          $subject     = sprintf(__('[%1$s] Your form receipt "%2$s" (%3$s)', MP_TXTDOM), get_option('blogname'), $form->label, $form->id);
 236  
 237          $mail->Theme     = $form->settings['recipient']['theme'];
 238          if ('0' != $form->settings['recipient']['template']) $mail->Template = $form->settings['recipient']['template'];
 239  
 240          if (isset($visitor_toemail))
 241          {
 242              $mail->fromemail     = $visitor_toemail;
 243              $mail->fromname   = (isset($visitor_toname)) ? $visitor_toname : $visitor_toemail;
 244          }
 245  
 246          $mail->toemail     = $form->settings['recipient']['toemail'];
 247          $mail->toname     = $form->settings['recipient']['toname'];
 248  
 249          $mail->subject     = $subject;
 250          $mail->content     = $recipient_content;    //self::get_form($form, $fields, $form_templates); 
 251          $mail->form     = $array;
 252  
 253          if (!MailPress::mail($mail)) return false;
 254          if ( !isset($form->settings['visitor'])) return true;
 255          
 256          if ('0' != $form->settings['visitor']['subscription'] && isset($visitor_toemail))
 257          {
 258  
 259              if ($mp_user = MP_User::get( MP_User::get_id_by_email($visitor_toemail) ))
 260              {
 261                  switch($mp_user->status) 
 262                  {
 263                      case 'active':
 264                      break;
 265                      case 'bounced':
 266                      break;
 267                      case 'waiting':
 268                          switch ($form->settings['visitor']['subscription'])
 269                          {
 270                              case '1' :    // not active
 271                              break;
 272                              case '2' :    // tbc
 273                                  MP_User::send_confirmation_subscription($mp_user->email, $mp_user->name, $mp_user->confkey);
 274                              break;
 275                              case '3' :    // active
 276                                  MP_User::set_status($mp_user->id, 'active');
 277                              break;
 278                          }
 279                      break;
 280                      case 'unsubscribed':
 281                          switch ($form->settings['visitor']['subscription'])
 282                          {
 283                              case '1' :    // not active
 284                                  MP_User::set_status($mp_user->id, 'waiting');
 285                              break;
 286                              case '2' :    // tbc
 287                                  MP_User::set_status($mp_user->id, 'waiting');
 288                                  MP_User::send_confirmation_subscription($mp_user->email, $mp_user->name, $mp_user->confkey);
 289                              break;
 290                              case '3' :    // active
 291                                  MP_User::set_status($mp_user->id, 'waiting');
 292                                  MP_User::set_status($mp_user->id, 'active');
 293                              break;
 294                          }
 295                      break;
 296                  }
 297                  do_action('MailPress_visitor_subscription', 'add', $visitor_toemail, $form);
 298              }
 299              else
 300              {
 301                  switch ($form->settings['visitor']['subscription'])
 302                  {
 303                      case '1' :    // not active
 304                          MP_User::insert($visitor_toemail, $visitor_toname);
 305                      break;
 306                      case '2' :    // tbc
 307                          MP_User::add($visitor_toemail, $visitor_toname);
 308                      break;
 309                      case '3' :    // active
 310                          MP_User::insert($visitor_toemail, $visitor_toname, array('status' => 'active'));
 311                      break;
 312                  }
 313                  do_action('MailPress_visitor_subscription', 'init', $visitor_toemail, $form);
 314              }
 315          }
 316  
 317          // no mail
 318          if (!isset($visitor_toemail)) return true;
 319          // form says no copy
 320          if (!isset($form->settings['visitor']['mail'])) return true;
 321          if ($form->settings['visitor']['mail'] == '0')  return true;
 322          // forms says copy but no email field in form (!!??)
 323          if (!isset($visitor_mail) && ($form->settings['visitor']['mail'] == '1')) return true;
 324          // forms says copy tbc and visitor unchecked the option
 325          if (isset($visitor_mail) && !$visitor_mail) return true;
 326  
 327          // no valid mail
 328          if (!is_email($visitor_toemail)) return false;
 329  
 330          $mail = new stdClass();
 331          $mail->id = MP_Mail::get_id('MP_Form::process2');
 332  
 333          // duplicate attachements
 334          if (!empty($attachements))
 335          {
 336              $metas = MP_Mail_meta::has( $mail_main_id, '_MailPress_attached_file');
 337              if ($metas)
 338              {
 339                  foreach($metas as $meta)
 340                  {
 341                      $meta_value = unserialize( $meta['meta_value'] );
 342                      if (!is_file($meta_value['file_fullpath'])) continue;
 343                      MP_Mail_meta::add( $mail->id, '_MailPress_attached_file', $meta_value );
 344                  }
 345              }
 346          }
 347  
 348          $mail->Theme     = $form->settings['visitor']['theme'];
 349          if ('0' != $form->settings['visitor']['template']) $mail->Template = $form->settings['visitor']['template'];
 350  
 351          $mail->toemail     = $visitor_toemail;
 352          $mail->toname     = $visitor_toname;
 353  
 354          $mail->subject     = $subject;
 355          $mail->content     = $visitor_content;
 356  
 357          return MailPress::mail($mail);
 358      }
 359  
 360  //// Getting form
 361  	public static function get_form($form, $fields, $form_templates, $submitted = false, $processed = false)
 362      {
 363          $message = '';
 364          if ($submitted) $message[(($processed) ? 'ok' : 'ko')] = $form->settings['message'][(($processed) ? 'ok' : 'ko')];
 365  
 366      // going for the message
 367          if (!empty($message))
 368          {
 369              foreach($message as $ret => $mess) {}
 370              $html = $form_templates->get_message_template($form->template, $ret);
 371              if (!$html) $html = '{{message}}';
 372  
 373              $search = $replace = array();
 374              $search[] = '{{message}}'; $replace[] = $mess;
 375              $html = str_replace($search, $replace, $html ); 
 376  
 377              $message = sprintf('%1$s<!-- start message -->%2$s<!--   end message -->%1$s', "\n", $html);
 378          }
 379  
 380      // going for the form
 381          $html = $form_templates->get_form_template($form->template);
 382          if (!$html) $html = '{{form}}';
 383  
 384          $search = $replace = array();
 385          $search[] = '{{label}}';     $replace[] = $form->label;
 386          $search[] = '{{description}}';$replace[] = $form->description;
 387          $search[] = '{{form}}';     $replace[] = self::build_form( $form, $fields, $form_templates);
 388          $search[] = '{{message}}';     $replace[] = $message;
 389          $html = str_replace($search, $replace, $html ); 
 390  
 391          return sprintf('%1$s<!-- MailPress_form : start of form #%2$s -->%1$s%3$s%1$s<!--   MailPress_form : end of form #%2$s -->%1$s%1$s', "\n", $form->id, $html);
 392      }
 393  
 394  //// Building form
 395  	public static function build_form( $form, $fields, $form_templates)
 396      {
 397      // going for the fields
 398          $i = 0;
 399          $have_groups = array();
 400          foreach($fields as $offset => $field)
 401          {
 402      // going for fields
 403              $field_template     = $field->template;
 404              $html            = (isset($field->submitted['on_error'])) ? $form_templates->get_field_on_error_template($form->template, $field->template) : $form_templates->get_field_template($form->template, $field->template);
 405              if (!$html) {$html = $form_templates->get_field_template($form->template, $field->template); }
 406              if (!$html) {$html = '{{field}}'; $field_template = 'not found'; }
 407              if ((isset($field->settings['attributes']['type'])) && ($field->settings['attributes']['type'] == 'hidden')) {$html = '{{field}}'; $field_template = "(type='hidden') => overridden "; }
 408              $htmls[$offset]     = sprintf('<!-- start field / form : %2$s, field : %3$s, type : %4$s, template : %5$s/%6$s, description : %7$s -->%1$s%8$s%1$s<!--   end field / form : %2$s, field : %3$s -->%1$s', "\n", $form->id, $field->id, $field->type, $form->template, $field_template, $field->description, self::get_field($field, $html));
 409      // looking for groups
 410              if (!$i) { $i = 1; $prev_field = $field;}
 411              if ( ($field->type == $prev_field->type) && ($field->template == $prev_field->template) && ($form_templates->get_group_template($form->template, $field->template)) )
 412              {
 413                  switch (true) 
 414                  {
 415                      case ('radio' == $field->type) :
 416                          if ($field->settings['attributes']['name'] == $prev_field->settings['attributes']['name']) 
 417                              $have_groups[$i][$offset] = $field->id;
 418                          else
 419                          {    
 420                              if (isset($have_groups[$i]))
 421                                  if (count($have_groups[$i]) < 2)     unset($have_groups[$i]);
 422                                  else $i++;
 423                              $have_groups[$i][$offset] = $field->id;
 424                          }
 425                      break;
 426                      default :
 427                          $have_groups[$i][$offset] = $field->id;
 428                      break;
 429                  }
 430              }
 431              else
 432              {
 433                  if (isset($have_groups[$i]))
 434                      if (count($have_groups[$i]) < 2)     unset($have_groups[$i]);
 435                      else $i++;
 436  
 437                  $have_groups[$i][$offset] = $field->id;
 438              }
 439              $prev_field = $field;
 440          }
 441  
 442          if (isset($have_groups[$i]))
 443              if (count($have_groups[$i]) < 2)     unset($have_groups[$i]);
 444  
 445      // going for groups
 446          foreach ($have_groups as $offsets)
 447          {
 448              $html    = '';
 449              $count = 1;
 450              $group_template     = false;
 451              foreach ($offsets as $offset => $v)
 452              {
 453                  $field = $fields[$offset];
 454                  if (!$group_template) $group_template = $form_templates->get_group_template($form->template, $field->template);
 455                  if (!$group_template) break;
 456  
 457                  if (is_array($group_template))
 458                  {
 459                      if (!isset($group_template[$field->template])) break;
 460                      if (($count == 1) && (isset($group_template['before'])))                $html .= $group_template['before'];
 461                      if (($count == 1) && (isset($group_template['first'])))                $html .= $group_template['first'];
 462                      elseif (($count == count($offsets)) && (isset($group_template['last'])))    $html .= $group_template['last'];
 463                      else                                                    $html .= $group_template[$field->template];
 464                      if (($count == count($offsets)) && (isset($group_template['after'])))         $html .= $group_template['after'];
 465                  }
 466                  else                                                        $html .= $group_template;
 467  
 468                  $search = $replace = array();
 469                  $search[] = '{{field}}';     $replace[] = $htmls[$offset];
 470                  $html = str_replace($search, $replace, $html ); 
 471                  $count++;
 472              }
 473              if (!empty($html))
 474              {
 475                  $first = true;
 476                  foreach ($offsets as $offset => $v) if (!$first) { unset($htmls[$offset]); } else { $first = false; $htmls[$offset] = sprintf('%1$s<!-- Start grouping fields : #%2$s -->%1$s%3$s%1$s<!-- End grouping fields : #%2$s -->%1$s', "\n", implode(', #', $offsets), $html); } 
 477              }
 478          }
 479  
 480          return sprintf('%2$s%1$s%3$s%1$s%4$s', "\n", self::get_tag( $form ), implode("\n", $htmls), '</form>');
 481      }
 482  
 483  	public static function get_tag( $form )
 484      {
 485          $attributes = $form->settings['attributes'];
 486      // misc
 487          $misc = (isset($attributes['misc'])) ? ' ' . $attributes['misc'] : '';
 488          unset($attributes['misc']);
 489  
 490      // opening tag
 491          $tag  = '<form' ;
 492      // id
 493          if (false === strpos($misc, 'id=')) $attributes['id'] = self::prefix . $form->id;
 494      // method
 495          $attributes['method'] = 'post';
 496      // action
 497          if (false === strpos($misc, 'action=')) $attributes['action'] = '';
 498      // enctype
 499          if (MP_Form_field::have_file($form->id)) $attributes['enctype'] = 'multipart/form-data';
 500      // other attributes
 501          foreach ($attributes as $attribute => $value)
 502          {
 503              $value = trim($value);
 504              $tag .= ( ('action' != $attribute) && ('' == trim($value)) ) ? '' : self::get_attribute($attribute, trim($value));
 505          } 
 506      // closing tag
 507          return $tag . "$misc >";
 508      }
 509  	public static function get_attribute($attr, $value) { $quote = (false !== strpos($value, '"')) ? "'" : '"'; return " $attr=$quote$value$quote"; }
 510  	public static function get_field($field, $html = false, $form_template = false)
 511      {
 512          if (!$html)
 513          {
 514              $form_templates     = new MP_Form_templates();
 515              $html            = $form_templates->get_field_template($form_template, $field->template);
 516              if (!$html) $html = '{{field}}';
 517          }
 518          $search = $replace = array();
 519          $search[] = '{{label}}';     $replace[] = $field->label;
 520          $search[] = '{{description}}';$replace[] = $field->description;
 521          $search[] = '{{field_id}}';     $replace[] = MP_Form_field_types::get_id($field);
 522          $search[] = '{{field}}';     $replace[] = MP_Form_field_types::get_tag($field);
 523          $html = str_replace($search, $replace, $html ); 
 524          return $html;
 525      }
 526  
 527  	public static function handle_upload($file_id, $draft_id) 
 528      {
 529          $overrides = array('test_form'=>false, 'unique_filename_callback' => 'mp_unique_filename_callback');
 530          $time = current_time('mysql');
 531  
 532          require_once (ABSPATH . 'wp-admin/includes/file.php');
 533  
 534          $uploaded_file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
 535  
 536          if ( isset($uploaded_file['error']) )
 537              return new WP_Error( 'upload_error', $uploaded_file['error'] );
 538  
 539  // Check file path is ok
 540          $uploads = wp_upload_dir();
 541          if ( $uploads && (false === $uploads['error']) )                             // Get upload directory
 542          {     
 543              if ( 0 === strpos($uploaded_file['file'], $uploads['basedir']) )                 // Check that the upload base exists in the file path
 544              {
 545                  $file = str_replace($uploads['basedir'], '', $uploaded_file['file']);         // Remove upload dir from the file path
 546                  $file = ltrim($file, '/');
 547              }
 548          }
 549  
 550  // Construct the attachment array
 551          $object = array(
 552                      'name'     => $_FILES[$file_id]['name'],
 553                      'mime_type'    => $uploaded_file['type'], 
 554                      'file'    => $file, 
 555                      'file_fullpath'    => str_replace("\\", "/", $uploaded_file['file']), 
 556                      'guid'     => $uploaded_file['url']
 557                  );
 558  // Save the data
 559          return MP_Mail_meta::add( $draft_id, '_MailPress_attached_file', $object );
 560      }
 561  
 562  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1