UPGRADE NOTE: Do not edit or add to this file if you wish to upgrade AbanteCart to newer versions in the future. If you wish to customize AbanteCart for your needs please refer to http://www.AbanteCart.com for more information. ------------------------------------------------------------------------------*/ if (!defined('DIR_CORE') || !IS_ADMIN) { header('Location: static_pages/'); } class ControllerResponsesCommonActionCommands extends AController { private $error = array(); public $commands = array(); //main method to load commands public function main() { $result = array(); $text_data = $this->language->getASet('common/action_commands'); $keys = preg_grep("/^command.*/", array_keys($text_data)); foreach($keys as $key) { $this->commands[$key] = $text_data[$key]; } unset($text_data); unset($keys); //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); //load all commands from languages. $term = $this->request->get['term']; if ( !$term ) { $this->extensions->hk_UpdateData($this, __FUNCTION__); return $this->_no_match(); } //search for possible commands foreach($this->commands as $key => $command){ $variations = explode(',', $command); //loop for command in the term foreach ($variations as $test) { $test = trim($test); preg_match("/^$test\s*(.*)/iu", $term, $matches); if (count($matches)) { $result['command'] = $test; $result['key'] = $key; $result['request'] = $matches[1]; //no breack. Take last matching command } } } if ( !$result ) { $this->extensions->hk_UpdateData($this, __FUNCTION__); return $this->_no_match(); }else{ //call method to perform action on the request in the command $function = "_".$result['key']; if( method_exists( $this, $function )){ //fillter duplicates and empty $result['found_actions'] = $this->_filter_result( $this->$function($result['request']) ); } else { $this->extensions->hk_UpdateData($this, __FUNCTION__); return $this->_no_match(); } } $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->load->library('json'); $this->response->setOutput(AJson::encode($result)); } // List of controllers for insert actions public function insert_controllers() { $this->extensions->hk_InitData($this, __FUNCTION__); $list = array( 'category' => 'catalog/category/insert', 'product' => 'catalog/product/insert', 'brand' => 'catalog/manufacturer/insert', 'manufacturer' => 'catalog/manufacturer/insert', 'download' => 'catalog/download/insert', 'review' => 'catalog/review/insert', 'attribute' => 'catalog/attribute/insert', 'customer' => 'sale/customer/insert', 'coupon' => 'sale/coupon/insert', 'discount' => 'sale/coupon/insert', 'block' => 'design/blocks/insert', 'menu' => 'design/menu/insert', 'content' => 'design/content/insert', 'page' => 'design/content/insert', 'banner' => 'extension/banner_manager/insert', 'store' => 'setting/store/insert', 'language' => 'localisation/language/insert', 'currency' => 'localisation/currency/insert', 'location' => 'localisation/location/insert', 'tax' => 'localisation/tax_class/insert', ); $this->extensions->hk_UpdateData($this, __FUNCTION__); return $list; } private function _no_match() { $result = array(); $result['message'] = $this->language->get('text_possible_commands'); //load all possible commands from language definitions. foreach($this->commands as $command){ $result['commands'][] = $command; } $this->load->library('json'); $this->response->setOutput(AJson::encode($result)); return null; } private function _command_open( $request ) { //some menu text $this->loadLanguage('common/header'); //return format (array): url =>, title =>, confirmation => (true, false) $result = array(); //remove junk words $request = preg_replace('/menu|tab|page/', '', $request); $request = trim($request); //look for page in the menu matching //assume for now we have cache get menu from databse. $menu_arr = $this->cache->get('admin_menu'); if (count($menu_arr)) { foreach($menu_arr as $menu){ $sub_res = array(); //load language for prospect controller //Check that filename has proper name with no other special characters. if ( preg_match("/[\W]+/", str_replace('/', '_', $menu['item_url'])) ) { $title = $this->language->get($menu['item_text']); } else { $this->loadLanguage($menu['item_url'], 'silent'); $title = $this->language->get($menu['item_text']) . " / " . $this->language->get('heading_title'); } if (preg_match("/$request/iu", $title)){ $sub_res["title"] = $title; $sub_res["url"] = $this->html->getSecureURL($menu['item_url']); $sub_res["confirmation"] = false; $result[] = $sub_res; } } } return $result; } private function _command_find( $request ) { //return format (array): url =>, title =>, confirmation => (true, false) $result = array(); $request = trim($request); //future!!! check for second level request and do specific area search //return global search result $result[0]["url"] = $this->html->getSecureURL('tool/global_search', '&search='.$request); $result[0]["confirmation"] = false; return $result; } private function _command_clear_cache( $request ) { $result = array(); $result[0]["url"] = $this->html->getSecureURL('tool/cache/delete', '&clear_all=all'); $result[0]["confirmation"] = true; return $result; } private function _command_view_log( $request ) { $result = array(); $request = trim($request); $result[0]["url"] = $this->html->getSecureURL('tool/error_log'); return $result; } private function _command_clear_log( $request ) { $result = array(); $request = trim($request); $result[0]["url"] = $this->html->getSecureURL('tool/error_log/clearlog'); $result[0]["confirmation"] = true; return $result; } private function _command_view_order( $request ) { $result = array(); $request = trim($request); if (is_numeric($request)) { $result[0]["url"] = $this->html->getSecureURL('sale/order/details', '&order_id='.$request); } else { $result[0]["url"] = $this->html->getSecureURL('sale/order'); } return $result; } private function _command_create_new( $request ) { //return format (array): url =>, title =>, confirmation => (true, false) $result = array(); $request = trim($request); $possible_matches = $this->insert_controllers(); foreach ($possible_matches as $key => $rt) { if (preg_match("/$request/iu", $this->language->get($key))){ $sub_res["title"] = $key; $sub_res["url"] = $this->html->getSecureURL($rt); $sub_res["confirmation"] = false; $result[] = $sub_res; } } return $result; } private function _filter_result($data) { if ( empty($data)) { return array(); } $ret = array(); foreach ($data as $record) { if ( !empty($record["url"]) && preg_match("/rt=/", $record["url"]) ) { //check if already present in result $skip = false; foreach($ret as $value) { if ( $value["url"] == $record["url"]) { $skip = true; break; } } if ( !$skip ) { $ret[] = $record; } } } return $ret; } } ?>