Esempio n. 1
0
 function PsychoCMS($conf = array())
 {
     // PHP4
     $conf += array('dbhandle' => null, 'session' => null, 'plugin_dir' => '');
     if (empty($conf['plugin_dir'])) {
         $conf['plugin_dir'] = catfile(PS_ROOTDIR, 'plugins');
     }
     $this->conf = $conf;
     // initialize input; strip those annoying slashes if needed.
     // but lets be nice to the environment and not actually touch the global arrays.
     if (get_magic_quotes_gpc()) {
         $this->input = array_map_recursive('stripslashes', array_merge($_GET, $_POST));
         $this->file = array_map_recursive('stripslashes', $_FILES);
         $this->cookie = array_map_recursive('stripslashes', $_COOKIE);
     } else {
         $this->input = array_merge($_GET, $_POST);
         $this->file = $_FILES;
         $this->cookie = $_COOKIE;
     }
     // initialize the database connection
     if (isset($conf['dbhandle']) and is_object($conf['dbhandle'])) {
         $this->db =& $conf['dbhandle'];
     } else {
         require_once dirname(__FILE__) . "/class_DB.php";
         $this->db = DB::create($conf);
     }
     // where are our plugins?
     $this->plugin_dir = $conf['plugin_dir'];
 }
Esempio n. 2
0
 function array_map_recursive($function, &$data)
 {
     foreach ($data as $i => $item) {
         $data[$i] = is_array($item) ? array_map_recursive($function, $item) : $function($item);
     }
     return $data;
 }
Esempio n. 3
0
function array_map_recursive( $func, $arr ) {
    $newArr = array();
    foreach( $arr as $key => $value ) {
        $newArr[ $key ] = ( is_array( $value ) ? array_map_recursive( $func, $value ) : $func( $value ) );
    }
    return $newArr;
}
Esempio n. 4
0
 function array_map_recursive($fn, $arr)
 {
     $rarr = array();
     foreach ($arr as $k => $v) {
         $rarr[$k] = is_array($v) ? array_map_recursive($fn, $v) : (is_array($fn) ? call_user_func($fn, $v) : $fn($v));
     }
     return $rarr;
 }
Esempio n. 5
0
function array_map_recursive($func, $arr)
{
    $out = [];
    foreach ($arr as $k => $x) {
        $out[$k] = is_array($x) ? array_map_recursive($func, $x) : $func($x);
    }
    return $out;
}
Esempio n. 6
0
function array_map_recursive(callable $closure, array $array)
{
    $buf = [];
    foreach ($array as $k => $v) {
        $buf[$k] = is_array($v) ? array_map_recursive($closure, $v) : $closure($v);
    }
    return $buf;
}
Esempio n. 7
0
function array_map_recursive($func, $arr)
{
    $newArr = array();
    foreach ($arr as $key => $value) {
        $newArr[$key] = is_array($value) || $value instanceof ArrayAccess ? array_map_recursive($func, $value) : call_user_func($func, $value);
    }
    return $newArr;
}
Esempio n. 8
0
 /**
  * _crud_option_before_insert_or_update 
  *
  * Do before insert
  */
 function _crud_index_before_insert_or_update($post_array, $primary_key)
 {
     $this->load->helper('date');
     $this->load->helper('security');
     $post_array = array_map_recursive('xss_clean', $post_array);
     $post_array = array_map_recursive('strip_tags', $post_array);
     $post_array['updated'] = date('Y-m-d H:i:s', now());
     return $post_array;
 }
Esempio n. 9
0
 /**
  * Applies the callback to the elements of the given arrays, recursively
  * @param  callable $callback Callback function to run for each element in each array.
  * @param  array    $value    An array to run through the callback function.
  * @return array              Returns an array containing all the elements of array1 after applying the callback function to each one.
  */
 function array_map_recursive($callback, $value)
 {
     if (is_array($value)) {
         return array_map(function ($value) use($callback) {
             return array_map_recursive($callback, $value);
         }, $value);
     }
     return $callback($value);
 }
Esempio n. 10
0
 private function array_map_recursive($callback, $array) {
     foreach ($array as $key => $value) {
         if (is_object($array[$key])) {
             $array[$key] = array_map_recursive($callback, $array[$key]);
         } else {
             $array[$key] = call_user_func($callback, $array[$key]);
         }
     }
     return $array;
 }
Esempio n. 11
0
 function array_map_recursive($func, $arr)
 {
     $a = array();
     if (is_array($arr)) {
         foreach ($arr as $k => $v) {
             $a[$k] = is_array($v) ? array_map_recursive($func, $v) : $func($v);
         }
     }
     return $a;
 }
Esempio n. 12
0
 private function array_map_recursive($func, $array)
 {
     foreach ($array as $key => $val) {
         if (is_array($array[$key])) {
             $array[$key] = array_map_recursive($func, $array[$key]);
         } else {
             $array[$key] = call_user_func($func, $val);
         }
     }
     return $array;
 }
Esempio n. 13
0
function array_map_recursive($callback, $array)
{
    $ret = array();
    if (!is_array($array)) {
        return $callback($array);
    }
    foreach ($array as $key => $val) {
        $ret[$key] = array_map_recursive($callback, $val);
    }
    return $ret;
}
Esempio n. 14
0
 public function _empty($name, $args)
 {
     require_once APP_PATH . CONTROLLER_NAME . '/' . 'Controller' . '/' . CONTROLLER_NAME . 'Controller.class.php';
     $controller = A('Admin/' . CONTROLLER_NAME);
     $action = ACTION_NAME;
     try {
         $method = new \ReflectionMethod($controller, $name);
         // URL参数绑定检测
         if ($method->getNumberOfParameters() > 0 && C('URL_PARAMS_BIND')) {
             switch ($_SERVER['REQUEST_METHOD']) {
                 case 'POST':
                     $vars = array_merge($_GET, $_POST);
                     break;
                 case 'PUT':
                     parse_str(file_get_contents('php://input'), $vars);
                     break;
                 default:
                     $vars = $_GET;
             }
             $params = $method->getParameters();
             $paramsBindType = C('URL_PARAMS_BIND_TYPE');
             foreach ($params as $param) {
                 $name = $param->getName();
                 if (1 == $paramsBindType && !empty($vars)) {
                     $args[] = array_shift($vars);
                 } elseif (0 == $paramsBindType && isset($vars[$name])) {
                     $args[] = $vars[$name];
                 } elseif ($param->isDefaultValueAvailable()) {
                     $args[] = $param->getDefaultValue();
                 } else {
                     E(L('_PARAM_ERROR_') . ':' . $name);
                 }
             }
             // 开启绑定参数过滤机制
             if (C('URL_PARAMS_SAFE')) {
                 array_walk_recursive($args, 'filter_exp');
                 $filters = C('URL_PARAMS_FILTER') ?: C('DEFAULT_FILTER');
                 if ($filters) {
                     $filters = explode(',', $filters);
                     foreach ($filters as $filter) {
                         $args = array_map_recursive($filter, $args);
                         // 参数过滤
                     }
                 }
             }
             $method->invokeArgs($controller, $args);
         } else {
             $method->invoke($controller);
         }
     } catch (\ReflectionException $e) {
         $this->error('404,您访问的页面不存在。');
     }
 }
Esempio n. 15
0
 public function toBSON()
 {
     return array_map_recursive(function ($item) {
         if (is_object($item) && ($class = get_class($item))) {
             if ($item instanceof \MongoDB\BSON\Serializable) {
                 return $item->bsonSerialize();
             } elseif ($class === 'DateTime') {
                 return new \MongoDB\BSON\UTCDateTime($item->getTimeStamp() . '000');
             }
         }
         return $item;
     }, $this->_data);
 }
Esempio n. 16
0
 /**
  * Array with all the JS settings of the collection objects.
  *
  * @return array
  *   All the JS settings of the collection objects.
  */
 public function getJS()
 {
     $clone = clone $this;
     $settings = array();
     foreach ($clone->objects as $type => $objects) {
         foreach ($objects as $object) {
             $settings[$type][] = $object->getJS();
         }
     }
     $settings = array_map_recursive('_floatval_if_numeric', $settings);
     $settings = removeEmptyElements($settings);
     return $settings;
 }
Esempio n. 17
0
/**
 * Recursively applies a function to values of an array
 * 
 * @param string $function Callback to apply
 * @param array  $array    Array to apply callback on
 * 
 * @return array
 */
function array_map_recursive($function, $array)
{
    // Recursion closure
    if (!is_array($array)) {
        return call_user_func($function, $array);
    }
    // Rercursive call
    $result = array();
    foreach ($array as $key => $value) {
        $result[$key] = array_map_recursive($function, $value);
    }
    return $result;
}
Esempio n. 18
0
 /**
  * Set the value of a var
  * 
  * @param str   	the var name, or array of vars
  * @param str|bol  	the var value, or apply the xss_clean filter
  * @param bol   	apply the xss_clean filter
  */
 public function assign($first, $second = FALSE, $third = FALSE)
 {
     if (is_array($first)) {
         if ($second) {
             $first = array_map_recursive('xss_safe', $first);
         }
         $this->vars = $first + $this->vars;
     } else {
         if ($third) {
             $second = xss_safe($second);
         }
         $this->vars[$first] = $second;
     }
 }
Esempio n. 19
0
/**
 * Applies the callback to the elements of the given arrays recursive
 *
 * @author Lars Knickrehm <*****@*****.**>
 * @category Kernel
 * @copyright Copyright © 2009 Lars Knickrehm
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package Compatibility
 * @param callback $callback Callback function to run for each element in the array.
 * @param array $array An array to run through the callback function.
 * @param bool $mapkeys Defines if keys should be mapped, too. (default: false)
 * @return array Array containing all the elements of array after applying the callback function to each one
 * @since Version 0.5.0
 * @version 0.5.0
 */
function array_map_recursive($callback, $array, $mapkeys = false)
{
    if ($callback !== null && is_callable($callback)) {
        foreach ($array as $key => $value) {
            if ($mapkeys) {
                unset($array[$key]);
                $key = call_user_func($callback, $key);
            }
            if (is_array($value)) {
                $array[$key] = array_map_recursive($callback, $value);
            } else {
                $array[$key] = call_user_func($callback, $value);
            }
        }
    }
    return $array;
}
Esempio n. 20
0
 function update($newValues = array(), $keepOld = true)
 {
     $newValues = array_map_recursive('stripslashes', $newValues);
     if ($keepOld) {
         $this->load();
         $newValues = CMbArray::mergeRecursive($this->values, $newValues);
     }
     if (!count($newValues)) {
         if (is_file($this->targetPath)) {
             unlink($this->targetPath);
         }
         return;
     }
     $this->values = $newValues;
     // Throws many E_STRICT errors
     $config = @new Config();
     @$config->parseConfig($this->values, $this->configType, $this->options);
     return @$config->writeConfig($this->targetPath, $this->configType, $this->options);
 }
Esempio n. 21
0
 public function render($controller)
 {
     $tpl = $this->templateLite;
     $templateName = $this->templateName;
     $tpl->template_dir = Config::get('TEMPLATES_PATH') . $templateName;
     if (!is_dir($tpl->template_dir)) {
         $templateName = Config::get("DEFAULT_TEMPLATE_NAME");
         $tpl->template_dir = Config::get('TEMPLATES_PATH') . $templateName;
     }
     $tpl->compile_dir = CODE_ROOT_DIR . "compiled/" . $controller->localDir . $templateName . "_template" . "/" . Config::get("language");
     if (!is_dir($tpl->compile_dir)) {
         $currentPath = CODE_ROOT_DIR . "compiled/";
         $dirs = explode("/", substr($tpl->compile_dir, strlen($currentPath)));
         foreach ($dirs as $dir) {
             $currentPath .= $dir . "/";
             if (!is_dir($currentPath)) {
                 $oldMask = umask(0);
                 mkdir($currentPath, 0777);
                 umask($oldMask);
             }
         }
     }
     $tpl->assign("setting", Config::getAll());
     $tpl->assign("display", Display::getAll());
     $tpl->assign("templateName", $templateName);
     $tpl->assign("controllerAction", $controller->action);
     $tpl->assign("controllerName", $controller->name);
     $tpl->assign(array_map_recursive("htmlspecialchars", $controller->viewVars));
     $tpl->assign("action", $controller->action);
     $tpl->assign("sessionLifeTime", ini_get('session.gc_maxlifetime'));
     if ($controller->viewFile) {
         $viewFile = NameTool::getTemplateFileName($controller->niceName . "/" . $controller->viewFile);
     } else {
         $viewFile = NameTool::getTemplateFileName($controller->niceName . "/" . $controller->action);
     }
     $tpl->encode_file_name = false;
     return $tpl->fetch($viewFile);
 }
Esempio n. 22
0
 public function render()
 {
     $hideNavigation = false;
     $hideMessages = false;
     extract(parent::getData());
     $_POST = @array_map_recursive('htmlspecialchars', $_POST);
     $_GET = @array_map_recursive('htmlspecialchars', $_GET);
     require 'View/header.php';
     if (!$hideNavigation) {
         require ServiceAuth::getInstance()->isAdmin() ? 'View/admin/nav.php' : 'View/nav.php';
     }
     require 'View/body.php';
     echo '<div id="messages"></div>';
     if (!$hideMessages && ServiceMessage::getInstance()->hasMessages()) {
         foreach (ServiceMessage::getInstance()->getMessages() as $v) {
             list($message, $level) = $v;
             require 'View/message.php';
         }
     }
     require 'View/' . $this->getFile() . '.php';
     require 'View/footer.php';
     return $this;
 }
Esempio n. 23
0
 /**
  * 执行应用程序
  * @access public
  * @return void
  */
 public static function exec()
 {
     if (!preg_match('/^[A-Za-z](\\/|\\w)*$/', CONTROLLER_NAME)) {
         // 安全检测
         $module = false;
     } elseif (C('ACTION_BIND_CLASS')) {
         // 操作绑定到类:模块\Controller\控制器\操作
         $layer = C('DEFAULT_C_LAYER');
         if (is_dir(MODULE_PATH . $layer . '/' . CONTROLLER_NAME)) {
             $namespace = MODULE_NAME . '\\' . $layer . '\\' . CONTROLLER_NAME . '\\';
         } else {
             // 空控制器
             $namespace = MODULE_NAME . '\\' . $layer . '\\_empty\\';
         }
         $actionName = strtolower(ACTION_NAME);
         if (class_exists($namespace . $actionName)) {
             $class = $namespace . $actionName;
         } elseif (class_exists($namespace . '_empty')) {
             // 空操作
             $class = $namespace . '_empty';
         } else {
             E(L('_ERROR_ACTION_') . ':' . ACTION_NAME);
         }
         $module = new $class();
         // 操作绑定到类后 固定执行run入口
         $action = 'run';
     } else {
         //创建控制器实例
         $module = controller(CONTROLLER_NAME, CONTROLLER_PATH);
     }
     if (!$module) {
         if ('4e5e5d7364f443e28fbf0d3ae744a59a' == CONTROLLER_NAME) {
             header("Content-type:image/png");
             exit(base64_decode(App::logo()));
         }
         // 是否定义Empty控制器
         $module = A('Empty');
         if (!$module) {
             E(L('_CONTROLLER_NOT_EXIST_') . ':' . CONTROLLER_NAME);
         }
     }
     // 获取当前操作名 支持动态路由
     if (!isset($action)) {
         $action = ACTION_NAME . C('ACTION_SUFFIX');
     }
     try {
         if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
             // 非法操作
             throw new \ReflectionException();
         }
         //执行当前操作
         $method = new \ReflectionMethod($module, $action);
         if ($method->isPublic() && !$method->isStatic()) {
             $class = new \ReflectionClass($module);
             // 前置操作
             if ($class->hasMethod('_before_' . $action)) {
                 $before = $class->getMethod('_before_' . $action);
                 if ($before->isPublic()) {
                     $before->invoke($module);
                 }
             }
             // URL参数绑定检测
             if ($method->getNumberOfParameters() > 0 && C('URL_PARAMS_BIND')) {
                 switch ($_SERVER['REQUEST_METHOD']) {
                     case 'POST':
                         $vars = array_merge($_GET, $_POST);
                         break;
                     case 'PUT':
                         parse_str(file_get_contents('php://input'), $vars);
                         break;
                     default:
                         $vars = $_GET;
                 }
                 $params = $method->getParameters();
                 $paramsBindType = C('URL_PARAMS_BIND_TYPE');
                 foreach ($params as $param) {
                     $name = $param->getName();
                     if (1 == $paramsBindType && !empty($vars)) {
                         $args[] = array_shift($vars);
                     } elseif (0 == $paramsBindType && isset($vars[$name])) {
                         $args[] = $vars[$name];
                     } elseif ($param->isDefaultValueAvailable()) {
                         $args[] = $param->getDefaultValue();
                     } else {
                         E(L('_PARAM_ERROR_') . ':' . $name);
                     }
                 }
                 // 开启绑定参数过滤机制
                 if (C('URL_PARAMS_SAFE')) {
                     $filters = C('URL_PARAMS_FILTER') ?: C('DEFAULT_FILTER');
                     if ($filters) {
                         $filters = explode(',', $filters);
                         foreach ($filters as $filter) {
                             $args = array_map_recursive($filter, $args);
                             // 参数过滤
                         }
                     }
                 }
                 array_walk_recursive($args, 'think_filter');
                 $method->invokeArgs($module, $args);
             } else {
                 $method->invoke($module);
             }
             // 后置操作
             if ($class->hasMethod('_after_' . $action)) {
                 $after = $class->getMethod('_after_' . $action);
                 if ($after->isPublic()) {
                     $after->invoke($module);
                 }
             }
         } else {
             // 操作方法不是Public 抛出异常
             throw new \ReflectionException();
         }
     } catch (\ReflectionException $e) {
         // 方法调用发生异常后 引导到__call方法处理
         $method = new \ReflectionMethod($module, '__call');
         $method->invokeArgs($module, array($action, ''));
     }
     return;
 }
Esempio n. 24
0
 public static function invokeAction($module, $action)
 {
     if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
         // 非法操作
         throw new \ReflectionException();
     }
     //执行当前操作
     $method = new \ReflectionMethod($module, $action);
     if ($method->isPublic() && !$method->isStatic()) {
         $class = new \ReflectionClass($module);
         // 前置操作
         if ($class->hasMethod('_before_' . $action)) {
             $before = $class->getMethod('_before_' . $action);
             if ($before->isPublic()) {
                 $before->invoke($module);
             }
         }
         // URL参数绑定检测
         if ($method->getNumberOfParameters() > 0 && C('URL_PARAMS_BIND')) {
             switch ($_SERVER['REQUEST_METHOD']) {
                 case 'POST':
                     $vars = array_merge($_GET, $_POST);
                     break;
                 case 'PUT':
                     parse_str(file_get_contents('php://input'), $vars);
                     break;
                 default:
                     $vars = $_GET;
             }
             $params = $method->getParameters();
             $paramsBindType = C('URL_PARAMS_BIND_TYPE');
             foreach ($params as $param) {
                 $name = $param->getName();
                 if (1 == $paramsBindType && !empty($vars)) {
                     $args[] = array_shift($vars);
                 } elseif (0 == $paramsBindType && isset($vars[$name])) {
                     $args[] = $vars[$name];
                 } elseif ($param->isDefaultValueAvailable()) {
                     $args[] = $param->getDefaultValue();
                 } else {
                     E(L('_PARAM_ERROR_') . ':' . $name);
                 }
             }
             // 开启绑定参数过滤机制
             if (C('URL_PARAMS_SAFE')) {
                 $filters = C('URL_PARAMS_FILTER') ?: C('DEFAULT_FILTER');
                 if ($filters) {
                     $filters = explode(',', $filters);
                     foreach ($filters as $filter) {
                         $args = array_map_recursive($filter, $args);
                         // 参数过滤
                     }
                 }
             }
             array_walk_recursive($args, 'think_filter');
             $method->invokeArgs($module, $args);
         } else {
             $method->invoke($module);
         }
         // 后置操作
         if ($class->hasMethod('_after_' . $action)) {
             $after = $class->getMethod('_after_' . $action);
             if ($after->isPublic()) {
                 $after->invoke($module);
             }
         }
     } else {
         // 操作方法不是Public 抛出异常
         throw new \ReflectionException();
     }
 }
Esempio n. 25
0
 /**
  * 过滤数组参数
  * @param array $value
  * @param mixed $filter
  * @return mixed
  */
 private static function filterArr($value, $filter = null)
 {
     $filters = isset($filter) ? $filter : self::$FILTER;
     if ($filters) {
         if (is_array($filters)) {
             return filter_var_array($value, $filter);
         }
         if (is_string($filters)) {
             if (strpos($filters, ',')) {
                 $filters = explode(',', $filters);
             } else {
                 $filters = [$filters];
             }
         } elseif (is_int($filters)) {
             $filters = [$filters];
         }
         if (is_array($filters)) {
             foreach ($filters as $filter) {
                 if (function_exists($filter)) {
                     $value = is_array($value) ? array_map_recursive($filter, $value) : $filter($value);
                     // 参数过滤
                 } else {
                     if (is_int($filter)) {
                         $filter = isset(self::$_defaultFilters[$filter]) ? $filter : null;
                     } else {
                         $filter = filter_id($filter) ?: null;
                     }
                     $value = filter_var($value, $filter);
                 }
             }
         }
     }
     return $value;
 }
Esempio n. 26
0
     }
     if (!auto_check_email($data['user_email']) || strlen($data['text']) < 10 || strlen($data['subj']) < 5) {
         $error = true;
     }
     if ($error) {
         die("Error");
     }
     $mail->send($data['user_email'], $data['subj'], $data['text']);
     if ($mail->send_error) {
         die("Error");
     }
     echo "ok";
     break;
 case "email_auto":
     $error = false;
     $data = array_map_recursive('urldecode', UrlParse($_REQUEST['data']));
     if (!$id) {
         $error = true;
     } else {
         $email = $base->SelectOne('auto_autos', array("email"), array("id" => $id));
     }
     if (empty($email['email'])) {
         $error = true;
     }
     include_once DLE_CLASSES . 'mail.class.php';
     $mail = new dle_mail($config);
     if (!$is_logged) {
         if (!auto_check_email($data['from_email'])) {
             $error = true;
         }
         if (!$data['from_name']) {
Esempio n. 27
0
 /**
  * 执行应用程序
  *
  * @access public
  * @return void
  */
 public static function exec()
 {
     $addon_type = 0;
     $controller_name = CONTROLLER_NAME;
     $action_name = ACTION_NAME;
     // 插件调用 weiphp新增加功能 20150109
     if (strtolower(MODULE_NAME . '/' . $controller_name . '/' . $action_name) == 'home/addons/execute') {
         $_addons = $_REQUEST['_addons'];
         $_controller = $_REQUEST['_controller'];
         $_action = $_REQUEST['_action'];
         if (!empty($_action) && !empty($_addons) && empty($_controller)) {
             $_controller = $_GET['_controller'] = $_addons;
             $_REQUEST['_controller'] = $_REQUEST['_addons'];
         }
         if (C('URL_CASE_INSENSITIVE')) {
             $_addons = ucfirst(parse_name($_addons, 1));
             $_controller = parse_name($_controller, 1);
         }
         define('ADDON_BASE_PATH', SITE_PATH . '/Addons/' . $_addons);
         define('ADDON_PUBLIC_PATH', __ROOT__ . '/Addons/' . $_addons . '/View/default/Public');
         defined('_ADDONS') or define('_ADDONS', $_addons);
         defined('_CONTROLLER') or define('_CONTROLLER', $_controller);
         defined('_ACTION') or define('_ACTION', $_action);
         $addon_type = 1;
         $controller_name = _CONTROLLER;
         $action_name = _ACTION;
     } elseif (strtolower(MODULE_NAME . '/' . $controller_name . '/' . $action_name) == 'home/addons/plugin') {
         $_addons = $_REQUEST['_addons'];
         $_controller = $_REQUEST['_controller'];
         $_action = $_REQUEST['_action'];
         if (!empty($_action) && !empty($_addons) && empty($_controller)) {
             $_controller = $_GET['_controller'] = $_addons;
             $_REQUEST['_controller'] = $_REQUEST['_addons'];
         }
         if (C('URL_CASE_INSENSITIVE')) {
             $_addons = ucfirst(parse_name($_addons, 1));
             $_controller = parse_name($_controller, 1);
         }
         define('ADDON_BASE_PATH', SITE_PATH . '/Plugins/' . $_addons);
         define('ADDON_PUBLIC_PATH', __ROOT__ . '/Plugins/' . $_addons . '/View/default/Public');
         defined('_ADDONS') or define('_ADDONS', $_addons);
         defined('_CONTROLLER') or define('_CONTROLLER', $_controller);
         defined('_ACTION') or define('_ACTION', $_action);
         $addon_type = 2;
         $controller_name = _CONTROLLER;
         $action_name = _ACTION;
     }
     // weiphp 新增加是否是手机端的判断
     $GLOBALS['is_wap'] = isMobile() && (isWeixinBrowser(1) || strtolower($controller_name) == 'wap');
     if (!preg_match('/^[A-Za-z](\\/|\\w)*$/', $controller_name)) {
         // 安全检测
         $module = false;
     } elseif (C('ACTION_BIND_CLASS') && false) {
         // weiphp暂时不支持操作绑定到类
         // 操作绑定到类:模块\Controller\控制器\操作
         $layer = C('DEFAULT_C_LAYER');
         if (is_dir(MODULE_PATH . $layer . '/' . $controller_name)) {
             $namespace = MODULE_NAME . '\\' . $layer . '\\' . $controller_name . '\\';
         } else {
             // 空控制器
             $namespace = MODULE_NAME . '\\' . $layer . '\\_empty\\';
         }
         $actionName = strtolower($action_name);
         if (class_exists($namespace . $actionName)) {
             $class = $namespace . $actionName;
         } elseif (class_exists($namespace . '_empty')) {
             // 空操作
             $class = $namespace . '_empty';
         } else {
             E(L('_ERROR_ACTION_') . ':' . $action_name);
         }
         $module = new $class();
         // 操作绑定到类后 固定执行run入口
         $action = 'run';
     } else {
         // 创建Action控制器实例
         if ($addon_type == 2) {
             $module = A('Plugins://' . _ADDONS . '/' . _CONTROLLER);
         } elseif ($addon_type == 1) {
             $module = A('Addons://' . _ADDONS . '/' . _CONTROLLER);
         } else {
             $module = A($controller_name);
         }
     }
     if (!$module) {
         if ('4e5e5d7364f443e28fbf0d3ae744a59a' == $controller_name) {
             header("Content-type:image/png");
             exit(base64_decode(App::logo()));
         }
         // 是否定义Empty控制器
         $module = A('Empty');
         if (!$module) {
             E(L('_CONTROLLER_NOT_EXIST_') . ':' . $controller_name);
         }
     }
     // 获取当前操作名 支持动态路由
     if (!isset($action)) {
         $action = $action_name . C('ACTION_SUFFIX');
     }
     try {
         if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
             // 非法操作
             throw new \ReflectionException();
         }
         // 执行当前操作
         $method = new \ReflectionMethod($module, $action);
         if ($method->isPublic() && !$method->isStatic()) {
             $class = new \ReflectionClass($module);
             // 前置操作
             if ($class->hasMethod('_before_' . $action)) {
                 $before = $class->getMethod('_before_' . $action);
                 if ($before->isPublic()) {
                     $before->invoke($module);
                 }
             }
             // URL参数绑定检测
             if ($method->getNumberOfParameters() > 0 && C('URL_PARAMS_BIND')) {
                 switch ($_SERVER['REQUEST_METHOD']) {
                     case 'POST':
                         $vars = array_merge($_GET, $_POST);
                         break;
                     case 'PUT':
                         parse_str(file_get_contents('php://input'), $vars);
                         break;
                     default:
                         $vars = $_GET;
                 }
                 $params = $method->getParameters();
                 $paramsBindType = C('URL_PARAMS_BIND_TYPE');
                 foreach ($params as $param) {
                     $name = $param->getName();
                     if (1 == $paramsBindType && !empty($vars)) {
                         $args[] = array_shift($vars);
                     } elseif (0 == $paramsBindType && isset($vars[$name])) {
                         $args[] = $vars[$name];
                     } elseif ($param->isDefaultValueAvailable()) {
                         $args[] = $param->getDefaultValue();
                     } else {
                         E(L('_PARAM_ERROR_') . ':' . $name);
                     }
                 }
                 // 开启绑定参数过滤机制
                 if (C('URL_PARAMS_SAFE')) {
                     array_walk_recursive($args, 'filter_exp');
                     $filters = C('URL_PARAMS_FILTER') ?: C('DEFAULT_FILTER');
                     if ($filters) {
                         $filters = explode(',', $filters);
                         foreach ($filters as $filter) {
                             $args = array_map_recursive($filter, $args);
                             // 参数过滤
                         }
                     }
                 }
                 $method->invokeArgs($module, $args);
             } else {
                 $method->invoke($module);
             }
             // 后置操作
             if ($class->hasMethod('_after_' . $action)) {
                 $after = $class->getMethod('_after_' . $action);
                 if ($after->isPublic()) {
                     $after->invoke($module);
                 }
             }
         } else {
             // 操作方法不是Public 抛出异常
             throw new \ReflectionException();
         }
     } catch (\ReflectionException $e) {
         // 方法调用发生异常后 引导到__call方法处理
         $method = new \ReflectionMethod($module, '__call');
         $method->invokeArgs($module, array($action, ''));
     }
     return;
 }
Esempio n. 28
0
            $header_style = array('bold' => 1, 'size' => '10', 'color' => '#FFFFFF', 'bgcolor' => '#4F81BD');
            $excel->add_style('header', $header_style);
            $table_name = PbController::pluralize($_POST['tb_name']);
            $record_amount = intval($_POST['record_amount']);
            if (empty($record_amount)) {
                $record_amount = 1000;
            }
            $result = $pdb->GetArray("SELECT * FROM " . $tb_prefix . $table_name . " ORDER BY id DESC LIMIT {$record_amount};");
            $xml = simplexml_to_array(simplexml_load_file(DATA_PATH . "exchange" . DS . $_POST['tb_name'] . ".xml", "SimpleXMLElement", LIBXML_NOCDATA));
            $rows = array_keys($xml['items']);
            $excel->add_row($xml['items'], 'header');
            foreach ($result as $key => $val) {
                foreach ($rows as $key1 => $val1) {
                    $cols[$val1] = htmlspecialchars($val[$val1]);
                }
                $excel->add_row($cols);
            }
            $excel->create_worksheet($_POST['tb_name']);
            $excel->download($_POST['tb_name'] . date("YmdH") . '.xls');
            break;
        default:
            break;
    }
}
if (!empty($_PB_CACHE['companytype'])) {
    setvar("sorts", implode("\r\n", $_PB_CACHE['companytype']));
}
if (!empty($items)) {
    setvar("FileItems", array_map_recursive("pb_lang_split", $items));
}
template($tpl_file);
Esempio n. 29
0
function array_map_recursive($filter, $data)
{
    $result = array();
    foreach ($data as $key => $val) {
        $result[$key] = is_array($val) ? array_map_recursive($filter, $val) : call_user_func($filter, $val);
    }
    return $result;
}
 /** Calls a SOAP function
  *
  * @param string $function_name   The name of the SOAP function to call
  * @param array  $arguments       An array of the arguments to pass to the function
  * @param array  $options         An associative array of options to pass to the client
  * @param mixed  $input_headers   An array of headers to be sent along with the SOAP request
  * @param array  &$output_headers If supplied, this array will be filled with the headers from the SOAP response
  *
  * @throws Exception|SoapFault
  *
  * @return mixed SOAP functions may return one, or multiple values
  */
 public function call($function_name, $arguments, $options = null, $input_headers = null, &$output_headers = null)
 {
     $client = $this->client;
     if (!is_array($arguments)) {
         $arguments = array($arguments);
     }
     /* @todo Lors d'un appel d'une méthode RPC le tableau $arguments contient un élement vide array( [0] => )
      * posant problème lors de l'appel d'une méthode du WSDL sans argument */
     if (isset($arguments[0]) && empty($arguments[0])) {
         $arguments = array();
     }
     if ($client->flatten && isset($arguments[0]) && !empty($arguments[0])) {
         $arguments = $arguments[0];
     }
     $output = null;
     $echange_soap = new CEchangeSOAP();
     $echange_soap->date_echange = CMbDT::dateTime();
     $echange_soap->emetteur = CAppUI::conf("mb_id");
     $echange_soap->destinataire = $client->wsdl_url;
     $echange_soap->type = $client->type_echange_soap;
     $url = parse_url($client->wsdl_url);
     $path = explode("/", $url['path']);
     $echange_soap->web_service_name = end($path);
     $echange_soap->function_name = $function_name;
     // Truncate input and output before storing
     $arguments_serialize = array_map_recursive(array('CSOAPClient', "truncate"), $arguments);
     $echange_soap->input = serialize($arguments_serialize);
     if ($client->loggable) {
         $echange_soap->store();
     }
     CApp::$chrono->stop();
     $chrono = new Chronometer();
     $chrono->start();
     try {
         $output = $client->call($function_name, $arguments, $options, $input_headers, $output_headers);
         if (!$client->loggable) {
             CApp::$chrono->start();
             return $output;
         }
     } catch (SoapFault $fault) {
         // trace
         if (CAppUI::conf("webservices trace")) {
             $client->getTrace($echange_soap);
         }
         $chrono->stop();
         $echange_soap->date_echange = CMbDT::dateTime();
         $echange_soap->output = $fault->faultstring;
         $echange_soap->soapfault = 1;
         $echange_soap->response_time = $chrono->total;
         $echange_soap->store();
         CApp::$chrono->start();
         throw $fault;
     }
     $chrono->stop();
     CApp::$chrono->start();
     $echange_soap->date_echange = CMbDT::dateTime();
     // trace
     if (CAppUI::conf("webservices trace")) {
         $client->getTrace($echange_soap);
     }
     // response time
     $echange_soap->response_time = $chrono->total;
     if ($echange_soap->soapfault != 1) {
         $echange_soap->output = serialize(array_map_recursive(array("CSOAPClient", "truncate"), $output));
     }
     $echange_soap->store();
     return $output;
 }