public function __construct() { $method = \Rails::application()->dispatcher()->request()->method(); if ($method != 'GET' && $method != 'POST') { $params = file_get_contents('php://input'); $decoded = []; if (!empty($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == "application/json") { $decoded = json_decode($params, true); if ($decoded === null) { $decoded = []; $this->_json_params_error = json_last_error(); } } else { parse_str($params, $decoded); } if ($method == 'DELETE') { $this->deleteVars = $decoded; } elseif ($method == 'PUT') { $this->putVars = $decoded; } elseif ($method == 'PATCH') { $this->patchVars = $decoded; } else { $this->other_params = $decoded; } } $this->_import_files(); // vpe($this->files); }
private function defaultParams() { $defaults = \Rails::application()->config()->cookies->toArray(); if (!$defaults['path']) { $defaults['path'] = \Rails::application()->router()->basePath() . '/'; } return $defaults; }
public function _render_view() { # Include helpers. ActionView\ViewHelpers::load(); $layout = !empty($this->_params['layout']) ? $this->_params['layout'] : false; $this->_template = new ActionView\Template(['lambda' => $this->_params['lambda']], ['layout' => $layout]); $this->_template->setLocals(\Rails::application()->controller()->locals()); $this->_template->renderContent(); }
public function linkTo($link, $url_params, array $attrs = array()) { if ($url_params == 'root') { return $this->base()->linkTo($link, $url_params, $attrs); } else { $base_path = Rails::application()->router()->basePath(); $attrs['href'] = $base_path . '/' . Rails::application()->config()->rails_panel_path . '/' . substr($url_params, 1); return $this->contentTag('a', $link, $attrs); } }
public function _render_view() { # Include helpers. ActionView\ViewHelpers::load(); $layout = !empty($this->_params['layout']) ? $this->_params['layout'] : false; # Create a template so we can call render_inline; $this->_template = new ActionView\Template(['inline' => $this->_params['code']], ['layout' => $layout]); $this->_template->setLocals(\Rails::application()->controller()->vars()); $this->_template->renderContent(); }
private function buildRequestInfo() { if (\Rails::application()->dispatcher() && ($request = \Rails::application()->dispatcher()->request())) { $info = '[' . $request->remoteIp() . '] ' . $request->method() . ' ' . $request->fullPath(); } elseif (\Rails::cli()) { $info = '[cli]'; } else { $info = ''; } return $info; }
/** * Returns the asset path (i.e., the URL) for a file. * If the digest option is true, the path to the compiled file * (with fingerprint) will be returned, if found. Otherwise, $file * will just be appended to the assets path. * Note that $file could include path relative to assets path, if necessary, * like $this->assetPath('jquery-ui/loading.gif'); */ protected function assetPath($file, array $options = []) { if (!isset($options['digest'])) { $options['digest'] = true; } if ($options['digest']) { if ($path = \Rails::assets()->findCompiledFile($file)) { return $path; } } $root = \Rails::application()->router()->rootPath(); if ($root == '/') { $root = ''; } return $root . \Rails::assets()->prefix() . '/' . $file; }
public function assetPath($source, array $options = []) { if (strpos($source, '/') !== 0 && strpos($source, 'http') !== 0) { if (!isset($options['digest'])) { $options['digest'] = true; } if (\Rails::config()->assets->enabled) { if (\Rails::config()->serve_static_assets && $options['digest']) { if ($url = \Rails::assets()->findCompiledFile($source)) { return $url; } } if ($file = \Rails::assets()->findFile($source)) { return $file->url(); } } return \Rails::application()->router()->rootPath() . $source; } else { return $source; } }
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 _render_view() { # Include helpers. ActionView\ViewHelpers::load(); $layout = !empty($this->_params['layout']) ? $this->_params['layout'] : false; $partial = $this->_params['partial']; $locals = (array) \Rails::application()->controller()->locals(); $this->_template = new ActionView\Template(['lambda' => function () use($partial, $locals) { echo $this->partial($partial, $locals); }], ['layout' => $layout]); // $this->_template->setLocals(); $this->_template->renderContent(); // $params = [$this->_params['partial']]; // if (isset($this->_params['locals'])) // $params = array_merge($params, [$this->_params['locals']]); # Include helpers. // ActionView\ViewHelpers::load(); # Create a template so we can call render_partial. # This shouldn't be done this way. // $template = new ActionView\Template([]); // vpe($this); // $this->_body = call_user_func_array([$template, 'renderContent'], $params); }
echo $this->linkTo('Compile assets', '#compile_assets'); ?> </li> <li><?php echo $this->linkTo('Create files', '#create_files'); ?> </li> <li><?php echo $this->linkTo('Generate database cache', '#gen_table_data'); ?> </li> </ul> <div class="pull-right navbar-text"> <?php echo $this->linkTo('Back to ' . Rails::application()->name(), 'root', ['class' => 'navbar-link']); ?> </div> </div> </div> <div class="container"> <div class="row"> <div class="navbar-default" style="text-align:center;margin-bottom:2em;"> </div> </div> <div class="row"> <?php echo $this->content(); ?> </div>
private function _error_message() { switch ($this->_type) { case 'number': case 'length': if ($this->_result == 2 && (!empty($this->_params['even']) || !empty($this->_params['odd']))) { $type = !empty($this->_params['even']) ? "even" : "odd"; $params = ["odd"]; } else { if (!empty($this->_params['in'])) { if ($this->_result == -1) { $params = ['greater_than_or_equal_to', ['count' => $this->_params['in'][0]]]; } else { $params = ['less_than_or_equal_to', ['count' => $this->_params['in'][1]]]; } } elseif (!empty($this->_params['is'])) { $params = ['equal_to', ['count' => $this->_params['is']]]; } elseif (!empty($this->_params['minimum'])) { $params = ['greater_than_or_equal_to', ['count' => $this->_params['minimum']]]; } elseif (!empty($this->_params['maximum'])) { $params = ['less_than_or_equal_to', ['count' => $this->_params['maximum']]]; } } break; case 'blank': $params = ['blank']; break; case 'uniqueness': $params = ['uniqueness']; break; case 'confirmation': $params = ["confirmation"]; break; default: $params = ['invalid']; break; } $params[0] = 'errors.messages.' . $params[0]; return call_user_func_array([\Rails::application()->I18n(), 't'], $params); }
PREFIX = '<?php echo Rails::application()->router()->rootPath(); ?> ';
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; } }
protected function createRoutes() { $router = \Rails::application()->dispatcher()->router(); $routes = [['root', '', '/', $router->rootRoute()->to()]]; foreach ($router->routes() as $route) { $routes[] = [$route->alias() ?: '', strtoupper(implode(', ', $route->via())), '/' . $route->url(), $route->to()]; } $aliasMaxLen = 0; $viaMaxLen = 0; $pathMaxLen = 0; $toMaxLen = 0; foreach ($routes as $route) { $aliasLen = strlen($route[0]); $viaLen = strlen($route[1]); $pathLen = strlen($route[2]); if ($aliasLen > $aliasMaxLen) { $aliasMaxLen = $aliasLen; } if ($viaLen > $viaMaxLen) { $viaMaxLen = $viaLen; } if ($pathLen > $pathMaxLen) { $pathMaxLen = $pathLen; } } $lines = []; foreach ($routes as $route) { $route[0] = str_pad($route[0], $aliasMaxLen, ' ', STR_PAD_LEFT); $route[1] = str_pad($route[1], $viaMaxLen, ' '); $route[2] = str_pad($route[2], $pathMaxLen, ' '); $lines[] = implode(' ', $route); } return implode("\n", $lines); }
protected function getNamedPath($method, array $params = []) { $alias = \Rails::services()->get('inflector')->underscore(substr($method, 0, -4)); return \Rails::application()->router()->url_helpers()->find_route_with_alias($alias, $params); }
protected function _render_view() { $url = \Rails::application()->router()->urlFor($this->_redirect_params); \Rails::application()->dispatcher()->response()->headers()->location($url); }
protected final function isUserAllowed() { if (!Rails::application()->validateSafeIps()) { $this->render(['action' => 'forbidden'], ['status' => 403]); } }
<?php $url = Rails::application()->router()->url_helpers(); ?> jQuery(document).ready(function($) { $('input.ac-user-name').autocomplete({ source: '<?php echo $url->acUserNamePath(); ?> ', minLength: 2 }); $('input.ac-tag-name').autocomplete({ source: '<?php echo $url->acTagNamePath(); ?> ', minLength: 2 }); if ($('#edit-form').length && $('textarea.ac-tags').length) { new TagCompletionBox($('textarea.ac-tags')[0]); if (TagCompletion) { TagCompletion.observe_tag_changes_on_submit($('#edit-form')[0], $('input.ac-tags')[0], null); }; }; });
(function() { var loaded = false; idxScroll = function() { if (loaded) { return; } loaded = true; var postPreviewTpl = '<div class="post-preview">' + '<h3 class="post-title"><a href="post.showUrl">post.title</a></h3>' + '<div class="post-image-container"><a href="post.showUrl"><img src="post.imageUrl"></a></div>' + '</div>'; var nextPage = 1; var postsUrl = '<?php echo Rails::application()->routes()->pathFor('base'); ?> /posts/get_images'; var canLoadMore = true; var busy = false; initScrollLoad = function() { var minHeightPercentage = 80; var ww = $(window); var dd = $(document); var scrollCb = function() { if (!canLoadMore) { ww.unbind('scroll', scrollCb); return; }
private static function _early_exception($e, $html) { self::log()->exception($e); if (Rails::application() && Rails::application()->config()->consider_all_requests_local) { echo $html; } else { echo "<strong>An error occured.</strong>"; } exit; }
public function redirectTo($redirect_params, array $params = array()) { $redirect_params[0] = '/' . Rails::application()->config()->rails_panel_path . '/' . $redirect_params[0]; parent::redirectTo($redirect_params, $params); }
public function headers() { return \Rails::application()->dispatcher()->headers(); }
public function router() { return \Rails::application()->router(); }
function CONFIG() { return Rails::application()->booruConfig(); }
<br /> <div class="well"> <?php echo $this->formTag([], ['style' => 'margin-bottom:0px;'], function () { ?> <table class="table" style="width:100%;margin-bottom:0px;"> <thead> <tr> <th>Assets folder</th> <th>File name</th> </tr> </thead> <tbody> <tr> <td><?php echo Rails::application()->config()->assets->prefix . '/'; ?> </td> <td><?php echo $this->textFieldTag('file', $this->params()->file, ['size' => 40, 'autofocus', 'placeholder' => 'E.g. application.css']); ?> </td> </tr> <tr><td colspan="3" style="text-align:center;"><?php echo $this->submitTag('Compile file', ['class' => 'btn btn-primary']); ?> </td></tr> </tbody> </table><?php }); ?>
public function format() { if ($route = \Rails::application()->dispatcher()->router()->route()) { return $route->format; } }