Beispiel #1
0
 /**
  * Test for Lang::set()
  *
  * @test
  */
 public function test_set()
 {
     Lang::set('testing_set_valid', 'Ahoy :name!');
     $output = Lang::get('testing_set_valid', array('name' => 'Bob'));
     $expected = 'Ahoy Bob!';
     $this->assertEquals($expected, $output);
 }
 /**
  * Frontend
  */
 public function dFrontendInitialised()
 {
     if (!$this->meetDependencies(true)) {
         return;
     }
     $this->_initFLang();
     Lang::set(FLang::getLangCode());
 }
 /**
  * The news link for the home pages
  * @return <html>
  */
 public static function news($hnumber = 2)
 {
     $html = '<div id="news">';
     $textQuery = "\r\n\t\tSELECT idNews, publish_date, title, short_desc\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_news\r\n\t\tWHERE language = '" . getLanguage() . "'\r\n\t\tORDER BY important DESC, publish_date DESC\r\n\t\tLIMIT 0," . Get::sett('visuNewsHomePage');
     //do query
     $result = sql_query($textQuery);
     if (sql_num_rows($hnumber)) {
         $html .= '<p>' . Lang::set('_NO_CONTENT', 'login') . '</p>';
     }
     while (list($idNews, $publish_date, $title, $short_desc) = sql_fetch_row($result)) {
         $html .= '<h' . $hnumber . '>' . '<a href="index.php?modname=login&amp;op=readnews&amp;idNews=' . $idNews . '">' . $title . '</a>' . '</h' . $hnumber . '>' . '<p class="news_textof">' . '<span class="news_data">' . Format::date($publish_date) . ' - </span>' . $short_desc . '</p>';
     }
     $html .= '</div>';
     return $html;
 }
Beispiel #4
0
function setLanguage()
{
    $lang = 'en';
    // Fetch language requests
    if (!empty($_REQUEST['lang'])) {
        $lang = preg_replace('/[^a-zA-Z\\-]/', NULL, $_REQUEST['lang']);
    }
    // Set language
    try {
        Lang::initialize();
        Lang::set($lang, false);
    } catch (Exception $s) {
        return NULL;
    }
    return true;
}
Beispiel #5
0
 /**
  * This function determines whether an there is a currently logged in
  * Author for Symphony by using the `$Cookie`'s username
  * and password. If an Author is found, they will be logged in, otherwise
  * the `$Cookie` will be destroyed.
  *
  * @see core.Cookie#expire()
  */
 public function isLoggedIn()
 {
     // Ensures that we're in the real world.. Also reduces three queries from database
     // We must return true otherwise exceptions are not shown
     if (is_null(self::$_instance)) {
         return true;
     }
     if ($this->Author) {
         return true;
     } else {
         $username = self::Database()->cleanValue($this->Cookie->get('username'));
         $password = self::Database()->cleanValue($this->Cookie->get('pass'));
         if (strlen(trim($username)) > 0 && strlen(trim($password)) > 0) {
             $author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf("\n\t\t\t\t\t\t\t`username` = '%s'\n\t\t\t\t\t\t", $username));
             if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), true)) {
                 $this->Author = current($author);
                 self::Database()->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', sprintf(" `id` = %d", $this->Author->get('id')));
                 // Only set custom author language in the backend
                 if (class_exists('Administration')) {
                     Lang::set($this->Author->get('language'));
                 }
                 return true;
             }
         }
         $this->Cookie->expire();
         return false;
     }
 }
 /**
  * Attempts to log an Author in given a username and password.
  * If the password is not hashed, it will be hashed using the sha1
  * algorithm. The username and password will be sanitized before
  * being used to query the Database. If an Author is found, they
  * will be logged in and the sanitized username and password (also hashed)
  * will be saved as values in the `$Cookie`.
  *
  * @see toolkit.Cryptography#hash()
  * @throws DatabaseException
  * @param string $username
  *  The Author's username. This will be sanitized before use.
  * @param string $password
  *  The Author's password. This will be sanitized and then hashed before use
  * @param boolean $isHash
  *  If the password provided is already hashed, setting this parameter to
  *  true will stop it becoming rehashed. By default it is false.
  * @return boolean
  *  True if the Author was logged in, false otherwise
  */
 public static function login($username, $password, $isHash = false)
 {
     $username = trim(self::Database()->cleanValue($username));
     $password = trim(self::Database()->cleanValue($password));
     if (strlen($username) > 0 && strlen($password) > 0) {
         $author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf("`username` = '%s'", $username));
         if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), $isHash)) {
             self::$Author = current($author);
             // Only migrate hashes if there is no update available as the update might change the tbl_authors table.
             if (self::isUpgradeAvailable() === false && Cryptography::requiresMigration(self::$Author->get('password'))) {
                 self::$Author->set('password', Cryptography::hash($password));
                 self::Database()->update(array('password' => self::$Author->get('password')), 'tbl_authors', sprintf(" `id` = %d", self::$Author->get('id')));
             }
             self::$Cookie->set('username', $username);
             self::$Cookie->set('pass', self::$Author->get('password'));
             self::Database()->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', sprintf(" `id` = %d", self::$Author->get('id')));
             // Only set custom author language in the backend
             if (class_exists('Administration', false)) {
                 Lang::set(self::$Author->get('language'));
             }
             return true;
         }
     }
     return false;
 }
Beispiel #7
0
 /**
  * 执行应用程序
  * @access public
  * @return void
  */
 public static function run(array $config = [])
 {
     if (version_compare(PHP_VERSION, '5.4.0', '<')) {
         throw new Exception('require PHP > 5.4.0 !');
     }
     // 日志初始化
     Log::init($config['log']);
     // 缓存初始化
     Cache::connect($config['cache']);
     // 加载框架底层语言包
     if (is_file(THINK_PATH . 'Lang/' . strtolower($config['default_lang']) . EXT)) {
         Lang::set(include THINK_PATH . 'Lang/' . strtolower($config['default_lang']) . EXT);
     }
     if (is_file(APP_PATH . 'build.php')) {
         // 自动化创建脚本
         Create::build(include APP_PATH . 'build.php');
     }
     // 监听app_init
     Hook::listen('app_init');
     // 初始化公共模块
     self::initModule(APP_PATH . $config['common_module'] . '/', $config);
     // 启动session
     if ($config['use_session']) {
         Session::init($config['session']);
     }
     // 应用URL调度
     self::dispatch($config);
     // 监听app_run
     Hook::listen('app_run');
     // 执行操作
     if (!preg_match('/^[A-Za-z](\\/|\\w)*$/', CONTROLLER_NAME)) {
         // 安全检测
         $instance = false;
     } elseif ($config['action_bind_class']) {
         // 操作绑定到类:模块\controller\控制器\操作
         if (is_dir(MODULE_PATH . CONTROLLER_LAYER . '/' . CONTROLLER_NAME)) {
             $namespace = MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . CONTROLLER_NAME . '\\';
         } else {
             // 空控制器
             $namespace = MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . $config['empty_controller'] . '\\';
         }
         $actionName = strtolower(ACTION_NAME);
         if (class_exists($namespace . $actionName)) {
             $class = $namespace . $actionName;
         } elseif (class_exists($namespace . '_empty')) {
             // 空操作
             $class = $namespace . '_empty';
         } else {
             throw new Exception('_ERROR_ACTION_:' . ACTION_NAME);
         }
         $instance = new $class();
         // 操作绑定到类后 固定执行run入口
         $action = 'run';
     } else {
         $instance = Loader::controller(CONTROLLER_NAME, '', $config['empty_controller']);
         // 获取当前操作名
         $action = ACTION_NAME . $config['action_suffix'];
     }
     if (!$instance) {
         throw new Exception('[ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(CONTROLLER_NAME, 1) . ' ] not exists');
     }
     try {
         // 操作方法开始监听
         $call = [$instance, $action];
         Hook::listen('action_begin', $call);
         if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
             // 非法操作
             throw new \ReflectionException();
         }
         //执行当前操作
         $method = new \ReflectionMethod($instance, $action);
         if ($method->isPublic()) {
             // URL参数绑定检测
             if ($config['url_params_bind'] && $method->getNumberOfParameters() > 0) {
                 switch ($_SERVER['REQUEST_METHOD']) {
                     case 'POST':
                         $vars = array_merge($_GET, $_POST);
                         break;
                     case 'PUT':
                         parse_str(file_get_contents('php://input'), $vars);
                         break;
                     default:
                         $vars = $_GET;
                 }
                 $params = $method->getParameters();
                 $paramsBindType = $config['url_parmas_bind_type'];
                 foreach ($params as $param) {
                     $name = $param->getName();
                     if (1 == $paramsBindType && !empty($vars)) {
                         $args[] = array_shift($vars);
                     }
                     if (0 == $paramsBindType && isset($vars[$name])) {
                         $args[] = $vars[$name];
                     } elseif ($param->isDefaultValueAvailable()) {
                         $args[] = $param->getDefaultValue();
                     } else {
                         throw new Exception('_PARAM_ERROR_:' . $name);
                     }
                 }
                 array_walk_recursive($args, 'Input::filterExp');
                 $data = $method->invokeArgs($instance, $args);
             } else {
                 $data = $method->invoke($instance);
             }
             // 操作方法执行完成监听
             Hook::listen('action_end', $data);
             // 返回数据
             Response::returnData($data, $config['default_return_type']);
         } else {
             // 操作方法不是Public 抛出异常
             throw new \ReflectionException();
         }
     } catch (\ReflectionException $e) {
         // 操作不存在
         if (method_exists($instance, '_empty')) {
             $method = new \ReflectionMethod($instance, '_empty');
             $method->invokeArgs($instance, [$action, '']);
         } else {
             throw new Exception('[ ' . (new \ReflectionClass($instance))->getName() . ':' . $action . ' ] not exists ', 404);
         }
     }
     return;
 }
Beispiel #8
0
 /**
  * Initialises the language by looking at the `lang` key,
  * passed via GET or POST
  */
 public function initialiseLang()
 {
     $lang = !empty($_REQUEST['lang']) ? preg_replace('/[^a-zA-Z\\-]/', NULL, $_REQUEST['lang']) : 'en';
     Lang::initialize();
     Lang::set($lang, false);
 }
                require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
                logIntoCourse($id_c, false);
            }
            if (isset($_SESSION['cp_assessment_effect'])) {
                unset($_SESSION['cp_assessment_effect']);
            }
            break;
        case "resetselmodule":
            unset($_SESSION['sel_module_id']);
            break;
        case "unregistercourse":
            if (isset($_SESSION['idCourse'])) {
                TrackUser::closeSessionCourseTrack();
                unset($_SESSION['idCourse']);
                unset($_SESSION['idEdition']);
            }
            if (isset($_SESSION['cp_assessment_effect'])) {
                unset($_SESSION['cp_assessment_effect']);
            }
            break;
        case "changelang":
            Lang::set(Get::req('new_lang', DOTY_MIXED));
            $_SESSION['changed_lang'] = true;
            break;
    }
}
// istance the course description class
if (isset($_SESSION['idCourse']) && !isset($GLOBALS['course_descriptor'])) {
    require_once _lms_ . '/lib/lib.course.php';
    $GLOBALS['course_descriptor'] = new DoceboCourse($_SESSION['idCourse']);
}
 /**
  * This function determines whether an there is a currently logged in
  * Author for Symphony by using the `$Cookie`'s username
  * and password. If an Author is found, they will be logged in, otherwise
  * the `$Cookie` will be destroyed.
  *
  * @see core.Cookie#expire()
  */
 public function isLoggedIn()
 {
     // Ensures that we're in the real world.. Also reduces three queries from database
     // We must return true otherwise exceptions are not shown
     if (is_null(self::$_instance)) {
         return true;
     }
     if ($this->Author) {
         return true;
     } else {
         $username = self::$Database->cleanValue($this->Cookie->get('username'));
         $password = self::$Database->cleanValue($this->Cookie->get('pass'));
         if (strlen(trim($username)) > 0 && strlen(trim($password)) > 0) {
             $id = self::$Database->fetchVar('id', 0, "SELECT `id` FROM `tbl_authors` WHERE `username` = '{$username}' AND `password` = '{$password}' LIMIT 1");
             if ($id) {
                 self::$Database->update(array('last_seen' => DateTimeObj::get('Y-m-d H:i:s')), 'tbl_authors', " `id` = '{$id}'");
                 $this->Author = AuthorManager::fetchByID($id);
                 Lang::set($this->Author->get('language'));
                 return true;
             }
         }
         $this->Cookie->expire();
         return false;
     }
 }
Beispiel #11
0
 /**
  * static public function for load user from login e password
  * @param string $login login of the user
  * @param string $password password of the user in clear text
  * @param string $prefix optional prefix for session publiciables
  * @return mixed DoceboUser instance of logged in user if success in login
  *				 FALSE otherwise
  **/
 public static function &createDoceboUserFromLogin($login, $password, $prefix = 'base', $new_lang = false)
 {
     if ($login == '') {
         $false_public = FALSE;
         return $false_public;
     }
     $user_manager = new DoceboACLManager();
     $user_info = $user_manager->getUser(false, $login);
     // first login
     $ret_value = false;
     if ($user_info === false) {
         return $ret_value;
     }
     if ($user_info[ACL_INFO_VALID] != '1') {
         return $ret_value;
     }
     if (Get::sett('ldap_used') == 'on') {
         if ($password == '') {
             $false_public = FALSE;
             return $false_public;
         }
         //connect to ldap server
         if (!($ldap_conn = @ldap_connect(Get::sett('ldap_server'), Get::sett('ldap_port', '389')))) {
             die("Could not connect to ldap server");
         }
         //bind on server
         $ldap_user = ereg_replace('\\$user', $login, Get::sett('ldap_user_string'));
         if (!@ldap_bind($ldap_conn, $ldap_user, $password)) {
             ldap_close($ldap_conn);
             // Edited by Claudio Redaelli
             if (Get::sett('ldap_alternate_check') == 'on') {
                 if ($user_info[ACL_INFO_PASS] != $user_manager->encrypt($password)) {
                     return $ret_value;
                 }
             } else {
                 $false_public = FALSE;
                 return $false_public;
             }
             // End edit
         }
         ldap_close($ldap_conn);
     } elseif ($user_info[ACL_INFO_PASS] != $user_manager->encrypt($password)) {
         return $ret_value;
     }
     unset($_SESSION[$prefix . "_idst"]);
     $du = new DoceboUser($login, $prefix);
     $_SESSION['last_enter'] = $user_info[ACL_INFO_LASTENTER];
     $du->setLastEnter(date("Y-m-d H:i:s"));
     $_SESSION['user_enter_mark'] = time();
     // language policy
     if (!$new_lang && isset($_SESSION['forced_lang'])) {
         $new_lang = Lang::get();
     }
     if ($new_lang != false) {
         $du->preference->setLanguage($new_lang);
     } else {
         if (!Get::cfg('demo_mode', false)) {
             Lang::set($du->preference->getLanguage());
         }
     }
     if (function_exists('session_regenerate_id')) {
         session_regenerate_id();
     }
     return $du;
 }
Beispiel #12
0
 /**
  * Initialises the language by looking at the existing
  * configuration
  */
 public function initialiseLang()
 {
     Lang::set(Symphony::Configuration()->get('lang', 'symphony'), false);
 }
Beispiel #13
0
    exit;
}
/* Max uploaded file size */
$max_file_size = get_max_fileupload_size();
if (!extension_loaded('sqlite3')) {
    echo "SqLite3 module not loaded";
    throw new Error("SqLite3 module not loaded");
}
$db = new SQLITE_DB($sqlite_path);
$db->connect();
if ((bool) $short) {
    return;
}
require_once $root . 'lib/lang.php';
$lng = new Lang();
$lng->set($_COOKIE['LANG']);
require_once $root . 'lib/user.php';
require_once $root . 'lib/cash.php';
require_once $root . 'lib/update.php';
if ($debug) {
    $db->debug = true;
}
$usr = new User($db, $lng);
$usr->auth();
$upd = new Update($db, $lng, $usr);
$ch = new Cash($db, $usr, $lng);
$settings['version'] = $version;
$settings['demo'] = $demo;
$settings['debug'] = $debug;
$settings['static'] = $static;
$settings['extjs'] = $extjs;
Beispiel #14
0
 /**
  * - load language from source
  * - set the system language looking at ( user preference, browser detect, user force )
  * @return array
  */
 private static function language()
 {
     self::log("Loading session language functions");
     require_once Docebo::inc(_i18n_ . '/lib.lang.php');
     $sop = Get::req('sop', DOTY_ALPHANUM, false);
     if (!$sop) {
         $sop = Get::req('special', DOTY_ALPHANUM, false);
     }
     switch ($sop) {
         case "changelang":
             $new_lang = Get::req('new_lang', DOTY_ALPHANUM, false);
             self::log("Sop 'changelang' intercepted, changing lang to : {$new_lang}");
             Lang::set($new_lang, isset($_GET['logout']));
             break;
     }
     //$glang =& DoceboLanguage::createInstance( 'standard', 'framework');
     //$glang->setGlobal();
 }
Beispiel #15
0
/**
 * Set the current language
 * @param string $lang_code the language that need to be setted
 * @return string the language setted
 * @deprecated
 */
function setLanguage($lang_code)
{
    return Lang::set($lang_code);
}