Exemplo n.º 1
0
function Application_BeginRequest()
{
    global $CurrentLang;
    if (isset($_GET['lang']) && $CurrentLang != $_GET['lang'] || isset($_GET['lang']) && $_GET['lang'] == 'en') {
        setcookie('lang', $_GET['lang'], time() + 2592000);
        if ($_GET['lang'] == 'en') {
            unset($_GET['lang']);
        }
        if (count($_GET) > 0) {
            \Nemiro\Server::$Url['query'] = $_GET;
        } else {
            unset(\Nemiro\Server::$Url['query']);
        }
        \Nemiro\Server::Redirect(\Nemiro\Server::$Url['path'] . (isset(\Nemiro\Server::$Url['query']) ? '?' . http_build_query(\Nemiro\Server::$Url['query']) : '') . (isset(\Nemiro\Server::$Url['fragment']) ? '#' . \Nemiro\Server::$Url['fragment'] : ''), 301);
    }
}
Exemplo n.º 2
0
 /**
  * Returns the physical file path that corresponds to the specified virtual path.
  * 
  * @param \string $path The virtual path in the application. 
  * 
  * @return \string
  */
 public static function MapPath($path)
 {
     $root = defined('MAIN_PATH') ? MAIN_PATH : $_SERVER['DOCUMENT_ROOT'];
     if ($path == NULL || $path === '') {
         return $root;
     }
     // $path = str_replace('\\', '/', $path);
     if (substr($path, 0, 1) == '~') {
         $path = $root . substr($path, 1, strlen($path) - 1);
     }
     return \Nemiro\Server::NormalizePathSeparators($path);
 }
Exemplo n.º 3
0
 function IncludeFile($path)
 {
     $path = \Nemiro\Server::MapPath($path);
     if (is_file($path)) {
         ob_start();
         require $path;
         $r = ob_get_contents();
         ob_end_clean();
     } else {
         $r = '<span style="color: Red">Ошибка. Объект <strong>' . $path . '</strong> не является файлом или отсутствует.</span>';
     }
     return $r;
 }
Exemplo n.º 4
0
 /**
  * Returns <input />.
  * 
  * @param \string $name The name of the element.
  * @param \string $type The type of the input.
  * @param \string $value The value of the input.
  * @param \array $htmlAttributes The additional attributes. Associative array - key = value.
  * 
  * @return \string
  */
 private static function Input($type, $name, $value, $htmlAttributes = NULL)
 {
     if (!isset($htmlAttributes) || count($htmlAttributes) <= 0) {
         $htmlAttributes = array();
     }
     $htmlAttributes['type'] = $type;
     $result = '<input ';
     $result .= Html::BuildAttributes($htmlAttributes) . ' ';
     $result .= 'name="' . $name . '" id="' . $name . '" ';
     if (\Nemiro\Server::IsPostBack() && isset($_POST[$name])) {
         $result .= 'value="' . $_POST[$name] . '" ';
     } else {
         if ($value != NULL && strlen($value) > 0) {
             $result .= 'value="' . $value . '" ';
         }
     }
     $result .= '/>';
     return $result;
 }
Exemplo n.º 5
0
 private function MergeResources($path)
 {
     $path = \Nemiro\Server::MapPath($path);
     if (file_exists($path)) {
         if (!($data = json_decode(file_get_contents($path), TRUE))) {
             \Nemiro\Console::Error('Resources file "%s" parse error #%s.', $path, json_last_error());
             return FALSE;
         } else {
             if (!isset($this->Resources)) {
                 $this->Resources = array();
             }
             foreach ($data as $item) {
                 $this->Resources[$item['Key']] = $item['Value'];
             }
             return TRUE;
         }
     } else {
         return FALSE;
     }
 }
Exemplo n.º 6
0
 /**
  * Includes the specified file.
  * 
  * @param \string|\string[] $path The file path to include.
  */
 public static function IncludeFile($path)
 {
     if (gettype($path) == 'array') {
         foreach ($path as $p) {
             App::IncludeFile($p);
         }
     } else {
         if (substr($path, 0, 1) == '~') {
             $path = \Nemiro\Server::MapPath($path);
         }
         if (is_dir($path)) {
             if (is_file($path . '/Import.php')) {
                 App::IncludeFile($path . '/Import.php');
             } else {
                 throw new \ErrorException('`' . $path . '/Import.php` not found. Specify the full path to a file, or create import rules.');
             }
         } else {
             require_once $path;
             App::RaiseEvent('Application_IncludedFile', $path);
         }
     }
 }
Exemplo n.º 7
0
				<php:Items>
					<php:TabItem Key="TabControl" Title="TabControl.php">
						<pre><code class="php"><?php 
echo str_replace("\t", '  ', \Nemiro\Text::HtmlEncode(file_get_contents(\Nemiro\Server::MapPath('~/Controls/TabControl.php'))));
?>
</code></pre>
					</php:TabItem>
					<php:TabItem Key="TabItem" Title="TabItem.php">
						<pre><code class="php"><?php 
echo str_replace("\t", '  ', \Nemiro\Text::HtmlEncode(file_get_contents(\Nemiro\Server::MapPath('~/Controls/TabItem.php'))));
?>
</code></pre>
					</php:TabItem>
					<php:TabItem Key="TabControlHtml" Title="TabControl.html.php">
						<pre><code class="html"><?php 
echo str_replace("\t", '  ', \Nemiro\Text::HtmlEncode(file_get_contents(\Nemiro\Server::MapPath('~/Controls/TabControl.html.php'))));
?>
</code></pre>
					</php:TabItem>
				</php:Items>
			</php:TabControl>
			<p>${ObjectModelText10}</p>
			<p>${ObjectModelText11}</p>
			<pre><code class="html">&lt;php:TabControl&gt;
  &lt;php:Items&gt;
    &lt;php:TabItem Key="Item1" Title="${Tab} #1"&gt;
      ${TabContent} #1
    &lt;/php:TabItem&gt;
    &lt;php:TabItem Key="Item2" Title="${Tab} #2"&gt;
      ${TabContent} #2
    &lt;/php:TabItem&gt;