예제 #1
0
 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);
 }
예제 #2
0
 private function defaultParams()
 {
     $defaults = \Rails::application()->config()->cookies->toArray();
     if (!$defaults['path']) {
         $defaults['path'] = \Rails::application()->router()->basePath() . '/';
     }
     return $defaults;
 }
예제 #3
0
 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();
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
 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();
 }
예제 #6
0
 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;
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
 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;
     }
 }
예제 #9
0
파일: Error.php 프로젝트: railsphp/railsphp
 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;
 }
예제 #10
0
 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);
 }
예제 #11
0
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>
예제 #12
0
 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);
 }
예제 #13
0
PREFIX = '<?php 
echo Rails::application()->router()->rootPath();
?>
';
예제 #14
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;
     }
 }
예제 #15
0
 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);
 }
예제 #16
0
 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);
 }
예제 #17
0
 protected function _render_view()
 {
     $url = \Rails::application()->router()->urlFor($this->_redirect_params);
     \Rails::application()->dispatcher()->response()->headers()->location($url);
 }
예제 #18
0
 protected final function isUserAllowed()
 {
     if (!Rails::application()->validateSafeIps()) {
         $this->render(['action' => 'forbidden'], ['status' => 403]);
     }
 }
예제 #19
0
<?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);
    };
  };
});
예제 #20
0
(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;
      }
예제 #21
0
파일: Rails.php 프로젝트: railsphp/railsphp
 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;
 }
예제 #22
0
 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);
 }
예제 #23
0
 public function headers()
 {
     return \Rails::application()->dispatcher()->headers();
 }
예제 #24
0
 public function router()
 {
     return \Rails::application()->router();
 }
예제 #25
0
function CONFIG()
{
    return Rails::application()->booruConfig();
}
예제 #26
0
  <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 
});
?>
예제 #27
0
 public function format()
 {
     if ($route = \Rails::application()->dispatcher()->router()->route()) {
         return $route->format;
     }
 }