public function tempfile_prefix() { if (!$this->tempfile_prefix) { $this->tempfile_prefix = \Rails::publicPath() . '/data/temp-' . uniqid('tfp_'); } return $this->tempfile_prefix; }
/** * Boots system. */ public static function initialize() { self::$cli = PHP_SAPI === 'cli'; # Set Rails path self::$path = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__); // self::$path = str_replace(DIRECTORY_SEPARATOR, '/', RAILS_PATH); # Set root path self::$root = str_replace(DIRECTORY_SEPARATOR, '/', RAILS_ROOT); # Set public path self::$publicPath = defined('RAILS_PUBLIC_PATH') ? RAILS_PUBLIC_PATH : self::$root . '/public'; self::$publicPath = str_replace(DIRECTORY_SEPARATOR, '/', self::$publicPath); /** * Set environment. */ self::$env = RAILS_ENV; self::$config = self::defaultConfig(); # Debugging functions... include self::$path . '/Toolbox/functions.php'; self::setRailsConfig(); }
public function _render_view() { $buffer = ''; $this->_report = $this->_params['report']; unset($this->_params['report']); if (\Rails::application()->config()->consider_all_requests_local) { $no_html = \Rails::cli(); if ($no_html) { $buffer .= strip_tags($this->_report); $buffer .= "\n"; } else { $buffer .= $this->_header(); $buffer .= $this->_report; $buffer .= $this->_footer(); } } else { $file = \Rails::publicPath() . '/' . $this->_params['status'] . '.html'; if (is_file($file)) { $buffer = file_get_contents($file); } } $this->_buffer = $buffer; }
public function sample_path() { return Rails::publicPath() . '/data/inline/sample/' . $this->file_name_jpg(); }
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; } }
public static function search_cache_dir() { return Rails::publicPath() . self::SEARCH_CACHE_DIR; }
$c->put('done'); # Run seeds $c->write("Seeding.............."); $migrator->runSeeds(); $c->put('done'); # Create user in database $c->write("Creating admin account..."); Rails\ActiveRecord\ActiveRecord::connection()->executeSql('INSERT INTO users (created_at, name, password_hash, level, show_advanced_editing) VALUES (?, ?, ?, ?, ?)', date('Y-m-d H:i:s'), $adminName, User::sha1($adminPass), 50, 1); Rails\ActiveRecord\ActiveRecord::connection()->executeSql('INSERT INTO user_blacklisted_tags VALUES (?, ?)', 1, implode("\r\n", CONFIG()->default_blacklists)); $c->put("done"); /** * Create /public/data folders */ $c->put("\n"); $c->write("Creating /public/data folders..."); $dataPath = Rails::publicPath() . '/data'; $dirs = ['avatars', 'image', 'import', 'jpeg', 'preview', 'sample']; if (!is_dir($dataPath)) { mkdir($dataPath); } foreach ($dirs as $dir) { $path = $dataPath . '/' . $dir; if (!is_dir($path)) { mkdir($path); } } /** * Compile assets */ $c->put("\n"); $c->put("Compiling assets", null, Color::BLUE);
public function import() { $import_dir = Rails::publicPath() . '/data/import/'; if ($this->request()->isPost()) { if ($this->request()->format() == 'json') { foreach (explode('::', $this->params()->dupes) as $file) { $file = stripslashes(utf8_decode($file)); $file = $import_dir . $file; if (file_exists($file)) { unlink($file); } else { $error = true; } } $resp = !empty($error) ? array('reason' => 'Some files could not be deleted') : array('success' => true); $this->render(array('json' => $resp)); return; } $this->setLayout(false); $this->errors = $this->dupe = false; $post = $this->params()->post; $post['filename'] = stripslashes(utf8_decode($post['filename'])); $filepath = $import_dir . $post['filename']; # Take folders as tags if (is_int(strpos($post['filename'], '/'))) { $folders = str_replace('#', ':', $post['filename']); $tags = array_filter(array_unique(array_merge(explode(' ', $post['tags']), explode('/', $folders)))); array_pop($tags); $post['tags'] = trim($post['tags'] . ' ' . implode(' ', $tags)); } $post = array_merge($post, array('ip_addr' => $this->request()->remoteIp(), 'user_id' => current_user()->id, 'status' => 'active', 'tempfile_path' => $filepath, 'tempfile_name' => $post['filename'], 'is_import' => true)); unset($post['filename'], $post['i']); $this->post = Post::create($post); if ($this->post->errors()->blank()) { $this->import_status = 'Posted'; } elseif ($this->post->errors()->invalid('md5')) { $this->dupe = true; $this->import_status = 'Already exists'; $this->post = Post::where(['md5' => $this->post->md5])->first(); $this->post->status = 'flagged'; } else { $this->errors = $this->post->errors()->fullMessages('<br />'); $this->import_status = 'Error'; } } else { $this->set_title('Import'); $this->invalid_files = $this->files = []; list($this->files, $this->invalid_files, $this->invalid_folders) = Post::get_import_files($import_dir); $pools = Pool::where('is_active')->take(); if ($pools) { $this->pool_list = '<datalist id="pool_list">'; foreach ($pools as $pool) { $this->pool_list .= '<option value="' . str_replace('_', ' ', $pool->name) . '" />'; } $this->pool_list .= '</datalist>'; } else { $this->pool_list = null; } } }