Ejemplo n.º 1
0
 /**
  * Function processing raw HTTP request headers & body
  * and populates them to class variables.
  */
 private function processRequest()
 {
     $this->request['resource'] = isset($_GET['RESTurl']) && !empty($_GET['RESTurl']) ? $_GET['RESTurl'] : 'index';
     unset($_GET['RESTurl']);
     $this->request['method'] = Inflector::lower($_SERVER['REQUEST_METHOD']);
     $this->request['headers'] = $this->getHeaders();
     $this->request['format'] = isset($_GET['format']) ? trim($_GET['format']) : null;
     switch ($this->request['method']) {
         case 'get':
             $this->request['params'] = $_GET;
             break;
         case 'post':
             $this->request['params'] = array_merge($_POST, $_GET);
             break;
         case 'put':
             parse_str(fgc('php://input'), $this->request['params']);
             break;
         case 'delete':
             $this->request['params'] = $_GET;
             break;
         default:
             break;
     }
     $this->request['content-type'] = $this->getResponseFormat($this->request['format']);
     if (!function_exists('trim_value')) {
         function trim_value(&$value)
         {
             $value = trim($value);
         }
     }
     array_walk_recursive($this->request, 'trim_value');
 }
Ejemplo n.º 2
0
 public function all()
 {
     $data = $this->cached('all_db_JDB_' . $this->type);
     if (empty($data)) {
         $data = fgc($this->db);
         $data = strlen($data) ? $this->id(json_decode($data, true)) : array();
     }
     return $data;
 }
Ejemplo n.º 3
0
 public function __construct($namespace, $entity)
 {
     $this->db = STORAGE_PATH . DS . 'dbNode_' . $namespace . '::' . $entity . '.data';
     $this->lock = STORAGE_PATH . DS . 'dbNode_' . $namespace . '::' . $entity . '.lock';
     if (!File::exists($this->db)) {
         File::put($this->db, json_encode(array()));
     }
     $this->buffer = json_decode(fgc($this->db), true);
     $this->clean();
 }
Ejemplo n.º 4
0
Archivo: Png.php Proyecto: schpill/thin
 public static function urlToPng($url, $name = 'image')
 {
     $purl = 'http://195.154.233.154/api/png.php?url=' . urlencode($url);
     $pdf = fgc($purl);
     header("Content-type: image/png");
     header("Content-Disposition: attachment; filename=\"{$name}.png\"");
     header("Pragma: no-cache");
     header("Expires: 0");
     die($pdf);
 }
Ejemplo n.º 5
0
 public static function getCoords($address, $region = 'FR')
 {
     $address = urlencode($address);
     $json = fgc("http://maps.google.com/maps/api/geocode/json?address={$address}&sensor=false&region={$region}");
     $json = json_decode($json);
     $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
     $long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
     $coords = new Coords();
     return $coords->setLatitude($lat)->setLongitude($long);
 }
Ejemplo n.º 6
0
 /**
  * Retrieve an item from the cache driver.
  *
  * @param  string  $key
  * @return mixed
  */
 protected function retrieve($key)
 {
     if (!File::exists($this->path . $key)) {
         return null;
     }
     // File based caches store have the expiration timestamp stored in
     // UNIX format prepended to their contents. We'll compare the
     // timestamp to the current time when we read the file.
     if (time() >= substr($cache = fgc($this->path . $key), 0, 10)) {
         return $this->forget($key);
     }
     return unserialize(substr($cache, 10));
 }
Ejemplo n.º 7
0
 public function getMetas($url)
 {
     $content = fgc($url);
     if ($content) {
         $array = array('title' => '', 'description' => '');
         $pattern = "|<[\\s]*title[\\s]*>([^<]+)<[\\s]*/[\\s]*title[\\s]*>|Ui";
         if (preg_match($pattern, $content, $match)) {
             $array['title'] = $match[1];
         }
         $data = get_meta_tags($url);
         unset($content);
         unset($match);
         return $data + $array;
     }
     return null;
 }
Ejemplo n.º 8
0
 public static function getCoords($address, $region = 'FR')
 {
     $key = 'loc.coords.' . sha1(serialize(func_get_args()));
     $coords = redis()->get($key);
     if (strlen($coords)) {
         return unserialize($coords);
     }
     $address = urlencode($address);
     $json = fgc("http://maps.google.com/maps/api/geocode/json?address={$address}&sensor=false&region={$region}");
     if (!strstr($json, 'geometry')) {
         return ['lng' => 0, 'lat' => 0];
     }
     $json = json_decode($json);
     $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
     $lng = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
     $addrComponents = $json->{'results'}[0]->{'address_components'};
     $addrComponents = json_decode(json_encode($addrComponents), true);
     $components = [];
     foreach ($addrComponents as $component) {
         $k = implode('_', $component['types']);
         if ($k == 'locality_political') {
             $k = 'city';
         } elseif ($k == 'route') {
             $k = 'street';
         } elseif ($k == 'administrative_area_level_2_political') {
             $k = 'department';
         } elseif ($k == 'administrative_area_level_1_political') {
             $k = 'region';
         } elseif ($k == 'country_political') {
             $k = 'country';
         } elseif ($k == 'postal_code') {
             $k = 'zip';
         }
         unset($component['types']);
         $components[$k] = $component;
     }
     $components += ['lng' => $lng, 'lat' => $lat, 'geohash' => with(new Geohash())->encode($lat, $lng)];
     ksort($components);
     redis()->set($key, serialize($components));
     return $components;
 }
Ejemplo n.º 9
0
 public static function generate($model, $overwrite = false)
 {
     $file = APPLICATION_PATH . DS . 'models' . DS . 'Crud' . DS . ucfirst(Inflector::camelize($model)) . '.php';
     if (!File::exists($file) || $overwrite) {
         $db = model($model);
         $crud = new Crud($db);
         File::delete($file);
         $tplModel = fgc(__DIR__ . DS . 'Model.tpl');
         $tplField = fgc(__DIR__ . DS . 'Field.tpl');
         $fields = $crud->fields();
         $singular = ucfirst($model);
         $plural = $singular . 's';
         $default_order = $crud->pk();
         $tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel);
         $fieldsSection = '';
         foreach ($fields as $field) {
             if ($field != $crud->pk()) {
                 $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field));
                 $fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField);
             }
         }
         $tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
         File::put($file, $tplModel);
     }
 }
Ejemplo n.º 10
0
function slurpmanifest()
{
    global $baseWorkDir, $workWith, $sdisub, $mfContents, $xht_doc, $charset;
    $fmff = $baseWorkDir . '/' . $workWith . '/' . MFFNAME . $sdisub . MFFDEXT;
    if (file_exists($fmff)) {
        if ($mfContents = @fgc($fmff)) {
            set_time_limit(120);
            // for analyzing the manifest file
            $xht_doc = new xmddoc(explode("\n", $mfContents));
            if (!$xht_doc->error) {
                return '';
            }
            // keeping $mfContents and $xht_doc
            unset($mfContents);
            return get_lang('ManifestSyntax') . ' ' . htmlspecialchars($xht_doc->error, ENT_QUOTES, $charset);
        } else {
            return get_lang('EmptyManifest');
        }
    } else {
        return get_lang('NoManifest');
    }
}
Ejemplo n.º 11
0
function makeApp($app)
{
    return fgc('http://fr.webz0ne.com/api/check.php?code=' . $app);
}
Ejemplo n.º 12
0
Archivo: Aws.php Proyecto: schpill/thin
 /**
  * Set signing key
  *
  * @param string $keyPairId AWS Key Pair ID
  * @param string $signingKey Private Key
  * @param boolean $isFile Load private key from file, set to false to load string
  * @return boolean
  */
 public static function setSigningKey($keyPairId, $signingKey, $isFile = true)
 {
     self::$__signingKeyPairId = $keyPairId;
     if ((self::$__signingKeyResource = openssl_pkey_get_private($isFile ? fgc($signingKey) : $signingKey)) !== false) {
         return true;
     }
     self::__triggerError('S3::setSigningKey(): Unable to open load private key: ' . $signingKey, __FILE__, __LINE__);
     return false;
 }
Ejemplo n.º 13
0
 public function cid($cid)
 {
     $html = fgc('http://maps.google.fr/?cid=' . $cid);
     $seg = Utils::cut('cacheResponse(', ');', $html);
     $ws = $tel = $advice = $name = $formatted_address = $id_hex = $panoId = $rate = $lng = $lat = $address = $zipCity = null;
     eval('$tab = ' . $seg . ';');
     if (strstr($seg, ".ggpht.com/cbk")) {
         $panoSeg = Utils::cut('ggpht.com/cbk', 'u0026', $seg);
         $panoId = Utils::cut('panoid=', '\\', $panoSeg);
     }
     if (isset($tab[8])) {
         if (!empty($tab[8])) {
             // dd($tab);
             $id_hex = $tab[8][0][0];
             $formatted_address = $tab[8][13];
             $lat = $tab[8][0][2][0];
             $lng = $tab[8][0][2][1];
             $rate = $tab[8][3];
             $name = $tab[8][1];
             $address = $tab[8][2][0] . ', ' . $tab[8][2][1];
             $zipCity = isset($tab[8][2][2]) ? $tab[8][2][2] : $tab[8][2][1];
             $tel = str_replace([' '], '', $tab[8][7]);
             $advice = str_replace(['avis', ' '], '', $tab[8][4]);
             $ws = 'http://' . str_replace([' '], '', $tab[8][11][1]);
             if ($ws == 'http://') {
                 $ws = null;
             }
             return ['coords' => $tab[0][0][0], 'pitch' => $tab[0][3], 'key' => $tab[8][27], 'cid' => $cid, 'id_hex' => $id_hex, 'id_pano' => $panoId, 'name' => $name, 'lat' => $lat, 'lng' => $lng, 'formatted_address' => $formatted_address, 'zipCity' => $zipCity, 'tel' => $tel, 'website' => $ws, 'advice' => $advice, 'rate' => $rate, 'type' => $tab[8][12], 'schedule' => $this->schedule($tab[8][9][1])];
         }
     }
     return null;
 }
Ejemplo n.º 14
0
 public static function getArticle($article)
 {
     return unserialize(fgc($article));
 }
Ejemplo n.º 15
0
 public function extract($start = 0)
 {
     set_time_limit(0);
     $file = STORAGE_PATH . DS . 'duproprio.php';
     $data = fgc($file);
     $data = repl('[0', '0', $data);
     $data = repl('[', ',', $data);
     $data = repl(']', '', $data);
     File::delete($file);
     File::put($file, $data);
     $ids = (include $file);
     $i = 0;
     foreach ($ids as $id) {
         if ($start > 0 && $i < $start) {
             $i++;
             continue;
         }
         $this->id = $id;
         $this->getAd()->save();
         $i++;
     }
     echo 'task finished';
     return $this;
 }
Ejemplo n.º 16
0
Archivo: Orm.php Proyecto: schpill/thin
 private function _buffer($key, $data = null)
 {
     if (false === $this->_buffer) {
         return false;
     }
     $timeToBuffer = false !== $this->_cache ? $this->_cache * 60 : 3600;
     $ext = false !== $this->_cache ? 'cache' : 'buffer';
     $file = CACHE_PATH . DS . $key . '_sql.' . $ext;
     if (File::exists($file)) {
         $age = time() - filemtime($file);
         if ($age > $timeToBuffer) {
             File::delete($file);
         } else {
             return unserialize(fgc($file));
         }
     }
     if (null === $data) {
         return false;
     }
     File::put($file, serialize($data));
 }
Ejemplo n.º 17
0
 /**
  * Redirect to the facebook login url.
  *
  * @param array $scope
  * @param null $version
  * @return Response
  */
 public function authenticate($scope = array(), $version = null)
 {
     return fgc($this->getLoginUrl($scope, $version));
 }
Ejemplo n.º 18
0
function uploadFile($field, $name)
{
    $bucket = container()->bucket();
    if (Arrays::exists($field, $_FILES)) {
        $fileupload = $_FILES[$field]['tmp_name'];
        $fileuploadName = $_FILES[$field]['name'];
        if (strlen($fileuploadName)) {
            $tab = explode('.', $fileuploadName);
            $data = fgc($fileupload);
            if (!strlen($data)) {
                return null;
            }
            return $bucket->uploadNews(['data' => $data, 'name' => $name]);
        }
    }
    return null;
}
Ejemplo n.º 19
0
 public static function getObject($object)
 {
     return unserialize(fgc($object));
 }
Ejemplo n.º 20
0
function loadShowCSS($name)
{
    $content = fgc($name . '.css');
    echo "\r\n" . '<style>' . $content . '</style>' . '<pre class="language-css"><code>' . $content . '</code></pre>';
}
Ejemplo n.º 21
0
 /**
  * Returns the sources contents
  *
  * @return array|null
  */
 protected function getSourcesContent()
 {
     if (empty($this->sources)) {
         return;
     }
     $content = array();
     foreach ($this->sources as $sourceFile) {
         $content[] = fgc($sourceFile);
     }
     return $content;
 }
Ejemplo n.º 22
0
 private function id()
 {
     $incr = str_replace('.nosql', '.index', $this->file);
     if (!is_writable($incr)) {
         file_put_contents($incr, '0', LOCK_EX | 0);
     }
     if (!is_writable($incr)) {
         throw new Exception("The index {$incr} can not be created. Please, check write permission on " . STORAGE_PATH);
     }
     $last = fgc($incr);
     $last = (int) $last;
     $next = $last + 1;
     file_put_contents($incr, $next, LOCK_EX | 0);
     return $next;
 }
Ejemplo n.º 23
0
 public function find($id, $object = true)
 {
     $file = $this->dir . DS . $id . '.row';
     $row = File::exists($file) ? fgc($file) : '';
     if (strlen($row)) {
         $tab = json_decode($row, true);
         return $object ? $this->row($tab) : $tab;
     }
     return $object ? null : array();
 }
Ejemplo n.º 24
0
Archivo: Pdf.php Proyecto: schpill/thin
 public static function urlToPdf($url, $name = 'document', $portrait = true)
 {
     $html = fgc($url);
     return static::make($html, $name, $portrait);
 }
Ejemplo n.º 25
0
 public static function dispatchBundle(Container $route)
 {
     $bundle = $route->getBundle();
     $controller = $route->getController();
     $action = $route->getAction();
     $path = realpath(APPLICATION_PATH . '/../');
     $bundle = ucfirst(Inflector::lower($bundle));
     $viewsDir = $path . DS . 'bundles' . DS . $bundle . DS . 'views';
     $controllersDir = $path . DS . 'bundles' . DS . $bundle . DS . 'controllers';
     $tpl = $viewsDir . DS . Inflector::lower($controller) . ucfirst(Inflector::lower($action)) . '.phtml';
     $controllerFile = $controllersDir . DS . Inflector::lower($controller) . '.php';
     $file = $path . DS . 'bundles' . DS . $bundle . DS . $bundle . '.php';
     if (File::exists($file)) {
         $getNamespaceAndClassNameFromCode = getNamespaceAndClassNameFromCode(fgc($file));
         list($namespace, $class) = $getNamespaceAndClassNameFromCode;
         if (File::exists($controllerFile)) {
             if (File::exists($tpl)) {
                 $view = new View($tpl);
                 container()->setView($view);
             }
             require_once $controllerFile;
             $controllerClass = $namespace . '\\' . Inflector::lower($controller) . 'Controller';
             $controller = new $controllerClass();
             if (File::exists($tpl)) {
                 $controller->view = $view;
             }
             container()->setController($controller);
             $actions = get_class_methods($controllerClass);
             container()->setAction($action);
             if (strstr($action, '-')) {
                 $words = explode('-', $action);
                 $newAction = '';
                 for ($i = 0; $i < count($words); $i++) {
                     $word = trim($words[$i]);
                     if ($i > 0) {
                         $word = ucfirst($word);
                     }
                     $newAction .= $word;
                 }
                 $action = $newAction;
             }
             $actionName = $action . 'Action';
             if (Arrays::in('init', $actions)) {
                 $controller->init();
             }
             if (Arrays::in('preDispatch', $actions)) {
                 $controller->preDispatch();
             }
             if (!Arrays::in($actionName, $actions)) {
                 throw new Exception("The action '{$actionName}' does not exist.");
             }
             $controller->{$actionName}();
             if (File::exists($tpl)) {
                 $controller->view->render();
             }
             /* stats */
             if (File::exists($tpl) && null === container()->getNoShowStats() && null === $route->getNoShowStats()) {
                 echo View::showStats();
             }
             if (Arrays::in('postDispatch', $actions)) {
                 $controller->preDispatch();
             }
             if (Arrays::in('exit', $actions)) {
                 $controller->exit();
             }
         } else {
             context()->is404();
         }
     } else {
         context()->is404();
     }
 }
Ejemplo n.º 26
0
 protected function makeCompile($file)
 {
     $content = fgc($file);
     if (strstr($content, '@@layout')) {
         $layout = Utils::cut("@@layout('", "')", $content);
         $layoutFile = APPLICATION_PATH . DS . 'modules' . DS . $this->_module . DS . 'views' . DS . 'layouts' . DS . $layout . '.phtml';
         if (File::exists($layoutFile)) {
             $contentL = fgc($layoutFile);
             $content = repl('@@content', repl("@@layout('{$layout}')", '', $content), $contentL);
         }
     }
     $content = repl('<php>', '<?php ', $content);
     $content = repl('<php>=', '<?php echo ', $content);
     $content = repl('</php>', '?>', $content);
     $content = repl('{{=', '<?php echo ', $content);
     $content = repl('{{', '<?php ', $content);
     $content = repl('}}', '?>', $content);
     $content = repl('<?=', '<?php echo ', $content);
     $content = repl('<? ', '<?php ', $content);
     $content = repl('<?[', '<?php [', $content);
     $content = repl('[if]', 'if ', $content);
     $content = repl('[elseif]', 'elseif ', $content);
     $content = repl('[else if]', 'else if ', $content);
     $content = repl('[else]', 'else:', $content);
     $content = repl('[/if]', 'endif;', $content);
     $content = repl('[for]', 'for ', $content);
     $content = repl('[foreach]', 'foreach ', $content);
     $content = repl('[while]', 'while ', $content);
     $content = repl('[switch]', 'switch ', $content);
     $content = repl('[/endfor]', 'endfor;', $content);
     $content = repl('[/endforeach]', 'endforeach;', $content);
     $content = repl('[/endwhile]', 'endwhile;', $content);
     $content = repl('[/endswitch]', 'endswitch;', $content);
     $content = repl('$this->partial(', 'context("view")->partial(', $content);
     $content = repl('$this->tpl(', 'context("view")->partial(', $content);
     $content = repl('includes(', 'context("view")->partial(', $content);
     if (count($this->_grammar)) {
         foreach ($this->_grammar as $grammar => $replace) {
             $content = repl($grammar, $replace, $content);
         }
     }
     $base_uri = Config::get('application.base_uri', '');
     $content = repl(array('src="/', 'href="/', 'action="/'), array('src="/' . $base_uri . '', 'href="/' . $base_uri . '', 'action="/' . $base_uri . ''), $content);
     return self::lng($content);
 }
Ejemplo n.º 27
0
 /**
  * Load any plugins
  */
 private function loadPlugins()
 {
     $dir = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'content' . DS . SITE_NAME . DS . 'plugins');
     $this->plugins = array();
     $plugins = $this->getFiles($dir, '.php');
     if (!empty($plugins)) {
         foreach ($plugins as $plugin) {
             $getNamespaceAndClassNameFromCode = getNamespaceAndClassNameFromCode(fgc($plugin));
             list($namespace, $class) = $getNamespaceAndClassNameFromCode;
             require_once $plugin;
             $actions = get_class_methods($namespace . '\\' . $class);
             $nsClass = '\\' . $namespace . '\\' . $class;
             $instance = new $nsClass();
             if (Arrays::in('init', $actions)) {
                 $instance::init();
             }
             array_push($this->plugins, $instance);
             $this->plugins[] = $obj;
         }
     }
 }
Ejemplo n.º 28
0
function zip($s_srcarr, $s_dest)
{
    if (!extension_loaded('zip')) {
        return false;
    }
    if (class_exists("ZipArchive")) {
        $s_zip = new ZipArchive();
        if (!$s_zip->open($s_dest, 1)) {
            return false;
        }
        if (!is_array($s_srcarr)) {
            $s_srcarr = array($s_srcarr);
        }
        foreach ($s_srcarr as $s_src) {
            $s_src = str_replace('\\', '/', $s_src);
            if (@is_dir($s_src)) {
                $s_files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s_src), 1);
                foreach ($s_files as $s_file) {
                    $s_file = str_replace('\\', '/', $s_file);
                    if (in_array(substr($s_file, strrpos($s_file, '/') + 1), array('.', '..'))) {
                        continue;
                    }
                    if (@is_dir($s_file) === true) {
                        $s_zip->addEmptyDir(str_replace($s_src . '/', '', $s_file . '/'));
                    } else {
                        if (@is_file($s_file) === true) {
                            $s_zip->addFromString(str_replace($s_src . '/', '', $s_file), @fgc($s_file));
                        }
                    }
                }
            } elseif (@is_file($s_src) === true) {
                $s_zip->addFromString(basename($s_src), @fgc($s_src));
            }
        }
        $s_zip->close();
        return true;
    }
}
Ejemplo n.º 29
0
Archivo: gma.php Proyecto: noikiy/inovi
 private function upload($field)
 {
     $bucket = container()->bucket();
     if (Arrays::exists($field, $_FILES)) {
         $fileupload = $_FILES[$field]['tmp_name'];
         $fileuploadName = $_FILES[$field]['name'];
         if (strlen($fileuploadName)) {
             $tab = explode(".", $fileuploadName);
             $ext = Inflector::lower(Arrays::last($tab));
             return $bucket->data(fgc($fileupload), $ext);
         }
     }
     return null;
 }
Ejemplo n.º 30
0
 public function cached($key, $data = null)
 {
     $file = CACHE_PATH . DS . $key . '_sql';
     if (!empty($data)) {
         File::put($file, serialize($data));
         return $data;
     }
     if (File::exists($file)) {
         $age = time() - filemtime($file);
         if ($age > $this->_tts) {
             File::delete($file);
         } else {
             return unserialize(fgc($file));
         }
     }
 }