예제 #1
0
 public static function generateSchemaFiles()
 {
     foreach (ActiveRecord::connections() as $connectionName => $cdata) {
         if (!isset($cdata['username']) || !isset($cdata['password']) || !isset($cdata['database'])) {
             continue;
         } else {
             try {
                 ActiveRecord::setConnection($connectionName);
                 $connection = ActiveRecord::connection();
                 $dbname = $connection->selectValue("SELECT DATABASE()");
                 $tables = $connection->selectValues(sprintf('SHOW TABLES FROM `%s`', $dbname));
             } catch (Throwable $e) {
                 continue;
             } catch (\Exception $e) {
                 continue;
             }
             if (!$tables) {
                 throw new Exception\RuntimeException(sprintf('Couldn\'t retrieve table information for connection %s', $connectionName));
             }
             foreach ($tables as $table_name) {
                 $class = 'Rails\\ActiveRecord\\Adapter\\' . $connection->adapterName() . '\\Table';
                 $data = $class::fetchSchema($connection, $table_name);
                 $path = \Rails::root() . '/db/table_schema/' . $connection->name();
                 if (!is_dir($path)) {
                     mkdir($path, 0777, true);
                 }
                 $file = $path . '/' . $table_name . '.php';
                 $contents = "<?php\nreturn ";
                 $contents .= var_export($data, true);
                 $contents .= "\n;";
                 file_put_contents($file, $contents);
             }
         }
     }
 }
예제 #2
0
 public static function errorFile()
 {
     if (!self::$save_path) {
         self::$save_path = Rails::root() . '/tmp';
     }
     return self::$save_path . '/' . self::$errorFile_name;
 }
예제 #3
0
파일: Base.php 프로젝트: JCQS04/myimouto
 protected function _create_dirs($dir)
 {
     $dirs = array_filter(explode('/', str_replace(Rails::root(), '', pathinfo($dir, PATHINFO_DIRNAME))));
     $dir = Rails::root() . '/';
     foreach ($dirs as $d) {
         $dir .= $d . '/';
         !is_dir($dir) && mkdir($dir);
     }
 }
예제 #4
0
파일: DText.php 프로젝트: JCQS04/myimouto
 public static function parse($str)
 {
     $state = ['newline'];
     $result = '';
     # Normalize newlines.
     $str = trim($str);
     $str = preg_replace(['/(\\r\\n?)/', '/\\n{3,}/', '/ *\\n */'], ["\n", "\n\n", "\n"], $str);
     $str = htmlentities($str);
     # Keep newline, use carriage return for split.
     $str = str_replace("\n", "\n\r", $str);
     $data = explode("\r", $str);
     # Parse header and list first, line by line.
     foreach ($data as $d) {
         $result .= self::parseline($d, $state);
     }
     # Parse inline tags as a whole.
     $result = self::parseinline($result);
     # htmLawed ensures valid html output.
     require_once Rails::root() . '/vendor/htmLawed/htmLawed.php';
     return htmLawed($result);
 }
예제 #5
0
 protected function fullFilePath()
 {
     return \Rails::root() . '/' . $this->filePath();
 }
예제 #6
0
 public function run()
 {
     switch ($this->mainArgv) {
         case 'generate':
             $gen = new Generators\Generator($this);
             $gen->parseCmd();
             break;
         case 'assets':
             $rules = ['assets' => '', 'action' => ''];
             $opts = new Zend\Console\Getopt($rules);
             $argv = $opts->getArguments();
             if (empty($argv[1])) {
                 $this->terminate("Missing argument 2");
             }
             \Rails::resetConfig('production');
             switch ($argv[1]) {
                 case 'compile:all':
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileAll();
                     break;
                 case strpos($argv[1], 'compile:') === 0:
                     $parts = explode(':', $argv[1]);
                     if (empty($parts[1])) {
                         $this->terminate("Missing asset name to compile");
                     }
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileFile($parts[1]);
                     break;
                 default:
                     $this->terminate("Unknown action for assets");
                     break;
             }
             break;
         case 'routes':
             $routes = $this->createRoutes();
             $rules = ['routes' => '', 'f-s' => ''];
             $opts = new Zend\Console\Getopt($rules);
             if ($filename = $opts->getOption('f')) {
                 if (true === $filename) {
                     $logFile = \Rails::config()->paths->log->concat('routes.log');
                 } else {
                     $logFile = \Rails::root() . '/' . $filename;
                 }
                 file_put_contents($logFile, $routes);
             }
             $this->write($routes);
             break;
             /**
              * Install database.
              */
         /**
          * Install database.
          */
         case 'db:create':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->loadSchema();
             break;
             /**
              * Run all/pending migrations.
              * Creates migrations table as well.
              */
         /**
          * Run all/pending migrations.
          * Creates migrations table as well.
          */
         case 'db:migrate':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->run();
             break;
             /**
              * Runs seeds.
              */
         /**
          * Runs seeds.
          */
         case 'db:seed':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->runSeeds();
             break;
         case 'db:schema:dump':
             $dumper = new \Rails\ActiveRecord\Schema\Dumper(\Rails\ActiveRecord\ActiveRecord::connection());
             $dumper->export(\Rails::root() . '/db/schema.sql');
             break;
     }
 }
예제 #7
0
 public static function loadApplication($namespace, array $appConfig)
 {
     $className = $namespace . '\\Application';
     $config = self::serviceManager()->get('rails.config');
     $config->merge($appConfig);
     $rootPath = new Path($config['root']);
     $config->merge(['paths' => ['root' => $rootPath]], true);
     if (!isset($config['paths']['public_path'])) {
         $config['paths']['public_path'] = $rootPath->extend('public');
     } else {
         $config['paths']['public_path'] = new Path($config['paths']['public_path']);
     }
     self::$publicPath = $config['paths']['public_path'];
     $config['paths']['app'] = new Path('app', $rootPath);
     $config['paths']['config'] = new Path('config', $rootPath);
     require $config['paths']['config']->expand('application.php');
     $app = new $className($config);
     if (!self::$application) {
         self::$application = $app;
         # TODO: load/set app config
         self::$root = $config['paths']['root'];
         self::$serviceManager->setService('app.conf', $config);
         error_reporting(E_ALL);
         if (self::cli()) {
             $app->dispatchConsole();
             return $app;
         } else {
             return $app;
         }
     } else {
         return $app;
     }
 }
예제 #8
0
 public function tempfile_jpeg_path()
 {
     return Rails::root() . "/public/data/" . $this->md5 . "-jpeg.jpg";
 }
예제 #9
0
파일: User.php 프로젝트: JCQS04/myimouto
 public function set_avatar($params)
 {
     $post = Post::find($params['id']);
     if (!$post->can_be_seen_by($this)) {
         $this->errors()->add('access', "denied");
         return false;
     }
     if ($params['top'] < 0 or $params['top'] > 1 or $params['bottom'] < 0 or $params['bottom'] > 1 or $params['left'] < 0 or $params['left'] > 1 or $params['right'] < 0 or $params['right'] > 1 or $params['top'] >= $params['bottom'] or $params['left'] >= $params['right']) {
         $this->errors()->add('parameter', "error");
         return false;
     }
     $tempfile_path = Rails::root() . "/public/data/" . $this->id . ".avatar.jpg";
     $use_sample = $post->has_sample();
     if ($use_sample) {
         $image_path = $post->sample_path();
         $image_ext = "jpg";
         $size = $this->_reduce_and_crop($post->sample_width, $post->sample_height, $params);
         # If we're cropping from a very small region in the sample, use the full
         # image instead, to get a higher quality image.
         if ($size['crop_bottom'] - $size['crop_top'] < CONFIG()->avatar_max_height or $size['crop_right'] - $size['crop_left'] < CONFIG()->avatar_max_width) {
             $use_sample = false;
         }
     }
     if (!$use_sample) {
         $image_path = $post->file_path();
         $image_ext = $post->file_ext;
         $size = $this->_reduce_and_crop($post->width, $post->height, $params);
     }
     try {
         Moebooru\Resizer::resize($image_ext, $image_path, $tempfile_path, $size, 95);
     } catch (Moebooru\Exception\ResizeErrorException $x) {
         if (file_exists($tempfile_path)) {
             unlink($tempfile_path);
         }
         $this->errors()->add("avatar", "couldn't be generated (" . $x->getMessage() . ")");
         return false;
     }
     rename($tempfile_path, $this->avatar_path());
     chmod($this->avatar_path(), 0775);
     $this->updateAttributes(array('avatar_post_id' => $params['post_id'], 'avatar_top' => $params['top'], 'avatar_bottom' => $params['bottom'], 'avatar_left' => $params['left'], 'avatar_right' => $params['right'], 'avatar_width' => $size['width'], 'avatar_height' => $size['height'], 'avatar_timestamp' => date('Y-m-d H:i:s')));
     return true;
 }
예제 #10
0
 public function error()
 {
     $report = $this->params()->report;
     $file = Rails::root() . "/log/user_errors.log";
     if (!is_file($file)) {
         $fh = fopen($file, 'a');
         fclose($fh);
     }
     file_put_contents($file, $report . "\n\n\n-------------------------------------------\n\n\n", FILE_APPEND);
     $this->render(array('json' => array('success' => true)));
 }
예제 #11
0
 public function jpeg_path()
 {
     return Rails::root() . "/public/data/jpeg/" . $this->_file_hierarchy() . "/" . $this->_post->md5 . ".jpg";
 }
예제 #12
0
$config->eager_load_paths = [];
/**
 * Set's the cache storing class.
 *
 * For FileStore
 * cache_store ( string 'file_store', string $cache_path )
 *
 * For Memcached
 * cache_store ( string 'mem_cached_store' [, mixed $server1 [, mixed $server2 ... ] ] )
 * Defaults to host "localhost" and port 11211.
 * Examples:
 * Add 1 server with default options.
 * $config->cache_store = 'mem_cached_store';
 * Add 1 server with foobarhost as host and default port.
 * $config->cache_store = [ 'mem_cached_store', 'foobarhost' ];
 * Add 2 servers: one with localhost as host with default port, and the other one
 *  with other.server as host and 4456 as port.
 * $config->cache_store = [ 'mem_cached_store', 'localhost', ['other.server', 4456] ];
 */
$config->cache_store = ['file_store', Rails::root() . '/tmp/cache'];
/**
 * This is supposed to be used to set a custom logger.
 * But rather, customize the default logger in Application\Base::init().
 */
$config->logger = null;
$config->log_file = Rails::root() . '/log/' . Rails::env() . '.log';
/**
 * Accepts int from 0 to 8.
 */
$config->log_level = false;
return $config;
예제 #13
0
파일: Rails.php 프로젝트: railsphp/railsphp
 private static function setRailsConfig()
 {
     $paths = array_merge([get_include_path(), self::$root . '/lib', self::$root . '/vendor']);
     set_include_path(implode(PATH_SEPARATOR, $paths));
     # Set loader.
     require self::$path . '/Loader/Loader.php';
     self::$loader = new Rails\Loader\Loader([dirname(self::$path), self::$config->paths->models->toString(), self::$config->paths->helpers, self::$config->paths->controllers->toString(), self::$config->paths->mailers->toString(), self::$root . '/lib', self::$root . '/vendor']);
     # Set Composer autoloader.
     $autoloadFile = defined("COMPOSER_AUTOLOADER") ? COMPOSER_AUTOLOADER : Rails::root() . '/vendor/autoload.php';
     self::$loader->setComposerAutoload(require $autoloadFile);
     spl_autoload_register([Rails::loader(), 'loadClass']);
     set_exception_handler('Rails::exceptionHandler');
     register_shutdown_function('Rails::runSystemExit');
     # This will be re-set in Rails_Application, setting also the customized second parameter.
     set_error_handler('Rails::errorHandler', E_ALL);
 }