Source for file admin_controller.php
Documentation is available at admin_controller.php
* Open Source Pure PHP Search Engine, Crawler, and Indexer
* Copyright (C) 2009 - 2013 Chris Pollett chris@pollett.org
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* @author Chris Pollett chris@pollett.org
* @license http://www.gnu.org/licenses/ GPL3
* @link http://www.seekquarry.com/
if(!defined('BASE_DIR')) {echo "BAD REQUEST"; exit();}
/** Load base controller class if needed */
require_once BASE_DIR. "/controllers/controller.php";
/** Loads common constants for web crawling */
require_once BASE_DIR. "/lib/crawl_constants.php";
/** Need get host for search filter admin */
require_once BASE_DIR. "/lib/url_parser.php";
/** Used in rule parser test in page options */
require_once BASE_DIR. "/lib/page_rule_parser.php";
/** Loads crawl_daemon to manage news_updater */
require_once BASE_DIR. "/lib/crawl_daemon.php";
/** get processors for different file types */
foreach(glob(BASE_DIR. "/lib/processors/*_processor.php") as $filename) {
* Controller used to handle admin functionalities such as
* modify login and password, CREATE, UPDATE,DELETE operations
* for users, roles, locale, and crawls
* Says which views to load for this controller
* admin is the main one, signin has the login screen crawlstatus
* is used to see how many pages crawled by the current crawl
var $views = array("admin", "signin", "crawlstatus", "machinestatus");
* Says which models to load for this controller.
"signin", "user", "activity", "crawl", "role", "locale", "profile",
"searchfilters", "source", "machine", "cron");
* Says which activities (roughly methods invoke from the web) this
* controller will respond to
var $activities = array("signin", "manageAccount", "manageUsers",
"manageRoles", "manageCrawls", "pageOptions", "resultsEditor",
"manageMachines", "manageLocales", "crawlStatus", "mixCrawls",
"machineStatus", "searchSources", "configure");
* An array of activities which are periodically updated within other
* activities that they live. For example, within manage crawl,
* the current crawl status is updated every 20 or so seconds.
* This is the main entry point for handling requests to administer the
* ProcessRequest determines the type of request (signin , manageAccount,
* etc) is being made. It then calls the appropriate method to handle the
* given activity. Finally, it draws the relevant admin screen
if(isset ($_SESSION['USER_ID'])) {
$user = $_SESSION['USER_ID'];
$user = $_SERVER['REMOTE_ADDR'];
if(isset ($_SESSION['USER_ID']) && !isset ($_REQUEST['u'])) {
if(!isset ($data['REFRESH'])) {
$view = $data['REFRESH'];
$user_id = $this->signinModel->getUserId(
$this->clean($_REQUEST['u'], "string"));
$session = $this->userModel->getUserSession($user_id);
$_SESSION['USER_ID'] = $user_id;
// now don't want to use remote address anymore
$data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
tl('admin_controller_login_successful'). "</h1>')";
$data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
tl('admin_controller_login_failed'). "</h1>')";
unset ($_SESSION['USER_ID']);
$data['SCRIPT'] = "doMessage('<h1 class=\"red\" >".
tl('admin_controller_login_to_config'). "</h1>')";
} else if(isset ($_REQUEST['a']) &&
tl('admin_controller_status_updates_stopped'). "</p>");
if($token_okay && isset ($_SESSION["USER_ID"])) {
unset ($_SESSION['USER_ID']);
$data['SCRIPT'] = "var u; if ((u = elt('username')) && u.focus) ".
* If there is no profile/work directory set up then this method
* get called to by pass any login and go to the configure screen.
* The configure screen is only displayed if the user is connected
* from localhost in this case
* Checks whether the user name and password sent presumably by the signin
* form match a user in the database
* @return bool whether they do or not
$result = $this->signinModel->checkValidSignin(
$this->clean($_REQUEST['u'], "string"),
$this->clean($_REQUEST['p'], "string") );
* Determines the user's current allowed activities and current activity,
* then calls the method for the latter.
* This is called from {@link processRequest()} once a user is logged in.
* @return array $data the results of doing the activity for display in the
} else if(isset ($_REQUEST['a']) &&
$activity = $_REQUEST['a'];
$activity = "manageAccount";
$allowed_activities = array( array(
$this->activityModel->getActivityNameFromMethodName($activity),
'METHOD_NAME' => $activity));
$this->userModel->getUserActivities($_SESSION['USER_ID']);
foreach($allowed_activities as $allowed_activity) {
if($activity == $allowed_activity['METHOD_NAME']) {
if($allowed_activity['METHOD_NAME'] == "manageCrawls" &&
$activity == "crawlStatus") {
if($allowed_activity['METHOD_NAME'] == "manageMachines" &&
$activity == "machineStatus") {
//for now we allow anyone to get crawlStatus
$data = $this->$activity();
$data['ACTIVITIES'] = $allowed_activities;
$data['CURRENT_ACTIVITY'] =
$this->activityModel->getActivityNameFromMethodName($activity);
* This method is data to signin a user and initialize the data to be
* @return array empty array of data to show so far in view
$this->signinModel->getUserId($_REQUEST['username']);
* Used to handle crawlStatus REST activities requesting the status of the
* @return array $data contains crawl status of current crawl as well as
* info about prior crawls and which crawl is being used for default
$data['REFRESH'] = "crawlstatus";
$crawl_time = $this->crawlModel->getCurrentIndexDatabaseName();
if(isset ($crawl_time) ) {
$data['CURRENT_INDEX'] = (int) $crawl_time;
$data['CURRENT_INDEX'] = - 1;
$machine_urls = $this->machineModel->getQueueServerUrls();
list ($stalled, $status, $data['RECENT_CRAWLS']) =
$this->crawlModel->combinedCrawlInfo($machine_urls);
$this->crawlModel->sendStopCrawlMessage($machine_urls);
$data["CRAWL_RUNNING"] = false;
if(isset ($data['CRAWL_TIME']) && $data["CRAWL_TIME"] != 0) {
//erase from previous crawl list any active crawl
$num_crawls = count($data['RECENT_CRAWLS']);
for($i = 0; $i < $num_crawls; $i++ ) {
if($data['RECENT_CRAWLS'][$i]['CRAWL_TIME'] ==
$data['RECENT_CRAWLS'][$i] = false;
$data["CRAWL_RUNNING"] = true;
$data['RECENT_CRAWLS']= array_filter($data['RECENT_CRAWLS']);
if(isset ($data['RECENT_CRAWLS'][0])) {
usort($data['RECENT_CRAWLS'], "rorderCallback");
* Gets data from the machineModel concerning the on/off states
* of the machines managed by this Yioop instance and then passes
* this data the the machinestatus view.
* @return array $data MACHINES field has information about each
* machine managed by this Yioop instance as well the on off
* status of its queue_servers and fetchers.
* The REFRESH field is used to tell the controller that the
* view shouldn't have its own sidemenu.
$data['REFRESH'] = "machinestatus";
$data['MACHINES'] = $this->machineModel->getMachineStatuses();
$data['NEWS_MODES'] = array(
"news_off" => tl('admin_controller_news_off'),
"news_web" => tl('admin_controller_news_update_web'),
"news_process" => tl('admin_controller_news_process'),
$data['NEWS_MODE'] = isset ($profile['NEWS_MODE']) ?
$profile['NEWS_MODE']: "";
* Used to handle the change current user password admin activity
* @return array $data SCRIPT field contains success or failure message
$possible_arguments = array("changepassword");
$data["ELEMENT"] = "manageaccountElement";
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
if($_REQUEST['retypepassword'] != $_REQUEST['newpassword']){
tl('admin_controller_passwords_dont_match');
"doMessage('<h1 class=\"red\" >". $data["MESSAGE"].
$this->signinModel->getUserName($_SESSION['USER_ID']);
$result = $this->signinModel->checkValidSignin($username,
$this->clean($_REQUEST['oldpassword'], "string") );
tl('admin_controller_invalid_old_password');
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
$data["MESSAGE"]. "</h1>')";
$this->signinModel->changePassword($username,
$this->clean($_REQUEST['newpassword'], "string"));
$data["MESSAGE"] = tl('admin_controller_change_password');
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
$data["MESSAGE"]. "</h1>')";
* Used to handle the manage user activity.
* This activity allows new users to be added, old users to be
* deleted and allows roles to be added to/deleted from a user
* @return array $data infomation about users of the system, roles, etc.
* as well as status messages on performing a given sub activity
$possible_arguments = array("adduser",
"deleteuser", "adduserrole", "deleteuserrole");
$data["ELEMENT"] = "manageusersElement";
"selectUser = elt('select-user'); ".
"selectUser.onchange = submitViewUserRole;";
$usernames = $this->userModel->getUserList();
if(isset ($_REQUEST['username'])) {
$username = $this->clean($_REQUEST['username'], "string" );
$base_option = tl('admin_controller_select_username');
$data['USER_NAMES'] = array();
$data['USER_NAMES'][""] = $base_option;
foreach($usernames as $name) {
$data['USER_NAMES'][$name]= $name;
if(isset ($_REQUEST['selectuser'])) {
$select_user = $this->clean($_REQUEST['selectuser'], "string" );
if($select_user != "" ) {
$userid = $this->signinModel->getUserId($select_user);
$data['SELECT_USER'] = $select_user;
$data['SELECT_ROLES'] = $this->userModel->getUserRoles($userid);
$all_roles = $this->roleModel->getRoleList();
if(isset ($_REQUEST['selectrole'])) {
$select_role = $this->clean($_REQUEST['selectrole'], "string" );
foreach($all_roles as $role) {
$role_ids[] = $role['ROLE_ID'];
if($select_role == $role['ROLE_ID']) {
$select_rolename = $role['ROLE_NAME'];
$all_roles, $data['SELECT_ROLES']);
$data['AVAILABLE_ROLES'][- 1] =
tl('admin_controller_select_rolename');
foreach($available_roles as $role) {
$data['AVAILABLE_ROLES'][$role['ROLE_ID']]= $role['ROLE_NAME'];
$data['SELECT_ROLE'] = $select_role;
$data['SELECT_ROLE'] = - 1;
$data['SELECT_USER'] = - 1;
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
$data['SELECT_ROLE'] = - 1;
unset ($data['AVAILABLE_ROLES']);
unset ($data['SELECT_ROLES']);
if($_REQUEST['retypepassword'] != $_REQUEST['password']) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_passwords_dont_match').
if($this->signinModel->getUserId($username) > 0) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_username_exists'). "</h1>')";
$this->userModel->addUser($username,
$this->clean($_REQUEST['password'], "string"));
$data['USER_NAMES'][$username] = $username;
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_username_added'). "</h1>')";
$data['SELECT_ROLE'] = - 1;
unset ($data['AVAILABLE_ROLES']);
unset ($data['SELECT_ROLES']);
if(!($this->signinModel->getUserId($username) > 0)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_username_doesnt_exists').
$this->userModel->deleteUser($username);
unset ($data['USER_NAMES'][$username]);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_username_deleted'). "</h1>')";
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_username_doesnt_exists').
if(!in_array($select_role, $role_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_doesnt_exists').
$this->userModel->addUserRole($userid, $select_role);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_added').
unset ($data['AVAILABLE_ROLES'][$select_role]);
$data['SELECT_ROLE'] = - 1;
$this->userModel->getUserRoles($userid);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_username_doesnt_exists').
if(!in_array($select_role, $role_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_doesnt_exists').
$this->userModel->deleteUserRole($userid, $select_role);
$this->userModel->getUserRoles($userid);
$data['AVAILABLE_ROLES'][$select_role] = $select_rolename;
$data['SELECT_ROLE'] = - 1;
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_deleted'). "</h1>')";
* Used to handle the manage role activity.
* This activity allows new roles to be added, old roles to be
* deleted and allows activities to be added to/deleted from a role
* @return array $data infomation about roles in the system, activities,etc.
* as well as status messages on performing a given sub activity
array("addrole", "deleterole", "addactivity", "deleteactivity");
$data["ELEMENT"] = "managerolesElement";
"selectRole = elt('select-role'); selectRole.onchange =".
" submitViewRoleActivities;";
$roles = $this->roleModel->getRoleList();
$base_option = tl('admin_controller_select_rolename');
$data['ROLE_NAMES'] = array();
$data['ROLE_NAMES'][- 1] = $base_option;
if(isset ($_REQUEST['rolename'])) {
$rolename = $this->clean($_REQUEST['rolename'], "string" );
foreach($roles as $role) {
$data['ROLE_NAMES'][$role['ROLE_ID']]= $role['ROLE_NAME'];
$role_ids[] = $role['ROLE_ID'];
$data['SELECT_ROLE'] = - 1;
if(isset ($_REQUEST['selectrole'])) {
$select_role = $this->clean($_REQUEST['selectrole'], "string" );
if($select_role != "" ) {
$data['SELECT_ROLE'] = $select_role;
$data['ROLE_ACTIVITIES'] =
$this->roleModel->getRoleActivities($select_role);
$all_activities = $this->activityModel->getActivityList();
$activity_names = array();
foreach($all_activities as $activity) {
$activity_ids[] = $activity['ACTIVITY_ID'];
$activity_names[$activity['ACTIVITY_ID']] =
$activity['ACTIVITY_NAME'];
$data['AVAILABLE_ACTIVITIES'][- 1] =
tl('admin_controller_select_activityname');
foreach($available_activities as $activity) {
$data['AVAILABLE_ACTIVITIES'][$activity['ACTIVITY_ID']] =
$activity['ACTIVITY_NAME'];
if(isset ($_REQUEST['selectactivity'])) {
$this->clean($_REQUEST['selectactivity'], "int" );
if($select_activity != "") {
$data['SELECT_ACTIVITY'] = $select_activity;
$data['SELECT_ACTIVITY'] = - 1;
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
unset ($data['ROLE_ACTIVITIES']);
unset ($data['AVAILABLE_ACTIVITIES']);
$data['SELECT_ROLE'] = - 1;
if($this->roleModel->getRoleId($rolename) > 0) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_exists').
$this->roleModel->addRole($rolename);
$roleid = $this->roleModel->getRoleId($rolename);
$data['ROLE_NAMES'][$roleid] = $rolename;
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_added').
$data['SELECT_ROLE'] = - 1;
unset ($data['ROLE_ACTIVITIES']);
unset ($data['AVAILABLE_ACTIVITIES']);
if(!in_array($select_role, $role_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_doesnt_exists').
$this->roleModel->deleteRole($select_role);
unset ($data['ROLE_NAMES'][$select_role]);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_deleted'). "</h1>')";
if(!in_array($select_role, $role_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_doesnt_exists').
if(!in_array($select_activity, $activity_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_activityname_doesnt_exists').
$this->roleModel->addActivityRole(
$select_role, $select_activity);
unset ($data['AVAILABLE_ACTIVITIES'][$select_activity]);
$data['ROLE_ACTIVITIES'] =
$this->roleModel->getRoleActivities($select_role);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_activity_added'). "</h1>')";
if(!in_array($select_role, $role_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_rolename_doesnt_exists').
if(!in_array($select_activity, $activity_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_activityname_doesnt_exists').
$this->roleModel->deleteActivityRole(
$select_role, $select_activity);
$data['ROLE_ACTIVITIES'] =
$this->roleModel->getRoleActivities($select_role);
$data['AVAILABLE_ACTIVITIES'][$select_activity] =
$activity_names[$select_activity];
$data['SELECT_ACTIVITY'] = - 1;
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_activity_deleted'). "</h1>')";
* Used to handle the manage crawl activity.
* This activity allows new crawls to be started, statistics about old
* crawls to be seen. It allows a user to stop the current crawl or
* restart an old crawl. It also allows a user to configure the options
* by which a crawl is conducted
* @return array $data information and statistics about crawls in the system
* as well as status messages on performing a given sub activity
array("start", "resume", "delete", "stop", "index", "options");
$data["ELEMENT"] = "managecrawlsElement";
$data['SCRIPT'] = "doUpdate();";
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
$machine_urls = $this->machineModel->getQueueServerUrls();
$num_machines = count($machine_urls);
if($num_machines < 1 || ($num_machines == 1 &&
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_stop_crawl'). "</h1>')";
$info[self::STATUS] = "STOP_CRAWL";
"/schedules/name_server_messages.txt";
$this->crawlModel->sendStopCrawlMessage($machine_urls);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_resume_crawl'). "</h1>')";
$crawl_params[self::STATUS] = "RESUME_CRAWL";
$crawl_params[self::CRAWL_TIME] =
$this->clean($_REQUEST['timestamp'], "int");
$seed_info = $this->crawlModel->getCrawlSeedInfo(
$crawl_params[self::CRAWL_TIME], $machine_urls);
Write the new crawl parameters to the name server, so
that it can pass them along in the case of a new archive
"/schedules/name_server_messages.txt";
$this->crawlModel->sendStartCrawlMessage($crawl_params,
if(isset ($_REQUEST['timestamp'])) {
$this->clean($_REQUEST['timestamp'], "int");
$this->crawlModel->deleteCrawl($timestamp,
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_delete_crawl_success').
"</h1>'); crawlStatusUpdate(); ";
$data['SCRIPT'] .= "crawlStatusUpdate(); ".
"doMessage('<h1 class=\"red\" >".
tl('admin_controller_delete_crawl_fail').
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_set_index'). "</h1>')";
$timestamp = $this->clean($_REQUEST['timestamp'], "int");
$this->crawlModel->setCurrentIndexDatabaseName($timestamp);
* Called from @see manageCrawls to start a new crawl on the machines
* $machine_urls. Updates $data array with crawl start message
* @param array &$data an array of info to supply to AdminView
* @param array $machine_urls string urls of machines managed by this
* Yioop name server on which to perform the crawl
function startCrawl(&$data, $machine_urls, $seed_info = NULL)
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_starting_new_crawl'). "</h1>')";
$crawl_params[self::STATUS] = "NEW_CRAWL";
$crawl_params[self::CRAWL_TIME] = time();
$seed_info = $this->crawlModel->getSeedInfo();
if(isset ($_REQUEST['description'])) {
$description = $this->clean($_REQUEST['description'], "string");
$description = tl('admin_controller_no_description');
$crawl_params['DESCRIPTION'] = $description;
$crawl_params[self::VIDEO_SOURCES] = array();
$this->sourceModel->getMediaSources('video');
foreach($sources as $source) {
$url = $source['SOURCE_URL'];
$crawl_params[self::VIDEO_SOURCES][] = $url_parts[0];
Write the new crawl parameters to the name server, so
that it can pass them along in the case of a new archive
"/schedules/name_server_messages.txt";
$this->crawlModel->sendStartCrawlMessage($crawl_params,
$seed_info, $machine_urls);
* Reads the parameters for a crawl from an array gotten from a crawl.ini
* @param array &$crawl_params parameters to write to queue_server
* @param array $seed_info data from crawl.ini file
$crawl_params[self::CRAWL_TYPE] = $seed_info['general']['crawl_type'];
$crawl_params[self::CRAWL_INDEX] =
(isset ($seed_info['general']['crawl_index'])) ?
$seed_info['general']['crawl_index'] : '';
$crawl_params[self::ARC_DIR]= (isset ($seed_info['general']['arc_dir'])) ?
$seed_info['general']['arc_dir'] : '';
$crawl_params[self::ARC_TYPE] =
(isset ($seed_info['general']['arc_type'])) ?
$seed_info['general']['arc_type'] : '';
$crawl_params[self::CACHE_PAGES] =
(isset ($seed_info['general']['cache_pages'])) ?
intval($seed_info['general']['cache_pages']) :
$crawl_params[self::PAGE_RANGE_REQUEST] =
(isset ($seed_info['general']['page_range_request'])) ?
intval($seed_info['general']['page_range_request']) :
$crawl_params[self::PAGE_RECRAWL_FREQUENCY] =
(isset ($seed_info['general']['page_recrawl_frequency'])) ?
intval($seed_info['general']['page_recrawl_frequency']) :
$crawl_params[self::TO_CRAWL] = $seed_info['seed_sites']['url'];
$crawl_params[self::CRAWL_ORDER] = $seed_info['general']['crawl_order'];
$crawl_params[self::RESTRICT_SITES_BY_URL] =
$seed_info['general']['restrict_sites_by_url'];
$crawl_params[self::ALLOWED_SITES] =
isset ($seed_info['allowed_sites']['url']) ?
$seed_info['allowed_sites']['url'] : array();
$crawl_params[self::DISALLOWED_SITES] =
isset ($seed_info['disallowed_sites']['url']) ?
$seed_info['disallowed_sites']['url'] : array();
$crawl_params[self::PAGE_RULES] =
isset ($seed_info['page_rules']['rule']) ?
$seed_info['page_rules']['rule'] : array();
if(isset ($seed_info['indexing_plugins']['plugins'])) {
$crawl_params[self::INDEXING_PLUGINS] =
$seed_info['indexing_plugins']['plugins'];
if(isset ($seed_info['indexed_file_types']['extensions'])) {
$crawl_params[self::INDEXED_FILE_TYPES] =
$seed_info['indexed_file_types']['extensions'];
* Called from @see manageCrawls to edit the parameters for the next
* crawl (or current crawl) to be carried out by the machines
* $machine_urls. Updates $data array to be supplied to AdminView
* @param array &$data an array of info to supply to AdminView
* @param array $machine_urls string urls of machines managed by this
* Yioop name server on which to perform the crawl
$data["ELEMENT"] = "crawloptionsElement";
$crawls = $this->crawlModel->getCrawlList(false, false, $machine_urls);
$indexes = $this->crawlModel->getCrawlList(true, true, $machine_urls);
$mixes = $this->crawlModel->getMixList(false);
foreach($mixes as $mix) {
$tmp["DESCRIPTION"] = "MIX::". $mix["MIX_NAME"];
$tmp["CRAWL_TIME"] = $mix["MIX_TIMESTAMP"];
$tmp["ARC_TYPE"] = "MixArchiveBundle";
$indexes_by_crawl_time = array();
$data['available_options'] = array(
tl('admin_controller_use_below'),
tl('admin_controller_use_defaults'));
$data['available_crawl_indexes'] = array();
$data['options_default'] = tl('admin_controller_use_below');
foreach($crawls as $crawl) {
if(strlen($crawl['DESCRIPTION']) > 0 ) {
$data['available_options'][$crawl['CRAWL_TIME']] =
tl('admin_controller_previous_crawl'). " ".
foreach($indexes as $i => $crawl) {
$data['available_crawl_indexes'][$crawl['CRAWL_TIME']]
$indexes_by_crawl_time[$crawl['CRAWL_TIME']] = & $indexes[$i];
$no_further_changes = false;
$seed_current = $this->crawlModel->getSeedInfo();
if(isset ($_REQUEST['load_option']) &&
$_REQUEST['load_option'] == 1) {
$seed_info = $this->crawlModel->getSeedInfo(true);
$seed_current['general']['page_range_request'])) {
$seed_info['general']['page_range_request'] =
$seed_current['general']['page_range_request'];
$seed_current['general']['page_recrawl_frequency'])
$seed_info['general']['page_recrawl_frequency'] =
$seed_current['general']['page_recrawl_frequency'];
$no_further_changes = true;
} else if (isset ($_REQUEST['load_option']) &&
$_REQUEST['load_option'] > 1 ) {
$this->clean($_REQUEST['load_option'], "int");
$seed_info = $this->crawlModel->getCrawlSeedInfo(
$timestamp, $machine_urls);
$no_further_changes = true;
} else if(isset ($_REQUEST['ts'])) {
$this->clean($_REQUEST['ts'], "int");
$seed_info = $this->crawlModel->getCrawlSeedInfo(
$timestamp, $machine_urls);
$data['ts'] = $timestamp;
$seed_info = $this->crawlModel->getSeedInfo();
$page_options_properties = array('indexed_file_types',
'page_rules', 'indexing_plugins');
//these properties should be changed under page_options not here
foreach($page_options_properties as $property) {
if(isset ($seed_current[$property])) {
$seed_info[$property] = $seed_current[$property];
if(!$no_further_changes && isset ($_REQUEST['crawl_indexes'])
$seed_info['general']['crawl_index'] = $_REQUEST['crawl_indexes'];
$index_data = $indexes_by_crawl_time[$_REQUEST['crawl_indexes']];
if(isset ($index_data['ARC_DIR'])) {
$seed_info['general']['arc_dir'] = $index_data['ARC_DIR'];
$seed_info['general']['arc_type'] = $index_data['ARC_TYPE'];
$seed_info['general']['arc_dir'] = '';
$seed_info['general']['arc_type'] = '';
$data['crawl_index'] = (isset ($seed_info['general']['crawl_index'])) ?
$seed_info['general']['crawl_index'] : '';
$data['available_crawl_types'] = array(self::WEB_CRAWL,
if(!$no_further_changes && isset ($_REQUEST['crawl_type']) &&
in_array($_REQUEST['crawl_type'], $data['available_crawl_types'])) {
$seed_info['general']['crawl_type'] =
$data['crawl_type'] = $seed_info['general']['crawl_type'];
if($data['crawl_type'] == self::WEB_CRAWL) {
$data['web_crawl_active'] = "active";
$data['archive_crawl_active'] = "";
$data['archive_crawl_active'] = "active";
$data['web_crawl_active'] = "";
$data['available_crawl_orders'] = array(
tl('admin_controller_breadth_first'),
tl('admin_controller_page_importance'));
if(!$no_further_changes && isset ($_REQUEST['crawl_order'])
$seed_info['general']['crawl_order'] =
$_REQUEST['crawl_order'];
$data['crawl_order'] = $seed_info['general']['crawl_order'];
if(!$no_further_changes && isset ($_REQUEST['posted'])) {
$seed_info['general']['restrict_sites_by_url'] =
(isset ($_REQUEST['restrict_sites_by_url'])) ?
$data['restrict_sites_by_url'] =
$seed_info['general']['restrict_sites_by_url'];
array('allowed_sites' => 'url', 'disallowed_sites' => 'url',
foreach($site_types as $type => $field) {
if(!$no_further_changes && isset ($_REQUEST[$type])) {
$seed_info[$type][$field] =
$_REQUEST[$type], $field);
if(isset ($seed_info[$type][$field])) {
$seed_info[$type][$field]);
($data['restrict_sites_by_url']) ?
"checked='checked'" : "";
$data['SCRIPT'] = "setDisplay('toggle', ".
"'{$data['restrict_sites_by_url']}');";
if(!isset ($_REQUEST['ts'])) {
" elt('load-options').onchange = ".
"function() { if(elt('load-options').selectedIndex !=".
" 0) { elt('crawloptionsForm').submit(); }};";
"switchTab('webcrawltab', 'archivetab');";
"switchTab('archivetab', 'webcrawltab');";
if(isset ($_REQUEST['ts']) &&
isset ($_REQUEST['inject_sites'])) {
$timestamp = $this->clean($_REQUEST['ts'],
$_REQUEST['inject_sites']);
if($this->crawlModel->injectUrlsCurrentCrawl(
$timestamp, $inject_urls, $machine_urls)) {
tl('admin_controller_urls_injected');
if(isset ($_REQUEST['ts'])) {
$this->crawlModel->setCrawlSeedInfo($timestamp,
$seed_info, $machine_urls);
$this->crawlModel->setSeedInfo($seed_info);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_update_seed_info').
* Converts an array of lines of strings into a single string with
* proper newlines, each line having been trimmed and potentially
* @param array $arr the array of lines to be process
* @param string $endline_string what string should be used to indicate
* @param bool $clean whether to clean each line
* @return string a concatenated string of cleaned lines
$out_line = $this->clean($out_line, "string");
$output .= trim($out_line);
* Cleans a string consisting of lines, typically of urls into an array of
* clean lines. This is used in handling data from the crawl options
* @param string $str contains the url data
* @param string $line_type does additional cleaning depending on the type
* of the lines. For instance, if is "url" then a line not beginning
* with a url scheme will have http:// prepended.
* @return $lines an array of clean lines
if($line_type == "url") {
foreach($pre_lines as $line) {
$pre_line = trim($this->clean($line, "string"));
if($line_type == "url") {
$start_line = substr($pre_line, 0, 6);
array("file:/", "http:/", "domain", "https:"))) {
$pre_line = "http://". $pre_line;
* Handles admin request related to the crawl mix activity
* The crawl mix activity allows a user to create/edit crawl mixes:
* weighted combinations of search indexes
* @return array $data info about available crawl mixes and changes to them
* as well as any messages about the success or failure of a
$possible_arguments = array(
"createmix", "deletemix", "editmix", "index");
$data["ELEMENT"] = "mixcrawlsElement";
$data['mix_default'] = 0;
$machine_urls = $this->machineModel->getQueueServerUrls();
$num_machines = count($machine_urls);
if($num_machines < 1 || ($num_machines == 1 &&
$crawls = $this->crawlModel->getCrawlList(false, true, $machine_urls);
$data['available_crawls'][0] = tl('admin_controller_select_crawl');
$data['available_crawls'][1] = tl('admin_controller_default_crawl');
$data['SCRIPT'] = "c = [];c[0]='".
tl('admin_controller_select_crawl'). "';";
$data['SCRIPT'] .= "c[1]='".
tl('admin_controller_default_crawl'). "';";
foreach($crawls as $crawl) {
$data['available_crawls'][$crawl['CRAWL_TIME']] =
$data['SCRIPT'] .= 'c['. $crawl['CRAWL_TIME']. ']="'.
$crawl['DESCRIPTION']. '";';
$mixes = $this->crawlModel->getMixList(true);
$data['available_mixes']= $mixes;
foreach($mixes as $mix) {
$mix_ids[] = $mix['MIX_TIMESTAMP'];
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
$mix['MIX_TIMESTAMP'] = time();
if(isset ($_REQUEST['MIX_NAME'])) {
$mix['MIX_NAME'] = $this->clean($_REQUEST['MIX_NAME'],
$mix['MIX_NAME'] = tl('admin_controller_unnamed');
$mix['GROUPS'] = array();
$this->crawlModel->setCrawlMix($mix);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_mix_created'). "</h1>');";
//$data passed by reference
$this->editMix($data, $mix_ids, $mix);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_set_index'). "</h1>')";
$timestamp = $this->clean($_REQUEST['timestamp'], "int");
$this->crawlModel->setCurrentIndexDatabaseName($timestamp);
if(!isset ($_REQUEST['timestamp'])|| !isset ($mix_ids) ||
!in_array($_REQUEST['timestamp'], $mix_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_mix_doesnt_exists').
$this->crawlModel->deleteCrawlMix($_REQUEST['timestamp']);
$data['available_mixes'] =
$this->crawlModel->getMixList(true);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_mix_deleted'). "</h1>')";
$crawl_time = $this->crawlModel->getCurrentIndexDatabaseName();
if(isset ($crawl_time) ) {
$data['CURRENT_INDEX'] = (int) $crawl_time;
$data['CURRENT_INDEX'] = - 1;
* Handles admin request related to the editing a crawl mix activity
* @return array $data info about the groups and their contents for a
function editMix(&$data, &$mix_ids, $mix)
$data["ELEMENT"] = "editmixElement";
if(isset ($_REQUEST['timestamp'])) {
$mix = $this->crawlModel->getCrawlMix(
$data['INCLUDE_SCRIPTS'] = array("mix");
//set up an array of translation for javascript-land
$data['SCRIPT'] .= "tl = {".
'editmix_element_add_crawls:"'. tl('editmix_element_add_crawls') .
'",' . 'editmix_element_num_results:"'.
tl('editmix_element_num_results'). '",'.
'editmix_element_del_grp:"'. tl('editmix_element_del_grp'). '",'.
'editmix_element_weight:"'. tl('editmix_element_weight'). '",'.
'editmix_element_name:"'. tl('editmix_element_name'). '",'.
'editmix_add_keywords:"'. tl('editmix_add_keywords'). '",'.
'editmix_element_actions:"'. tl('editmix_element_actions'). '",'.
'editmix_add_query:"'. tl('editmix_add_query'). '",'.
'editmix_element_delete:"'. tl('editmix_element_delete'). '"'.
//clean and save the crawl mix sent from the browser
if(isset ($_REQUEST['update']) && $_REQUEST['update'] ==
$this->clean($mix['MIX_TIMESTAMP'], "int");
$mix['MIX_NAME'] = $this->clean($mix['MIX_NAME'],
if(isset ($mix['GROUPS'])) {
if($mix['GROUPS'] != NULL) {
foreach($mix['GROUPS'] as $group_id => $group_data) {
if(isset ($group_data['RESULT_BOUND'])) {
$mix['GROUPS'][$group_id]['RESULT_BOUND'] =
$this->clean($group_data['RESULT_BOUND'],
$mix['GROUPS']['RESULT_BOUND'] = 0;
if(isset ($group_data['COMPONENTS'])) {
foreach($group_data['COMPONENTS'] as $component) {
$row['CRAWL_TIMESTAMP'] =
$this->clean($component['CRAWL_TIMESTAMP'],
$row['WEIGHT'] = $this->clean(
$component['WEIGHT'], "float");
$row['KEYWORDS'] = $this->clean(
$mix['GROUPS'][$group_id]['COMPONENTS'] = $comp;
$mix['GROUPS'][$group_id]['COMPONENTS'] = array();
$mix['COMPONENTS'] = array();
$mix['GROUPS'] = $data['MIX']['GROUPS'];
$this->crawlModel->setCrawlMix($mix);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_mix_saved'). "</h1>');";
$data['SCRIPT'] .= 'groups = [';
foreach($mix['GROUPS'] as $group_id => $group_data) {
$data['SCRIPT'] .= $not_first. '{';
if(isset ($group_data['RESULT_BOUND'])) {
$data['SCRIPT'] .= "num_results:". $group_data['RESULT_BOUND'];
$data['SCRIPT'] .= "num_results:1 ";
$data['SCRIPT'] .= ", components:[";
if(isset ($group_data['COMPONENTS'])) {
foreach($group_data['COMPONENTS'] as $component) {
$crawl_ts = $component['CRAWL_TIMESTAMP'];
$crawl_name = $data['available_crawls'][$crawl_ts];
$data['SCRIPT'] .= $comma. " [$crawl_ts, '$crawl_name', ".
$component['WEIGHT']. ", ";
$keywords = (isset ($component['KEYWORDS'])) ?
$component['KEYWORDS'] : "";
$data['SCRIPT'] .= "'$keywords'] ";
$data['SCRIPT'] .= "] }";
$data['SCRIPT'] .= ']; drawGroups();';
* Handles admin request related to controlling file options to be used
* This activity allows a user to specify the page range size to be
* be used during a crawl as well as which file types can be downloaded
* @return array $data info about the groups and their contents for a
global $INDEXED_FILE_TYPES;
$data["ELEMENT"] = "pageoptionsElement";
$machine_urls = $this->machineModel->getQueueServerUrls();
$num_machines = count($machine_urls);
if($num_machines < 1 || ($num_machines == 1 &&
$data['available_options'] = array(
tl('admin_controller_use_below'),
tl('admin_controller_use_defaults'));
$crawls = $this->crawlModel->getCrawlList(false, true, $machine_urls);
$data['options_default'] = tl('admin_controller_use_below');
foreach($crawls as $crawl) {
if(strlen($crawl['DESCRIPTION']) > 0 ) {
$data['available_options'][$crawl['CRAWL_TIME']] =
tl('admin_controller_previous_crawl'). " ".
$seed_info = $this->crawlModel->getSeedInfo();
$data['RECRAWL_FREQS'] = array(- 1=> tl('admin_controller_recrawl_never'),
1=> tl('admin_controller_recrawl_1day'),
2=> tl('admin_controller_recrawl_2day'),
3=> tl('admin_controller_recrawl_3day'),
7=> tl('admin_controller_recrawl_7day'),
14=> tl('admin_controller_recrawl_14day'));
$data['SIZE_VALUES'] = array(10000=> 10000, 50000=> 50000,
100000=> 100000, 500000=> 500000, 1000000=> 1000000,
5000000=> 5000000, 10000000=> 10000000);
if(!isset ($seed_info["indexed_file_types"]["extensions"])) {
$seed_info["indexed_file_types"]["extensions"] =
if(isset ($_REQUEST['load_option']) &&
$_REQUEST['load_option'] > 0) {
if($_REQUEST['load_option'] == 1) {
$seed_loaded = $this->crawlModel->getSeedInfo(true);
$timestamp = $this->clean($_REQUEST['load_option'], "int");
$seed_loaded = $this->crawlModel->getCrawlSeedInfo(
$timestamp, $machine_urls);
$copy_options = array("general" => array("page_recrawl_frequency",
"page_range_request", "cache_pages"),
"indexed_file_types" => array("extensions"),
"indexing_plugins" => array("plugins"));
foreach($copy_options as $main_option => $sub_options) {
foreach($sub_options as $sub_option) {
if(isset ($seed_loaded[$main_option][$sub_option])) {
$seed_info[$main_option][$sub_option] =
$seed_loaded[$main_option][$sub_option];
if(isset ($seed_loaded['page_rules'])) {
$seed_info['page_rules'] =
$seed_loaded['page_rules'];
$seed_info = $this->crawlModel->getSeedInfo();
if(isset ($_REQUEST["page_recrawl_frequency"]) &&
in_array($_REQUEST["page_recrawl_frequency"],
$seed_info["general"]["page_recrawl_frequency"] =
$_REQUEST["page_recrawl_frequency"];
if(isset ($_REQUEST["page_range_request"]) &&
in_array($_REQUEST["page_range_request"],$data['SIZE_VALUES'])){
$seed_info["general"]["page_range_request"] =
$_REQUEST["page_range_request"];
if(isset ($_REQUEST["cache_pages"]) ) {
$seed_info["general"]["cache_pages"] = true;
} else if(isset ($_REQUEST['posted'])) {
//form sent but check box unchecked
$seed_info["general"]["cache_pages"] = false;
if(isset ($_REQUEST['page_rules'])) {
$seed_info['page_rules']['rule'] =
$_REQUEST['page_rules'], 'rule');
if(!isset ($seed_info["general"]["page_recrawl_frequency"])) {
$seed_info["general"]["page_recrawl_frequency"] =
$data['PAGE_RECRAWL_FREQUENCY'] =
$seed_info["general"]["page_recrawl_frequency"];
if(!isset ($seed_info["general"]["cache_pages"])) {
$seed_info["general"]["cache_pages"] = false;
$data["CACHE_PAGES"] = $seed_info["general"]["cache_pages"];
if(!isset ($seed_info["general"]["page_range_request"])) {
$data['PAGE_SIZE'] = $seed_info["general"]["page_range_request"];
$data['INDEXING_PLUGINS'] = array();
$included_plugins = array();
if(isset ($_REQUEST["posted"])) {
$seed_info['indexing_plugins']['plugins'] =
(isset ($_REQUEST["INDEXING_PLUGINS"])) ?
$_REQUEST["INDEXING_PLUGINS"] : array();
(isset ($seed_info['indexing_plugins']['plugins'])) ?
$seed_info['indexing_plugins']['plugins']
$data['INDEXING_PLUGINS'][$plugin_name] =
(in_array($plugin_name, $included_plugins)) ?
"checked='checked'" : "";
if(!isset ($_REQUEST['load_option'])) {
array('IP_LINK','CACHE_LINK', 'SIMILAR_LINK', 'IN_LINK',
'SIGNIN_LINK', 'SUBSEARCH_LINK','WORD_SUGGEST'));
$weights = array('TITLE_WEIGHT' => 4,
'DESCRIPTION_WEIGHT' => 1, 'LINK_WEIGHT' => 2,
'MIN_RESULTS_TO_GROUP' => 200, 'SERVER_ALPHA' => 1.6);
foreach($weights as $weight => $value) {
if(isset ($_REQUEST[$weight])) {
$data[$weight] = $this->clean($_REQUEST[$weight], 'float', 1
$profile[$weight] = $data[$weight];
} else if(isset ($profile[$weight]) && $profile[$weight] != ""){
$data[$weight] = $profile[$weight];
$profile[$weight] = $data[$weight];
$data['INDEXED_FILE_TYPES'] = array();
foreach($INDEXED_FILE_TYPES as $filetype) {
if(isset ($_REQUEST["filetype"]) && !$loaded) {
if(isset ($_REQUEST["filetype"][$filetype])) {
$filetypes[] = $filetype;
$seed_info["indexed_file_types"]["extensions"])) {
$filetypes[] = $filetype;
$data['INDEXED_FILE_TYPES'][$filetype] = ($ison) ?
$seed_info["indexed_file_types"]["extensions"] = $filetypes;
if(isset ($seed_info['page_rules']['rule'])) {
$seed_info['page_rules']['rule']);
$data['page_rules'] = "";
$allowed_options = array('crawl_time', 'search_time', 'test_options');
if(isset ($_REQUEST['option_type']) &&
in_array($_REQUEST['option_type'], $allowed_options)) {
$data['option_type'] = $_REQUEST['option_type'];
$data['option_type'] = 'crawl_time';
if($data['option_type'] == 'crawl_time') {
$data['crawl_time_active'] = "active";
$data['search_time_active'] = "";
$data['test_options_active'] = "";
$data['SCRIPT'] .= "\nswitchTab('crawltimetab',".
"'searchtimetab', 'testoptionstab')\n";
} else if($data['option_type'] == 'search_time') {
$data['search_time_active'] = "active";
$data['crawl_time_active'] = "";
$data['test_options_active'] = "";
$data['SCRIPT'] .= "\nswitchTab('searchtimetab',".
"'crawltimetab', 'testoptionstab')\n";
$data['search_time_active'] = "";
$data['crawl_time_active'] = "";
$data['test_options_active'] = "active";
$data['SCRIPT'] .= "\nswitchTab('testoptionstab',".
"'crawltimetab', 'searchtimetab');\n";
$this->crawlModel->setSeedInfo($seed_info);
if($change == true && $data['option_type'] != 'test_options') {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_page_options_updated'). "</h1>')";
$test_processors = array(
"text/html" => "HtmlProcessor",
"text/asp" => "HtmlProcessor",
"text/xml" => "XmlProcessor",
"text/robot" => "RobotProcessor",
"application/xml" => "XmlProcessor",
"application/xhtml+xml" => "HtmlProcessor",
"application/rss+xml" => "RssProcessor",
"application/atom+xml" => "RssProcessor",
"text/rtf" => "RtfProcessor",
"text/plain" => "TextProcessor",
"text/csv" => "TextProcessor",
"text/tab-separated-values" => "TextProcessor",
$data['MIME_TYPES'] = array_keys($test_processors);
$data['page_type'] = "text/html";
if(isset ($_REQUEST['page_type']) && in_array($_REQUEST['page_type'],
$data['page_type'] = $_REQUEST['page_type'];
$data['TESTPAGE'] = (isset ($_REQUEST['TESTPAGE'])) ?
$this->clean($_REQUEST['TESTPAGE'], 'string') : "";
if($data['option_type'] == 'test_options' && $data['TESTPAGE'] != "") {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_page_options_running_tests'). "</h1>')";
$site[self::ENCODING] = "UTF-8";
$site[self::URL] = "http://test-site.yioop.com/";
$site[self::IP_ADDRESSES] = array("1.1.1.1");
$site[self::HTTP_CODE] = 200;
$site[self::MODIFIED] = date("U", time());
$site[self::TIMESTAMP] = time();
$site[self::TYPE] = "text/html";
$site[self::HEADER] = "page options test extractor";
$site[self::SERVER] = "unknown";
$site[self::SERVER_VERSION] = "unknown";
$site[self::OPERATING_SYSTEM] = "unknown";
$site[self::LANG] = 'en';
$site[self::JUST_METAS] = false;
if(isset ($_REQUEST['page_type']) &&
in_array($_REQUEST['page_type'], $data['MIME_TYPES'])) {
$site[self::TYPE] = $_REQUEST['page_type'];
$processor_name = $test_processors[$site[self::TYPE]];
$page_processor = new $processor_name();
$doc_info = $page_processor->handle($_REQUEST['TESTPAGE'],
foreach($doc_info as $key => $value) {
if(isset ($site[self::PAGE])) {
unset ($site[self::PAGE]);
if(isset ($site[self::ROBOT_PATHS])) {
$site[self::JUST_METAS] = true;
$reflect = new ReflectionClass("CrawlConstants");
$crawl_constants = $reflect->getConstants();
$after_process = array();
foreach($site as $key => $value) {
$out_key = (isset ($inverse_constants[$key])) ?
$inverse_constants[$key] : $key;
$after_process[$out_key] = $value;
print_r($after_process, true), "string"), 75, "\n", true);
$rule_string = implode("\n", $seed_info['page_rules']['rule']);
$page_rule_parser->executeRuleTrees($site);
$after_process = array();
foreach($site as $key => $value) {
$out_key = (isset ($inverse_constants[$key])) ?
$inverse_constants[$key] : $key;
$after_process[$out_key] = $value;
print_r($after_process, true), "string"), 75, "\n", true);
if(isset ($site[self::LANG])) {
$lang = $site[self::LANG];
if(!$site[self::JUST_METAS]) {
$phrase_string = $host_words. " ". $site[self::TITLE] .
" ". $path_words . " ". $site[self::DESCRIPTION];
$len = strlen($phrase_string);
$meta_ids[] = "safe:true";
$meta_ids[] = "safe:false";
print_r($word_lists, true), "string"), 75, "\n", true);;
print_r($meta_ids, true), "string"), 75, "\n", true);
* Handles admin request related to the search filter activity
* This activity allows a user to specify hosts whose web pages are to be
* filtered out the search results
* @return array $data info about the groups and their contents for a
$data["ELEMENT"] = "resultseditorElement";
if(isset ($_REQUEST['disallowed_sites'])) {
$_REQUEST['disallowed_sites']);
$disallowed_sites = array();
foreach($sites as $site) {
$disallowed_sites[] = $site. "/";
$data['disallowed_sites'] = implode("\n", $disallowed_sites);
$this->searchfiltersModel->set($disallowed_sites);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_results_editor_update'). "</h1>')";
if(!isset ($data['disallowed_sites'])) {
$data['disallowed_sites'] =
implode("\n", $this->searchfiltersModel->getUrls());
foreach (array("URL", "TITLE", "DESCRIPTION") as $field) {
$data[$field] = (isset ($_REQUEST[$field])) ?
$this->clean($_REQUEST[$field], "string") :
((isset ($data[$field]) ) ? $data[$field] : "");
$tmp = tl('admin_controller_edited_pages');
$data["URL_LIST"] = array ($tmp => $tmp);
$summaries = $this->searchfiltersModel->getEditedPageSummaries();
foreach($summaries as $hash => $summary) {
$data["URL_LIST"][$summary[self::URL]] = $summary[self::URL];
if(isset ($_REQUEST['arg']) ) {
$missing_page_field = ($data["URL"] == "") ? true: false;
if($missing_page_field) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_results_editor_need_url').
$this->searchfiltersModel->updateResultPage(
$data["URL"], $data["TITLE"], $data["DESCRIPTION"]);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_results_editor_page_updated').
$hash_url = crawlHash($_REQUEST['LOAD_URL'], true);
if(isset ($summaries[$hash_url])) {
$data["URL"] = $this->clean($_REQUEST['LOAD_URL'],
$data["TITLE"] = $summaries[$hash_url][self::TITLE];
$data["DESCRIPTION"] = $summaries[$hash_url][
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_results_editor_page_loaded').
* Handles admin request related to the managing the machines which perform
* With this activity an admin can add/delete machines to manage. For each
* managed machine, the admin can stop and start fetchers/queue_servers
* as well as look at their log files
* @return array $data MACHINES, their MACHINE_NAMES, data for
* FETCHER_NUMBERS drop-down
$data["ELEMENT"] = "managemachinesElement";
$possible_arguments = array("addmachine", "deletemachine",
"newsmode", "log", "update");
$data['SCRIPT'] = "doUpdate();";
$data['MACHINES'] = array();
$data['MACHINE_NAMES'] = array();
$data['FETCHER_NUMBERS'] = array(
$machines = $this->machineModel->getMachineList();
$tmp = tl('admin_controller_select_machine');
$data['DELETABLE_MACHINES'] = array(
$data['REPLICATABLE_MACHINES'] = array(
foreach($machines as $machine) {
$data['MACHINE_NAMES'][] = $machine["NAME"];
$urls[] = $machine["URL"];
$data['DELETABLE_MACHINES'][$machine["NAME"]] = $machine["NAME"];
if(!isset ($machine["PARENT"]) || $machine["PARENT"] == "") {
$data['REPLICATABLE_MACHINES'][$machine["NAME"]]
if(!isset ($_REQUEST["has_queue_server"]) ||
isset ($_REQUEST['is_replica'])) {
$_REQUEST["has_queue_server"] = false;
if(isset ($_REQUEST['is_replica'])) {
$_REQUEST['num_fetchers'] = 0;
$_REQUEST['parent'] = "";
"has_queue_server" => "bool",
foreach($request_fields as $field => $type) {
if(isset ($_REQUEST[$field])) {
$r[$field] = $this->clean($_REQUEST[$field], $type);
if($field == "url" && $r[$field][strlen($r[$field])- 1]
if(isset ($r["num_fetchers"]) &&
in_array($r["num_fetchers"], $data['FETCHER_NUMBERS'])) {
$data['FETCHER_NUMBER'] = $r["num_fetchers"];
$data['FETCHER_NUMBER'] = 0;
if(isset ($r["num_fetchers"])) {
$machine_exists = (isset ($r["name"]) && in_array($r["name"],
$data['MACHINE_NAMES']) ) || (isset ($r["url"]) &&
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
if($allset == true && !$machine_exists) {
$this->machineModel->addMachine(
$r["name"], $r["url"], $r["has_queue_server"],
$r["num_fetchers"], $r["parent"]);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_machine_added').
$data['MACHINE_NAMES'][] = $r["name"];
$data['DELETABLE_MACHINES'][$r["name"]] = $r["name"];
sort($data['MACHINE_NAMES']);
} else if ($allset && $machine_exists ) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_machine_exists').
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_machine_incomplete').
!in_array($r["name"], $data['MACHINE_NAMES'])) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_machine_doesnt_exists').
$machines = $this->machineModel->getMachineStatuses();
foreach($machines as $machine) {
if($machine['NAME'] == $r["name"]) {
if($machine['STATUSES'] != array()) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_stop_service_first'). "</h1>');";
$this->machineModel->deleteMachine($r["name"]);
$tmp_array = array($r["name"]);
$tmp_array = array($r["name"] => $r["name"]);
array_diff($data['DELETABLE_MACHINES'], $tmp_array);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_machine_deleted'). "</h1>');";
$news_modes = array("news_off", "news_web", "news_process");
if(isset ($_REQUEST['news_mode']) && in_array(
$_REQUEST['news_mode'], $news_modes)) {
$profile["NEWS_MODE"] = $_REQUEST['news_mode'];
if($profile["NEWS_MODE"] != "news_process") {
$cron_time = $this->cronModel->getCronTime(
$delta = time() - $cron_time;
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_news_process_running').
$profile["NEWS_MODE"] = "news_off";
$this->profileModel->updateProfile(
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_news_mode_updated').
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_news_update_failed').
if(isset ($_REQUEST["fetcher_num"])) {
$this->clean($_REQUEST["fetcher_num"], "int");
if(isset ($_REQUEST["mirror_name"])) {
$this->clean($_REQUEST["mirror_name"], "string");
if(isset ($_REQUEST["time"])) {
$this->clean($_REQUEST["time"], "int") + 30;
if(isset ($_REQUEST["NO_REFRESH"])) {
$data["NO_REFRESH"] = $this->clean(
$_REQUEST["NO_REFRESH"], "bool");
$data["NO_REFRESH"] = false;
$data["ELEMENT"] = "machinelogElement";
if(isset ($_REQUEST['f'])) {
$this->clean($_REQUEST['f'], "string");
$data['filter'] = $filter;
$data["REFRESH_LOG"] = "&time=". $data["time"];
if(isset ($r['fetcher_num']) && isset ($r['name'])) {
$data["LOG_FILE_DATA"] = $this->machineModel->getLog(
$r["name"], $r["fetcher_num"], $filter);
$data["LOG_TYPE"] = $r['name'].
" fetcher ". $r["fetcher_num"];
$data["REFRESH_LOG"] .= "&arg=log&name=". $r['name'].
"&fetcher_num=". $r['fetcher_num'];
} else if(isset ($r["mirror_name"])) {
$data["LOG_TYPE"] = $r['mirror_name']. " mirror";
$data["LOG_FILE_DATA"] = $this->machineModel->getLog(
$r["mirror_name"], NULL, $filter, true);
} else if(isset ($r['name'])) {
$data["LOG_TYPE"] = $r['name']. " queue_server";
if($r['name'] == "news") {
$data["LOG_TYPE"] = "Name Server News Updater";
$data["LOG_FILE_DATA"] = $this->machineModel->getLog(
$r["name"], NULL, $filter);
"&arg=log&name=". $r['name'];
if($data["time"] >= 1200) {
$data["REFRESH_LOG"] = "";
if(!isset ($data["LOG_FILE_DATA"])
|| $data["LOG_FILE_DATA"] == ""){
tl('admin_controller_no_machine_log');
$data["LOG_FILE_DATA"] = implode("\n", $lines);
if(isset ($_REQUEST["fetcher_num"])) {
$this->clean($_REQUEST["fetcher_num"], "int");
$r["fetcher_num"] = NULL;
$available_actions = array("start", "stop",
"mirror_start", "mirror_stop");
if(isset ($r["name"]) && isset ($_REQUEST["action"]) &&
in_array($_REQUEST["action"], $available_actions)) {
$action = $_REQUEST["action"];
if($action == "mirror_start") {
} else if ($action == "mirror_stop") {
$this->machineModel->update($r["name"],
$action, $r["fetcher_num"], $is_mirror);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_machine_servers_updated').
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_machine_no_action').
if(!isset ($_REQUEST['arg']) || $_REQUEST['arg'] != 'log') {
$data['SCRIPT'] .= "toggleReplica(false);";
* Handles admin request related to the manage locale activity
* The manage locale activity allows a user to add/delete locales, view
* statistics about a locale as well as edit the string for that locale
* @return array $data info about current locales, statistics for each
* locale as well as potentially the currently set string of a
* locale and any messages about the success or failure of a
$possible_arguments = array("addlocale", "deletelocale", "editlocale");
$data["ELEMENT"] = "managelocalesElement";
$data["LOCALES"] = $this->localeModel->getLocaleList();
$data['LOCALE_NAMES'][- 1] = tl('admin_controller_select_localename');
foreach ($data["LOCALES"] as $locale) {
$data["LOCALE_NAMES"][$locale["LOCALE_TAG"]] =
$locale_ids[] = $locale["LOCALE_TAG"];
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
if(isset ($_REQUEST['localename'])) {
$localename = $this->clean($_REQUEST['localename'], "string" );
if(isset ($_REQUEST['localetag'])) {
$localetag = $this->clean($_REQUEST['localetag'], "string" );
if(isset ($_REQUEST['writingmode'])) {
$this->clean($_REQUEST['writingmode'], "string" );
if(isset ($_REQUEST['selectlocale'])) {
$this->clean($_REQUEST['selectlocale'], "string" );
$this->localeModel->addLocale(
$localename, $localetag, $writingmode);
$this->localeModel->extractMergeLocales();
$data["LOCALES"] = $this->localeModel->getLocaleList();
$data['LOCALE_NAMES'][$localetag] = $localename;
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_locale_added'). "</h1>')";
if(!in_array($select_locale, $locale_ids)) {
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_localename_doesnt_exists').
$this->localeModel->deleteLocale($select_locale);
$data["LOCALES"] = $this->localeModel->getLocaleList();
unset ($data['LOCALE_NAMES'][$select_locale]);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_localename_deleted'). "</h1>')";
if(!isset ($select_locale)) break;
$data["ELEMENT"] = "editlocalesElement";
$data['STATIC_PAGES'][- 1]=
tl('admin_controller_select_staticpages');
$this->localeModel->getStaticPageList($select_locale);
$data['CURRENT_LOCALE_NAME'] =
$data['LOCALE_NAMES'][$select_locale];
$data['CURRENT_LOCALE_TAG'] = $select_locale;
$tmp_pages = $data['STATIC_PAGES'];
if(isset ($_REQUEST['static_page']) &&
in_array($_REQUEST['static_page'], $page_keys)) {
$data["ELEMENT"] = "editstaticElement";
$data['STATIC_PAGE'] = $_REQUEST['static_page'];
if(isset ($_REQUEST['PAGE_DATA'])) {
$this->localeModel->setStaticPage(
$_REQUEST['static_page'],
$data['CURRENT_LOCALE_TAG'],
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_staticpage_updated').
$data['STATIC_PAGES'][$data['STATIC_PAGE']];
$this->localeModel->getStaticPage(
$_REQUEST['static_page'],
$data['CURRENT_LOCALE_TAG']);
/*since page data can contain tags we clean it
htmlentities it just before displaying*/
$data['PAGE_DATA'] = $this->clean($data['PAGE_DATA'],
$data['SCRIPT'] .= "selectPage = elt('static-pages');".
"selectPage.onchange = submitStaticPageForm;";
if(isset ($_REQUEST['STRINGS'])) {
foreach($_REQUEST['STRINGS'] as $key => $value) {
$clean_key = $this->clean($key, "string" );
$clean_value = $this->clean($value, "string" );
$safe_strings[$clean_key] = $clean_value;
$this->localeModel->updateStringData(
$select_locale, $safe_strings);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_localestrings_updated').
$this->localeModel->extractMergeLocales();
$this->localeModel->getStringData($select_locale);
$data['DEFAULT_STRINGS'] =
* Checks to see if the current machine has php configured in a way
* @return string a message indicatign which required and optional
* components are missing; or "Passed" if nothing missing.
array("name" => "Multi-Curl",
"check"=> "curl_multi_init", "type"=> "function"),
array("name" => "GD Graphics Library",
"check"=> "imagecreate", "type"=> "function"),
array("name" => "SQLite3 Library",
"check"=> "SQLite3|PDO", "type"=> "class"),
array("name" => "Multibyte Character Library",
"check"=> "mb_internal_encoding", "type"=> "function"),
/* as an example of what this array could contain...
array("name" => "Memcache", "check" => "Memcache",
foreach($required_items as $item) {
$check_function = $item["type"]. "_exists";
$check_parts = explode("|", $item["check"]);
foreach($check_parts as $check) {
if($check_function($check)) {
$missing_required .= $comma. $item["name"];
if(!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
$missing_required .= $comma. tl("admin_controller_php_version");
$out .= tl('admin_controller_no_write_config_php');
$out .= $br. tl('admin_controller_no_write_work_dir');
$out .= $br. tl('admin_controller_post_size_small');
if($missing_required != "") {
tl('admin_controller_missing_required', $missing_required);
foreach($optional_items as $item) {
$check_function = $item["type"]. "_exists";
$check_parts = explode("|", $item["check"]);
foreach($check_parts as $check) {
if($check_function($check)) {
$missing_optional .= $comma. $item["name"];
if($missing_optional != "") {
tl('admin_controller_missing_optional', $missing_optional);
$out = tl('admin_controller_check_passed');
$out = "<span class='red'>$out</span>";
$out .= "<br />". tl('admin_controller_using_local_config');
* Handles admin request related to the search sources activity
* The search sources activity allows a user to add/delete search sources
* for video and news, it also allows a user to control which subsearches
* appear on the SearchView page
* @return array $data info about current search sources, and current
$possible_arguments = array("addsource", "deletesource",
"addsubsearch", "deletesubsearch");
$data["ELEMENT"] = "searchsourcesElement";
$data['SOURCE_TYPES'] = array(- 1 => tl('admin_controller_media_kind'),
"video" => tl('admin_controller_video'),
"rss" => tl('admin_controller_rss_feed'));
$source_type_flag = false;
if(isset ($_REQUEST['sourcetype']) &&
$data['SOURCE_TYPE'] = $_REQUEST['sourcetype'];
$source_type_flag = true;
$data['SOURCE_TYPE'] = - 1;
$machine_urls = $this->machineModel->getQueueServerUrls();
$search_lists = $this->crawlModel->getCrawlList(false, true,
$data["SEARCH_LISTS"] = array(- 1 =>
tl('admin_controller_sources_indexes'));
foreach($search_lists as $item) {
$data["SEARCH_LISTS"]["i:". $item["CRAWL_TIME"]] =
$search_lists= $this->crawlModel->getMixList();
foreach($search_lists as $item) {
$data["SEARCH_LISTS"]["m:". $item["MIX_TIMESTAMP"]] =
array($n => $n, 2* $n => 2* $n, 5* $n=> 5* $n, 10* $n=> 10* $n);
if(isset ($_REQUEST['perpage']) &&
$data['PER_PAGE_SELECTED'] = $_REQUEST['perpage'];
$locales = $this->localeModel->getLocaleList();
$data["LANGUAGES"] = array();
foreach($locales as $locale) {
$data["LANGUAGES"][$locale['LOCALE_TAG']] = $locale['LOCALE_NAME'];
if(isset ($_REQUEST['sourcelocaletag']) &&
$data['SOURCE_LOCALE_TAG'] =
$_REQUEST['sourcelocaletag'];
if(isset ($_REQUEST['arg']) &&
in_array($_REQUEST['arg'], $possible_arguments)) {
if(!$source_type_flag) break;
$must_have = array("sourcename", "sourcetype",
array('sourcethumbnail','sourcelocaletag'));
foreach ($to_clean as $clean_me) {
$r[$clean_me] = (isset ($_REQUEST[$clean_me])) ?
$this->clean($_REQUEST[$clean_me], "string" ) : "";
$r[$clean_me] == "" ) break 2;
$this->sourceModel->addMediaSource(
$r['sourcename'], $r['sourcetype'], $r['sourceurl'],
$r['sourcethumbnail'], $r['sourcelocaletag']);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_media_source_added').
if(!isset ($_REQUEST['ts'])) break;
$timestamp = $this->clean($_REQUEST['ts'], "string");
$this->sourceModel->deleteMediaSource($timestamp);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_media_source_deleted').
$to_clean = array("foldername", 'indexsource');
foreach ($to_clean as $clean_me) {
$r[$clean_me] = (isset ($_REQUEST[$clean_me])) ?
$this->clean($_REQUEST[$clean_me], "string" ) : "";
$r[$clean_me] == "" ) break 2;
$this->sourceModel->addSubsearch(
$r['foldername'], $r['indexsource'],
$data['PER_PAGE_SELECTED']);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_subsearch_added').
if(!isset ($_REQUEST['fn'])) break;
$folder_name = $this->clean($_REQUEST['fn'], "string");
$this->sourceModel->deleteSubsearch($folder_name);
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
tl('admin_controller_subsearch_deleted').
$data["MEDIA_SOURCES"] = $this->sourceModel->getMediaSources();
$subsearches = $this->sourceModel->getSubsearches();
$data["SUBSEARCHES"] = array();
foreach($subsearches as $search) {
if(isset ($data["SEARCH_LISTS"][$search['INDEX_IDENTIFIER']])) {
$data["SUBSEARCHES"][] = $search;
$this->sourceModel->deleteSubsearch($search["FOLDER_NAME"]);
$data['SCRIPT'] .= "source_type = elt('source-type');".
"source_type.onchange = switchSourceType;".
* Responsible for handling admin request related to the configure activity
* The configure activity allows a user to set the work directory for
* storing data local to this SeekQuarry/Yioop instance. It also allows one
* to set the default language of the installation, dbms info, robot info,
* test info, as well as which machine acts as the queue server.
* @return array $data fields for available language, dbms, etc as well as
* results of processing sub activity if any
$languages = $this->localeModel->getLocaleList();
foreach($languages as $language) {
$data['LANGUAGES'][$language['LOCALE_TAG']] =
$language['LOCALE_NAME'];
if(isset ($_REQUEST['lang'])) {
$data['lang'] = $this->clean($_REQUEST['lang'], "string");
$profile['DEFAULT_LOCALE'] = $data['lang'];
$data["ELEMENT"] = "configureElement";
$data['PROFILE'] = false;
if(isset ($_REQUEST['WORK_DIRECTORY']) || (defined('WORK_DIRECTORY') &&
$_REQUEST['arg'] = "directory";
@unlink($_REQUEST['WORK_DIRECTORY']. "/profile.php");
$this->clean($_REQUEST['WORK_DIRECTORY'], "string");
//convert to forward slashes so consistent with rest of code
if($dir[0] != "/" && $dir[1] != ":") {
$data['PROFILE'] = false;
} else if($dir[0] != "/") {
$data['PROFILE'] = false;
if($data['PROFILE'] == false) {
tl('admin_controller_configure_use_absolute_path');
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
$data["MESSAGE"]. "</h1>');" .
"setTimeout('window.location.href= ".
"window.location.href', 3000);";
$data['WORK_DIRECTORY'] = $dir;
$data['PROFILE'] = false;
tl('admin_controller_configure_diff_base_dir');
$data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
$data["MESSAGE"]. "</h1>');" .
"setTimeout('window.location.href= ".
"window.location.href', 3000);";
$data['WORK_DIRECTORY'] = $dir;
$data['WORK_DIRECTORY'] = $dir;
if(isset ($_REQUEST['arg'])) {
if(!isset ($data['WORK_DIRECTORY'])) {break;}
$this->profileModel->getProfile(
$data['WORK_DIRECTORY']));
$this->profileModel->setWorkDirectoryConfigFile(
$data['WORK_DIRECTORY']);
tl('admin_controller_configure_work_dir_set');
"doMessage('<h1 class=\"red\" >".
$data["MESSAGE"]. "</h1>');setTimeout(".
"'window.location.href=window.location.href', 3000);";
} else if ($data['PROFILE'] &&
strlen($data['WORK_DIRECTORY']) > 0) {
if($this->profileModel->makeWorkDirectory(
$data['WORK_DIRECTORY'])) {
$profile['DBMS'] = 'sqlite3';
$data['DBMS'] = 'sqlite3';
$profile['DB_NAME'] = 'default';
$data['DB_NAME'] = 'default';
$profile['USER_AGENT_SHORT'] =
tl('admin_controller_name_your_bot');
$data['USER_AGENT_SHORT'] =
$profile['USER_AGENT_SHORT'];
$http = (isset ($_SERVER['HTTPS'])) ? "https://" :
$profile['NAME_SERVER'] =
$http . $_SERVER['SERVER_NAME'] . $uri;
$data['NAME_SERVER'] = $profile['NAME_SERVER'];
$data['WORK_DIRECTORY']. time());
$data['AUTH_KEY'] = $profile['AUTH_KEY'];
$_SERVER['SERVER_NAME']). "-". time();
$profile['ROBOT_INSTANCE'] = $robot_instance;
$data['ROBOT_INSTANCE'] = $profile['ROBOT_INSTANCE'];
if($this->profileModel->updateProfile(
$data['WORK_DIRECTORY'], array(), $profile)) {
$this->profileModel->setWorkDirectoryConfigFile(
$data['WORK_DIRECTORY'])) {
tl('admin_controller_configure_work_profile_made');
"doMessage('<h1 class=\"red\" >".
$data["MESSAGE"]. "</h1>');" .
"setTimeout('window.location.href= ".
"window.location.href', 3000);";
$this->profileModel->getProfile(
$data['WORK_DIRECTORY']));
$data['PROFILE'] = false;
tl('admin_controller_configure_no_set_config');
"doMessage('<h1 class=\"red\" >".
$data["MESSAGE"] . "</h1>');" .
"setTimeout('window.location.href= ".
"window.location.href', 3000);";
$this->profileModel->setWorkDirectoryConfigFile(
$data['WORK_DIRECTORY']);
$data['PROFILE'] = false;
tl('admin_controller_configure_no_create_profile');
"doMessage('<h1 class=\"red\" >".
"</h1>'); setTimeout('window.location.href=".
"window.location.href', 3000);";
$this->profileModel->setWorkDirectoryConfigFile(
$data['WORK_DIRECTORY']);
tl('admin_controller_configure_work_dir_invalid');
"doMessage('<h1 class=\"red\" >". $data["MESSAGE"].
"setTimeout('window.location.href=".
"window.location.href', 3000);";
$data['PROFILE'] = false;
$this->profileModel->setWorkDirectoryConfigFile(
$data['WORK_DIRECTORY']);
tl('admin_controller_configure_work_dir_invalid');
"doMessage('<h1 class=\"red\" >". $data["MESSAGE"] .
"setTimeout('window.location.href=".
"window.location.href', 3000);";
$data['PROFILE'] = false;
array('USE_FILECACHE', 'USE_MEMCACHE', "WEB_ACCESS",
'RSS_ACCESS', 'API_ACCESS'));
$data['DEBUG_LEVEL'] = 0;
(isset ($_REQUEST["ERROR_INFO"])) ? ERROR_INFO : 0;
(isset ($_REQUEST["QUERY_INFO"])) ? QUERY_INFO : 0;
(isset ($_REQUEST["TEST_INFO"])) ? TEST_INFO : 0;
$profile['DEBUG_LEVEL'] = $data['DEBUG_LEVEL'];
$this->profileModel->getProfile($data['WORK_DIRECTORY']);
if((isset ($profile['DBMS']) &&
$profile['DBMS'] != $old_profile['DBMS']) ||
(isset ($profile['DB_NAME']) &&
$profile['DB_NAME'] != $old_profile['DB_NAME']) ||
(isset ($profile['DB_HOST']) &&
$profile['DB_HOST'] != $old_profile['DB_HOST'])) {
if(!$this->profileModel->migrateDatabaseIfNecessary(
} else if ((isset ($profile['DB_USER']) &&
$profile['DB_USER'] != $old_profile['DB_USER']) ||
(isset ($profile['DB_PASSWORD']) &&
$profile['DB_PASSWORD'] != $old_profile['DB_PASSWORD'])) {
if($this->profileModel->testDatabaseManager(
tl('admin_controller_configure_no_change_db');
"doMessage('<h1 class=\"red\" >". $data['MESSAGE'].
$data['DBMS'] = $old_profile['DBMS'];
$data['DB_NAME'] = $old_profile['DB_NAME'];
$data['DB_HOST'] = $old_profile['DB_HOST'];
$data['DB_USER'] = $old_profile['DB_USER'];
$data['DB_PASSWORD'] = $old_profile['DB_PASSWORD'];
if($this->profileModel->updateProfile(
$data['WORK_DIRECTORY'], $profile, $old_profile)) {
tl('admin_controller_configure_profile_change');
"doMessage('<h1 class=\"red\" >". $data['MESSAGE'].
if($old_profile['DEBUG_LEVEL'] !=
$profile['DEBUG_LEVEL']) {
"setTimeout('window.location.href=\"".
$data['PROFILE'] = false;
tl('admin_controller_configure_no_change_profile');
"doMessage('<h1 class=\"red\" >". $data["MESSAGE"].
if(isset ($data['WORK_DIRECTORY']) &&
$this->profileModel->getProfile(
$data['WORK_DIRECTORY']));
"|Z|","\n", $data['MEMCACHE_SERVERS']);
$data['WORK_DIRECTORY'] = "";
$data['PROFILE'] = false;
$data['advanced'] = "false";
$data['DBMSS'] = array();
$data['SCRIPT'] .= "logindbms = Array();\n";
foreach($this->profileModel->getDbmsList() as $dbms) {
$data['DBMSS'][$dbms] = $dbms;
if($this->profileModel->loginDbms($dbms)) {
$data['SCRIPT'] .= "logindbms['$dbms'] = true;\n";
$data['SCRIPT'] .= "logindbms['$dbms'] = false;\n";
if(!isset ($data['ROBOT_DESCRIPTION']) ||
strlen($data['ROBOT_DESCRIPTION']) == 0) {
$data['ROBOT_DESCRIPTION'] =
tl('admin_controller_describe_robot');
//since the description might contain tags we apply htmlentities
$data['ROBOT_DESCRIPTION'] =
$this->clean($data['ROBOT_DESCRIPTION'], "string");
if(!isset ($data['MEMCACHE_SERVERS']) ||
strlen($data['MEMCACHE_SERVERS']) == 0) {
$data['MEMCACHE_SERVERS'] =
if(isset ($_REQUEST['advanced']) && $_REQUEST['advanced']) {
$data['advanced'] = "true";
$data['SCRIPT'] .= <<< EOD
elt('database-system').onchange = function () {
setDisplay('login-dbms', self.logindbms[elt('database-system').value]);
setDisplay('login-dbms', logindbms[elt('database-system').value]);
setDisplay('advance-configure', { $data['advanced']});
setDisplay('advance-robot', { $data['advanced']});
function toggleAdvance() {
var advanced = elt('a-settings');
advanced.value = (advanced.value =='true')
var value = (advanced.value == 'true') ? true : false;
setDisplay('advance-configure', value);
setDisplay('advance-robot', value);
$data['SCRIPT'] .= <<< EOD
elt('use-memcache').onchange = function () {
setDisplay('filecache', (elt('use-memcache').checked) ? false: true);
setDisplay('memcache', (elt('use-memcache').checked) ? true : false);
setDisplay('filecache', (elt('use-memcache').checked) ? false : true);
setDisplay('memcache', (elt('use-memcache').checked) ? true : false);
"elt('locale').onchange = ".
"function () { elt('configureProfileForm').submit();};\n";
foreach($this->profileModel->profile_fields as $field) {
if(isset ($_REQUEST[$field])) {
if($field != "ROBOT_DESCRIPTION" &&
$field != "MEMCACHE_SERVERS") {
$this->clean($_REQUEST[$field], "string");
$clean_field = $_REQUEST[$field];
if($field == "NAME_SERVER" &&
$clean_field[strlen($clean_field) - 1] != "/") {
$data[$field] = $clean_field;
$profile[$field] = $data[$field];
if($field == "MEMCACHE_SERVERS") {
$mem_array, "|Z|", true);
if(!isset ($data[$field])) {
if(in_array($field, $check_box_fields)) {
$profile[$field] = false;
|