function merchant_is_logged_in()
{
    $tool =& \Clips\get_clips_tool();
    $merchant = $tool->model('merchant');
    \Clips\log('The id of user is {0}', array($merchant->getCurrentMerchantID()));
    return !!$merchant->getCurrentMerchantID();
}
Beispiel #2
0
 protected function initPlugins()
 {
     $tool =& \Clips\get_clips_tool();
     foreach (\Clips\clips_config('sass_plugins', array()) as $plugin) {
         $this->plugins[] = $tool->library($plugin);
     }
 }
 public function init()
 {
     $class = explode('\\', get_class($this));
     $class = array_pop($class);
     // The last one
     $class = \Clips\to_flat(str_replace('Migration', '', $class));
     $this->tool =& \Clips\get_clips_tool();
     $this->template = $this->tool->library('MigrationTool');
     $this->config = Yaml::parse(\Clips\content_relative('schemas/' . $class . '.yml', $this));
 }
Beispiel #4
0
 public function execute($args)
 {
     if (count($args) > 0) {
         $tool =& \Clips\get_clips_tool();
         foreach ($args as $file) {
             $tool->loadRule($file);
             $tool->clips->run();
         }
     }
 }
Beispiel #5
0
 public function execute($args)
 {
     $tool =& \Clips\get_clips_tool();
     $sass = $tool->library('sass');
     $sass->addIncludePath(getcwd());
     if (count($args) == 1 && $args['0'] == 'console') {
         $sass->console();
     } else {
         echo $sass->compile($args);
     }
 }
 protected function doRun($line)
 {
     $tool =& \Clips\get_clips_tool();
     $script = 'clips_console_internal.php';
     file_put_contents($script, $this->php($line));
     ob_start();
     include $script;
     $output = ob_get_contents();
     ob_end_clean();
     unlink($script);
     echo $output . "\n";
 }
/**
 * The download progress manager
 *
 * @author Jack
 * @version 1.0
 * @date Sat Mar 28 14:52:48 2015
 */
function download_progress($resource, $download_size, $downloaded, $upload_size, $uploaded)
{
    if ($downloaded > 0 && $download_size > 0) {
        $tool =& \Clips\get_clips_tool();
        $progress = $tool->library('progressManager');
        if ($progress->isStarted()) {
            $progress->update($downloaded);
        } else {
            $progress->start($download_size);
        }
    }
}
Beispiel #8
0
function smarty_block_markup($params, $content = '', $template, &$repeat)
{
    if ($repeat) {
        Clips\context('indent_level', 1, true);
        return;
    }
    $tool =& Clips\get_clips_tool();
    $flavor = Clips\get_default($params, 'flavor', 'github');
    $markup = $tool->library('markup');
    $content = $markup->render($content, $flavor);
    Clips\context_pop('indent_level');
    return Clips\create_tag_with_content('div', $content, $params, array('class' => 'markup'));
}
 public function getTemplate($uri)
 {
     $tool =& \Clips\get_clips_tool();
     $name = str_replace("tpl://", "", $uri);
     foreach (array(getcwd(), CLIPS_TOOL_PATH) as $path) {
         // Test for clips tool's path and the cwd
         foreach ($tool->config->template_dir as $dir) {
             $file_name = $path . '/' . $dir . '/' . $name . '.tpl';
             if (file_exists($path . '/' . $dir . '/' . $name . '.tpl')) {
                 return $file_name;
             }
         }
     }
     return null;
 }
Beispiel #10
0
 public function execute($args)
 {
     $tool =& \Clips\get_clips_tool();
     $arr = array();
     foreach ($tool->listLoadDirs() as $dir) {
         if ($dir) {
             foreach ($this->fetchCommands($dir) as $d) {
                 $command = str_replace('clips_', '', substr($d, strlen($dir) + 1, strlen($d) - strlen($dir) - 12));
                 $arr[] = array('command' => $command, 'desc' => $tool->descCommand($command));
             }
         }
     }
     $script = basename(array_shift($args));
     \Clips\clips_out('list', array('app' => $script, 'commands' => $arr));
 }
Beispiel #11
0
 public function __construct($type = 'mysqli')
 {
     $tool =& \Clips\get_clips_tool();
     $this->type = $type;
     $this->clips = $tool->clips;
     if (!$this->clips->isEnvExists('SQL')) {
         $this->clips->createEnv('SQL');
     }
     // Register all the template into the clips context
     $this->clips->runWithEnv('SQL', function ($clips, $type) {
         $clips->clear();
         $clips->template(array('Clips\\Libraries\\Select', 'Clips\\Libraries\\From', 'Clips\\Libraries\\Join', 'Clips\\Libraries\\Where', 'Clips\\Libraries\\GroupBy', 'Clips\\Libraries\\OrderBy', 'Clips\\Libraries\\Limit', 'Clips\\Libraries\\SqlTable', 'Clips\\Libraries\\SqlResult'));
         if (isset($type)) {
             $type = strtolower($type);
             $clips->load('/config/rules/sql/' . $type . '.rules');
         }
     }, $type);
 }
function _smarty_block_navigation_tree_node($action, $indent, $template, $repeat, $li_class = array())
{
    $tool =& Clips\get_clips_tool();
    $security = $tool->load_class('securityEngine', true);
    $result = $security->test($action);
    if ($result) {
        // If rejected this action
        Clips\log('Rejected action [{0}] for reasion [{1}]', array($action->label(), $result[0]->reason, $action));
        return '';
    }
    $f = true;
    // Start the li
    smarty_block_li(array(), '', $template, $f);
    // Start the action
    smarty_block_action(array(), '', $template, $f);
    // Close the action
    $a = smarty_block_action(array('action' => $action), '', $template, $repeat);
    $children = $action->children();
    if ($children) {
        $class[] = 'treeview';
        $sub = array();
        smarty_block_ul(array('class' => array('treeview', 'sub-navi')), '', $template, $f);
        foreach ($children as $c) {
            $sub[] = _smarty_block_navigation_tree_node($c, $indent . "\t\t", $template, $repeat, $li_class);
        }
        $a .= "\n{$indent}\t" . smarty_block_ul(array('class' => array('sub-navi', 'treeview-menu')), implode("", $sub), $template, $repeat);
    }
    $class = array();
    if ($li_class) {
        if (!is_array($li_class)) {
            $li_class = array($li_class);
        }
        $class = $li_class;
    }
    if ($action->active()) {
        $class[] = 'active';
    }
    if ($action->type() == 'header') {
        $class[] = 'header';
    }
    // Close the li
    return "\n{$indent}" . smarty_block_li(array('class' => $class), $a, $template, $repeat);
}
Beispiel #13
0
 public function segment($path)
 {
     if (file_exists($path)) {
         $str = file_get_contents($path);
     } else {
         $str = $path;
     }
     $tool =& \Clips\get_clips_tool();
     $mmseg = $tool->library('mmseg');
     $mmseg->tokenize($str, function ($type, $token) {
         switch ($type) {
             case "TOKEN":
                 echo "{$token}/x";
                 break;
             case "STOP_WORD":
                 echo "{$token}/s";
                 break;
             case "LINE_BREAK":
                 echo $token;
                 break;
         }
     });
 }
 protected function init($config)
 {
     // Fixed the bug that when initializing this datasource, didn't run the enhance
     $this->tool = \Clips\get_clips_tool();
     $this->config = $config;
     $this->table_prefix = \Clips\get_default($config, 'table_prefix', '');
     // Get the underlying datasource
     $ds = \Clips\get_default($config, 'datasource');
     // Since this datasource will use an underlying datasource as the delegate, so must have
     // the datasource configuration set for this datasource, not try uing the first one
     if (!$ds) {
         throw new DataSourceException('No datasource configured for this datasource!');
     }
     $ds = $this->get($ds);
     // TODO : This will initialize all the datasource list again( the first one is in datasource itself, this will waste a little more time
     if (!$ds) {
         throw new DataSourceException('No datasource configured for this datasource!');
     }
     // Setting the underlying datasource
     $this->ds = $ds;
     // Sql Creator will use MySQL as default.
     $sqlCreator = \Clips\get_default($config, 'sql_creator', 'PHPSQLParser\\PHPSQLCreator');
     if (!class_exists($sqlCreator)) {
         throw new DataSourceException('No sql creator found!');
     }
     // Setting the sql creator
     $this->creator = $this->tool->create($sqlCreator);
     // Initializing the SQL filters
     $this->filters = array();
     foreach (\Clips\get_default($config, 'filters', array()) as $filter) {
         $f = $this->tool->library($filter, true, 'SqlFilter');
         if ($f) {
             $this->filters[] = $f;
         }
     }
 }
Beispiel #15
0
 public function doSetUp()
 {
     $this->tool =& Clips\get_clips_tool();
     $this->git = $this->tool->library('git');
 }
Beispiel #16
0
function smarty_function_js($params, $template)
{
    $tool = \Clips\get_clips_tool();
    //Processing jquery init
    $init = \Clips\clips_context('jquery_init');
    if ($init) {
        if (!is_array($init)) {
            $init = array($init);
        }
        $init[] = "if(typeof initialize === 'function') initialize();";
        \Clips\add_init_js("//====================================\n// The jQuery initialize function \n//====================================\n\n" . 'jQuery(function($){' . "\n\t" . implode("\n\t", $init) . "\n" . '});');
    }
    // Processing js
    $scripts = \Clips\context('js');
    if ($scripts) {
        if (!is_array($scripts)) {
            $scripts = array($scripts);
        }
        $output = array();
        $init = array();
        foreach ($scripts as $item) {
            if (is_array($item)) {
                $js = explode("\n", $item['script']);
                $ret = array();
                foreach ($js as $line) {
                    $ret[] = "\t" . $line;
                }
                $init[] = implode("\n\t\t", $ret);
            } else {
                if (is_object($item)) {
                    $js = explode("\n", $item->script);
                    $ret = array();
                    foreach ($js as $line) {
                        $ret[] = "\t" . trim($line);
                    }
                    $init[] = implode("\n\t\t", $ret);
                } else {
                    $path = \Clips\safe_add_extension($item, 'js');
                    if (strpos($path, 'http:') === false) {
                        $path = \Clips\static_url($path);
                    }
                    $output[] = '<script type="text/javascript" src="' . $path . '"></script>';
                }
            }
        }
        $output[] = '<script type="text/javascript">' . "\n\t\t" . implode("\n\t\t", $init) . "\n\t\t" . '</script>';
        // Added the jsx support for ReactJs
        $jsx = \Clips\context('jsx');
        if ($jsx) {
            if (\Clips\config('babel')) {
                // TODO: This is a little bit ugly, needs refactor....
                $babel = $tool->library('babel');
                foreach ($jsx as $item) {
                    $path = Clips\try_path(Clips\safe_add_extension($item, 'jsx'));
                    if ($path) {
                        $output[] = '<script type="text/javascript" src="' . Clips\static_url($babel->compile($path)) . '"></script>';
                    }
                }
            } else {
                foreach ($jsx as $item) {
                    $output[] = '<script type="text/babel" src="' . Clips\static_url(Clips\safe_add_extension($item, 'jsx')) . '"></script>';
                }
            }
        }
        $jsx = \Clips\context('jsx_script');
        if ($jsx) {
            if (\Clips\config('babel')) {
                $babel = $tool->library('babel');
                $cache = $tool->library('fileCache');
                $c = \Clips\context('controller');
                $cm = \Clips\context('controller_method');
                $name = $c . '_' . $cm . '.jsx';
                $cache_file = $cache->cacheDir() . '/js/cache/' . $c . '_' . $cm . '.js';
                if (\Clips\try_path($cache_file) && !\Clips\config('debug_jsx')) {
                    $output[] = '<script type="text/javascript" src="' . Clips\static_url($cache_file) . '"></script>';
                } else {
                    $cache->save($name, $jsx, \Clips\path_join($cache->cacheDir(), 'js'));
                    $output[] = '<script type="text/javascript" src="' . Clips\static_url($babel->compile($cache->cacheDir() . '/js/' . $name)) . '"></script>';
                }
            } else {
                $output[] = '<script type="text/babel">' . implode("\n\t\t", $jsx) . '</script>';
            }
        }
        return implode("\n\t\t", $output);
    } else {
        return '';
    }
}
Beispiel #17
0
 public function execute($args)
 {
     $tool =& \Clips\get_clips_tool();
     $tool->ruleConsole();
 }
Beispiel #18
0
 public function doSetUp()
 {
     $tool = Clips\get_clips_tool();
     $this->sql = new Clips\Libraries\Sql();
 }
Beispiel #19
0
 public function doSetUp()
 {
     $this->tool =& Clips\get_clips_tool();
 }
Beispiel #20
0
 public function repo($path, $readonly = true)
 {
     $tool =& \Clips\get_clips_tool();
     return $tool->create('Clips\\Libraries\\Repository', array($path, $readonly));
 }