function smarty_function_alert($params, $template)
{
    $CI =& get_instance();
    $ret = array();
    ci_log('The alerts is ', $CI->getAlerts());
    $origin_class = get_default($params, 'class');
    foreach ($CI->getAlerts() as $alert) {
        $classes = make_classes($origin_class, 'alert');
        $classes[] = 'pinet-alert-' . $alert->type;
        $classes[] = 'alert-map-item';
        $params['class'] = $classes;
        $yes_btn = create_tag('button', array('class' => array('btn', 'pinet-alert-btn-default', 'yes')), array(), 'YES');
        $no_btn = create_tag('button', array('class' => array('btn', 'pinet-alert-btn-default', 'no')), array(), 'NO');
        $content = $yes_btn . $no_btn;
        $menu = create_tag('div', array('class' => array('menu')), array(), $content);
        $info = create_tag('div', array('class' => 'info'), array(), $alert->message);
        $alert_inner = $menu . $info;
        $ret[] = create_tag('div', $params, array('role' => 'alert'), $alert_inner);
    }
    $CI->clearAlerts();
    $alerts = '';
    if ($ret) {
        $alerts = create_tag('div', array('class' => 'pinet-alert-map'), array(), implode("\n", $ret));
    }
    return $alerts;
}
function store_login_args()
{
    $CI =& get_instance();
    $CI->load->library('session');
    ci_log('The args to be stored is ', get_login_args());
    $CI->session->set_userdata('pinet_args', json_encode(get_login_args()));
}
 public function index($path, $page = '')
 {
     if (func_num_args() > 2) {
         $arr = func_get_args();
         $page = implode('/', $arr);
     }
     ci_log($page);
     if ($page) {
         $path .= '/' . $page;
     }
     $this->render($path, array());
 }
function smarty_function_picture($params, $template)
{
    $src = smarty_plugin_get_variable($params, $template, 'src', true);
    $alt = smarty_plugin_get_variable($params, $template, 'alt');
    $path = smarty_plugin_get_variable($params, $template, 'path');
    $CI =& get_instance();
    $CI->load->helper('image');
    $file = find_img($src);
    ci_log('The image file that needs to be picture is %s', $file);
    if ($file == null) {
        // We can't read the file
        $src = 'default.png';
    }
    $size = get_image_size($src);
    $size = $size['width'];
    $attr = $params;
    $medias = array();
    $ret = array();
    $attr['src'] = $src;
    if ($path != '') {
        $attr['path'] = site_url($path);
    }
    $ret[] = '<picture ' . _parse_form_attributes($attr, array()) . ' >';
    foreach ($params as $key => $value) {
        // Check if user has set the customized media
        if (strpos($key, 'media') !== false) {
            $media = str_replace('media', '', $key);
            $medias[] = $media;
            $ret[] = "\t" . '<source src="' . site_url('responsive/size/' . $value . '/' . $src) . '" media="(min-width:' . $media . 'px)">';
            continue;
        }
        $attr[$key] = smarty_plugin_get_variable($params, $template, $key, false);
    }
    if ($path == '') {
        $resolutions = get_ci_config('resolutions');
        foreach ($resolutions as $res) {
            if (array_search($res, $medias) !== false) {
                // If the resolution is already covered
                continue;
            }
            $ret[] = "\t" . '<source src="' . site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src) . '" media="(min-width:' . $res . 'px)">';
        }
    }
    $ret[] = "\t" . '<noscript>';
    $ret[] = "\t\t" . '<img src="' . site_url('static/img/' . $src) . '" alt="' . $alt . '">';
    $ret[] = "\t" . '</noscript>';
    $ret[] = '</picture>';
    return implode("\n", $ret);
}
 /**
  * Need to use transaction to fix the problem that the datatable and listview can't use together
  */
 public function index($type = '')
 {
     ci_log('breadscrums', get_breadscrums());
     $this->session->unset_userdata('need_to_redirect_url');
     $data = array();
     $this->stickup();
     if ($type == 'test') {
         $this->log('Navigations is ', $this->navigation->getNavigations());
         $this->less('home/welcome_css');
         $this->render('welcome_message', $data);
     } else {
         $this->less('home/index_css');
         $this->render('index', $data);
     }
 }
 public function __construct()
 {
     $this->key_path = get_ci_config('encryptor_key', FCPATH . APPPATH . 'config/encrypt.key');
     $this->public_key_path = get_ci_config('encryptor_public_key', FCPATH . APPPATH . 'config/encrypt_public.key');
     if (file_exists($this->key_path)) {
         ci_log('Loading the private key file from %s', $this->key_path);
         $this->key = file_get_contents($this->key_path);
     } else {
         ci_error('Can\'t find private key file at %s', $this->key_path);
     }
     if (file_exists($this->public_key_path)) {
         ci_log('Loading the public key file from %s', $this->public_key_path);
         $this->public_key = file_get_contents($this->public_key_path);
     } else {
         ci_error('Can\'t find public key file at %s', $this->key_path);
     }
 }
function smarty_function_action($params, $template)
{
    $action = get_default($params, 'obj', null);
    $alt = get_default($params, 'alt', '');
    if ($action == null) {
        trigger_error('The obj parameter is required for action!');
        return '';
    }
    if (gettype($action) != 'object' || get_class($action) != 'Action') {
        trigger_error('The obj parameter must be of Class Action!');
        return '';
    }
    $fields = json_decode($action->fields);
    ci_log('The action to show is', $action);
    $data = array();
    $uri = $action->uri();
    if ($uri) {
        $data['href'] = $uri;
    }
    $content = lang($action->label);
    if (isset($action->logo) && $action->logo != '') {
        $data = array('src' => $action->logo, 'path' => '/responsive/size', 'data-placement' => isset($fields->placement) ? $fields->placement : 'right', 'data-original-title' => $action->label);
        $auto = get_default($params, 'auto', true);
        if ($auto) {
            $data["data-toggle"] = "tooltip";
        }
        $CI =& get_instance();
        $CI->load->helper('image');
        $file = find_img($data['src']);
        // Try to find the image in static/img
        if ($file == null) {
            // We can't read the file
            $data['src'] = 'default.png';
        }
        $picturedata = $data;
        unset($picturedata['data-toggle']);
        $content = smarty_function_picture($picturedata, $template);
        if (isset($action->controller) && isset($action->method) && $uri) {
            $data['href'] = $uri;
        }
    }
    return build_tag('a', $data, $content);
}
 public function validAction($action)
 {
     if (!$action) {
         return false;
     }
     $CI =& get_instance();
     if (!isset($CI->security_engine)) {
         return true;
     }
     $result = $CI->security_engine->validate($action);
     ci_log('The result for action is %s', $action, $result);
     if ($action->group == MAIN_NAVIGATION) {
         return $result == SECURITY_ALLOW;
     }
     if ($result != SECURITY_ALLOW) {
         return false;
     }
     $parent_action = $this->getActionByName($action->group);
     return $this->validAction($parent_action);
 }
function smarty_function_css($params, $template)
{
    $CI =& get_instance();
    foreach ($CI->cssFiles as $css) {
        echo $css->render();
    }
    if (isset($CI->sasscompiler)) {
        $meta = get_controller_meta();
        $CI =& get_instance();
        $suffix = get_default($CI, 'sass_suffix', '');
        $name = $meta->controller . '-' . $meta->method . $suffix . '.css';
        $dir = 'cache/css/';
        if (!file_exists(FCPATH . APPPATH . $dir)) {
            mkdir(FCPATH . APPPATH . $dir, 0755, true);
        }
        $file_name = FCPATH . APPPATH . $dir . $name;
        if (!file_exists($file_name) || get_ci_config('debug_sass')) {
            ci_log('The compiler is ', $CI->sasscompiler);
            file_put_contents($file_name, $CI->sasscompiler->compile());
        }
        return '<link rel="stylesheet" href="' . site_url(APPPATH . $dir . $name) . '">';
    }
}
 public function handle($i)
 {
     $template = $i->call_method;
     // Yes, this is a little bit tricky, since the render inteceptor is added after the desigin, and try to not interfere with the origin design.
     $args = $i->args;
     $CI =& get_instance();
     if (method_exists($CI, 'getTheme')) {
         $theme = $CI->getTheme();
     }
     $module =& get_current_module();
     if (isset($module)) {
         // We're in a module
         $module_path = dirname(get_class_script_path(get_class($module)));
         if (method_exists($module, 'getTheme')) {
             $theme = $module->getTheme();
         }
         if (isset($theme)) {
             ci_log('Adding the path %s', $module_path . '/views/themes/' . $theme . '/');
             $CI->addTemplateDir($module_path . '/views/themes/' . $theme . '/');
             ci_log('The template dirs is ', $CI->smarty->template_dir);
         }
     } else {
         // We're in a controller
         if (isset($theme)) {
             $CI->addTemplateDir(FCPATH . APPPATH . '/views/themes/' . $theme);
         }
     }
     if (isset($theme)) {
         if (isset($CI->sasscompiler)) {
             foreach (array(APPPATH, 'pinet/') as $d) {
                 $p = FCPATH . $d . 'static/scss/themes/' . $theme . '/';
                 ci_log('Adding the include path for scss %s', $p);
                 $CI->sasscompiler->addIncludePath($p, 0);
             }
         }
     }
 }
function stacktrace($level = 2)
{
    $trace = debug_backtrace();
    for ($i = 1; $i < $level; $i++) {
        $t = $trace[$i];
        ci_log('The trace is', $t);
    }
}
 public function toPagination()
 {
     $p = new PaginationSupport(0, $this->start, $this->length);
     $selects = array();
     $CI =& get_instance();
     $orig_columns = $CI->datatable->model->columns;
     foreach ($this->columns as $col) {
         $field = $this->getField($col);
         $dataCol = null;
         foreach ($orig_columns->columns as $c) {
             if (isset($c->refer) && $c->refer == $field) {
                 if (isset($c->referCol)) {
                     $selects[] = $c->referCol . ' as ' . $field;
                     $referCol = $c->referCol;
                 } else {
                     $selects[] = $field;
                 }
                 break;
             }
         }
         foreach ($orig_columns->columns as $c) {
             if ($c->data == $field) {
                 if (isset($c->dataCol)) {
                     $selects[] = $c->dataCol . ' as ' . $field;
                     $dataCol = $c->dataCol;
                 } else {
                     $selects[] = $field;
                 }
                 if (isset($c->refer)) {
                     if (isset($c->referCol)) {
                         $selects[] = $c->referCol . ' as ' . $c->refer;
                     } else {
                         $selects[] = $c->refer;
                     }
                 }
                 break;
             }
         }
         if ($this->search != null && isset($this->search['value']) && $this->search['value'] != '' && $this->getField($col, 'search') != null) {
             $value = $this->search['value'];
             if ($dataCol != null) {
                 $p->where[$dataCol] = $value;
             } else {
                 $p->where[$field] = $value;
             }
         }
     }
     if (isset($CI->datatable->model->conditions)) {
         ci_log('Filtering the datatable using conditions', $CI->datatable->model->conditions);
         foreach ($CI->datatable->model->conditions as $k => $v) {
             $p->and_or_where[$k] = $v;
         }
     }
     if ($this->joins != null) {
         $p->joins = $this->joins;
     }
     if ($this->order != null) {
         foreach ($this->order as $o) {
             $col = $o['column'];
             $field = $this->getField($this->columns[$col], 'order');
             if ($field == null) {
                 continue;
             }
             $dir = $o['dir'];
             $p->orderBy[] = array($field, $dir);
         }
     }
     $p->select = implode(',', $selects);
     $p->tag = $this->draw;
     // Setting the pagination tag to remember the draw
     if (isset($CI->datatable->model->customized_query)) {
         $p->customized_query = $CI->datatable->model->customized_query;
     }
     return $p;
 }
function create_image_thumbnail($orig, $width, $height = 0)
{
    $output_dir = 'application/cache/img/' . $width . 'x' . $height . '/';
    // All the thumbnails is located in cache
    $out_file = find_file($orig, $output_dir);
    // Try to find the file from output dir
    if ($out_file != null) {
        // If the cached file is exists, return it
        return file_get_contents($out_file);
    }
    $file = find_file($orig, 'static/uploads/');
    // Try to find the image in static/img
    if ($file == null) {
        // We can't read the in uploads
        $file = find_file($orig, 'static/img/');
        // Try to find the image in static/img
        if ($file == null) {
            // We can't read the file {
            return null;
        }
    }
    if ($width == 'normal') {
        return file_get_contents($file);
    }
    if (!file_exists($output_dir)) {
        // If the output dir is not exists, then create it
        mkdir($output_dir, 0777, true);
    }
    $path_parts = pathinfo($file);
    $name = $path_parts['filename'];
    $ext = $path_parts['extension'];
    $out_file = FCPATH . $output_dir . $name . '.' . $ext;
    if (extension_loaded('imagick')) {
        $img = new Imagick($file);
        $img->thumbnailImage($width, $height);
        $img->writeImage($out_file);
        return file_get_contents($out_file);
    }
    if (extension_loaded('gd')) {
        ci_log('Thumbnailing file %s using GD', $file);
        if ($ext == 'jpg' || $ext == 'jpeg') {
            $src_img = imagecreatefromjpeg($file);
        } else {
            $src_img = imagecreatefrompng($file);
        }
        $old_x = imageSX($src_img);
        $old_y = imageSY($src_img);
        if ($height == 0) {
            $height = $old_y * $width / $old_x;
        }
        $dst_img = ImageCreateTrueColor($width, $height);
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y);
        if ($ext == 'jpg' || $ext == 'jpeg') {
            imagejpeg($dst_img, $out_file);
        } else {
            imagepng($dst_img, $out_file);
        }
        imagedestroy($dst_img);
        imagedestroy($src_img);
    }
    return null;
}
Exemple #14
0
 /**
  * Fetch a config file item
  *
  *
  * @access	public
  * @param	string	the config item name
  * @param	string	the index name
  * @param	bool
  * @return	string
  */
 function item($item, $index = '')
 {
     if ($item == 'breadscrum_depth') {
         ci_log('The index is %s config is ', $this, $index);
     }
     if ($index == '') {
         if (!isset($this->config[$item])) {
             return FALSE;
         }
         $pref = $this->config[$item];
     } else {
         if (!isset($this->config[$index])) {
             return FALSE;
         }
         if (!isset($this->config[$index][$item])) {
             return FALSE;
         }
         $pref = $this->config[$index][$item];
     }
     return $pref;
 }
 public function reset()
 {
     $this->CI->user_model->myclear('groups_users');
     $this->CI->device_model->clear();
     $this->CI->gateway_model->clear();
     $this->CI->user_model->clear();
     $this->CI->group_model->clear();
     $this->CI->action_model->clear();
     $this->CI->sns_account_model->clear();
     $this->CI->security_subject_model->clear();
     $this->CI->security_target_model->clear();
     $this->CI->security_configuration_model->clear();
     $this->CI->token_model->clear();
     ci_log('Going to reset heart beats');
     $this->CI->heartbeat_model->clear();
 }
 private function customizeQuery($pagination)
 {
     ci_log('Using the customize query to query pagination', $pagination->customized_query);
     $sql = $pagination->customized_query->query . ' limit ' . $pagination->offset . ',' . $pagination->length;
     $pagination->items = $this->db->query($this->fixPrefix($sql))->result();
     $pagination->dbtotal = $this->queryCount($pagination->customized_query->dbtotal_count_query);
     $pagination->total = $this->queryCount($pagination->customized_query->total_count_query);
     return $pagination;
 }
Exemple #17
0
 /**
  * Set an error message
  *
  * @param	string
  * @return	void
  */
 public function set_error($msg)
 {
     $CI =& get_instance();
     $CI->lang->load('upload');
     ci_log('The error is %s', $msg);
     if (is_array($msg)) {
         foreach ($msg as $val) {
             $msg = $CI->lang->line($val) == FALSE ? $val : $CI->lang->line($val);
             $this->error_msg[] = $msg;
             log_message('error', $msg);
         }
     } else {
         $msg = $CI->lang->line($msg) == FALSE ? $msg : $CI->lang->line($msg);
         $this->error_msg[] = $msg;
         log_message('error', $msg);
     }
 }
 function addField($field)
 {
     $formField = copy_new($field, 'FormField');
     ci_log("The form field is ", $formField);
     $formField->init();
     $this->formFields[] = $formField;
     $this->_param($formField->name, $formField->label, $formField->getFormValidationRules());
 }
 public function user_datatable_customize($pagination)
 {
     $search_condition = '';
     foreach ($pagination->where as $column => $search) {
         if ($search_condition) {
             $search_condition .= ' or ' . $column . " like '%" . $search . "%'";
         } else {
             $search_condition .= $column . " like '%" . $search . "%'";
         }
     }
     $args = get_controller_args();
     if (count($args)) {
         $pagination->customized_query->query .= " and d.gateway_id='" . $args[0] . "'";
         $pagination->customized_query->dbtotal_count_query .= " and d.gateway_id='" . $args[0] . "'";
         $pagination->customized_query->total_count_query .= " and d.gateway_id='" . $args[0] . "'";
     }
     if ($search_condition) {
         $pagination->customized_query->query .= " and (" . $search_condition . ")";
         $pagination->customized_query->dbtotal_count_query .= " and (" . $search_condition . ")";
         $pagination->customized_query->total_count_query .= " and (" . $search_condition . ")";
     }
     ci_log('The pagination is ', $pagination);
     return $pagination;
 }
 public function parse()
 {
     if (isset($this->blocks)) {
         return true;
     }
     $content = file_get_contents($this->getTemplatePath());
     $state = '';
     $this->blocks = array();
     foreach (explode("\n", $content) as $line) {
         $l = trim($line);
         if (strpos($l, '{block') !== false) {
             $state = 'block';
         }
         if (strpos($l, '{extends') !== false) {
             $state = 'extend';
         }
         if ($state != 'block') {
             if (strpos($l, '{**') !== false) {
                 $state = 'meta';
             }
             if (strpos($l, '**}') !== false) {
                 $state = 'meta_end';
             }
         }
         switch ($state) {
             case 'extend':
                 if (preg_match_all('/\\{extends file=\'(.+).tpl\'\\}/', $l, $names)) {
                     ci_log('The parent is ', $names);
                     $this->parent = new MeshLayout($names[1][0], $this->layoutFolder);
                     $this->parent->parse();
                 }
                 break;
             case 'block':
                 if (preg_match_all('/\\{block name=(\\w+)\\}/', $l, $names)) {
                     if (count($names[0]) == 1) {
                         // We only support for 1 block per line
                         $block_name = $names[1][0];
                         $block_comment = '';
                         $block_type = 'default';
                         if (preg_match_all('/\\{\\*\\*\\s*(.+)\\s*\\*\\*\\}/', $l, $comments)) {
                             $block_comment = trim($comments[1][0]);
                         }
                         if (strpos($l, '{/block}') === false) {
                             $block_type = 'append';
                         } else {
                             $state = 'block_end';
                         }
                         $this->blocks[] = new MeshLayoutBlock($block_name, $block_comment, $block_type);
                     }
                 }
                 break;
             case 'meta':
                 $i = strpos($l, '@');
                 if ($i !== false) {
                     $l = substr($l, $i);
                     $kv = explode(':', $l);
                     if (count($kv) > 1) {
                         $k = trim(str_replace('@', '', $kv[0]));
                         $this->{$k} = trim($kv[1]);
                     }
                 }
                 break;
         }
     }
 }
Exemple #21
0
 public function init()
 {
     parent::init();
     ci_log('Sample Widget is initializing.....');
 }
/**
 * The field group has many states, list as below:
 *
 * None: The field group won't show in the form
 * Hidden: The field group is hidden from user
 * Disabled: The field group is disabled
 * Readonly: The field group is readonly
 *
 * The field state can be set in 4 ways:
 *
 * 1. By the tag itself
 * 2. By the security engine
 * 3. By the controller
 * 4. By the form configuration
 *
 * The priority of the value is like the list too. So, the tag itself
 * will have the highest priority than others.
 */
function smarty_block_field_group($params, $content = '', $template, &$repeat)
{
    $CI =& get_instance();
    $CI->load->helper('form');
    $labelClass = get_default($params, 'labelClass');
    $inputClass = get_default($params, 'inputClass');
    $glyphicon = get_default($params, 'glyphicon');
    if ($labelClass == "") {
        $labelClass = "pinet-form-label";
    }
    if ($inputClass == "") {
        $inputClass = "pinet-form-input";
    }
    $f = get_field($params, $template);
    if ($f == null) {
        return '';
    }
    if ($repeat) {
        // This is the start part
        // Set the field to parent's template variables to let the form fields to access it
        $parent_vars['current_form_field'] = new Smarty_Variable($f);
        $template->block_data = $f;
        return;
    }
    if ($f->state == 'none') {
        ci_log('The field is not allowed for this security configuration', $f);
        return '';
    }
    $layout = get_default($params, 'layout', array());
    $classes = make_classes(get_default($params, 'class'), array('form-group', 'control-group'));
    $label_layout_class = 'col-1280-2';
    $element_layout_class = 'col-1280-10';
    if (is_array($layout)) {
        if (isset($layout['label'])) {
            $label_layout_class = 'col-1280-' . $layout['label'];
        }
        if (isset($layout['element'])) {
            $element_layout_class = 'col-1280-' . $layout['element'];
        }
        if (isset($layout['mobile-label'])) {
            $label_layout_class .= ' col-320-' . $layout['mobile-label'];
        }
        if (isset($layout['mobile-element'])) {
            $element_layout_class .= ' col-320-' . $layout['mobile-element'];
        }
    } else {
        if (isset($f->container)) {
            $template->block_data = $f->container;
        } else {
            $template->block_data = null;
        }
        return create_tag('div', array('class' => $classes), array(), $content);
    }
    // Creating the label div
    if (!isset($f->label)) {
        $f->label = '';
    }
    $label = create_tag('label', array('for' => $f->getId(), 'class' => array($label_layout_class, $labelClass, 'control-label', isset($f->required) ? 'form_field_required' : '')), array(), $f->label);
    if (trim($content) == '') {
        // If we don't have any sub element, just add an input
        $inputData = array();
        // Check field type
        if (isset($f->type) && $f->type != '') {
            $inputData['type'] = $f->type;
        }
        $content = smarty_function_input($inputData, $template);
    }
    if (is_string($glyphicon) && $glyphicon != '') {
        $classes = make_classes($classes, array('has-feedback'));
        $content .= create_tag('span', array('class' => array('glyphicon', 'glyphicon-' . $glyphicon, 'form-control-feedback')), array(), '');
    }
    // Adding the error notification area
    $content .= create_tag('p', array('class' => array('help-block')), array(), '');
    // Creating the element div
    $element = create_tag('div', array('class' => array($element_layout_class, $inputClass)), array(), $content);
    if (isset($f->container)) {
        $template->block_data = $f->container;
    } else {
        $template->block_data = null;
    }
    if ($f->state == 'hidden') {
        $classes[] = 'hidden';
    }
    // Jam them together
    return create_tag('div', array('class' => $classes), array(), $label . "\n" . $element);
}
 public function getTransport($data)
 {
     ci_log('tttt', $data);
     $this->transport = copy_new($data, 'DataTableTransport');
     if (isset($this->model->joins)) {
         $this->transport->joins = $this->model->joins;
     }
     return $this->transport;
 }
 public function loadConfig()
 {
     $path = dirname(get_class_script_path($this)) . '/widget.json';
     if (file_exists($path)) {
         $json = file_get_contents($path);
         $this->config = json_decode($json);
         ci_log('The config is ', $this->config);
     } else {
         show_error(lang_f('Cant\'t find configuration file for widget %s', get_class($this)));
     }
 }