diff --git a/.htaccess b/.htaccess index e3fdd2ac9..37afe2e0c 100644 --- a/.htaccess +++ b/.htaccess @@ -1,3 +1,5 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !index.php RewriteRule ^ index.php [L] + +SetEnv YIOOP_REDIRECTS_ON true diff --git a/index.php b/index.php index 646d2da1e..f691ebe45 100644 --- a/index.php +++ b/index.php @@ -55,9 +55,6 @@ function passthruYioopRequest() $web_site->header("Location: $new_uri"); L\webExit(); } - if (!defined("seekquarry\\yioop\\configs\\REDIRECTS_ON")) { - define("seekquarry\\yioop\\configs\\REDIRECTS_ON", true); - } require_once __DIR__ . "/src/index.php"; bootstrap($web_site); return true; diff --git a/src/blog.php b/src/blog.php index 37f0a8115..e85128539 100755 --- a/src/blog.php +++ b/src/blog.php @@ -37,8 +37,9 @@ $_REQUEST['c'] = "group"; $_REQUEST['a'] = "groupFeeds"; $_REQUEST['just_group_id'] = 2; require_once __DIR__ . "/library/WebSite.php"; -require_once __DIR__ . "/index.php"; $web_site = empty($GLOBALS['web_site']) ? - new L\WebSite() : $GLOBALS['web_site']; + new \seekquarry\yioop\library\WebSite() : $GLOBALS['web_site']; +require_once __DIR__ . "/library/Utility.php"; +require_once __DIR__ . "/index.php"; bootstrap($web_site, false); \seekquarry\yioop\library\webExit(); diff --git a/src/bot.php b/src/bot.php index 852148701..1c2403f16 100644 --- a/src/bot.php +++ b/src/bot.php @@ -36,7 +36,9 @@ namespace seekquarry\yioop; $_REQUEST['c'] = "static"; $_REQUEST['p'] = "bot"; require_once __DIR__ . "/library/WebSite.php"; -require_once __DIR__ . "/index.php"; $web_site = empty($GLOBALS['web_site']) ? - new L\WebSite() : $GLOBALS['web_site']; + new \seekquarry\yioop\library\WebSite() : $GLOBALS['web_site']; +require_once __DIR__ . "/library/Utility.php"; +require_once __DIR__ . "/index.php"; bootstrap($web_site, false); +\seekquarry\yioop\library\webExit(); diff --git a/src/configs/Config.php b/src/configs/Config.php index c2e48d2dd..5374e5f7d 100755 --- a/src/configs/Config.php +++ b/src/configs/Config.php @@ -85,11 +85,8 @@ if (file_exists(__DIR__ . "/../../vendor/autoload.php")) { * @param string $errstr the error message * @param string $errfile the filename the error occurred in * @param int $errline the line number of the error - * @param array $errcontext the context (variables and their values) - * at the point the error occurred */ -function yioop_error_handler($errno, $errstr, $errfile, $errline, - $errcontext) +function yioop_error_handler($errno, $errstr, $errfile, $errline) { $num_lines_of_backtrace = 5; $error_types = [ @@ -232,7 +229,7 @@ function initializeBaseUrlAndCurrentWorkingDirectory() $_SERVER['SERVER_NAME'] = $context['SERVER_NAME']; } } - $server_name = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : + $server_name = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : "localhost"; if (strpos($server_name, ":") !== false && $server_name[0] != '[') { $server_name = "[$server_name]"; //guessing ipv6 address @@ -242,6 +239,10 @@ function initializeBaseUrlAndCurrentWorkingDirectory() $dir_name = ""; } $extra_slash = ($dir_name == '/') ? "" : '/'; + if ((!defined("seekquarry\\yioop\\configs\\REDIRECTS_ON") || !REDIRECTS_ON) + && strpos($dir_name, "src") === false) { + $extra_slash .= "src/"; + } //used in register controller to create links back to server nsdefine("BASE_URL", $http . $server_name . $port . $dir_name . $extra_slash); @@ -269,6 +270,14 @@ if (file_exists(BASE_DIR . "/configs/LocalConfig.php")) { way to set work directory) */ require_once(BASE_DIR . "/configs/LocalConfig.php"); } +if (!defined("seekquarry\\yioop\\configs\\REDIRECTS_ON")) { + if (!empty($_SERVER['YIOOP_REDIRECTS_ON']) || + (nsdefined("IS_OWN_WEB_SERVER") && IS_OWN_WEB_SERVER)) { + define("seekquarry\\yioop\\configs\\REDIRECTS_ON", true); + } else { + define("seekquarry\\yioop\\configs\\REDIRECTS_ON", false); + } +} initializeBaseUrlAndCurrentWorkingDirectory(); /** Yioop Namespace*/ nsdefine('NS', "seekquarry\\yioop\\"); @@ -594,19 +603,24 @@ if (!PROFILE) { /** this is the User-Agent names the crawler provides * a web-server it is crawling */ -if (defined("seekquarry\\yioop\\REDIRECTS_ON")) { +if (defined("seekquarry\\yioop\\config\REDIRECTS_ON") && + REDIRECTS_ON) { nsconddefine('USER_AGENT', 'Mozilla/5.0 (compatible; '.USER_AGENT_SHORT.'; +'.NAME_SERVER.'bot)'); + $name_server_url = NAME_SERVER; } else { + $name_server_url = (NAME_SERVER . "src/" == BASE_URL || + NAME_SERVER . "/src/" == BASE_URL || + substr(NAME_SERVER, -4) == "src/" ) ? BASE_URL : NAME_SERVER; nsconddefine('USER_AGENT', - 'Mozilla/5.0 (compatible; '. - USER_AGENT_SHORT.'; +'.NAME_SERVER . 'bot.php)'); + 'Mozilla/5.0 (compatible; ' . + USER_AGENT_SHORT.'; +' . NAME_SERVER . 'bot.php)'); } /** * To change the Open Search Tool bar name overrride the following variable * in your LocalConfig.php file */ -nsconddefine('SEARCHBAR_PATH', NAME_SERVER . "yioopbar.xml"); +nsconddefine('SEARCHBAR_PATH', $name_server_url . "yioopbar.xml"); /** * Phantom JS is used by some optional Javascript tests of the Yioop interface. * The constant PHANTOM_JS should point to the path to phantomjs diff --git a/src/controllers/ResourceController.php b/src/controllers/ResourceController.php index 94a38ada9..0d70e96f7 100644 --- a/src/controllers/ResourceController.php +++ b/src/controllers/ResourceController.php @@ -108,8 +108,17 @@ class ResourceController extends Controller implements CrawlConstants $base_dir = C\CRAWL_DIR . "/$folder"; } else if (in_array($_REQUEST['f'], ["locale"])) { $name = $this->clean($_REQUEST['n'], "file_name"); + $sub_path = ""; + if (!empty($_REQUEST['sf'])) { + $sub_path = $this->clean($_REQUEST['sf'], "string"); + $sub_path = str_replace(".", "", $sub_path) . "/"; + if ($sub_path == "/") { + $sub_path = ""; + } + } $folder = $_REQUEST['f']; $base_dir = C\APP_DIR . "/$folder"; + $name = $sub_path . $name; } else { $this->requestError(); return; @@ -241,9 +250,6 @@ class ResourceController extends Controller implements CrawlConstants { $error = B\directUrl("error", false, true); $error_location = "Location: $error"; - if (!C\REDIRECTS_ON) { - $error_location .= ".php"; - } $this->web_site->header($error_location); return; } diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php index bd29b3aef..d73939e6f 100644 --- a/src/controllers/components/SocialComponent.php +++ b/src/controllers/components/SocialComponent.php @@ -1903,14 +1903,15 @@ class SocialComponent extends Component implements CrawlConstants $paging_query .= "{$connector}v=ungrouped"; $data['RSS_FEED_URL'] = $paging_query . "&f=rss"; } + $paging_query = html_entity_decode($paging_query); $data['SCRIPT'] .= " let nextPage = initNextResultsPage($limit," . " {$data['TOTAL_ROWS']}, $results_per_page, ". - "'$paging_query$token_string', '', 'results-container', ". + "'$paging_query&$token_string', '', 'results-container', ". "'result-batch');\n"; if ($limit > 0) { $data['SCRIPT'] .= " let previousPage = initPreviousResultsPage(". "$limit, {$data['TOTAL_ROWS']}, $results_per_page, ". - "'$paging_query$token_string', 'results-container', ". + "'$paging_query&$token_string', 'results-container', ". "'result-batch');\n"; } if (!empty($data['REFRESH_TIMESTAMP']) && !empty($pages)) { diff --git a/src/controllers/components/SystemComponent.php b/src/controllers/components/SystemComponent.php index ca931d811..7f279b2b7 100755 --- a/src/controllers/components/SystemComponent.php +++ b/src/controllers/components/SystemComponent.php @@ -38,7 +38,7 @@ use seekquarry\yioop\library\UrlParser; /** * This component is used to handle activities related to the configuration - * of a Yioop installation, translations of text appearing in the installation, + * of a Yioop installation, translations of text ging in the installation, * as well as control of specifying what machines make up the installation * and which processes they run. * @@ -1013,10 +1013,11 @@ EOD; } break; case "reset": - $base_url = C\NAME_SERVER; - if (defined("BASE_URL")) { - $base_url = C\BASE_URL; - } + $base_url = (C\nsdefined("BASE_URL")) ? C\BASE_URL : + C\NAME_SERVER; + $name_server_url = (C\NAME_SERVER . "src/" == C\BASE_URL || + C\NAME_SERVER . "/src/" == C\BASE_URL) ? C\BASE_URL : + C\NAME_SERVER; $profile = [ 'LANDING_PAGE' => false, 'BACKGROUND_COLOR' => "#FFFFFF", @@ -1032,7 +1033,7 @@ EOD; 'SESSION_NAME' => "yioopbiscuit", 'CSRF_TOKEN' => "YIOOP_TOKEN", 'AUXILIARY_CSS' => "", - 'SEARCHBAR_PATH' => C\NAME_SERVER . "yioopbar.xml" + 'SEARCHBAR_PATH' => $name_server_url . "yioopbar.xml" ]; $old_profile = $profile_model->getProfile(C\WORK_DIRECTORY); foreach ($old_profile as $key => $value) { diff --git a/src/error.php b/src/error.php index a120a63d4..02692dce7 100755 --- a/src/error.php +++ b/src/error.php @@ -45,7 +45,7 @@ function webError() $_REQUEST['p'] = "404"; } $_REQUEST['c'] = "static"; - require_once __DIR__ . "/index.php"; + require_once __DIR__ . "/library/WebSite.php"; $web_site = empty($GLOBALS['web_site']) ? new L\WebSite() : $GLOBALS['web_site']; @@ -60,6 +60,8 @@ function webError() $web_site->header("HTTP/1.0 409 Conflict"); break; } + require_once __DIR__ . "/library/Utility.php"; + require_once __DIR__ . "/index.php"; bootstrap($web_site, false); \seekquarry\yioop\library\webExit(); } diff --git a/src/models/GroupModel.php b/src/models/GroupModel.php index 4dfc93793..8edeca520 100644 --- a/src/models/GroupModel.php +++ b/src/models/GroupModel.php @@ -404,7 +404,7 @@ class GroupModel extends Model implements MediaConstants if (!$row = $db->fetchArray($result)) { return false; } - return ($row['ENCRYPTION'] != 0); + return ($row['ENCRYPTION'] != 0 && $row['ENCRYPTION'] != 'Disabled'); } /** * Delete a group from the database and any associated data in @@ -627,7 +627,8 @@ class GroupModel extends Model implements MediaConstants if ($result) { $row = $private_db->fetchArray($result); } - return base64_decode($row['KEY_NAME']); + return empty($row['KEY_NAME']) ? false : + base64_decode($row['KEY_NAME']); } /** * To update the OWNER_ID of a group diff --git a/src/models/Model.php b/src/models/Model.php index af612f3a7..3ee532db1 100755 --- a/src/models/Model.php +++ b/src/models/Model.php @@ -546,7 +546,7 @@ class Model implements CrawlConstants } } else { list(, $comparison, $value, $sort_dir,) = $row; - if ($value != "" && (!in_array($row[0], $any_fields) + if (!empty($value) && (!in_array($row[0], $any_fields) || $value != "-1")) { if ($where == "") { $where = " WHERE "; diff --git a/src/models/RoleModel.php b/src/models/RoleModel.php index de43b3c50..f756f6260 100644 --- a/src/models/RoleModel.php +++ b/src/models/RoleModel.php @@ -116,7 +116,7 @@ class RoleModel extends Model * @param int $num number of roles to return * @return array of role_ids and their names */ - public function getUserRoles($user_id, $filter, $sorts = [], $limit, + public function getUserRoles($user_id, $filter, $sorts = [], $limit = 0, $num = C\NUM_RESULTS_PER_PAGE) { $db = $this->db; diff --git a/src/privacy.php b/src/privacy.php index 5dfa37a1e..80b8293b2 100755 --- a/src/privacy.php +++ b/src/privacy.php @@ -37,8 +37,9 @@ namespace seekquarry\yioop; $_REQUEST['c'] = "static"; $_REQUEST['p'] = "privacy"; require_once __DIR__ . "/library/WebSite.php"; -require_once __DIR__ . "/index.php"; $web_site = empty($GLOBALS['web_site']) ? - new L\WebSite() : $GLOBALS['web_site']; + new \seekquarry\yioop\library\WebSite() : $GLOBALS['web_site']; +require_once __DIR__ . "/library/Utility.php"; +require_once __DIR__ . "/index.php"; bootstrap($web_site, false); \seekquarry\yioop\library\webExit(); diff --git a/src/terms.php b/src/terms.php index 57ebaead9..b881134bc 100755 --- a/src/terms.php +++ b/src/terms.php @@ -36,8 +36,9 @@ namespace seekquarry\yioop; $_REQUEST['c'] = "static"; $_REQUEST['p'] = "terms"; require_once __DIR__ . "/library/WebSite.php"; -require_once __DIR__ . "/index.php"; $web_site = empty($GLOBALS['web_site']) ? - new L\WebSite() : $GLOBALS['web_site']; + new \seekquarry\yioop\library\WebSite() : $GLOBALS['web_site']; +require_once __DIR__ . "/library/Utility.php"; +require_once __DIR__ . "/index.php"; bootstrap($web_site, false); \seekquarry\yioop\library\webExit(); diff --git a/src/views/layouts/WebLayout.php b/src/views/layouts/WebLayout.php index f0269350c..63b1fff76 100755 --- a/src/views/layouts/WebLayout.php +++ b/src/views/layouts/WebLayout.php @@ -345,12 +345,13 @@ class WebLayout extends Layout </div><?php } $script_path = C\APP_DIR . "/scripts/basic.js"; - $pre_path = $path_url; + $basic_js = $path_url . "scripts/basic.js"; if (file_exists($script_path)) { - $pre_path = $path_url . "wd/"; + $basic_js = "$path_url?c=resource&a=get" . + "&f=scripts&n=basic.js"; } ?> - <script src="<?=$pre_path ?>scripts/basic.js" ></script><?php + <script src="<?=$basic_js ?>" ></script><?php if ($this->view->helper('helpbutton')->is_help_initialized) { if (!isset($data["INCLUDE_SCRIPTS"])) { $data["INCLUDE_SCRIPTS"] = []; @@ -412,10 +413,12 @@ class WebLayout extends Layout "/locale/$locale_tag/resources/locale.js"; $default_locale_path = C\BASE_DIR . "/locale/$locale_tag/resources/locale.js"; - $wd = (file_exists($locale_path)) ? "wd/" : ""; - if (file_exists($locale_path) || - file_exists($default_locale_path)) { - ?><script src='<?=$path_url . $wd . "locale/$locale_tag" . + if (file_exists($locale_path)) { ?> + <script src='<?=$path_url . "?c=resource&a=get" . + "&f=locale&sf=$locale_tag/resources". + "&n=$script_name.js" ?>' ></script><?php + } else if (file_exists($default_locale_path)) { ?> + <script src='<?=$path_url . "locale/$locale_tag" . "/resources/locale.js" ?>' ></script><?php } } ?>