Esempio n. 1
0
 public static function last($table, $limit = 15, $order = false)
 {
     $_order = '';
     if ($order) {
         $_a = [];
         foreach ($order as $k => $v) {
             array_push($_a, $k . ' ' . $v);
         }
         $_order = ' order by ' . implode(', ', $_a);
     }
     $sql = "Select * from {$table} {$_order} limit 0, {$limit}";
     $result = static::query($sql);
     if (!!$result && is_array($result) && count($result) > 0) {
         $temp = [];
         foreach ($result as $item) {
             array_push($temp, Bella::oval($item));
         }
         return $temp;
     }
     return null;
 }
Esempio n. 2
0
 private static function remoteToLocalImage($url, $path, $lim = false, $saveas = '', $quality = 75)
 {
     $im = @getimagesize($url);
     if (!!$im) {
         require_once 'Master/base/libraries/Images/SimpleImage.php';
         $type = $im['mime'];
         $width = $im[0];
         $height = $im[1];
         $minWidth = static::MIN_WIDTH;
         $minHeight = static::MIN_HEIGHT;
         $maxWidth = static::MAX_WIDTH;
         $maxHeight = static::MAX_HEIGHT;
         if (!!$lim) {
             $lim = (object) $lim;
             if (isset($lim->minWidth)) {
                 $minWidth = $lim->minWidth;
             }
             if (isset($lim->minHeight)) {
                 $minHeight = $lim->minHeight;
             }
             if (isset($lim->maxWidth)) {
                 $maxWidth = $lim->maxWidth;
             }
             if (isset($lim->maxHeight)) {
                 $maxHeight = $lim->maxHeight;
             }
         }
         if ($width > $minWidth && $height > $minHeight && strpos($type, 'image') === 0) {
             $ext = static::getExt($type);
             if (!!$ext) {
                 $content = Remote::pull($url);
                 if (!!$content) {
                     $name = !!$saveas ? $saveas : Bella::createId(32);
                     $name .= $ext;
                     $file = $path . $name;
                     $save = @file_put_contents($file, $content);
                     if (!!$save) {
                         if ($width > $maxWidth || $height > $maxHeight) {
                             $sm = new SimpleImage();
                             $sm->load($file);
                             $sm->fillTo($maxWidth, $maxHeight);
                             $sm->save($file, false, $quality);
                         }
                         return $name;
                     }
                 }
             }
         }
     }
     return false;
 }
Esempio n. 3
0
 public static function json($data, $end = true)
 {
     return Bella::json($data, $end);
 }
Esempio n. 4
0
 public function stopAccess()
 {
     return Bella::deny();
 }
Esempio n. 5
0
 public static function initialize($onstart = null, $onfly = null)
 {
     Config::init();
     if (Config::get('active') === 0) {
         return Bella::shutdown();
     }
     $q = Config::get('settings');
     if (is_dir($q->requires_dir)) {
         foreach (glob($q->requires_dir . '*.php') as $file) {
             include_once $file;
         }
     }
     if (is_dir($q->utils_dir)) {
         foreach (glob($q->utils_dir . '*.php') as $file) {
             include_once $file;
         }
     }
     Session::init();
     Path::init();
     Request::init();
     if (isset($onstart) && is_callable($onstart)) {
         $onstart();
     }
     $user = Session::get('user');
     if (!$user) {
         $user = Session::get('manager');
     }
     if (!!$user) {
         Context::set('user', $user);
     }
     $c = Path::get(0);
     if (!$c) {
         Bella::loadCoordinator('index');
     } else {
         $dir = Config::get('settings')->controllers_dir;
         $f = $dir . $c . '.php';
         if (file_exists($f)) {
             Bella::loadCoordinator($c);
         } else {
             if (isset($onfly) && is_callable($onfly)) {
                 return $onfly($c);
             }
         }
     }
 }
Esempio n. 6
0
 public static function parse()
 {
     $m = static::getRequestMethod();
     $p = Path::get();
     $maps = static::$map[$m];
     if (!!$maps && is_array($maps) && count($maps) > 0) {
         $matching = '';
         for ($i = count($p) - 1; $i >= 0; $i--) {
             if (!$p[$i]) {
                 array_splice($p, $i, 1);
             }
         }
         $uri = implode('/', $p);
         $min = 1000;
         foreach ($maps as $map) {
             $num = 0;
             $pattern = $map->pattern;
             for ($i = count($pattern) - 1; $i >= 0; $i--) {
                 if (strpos($pattern[$i], ':') === 0) {
                     $pattern[$i] = '(\\w+)';
                     $num++;
                 }
             }
             $sroute = implode('/', $pattern);
             $matcount = 0;
             $min = min(count($pattern), count($p));
             for ($j = 0; $j < $min; $j++) {
                 if ($pattern[$j] == '(\\w+)' || $p[$j] == $pattern[$j]) {
                     $matcount++;
                     continue;
                 }
             }
             if ($matcount == count($pattern)) {
                 if (preg_match_all('#^' . $sroute . '$#', $uri, $matches)) {
                     if ($num < $min) {
                         $min = $num;
                         $matching = (object) ['route' => $map, 'data' => array_slice($matches, 1)];
                     }
                 }
             }
         }
         if (!!$matching && is_object($matching)) {
             $args = [];
             $matches = property_exists($matching, 'data') ? $matching->data : [];
             foreach ($matches as $val) {
                 array_push($args, $val[0]);
             }
             $fn = $matching->route->callback;
             call_user_func_array($fn, $args);
         }
     }
     if ($m == 'HEAD') {
         ob_end_clean();
     }
     return Bella::end();
 }
Esempio n. 7
0
 public function deny()
 {
     return Bella::deny();
 }