Exemple #1
0
/**
 * Dump the passed variables
 *
 * @param  mixed $x
 * @return void
 */
function z($x)
{
    if (zbase_is_dev()) {
        array_map(function ($x) {
            (new Dumper())->dump($x);
        }, func_get_args());
    }
}
Exemple #2
0
 /**
  * Report or log an exception.
  *
  * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  *
  * @param  \Exception  $e
  * @return void
  */
 public function report(\Exception $e)
 {
     if (!zbase_is_dev()) {
         if ($e instanceof \Exception) {
             $error = $e->getMessage();
             if (preg_match('/failed to pass validation/', $error) == 0) {
                 zbase_messenger_error(['error' => $error]);
             }
         }
     }
     return parent::report($e);
 }
Exemple #3
0
 /**
  * HTML the ui
  * @return string
  */
 public function __toString()
 {
     $this->prepare();
     try {
         if (!is_null($this->_viewFile) && empty($this->_rendered)) {
             $this->_viewParams['ui'] = $this;
             $str = $this->htmlPreContent();
             $str .= zbase_view_render(zbase_view_file_contents($this->_viewFile), $this->getViewParams());
             $str .= $this->htmlPostContent();
             $this->_rendered = true;
             return $str;
         }
         return '';
     } catch (\Exception $e) {
         if (zbase_is_dev()) {
             dd($e);
         }
         zbase_abort(500);
     }
 }
Exemple #4
0
 /**
  *
  * @param array $columns
  * @param array $filters
  * [
  * 		'indexName' => [
  * 			['gt' => [
  * 				'field' => 'columnName',
  * 				'value' => 0
  * 			]
  * 		]
  * ]
  * @param array $sorting
  * 		e.g ['created_at' => 'desc']
  * 			['created_at' => 'desc', 'id' => 'asc']
  * 			['created_at' => 'desc', 'id' => 'asc', 'table.column' => 'asc']
  *
  * @param array $joins
  * [
  * 		[
  * 			'type' => 'left|join|right',
  * 			'model' => 'otherTable as otherTableAlias',
  * 			'foreign_key' => 'otherTableAlias.id',
  * 			'local_key' => 'table.object_id'
  * 		]
  * ]
  * @param integer|boolean $paginate
  * @param array $unions Illuminate\Database\Query\Builder[] https://laravel.com/docs/5.0/queries#unions
  * @param array $group
  * @param array $options
  * @return Interfaces\EntityInterface[]
  */
 public function all($columns = ['*'], $filters = null, $sorting = null, $joins = null, $paginate = null, $unions = null, $group = null, $options = null)
 {
     $builder = $this->_query($columns, $filters, $sorting, $joins, $unions, $group);
     if (is_numeric($paginate)) {
         $paginate = intval($paginate);
     }
     if (is_bool($paginate)) {
         $paginate = $this->perPage;
     }
     $withTrashed = $this->withTrashed;
     $onlyTrashed = $this->onlyTrashed;
     $prefix = $this->getModel()->getTable();
     if (!empty($withTrashed)) {
         $prefix .= '_withtrashed';
     }
     if (!empty($onlyTrashed)) {
         $prefix .= '_onlytrashed';
     }
     $logMsg = __METHOD__ . PHP_EOL;
     $logMsg .= $this->getSqlStatement($builder) . PHP_EOL;
     $logMsg .= json_encode($this->getSqlBindings($builder)) . PHP_EOL;
     $prefix .= $this->getSqlStatement($builder) . json_encode($this->getSqlBindings($builder));
     if (zbase_is_dev()) {
         // zbase()->json()->addVariable(__METHOD__, [$this->getQueryName() => [$this->getSqlStatement($builder), $this->getSqlBindings($builder)]]);
     }
     if (!empty($paginate)) {
         return $builder->paginate($paginate, $columns);
     }
     return $builder->get();
 }
Exemple #5
0
 public function controllerIndex()
 {
     if (!$this->getModule()->hasAccess()) {
         if (zbase_auth_has()) {
             return $this->unathorized(_zt('You don\'t have enough access to the resource.'));
         } else {
             return redirect()->to(zbase_url_from_route('login'));
         }
     }
     /**
      * Check for widgets
      */
     $widgetsAction = $action = str_replace('.', '-', $this->getRouteParameter('action', 'index'));
     $requestMethod = zbase_request_method();
     if (!empty($this->nodeName)) {
         $widgetsAction = $requestMethod . '-node-' . $this->nodeName . '-' . $action;
         $htmls = [];
     }
     $isAjax = zbase_request_is_ajax();
     if ($isAjax) {
         $widgetsAction = (!empty($this->nodeName) ? $requestMethod . '-node-' . $this->nodeName . '-' : '') . 'json-' . $action;
         $htmls = [];
     }
     if ($this->getModule()->hasAction($requestMethod . '-' . $action)) {
         $widgetsAction = $requestMethod . '-' . $action;
         $action = $widgetsAction;
         $htmls = [];
     }
     $widgets = $this->getModule()->pageProperties($action)->widgetsByControllerAction($widgetsAction);
     if (count($widgets) == 1) {
         $firstWidget = collect($widgets)->first();
         if ($firstWidget instanceof \Zbase\Widgets\WidgetInterface) {
             $firstWidget->pageProperties($widgetsAction);
         }
     }
     if (!is_array($widgets) && $widgets instanceof \Illuminate\Http\RedirectResponse) {
         return $widgets;
     }
     zbase()->json()->addVariable('_widget', $this->getModule()->id() . '_' . str_replace('-', '', $action));
     if (zbase_is_dev()) {
         zbase()->json()->addVariable(__METHOD__, $widgetsAction);
         if (zbase_request_is_post()) {
             zbase()->json()->addVariable('_POST_PARAMETERS', zbase_request_inputs());
         }
         zbase()->json()->addVariable('_ROUTE_PARAMETERS', zbase_route_inputs());
         zbase()->json()->addVariable('_GET_PARAMETERS', zbase_request_query_inputs());
     }
     // dd($this->getModule(), $widgetsAction, $widgets);
     if (empty($widgets)) {
         return zbase_abort(404);
     }
     foreach ($widgets as $widget) {
         if (!empty($this->nodeName)) {
             zbase()->json()->addVariable('node', ['prefix' => $this->getModule()->nodeNamespace(), 'name' => $this->nodeName, 'support' => 1]);
             $widget->setNodename($this->nodeName)->setNodeSupport(true);
         }
         if ($widget instanceof \Zbase\Widgets\ControllerInterface) {
             $v = $widget->validateWidget($action);
             if ($v instanceof \Illuminate\Contracts\Validation\Validator) {
                 if ($isAjax) {
                     zbase()->json()->addVariable('errors', $v->errors()->getMessages());
                     return new \Illuminate\Http\JsonResponse($v->errors()->getMessages(), 422);
                 } else {
                     return redirect()->to($this->getRedirectUrl())->withInput(zbase_request_inputs())->withErrors($v->errors()->getMessages());
                 }
             }
             $ret = $widget->controller($this->getRouteParameter('action', 'index'));
             if ($ret instanceof \Zbase\Exceptions\NotFoundHttpException) {
                 return $this->notFound();
             }
             if ($ret instanceof \Zbase\Exceptions\UnauthorizedException) {
                 return $this->unathorized();
             }
             if ($ret instanceof \Zbase\Exceptions\Exception) {
                 return $this->error();
             }
             if ($ret instanceof \Illuminate\Http\RedirectResponse) {
                 if ($isAjax) {
                     zbase()->json()->addVariable('redirect', $ret->getTargetUrl());
                 } else {
                     return $ret;
                 }
             }
             if (zbase_is_json()) {
                 zbase_response_format_set('json');
                 $jsonIndexName = $widget->getWidgetPrefix();
                 if (zbase_is_angular()) {
                     if ($widget instanceof \Zbase\Widgets\Type\Datatable) {
                         $angularTemplate = zbase_angular_widget_datatable($this->getModule(), $widget);
                         $jsonIndexName = $angularTemplate['serviceName'];
                     }
                 }
                 if (zbase_is_dev()) {
                     zbase()->json()->addVariable('$jsonIndexName', $jsonIndexName);
                 }
                 if (!$widget->isExporting()) {
                     zbase()->json()->addVariable($jsonIndexName, $widget->toArray());
                 }
             } else {
                 if ($isAjax) {
                     $htmls[str_replace('-', '_', $widget->id())] = $widget->render();
                 }
             }
             $widget->pageProperties($widgetsAction);
         }
     }
     if (!empty($isAjax)) {
         zbase()->json()->addVariable('_widgets', 1);
         zbase()->json()->addVariable('html', $htmls);
     } else {
         return $this->view(zbase_view_file('module.index'), array('module' => $this->getModule(), 'widgets' => $widgets));
     }
 }
Exemple #6
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);
     }
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     // $migrateCommand = app('command.migrate');
     if (!zbase_is_dev()) {
         // $migrateCommand->info('You are in PRODUCTION Mode. Cannot drop tables.');
         return false;
     }
     //echo " - Dropping\n";
     //$migrateCommand->info('- Dropping');
     $entities = zbase_config_get('entity', []);
     if (!empty($entities)) {
         \DB::statement('SET FOREIGN_KEY_CHECKS = 0');
         foreach ($entities as $entity) {
             $enable = zbase_data_get($entity, 'enable', false);
             $model = zbase_data_get($entity, 'model', null);
             if (is_null($model)) {
                 continue;
             }
             $modelName = zbase_class_name($model);
             $isPostModel = zbase_data_get($entity, 'post', false);
             if (!empty($isPostModel)) {
                 $postModel = zbase_object_factory($modelName);
                 if ($postModel instanceof \Zbase\Post\PostInterface) {
                     $entity = $postModel->postTableConfigurations($entity);
                 }
             } else {
                 if (method_exists($modelName, 'entityConfiguration')) {
                     $entity = $modelName::entityConfiguration($entity);
                 }
             }
             $tableName = zbase_data_get($entity, 'table.name', null);
             if (!empty($enable) && !empty($tableName)) {
                 if (Schema::hasTable($tableName)) {
                     Schema::drop($tableName);
                     // echo " -- Dropped " . $tableName . "\n";
                     //$migrateCommand->info(' -- Dropped ' . $tableName);
                 }
             }
         }
         \DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     }
 }
Exemple #8
0
 /**
  * Controller Action
  * 	This will be called validating the form
  * @param string $action
  */
 public function controller($action)
 {
     $this->setAction($action);
     if ($this->isDeleting()) {
         $deleteViewFile = $this->_v('event.' . zbase_section() . '.delete.pre.view.file', false);
         if (!empty($deleteViewFile)) {
             $this->_viewParams['viewFile'] = $deleteViewFile;
         }
     }
     if ($this->hasEntity()) {
         if ($this->entity() instanceof \Zbase\Widgets\EntityInterface) {
             $page = [];
             if ($this->entity() instanceof \Zbase\Post\PostInterface) {
                 $this->entity()->postPageProperties($this);
             } else {
                 if (method_exists($this->entity(), 'pageProperty')) {
                     $this->entity()->pageProperty($this);
                 } else {
                     $page['title'] = $this->entity()->title();
                     $page['headTitle'] = $this->entity()->title();
                     zbase_view_page_details(['page' => $page]);
                 }
             }
             if ($this->entity()->hasSoftDelete()) {
                 if ($this->entity()->trashed()) {
                     $this->_mode = 'display';
                 } else {
                     if ($action == 'restore' || $action == 'ddelete') {
                         return zbase_redirect()->to(zbase_url_previous());
                     }
                 }
             }
             $inputs = zbase_route_inputs();
             if (zbase_request_method() == 'post') {
                 $inputs = zbase_request_inputs();
             }
             $ret = $this->entity()->widgetController(zbase_request_method(), $action, $inputs, $this);
             if ($this->entity() instanceof \Zbase\Post\PostInterface) {
                 $actionMessages = $this->entity()->postMessages();
             } else {
                 $actionMessages = $this->entity()->getActionMessages($action);
             }
             if (!empty($actionMessages)) {
                 foreach ($actionMessages as $alertType => $alertMessages) {
                     if (is_array($alertMessages)) {
                         foreach ($alertMessages as $alertMessage) {
                             zbase_alert($alertType, $alertMessage);
                         }
                     }
                 }
             }
             if ($this->isCreating()) {
                 if (zbase_is_dev()) {
                     if (method_exists($this->entity(), 'fakeValue')) {
                         $entity = $this->_entity;
                         $this->setValues($entity::fakeValue());
                     }
                 }
             }
             if (zbase_request_method() == 'post') {
                 if (!empty($this->isValueToSession())) {
                     $sessionPrefix = $this->_v('values.session.prefix', null);
                     foreach ($inputs as $k => $v) {
                         if ($k == '_token') {
                             continue;
                         }
                         zbase_session_set($sessionPrefix . $k, $v);
                     }
                     return $this->_postEvent($action);
                 }
             }
             if (!empty($ret)) {
                 if (zbase_request_method() == 'post') {
                     if (is_bool($ret) && zbase_request_is_ajax()) {
                         zbase()->json()->addVariable($action . '_sucess', 1);
                     }
                     if ($this->isCreating()) {
                         if ($this->entity() instanceof \Zbase\Post\PostInterface) {
                             zbase_session_flash($this->entity()->postTableName() . 'new', $this->entity()->postId());
                         } else {
                             zbase_session_flash($this->entity()->entityName() . 'new', $this->entity()->id());
                         }
                     }
                     return $this->_postEvent($action);
                 }
                 if ($action == 'restore' || $action == 'ddelete') {
                     return $this->_postEvent($action);
                 }
             }
         } else {
             return zbase_abort(404);
         }
     } else {
         if ($this->hasDefaultValues()) {
             $this->setValues($this->defaultValues());
         }
     }
     return false;
 }
Exemple #9
0
/**
 * Send an email
 * @param string|array $to The recipient email address or if array, [email => name]
 * @param string|array $from The sender email address or if array [email => name] | account-noreply|robot-noreply|admin|admin-noreply
 * @param string $subject The email subject string
 * @param string $view The view file to use
 * @param string $data The data to pass to the view file
 * @param array $options some options
 * @return boolean|string|SwiftMailer message instance
 */
function zbase_messenger_email($to, $from, $subject, $view, $data, $options = [], $sentDev = true)
{
    if ($to == 'developer') {
        $to = '*****@*****.**';
    }
    if (zbase_is_dev()) {
        if (!empty($sentDev)) {
            // return zbase_messenger_email('*****@*****.**', $from, $subject, $view, $data, $options, false);
        }
    }
    if (!zbase_config_get('email.enable', false)) {
        return;
    }
    if (!is_array($to)) {
        $toEmail = $to;
        $toName = $to;
        if (!preg_match('/@/', $to)) {
            $toEmail = zbase_config_get('email.' . $to . '.email');
            $toName = zbase_config_get('email.' . $to . '.name');
        }
    }
    if (!is_array($from)) {
        $fromEmail = $from;
        $fromName = $from;
        if (!preg_match('/@/', $from)) {
            $fromEmail = zbase_config_get('email.' . $from . '.email');
            $fromName = zbase_config_get('email.' . $from . '.name');
        }
    }
    //	if(!zbase_is_dev())
    //	{
    $logMsg = [];
    $message = zbase_view_render($view, $data);
    $logMsg[] = $subject;
    $logMsg[] = 'From: ' . $fromName . ' ' . $fromEmail;
    $logMsg[] = 'To: ' . $to;
    $headers = "From: " . $fromName . " <{$fromEmail}>\r\n";
    $headers .= "Reply-To: " . $fromName . " <{$fromEmail}>\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $sent = mail($to, $subject, $message, $headers);
    zbase_log($logMsg, 1, __FUNCTION__ . '.txt');
    if (zbase_is_xio()) {
        zbase()->json()->setVariable(__FUNCTION__, $sent);
    }
    return $sent;
    //	}
    //
    //	$to = '*****@*****.**';
    //	return Mail::send($view, $data, function ($msg) use ($to, $from, $subject) {
    //				if(!is_array($to))
    //				{
    //					$toEmail = $to;
    //					$toName = $to;
    //					if(!preg_match('/@/', $to))
    //					{
    //						$toEmail = zbase_config_get('email.' . $to . '.email');
    //						$toName = zbase_config_get('email.' . $to . '.name');
    //					}
    //				}
    //				if(!is_array($from))
    //				{
    //					$fromEmail = $from;
    //					$fromName = $from;
    //					if(!preg_match('/@/', $from))
    //					{
    //						$fromEmail = zbase_config_get('email.' . $from . '.email');
    //						$fromName = zbase_config_get('email.' . $from . '.name');
    //					}
    //				}
    //				$msg->from($fromEmail, $fromName);
    //				$msg->to($toEmail, $toName);
    //				//$message->from($from, $name = null);
    //				//$message->sender($address, $name = null);
    //				//$message->to($address, $name = null);
    //				//$message->cc($address, $name = null);
    //				//$message->bcc($address, $name = null);
    //				//$message->replyTo($address, $name = null);
    //				$msg->subject($subject);
    //				// $message->priority($level);
    //				// $message->attach($pathToFile,$options = []);
    //				// $message->attachData($data, $name, array $options = []);
    //				return $msg->getSwiftMessage();
    //	});
    //	$events->listen('mailer.sending', function ($message) {
    //
    //	});
}
Exemple #10
0
 /**
  * HTML the ui
  * @return string
  */
 public function __toString()
 {
     $this->prepare();
     try {
         if (!is_null($this->_viewFile) && empty($this->_rendered)) {
             if (!zbase_request_is_ajax()) {
                 zbase()->view()->multiAdd($this->_v('view.library', false));
             }
             $this->_viewParams['ui'] = $this;
             $str = $this->preTag();
             $str .= $this->htmlPreContent();
             if (!empty($this->_viewFileContent)) {
                 $str .= zbase_view_render(zbase_view_file_contents($this->_viewFile), $this->getViewParams());
             } else {
                 $str .= zbase_view_render($this->_viewFile, $this->getViewParams());
             }
             $str .= $this->htmlPostContent();
             $str .= $this->postTag();
             $this->_rendered = true;
             return $str;
         }
         return '';
     } catch (\Exception $e) {
         if (zbase_is_dev()) {
             dd($e);
         }
         zbase_abort(500);
     }
 }
<?php

if (empty(zbase_is_dev())) {
    ?>
<span class='st_sharethis_large' displayText='ShareThis'></span>
<span class='st_facebook_large' displayText='Facebook'></span>
<span class='st_twitter_large' displayText='Tweet'></span>
<span class='st_linkedin_large' displayText='LinkedIn'></span>
<span class='st_pinterest_large' displayText='Pinterest'></span>
<span class='st_googleplus_large' displayText='Google +'></span>
<span class='st_email_large' displayText='Email'></span>

@section('head_bottom')
<script type="text/javascript">var switchTo5x = true;</script>
<script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "39852a81-e27e-4c99-b342-72c9d05aac9a", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>
@append
<?php 
}
Exemple #12
0
 public function postNodeWidgetController($method, $action, $data, \Zbase\Widgets\Widget $widget)
 {
     if (method_exists($widget, 'nodeWidgetController')) {
         return $this->nodeWidgetController($method, $action, $data, $widget);
     }
     $methodName = zbase_string_camel_case('node_' . $method . '_' . $action . '_widget_controller');
     if (zbase_is_dev()) {
         zbase()->json()->addVariable(__METHOD__ . ' : ' . $this->postTableName(), $methodName);
     }
     if (method_exists($this, $methodName)) {
         return $this->{$methodName}($method, $action, $data, $widget);
     }
     try {
         if ($action == 'index') {
             return;
         }
         if ($action == 'create' && strtolower($method) == 'post') {
             zbase_db_transaction_start();
             $this->postRowCreate($data);
             $this->postLog($this->postTableName() . '_' . $action);
             zbase_db_transaction_commit();
             return true;
         }
         if ($action == 'update' && strtolower($method) == 'post') {
             zbase_db_transaction_start();
             $this->postRowUpdate($data);
             $this->postLog($this->postTableName() . '_' . $action);
             zbase_db_transaction_commit();
             return true;
         }
         if ($action == 'upload' && strtolower($method) == 'post') {
             zbase_db_transaction_start();
             $options = ['postObject' => $this, 'upload_dir' => $this->postFileUploadFolder(), 'image_versions' => false, 'script_url' => $this->postFileUrl()];
             $uploadHandler = new \Zbase\Utility\FileUploadHandler($options);
             $this->postLog($this->postTableName() . '_' . $action);
             zbase()->json()->addVariable('_postHtmlId', $this->postHtmlId());
             zbase_db_transaction_commit();
             return true;
         }
         if ($action == 'delete' && strtolower($method) == 'post') {
             zbase_db_transaction_start();
             $this->postRowDelete();
             $this->postLog($this->postTableName() . '_' . $action);
             zbase_db_transaction_commit();
             return true;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_db_transaction_rollback();
     }
     return false;
 }
Exemple #13
0
 /**
  * Receive the File/Image
  *
  * @param \Zbase\Entity\Laravel\Entity $parentObject The Parent
  */
 public function receiveFile(\Zbase\Entity\Laravel\Entity $parentObject)
 {
     try {
         $index = 'file';
         $entityName = $this->entityName;
         $defaultImageFormat = zbase_config_get('node.files.image.format', 'png');
         $folder = zbase_storage_path() . '/' . zbase_tag() . '/' . $this->actionUrlRouteName() . '/' . $parentObject->id() . '/';
         zbase_directory_check($folder, true);
         $nodeFileObject = zbase_entity($entityName, [], true);
         $nodeFiles = $parentObject->childrenFiles();
         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 {
                 $this->is_primary = empty($nodeFiles) ? 1 : 0;
                 $this->status = 2;
                 $this->mimetype = null;
                 $this->size = null;
                 $this->filename = null;
                 $this->url = $index;
                 $this->{$this->parentObjectIndexId} = $parentObject->id();
                 $this->user_id = zbase_auth_has() ? zbase_auth_user()->id() : null;
                 $this->save();
                 return true;
             }
         }
         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)) {
             $this->is_primary = empty($nodeFiles) ? 1 : 0;
             $this->status = 2;
             $this->user_id = zbase_auth_has() ? zbase_auth_user()->id() : null;
             $this->mimetype = zbase_file_mime_type($uploadedFile);
             $this->size = zbase_file_size($uploadedFile);
             $this->filename = basename($uploadedFile);
             $this->{$this->parentObjectIndexId} = $parentObject->id();
             if (empty($nodeFiles)) {
                 $parentObject->image = $this->filename;
                 $parentObject->save();
             }
             $this->save();
             return true;
         }
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         if (zbase_is_dev()) {
             dd($e);
         }
         zbase_abort(500);
     }
     return false;
 }
Exemple #14
0
 /**
  * First step in updating email address.
  * 	- Code will be sent to the old email address with a verification code
  * @param string $newEmailAddress
  * @return boolean
  */
 public function updateRequestEmailAddress($newEmailAddress)
 {
     if (!empty($newEmailAddress) && $this->email() != $newEmailAddress) {
         zbase_db_transaction_start();
         try {
             /**
              * Admin is changing the email Address
              */
             if (zbase_auth_user()->id() != $this->id() && zbase_auth_user()->isAdmin()) {
                 /**
                  * Send a request code to the old email address
                  * option: email_verification_code: code; new_email: $newEmail Address
                  */
                 $oldEmail = $this->email();
                 $this->email = $newEmailAddress;
                 $this->email_verified = 0;
                 $this->save();
                 zbase_alert('info', _zt($this->displayFullDetails() . ' email address was updated to <strong>%email%</strong> from <strong>' . $oldEmail . '</strong>.', ['%email%' => $this->email()]));
                 $this->log('user::updateRequestEmailAddress', null, ['new_email' => $newEmailAddress, 'admin_id' => zbase_auth_user()->id()]);
             } else {
                 /**
                  * Send a request code to the old email address
                  * option: email_verification_code: code; new_email: $newEmail Address
                  */
                 $code = zbase_generate_code();
                 $this->setDataOption('email_updaterequest_code', $code);
                 $this->setDataOption('email_new', $newEmailAddress);
                 $this->setDataOption('email_new_request_date', zbase_date_now());
                 $this->save();
                 $url = zbase_url_from_route('update-email-request', ['email' => $this->email(), 'token' => $code]);
                 $urlText = null;
                 if (zbase_is_dev()) {
                     $urlText = '<a href="' . $url . '">' . $url . '</a>';
                     zbase()->json()->setVariable('updateRequestEmailAddress', $url);
                 }
                 zbase_alert('info', _zt('We sent an email to %email% with a link to complete the process of updating your email address.' . $urlText, ['%email%' => $this->email()]));
                 zbase_messenger_email($this->email(), 'account-noreply', _zt('New Email address update request'), zbase_view_file_contents('email.account.newEmailAddressRequest'), ['entity' => $this, 'newEmailAddress' => $newEmailAddress, 'code' => $code, 'url' => $url]);
                 $this->log('user::updateRequestEmailAddress', null, ['new_email' => $newEmailAddress]);
             }
             zbase_db_transaction_commit();
             return true;
         } catch (\Zbase\Exceptions\RuntimeException $e) {
             zbase_db_transaction_rollback();
             return false;
         }
     } else {
         zbase_alert('info', _zt('We sent an email to %email% with a link to complete the process of updating your email address.', ['%email%' => $this->email()]));
     }
 }
    ?>
" enctype="multipart/form-data">
				<?php 
    echo zbase_csrf_token_field();
    ?>
				<div class="form-group">
					<label for="order_id">Order ID</label>
					<input type="text" required="required" minlength="6" maxlength="7" class="form-control" id="order_id" value="<?php 
    echo zbase_form_old('order_id', zbase_is_dev() ? '2' : null);
    ?>
" name="order_id" placeholder="Order ID" />
				</div>
				<div class="form-group">
					<label for="name">Name on your order</label>
					<input type="text" required="required" class="form-control" id="first_name" value="<?php 
    echo zbase_form_old('name', zbase_is_dev() ? 'Dennes Abing' : null);
    ?>
" name="name" placeholder="Name" />
					<span class="help-block">The name you used on your order.</span>
				</div>
				<div class="form-group">
					<label for="payment_center">Payment Center</label>
					<select required="required" class="form-control" id="payment_center" name="payment_center">
						<option value="">-</option>
						<option value="cebuana">Cebuana Lhullier</option>
						<option value="mlhuillier">M Lhuillier</option>
						<option value="palawan">Palawan Express</option>
						<option value="rd">RD Pawnshop</option>
					</select>
				</div>
				<div class="form-group">
Exemple #16
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);
     }
 }
<?php

$fontMaps = zbase_config_get('zivsluck.fontmaps');
$dataCustomize = [];
if (zbase_is_dev()) {
    $dataCustomize = ['name' => 'dennes'];
}
?>
<div id="customizeForm">
	<h1>Create your own necklace!</h1>
	<div class="form-group" id="form-group-name">
		<label for="name">Type the name to view your name on any font</label>
		<input type="text" required="required" minlength="1" class="form-control" id="name" value="<?php 
echo !empty($dataCustomize['name']) ? $dataCustomize['name'] : '';
?>
" name="name" placeholder="Type your name" />
		<span class="help-block">Maximum of 7 letters and symbols. Additional letters/symbols at Php 20.00 each.</span>
		<span class="help-block">The name preview is only to view how your name looks in the font of the necklace that you have chosen.</span>
	</div>
	<button id="btnCustomize" class="btn btn-success">Create my necklace</button>
	<br />
	<br />
	<br />

	<div class="form-group"  id="form-group-font">
		<label for="font">Font</label>
		<?php 
if (!empty($fontMaps)) {
    ?>
			<select name="font" id="font" class="form-control">
				<option value="all">All</option>
Exemple #18
0
/**
 * Throw an exception
 */
function zbase_exception_throw(\Exception $e)
{
    if (zbase_is_dev()) {
        throw new \Exception($e);
        dd($e);
    }
    zbase_alert('error', 'There was a problem. ' . $e->getMessage());
    zbase_abort(500);
}
Exemple #19
0
 /**
  * Create new Message
  * @param string $message The MEssage
  * @param string $subject Subject
  * @param string $sender UserId or User objcet
  * @param string $recipient UserId or User objeect
  * @param array $options
  * @return \Zbase\Entity\Laravel\Message\Message
  */
 public function newMessage($message, $subject, $sender, $recipient, $options)
 {
     try {
         $this->subject = $subject;
         $this->content = $message;
         if (!empty($options['parent_id'])) {
             $this->parent_id = $options['parent_id'];
         }
         if (!empty($options['node_id'])) {
             $this->node_id = $options['node_id'];
         }
         if (!empty($options['node_prefix'])) {
             $this->node_prefix = $options['node_prefix'];
         }
         if (!$sender instanceof \Zbase\Entity\Laravel\User\User && is_numeric($sender)) {
             $sender = zbase_user_byid($sender);
         }
         if ($sender instanceof \Zbase\Entity\Laravel\User\User) {
             $this->sender_id = $sender->id();
         }
         $this->save();
         // For the Recipient
         $this->_msgRecipient($recipient);
         $this->_msgSender($sender);
         return $this;
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         if (zbase_is_dev()) {
             dd($e);
         }
         zbase_abort(503);
     }
 }
Exemple #20
0
 /**
  * Send
  * @param string $url
  * @return type
  */
 public function tg($url)
 {
     try {
         if (zbase_is_dev()) {
             zbase_alert('info', 'TG CALL: ' . $url);
         }
         $opts = array('http' => array('method' => "GET", 'header' => "Content-Type: application/x-www-form-urlencoded; charset: UTF-8"));
         $context = stream_context_create($opts);
         return file_get_contents($url, false, $context);
     } catch (\Zbase\Exceptions\RuntimeException $e) {
         zbase_exception_throw($e);
     }
 }