Пример #1
0
 public function update()
 {
     $orderEntity = false;
     if ($this->isPost()) {
         $tableName = zbase_entity('custom_orders')->getTable();
         $name = zbase_request_input('name', false);
         $orderId = zbase_request_input('order_id', false);
         $amount = zbase_request_input('amount', false);
         $validators = ['name' => 'required', 'amount' => 'required', 'order_id' => 'required|exists:' . $tableName . ',order_id,name,' . $name . ',total,' . number_format($amount, 2) . ',status,1', 'date' => 'required|date_format:Y-m-d|before:' . zbase_date_now()->addDay(), 'payment_center' => 'required', 'file' => 'required|image'];
         $messages = ['order_id.exists' => 'Order ID, Name and Amount don\'t match.', 'amount.required' => 'Enter the amount that you deposited or paid.', 'file.required' => 'Kindly upload your deposit or payment slip.', 'file.image' => 'The file you uploaded is not an image.'];
         $this->validate(zbase_request(), $validators, $messages);
         $folder = zbase_storage_path() . '/zivsluck/order/receipts/';
         $newFilename = zbase_file_name_from_file($_FILES['file']['name'], $orderId, true);
         $newFilename = zbase_file_upload_image('file', $folder, $newFilename, 'png', [280, null]);
         if (file_exists($newFilename)) {
             $orderEntity = zbase_entity('custom_orders')->repository()->byId($orderId);
             $orderEntity->status = 2;
             $orderEntity->payment_merchant = zbase_request_input('payment_center', null);
             $orderEntity->paid_date_at = zbase_request_input('date', null);
             $orderEntity->payment_tracking_number = zbase_request_input('payment_tracking', null);
             $orderEntity->save();
             $orderEntity->sendPaymentReceiptToShane();
         }
     }
     zbase_view_pagetitle_set('Update Order');
     return $this->view(zbase_view_file('order.update'), compact('orderEntity'));
 }
Пример #2
0
/**
 * Call Remote URL by Post
 * @param string $url The URL to call
 * @param array $data The data to post
 * @param array $options some options
 *
 * @return string
 */
function zbase_remote_post_json($url, $data, $options = [])
{
    $dataString = '';
    foreach ($data as $key => $value) {
        $dataString .= $key . '=' . $value . '&';
    }
    rtrim($dataString, '&');
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, count($data));
    curl_setopt($ch, CURLOPT_COOKIEJAR, zbase_storage_path() . 'cookie.txt');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($dataString)));
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
Пример #3
0
 public function watermark()
 {
     $folder = zbase_storage_path() . '/zivsluck/site/images/';
     $filename = str_replace('.png', '', zbase_route_input('f', false));
     $download = zbase_request_query_input('d', false);
     if (!empty($download)) {
         if (file_exists($folder . $filename . '.png')) {
             $w = new \Zivsluck\Models\Image();
             $w->watermark($folder . $filename . '.png');
             $w->download();
         }
     } else {
         if (file_exists($folder . $filename . '.png')) {
             $w = new \Zivsluck\Models\Image();
             $w->watermark($folder . $filename . '.png');
             $w->serve();
         }
     }
 }
Пример #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     zbase()->setConsoleCommand($this);
     $phpCommand = env('ZBASE_PHP_COMMAND', 'php');
     $packages = zbase()->packages();
     if (!empty($packages)) {
         foreach ($packages as $packageName) {
             $zbase = zbase_package($packageName);
             if ($zbase instanceof Interfaces\ClearCommandInterface) {
                 $this->info($this->signature . '.pre - ' . $packageName);
                 $zbase->clearCommand($phpCommand, ['clear.pre' => true, 'command' => $this]);
             }
         }
     }
     echo shell_exec($phpCommand . ' artisan clear-compiled');
     echo shell_exec($phpCommand . ' artisan cache:clear');
     echo shell_exec($phpCommand . ' artisan view:clear');
     echo shell_exec($phpCommand . ' artisan config:clear');
     echo shell_exec($phpCommand . ' artisan route:clear');
     \File::cleanDirectory(zbase_storage_path('tmp/images'));
     \File::cleanDirectory(zbase_storage_path(zbase_tag() . '_tmp/images'));
     $commands = [];
     // zbase()->commands('clear');
     if (!empty($commands)) {
         foreach ($commands as $command) {
             if ($command instanceof \Closure) {
                 $command();
             } else {
                 echo shell_exec($phpCommand . ' artisan ' . $command);
             }
         }
     }
     if (!empty($packages)) {
         foreach ($packages as $packageName) {
             $zbase = zbase_package($packageName);
             if ($zbase instanceof Interfaces\ClearCommandInterface) {
                 $this->info($this->signature . '.post - ' . $packageName);
                 $zbase->clearCommand($phpCommand, ['clear.post' => true, 'command' => $this]);
             }
         }
     }
 }
Пример #5
0
 public function create($text, $font = null, $material = null, $options = null)
 {
     if (!empty($text)) {
         $this->setText($text);
     }
     if (!empty($font)) {
         $this->setFont($font);
     }
     if (!$this->orderData instanceof \Zivsluck\Entity\Laravel\Order && !empty($options['oid'])) {
         $orderData = zbase_entity('custom_orders')->repository()->byId($options['oid']);
         if (empty($orderData)) {
             return zbase_abort(404);
         }
         $this->setOrderData($orderData);
     }
     $tags = [];
     $dealerCopy = !empty($options['dealerCopy']) ? true : false;
     /**
      * <span id="IL_AD8" class="IL_AD">Setup</span> some custom variables for creating our font and image.
      */
     $chain = !empty($options['chain']) ? $options['chain'] : false;
     $chainLength = !empty($options['chainLength']) ? $options['chainLength'] : false;
     $maxLetter = 7;
     $pricePerLetter = 20;
     $boxWidth = 280;
     $boxHeight = 200;
     $brandingHeightPosition = 200;
     $borderWidth = 10;
     $hasBorder = !empty($dealerCopy) ? true : false;
     $hasDetails = false;
     $fontsNotForMaterial = zbase_config_get('zivsluck.chains.' . $material . '.fonts.not', []);
     $fontNotForMaterial = false;
     $posYDiff = 0;
     if (!empty($fontsNotForMaterial)) {
         if (in_array($font, $fontsNotForMaterial)) {
             $fontNotForMaterial = true;
         }
     }
     if (!empty($chain) && !empty($chainLength)) {
         $hasDetails = true;
         $boxWidth = 280;
         $boxHeight = 600;
         $brandingHeightPosition = 600;
         $chainFile = zbase_config_get('zivsluck.chains.' . strtolower($material) . '.' . strtolower($chain) . '.file', false);
         $chainImage = zbase_public_path() . '/zbase/assets/zivsluck/img/chain/' . $chainFile;
         $tags[] = $chain;
     }
     $letterPrice = 0;
     $shippingFee = 0;
     $hasShipping = false;
     $total = 0;
     $courier = !empty($options['courier']) ? $options['courier'] : false;
     if (!empty($courier)) {
         $courier = zbase_config_get('zivsluck.shipping.' . strtolower($courier), false);
         if (!empty($courier)) {
             $deliveryMode = !empty($options['deliveryMode']) ? $options['deliveryMode'] : false;
             $hasShipping = true;
             $courierName = $courier['name'];
             if ($deliveryMode == 'meetup') {
                 $courierText = 'Meet Up';
                 $shippingFee = 0.0;
             } else {
                 $shippingFee = $courier['fee'];
                 $courierText = $courierName . ' - ' . ($deliveryMode == 'doortodoor' ? 'Door-to-Door' : 'PickUp');
             }
             $boxWidth = 280;
             $boxHeight = 800;
             $brandingHeightPosition = 800;
         }
         if (empty($options['shippingSame'])) {
             $options['shippingFirstName'] = $options['first_name'];
             $options['shippingLastName'] = $options['last_name'];
         }
     }
     $customerNote = !empty($options['customerNote']) ? $options['customerNote'] : '';
     $orderData = $this->getOrderData();
     $statusNew = false;
     $statusPaid = false;
     if (!empty($orderData)) {
         $statusPaid = $orderData->status == 2;
         if (!empty($options['download']) && $orderData->status == 1) {
             $boxWidth = 280;
             $boxHeight = 800 + 380;
             $posYDiff = 190;
             $brandingHeightPosition = 800;
             $statusNew = true;
         }
         if (!empty($statusPaid)) {
             $paymentCenterName = zbase_config_get('zivsluck.paymentCenters.' . $orderData->payment_merchant . '.shortName');
             $paymentAmount = $orderData->total;
             if (file_exists(zbase_storage_path() . '/zivsluck/order/receipts/' . $orderData->maskedId() . '.png')) {
                 $paymentDetailsIm = imagecreatefrompng(zbase_storage_path() . '/zivsluck/order/receipts/' . $orderData->maskedId() . '.png');
                 $boxHeight = $boxHeight + imagesy($paymentDetailsIm);
                 $posYDiff = imagesy($paymentDetailsIm) / 2;
                 $brandingHeightPosition = 800;
             }
         }
     }
     $price = zbase_config_get('zivsluck.price.' . $material, false);
     $fontSize = 30;
     // font size
     $chars = 30;
     $fontFile = zbase_public_path() . '/zbase/assets/zivsluck/fonts/deftonestylus.ttf';
     // the text file to be used
     $verdanaFont = zbase_public_path() . '/zbase/assets/zivsluck/fonts/verdana.ttf';
     // the text file to be used
     $textureFile = zivsluck()->path() . 'resources/assets/img/texture/' . strtolower($material) . '.png';
     // the texture file
     $logo = zivsluck()->path() . 'resources/assets/img/texture/logo.png';
     // the texture file
     $paymentDetails = zivsluck()->path() . 'resources/assets/img/payments/bayadCenter.png';
     // the texture file
     $fontDetails = $this->getFontDetails();
     $tags[] = $material;
     $tags[] = $font;
     if (!empty($dealerCopy)) {
         $boxWidth = 280;
         $boxHeight = 500;
         $brandingHeightPosition = 500;
         $posYDiff = 0;
     }
     /**
      * Get text string that is <span id="IL_AD7" class="IL_AD">passed</span> to this file and clean it up.
      */
     $text = $this->getText();
     $text = trim(strip_tags(html_entity_decode($text)));
     // $text = trim(preg_replace('/ss+/', ' ', $text));
     $text = strlen($text) > $chars ? substr($text, 0, $chars) . '..' : $text;
     if (!empty($fontDetails['enable'])) {
         $fontFile = zbase_public_path() . '/zbase/assets/zivsluck/fonts/' . $fontDetails['file'];
         if (!empty($fontDetails['fontsize'])) {
             $fontSize = $fontDetails['fontsize'];
         }
     } else {
         $fontFile = $verdanaFont;
         $text = 'FONT NOT AVAILABLE.';
     }
     if ($fontNotForMaterial) {
         $fontFile = $verdanaFont;
         $fontSize = 14;
         // font size
         $text = wordwrap("ERROR: \nFONT NOT FOR " . strtoupper($material) . ". \nSelect another font.", 20);
         $hasDetails = false;
         $boxWidth = 280;
         $boxHeight = 200;
         $brandingHeightPosition = 200;
     }
     // <editor-fold defaultstate="collapsed" desc="Image Printin">
     /**
      * Read the TTF file and get the width and height of our font.
      */
     $box = imagettfbbox($fontSize, 0, $fontFile, $text);
     $width = abs($box[2] - $box[0]) + 50;
     /**
      * Create <span id="IL_AD2" class="IL_AD">the blank</span> image, alpha channel and colors.
      */
     // http://stackoverflow.com/questions/26288347/php-gd-complex-stacking-multiple-layers
     // $clipart = imagecreatefrompng(zivsluck()->path() . 'resources/assets/img/createBaseImage.png');
     $bgTexture = imagecreatefrompng($textureFile);
     $noBg = !empty(zbase_cookie('nobg')) ? true : false;
     $logo = imagecreatefrompng($logo);
     $white = imagecolorallocate($bgTexture, 255, 255, 255);
     if ($dealerCopy) {
         // Canvass
         $bgTexture = imagecreatetruecolor($boxWidth - $borderWidth * 2, $boxHeight - $borderWidth * 2);
         // Background Color
         $white = imagecolorallocate($bgTexture, 255, 255, 255);
     }
     if (!empty($noBg)) {
         $bgTexture = imagecreatetruecolor($boxWidth, $boxHeight);
     }
     /**
      * Create text on a white background
      */
     imagefill($bgTexture, 0, 0, $white);
     $textColorBlack = imagecolorallocate($bgTexture, 0, 0, 0);
     if (empty($posY)) {
         if ($hasDetails) {
             if ($hasShipping) {
                 $posY = $boxHeight / 2 + 10 - 300 - $posYDiff;
             } else {
                 $posY = $boxHeight / 2 + 10 - 200 - $posYDiff;
             }
         } else {
             $posY = $boxHeight / 2 + 10 - $posYDiff;
         }
         $posX = $boxWidth / 2 - $width / 2 + 10;
         if (!empty($hasBorder)) {
             $posY = $boxHeight / 2 + 10 - 150 - $borderWidth - $posYDiff;
             $posX = $boxWidth / 2 - $width / 2;
         }
     }
     if ($fontNotForMaterial) {
         imagettftext($bgTexture, $fontSize, 0, $posX, 60, $textColorBlack, $fontFile, $text);
     } else {
         imagettftext($bgTexture, $fontSize, 0, $posX, $posY, $textColorBlack, $fontFile, $text);
     }
     $im = imagecreatetruecolor($boxWidth, $boxHeight);
     if (!empty($dealerCopy)) {
         imagecopy($im, $bgTexture, $borderWidth, $borderWidth, 0, 0, $boxWidth, $boxHeight);
     } else {
         imagecopy($im, $bgTexture, 0, 0, 0, 0, $boxWidth, $boxHeight);
     }
     $img = imagecreatetruecolor($boxWidth, $boxHeight);
     imagecopymerge($img, $im, 0, 0, 0, 0, $boxWidth, $boxHeight, 100);
     if ($hasBorder) {
         imagecopy($img, $logo, 234, $brandingHeightPosition - 45, 0, 0, imagesx($logo), imagesy($logo));
     } else {
         imagecopy($img, $logo, 245, $brandingHeightPosition - 35, 0, 0, $boxWidth, $boxHeight);
     }
     if (!empty($dealerCopy)) {
         // Add border
         imagefilltoborder($img, 1, 1, $textColorBlack, $white);
     }
     // </editor-fold>
     // <editor-fold defaultstate="collapsed" desc="ADDON">
     $totalAddon = 0;
     if (!empty($options['addon'])) {
         $addonDroppableTop = zbase_config_get('zivsluck.addons.configuration.droppable.top') - 5;
         $addonDroppableLeft = zbase_config_get('zivsluck.addons.configuration.droppable.left') - 5;
         $addonDroppableHeight = zbase_config_get('zivsluck.addons.configuration.droppable.height');
         $addonDroppableWidth = zbase_config_get('zivsluck.addons.configuration.droppable.width');
         $addons = explode('|', $options['addon']);
         $includedAddons = [];
         foreach ($addons as $addon) {
             if (!empty($addon)) {
                 //					$addon = explode('-', $addon);
                 //					$addonName = !empty($addon[0]) ? $addon[0] : false;
                 //					$addonEnabled = zbase_config_get('zivsluck.addons.' . $addonName . '.enable');
                 //					$addonFile = zivsluck()->path() . 'resources/assets/img/addons/' . zbase_config_get('zivsluck.addons.' . $addonName . '.file');
                 //					$addonPosition = !empty($addon[1]) ? explode(',', $addon[1]) : false;
                 //					$addonSize = !empty($addon[2]) ? explode('x', $addon[2]) : false;
                 //					$addonRotate = intval(!empty($addon[3]) ? $addon[3] : false);
                 $addon = explode('-', $addon);
                 $addonName = !empty($addon[0]) ? $addon[0] : false;
                 $addonEnabled = true;
                 //zbase_config_get('zivsluck.addons.' . $addonName . '.enable');
                 $addonFile = zivsluck()->path() . 'resources/assets/img/addons/' . $addonName . '.png';
                 $addonPosition = !empty($addon[1]) ? explode(',', $addon[1]) : false;
                 $addonSize = !empty($addon[2]) ? explode('x', $addon[2]) : false;
                 $addonRotate = intval(!empty($addon[3]) ? $addon[3] : false);
                 if (!empty($addonEnabled) && file_exists($addonFile)) {
                     if (!in_array($addonName, $tags)) {
                         $tags[] = $addonName;
                     }
                     $includedAddons[] = $addonName;
                     $addonNewImage = imagecreatetruecolor($addonSize[0], $addonSize[1]);
                     $transparent = imagecolorallocatealpha($addonNewImage, 0, 0, 0, 127);
                     $addonFile = imagecreatefrompng($addonFile);
                     if (!empty($addonRotate)) {
                         $addonFile = imagerotate($addonFile, 360 - $addonRotate, imageColorAllocateAlpha($addonFile, 0, 0, 0, 127));
                     }
                     if (empty($addonSize[0])) {
                         $addonSize[0] = imagesx($addonFile);
                     }
                     if (empty($addonSize[1])) {
                         $addonSize[1] = imagesy($addonFile);
                     }
                     imagefill($addonNewImage, 0, 0, $transparent);
                     imagecopyresampled($addonNewImage, $addonFile, 0, 0, 0, 0, $addonSize[0], $addonSize[1], imagesx($addonFile), imagesy($addonFile));
                     $totalAddon++;
                     imagecopy($img, $addonNewImage, $addonPosition[0] + $addonDroppableLeft, $addonPosition[1] + $addonDroppableTop, 0, 0, $addonSize[0], $addonSize[1]);
                 }
             }
         }
     }
     // </editor-fold>
     // <editor-fold defaultstate="collapsed" desc="Checkout Details">
     if ($hasDetails) {
         // <editor-fold defaultstate="collapsed" desc="DISCOUNT">
         $discountInPrice = zbase_config_get('zivsluck.promotion.discount', 0.0);
         if (!empty($orderData) && !empty($options['final'])) {
             $promo = !empty($options['promo_flag']) ? true : false;
             if (!empty($promo)) {
                 $discountInPrice = $options['promo_discountprice'];
                 $shippingFee = $options['promo_shipping_fee'];
                 $associateOrderId = $options['promo_associate_order_id'];
             } else {
                 if (!empty($options['promo_associate_order_id'])) {
                     $associateOrderId = $options['promo_associate_order_id'];
                 }
             }
         } else {
             $promo = $this->_discountOnNextOrder($text, $font, $material, $options);
             $options['promo_flag'] = 0;
             if (!empty($promo)) {
                 $promoOrder = $promo;
                 $promo = true;
                 $options['promo_flag'] = 1;
                 $shippingFee = 0.0;
                 $options['promo_discountprice'] = $discountInPrice;
                 $options['promo_shipping_fee'] = $shippingFee;
                 $options['promo_associate_order_id'] = $promoOrder->id();
                 $associateOrderId = $promoOrder->id();
             }
         }
         // </editor-fold>
         if (empty($dealerCopy)) {
             $chainImage = imagecreatefrompng($chainImage);
             $total = $price;
             $subTotal = $price;
             $letterCount = strlen($text);
             $addonPrice = 0;
             $totalCharacters = $letterCount + $totalAddon;
             if ($totalCharacters > $maxLetter) {
                 if ($letterCount > $maxLetter) {
                     if (!empty($totalAddon)) {
                         $addonCount = $letterCount + $totalAddon - $maxLetter;
                         $addonPrice = $addonCount * 20;
                         $total += $addonPrice;
                         $subTotal += $addonPrice;
                     }
                 } else {
                     $totalAddon = $totalCharacters - $maxLetter;
                     $addonPrice = $totalAddon * 20;
                 }
             }
             //				if($letterCount < $maxLetter)
             //				{
             //					if(!empty($totalAddon))
             //					{
             //						$addonCount = ($letterCount + $totalAddon) - $maxLetter;
             //						$addonPrice = $addonCount * 20;
             //						$total += $addonPrice;
             //						$subTotal += $addonPrice;
             //					}
             //				}
             //				if($letterCount > $maxLetter)
             //				{
             //					$letterPrice = ($letterCount - $maxLetter) * 20;
             //					$total += $letterPrice;
             //					$addonPrice = $totalAddon * 20;
             //					$total += $addonPrice;
             //					$subTotal += $addonPrice;
             //				}
             $total += $shippingFee;
             if (!empty($promo)) {
                 $total -= $discountInPrice;
             }
             if (!empty($orderData)) {
                 imagettftext($img, 12, 0, 15, 180, $textColorBlack, $verdanaFont, 'ORDER ID: ' . $orderData->maskedId());
             }
             imagecopy($img, $chainImage, 15, 295, 0, 0, imagesx($chainImage), imagesy($chainImage));
         }
         if (!empty($dealerCopy)) {
             imagettftext($img, 9, 0, 25, 200, $textColorBlack, $verdanaFont, 'Text: ' . $text);
             imagettftext($img, 9, 0, 25, 220, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']);
             imagettftext($img, 9, 0, 25, 240, $textColorBlack, $verdanaFont, 'Material: ' . ucfirst($material));
             imagettftext($img, 9, 0, 25, 260, $textColorBlack, $verdanaFont, 'Chain: ' . strtoupper($chain));
             imagettftext($img, 9, 0, 25, 280, $textColorBlack, $verdanaFont, 'Chain Length: ' . $chainLength . '"');
             if (!empty($includedAddons)) {
                 imagettftext($img, 8, 0, 25, 300, $textColorBlack, $verdanaFont, 'Included Addons:');
                 imagettftext($img, 8, 0, 25, 320, $textColorBlack, $verdanaFont, wordwrap(implode(', ', $includedAddons), 30));
             }
             if (!empty($customerNote)) {
                 imagettftext($img, 9, 0, 25, 360, $textColorBlack, $verdanaFont, 'Customer Note:');
                 imagettftext($img, 8, 0, 25, 380, $textColorBlack, $verdanaFont, wordwrap($customerNote, 40));
             }
         } else {
             imagettftext($img, 9, 0, 15, 200, $textColorBlack, $verdanaFont, 'Text: ' . $text);
             imagettftext($img, 9, 0, 15, 215, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']);
             imagettftext($img, 9, 0, 15, 230, $textColorBlack, $verdanaFont, 'Character: ' . strlen($text));
             imagettftext($img, 9, 0, 15, 245, $textColorBlack, $verdanaFont, 'Symbols: ' . $totalAddon);
             imagettftext($img, 9, 0, 15, 260, $textColorBlack, $verdanaFont, 'Material: ' . ucfirst($material));
             imagettftext($img, 9, 0, 15, 275, $textColorBlack, $verdanaFont, 'Chain Length: ' . $chainLength . '"');
             imagettftext($img, 9, 0, 15, 290, $textColorBlack, $verdanaFont, 'Chain: ' . strtoupper($chain));
             if (!empty($this->displayPrice)) {
                 imagettftext($img, 9, 0, 15, 430, $textColorBlack, $verdanaFont, ucfirst($material) . ' Price: Php ' . number_format($price, 2));
                 imagettftext($img, 9, 0, 15, 445, $textColorBlack, $verdanaFont, 'Characters: Php ' . number_format($letterPrice, 2));
                 imagettftext($img, 9, 0, 15, 460, $textColorBlack, $verdanaFont, 'Symbols: Php ' . number_format($addonPrice, 2));
             }
             if ($hasShipping) {
                 imagettftext($img, 9, 0, 15, 475, $textColorBlack, $verdanaFont, 'Shipping: Php ' . number_format($shippingFee, 2));
                 imagettftext($img, 9, 0, 15, 490, $textColorBlack, $verdanaFont, 'Courier: ' . $courierText);
                 if (!empty($promo)) {
                     imagettftext($img, 9, 0, 15, 505, $textColorBlack, $verdanaFont, 'Discount: ' . number_format($discountInPrice, 2) . ' (Order#' . $associateOrderId . ')');
                 } else {
                     if (!empty($associateOrderId)) {
                         imagettftext($img, 9, 0, 15, 505, $textColorBlack, $verdanaFont, 'Associate Order Id: ' . $associateOrderId);
                     }
                 }
                 imagettftext($img, 9, 0, 15, 580, $textColorBlack, $verdanaFont, 'Shipping Information:');
                 imagettftext($img, 9, 0, 15, 600, $textColorBlack, $verdanaFont, $options['shippingFirstName'] . ' ' . $options['shippingLastName']);
                 imagettftext($img, 9, 0, 15, 615, $textColorBlack, $verdanaFont, $options['address']);
                 imagettftext($img, 9, 0, 15, 630, $textColorBlack, $verdanaFont, $options['addressb']);
                 imagettftext($img, 9, 0, 15, 645, $textColorBlack, $verdanaFont, $options['city']);
                 imagettftext($img, 8, 0, 15, 665, $textColorBlack, $verdanaFont, 'Ordered By: ' . $options['first_name'] . ' ' . $options['last_name']);
                 imagettftext($img, 8, 0, 15, 680, $textColorBlack, $verdanaFont, $options['fb']);
                 imagettftext($img, 8, 0, 15, 695, $textColorBlack, $verdanaFont, 'Phone: ' . $options['phone']);
                 if (!empty($options['email'])) {
                     imagettftext($img, 8, 0, 15, 710, $textColorBlack, $verdanaFont, 'Email: ' . $options['email']);
                 }
                 if (!empty($options['oid'])) {
                     imagettftext($img, 8, 0, 15, 748, $textColorBlack, $verdanaFont, 'Order Link: ' . zbase_url_create('order', array('id' => $options['oid'])));
                 }
                 imagettftext($img, 8, 0, 15, 760, $textColorBlack, $verdanaFont, 'Date: ' . date('F d, Y h:i A'));
             }
             if (!empty($this->displayPrice)) {
                 imagettftext($img, 18, 0, 15, 540, $textColorBlack, $verdanaFont, 'Total: Php ' . number_format($total, 2));
             }
             if (!empty($statusPaid)) {
                 imagettftext($img, 9, 0, 15, 555, $textColorBlack, $verdanaFont, 'PAID ' . number_format($paymentAmount, 2) . ' via ' . $paymentCenterName . ' (' . $orderData->paid_date_at->format('m/d/Y') . ')');
             }
             if (!empty($orderData) && $orderData->status == 1 && !empty($options['step']) && $options['step'] == 5) {
                 $orderData->total = $total;
                 $orderData->subtotal = $subTotal;
                 $orderData->shipping_fee = $shippingFee;
                 unset($options['step']);
                 $options['final'] = 1;
                 if (!empty($promoOrder)) {
                     $orderData->promo_flag = 1;
                 }
                 $orderData->details = json_encode($options);
                 if (!empty($tags)) {
                     $orderData->tags = implode(', ', $tags);
                 }
                 $orderData->save();
                 if (!empty($promoOrder)) {
                     $promoOrderDetails = (array) $promoOrder->details();
                     $promoOrderDetails['promo_associate_order_id'] = $orderData->id();
                     $promoOrder->details = json_encode($promoOrderDetails);
                     $promoOrder->promo_flag = 1;
                     $promoOrder->save();
                 }
             }
         }
     } else {
         imagettftext($img, 9, 0, 15, 23, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']);
     }
     if (!empty($hasBorder)) {
         imagettftext($img, 7, 0, 15, $brandingHeightPosition - (10 + $borderWidth), $textColorBlack, $verdanaFont, 'Create your necklace at http://zivsluck.com');
     } else {
         imagettftext($img, 7, 0, 15, $brandingHeightPosition - 10, $textColorBlack, $verdanaFont, 'Create your necklace at http://zivsluck.com');
     }
     if (!empty($statusNew)) {
         $paymentDetailsIm = imagecreatefrompng($paymentDetails);
         imagecopy($img, $paymentDetailsIm, 0, 800, 0, 0, $boxWidth, $boxHeight);
     }
     if (!empty($statusPaid) && empty($dealerCopy)) {
         if (!empty($paymentDetailsIm)) {
             imagecopy($img, $paymentDetailsIm, 0, 800, 0, 0, $boxWidth, $boxHeight);
         }
     }
     // </editor-fold>
     /**
      * Label
      */
     $this->_image = $img;
     return $this;
 }
Пример #6
0
/**
 * Log to File
 * @param string $msg the mssg to write
 * @param string $type Type of Log
 * @param string $logFile the file to write the log
 * @param string|Entity The entity to save the log
 * @return null
 */
function zbase_log($msg, $type = null, $logFile = null, $entity = null)
{
    if (!empty($msg) && is_array($msg)) {
        $msg = implode(PHP_EOL, $msg);
    }
    if (!empty($entity)) {
        if (!$entity instanceof \Zbase\Interfaces\EntityInterface) {
            $entity = zbase_entity($entity);
        }
        if ($entity instanceof \Zbase\Interfaces\EntityLogInterface) {
            $options = [];
            zbase_entity($entity)->log($msg, $type, $options);
            return;
        }
    }
    $folder = zbase_storage_path() . '/logs/' . date('Y/m/d/');
    zbase_directory_check($folder, true);
    $file = !empty($logFile) ? $logFile : 'log.txt';
    $file = str_replace(array('/', '\\', ':'), '_', $file);
    if (preg_match('/.txt/', $file) == 0) {
        $file .= '.txt';
    }
    $msg = date('Y-m-d H:i:s') . ' : ' . zbase_ip() . PHP_EOL . $msg . PHP_EOL . "--------------------" . PHP_EOL;
    file_put_contents($folder . $file, $msg . PHP_EOL, FILE_APPEND);
}
Пример #7
0
 /**
  * Upload a file for this node
  * @param string $index The Upload file name/index or the URL to file to download and save
  * @return void
  */
 public function uploadNodeFile($index = 'file')
 {
     try {
         $folder = zbase_storage_path() . '/' . zbase_tag() . '/' . static::$nodeNamePrefix . '_category' . '/' . $this->id() . '/';
         zbase_directory_check($folder, true);
         if (!empty($_FILES[$index]['name'])) {
             $filename = $this->alphaId();
             //zbase_file_name_from_file($_FILES[$index]['name'], time(), true);
             $uploadedFile = zbase_file_upload_image($index, $folder, $filename, zbase_config_get('node.files.image.format', 'png'));
         }
         if (!empty($uploadedFile) && zbase_file_exists($uploadedFile)) {
             $filename = basename($uploadedFile);
             $this->setDataOption('avatar', $filename);
             $this->save();
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         if (zbase_is_dev()) {
             dd($e);
         }
         zbase_abort(500);
     }
 }
Пример #8
0
 /**
  * Upload a file for this node
  * @param string $index The Upload file name/index or the URL to file to download and save
  * @return void
  */
 public function uploadNodeFile($index = 'file')
 {
     try {
         $defaultImageFormat = zbase_config_get('node.files.image.format', 'png');
         $folder = zbase_storage_path() . '/' . zbase_tag() . '/' . static::$nodeNamePrefix . '/' . $this->id() . '/';
         zbase_directory_check($folder, true);
         $nodeFileObject = zbase_entity(static::$nodeNamePrefix . '_files', [], true);
         $nodeFiles = $this->files()->get();
         if (preg_match('/http\\:/', $index) || preg_match('/https\\:/', $index)) {
             // File given is a URL
             if ($nodeFileObject->isUrlToFile()) {
                 $filename = zbase_file_name_from_file(basename($index), time(), true);
                 $uploadedFile = zbase_file_download_from_url($index, $folder . $filename);
             } else {
                 $nodeFiles = $this->files()->get();
                 $nodeFileObject->is_primary = empty($nodeFiles) ? 1 : 0;
                 $nodeFileObject->status = 2;
                 $nodeFileObject->mimetype = null;
                 $nodeFileObject->size = null;
                 $nodeFileObject->filename = null;
                 $nodeFileObject->url = $index;
                 $nodeFileObject->node_id = $this->id();
                 $nodeFileObject->save();
                 $this->files()->save($nodeFileObject);
                 return $nodeFileObject;
             }
         }
         if (zbase_file_exists($index)) {
             $uploadedFile = $index;
             $filename = basename($index);
         }
         if (!empty($_FILES[$index]['name'])) {
             $filename = zbase_file_name_from_file($_FILES[$index]['name'], time(), true);
             $uploadedFile = zbase_file_upload_image($index, $folder, $filename, $defaultImageFormat);
         }
         if (!empty($uploadedFile) && zbase_file_exists($uploadedFile)) {
             $nodeFileObject->is_primary = empty($nodeFiles) ? 1 : 0;
             $nodeFileObject->status = 2;
             $nodeFileObject->mimetype = zbase_file_mime_type($uploadedFile);
             $nodeFileObject->size = zbase_file_size($uploadedFile);
             $nodeFileObject->filename = basename($uploadedFile);
             $nodeFileObject->node_id = $this->id();
             $nodeFileObject->save();
             $this->files()->save($nodeFileObject);
             return $nodeFileObject;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         if (zbase_is_dev()) {
             dd($e);
         }
         zbase_abort(500);
     }
 }
Пример #9
0
 /**
  * Send Order pHoto to Shane
  */
 public function sendPaymentReceiptToShane()
 {
     $token = zbase_config_get('zivsluck.telegram.bot.token');
     $shane = zbase_config_get('zivsluck.telegram.shane');
     $enable = env('ZIVSLUCK_TELEGRAM', zbase_config_get('zivsluck.telegram.enable', false));
     if ($enable) {
         $folder = zbase_storage_path() . '/zivsluck/order/receipts/';
         $image = $folder . $this->id() . '.png';
         $url = 'https://api.telegram.org/bot' . $token . '/sendPhoto?chat_id=' . $shane;
         $post_fields = array('chat_id' => $shane, 'photo' => new \CURLFile(realpath($image)), 'caption' => 'Payment received from ' . $this->name . ' via ' . $this->paymentMerchant() . ' for Order ID ' . $this->maskedId());
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
         curl_exec($ch);
     }
 }
Пример #10
0
 /**
  * Return the File Upload Folder
  *
  * @return string
  */
 public function postFileUploadFolder($tmp = false)
 {
     if (method_exists($this, 'fileUploadFolder')) {
         return $this->fileUploadFolder($tmp);
     }
     return zbase_storage_path() . '/' . zbase_tag() . '/' . $this->postTableName() . '/' . $this->postId() . '/';
 }
Пример #11
0
 /**
  * Return the Folder Path
  * @return string
  */
 public function folder()
 {
     $path = zbase_storage_path() . '/' . zbase_tag() . '/' . static::$nodeNamePrefix . '/';
     if (!empty($this->node_id)) {
         $path .= $this->node_id . '/';
     }
     return $path;
 }
Пример #12
0
 /**
  * Serve the File
  * @param integer $width
  * @param integer $height
  * @param integer $quality Image Quality
  * @param boolean $download If to download
  * @return boolean
  */
 public function serveImage($width, $height = null, $quality = null, $download = false, $image = null)
 {
     $folder = zbase_storage_path() . '/' . zbase_tag() . '/user/' . $this->id() . '/';
     if (!empty($image)) {
         $path = $folder . $image;
     } else {
         $path = $folder . $this->avatar;
     }
     if (!class_exists('\\Image')) {
         $image = zbase_file_serve_image($path, $width, $height, $quality, $download);
         if (!empty($image)) {
             return \Response::make(readfile($image['src'], $image['size'])->header('Content-Type', $image['mime']));
         }
         return zbase_abort(404);
     }
     // dd($this, $path, file_exists($path));
     if (file_exists($path)) {
         $cachedImage = \Image::cache(function ($image) use($width, $height, $path) {
             if (empty($width)) {
                 $size = getimagesize($path);
                 $width = $size[0];
                 $height = $size[1];
             }
             if (!empty($width) && empty($height)) {
                 return $image->make($path)->resize($width, null, function ($constraint) {
                     $constraint->upsize();
                     $constraint->aspectRatio();
                 });
             }
             if (empty($width) && !empty($height)) {
                 return $image->make($path)->resize(null, $height, function ($constraint) {
                     $constraint->upsize();
                     $constraint->aspectRatio();
                 });
             }
             return $image->make($path)->resize($width, $height);
         });
         return \Response::make($cachedImage, 200, array('Content-Type' => 'image/png'));
     }
     return false;
 }
Пример #13
0
/**
 * Serve file/image publicly
 * Will create a file in the public folder and serve the public file
 * @param string $path Path to file original
 * @param int $width
 * @param int $height
 * @param int $quality
 * @param boolean $download
 *
 * @return array [src => '',size => '', mime => '']
 */
function zbase_file_serve_image($path, $width, $height, $quality = 80, $download = false)
{
    if (file_exists($path)) {
        $info = $path !== null ? getimagesize($path) : getimagesizefromstring($path);
        zbase_directory_check(zbase_storage_path('tmp/images'), true);
        $newFile = zbase_storage_path('tmp/images') . '/' . md5(basename($path) . '_' . $width . 'x' . $height);
        switch ($info[2]) {
            case IMAGETYPE_JPEG:
                $newFile = $newFile . '.jpg';
                break;
            case IMAGETYPE_GIF:
                $newFile = $newFile . '.gif';
                break;
            case IMAGETYPE_PNG:
                $newFile = $newFile . '.png';
                break;
            default:
                return false;
        }
        if (!file_exists($newFile)) {
            copy($path, $newFile);
            zbase_file_image_resize($newFile, null, $width, $height, true, 'file', true, false, $quality);
        }
        $mime = image_type_to_mime_type($info[2]);
        $size = filesize($newFile);
        return ['src' => $newFile, 'size' => $size, 'mime' => $mime];
    }
}
Пример #14
0
 /**
  * Return a new user Code
  *
  * @return string
  */
 public function checkUserCode(User $user)
 {
     $userCode = \DB::table('user_tokens')->where(['taggable_type' => 'telegram', 'user_id' => $user->id()])->first();
     if (!empty($userCode)) {
         $codeFile = zbase_storage_path() . '/tg/' . $userCode->token;
         if (file_exists($codeFile)) {
             $chatId = trim(file_get_contents($codeFile));
             if (!empty($chatId)) {
                 $user->setDataOption('telegram_chat_id', $chatId);
                 $user->save();
                 $user->clearEntityCacheById();
                 $this->send($user, 'Welcome, you have successfully enabled ' . zbase_site_name() . ' notifications.');
                 unlink($codeFile);
                 return true;
             }
         }
     }
     return false;
 }
Пример #15
0
 /**
  *
  */
 public function __construct()
 {
     $this->maintenanceFile = zbase_storage_path() . '/maintenance';
 }