Ejemplo n.º 1
0
 /**
  * Overload object factory for Singleton
  *
  * @return bRequest|null|static
  */
 public static function create()
 {
     if (self::$_instance === null) {
         self::$_instance = parent::create(func_get_args());
     }
     return self::$_instance;
 }
Ejemplo n.º 2
0
 /**
  * Overload object factory for Singleton
  *
  * @return null|static
  */
 public static final function create()
 {
     $caller = get_called_class();
     if (!isset(self::$_mappers[$caller])) {
         self::$_mappers[$caller] = parent::create(func_get_args());
     }
     return self::$_mappers[$caller];
 }
Ejemplo n.º 3
0
 /**
  * Get all blocks name which have bPanel controller
  *
  * @param string $elem  - element filter
  * @return array - blocks list
  * @throws Exception
  */
 public final function getBlocks($elem = null)
 {
     $arr = opendir('b');
     $temp = array();
     while ($v = readdir($arr)) {
         if ($v == '.' or $v == '..' or $v == 'bBlib') {
             continue;
         }
         $name = $v . $elem;
         $path = bBlib::path($name, 'php');
         if (file_exists($path)) {
             $temp[$v] = $name;
         }
     }
     return $temp;
 }
Ejemplo n.º 4
0
 /**
  * Collects all code from the dev-files and sorts it by file extension
  *
  * @param string $name - block`s name
  * @param array $stack - empty array or result previous iteration
  * @param int $root     root flag
  * @return array - sorted glues code (like ["js"=>"code1 \n code2", "css"=>"css rule1 \n css rule2"])
  * @throws Exception
  */
 private function concatCode($name = '', $stack = array(), $root = 0)
 {
     $path = bBlib::path($name);
     $folder = opendir($path);
     while ($file = readdir($folder)) {
         // glue only .dev files
         if (preg_match('/\\w*.(\\w+).dev$/', $file, $matches)) {
             if (!isset($stack[$matches[1]])) {
                 $stack[$matches[1]] = '';
             }
             $content = file_get_contents($path . $file);
             $stack[$matches[1]] = $root == 0 ? $content . $stack[$matches[1]] : $stack[$matches[1]] . $content;
             continue;
         }
         // climb down if the folder named like element '__...'
         if (is_dir($path . $file) && substr($file, 0, 2) === '__') {
             $stack = $this->concatCode($name . $file, $stack, $root + 1);
         }
     }
     return $stack;
 }
Ejemplo n.º 5
0
 /**
  * Generate page and show it
  *
  * @throws Exception
  */
 public function indexAction()
 {
     /** @var bIndex__bDataMapper $_db  - page data mapper */
     $_db = $this->getInstance('db');
     /** @var bConverter__instance $_converter  - converter */
     $_converter = $this->getInstance('converter');
     /** @var self $_this */
     $_this = $this->getInstance('this');
     /** @var bTemplate $_template */
     $_template = $this->getInstance('template');
     $pageNo = $this->_config['pageNo'];
     // page number
     $access = $this->_config['access'];
     // flag of page protection
     // replace points (for template)
     $point = array("'{keywords}'" => $this->_config["'{keywords}'"], "'{description}'" => $this->_config["'{description}'"], "'{title}'" => $this->_config["'{title}'"], "'{template}'" => '{"block":"bServerMessage", "content":"accesserror"}');
     // if page is not locked or user have permission for get it
     if (!is_string($access) || $_this->checkAccess($access, $pageNo)) {
         // get page template tree
         $page = $_db->getItem($pageNo);
         // save it
         $this->_config['template'] = $page->tree;
         // create page from template
         $point["'{template}'"] = $_template->getTemplateDiff(false, $page->tree);
     }
     switch ($this->getView()) {
         // output json page
         case "json":
             $temp = $_converter->setData($point["'{template}'"])->setFormat('json')->convertTo('array');
             $_converter->setData($temp)->setFormat('array')->convertTo('json');
             $_converter->output();
             break;
             // if page gets in first time
         // if page gets in first time
         default:
             $skeleton = file_get_contents(bBlib::path($this->_config['skeleton'], 'tpl'));
             echo str_replace(array_keys($point), array_values($point), $skeleton);
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * Get all config names
  *
  * @return array
  * @throws Exception
  */
 public function getConfigList()
 {
     $arr = opendir('b');
     $temp = array();
     while ($v = readdir($arr)) {
         if ($v == '.' or $v == '..' or $v == 'bBlib') {
             continue;
         }
         $path = bBlib::path($v, 'php');
         if (file_exists($path)) {
             $temp[] = $v;
         }
     }
     return $temp;
 }
Ejemplo n.º 7
0
 public static function _editItem($data = array(), $caller = null)
 {
     if ($caller == null) {
         return;
     }
     bBlib::extend($data, '0', array());
     $update = array_merge(array('name' => 'noname', 'owner' => NULL, 'block' => NULL, 'template' => NULL), (array) $data[0]);
     $id = $update['id'];
     $update['blib'] = $update['block'];
     unset($update['id']);
     unset($update['block']);
     $Q = array('update' => array('btemplate' => $update), 'where' => array('btemplate' => array('id' => $id)));
     //var_dump($Q, $caller->_query($Q,true));
     return $caller->_query($Q);
 }
Ejemplo n.º 8
0
 public static function _editItem($data = array(), $caller = null)
 {
     if ($caller == null) {
         return;
     }
     bBlib::extend($data, '0', array());
     $update = array_merge(array('template' => NULL, 'bcategory_id' => NULL), (array) $data[0]);
     $id = $update['id'];
     unset($update['id']);
     $Q = array('update' => array('bIndex' => $update), 'where' => array('bIndex' => array('id' => $id)));
     return $caller->_query($Q);
 }
Ejemplo n.º 9
0
 /**
  * Configure php session
  *
  * @throws Exception
  */
 protected function input()
 {
     $this->_system = $this->getInstance('system', 'bSystem');
     $this->updateSession($this->_expire, bBlib::path('bSession__phpsession__storage'));
 }
Ejemplo n.º 10
0
 /**
  * Get default configuration map
  *
  * @param string $block        block name
  * @return array|mixed  configuration map
  * @throws Exception
  */
 public function getMap($block = '')
 {
     $path = bBlib::path($block . '__bConfig', 'json');
     if (!file_exists($path)) {
         return array();
     }
     try {
         $map = json_decode(file_get_contents($path), true);
     } catch (Exception $e) {
         throw new Exception('Not correct config map format.');
     }
     return $map;
 }
Ejemplo n.º 11
0
 /**
  * Dynamically created autoloader
  *
  * @param string $class - class name
  * @throws Exception
  */
 function _autoload($class = '')
 {
     $path = bBlib::path($class, 'php');
     if (!file_exists($path)) {
         throw new Exception('Called class ' . $class . ' is missing.');
     }
     require_once $path;
 }
Ejemplo n.º 12
0
<?php

require_once "vendor/autoload.php";
error_reporting(-1);
$request = (array) json_decode(file_get_contents("php://input"), true) + (array) $_POST + (array) $_GET;
if (!isset($request['blib'])) {
    $request['blib'] = 'bIndex';
}
require_once "b/bBlib/bBlib.php";
bBlib::init($request['blib']);