function ParentLinksView($arr_hierarchy, $url_fancy, $idfield, $arr_parameters = array(), $last_link = 0, $name_home = 'Principal') { $arr_hierarchy[0]['name'] = $name_home; $arr_final = array(); $c = count($arr_hierarchy) - 1; for ($x = 0; $x < $c; $x++) { $arr_id =& $arr_hierarchy[$x]; $arr_tmp_param = $arr_parameters; $arr_tmp_param[$idfield] = $arr_id['id']; //$arr_tmp_param[]=slugify($arr_id['name']); $arr_final[$x] = '<a href="' . Routes::add_get_parameters($url_fancy, $arr_tmp_param) . '">' . $arr_id['name'] . '</a>'; } switch ($last_link) { default: $arr_final[$x] = $arr_hierarchy[$x]['name']; break; case 1: $arr_tmp_param = $arr_parameters; $arr_tmp_param[$idfield] = $arr_hierarchy[$x]['id']; $arr_tmp_param[] = Utils::slugify($arr_hierarchy[$x]['name']); $arr_final[$x] = '<a href="' . Routes::add_get_parameters($url_fancy, $arr_tmp_param) . '">' . $arr_hierarchy[$x]['name'] . '</a>'; break; } echo '<p>' . implode(' > ', $arr_final); }
function RecoveryPassFormView($model_login, $login) { ?> <h3><?php echo I18n::lang('users', 'remember_password_explain', 'Please enter the email address you registered on the website, which is where you receive your new password'); ?> </h3> <form method="post" action="<?php echo $login->url_recovery_send; ?> "> <?php Utils::set_csrf_key(); ?> <label for="email"></label> <?php echo PhangoApp\PhaModels\CoreForms::TextForm('email', ''); ?> <p><input type="submit" value="<?php echo I18n::lang('users', 'remember_password', 'Remember password'); ?> " /></p> </form> <?php }
function LoginFormView($model_user, $model_login) { //'no_expire_session' $arr_fields_login = array($model_login->field_user, $model_login->field_password); /* $model_user->forms['no_expire_session']=new ModelForm('form_login', 'no_expire_session', 'PhangoApp\PhaModels\CoreForms::CheckBoxForm', I18n::lang('users', 'automatic_login', 'Automatic login'), new BooleanField(), $required=1, $parameters=''); $model_user->forms['no_expire_session']->label_class='expire_button';*/ ?> <?php echo View::show_flash(); ?> <form method="post" action="<?php echo $model_login->url_login; ?> "> <?php Utils::set_csrf_key(); echo View::load_view(array($model_user->forms, $arr_fields_login), 'forms/modelform'); ?> <p><?php echo I18n::lang('users', 'remember_login', 'Remember login?'); ?> <input type="checkbox" name="no_expire_session" value="1" /></p> <p><a href="<?php echo $model_login->url_recovery; ?> "><?php echo I18n::lang('users', 'remember_password', 'Remember password'); ?> </a></p> <p><input type="submit" class="submit" value="<?php echo I18n::lang('common', 'login', 'Login'); ?> " /></p> </form> <?php }
/** * Create an account from a form created with LoginClass::create_account_form */ public function create_account() { $this->prepare_insert_user(); $this->was_prepared = 1; $post = Utils::filter_fields_array($this->arr_user_insert, $_POST); $no_user = 0; $check_user = $this->model_login->components[$this->field_user]->check($post[$this->field_user]); //$no_user=$this->model_login->select_count('where `'.$this->model_login->name.'`.`'.$this->field_user.'`="'.$check_user.'"'); // && $no_user==0 /*if(ModelForm::check_form($this->model_login->forms, $post)) {*/ /*if($_POST['repeat_password']==$post[$this->field_password] && $check_captcha==1 && $no_user==0) {*/ if ($no_user === 0) { $this->model_login->reset_require(); foreach ($this->arr_user_insert as $field_require) { if (isset($this->model_login->components[$field_require])) { $this->model_login->components[$field_require]->required = 1; } } $this->model_login->fields_to_update = $this->arr_user_insert; $this->model_login->components['password']->protected = false; if ($this->model_login->insert($post)) { return true; } else { ModelForm::set_values_form($this->model_login->forms, $_POST, 1); return false; } } else { $this->model_login->forms[$this->field_user]->std_error = I18n::lang('users', 'user_or_email_exists', 'User or email exists'); ModelForm::set_values_form($this->model_login->forms, $_POST, 1); return false; } /*} else { if($no_user>0) { $this->model_login->forms[$this->field_user]->std_error= I18n::lang('users', 'user_or_email_exists', 'User or email exists'); } ModelForm::set_values_form($this->model_login->forms, $_POST, 1); return false; }*/ }
//date_default_timezone_set (MY_TIMEZONE); $utility_console = 1; //load_lang('common', 'user'); $model = array(); //Check arguments define('OPTS', 'm:c:'); $longopts = array(); $options = getopt(OPTS, $longopts); $climate = new League\CLImate\CLImate(); if (!isset($options['m']) && !isset($options['c'])) { //die("Use: php console.php -m=module -c=console_controller [more arguments for daemon]\n"); $climate->white()->backgroundBlack()->out("Use: php console.php -m=group/module -c=console_controller [more arguments for daemon]"); die; } $module = @Utils::form_text($options['m']); $console_controller = @Utils::form_text(basename($options['c'])); //Include console_controller $controller = __DIR__ . '/vendor/' . $module . '/console/controller_' . $console_controller . '.php'; \PhangoApp\PhaView\View::$folder_env[] = 'vendor/' . $module . '/views'; if (file_exists($controller)) { include $controller; $script_base_controller = $module; $function_console = $console_controller . 'Console'; if (function_exists($function_console)) { /* * $longopts = array( "required:", // Valor obligatorio "optional::", // Valor opcional "option", // Sin valores "opt", // Sin valores );*/
<?php use PhangoApp\PhaRouter\Routes; use PhangoApp\PhaView\View; use PhangoApp\PhaUtils\Utils; include __DIR__ . '/vendor/autoload.php'; //Define the views folders based on app installed and global config of the app. Utils::load_config('config'); Utils::load_config('config_views'); //Set the theme folder media folder_env View::$media_env = array(View::$folder_env[0]); //Here don't worry about check ten directories for find view. foreach (Routes::$apps as $app) { View::$folder_env[] = 'vendor/' . $app . '/views'; View::$media_env[] = View::$folder_env[0] . '/' . $app; View::$media_env[] = 'vendor/' . $app; } View::load_media_file($_SERVER['REQUEST_URI']);
<?php use PhangoApp\PhaRouter\Routes; use PhangoApp\PhaUtils\Utils; use PhangoApp\PhaView\View; use PhangoApp\PhaI18n\I18n; include __DIR__ . "/vendor/autoload.php"; if (!defined('COOKIE_SESSION_NAME')) { define('COOKIE_SESSION_NAME', 'phango'); } $route = new Routes(); $route->arr_finish_callbacks = array('PhangoApp\\PhaModels\\Webmodel::save_cache_query' => []); Utils::load_config('config_i18n'); Utils::load_config('config'); Utils::load_config('config_views'); session_name(COOKIE_SESSION_NAME . '_session'); session_set_cookie_params(0, Routes::$root_url); session_start(); I18n::load_lang('common'); /**Load configurations from modules**/ foreach (Routes::$apps as $admin_module) { Utils::load_config('config', $path = 'vendor/' . $admin_module . "/settings"); } date_default_timezone_set(PhangoApp\PhaTime\DateTime::$timezone); $route->response($_SERVER['REQUEST_URI']);
*<?php use PhangoApp\PhaModels\Webmodel; use PhangoApp\PhaUtils\Utils; use PhangoApp\PhaModels\CoreFields\CharField; use PhangoApp\PhaModels\CoreFields\PasswordField; use PhangoApp\PhaModels\CoreFields\EmailField; use PhangoApp\PhaModels\Forms\PasswordForm; use PhangoApp\PhaLibs\LoginClass; use PhangoApp\PhaModels\ExtraModels\UserPhangoModel; include "../vendor/autoload.php"; Utils::load_config('config', '../settings'); $user_test = new UserPhangoModel('user_test'); $user_test->register('name', new CharField(255)); $user_test->register('username', new CharField(255)); $user_test->register('password', new PasswordField(255)); $user_test->register('email', new EmailField(255)); $user_test->register('token', new CharField(255)); $user_test->create_forms(); $user_test->forms['repeat_password'] = new PasswordForm('repeat_password'); $login_class = new LoginClass($user_test, 'username', 'password', 'token', $arr_user_session = array(), $arr_user_insert = array()); $login_class->field_mail = 'email'; class LoginTest extends PHPUnit_Framework_TestCase { public function testCreateTableUser() { global $user_test; $this->assertTrue($user_test->create_table()); } /** * @depends testCreateTableUser */
public function home($module_id = 'none', $submodule_id = '') { if ($submodule_id != '') { $module_id = basename(Utils::slugify($module_id)) . '/' . basename(Utils::slugify($submodule_id)); } class_alias('indexController', 'AdminSwitchClass'); AdminSwitchClass::$login = new LoginClass(Webmodel::$model['user_admin'], 'user_admin', 'password', '', $arr_user_session = array('IdUser_admin', 'privileges_user', 'username', 'token_client', 'lang'), $arr_user_insert = array('user_admin', 'password', 'repeat_password', 'email')); AdminSwitchClass::$login->field_key = 'token_client'; ob_start(); //global $model, $lang, PhangoVar::$base_url, PhangoVar::$base_path, $user_data, $arr_module_admin, $config_data, $arr_block, $original_theme, $module_admin, $header; $header = ''; $content = ''; //load_libraries(array('utilities/set_admin_link')); //settype($module_id, 'string'); $module_id = Utils::slugify($module_id, 1); $extra_urls = array(); //Make menu... //Admin was internationalized if (AdminSwitchClass::$login->check_login()) { LoginClass::$session['user_admin']['token_client'] = sha1(LoginClass::$session['user_admin']['token_client']); if (!isset($_SESSION['language'])) { $_SESSION['language'] = LoginClass::$session['user_admin']['lang']; } I18n::load_lang('phangoapp/admin'); Utils::load_config('config_admin', 'settings/admin'); //variables for define titles for admin page $arr_son_module = array(); $title_admin = I18n::lang('phangoapp/admin', 'admin', 'Admin'); $title_module = I18n::lang('phangoapp/admin', 'home', 'Home'); $content = ''; $name_modules = array(); $no_show_menu = []; $urls = array(); $arr_permissions_admin = array(); $arr_permissions_admin['none'] = 1; $module_admin = array(); $arr_admin_script['none'] = AdminUtils::$admin_controller; //Define $module_admin[$module_id] for check if exists in database the module $module_admin[$module_id] = 'AdminIndex'; //I18n::$lang[$module_admin[$module_id].'_admin']['AdminIndex_admin_name']=ucfirst(I18n::lang('phangoapp/admin', 'admin', 'Admin')); //0=> name in uri, 1 => route to script, 2 name of script $title_admin = AdminUtils::$name_admin; foreach (ModuleAdmin::$arr_modules_admin as $ser_admin_script) { //load little file lang with the name for admin. With this you don't need bloated with biggest files of langs... $idmodule = $ser_admin_script[0]; $name_module = $idmodule; if (gettype($ser_admin_script[1]) == 'string') { $name_modules[$name_module] = $ser_admin_script[2]; $arr_admin_script[$idmodule] = $ser_admin_script; $urls[$name_module] = AdminUtils::set_admin_link($idmodule, array()); $module_admin[$idmodule] = $name_module; $arr_permissions_admin[$idmodule] = 1; if (isset($ser_admin_script[3])) { $no_show_menu[$name_module] = 1; } } else { $name_modules[$name_module] = $ser_admin_script[2]; //unset(ModuleAdmin::$arr_modules_admin[$idmodule]['title']); foreach ($ser_admin_script[1] as $ser_admin_script_son) { $idmodule_son = $ser_admin_script_son[0]; $name_module_son = $idmodule_son; $name_modules[$name_module_son] = $ser_admin_script_son[2]; $arr_admin_script[$idmodule_son] = $ser_admin_script_son; $urls[$name_module_son] = AdminUtils::set_admin_link($idmodule_son, array()); $module_admin[$idmodule_son] = $name_module_son; $arr_permissions_admin[$idmodule_son] = 1; if (isset($ser_admin_script_son[3])) { $no_show_menu[$name_module_son] = 1; } } } } if (!isset($arr_admin_script[$module_id])) { //Need show error. $this->route->response404(); die; } //$file_include=Routes::$base_path.'/vendor/'.$arr_admin_script[ $module_id ][1].'/controllers/admin/admin_'.basename($arr_admin_script[ $module_id ][0]).'.php'; $file_include = Routes::$base_path . '/' . $arr_admin_script[$module_id][1] . '.php'; if (LoginClass::$session['user_admin']['privileges_user'] == 1) { $arr_permissions_admin = array(); $arr_module_saved = array(); $arr_module_strip = array(); $arr_permissions_admin[$module_id] = 0; $arr_permissions_admin['none'] = 1; Webmodel::$model['moderators_module']->set_conditions(['where moderator=?', [$_SESSION['IdUser_admin']]]); $query = Webmodel::$model['moderators_module']->select(array('idmodule'), 1); while (list($idmodule_mod) = Webmodel::$model['moderators_module']->fetch_row($query)) { //settype($idmodule_mod, 'integer'); $arr_permissions_admin[$idmodule_mod] = 1; $arr_module_saved[] = $module_admin[$idmodule_mod]; } $arr_module_strip = array_diff(array_keys($name_modules), $arr_module_saved); foreach ($arr_module_strip as $name_module_strip) { unset($name_modules[$name_module_strip]); unset($urls[$name_module_strip]); } } if (file_exists($file_include) && $module_admin[$module_id] != '' && $arr_permissions_admin[$module_id] == 1) { include $file_include; $func_admin = basename($module_admin[$module_id]) . 'Admin'; if ($module_id != 'none') { $title_admin = $name_modules[$module_id]; } if (function_exists($func_admin)) { $extra_data = $func_admin(); settype($extra_data, 'array'); $extra_data = array_merge($extra_data, $arr_son_module); } else { throw new Exception('Error: no exists function ' . ucfirst($func_admin) . ' for admin application'); } } else { if ($module_admin[$module_id] != '' && $arr_permissions_admin[$module_id] == 1) { $output = ob_get_contents(); ob_clean(); throw new Exception('Error: no exists file ' . $file_include . ' for admin application'); die; } else { $this->route->response404(); die; } } $content = ob_get_contents(); ob_end_clean(); if (AdminUtils::$show_admin_view == true) { $content = '<h1>' . $title_admin . "</h1>\n" . $content; echo View::load_view(array('header' => $header, 'title' => I18n::lang('phangoapp/admin', 'admin_zone', 'Admin zone'), 'content' => $content, 'name_modules' => $name_modules, 'urls' => $urls, 'extra_data' => $extra_data, 'no_show_menu' => $no_show_menu), 'admin/admin'); } else { echo $content; } } else { $url = Routes::make_simple_url(ADMIN_FOLDER . '/login'); die(header('Location: ' . $url, true)); } }
function AdminView($header, $title, $content, $name_modules, $url_modules, $extra_data, $no_show_menu) { View::$js[] = 'jquery.min.js'; View::$css[] = 'font-awesome.min.css'; View::$js_module['admin'][] = 'responsive-nav.min.js'; View::$css_module['admin'][] = 'admin.css'; View::$css_module['admin'][] = 'responsive-nav.css'; ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"> <title><?php echo $title; ?> </title> <?php echo View::load_css(); ?> <?php echo View::load_js(); ?> <?php echo View::load_header(); ?> </head> <body> <div id="logout"> <a href="<?php echo AdminUtils::set_admin_link('login/logout'); ?> "><i class="fa fa-power-off" aria-hidden="true"></i> Logout</a> </div> <div id="center_body"> <div id="header"> <a href="#nav" id="toggle"><i class="fa fa-bars" aria-hidden="true"></i><span>Menu</span></a> <span id="title_phango">Phango</span> <span id="title_framework">Framework!</span> <div id="languages_general"> <?php $arr_selected = array(); foreach (I18n::$arr_i18n as $lang_item) { //set $arr_selected[Utils::slugify($lang_item)] = 'no_choose_flag_general'; $arr_selected[Utils::slugify(I18n::$language)] = 'choose_flag_general'; ?> <a class="<?php echo $arr_selected[Utils::slugify($lang_item)]; ?> " href="<?php echo Routes::make_module_url('lang', 'index', 'home', array('language' => $lang_item)); ?> "><img src="<?php echo View::get_media_url('images/languages/' . $lang_item . '.png'); ?> " alt="<?php echo $lang_item; ?> "/></a> <?php } ?> </div> </div> <div class="content_admin"> <nav id="menu" class="nav-collapse"> <ul> <li class="menu_title"><i class="fa fa-gear" aria-hidden="true"></i> <?php echo I18n::lang('phangoapp/admin', 'applications', 'Applications'); ?> </li> <?php foreach ($name_modules as $key_module => $name_module) { if (!isset($no_show_menu[$key_module])) { if (isset($url_modules[$key_module])) { ?> <li><a href="<?php echo $url_modules[$key_module]; ?> "><i class="fa fa-circle-o" aria-hidden="true"></i> <?php echo $name_module; ?> </a></li> <?php } else { echo '<li><div class="father_admin">' . $name_module . '</div></li>'; } } //If have $key_module with an extra_url element from extra_data, put here. if (isset($extra_data['extra_url'][$key_module])) { foreach ($extra_data['extra_url'][$key_module]['url_module'] as $key => $url_module) { ?> <li><a class="sub_module" href="<?php echo $url_module; ?> "> <i class="fa fa-circle-o" aria-hidden="true"></i> <?php echo ucfirst($extra_data['extra_url'][$key_module]['name_module'][$key]); ?> </a></li> <?php } } } ?> </ul> </nav> <div class="contents"> <?php echo View::show_flash(); ?> <?php echo $content; ?> </nav> </div> </div> <div id="loading_ajax"> </div> <script> var navigation = responsiveNav(".nav-collapse", {customToggle: "#toggle"}); </script> </body> </html> <?php }
public function search_by_url() { if (!isset($_GET['field_search'])) { $_GET['field_search'] = $this->order_field; } $this->order_field = $_GET['field_search']; if (isset($_GET['search']) && isset($_GET['field_search'])) { $_GET['field_search'] = Utils::slugify($_GET['field_search'], 1); if (isset($this->model->components[$_GET['field_search']])) { //$_GET['search']=trim($this->model->components[$_GET['field_search']]->check($_GET['search'])); //$_GET['search']=trim(Utils::form_text($_GET['search'])); if ($_GET['search'] != false) { $this->where_sql[0] .= 'AND `' . $_GET['field_search'] . '` LIKE ?'; $this->where_sql[1][] = '%' . $_GET['search'] . '%'; } } } else { $_GET['search'] = ''; } $this->change_order_by_url(); $this->url_options = Routes::add_get_parameters($this->url_options, array('field_search' => $_GET['field_search'], 'order' => $_GET['order'])); if ($_GET['search'] != '') { $this->url_options = Routes::add_get_parameters($this->url_options, array('search' => $_GET['search'])); } }
public function testWrapWords() { $this->assertEquals('This is ...', Utils::wrap_words('This is a phrase', 2)); }
public function testSlugify() { $this->assertEquals('esto-es-un-texto', Utils::slugify('Esto es un texto')); }