Ejemplo n.º 1
0
 public function Hash($value = null)
 {
     if ($value !== null && !is_array($value)) {
         throw new Exception(sprint_f('Invalid value specified for type %s.', __FUNCTION__));
     }
     return $this->Bucket(null, $value);
 }
Ejemplo n.º 2
0
 /**
  * Recupera uma chave da sessão registrada para o usuário.
  * 
  * @param string $key 
  * @return Mixed
  */
 protected function getSessionVar($key)
 {
     $session = $this->getSession();
     if ($session) {
         if (isset($session[$key])) {
             return $session[$key];
         } else {
             throw new \Exception(sprint_f('A variável de sessão "%s" não existe!', $key));
         }
     }
 }
 /**
  * Ensures that tthe specified message type for the given messenger is currently active, if not activates it.
  * This ALSO ensures that the given messenger is active as well!.
  *
  * @param string $message_type message type name
  *
  * @return boolean true if it got activated (or was active) and false if not.
  */
 public function ensure_message_type_is_active($message_type, $messenger)
 {
     //first validate that the incoming messenger allows this message type to be activated.
     $messengers = $this->get_installed_messengers();
     if (!isset($messengers[$messenger])) {
         throw new EE_Error(sprintf(__('The messenger sent to %s is not installed', 'event_espresso'), __METHOD__));
     }
     $msgr = $messengers[$messenger];
     $valid_message_types = $msgr->get_valid_message_types();
     if (!in_array($message_type, $valid_message_types)) {
         throw new EE_Error(sprint_f(__('The message type ($1%s) sent to $2%s is not valid for the $3%s messenger.  Doublecheck the spelling and verify that message type has been registered as a valid type with the messenger.', 'event_espresso'), $message_type, __METHOD__, $messenger));
     }
     //all is good so let's just get it active
     return $this->activate_messenger($messenger, array($message_type));
 }
Ejemplo n.º 4
0
 public function setVar($key, $value_escaped)
 {
     throw new \Exception(sprint_f("Use WordPress Translate Core to set var '%s' with value '%s'!", $key, $value), 500);
 }
Ejemplo n.º 5
0
/**
 * 3-step function to Process & Save Transaction
 *
 * 1) Capture POST
 * 2) Create Charge using wp_stripe_charge()
 * 3) Store Transaction in Custom Post Type
 *
 * @since 1.0
 *
 */
function wp_stripe_charge_initiate()
{
    // Security Check
    if (!wp_verify_nonce($_POST['nonce'], 'wp-stripe-nonce')) {
        wp_die(__('Nonce verification failed!', 'wp-stripe'));
    }
    // Define/Extract Variables
    $public = sanitize_text_field($_POST['wp_stripe_public']);
    $name = sanitize_text_field($_POST['wp_stripe_name']);
    $email = sanitize_email($_POST['wp_stripe_email']);
    // Strip any comments from the amount
    $amount = str_replace(',', '', sanitize_text_field($_POST['wp_stripe_amount']));
    $amount = str_replace('$', '', $amount) * 100;
    $card = sanitize_text_field($_POST['stripeToken']);
    $widget_comment = '';
    if (empty($_POST['wp_stripe_comment'])) {
        $stripe_comment = __('E-mail: ', 'wp-stipe') . sanitize_text_field($_POST['wp_stripe_email']) . ' - ' . __('This transaction has no additional details', 'wp-stripe');
    } else {
        $stripe_comment = __('E-mail: ', 'wp-stipe') . sanitize_text_field($_POST['wp_stripe_email']) . ' - ' . sanitize_text_field($_POST['wp_stripe_comment']);
        $widget_comment = sanitize_text_field($_POST['wp_stripe_comment']);
    }
    // Create Charge
    try {
        $response = wp_stripe_charge($amount, $card, $name, $stripe_comment);
        $id = $response->id;
        $amount = $response->amount / 100;
        $currency = $response->currency;
        $created = $response->created;
        $live = $response->livemode;
        $paid = $response->paid;
        if (isset($response->fee)) {
            $fee = $response->fee;
        }
        $result = '<div class="wp-stripe-notification alert alert-success"> ' . sprintf(__('Success, you just transferred %s', 'wp-stripe'), '<span class="wp-stripe-currency">' . esc_html($currency) . '</span> ' . esc_html($amount)) . ' !</div>';
        // Save Charge
        if ($paid === true) {
            $post_id = wp_insert_post(array('post_type' => 'wp-stripe-trx', 'post_author' => 1, 'post_content' => $widget_comment, 'post_title' => $id, 'post_status' => 'publish'));
            // Define Livemode
            if ($live) {
                $live = 'LIVE';
            } else {
                $live = 'TEST';
            }
            // Define Public (for Widget)
            if ($public === 'public') {
                $public = 'YES';
            } else {
                $public = 'NO';
            }
            // Update Meta
            update_post_meta($post_id, 'wp-stripe-public', $public);
            update_post_meta($post_id, 'wp-stripe-name', $name);
            update_post_meta($post_id, 'wp-stripe-email', $email);
            update_post_meta($post_id, 'wp-stripe-live', $live);
            update_post_meta($post_id, 'wp-stripe-date', $created);
            update_post_meta($post_id, 'wp-stripe-amount', $amount);
            update_post_meta($post_id, 'wp-stripe-currency', strtoupper($currency));
            if (isset($fee)) {
                update_post_meta($post_id, 'wp-stripe-fee', $fee);
            }
            do_action('wp_stripe_post_successful_charge', $response, $email, $stripe_comment);
            // Update Project
            // wp_stripe_update_project_transactions( 'add', $project_id , $post_id );
        }
        // Error
    } catch (Exception $e) {
        $result = '<div class="wp-stripe-notification wp-stripe-failure">' . sprint_f(__('Oops, something went wrong (%s)', 'wp-stripe'), $e->getMessage()) . '</div>';
        do_action('wp_stripe_post_fail_charge', $email, $e->getMessage());
    }
    // Return Results to JS
    header('Content-Type: application/json');
    echo json_encode($result);
    exit;
}
 public function Terminate()
 {
     if ($this->GetStatus() == BackgroundProcess::TERMINATED) {
         return TRUE;
     }
     SysLog::Log('Terminating child process...', 'BgProcess');
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         // windows family
         $exe = Configuration::Instance()->GetValue('background_process', 'win_kill_exe');
         if (file_exists($exe)) {
             exec(sprintf($exe . ' ' . Configuration::Instance()->GetValue('background_process', 'win_kill_args'), $this->mRealProcessId), $output, $result);
             SysLog::Log('Terminating child process using ' . $exe . ': got ' . implode("\n", $output) . ', result ' . $result, 'BgProcess');
         }
     } else {
         // assumes *nix family
         $killed = FALSE;
         if (function_exists('posix_kill')) {
             // preferred way
             if (!defined('SIGKILL')) {
                 define('SIGKILL', 9);
             }
             // assumes sigkill constant = 9
             if (posix_kill($this->mRealProcessId, SIGKILL)) {
                 SysLog::Log('Terminating child process using posix_kill(): succeded', 'BgProcess');
                 $killed = TRUE;
             } else {
                 SysLog::Log('Terminating child process using posix_kill(): failed', 'BgProcess');
             }
         }
         // alternative way
         $bin = Configuration::Instance()->GetValue('background_process', 'unix_kill_bin');
         if (file_exists($bin) && !$killed) {
             exec(sprint_f($bin . ' ' . Configuration::Instance()->GetValue('background_process', 'unix_kill_args'), $this->mRealProcessId), $output, $result);
             SysLog::Log('Terminating child process using ' . $bin . ': got ' . implode("\n", $output) . ', result ' . $result, 'BgProcess');
         }
     }
     $this->mStatus = $this->GetStatus();
     return $this->mStatus == BackgroundProcess::TERMINATED;
 }
 public function ajax_callback()
 {
     if (isset($_POST['type'])) {
         $type = $_POST['type'];
     }
     $offset = 0;
     switch ($type) {
         case 'general':
             $args = array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'any', 'offset' => 0);
             if (isset($_POST['period'])) {
                 $period = $_POST['period'];
                 switch ($period) {
                     case '0':
                         break;
                     case '1':
                         $date = '-1 day';
                         break;
                     case '2':
                         $date = '-1 week';
                         //                            echo $date;
                         break;
                     case '3':
                         $date = '-1 month';
                         break;
                     case '4':
                         $date = $_POST['fromTo'];
                         break;
                 }
             }
             if (!empty($date)) {
                 $fromTo = explode('-', $date);
                 $startDate = date("m/d/Y", strtotime($fromTo[0] . " -1 day"));
                 $endDate = date("m/d/Y", strtotime($fromTo[1] . " +1 day"));
                 if (!empty($startDate) && empty($endDate)) {
                     $args['date_query'] = array('after' => $startDate);
                 } elseif (!empty($endDate) && empty($startDate)) {
                     $args['date_query'] = array('before' => $endDate);
                 } elseif (!empty($startDate) && !empty($endDate)) {
                     $args['date_query'] = array('after' => $startDate, 'before' => $endDate);
                 }
             }
             $the_query = new WP_Query($args);
             $post_count = 0;
             if ($the_query->have_posts()) {
                 $post_count = $the_query->post_count;
             }
             wp_reset_query();
             wp_reset_postdata();
             //                $logstatus .= "<pre>" . print_r($the_query, true) . "</pre>";
             $return_arr = array('pCount' => $post_count, 'fromTo' => $date, 'type' => $_POST['type'], 'period' => $period);
             //                return the total number of results
             echo json_encode($return_arr);
             break;
         case 'submit':
             //                $logstatus = '';
             $error = array();
             if (isset($_POST['offset'])) {
                 $offset = $_POST['offset'];
             }
             if (isset($_POST['period'])) {
                 $period = $_POST['period'];
                 $args = array('post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => 1, 'offset' => $offset, 'orderby' => 'ID', 'order' => 'DESC');
                 switch ($period) {
                     case '0':
                         break;
                     case '1':
                         $date = '-1 day';
                         break;
                     case '2':
                         $date = '-1 week';
                         break;
                     case '3':
                         $date = '-1 month';
                         break;
                     case '4':
                         $date = $_POST['fromTo'];
                         break;
                 }
             }
             $args = array('post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => 1, 'offset' => $offset);
             if ($period != 0 && isset($date)) {
                 if (!empty($date)) {
                     $fromTo = explode('-', $date);
                     $startDate = date("m/d/Y", strtotime($fromTo[0]));
                     $endDate = date("m/d/Y", strtotime($fromTo[1] . " +1 day"));
                     if (!empty($startDate) && empty($endDate)) {
                         $args['date_query'] = array('after' => $startDate);
                     } elseif (!empty($endDate) && empty($startDate)) {
                         $args['date_query'] = array('before' => $endDate);
                     } elseif (!empty($startDate) && !empty($endDate)) {
                         $args['date_query'] = array('after' => $startDate, 'before' => $endDate);
                     }
                 }
                 //                    $args = array_merge($args, $period_arr);
             }
             $the_query = new WP_Query($args);
             if ($the_query->have_posts()) {
                 while ($the_query->have_posts()) {
                     $the_query->the_post();
                     $image_id = $the_query->post->ID;
                     $is_image = true;
                     $fullsizepath = get_attached_file($image_id);
                     //is image:
                     if (!is_array(getimagesize($fullsizepath))) {
                         $is_image = false;
                     }
                     if ($is_image) {
                         if (false === $fullsizepath || !file_exists($fullsizepath)) {
                             $error[] = '<code>' . esc_html($fullsizepath) . '</code>';
                         }
                         @set_time_limit(900);
                         $metadata = wp_generate_attachment_metadata($image_id, $fullsizepath);
                         //get the attachment name
                         $filename_only = basename(get_attached_file($image_id));
                         if (is_wp_error($metadata)) {
                             $error[] = sprint_f("%s Image ID:%d", $metadata->get_error_message(), $image_id);
                         }
                         if (empty($metadata)) {
                             //$this->die_json_error_msg($image_id, __('Unknown failure reason.', 'regenerate-thumbnails'));
                             $error[] = sprint_f('Unknown failure reason. regenerate-thumbnails %d', $image_id);
                         } else {
                             wp_update_attachment_metadata($image_id, $metadata);
                         }
                         $logstatus = "<br/>" . $filename_only . " - <b>Processed</b>";
                     } else {
                         $filename_only = basename(get_attached_file($image_id));
                         $error[] = sprintf('Attachment (<b>%s</b> - ID:%d) is not an image. Skipping', $filename_only, $image_id);
                     }
                 }
             } else {
                 $error[] = "No pictures uploaded";
             }
             if (!extension_loaded('gd') && !function_exists('gd_info')) {
                 $error[] = "<b>PHP GD library is not installed</b> on your web server. Please install in order to have the ability to resize and crop images";
             }
             //increment offset
             $result = $offset + 1;
             //                $logstatus .= "<br/>".$the_query->post->ID;
             //                $logstatus .= "<br/><pre>" . print_r($args, true) . "</pre>";
             echo json_encode(array('offset' => $offset + 1, 'error' => $error, 'logstatus' => $logstatus, 'startTime' => $_POST['startTime'], 'fromTo' => $_POST['fromTo'], 'type' => $_POST['type'], 'period' => $period));
             break;
     }
     /* Restore original Post Data */
     wp_reset_query();
     wp_reset_postdata();
     wp_die();
 }