Example #1
0
 /**
  * Get all options
  *
  * @param bool $force Force
  * @return array|mixed
  */
 public static function getAll($force = false)
 {
     if ($force === true || self::$_config['cache'] === false || self::$_config['cache'] === true && !Cache::read(self::$_config['cache_name'])) {
         $options = self::$_table->find('all');
         $optionsArray = [];
         foreach ($options as $v) {
             $value = $v->{self::$_config['column_value']};
             $setting = Settings::getSetting($v->{self::$_config['column_key']});
             if (!is_null($setting)) {
                 switch ($setting['type']) {
                     case 'boolean':
                         $value = boolval($value);
                         break;
                     case 'integer':
                         $value = intval($value);
                         break;
                     case 'float':
                         $value = floatval($value);
                         break;
                 }
             }
             $optionsArray[$v->{self::$_config['column_key']}] = $value;
         }
         if (self::$_config['cache'] === true) {
             Cache::write(self::$_config['cache_name'], $optionsArray, self::$_config['cache_config']);
         }
         return $optionsArray;
     }
     return Cache::read(self::$_config['cache_name']);
 }
Example #2
0
 /**
  * @param $key
  * @param $value
  * @return bool
  */
 public function hasLabel($key, $value = null)
 {
     if (!$value) {
         return (bool) isset($this->labels[$key]);
     }
     return boolval((isset($this->labels[$key]) ? $this->labels[$key] : false) === $value);
 }
 public function __construct($boolean)
 {
     if (!is_bool($boolean)) {
         $boolean = boolval($boolean);
     }
     $this->boolean = $boolean;
 }
Example #4
0
 /**
  *    输出Json数据
  */
 public function renderJson($result, $msg, $data = [])
 {
     $arr = ['result' => boolval($result), 'message' => $msg, 'data' => $data];
     $res = Yii::$app->response;
     $res->format = $res::FORMAT_JSON;
     return $arr;
 }
Example #5
0
 /**
  * @return string
  */
 public function run()
 {
     parent::run();
     if (null === $this->rootCategory) {
         return '';
     }
     $cacheKey = $this->className() . ':' . implode('_', [$this->viewFile, $this->rootCategory, null === $this->depth ? 'null' : intval($this->depth), intval($this->includeRoot), intval($this->fetchModels), intval($this->onlyNonEmpty), implode(',', $this->excludedCategories), \Yii::$app->request->url]) . ':' . json_encode($this->additional);
     if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
         return $cache;
     }
     /** @var array|Category[] $tree */
     $tree = Category::getMenuItems(intval($this->rootCategory), $this->depth, boolval($this->fetchModels));
     if (true === $this->includeRoot) {
         if (null !== ($_root = Category::findById(intval($this->rootCategory)))) {
             $tree = [['label' => $_root->name, 'url' => Url::toRoute(['@category', 'category_group_id' => $_root->category_group_id, 'last_category_id' => $_root->id]), 'id' => $_root->id, 'model' => $this->fetchModels ? $_root : null, 'items' => $tree]];
         }
     }
     if (true === $this->onlyNonEmpty) {
         $_sq1 = (new Query())->select('main_category_id')->distinct()->from(Product::tableName());
         $_sq2 = (new Query())->select('category_id')->distinct()->from('{{%product_category}}');
         $_query = (new Query())->select('id')->from(Category::tableName())->andWhere(['not in', 'id', $_sq1])->andWhere(['not in', 'id', $_sq2])->all();
         $this->excludedCategories = array_merge($this->excludedCategories, array_column($_query, 'id'));
     }
     $tree = $this->filterTree($tree);
     $cache = $this->render($this->viewFile, ['tree' => $tree, 'fetchModels' => $this->fetchModels, 'additional' => $this->additional, 'activeClass' => $this->activeClass, 'activateParents' => $this->activateParents]);
     \Yii::$app->cache->set($cacheKey, $cache, 0, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Category::className()), ActiveRecordHelper::getCommonTag(Product::className())]]));
     return $cache;
 }
Example #6
0
/**
 * @param $value
 *
 * @return bool|null
 */
function tril($value)
{
    if (null === $value || false === $value || true === $value) {
        return $value;
    }
    if (is_array($value)) {
        return !empty($value);
    }
    if (is_object($value)) {
        return true;
    }
    if (is_double($value) && is_nan($value)) {
        return null;
    }
    $value = trim(strtolower($value));
    if (in_array($value, ['', 'null', 'maybe'])) {
        return null;
    }
    if (in_array($value, ['no', 'off', '0', 'false'])) {
        return false;
    }
    if (in_array($value, ['yes', 'on', '1', 'true'])) {
        return true;
    }
    return boolval($value);
}
/**
 * Add plugin core settings.
 *
 * @param  array $def Array of existing settings
 *
 * @return array      Updated settings
 */
function wpas_core_settings_general($def)
{
    $user_registration = boolval(get_option('users_can_register'));
    $registration_lbl = true === $user_registration ? _x('allowed', 'User registration is allowed', 'awesome-support') : _x('not allowed', 'User registration is not allowed', 'awesome-support');
    $settings = array('general' => array('name' => __('General', 'awesome-support'), 'options' => array(array('name' => __('Misc', 'awesome-support'), 'type' => 'heading'), array('name' => __('Default Assignee', 'awesome-support'), 'id' => 'assignee_default', 'type' => 'select', 'desc' => __('Who to assign tickets to in the case that auto-assignment wouldn&#039;t work. This does NOT mean that all tickets will be assigned to this user. This is a fallback option. To enable/disable auto assignment for an agent, please do so in the user profile settings.', 'awesome-support'), 'options' => isset($_GET['post_type']) && 'ticket' === $_GET['post_type'] && isset($_GET['page']) && 'wpas-settings' === $_GET['page'] ? wpas_list_users('edit_ticket') : array(), 'default' => ''), array('name' => __('Allow Registrations', 'awesome-support'), 'id' => 'allow_registrations', 'type' => 'radio', 'desc' => sprintf(__('Allow users to register on the support page. This setting can be enabled even though the WordPress setting is disabled. Currently, registrations are %s by WordPress.', 'awesome-support'), "<strong>{$registration_lbl}</strong>"), 'default' => 'allow', 'options' => array('allow' => __('Allow registrations', 'awesome-support'), 'disallow' => __('Disallow registrations', 'awesome-support'), 'disallow_silent' => __('Disallow registrations without notice (just show the login form)', 'awesome-support'))), array('name' => __('Replies Order', 'awesome-support'), 'id' => 'replies_order', 'type' => 'radio', 'desc' => __('In which order should the replies be displayed (for both client and admin side)?', 'awesome-support'), 'options' => array('ASC' => __('Old to New', 'awesome-support'), 'DESC' => __('New to Old', 'awesome-support')), 'default' => 'ASC'), array('name' => __('Replies Per Page', 'awesome-support'), 'id' => 'replies_per_page', 'type' => 'text', 'default' => 10, 'desc' => __('How many replies should be displayed per page on a ticket details screen?', 'awesome-support')), array('name' => __('Hide Closed', 'awesome-support'), 'id' => 'hide_closed', 'type' => 'checkbox', 'desc' => __('Only show open tickets when clicking the "All Tickets" link.', 'awesome-support'), 'default' => true), array('name' => __('Show Count', 'awesome-support'), 'id' => 'show_count', 'type' => 'checkbox', 'desc' => __('Display the number of open tickets in the admin menu.', 'awesome-support'), 'default' => true), array('name' => __('Old Tickets', 'awesome-support'), 'id' => 'old_ticket', 'type' => 'text', 'default' => 10, 'desc' => __('After how many days should a ticket be considered &laquo;old&raquo;?', 'awesome-support')), array('name' => __('Departments', 'awesome-support'), 'id' => 'departments', 'type' => 'checkbox', 'desc' => __('Enable departments management.', 'awesome-support'), 'default' => false), array('name' => __('Products Management', 'awesome-support'), 'type' => 'heading', 'options' => wpas_get_products_options()), array('name' => __('Plugin Pages', 'awesome-support'), 'type' => 'heading'), array('name' => __('Ticket Submission', 'awesome-support'), 'id' => 'ticket_submit', 'type' => 'select', 'multiple' => true, 'desc' => sprintf(__('The page used for ticket submission. This page should contain the shortcode %s', 'awesome-support'), '<code>[ticket-submit]</code>'), 'options' => wpas_list_pages(), 'default' => ''), array('name' => __('Tickets List', 'awesome-support'), 'id' => 'ticket_list', 'type' => 'select', 'multiple' => false, 'desc' => sprintf(__('The page that will list all tickets for a client. This page should contain the shortcode %s', 'awesome-support'), '<code>[tickets]</code>'), 'options' => wpas_list_pages(), 'default' => ''), array('name' => __('Terms & Conditions', 'awesome-support'), 'type' => 'heading'), array('name' => __('Content', 'awesome-support'), 'id' => 'terms_conditions', 'type' => 'editor', 'default' => '', 'desc' => __('Terms & conditions are not mandatory. If you add terms, a mandatory checkbox will be added in the registration form. Users won\'t be able to register if they don\'t accept your terms', 'awesome-support'), 'settings' => array('quicktags' => true, 'textarea_rows' => 7)), array('name' => __('Credit', 'awesome-support'), 'type' => 'heading'), array('name' => __('Show Credit', 'awesome-support'), 'id' => 'credit_link', 'type' => 'checkbox', 'desc' => __('Do you like this plugin? Please help us spread the word by displaying a credit link at the bottom of your ticket submission page.', 'awesome-support'), 'default' => false))));
    return array_merge($def, $settings);
}
Example #8
0
 public static function rememberLogin($value)
 {
     if (boolval($value)) {
         //die(Session::get('user'));
         setcookie('absotus_user', json_encode(Session::get('user')), time() + 86400 * 30, '/Absotus');
     }
 }
 /**
  * Case-insensitive search in directory contents
  * @param string|IStringBehaviour $needle
  * @param bool|false $isNeedleRegex
  * @param bool|false $firstMatchOnly
  * @return array
  * @throws NotReadableException
  */
 public function find($needle, $isNeedleRegex = false, $firstMatchOnly = false)
 {
     $matches = [];
     try {
         $contents = $this->toArray();
     } catch (NotReadableException $e) {
         throw $e;
     }
     foreach ($contents as $entry) {
         if ($isNeedleRegex && boolval(preg_match($needle, $entry))) {
             if ($firstMatchOnly) {
                 return $entry;
             } else {
                 $matches[] = $entry;
             }
         } elseif (!$isNeedleRegex && stripos($entry, $needle) !== false) {
             if ($firstMatchOnly) {
                 return $entry;
             } else {
                 $matches[] = $entry;
             }
         }
     }
     return $matches;
 }
 public function bool($id, $default = null)
 {
     if (NULL !== ($val = $this->read($id))) {
         return boolval($val);
     }
     return $default;
 }
Example #11
0
 /**
  * @inheritdoc
  */
 public function config($config)
 {
     $def_conf = ['root_path' => realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..'])), 'mapper_path' => '', 'log_dir' => __DIR__, 'debug' => false, 'connections' => []];
     $conf = array_merge($def_conf, $config);
     $root_path = $conf['root_path'];
     $map_path = $conf['mapper_path'];
     $log_dir = $conf['log_dir'];
     $debug = boolval($conf['debug']);
     foreach ($conf['connections'] as $connection) {
         $name = $connection['name'];
         $cls = $connection['class'];
         $connection['debug'] = $debug;
         if (!isset($connection['root_path'])) {
             $connection['root_path'] = $root_path;
         }
         if (!isset($connection['mapper_path'])) {
             $connection['mapper_path'] = $map_path;
         }
         if (isset($connection['logger'])) {
             if (!isset($connection['logger']['log_dir'])) {
                 $connection['logger']['log_dir'] = $log_dir;
             }
         }
         $this->configs[$name] = $connection;
         $this->connections[$name] = new \ReflectionClass($cls);
     }
     return $this;
 }
 public function listOfPassedTests(User $user, $data) : Query
 {
     switch ($data['answer_type']) {
         case 'all':
             $answer_type = null;
             break;
         case 0:
         case 1:
             $answer_type = $data['answer_type'];
             break;
     }
     empty($data['start']) ? $start = date('Y-m-d') : ($start = $data['start']);
     empty($data['end']) ? $end = date('Y-m-d') : ($end = $data['end']);
     $queryBuilder = $this->getEntityManager()->createQueryBuilder();
     $queryBuilder->select('stat')->from('TestBundle\\Entity\\Statistics', 'stat')->innerJoin('stat.task', 'task')->innerJoin('task.user', 'user');
     $queryBuilder->where($queryBuilder->expr()->eq('user.id', ':user'))->setParameter(':user', $user->getId(), Type::BIGINT);
     if (!is_null($answer_type) && ($answer_type == 0 || $answer_type == 1)) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('stat.results', ':results'))->setParameter(':results', boolval($answer_type), Type::BOOLEAN);
     }
     if ($start && $end) {
         $queryBuilder->andWhere($queryBuilder->expr()->between('stat.time', ':start', ':end'))->setParameter(':start', $start, Type::STRING)->setParameter(':end', $end, Type::STRING);
     }
     $query = $queryBuilder->getQuery();
     return $query;
 }
 public function removeDirectly($type, $id)
 {
     /** @fix detect user id */
     $query = $this->_db->queryAdapter()->delete('tag_items', ['tag' => $this->id, 'item_type' => $type, 'item' => $id], $this->queryAdapterItemsPrefixes());
     $stmt = $this->_db->prepare($query[GC_AFIELD_QUERY]);
     return boolval($stmt->execute($query[GC_AFIELD_PARAMS]));
 }
function formatter_bool_get($data, $fieldInfo)
{
    if (function_exists('boolval')) {
        return boolval($data);
    }
    return settype($data, 'boolean');
}
/**
 * Add plugin core settings.
 * 
 * @param  (array) $def Array of existing settings
 * @return (array)      Updated settings
 */
function wpas_core_settings_general($def)
{
    $user_registration = boolval(get_option('users_can_register'));
    $registration_lbl = true === $user_registration ? _x('allowed', 'User registration is allowed', 'wpas') : _x('not allowed', 'User registration is not allowed', 'wpas');
    $settings = array('general' => array('name' => __('General', 'wpas'), 'options' => array(array('name' => __('Multiple Products', 'wpas'), 'id' => 'support_products', 'type' => 'checkbox', 'desc' => __('If you need to provide support for multiple products, please enable this option. You will then be able to add your products.', 'wpas'), 'default' => false), array('name' => __('Default Assignee', 'wpas'), 'id' => 'assignee_default', 'type' => 'select', 'desc' => __('Who to assign tickets to by default (if auto-assignment is enabled, this will only be used in case an assignment rule is incorrect).', 'wpas'), 'options' => isset($_GET['post_type']) && 'ticket' === $_GET['post_type'] && isset($_GET['page']) && 'settings' === $_GET['page'] ? wpas_list_users('edit_ticket') : array(), 'default' => ''), array('name' => __('Allow Registrations', 'wpas'), 'id' => 'allow_registrations', 'type' => 'checkbox', 'desc' => sprintf(__('Allow users to register on the support. This setting can be enabled even though the WordPress setting is disabled. Currently, registrations are %s by WordPress.', 'wpas'), "<strong>{$registration_lbl}</strong>"), 'default' => true), array('name' => __('Replies Order', 'wpas'), 'id' => 'replies_order', 'type' => 'radio', 'desc' => __('In which order should the replies be displayed (for both client and admin side)?', 'wpas'), 'options' => array('ASC' => __('Old to New', 'wpas'), 'DESC' => __('New to Old', 'wpas')), 'default' => 'ASC'), array('name' => __('Hide Closed', 'wpas'), 'id' => 'hide_closed', 'type' => 'checkbox', 'desc' => __('Only show open tickets when clicking the "All Tickets" link.', 'wpas'), 'default' => true), array('name' => __('Show Count', 'wpas'), 'id' => 'show_count', 'type' => 'checkbox', 'desc' => __('Display the number of open tickets in the admin menu.', 'wpas'), 'default' => true), array('name' => __('Old Tickets', 'wpas'), 'id' => 'old_ticket', 'type' => 'text', 'default' => 10, 'desc' => __('After how many days should a ticket be considered &laquo;old&raquo;?', 'wpas')), array('name' => __('Plugin Pages', 'wpas'), 'type' => 'heading'), array('name' => __('Ticket Submission', 'wpas'), 'id' => 'ticket_submit', 'type' => 'select', 'desc' => sprintf(__('The page used for ticket submission. This page should contain the shortcode %s', 'wpas'), '<code>[ticket-submit]</code>'), 'options' => wpas_list_pages(), 'default' => ''), array('name' => __('Tickets List', 'wpas'), 'id' => 'ticket_list', 'type' => 'select', 'desc' => sprintf(__('The page that will list all tickets for a client. This page should contain the shortcode %s', 'wpas'), '<code>[tickets]</code>'), 'options' => wpas_list_pages(), 'default' => ''), array('name' => __('Terms & Conditions', 'wpas'), 'type' => 'heading'), array('name' => __('Content', 'wpas'), 'id' => 'terms_conditions', 'type' => 'editor', 'default' => '', 'desc' => __('Terms & conditions are not mandatory. If you add terms, a mendatory checkbox will be added in the registration form. Users won\'t be able to register if they don\'t accept your terms', 'wpas'), 'settings' => array('quicktags' => true, 'textarea_rows' => 7)), array('name' => __('Credit', 'wpas'), 'type' => 'heading'), array('name' => __('Show Credit', 'wpas'), 'id' => 'credit_link', 'type' => 'checkbox', 'desc' => __('You like the plugin? Please help us spread the word by displaying a credit link at the bottom of your ticket submission page.', 'wpas'), 'default' => false))));
    return array_merge($def, $settings);
}
Example #16
0
 /**
  * @param mixed $value
  * @return bool
  */
 public function render($value = null)
 {
     if ($value === null) {
         $value = $this->renderChildren();
     }
     return !boolval($value);
 }
Example #17
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param Closure $next
  * @param $roles
  * @param $permissions
  * @param bool $validateAll
  * @return mixed
  */
 public function handle($request, Closure $next, $roles, $permissions, $validateAll = false)
 {
     if ($this->auth->guest() || !$request->user()->ability(explode('|', $roles), explode('|', $permissions), array('validate_all' => boolval($validateAll)))) {
         return (new \Addons\Core\Controllers\Controller(false))->failure('auth.failure_permission');
     }
     return $next($request);
 }
 /**
  * Return the field markup for the front-end.
  *
  * @return string Field markup
  */
 public function display()
 {
     $editor = '';
     /**
      * Check if the description field should use the WYSIWYG editor
      *
      * @var string
      */
     $wysiwyg = boolval(wpas_get_option('frontend_wysiwyg_editor'));
     if (true === $wysiwyg || is_admin()) {
         $editor_defaults = array('media_buttons' => false, 'textarea_name' => $this->get_field_id(), 'textarea_rows' => 10, 'tabindex' => 2, 'editor_class' => $this->get_field_class(), 'quicktags' => false, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,hr,|,bullist,numlist,|,link,unlink', 'toolbar2' => ''));
         /* Merge custom editor settings if any */
         $args = isset($this->field_args['editor']) && is_array($this->field_args['editor']) ? wp_parse_args($this->field_args['editor'], $editor_defaults) : $editor_defaults;
         $wysiwyg_id = str_replace('_', '-', $this->get_field_id());
         // The codex says the opposite, but underscores causes issues while hyphens don't. Weird...
         ob_start();
         wp_editor($this->populate(), $wysiwyg_id, $args);
         /* Get the buffered content into a var */
         $editor = ob_get_contents();
         /* Clean buffer */
         ob_end_clean();
         $editor = "<label {{label_atts}}>{{label}}</label><div class='wpas-submit-ticket-wysiwyg'>{$editor}</div>";
     } else {
         $path = WPAS_PATH . "includes/custom-fields/field-types/class-cf-textarea.php";
         if (file_exists($path)) {
             include_once $path;
             $textarea = new WPAS_CF_Textarea($this->field_id, $this->field);
             $editor = $textarea->display();
         }
     }
     return $editor;
 }
 public function ajoutDetailsWEIAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     if ($request->isMethod('POST')) {
         $id = $_POST['id'];
     } else {
         $id = $_GET['id'];
     }
     $detailsWEI = $this->serviceMembre->GetDetailsByIdEtudiant($id);
     if ($detailsWEI == NULL) {
         $detailsWEI = new DetailsWEI();
     }
     $etu = $this->serviceMembre->GetEtudiantById($id);
     if (boolval($em->getRepository("BdEMainBundle:Config")->get("wei.bungMixtes"))) {
         $sexeEtu = -1;
     } elseif ($etu->getCivilite() == "M") {
         $sexeEtu = "M";
     } else {
         $sexeEtu = "F";
     }
     $form = $this->createForm(new DetailsWEIType($sexeEtu, $detailsWEI->getBus(), $detailsWEI->getBungalow()), $detailsWEI);
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $bizuth = $this->serviceMembre->GetEtudiantById($request->request->get('id'));
             $detailsWEI->setIdEtudiant($bizuth);
             $em->persist($detailsWEI);
             $em->flush();
             $this->get('session')->getFlashBag()->add('notice', 'Details enregistres');
             return $this->redirect($this->generateUrl('bde_wei_inscription_rechercheBizuthWEI'));
         }
     }
     return $this->render('BdEWeiBundle:Default:ajoutDetailsWEI.html.twig', array('form' => $form->createView(), 'id' => $request->query->get('id')));
 }
Example #20
0
 public static function toBool($self) : bool
 {
     if ($self === 'false') {
         return false;
     }
     return boolval($self);
 }
 /**
  * @inheritDoc
  */
 public function fetch()
 {
     /** @var ActiveRecord $categoryClass */
     $categoryClass = $this->categoryClass;
     $category = $categoryClass::findOne($this->categoryId);
     /** @var AttributeRuleRecord $ruleModelClass */
     $ruleModelClass = $this->ruleModelClass;
     /** @var AttributeEnumRecord $enumModelClass */
     $enumModelClass = $this->enumModelClass;
     if (isset(static::$rules[$this->categoryId])) {
         $rules = static::$rules[$this->categoryId];
     } else {
         $rules = $ruleModelClass::find()->byCategory($this->categoryId)->all();
         static::$rules[$this->categoryId] = $rules;
     }
     /** @var AttributeRuleRecord[] $rules */
     $result = [];
     foreach ($rules as $rule) {
         if (isset(static::$enums[$rule->id])) {
             $enums = static::$enums[$rule->id];
         } else {
             $enums = $enumModelClass::find()->byRule($rule->id)->getSortBehavior()->sort()->owner->all();
             static::$enums[$rule->id] = $enums;
         }
         $result[$rule->attribute_name] = [];
         $result[$rule->attribute_name]['multiple'] = boolval($rule->multiple);
         $result[$rule->attribute_name]['enum'] = array_map(function (AttributeEnumRecord $enum) {
             return ['title' => $enum->title, 'id' => $enum->enum_id, 'sort' => $enum->sort];
         }, $enums);
     }
     return $result;
 }
Example #22
0
 public function run()
 {
     $model = new $this->pars[0]();
     $data = $this->request->getData();
     //var_dump($data);
     $query = $data['search'];
     $sortBy = $data['sort']['by'] !== null ? $data['sort']['by'] : '';
     $pageSize = intval($data['page']['size']) ? intval($data['page']['size']) : null;
     $page = intval($data['page']['no']) ? intval($data['page']['no']) : 1;
     $sortMode = boolval($data['sort']['discend']) ? 'DSC' : 'ASC';
     $gQuery = ['search' => $query, 'sort' => ['by' => $sortBy, 'mode' => $sortMode]];
     $model->setLazy(true);
     $readed = $model->read(true, $gQuery, $page, $pageSize);
     if ($readed instanceof ModelCollection) {
         $url = 'http://' . $_SERVER['HTTP_HOST'] . Graphene::getInstance()->getSettings()['baseUrl'] . $this->request->getUrl();
         $page = $readed->getPage();
         $pageSize = $readed->getPageSize();
         $httpQ = ['search' => $query, 'sort_by' => $sortBy, 'sort_discend' => $sortMode === 'DSC' ? '1' : '0', 'page_size' => $pageSize, 'page_no' => $page];
         $httpQN = $httpQ;
         $httpQN['page_no'] = $httpQN['page_no'] + 1;
         $httpQP = $httpQ;
         $httpQP['page_no'] = $httpQP['page_no'] - 1;
         $readed->setNextPageUrl($url . '?' . http_build_query($httpQN));
         $readed->setCurrentPageUrl($url . '?' . http_build_query($httpQ));
         if ($page > 1) {
             $readed->setPreviousPageUrl($url . '?' . http_build_query($httpQP));
         }
     }
     $this->send($readed);
 }
Example #23
0
 /**
  * Authenticates valid user.
  *
  * @return array
  * @throws \DreamFactory\Core\Exceptions\BadRequestException
  * @throws \DreamFactory\Core\Exceptions\UnauthorizedException
  */
 protected function handlePOST()
 {
     $serviceName = $this->getPayloadData('service');
     if (empty($serviceName)) {
         $serviceName = $this->request->getParameter('service');
     }
     if (!empty($serviceName)) {
         $service = ServiceHandler::getService($serviceName);
         $serviceModel = Service::find($service->getServiceId());
         $serviceType = $serviceModel->serviceType()->first();
         $serviceGroup = $serviceType->group;
         if (!in_array($serviceGroup, [ServiceTypeGroups::OAUTH, ServiceTypeGroups::LDAP])) {
             throw new BadRequestException('Invalid login service provided. Please use an OAuth or AD/Ldap service.');
         }
         if ($serviceGroup === ServiceTypeGroups::LDAP) {
             $credentials = ['username' => $this->getPayloadData('username'), 'password' => $this->getPayloadData('password')];
             return $service->handleLogin($credentials, $this->getPayloadData('remember_me'));
         } elseif ($serviceGroup === ServiceTypeGroups::OAUTH) {
             $oauthCallback = $this->request->getParameterAsBool('oauth_callback');
             if (!empty($oauthCallback)) {
                 return $service->handleOAuthCallback();
             } else {
                 return $service->handleLogin($this->request->getDriver());
             }
         }
     } else {
         $credentials = ['email' => $this->getPayloadData('email'), 'password' => $this->getPayloadData('password'), 'is_sys_admin' => false];
         return $this->handleLogin($credentials, boolval($this->getPayloadData('remember_me')));
     }
 }
Example #24
0
 /**
  * Add custom javascript within head section.
  *
  * @since 1.0.0
  */
 public function add_snippet()
 {
     if (\is_admin()) {
         return;
     }
     if (\is_feed()) {
         return;
     }
     if (\is_robots()) {
         return;
     }
     if (\is_trackback()) {
         return;
     }
     $disable_recording = boolval(\get_post_meta(\get_the_id(), 'smartlook_disable_rec', true));
     // Disable recording for this content type
     if ($disable_recording) {
         return;
     }
     $snippet = trim(\get_option('smartlook_snippet'));
     if (empty($snippet)) {
         return;
     }
     echo $snippet;
 }
 /**
  * Exibe os dados de PID.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id = null)
 {
     if ($id) {
         $pid = Pid::findOrFail($id);
         $instituicoes = [];
         foreach ($pid->instituicoes as $instituicao) {
             $cidade = DB::table('cidades')->select('nomeCidade', 'uf_id')->where('idCidade', '=', $instituicao->endereco->cidade_id)->first();
             $uf = DB::table('uf')->select('uf')->where('idUf', '=', $cidade->uf_id)->first();
             $instituicoes[] = array('idInstituicao' => $instituicao->idInstituicao, 'nome' => $instituicao->nome, 'nomeCidade' => $cidade->nomeCidade, 'uf' => $uf->uf, 'tipoVinculo' => $instituicao->pivot->tipoVinculo);
         }
         $iniciativas = [];
         foreach ($pid->iniciativas as $iniciativa) {
             $cidade = DB::table('cidades')->select('nomeCidade', 'uf_id')->where('idCidade', '=', $iniciativa->endereco->cidade_id)->first();
             $uf = DB::table('uf')->select('uf')->where('idUf', '=', $cidade->uf_id)->first();
             $iniciativas[] = array('idIniciativa' => $iniciativa->idIniciativa, 'nome' => $iniciativa->nome, 'nomeCidade' => $cidade->nomeCidade, 'uf' => $uf->uf);
         }
         $servicos = [];
         foreach ($pid->servicos as $servico) {
             $servicos[] = $servico->idServico;
         }
         $cidade = DB::table('cidades')->select('uf_id', 'nomeCidade')->where('idCidade', '=', $pid->endereco->cidade_id)->first();
         $uf = DB::table('uf')->select('idUf', 'uf')->where('idUf', '=', $cidade->uf_id)->first();
         return ['idPid' => $pid->idPid, 'nome' => $pid->nome, 'email' => $pid->email, 'url' => $pid->url, 'tipo_id' => $pid->tipo_id, 'tipo' => DB::table('pidTipos')->select('tipo')->where('idTipo', '=', $pid->tipo_id)->first()->tipo, 'endereco' => ['cep' => $pid->endereco->cep, 'logradouro' => $pid->endereco->logradouro, 'numero' => $pid->endereco->numero, 'complemento' => $pid->endereco->complemento, 'bairro' => $pid->endereco->bairro, 'idUf' => $uf->idUf, 'uf' => $uf->uf, 'cidade_id' => $pid->endereco->cidade_id, 'cidade' => $cidade->nomeCidade, 'latitude' => $pid->endereco->latitude, 'longitude' => $pid->endereco->longitude, 'localidade_id' => $pid->endereco->localidade_id, 'localidade' => $pid->endereco->localidade_id ? DB::table('localidades')->select('localidade')->where('idLocalidade', '=', $pid->endereco->localidade_id)->first()->localidade : null, 'localizacao_id' => $pid->endereco->localizacao_id, 'localizacao' => $pid->endereco->localizacao_id ? DB::table('localizacoes')->select('localizacao')->where('idLocalizacao', '=', $pid->endereco->localizacao_id)->first()->localizacao : null], 'telefones' => $pid->telefones, 'instituicoes' => $instituicoes, 'iniciativas' => $iniciativas, 'servicos' => $servicos, 'fotos' => $pid->fotos, 'updated_at' => $pid->updated_at, 'destaque' => boolval($pid->destaque)];
     }
 }
Example #26
0
 /**
  * Load config
  */
 public function loadConfig()
 {
     Config::load(CONFIG_DIR . DS . 'config.default.php');
     Config::load(CONFIG_DIR . DS . sprintf('config.%s.php', getenv('RAD_ENVIRONMENT')));
     Config::set('environment', getenv('RAD_ENVIRONMENT'));
     Config::set('debug', boolval(getenv('RAD_DEBUG')));
 }
Example #27
0
 /**
  * @return string
  * @throws \DreamFactory\Core\Exceptions\UnauthorizedException
  */
 public static function refreshToken()
 {
     $token = Session::getSessionToken();
     try {
         $newToken = \JWTAuth::refresh($token);
         $payload = \JWTAuth::getPayload($newToken);
         $userId = $payload->get('user_id');
         $user = User::find($userId);
         $userInfo = $user->toArray();
         ArrayUtils::set($userInfo, 'is_sys_admin', $user->is_sys_admin);
         Session::setSessionToken($newToken);
         Session::setUserInfo($userInfo);
         static::setTokenMap($payload, $newToken);
     } catch (TokenExpiredException $e) {
         $payloadArray = \JWTAuth::manager()->getJWTProvider()->decode($token);
         $forever = boolval(ArrayUtils::get($payloadArray, 'forever'));
         if ($forever) {
             $userId = ArrayUtils::get($payloadArray, 'user_id');
             $user = User::find($userId);
             Session::setUserInfoWithJWT($user, $forever);
         } else {
             throw new UnauthorizedException($e->getMessage());
         }
     }
     return Session::getSessionToken();
 }
Example #28
0
 /**
  * Cast value.
  *
  * @param  mixed $value
  * @param  mixed $type
  *
  * @return mixed Value.
  */
 private function cast($value, $type)
 {
     switch ($type) {
         case 'bool':
             return boolval($value);
             break;
         case 'int':
             return intval($value);
             break;
         case 'float':
             return floatval($value);
             break;
         case 'string':
             return $value;
             break;
         case 'array':
             if (is_array($value)) {
                 return serialize($value);
             } else {
                 return unserialize($value);
             }
             break;
         default:
             return $value;
     }
 }
Example #29
0
 /**
  * Quick debugging of any variable. Any number of parameters can be set.
  *
  * @return  string
  */
 public static function debug()
 {
     if (func_num_args() === 0) {
         return null;
     }
     // Get params
     $params = func_get_args();
     $printBool = true;
     if (func_num_args() > 1) {
         $printBool = boolval(array_shift($params));
     }
     $output = array();
     foreach ($params as $var) {
         $output[] = '(' . gettype($var) . ') ' . var_export($var, true) . '';
     }
     if (php_sapi_name() == 'cli') {
         if ($printBool == true) {
             print implode("\n", $output);
         } else {
             return implode("\n", $output);
         }
     } else {
         if ($printBool == true) {
             print '<pre>' . implode("</pre>\n<pre>", $output) . '</pre>';
         } else {
             return '<pre>' . implode("</pre>\n<pre>", $output) . '</pre>';
         }
     }
     return null;
 }
 /**
  * Check if the passed data provided through the form is empty.
  * i.e., to check if all fields are empty.
  *
  * @param array $formInput
  * @return bool
  */
 protected function isEmpty(array $formInput)
 {
     foreach ($formInput as $data) {
         if (!is_array($data)) {
             if (boolval($data)) {
                 return false;
             } else {
                 continue;
             }
         }
         if (is_array($data)) {
             foreach ($data as $datum) {
                 if (is_array($datum)) {
                     foreach ($datum as $value) {
                         if (is_array($value)) {
                             foreach ($value as $index) {
                                 if (boolval($index)) {
                                     return false;
                                 }
                             }
                         } else {
                             if (boolval($value)) {
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }