public function getNumberAttribute($value) { $value = cleanPhone($value); $phoneUtil = PhoneNumberUtil::getInstance(); try { $number = $phoneUtil->parse($value, null); } catch (\libphonenumber\NumberParseException $e) { return $value; } return $phoneUtil->format($number, PhoneNumberFormat::INTERNATIONAL); }
public function store() { $data = Input::all(); if (isset($data['fileNames']) && $data['fileNames']) { foreach ($data['fileNames'] as &$file) { $path = $this->file->getFilePath($file); $file = new File($path); } } // clean up the phone number if necessary $data['fullNumber'] = isset($data['fullNumber']) ? cleanPhone($data['fullNumber']) : ''; $result = $this->faxForm->save($data); if ($result['success']) { // Success! Session::flash('success', $result['message']); return Redirect::action('FaxController@index'); } else { Session::flash('error', $result['message'] ?: 'Please fix the errors below and resend your fax'); return Redirect::action('FaxController@create')->withInput()->withErrors($this->faxForm->errors()); } }
/** * Function to format a phone number. * * @since 1.0 * * @param string $phone The phone number to format. */ function formatPhone($phone) { $r = cleanPhone($phone); if (strlen($r) == 11) { $r = substr($r, 0, 1) . " (" . substr($r, 1, 3) . ") " . substr($r, 4, 3) . "-" . substr($r, 7, 4); } elseif (strlen($r) == 10) { $r = "(" . substr($r, 0, 3) . ") " . substr($r, 3, 3) . "-" . substr($r, 6, 4); } elseif (strlen($r) == 7) { $r = substr($r, 0, 3) . "-" . substr($r, 3, 4); } /** * Filter to do more or less cleaning of phone numbers. * * @since 1.8.4.4 * * @param string $r The formatted phone number. * @param string $phone The original phone number. */ return apply_filters('pmpro_format_phone', $r, $phone); }
/** * Save/update the values of the order in the database. */ function saveOrder() { global $current_user, $wpdb; //get a random code to use for the public ID if (empty($this->code)) { $this->code = $this->getRandomCode(); } //figure out how much we charged if (!empty($this->InitialPayment)) { $amount = $this->InitialPayment; } elseif (!empty($this->subtotal)) { $amount = $this->subtotal; } else { $amount = 0; } //Todo: Tax?!, Coupons, Certificates, affiliates if (empty($this->subtotal)) { $this->subtotal = $amount; } if (isset($this->tax)) { $tax = $this->tax; } else { $tax = $this->getTax(true); } $this->certificate_id = ""; $this->certificateamount = ""; //calculate total if (!empty($this->total)) { $total = $this->total; } else { $total = (double) $amount + (double) $tax; } //these fix some warnings/notices if (empty($this->billing)) { $this->billing = new stdClass(); $this->billing->name = $this->billing->street = $this->billing->city = $this->billing->state = $this->billing->zip = $this->billing->country = $this->billing->phone = ""; } if (empty($this->user_id)) { $this->user_id = 0; } if (empty($this->paypal_token)) { $this->paypal_token = ""; } if (empty($this->couponamount)) { $this->couponamount = ""; } if (empty($this->payment_type)) { $this->payment_type = ""; } if (empty($this->payment_transaction_id)) { $this->payment_transaction_id = ""; } if (empty($this->subscription_transaction_id)) { $this->subscription_transaction_id = ""; } if (empty($this->affiliate_id)) { $this->affiliate_id = ""; } if (empty($this->affiliate_subid)) { $this->affiliate_subid = ""; } if (empty($this->session_id)) { $this->session_id = ""; } if (empty($this->accountnumber)) { $this->accountnumber = ""; } if (empty($this->cardtype)) { $this->cardtype = ""; } if (empty($this->ExpirationDate)) { $this->ExpirationDate = ""; } if (empty($this->status)) { $this->status = ""; } if (empty($this->gateway)) { $this->gateway = pmpro_getOption("gateway"); } if (empty($this->gateway_environment)) { $this->gateway_environment = pmpro_getOption("gateway_environment"); } if (empty($this->notes)) { $this->notes = ""; } //build query if (!empty($this->id)) { //set up actions $before_action = "pmpro_update_order"; $after_action = "pmpro_updated_order"; //update $this->sqlQuery = "UPDATE {$wpdb->pmpro_membership_orders}\n\t\t\t\t\t\t\t\t\tSET `code` = '" . $this->code . "',\n\t\t\t\t\t\t\t\t\t`session_id` = '" . $this->session_id . "',\n\t\t\t\t\t\t\t\t\t`user_id` = " . intval($this->user_id) . ",\n\t\t\t\t\t\t\t\t\t`membership_id` = " . intval($this->membership_id) . ",\n\t\t\t\t\t\t\t\t\t`paypal_token` = '" . $this->paypal_token . "',\n\t\t\t\t\t\t\t\t\t`billing_name` = '" . esc_sql($this->billing->name) . "',\n\t\t\t\t\t\t\t\t\t`billing_street` = '" . esc_sql($this->billing->street) . "',\n\t\t\t\t\t\t\t\t\t`billing_city` = '" . esc_sql($this->billing->city) . "',\n\t\t\t\t\t\t\t\t\t`billing_state` = '" . esc_sql($this->billing->state) . "',\n\t\t\t\t\t\t\t\t\t`billing_zip` = '" . esc_sql($this->billing->zip) . "',\n\t\t\t\t\t\t\t\t\t`billing_country` = '" . esc_sql($this->billing->country) . "',\n\t\t\t\t\t\t\t\t\t`billing_phone` = '" . esc_sql($this->billing->phone) . "',\n\t\t\t\t\t\t\t\t\t`subtotal` = '" . $this->subtotal . "',\n\t\t\t\t\t\t\t\t\t`tax` = '" . $this->tax . "',\n\t\t\t\t\t\t\t\t\t`couponamount` = '" . $this->couponamount . "',\n\t\t\t\t\t\t\t\t\t`certificate_id` = " . intval($this->certificate_id) . ",\n\t\t\t\t\t\t\t\t\t`certificateamount` = '" . $this->certificateamount . "',\n\t\t\t\t\t\t\t\t\t`total` = '" . $this->total . "',\n\t\t\t\t\t\t\t\t\t`payment_type` = '" . $this->payment_type . "',\n\t\t\t\t\t\t\t\t\t`cardtype` = '" . $this->cardtype . "',\n\t\t\t\t\t\t\t\t\t`accountnumber` = '" . $this->accountnumber . "',\n\t\t\t\t\t\t\t\t\t`expirationmonth` = '" . $this->expirationmonth . "',\n\t\t\t\t\t\t\t\t\t`expirationyear` = '" . $this->expirationyear . "',\n\t\t\t\t\t\t\t\t\t`status` = '" . esc_sql($this->status) . "',\n\t\t\t\t\t\t\t\t\t`gateway` = '" . $this->gateway . "',\n\t\t\t\t\t\t\t\t\t`gateway_environment` = '" . $this->gateway_environment . "',\n\t\t\t\t\t\t\t\t\t`payment_transaction_id` = '" . esc_sql($this->payment_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t`subscription_transaction_id` = '" . esc_sql($this->subscription_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t`affiliate_id` = '" . esc_sql($this->affiliate_id) . "',\n\t\t\t\t\t\t\t\t\t`affiliate_subid` = '" . esc_sql($this->affiliate_subid) . "',\n\t\t\t\t\t\t\t\t\t`notes` = '" . esc_sql($this->notes) . "'\n\t\t\t\t\t\t\t\t\tWHERE id = '" . $this->id . "'\n\t\t\t\t\t\t\t\t\tLIMIT 1"; } else { //set up actions $before_action = "pmpro_add_order"; $after_action = "pmpro_added_order"; //insert $this->sqlQuery = "INSERT INTO {$wpdb->pmpro_membership_orders}\n\t\t\t\t\t\t\t\t(`code`, `session_id`, `user_id`, `membership_id`, `paypal_token`, `billing_name`, `billing_street`, `billing_city`, `billing_state`, `billing_zip`, `billing_country`, `billing_phone`, `subtotal`, `tax`, `couponamount`, `certificate_id`, `certificateamount`, `total`, `payment_type`, `cardtype`, `accountnumber`, `expirationmonth`, `expirationyear`, `status`, `gateway`, `gateway_environment`, `payment_transaction_id`, `subscription_transaction_id`, `timestamp`, `affiliate_id`, `affiliate_subid`, `notes`)\n\t\t\t\t\t\t\t\tVALUES('" . $this->code . "',\n\t\t\t\t\t\t\t\t\t '" . session_id() . "',\n\t\t\t\t\t\t\t\t\t " . intval($this->user_id) . ",\n\t\t\t\t\t\t\t\t\t " . intval($this->membership_id) . ",\n\t\t\t\t\t\t\t\t\t '" . $this->paypal_token . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql(trim($this->billing->name)) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql(trim($this->billing->street)) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->city) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->state) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->zip) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->country) . "',\n\t\t\t\t\t\t\t\t\t '" . cleanPhone($this->billing->phone) . "',\n\t\t\t\t\t\t\t\t\t '" . $amount . "',\n\t\t\t\t\t\t\t\t\t '" . $tax . "',\n\t\t\t\t\t\t\t\t\t '" . $this->couponamount . "',\n\t\t\t\t\t\t\t\t\t " . intval($this->certificate_id) . ",\n\t\t\t\t\t\t\t\t\t '" . $this->certificateamount . "',\n\t\t\t\t\t\t\t\t\t '" . $total . "',\n\t\t\t\t\t\t\t\t\t '" . $this->payment_type . "',\n\t\t\t\t\t\t\t\t\t '" . $this->cardtype . "',\n\t\t\t\t\t\t\t\t\t '" . hideCardNumber($this->accountnumber, false) . "',\n\t\t\t\t\t\t\t\t\t '" . substr($this->ExpirationDate, 0, 2) . "',\n\t\t\t\t\t\t\t\t\t '" . substr($this->ExpirationDate, 2, 4) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->status) . "',\n\t\t\t\t\t\t\t\t\t '" . $this->gateway . "',\n\t\t\t\t\t\t\t\t\t '" . $this->gateway_environment . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->payment_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->subscription_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t '" . current_time('mysql') . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->affiliate_id) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->affiliate_subid) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->notes) . "'\n\t\t\t\t\t\t\t\t\t )"; } do_action($before_action, $this); if ($wpdb->query($this->sqlQuery) !== false) { if (empty($this->id)) { $this->id = $wpdb->insert_id; } do_action($after_action, $this); return $this->getMemberOrderByID($this->id); } else { return false; } }
function formatPhone($phone) { $phone = cleanPhone($phone); if (strlen($phone) == 11) { return substr($phone, 0, 1) . " (" . substr($phone, 1, 3) . ") " . substr($phone, 4, 3) . "-" . substr($phone, 7, 4); } elseif (strlen($phone) == 10) { return "(" . substr($phone, 0, 3) . ") " . substr($phone, 3, 3) . "-" . substr($phone, 6, 4); } elseif (strlen($phone) == 7) { return substr($phone, 0, 3) . "-" . substr($phone, 3, 4); } else { return $phone; } }
/** * * * @since 1.0.0 * @access public * @param * @return void */ private function validatePhone($value, $fieldname) { function cleanPhone($value) { // remove whitespace $value = trim($value); // look for extension followed by 'x' // split phone number and extension into two seperate strings if (strpos($value, 'x') != false) { $complete_phone = preg_split('/[x]/i', $value); $value = $complete_phone[0]; } // strip spaces and everything that is not a number $value = preg_replace('/[^0-9]*/', '', $value); // strip leading 1 $value = preg_replace('/\\b[1]/', '', $value); return $value; } // no bad area codes or toll free / pay per call // BAD_AREA_CODES = open('bad-area-codes.txt', 'r').read().split('\n'); // make sure phone number is exactly 10 digits if (strlen($value) < 10) { $valid = false; $this->validation_errors[] = "Too short! Please provide a valid phone number for {$fieldname}"; } else { $phone = cleanPhone($value); if (strlen($phone) != 10) { $valid = false; $this->validation_errors[] = "Please provide a valid phone number for {$fieldname}"; } else { $valid = true; } } return $valid; }
/** * @function set * @returns Id of the record. * @abstract * Sets a single field. Takes "field","value" */ function set($field, $value = false) { if ($value == false) { $value = $_REQUEST[$field]; } $value = stripslashes($value); if (!empty($this->db)) { mysql_select_db($this->db); } // Backwards compatibility if ($this->table && !$this->_table) { $this->_table = $this->table; } if ($this->indexField && !$this->_idField) { $this->_idField = $this->indexField; } if (contains("phone", $field)) { $info = cleanPhone($value); if (is_numeric($info[numeric])) { $value = $info[numeric]; } } $query = "UPDATE {$this->_table}\n SET {$field} = '" . addslashes($value) . "'\n WHERE {$this->_idField} = '" . $this->id . "'"; mysql_query($query) or mysql_die($query); $this->{$field} = $value; return $this->id; }
$account = $result[0]; $account->Id = $account->id; $account->fresh = true; unset($account->id); $logger->debug(sprintf(MSG_SF_ACCOUNT_CREATED, $result[0]->id), [$result[0]]); } else { $account = new stdClass(); $account->Id = sprintf('row#%d', $pos); $account->fresh = true; $logger->info(sprintf(MSG_SF_ACCOUNT_CREATED . ' from row %d', $row->phone, $pos)); } } else { if (strtolower($account->fields->Name) === strtolower($row->dealership)) { continue; } else { if (in_array(cleanPhone($account->fields->Phone), [$row->phone, $row->altPhone])) { continue; } } $account->fresh = false; } $counter->inc($account->fresh ? COUNT_ACCOUNT_CREATED : COUNT_ACCOUNT_EXISTING); if (!$account->fresh) { if (strlen($row->phone) !== 10) { $logger->warning(sprintf(MSG_SF_UNRELIABLE_PHONE_LOOKUP, $pos)); } $qb = $client->createQueryBuilder(); $qb->select('Id')->from('Contact')->where('AccountId = :id')->andWhere($qb->expr()->orX('Phone like :phone', 'Phone_2__c like :phone', 'Phone like :alt', 'Phone_2__c like :alt')); $contact = $qb->setMaxResults(1)->setParameter('id', $account->Id)->setParameter('phone', getPhoneLikeStatement($row->phone))->setParameter('alt', getPhoneLikeStatement($row->altPhone))->getQuery()->getOneOrNullResult(); if ($contact !== null) { $counter->inc(COUNT_CONTACT_EXISTING);