Ejemplo n.º 1
0
function redirect($loc)
{
    $url = getFullURL($loc);
    // technically, a die(header('Location: '.$url)); would suffice for all web browsers... ~J
    header('Location: ' . $url);
    echo '<html>' . "\n";
    echo "\t" . ' <head>' . "\n";
    echo "\t\t" . ' <title>Redirecting...</title>' . "\n";
    echo "\t\t" . ' <meta http-equiv="refresh" content="0; url=' . $url . '" />' . "\n";
    echo "\t\t" . ' <script type="application/x-javascript"><![CDATA[ window.location.href = \'' . $url . '\'; ]]></script>' . "\n";
    echo "\t" . ' </head>' . "\n";
    echo "\t" . ' <body>' . "\n";
    echo "\t\t" . ' <p>If you are not automatically redirected, please click <a href="' . $url . '">here</a> to continue.</p>' . "\n";
    echo "\t" . ' </body>' . "\n";
    echo '</html>';
}
Ejemplo n.º 2
0
 /**
  * 系统初始化函数,主要初始化smarty模板引擎,定义一些主要的全局模板路径
  * @param $c 控制器名称
  */
 public function _sys_init_action($c)
 {
     $this->smt = new Smarty();
     $this->smt->left_delimiter = "{";
     $this->smt->right_delimiter = "}";
     //模板目录,模板命名为方法名驼峰转下划线,再小写
     $tmpDir = APP_PATH . "/tpl/" . strtolower(toUnderLineName($c));
     //模板编译缓存目录
     $cmpDir = TEMP_PATH . "/tpl_c";
     $this->smt->setTemplateDir($tmpDir)->setCompileDir($cmpDir);
     //定义程序相对路径
     $this->smt->assign("myf_path", getBasePath());
     //定义程序绝对URL路径
     $this->smt->assign("myf_full_url", getFullURL());
     //定义程序根目录绝对URL路径
     $this->smt->assign("myf_project_url", getProjectURL());
 }
Ejemplo n.º 3
0
 /**
  * 获取上传的图片
  * @param string $fileKey
  * @return array
  * @throws Exception
  */
 public static function getPic($fileKey = "file")
 {
     //允许的后缀
     $exts = array("gif", "jpeg", "jpg", "png");
     //允许的文件格式
     $types = array("image/gif", "image/jpeg", "image/jpg", "image/pjpeg", "image/x-png", "image/png");
     //最大大小
     $maxSize = 20 * 1000;
     $error = "";
     if (isset($_FILES) && isset($_FILES[$fileKey])) {
         $file = $_FILES[$fileKey];
         $enames = explode(".", $file["name"]);
         $ext = end($enames);
         $type = $file["type"];
         $size = $file["size"];
         //验证图片格式
         if (!in_array($ext, $exts)) {
             $error = "上传图片格式错误,仅支持:" . join(",", $exts);
         }
         //验证图片类型
         if (empty($error) && !in_array($type, $types)) {
             $error = "上传图片类型错误,仅支持:" . join(",", $types);
         }
         //验证大小
         if (empty($error) && $size > $maxSize) {
             $error = "上传图片的大小超过:" . $maxSize . "bit";
         }
         if (empty($error)) {
             $tmpName = $file["tmp_name"];
             //重命名图片,随机不重复
             $filename = "/uploads/pics/" . uniqid(mt_rand(), true) . "." . $ext;
             $filepath = APP_PATH . $filename;
             createFolders(APP_PATH . "/uploads/pics/");
             move_uploaded_file($tmpName, $filepath);
             $res = array("filename" => $filename, "url" => getFullURL() . $filename);
             return $res;
         }
     } else {
         $error = "上传图片为空";
     }
     throw new Exception($error);
 }
Ejemplo n.º 4
0
function areWeInIgnoredUrl()
{
    if (basename(DIR_APPLICATION) != 'catalog') {
        return true;
    }
    $url = getFullURL();
    $ignoredUrls = getIgnoredUrls();
    foreach ($ignoredUrls as $ignoredUrl) {
        if ($ignoredUrl[0] != '!') {
            if (preg_match('~' . str_replace(array('~', '#asterisk#'), array('\\~', '.*'), preg_quote(str_replace('*', '#asterisk#', $ignoredUrl))) . '~', $url)) {
                return true;
            }
        } else {
            if (!preg_match('~' . str_replace(array('~', '#asterisk#'), array('\\~', '.*'), preg_quote(str_replace('*', '#asterisk#', substr($ignoredUrl, 1)))) . '~', $url)) {
                return true;
            }
        }
    }
    return false;
}
Ejemplo n.º 5
0
/**
 * 获取项目相对URL路径
 * @return null
 */
function getProjectURL()
{
    $sysPath = dirname(dirname(__FILE__));
    $cwd = getcwd();
    $filepath = str_replace($sysPath, "", $cwd);
    $url = str_replace($filepath, "", getFullURL());
    return $url;
}
Ejemplo n.º 6
0
function generateNameOfCacheFile()
{
    if (!empty($GLOBALS['nitro.pagecache.file'])) {
        return $GLOBALS['nitro.pagecache.file'];
    }
    nitroEnableSession();
    if (empty($_SESSION['language']) && empty($_SESSION['currency'])) {
        $db = NitroDb::getInstance();
        $db->query("SET NAMES 'utf8'");
        $db->query("SET CHARACTER SET utf8");
        $db->query("SET CHARACTER_SET_CONNECTION=utf8");
        $db->query("SET SQL_MODE = ''");
        // In, when the site is opened for first time
        // Store
        if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == '1')) {
            $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
        } else {
            $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
        }
        $store_id = 0;
        if ($store_query->num_rows) {
            $result = $store_query->row;
            $store_id = (int) $result['store_id'];
        }
        $GLOBALS['nitro.store_id'] = $store_id;
        $resource = $db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE (`key`='config_language' OR `key`='config_currency') AND `store_id` = '" . $store_id . "'");
        if ($resource->num_rows) {
            $data = array();
            $config_language = 0;
            $config_currency = 0;
            foreach ($resource->rows as $result) {
                if (!empty($result['key']) && $result['key'] == 'config_language') {
                    $config_language = strtolower($result['value']);
                }
                if (!empty($result['key']) && $result['key'] == 'config_currency') {
                    $config_currency = strtolower($result['value']);
                }
            }
            if (isset($_SESSION)) {
                $_SESSION['language'] = $config_language;
                $_SESSION['currency'] = $config_currency;
            }
        }
    }
    $filename = getFullURL();
    $filename = str_replace(array('/', '?', ':', ';', '=', '&amp;', '&', '.', '--', '%', '~', '-amp-'), '-', $filename);
    $default_language = !empty($_COOKIE['language']) ? $_COOKIE['language'] : '0';
    $default_currency = !empty($_COOKIE['currency']) ? $_COOKIE['currency'] : '0';
    $language = strtolower(!empty($_SESSION['language']) && is_string($_SESSION['language']) ? $_SESSION['language'] : $default_language);
    $currency = strtolower(!empty($_SESSION['currency']) && is_string($_SESSION['currency']) ? $_SESSION['currency'] : $default_currency);
    if (NITRO_DEBUG_MODE) {
        $cached_filename = $filename . '-' . $language . '-' . $currency . '.html';
    } else {
        $cached_filename = md5($filename . '-' . $language . '-' . $currency) . '.html';
    }
    if (mobileCheck()) {
        $cached_filename = 'mobile-' . $cached_filename;
    }
    $GLOBALS['nitro.pagecache.file'] = getSSLCachePrefix() . $cached_filename;
    return $GLOBALS['nitro.pagecache.file'];
}
Ejemplo n.º 7
0
            foreach ($r->mods as $modifiedResource) {
                switch ($modifiedResource->action) {
                    case 'A':
                        $description .= '+ ';
                        break;
                    case 'M':
                        $description .= '~ ';
                        break;
                    case 'D':
                        $description .= 'x ';
                        break;
                }
                $description .= $modifiedResource->path . '<br />';
            }
        }
        $itemLink = getFullURL($baseurl . $config->getURL($rep, '', 'revision') . 'rev=' . $r->rev);
        $rss .= '<item>';
        $rss .= '<pubDate>' . date('r', $r->committime) . '</pubDate>';
        $rss .= '<dc:creator>' . htmlspecialchars($r->author) . '</dc:creator>';
        $rss .= '<title>' . htmlspecialchars($title) . '</title>';
        $rss .= '<description>' . htmlspecialchars($description) . '</description>';
        $rss .= '<link>' . $itemLink . '</link>';
        $rss .= '<guid>' . $itemLink . '</guid>';
        $rss .= '</item>' . "\n";
    }
}
$rss .= '</channel></rss>';
if ($rep->isRssCachingEnabled()) {
    $file = fopen($cache, 'w+');
    if ($file) {
        fputs($file, $rss);
Ejemplo n.º 8
0
/**
 * This function runs the PhantomJS tests by calling the Browser shell to
 * execute the PhantomJs tests written in JavaScript.
 */
function runBrowserTests()
{
    if (ob_get_clean()) {
        ob_clean();
    }
    $path_url = str_replace(basename(__DIR__) . "/", "", getFullURL(true));
    $mode = "";
    $resp_code = "";
    $u = $_REQUEST['u'];
    $p = $_REQUEST['p'];
    if (isset($_REQUEST['mode'])) {
        if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == "true") {
            $debug = true;
        } else {
            $debug = "false";
        }
        $mode = htmlentities($_REQUEST['mode'], ENT_QUOTES, "UTF-8");
        $resp = array();
        if (!in_array($mode, array("web", "mobile"))) {
            $resp_code = "HTTP/1.1 400 Bad Request";
        } else {
            try {
                $browser_runner = new BrowserRunner();
                $test_results = $browser_runner->execute("phantomjs_runner.js", $path_url, $mode, $debug, $u, $p);
                if (!$test_results) {
                    $resp_code = "HTTP/1.1 500";
                } else {
                    $resp['results'] = $test_results;
                    $resp_code = "HTTP/1.1 200 OK";
                }
            } catch (Exception $e) {
                $resp_code = "HTTP/1.1 500";
                $resp['error'] = $e->getMessage();
            }
        }
    } else {
        $resp_code = "HTTP/1.1 500";
        $resp['error'] = "Bad Request";
    }
    header($resp_code);
    header("Content-Type : application/json");
    echo json_encode($resp);
    exit;
}
Ejemplo n.º 9
0
Archivo: top.php Proyecto: BulatSa/Ctex
function generateNameOfCacheFile()
{
    if (empty($_SESSION['language']) && empty($_SESSION['currency'])) {
        // In, when the site is opened for first time
        if ($link = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD)) {
            if (mysql_select_db(DB_DATABASE, $link)) {
                mysql_query("SET NAMES 'utf8'", $link);
                mysql_query("SET CHARACTER SET utf8", $link);
                mysql_query("SET CHARACTER_SET_CONNECTION=utf8", $link);
                mysql_query("SET SQL_MODE = ''", $link);
                $resource = mysql_query("SELECT * FROM " . DB_PREFIX . "setting WHERE `key`='config_language' OR `key`='config_currency'", $link);
                if ($resource && is_resource($resource)) {
                    $data = array();
                    $config_language = 0;
                    $config_currency = 0;
                    while ($result = mysql_fetch_assoc($resource)) {
                        if (!empty($result['key']) && $result['key'] == 'config_language') {
                            $config_language = strtolower($result['value']);
                        }
                        if (!empty($result['key']) && $result['key'] == 'config_currency') {
                            $config_currency = strtolower($result['value']);
                        }
                    }
                    if (isset($_SESSION)) {
                        $_SESSION['language'] = $config_language;
                        $_SESSION['currency'] = $config_currency;
                    }
                }
                mysql_close($link);
            }
        }
    }
    $filename = getFullURL();
    $filename = str_replace(array('/', '?', ':', ';', '=', '&amp;', '&', '.', '--', '%', '~', '-amp-'), '-', $filename);
    $language = strtolower(!empty($_SESSION['language']) ? $_SESSION['language'] : '0');
    $currency = strtolower(!empty($_SESSION['currency']) ? $_SESSION['currency'] : '0');
    if (NITRO_MODE) {
        //if > 0 than we are in debug mode
        $cached_filename = $filename . '-' . $language . '-' . $currency . '.html';
    } else {
        $cached_filename = md5($filename . '-' . $language . '-' . $currency) . '.html';
    }
    return getSSLCachePrefix() . $cached_filename;
}