/** * Get merged cookie, get and post * * @param mixed $key * @param boolean $xss * @param boolean $cookie * @return mixed */ public static function input($key = '', $xss = true, $cookie = false) { // cookie first, get and post after if ($cookie) { $result = array_merge2($_COOKIE, $_GET, $_POST); } else { $result = array_merge2($_GET, $_POST); } // protection against XSS attacks is on by default if ($xss) { $result = self::strip_tags($result); } // we need to get rid of session id from the result if (!$cookie) { unset($result[session_name()]); } // if we are debugging if (debug::$debug) { debug::$data['input'][] = $result; } // returning result if ($key) { return array_key_get($result, $key); } else { return $result; } }
/** * Load configuration files * * @param type $ini_folder * @return type */ public static function load($ini_folder) { $settings = ['environment' => 'production']; // environment ini file first $file = $ini_folder . 'environment.ini'; if (file_exists($file)) { $ini_data = self::ini($file); $settings = array_merge2($settings, $ini_data); } // application.ini file second $file = $ini_folder . 'application.ini'; if (file_exists($file)) { $ini_data = self::ini($file, $settings['environment']); $settings = array_merge2($settings, $ini_data); } return $settings; }
/** * Initialize db connections, cache and session */ public static function init($options = []) { // initialize mbstring mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); // get flags & dependencies $flags = application::get('flag'); $backend = application::get('numbers.backend', ['backend_exists' => true]); // processing wildcard first $wildcard = application::get('wildcard'); $wildcard_keys = null; if (!empty($wildcard['enabled']) && !empty($wildcard['model'])) { $wildcard_keys = call_user_func($wildcard['model']); application::set(['wildcard', 'keys'], $wildcard_keys); } // initialize cryptography $crypt = application::get('crypt'); if (!empty($crypt) && $backend) { foreach ($crypt as $crypt_link => $crypt_settings) { if (!empty($crypt_settings['submodule']) && !empty($crypt_settings['autoconnect'])) { $crypt_object = new crypt($crypt_link, $crypt_settings['submodule'], $crypt_settings); } } } // create database connections $db = application::get('db'); if (!empty($db) && $backend) { foreach ($db as $db_link => $db_settings) { if (empty($db_settings['autoconnect']) || empty($db_settings['servers']) || empty($db_settings['submodule'])) { continue; } $connected = false; foreach ($db_settings['servers'] as $server_key => $server_values) { $db_object = new db($db_link, $db_settings['submodule']); // wildcards replaces if (isset($wildcard_keys[$db_link])) { $server_values['dbname'] = $wildcard_keys[$db_link]['dbname']; } // connecting $server_values = array_merge2($server_values, $db_settings); $db_status = $db_object->connect($server_values); if ($db_status['success'] && $db_status['status']) { $connected = true; break; } } // checking if not connected if (!$connected) { throw new Exception('Unable to open database connection!'); } } } // initialize cache $cache = application::get('cache'); if (!empty($cache) && $backend) { foreach ($cache as $cache_link => $cache_settings) { if (empty($cache_settings['submodule']) || empty($cache_settings['autoconnect'])) { continue; } $connected = false; foreach ($cache_settings['servers'] as $cache_server) { $cache_object = new cache($cache_link, $cache_settings['submodule']); $cache_status = $cache_object->connect($cache_server); if ($cache_status['success']) { $connected = true; break; } } // checking if not connected if (!$connected) { throw new Exception('Unable to open cache connection!'); } } } // if we are from command line we exit here if (!empty($options['__run_only_bootstrap'])) { return; } // initialize session $session = application::get('flag.global.session'); if (!empty($session['start']) && $backend && !application::get('flag.global.__skip_session')) { session::start(isset($session['options']) ? $session['options'] : []); } // we need to get overrides from session and put them back to flag array $flags = array_merge_hard($flags, session::get('numbers.flag')); application::set('flag', $flags); // initialize i18n if ($backend) { $temp_result = i18n::init(); if (!$temp_result['success']) { throw new Exception('Could not initialize i18n.'); } } // format format::init(); // including libraries that we need to auto include if (!empty($flags['global']['library'])) { foreach ($flags['global']['library'] as $k => $v) { // we need to skip certain keys if ($k == 'submodule' || $k == 'options') { continue; } // we only include if autoconnect is on if (!empty($v['autoconnect'])) { factory::submodule('flag.global.library.' . $k . '.submodule')->add(); } } } // check if we need to include system files from frontend if (application::get('dep.submodule.numbers.frontend.system')) { numbers_frontend_system_model_base::start(); } }
function smarty_function_input($params, &$smarty) { if (isset($params['attributes'])) { $params = $params['attributes']; } $params['class'] = $params['class'] ? $params['class'] . ' _x_ipt' : '_x_ipt' . ' ' . $params['type']; $params['vtype'] = isset($params['vtype']) ? $params['vtype'] : $params['type']; if (isset($params['default']) && !$params['value']) { $params['value'] = $params['default']; } switch ($params['type']) { case 'text': return buildTag($params, 'input autocomplete="off"'); break; case 'password': return buildTag($params, 'input autocomplete="off"'); break; case 'search': return buildTag($params, 'input autocomplete="off"'); break; case 'date': if (!$params['id']) { $domid = 'mce_' . substr(md5(rand(0, time())), 0, 6); $params['id'] = $domid; } else { $domid = $params['id']; } $params['value'] = mydate('Y-m-d', $params['value']); $params['type'] = 'text'; return buildTag($params, 'input autocomplete="off"') . '<script>$("' . $domid . '").makeCalable();</script>'; break; case 'time': $params['value'] = mydate('Y-m-d H:i', $params['value']); return buildTag($params, 'input autocomplete="off"'); break; case 'file': if ($params['backend'] == 'public') { if (!$GLOBALS['storager']) { $system =& $GLOBALS['system']; $GLOBALS['storager'] = $system->loadModel('system/storager'); } $storager =& $GLOBALS['storager']; $url = $storager->getUrl($params['value']); $img = array('png' => 1, 'gif' => 1, 'jpg' => 1, 'jpeg' => 1); if ($img[strtolower(substr($url, strrpos($url, '.') + 1))]) { $html = '<img src="' . $url . '" />'; } else { $html = $url; } } else { $html = ''; } return buildTag($params, 'input autocomplete="off"') . $html; break; case 'bool': $params['type'] = 'checkbox'; if ($value == 'true') { $params['checked'] = 'checked'; } $params['value'] = "true"; return buildTag($params, 'input'); break; case 'combox': return buildTag($params, 'input autocomplete="off"'); break; case 'textarea': $value = $params['value']; if ($params['width']) { $params['style'] .= ';width:' . $params['width']; unset($params['width']); } if ($params['height']) { $params['style'] .= ';height:' . $params['height']; unset($params['height']); } unset($params['value']); return buildTag($params, 'textarea', false) . htmlspecialchars($value) . '</textarea>'; break; case 'checkbox': $params['selected'] = $params['value']; smarty_core_load_plugins(array('plugins' => array(array('function', 'html_checkboxes', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return smarty_function_html_checkboxes($params, $smarty); break; case 'radio': $params['selected'] = $params['value']; smarty_core_load_plugins(array('plugins' => array(array('function', 'html_radios', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return smarty_function_html_radios($params, $smarty); break; case 'select': if (isset($params['rows'])) { foreach ($params['rows'] as $item) { $params['options'][$item[$params['valueColumn']]] = $item[$params['labelColumn']]; } } if ($params['nulloption']) { $params['options'] = array_merge2(array('' => __('- 请选择 -')), $params['options']); } $params['selected'] = $params['value']; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; break; case 'color': $params['selected'] = $params['value'] == '' ? '#000000' : $params['value']; $params['style'] = 'width:50px;background-color:' . $params['selected']; $params['onChange'] = "this.style.backgroundColor=this.options[this.selectedIndex].value;"; $t = buildTag($params, 'select', false); unset($params['name']); $params['color'] = array('#00ffff' => ' ', '#000000' => ' ', '#ff00ff' => ' ', '#800000' => ' ', '#008000' => ' ', '#00ff00' => ' ', '#800000' => ' ', '#000080' => ' ', '#808000' => ' ', '#800080' => ' ', '#ff0000' => ' ', '#c0c0c0' => ' ', '#008080' => ' ', '#ffffff' => ' ', '#ffff00' => ' ', '#0000ff' => ' '); return $t . _build_color_options($params) . '</select>'; break; case 'region': $SYSTEM =& $GLOBALS['system']; $loc =& $SYSTEM->loadModel('system/local'); if ($params['required'] == 'true') { $req = ' vtype="area"'; } else { $req = ' vtype=' . $params['vtype']; } if (!$params['value']) { $package = $params['package'] ? $params['package'] : $SYSTEM->getConf('system.location'); return '<span package="' . $package . '" class="span _x_ipt"' . $req . '><input ' . ($params['id'] ? ' id="' . $params['id'] . '" ' : '') . ' type="hidden" name="' . $params['name'] . '" />' . $loc->get_area_select(null, $params) . '</span>'; } else { list($package, $regions, $region_id) = explode(':', $params['value']); if (!is_numeric($region_id)) { if (!$package) { $package = $SYSTEM->getConf('system.location'); } return '<span package="' . $package . '" class="span _x_ipt"' . $req . '><input type="hidden" name="' . $params['name'] . '" />' . $loc->get_area_select(null, $params) . '</span>'; } else { $arr_regions = array(); $ret = ''; while ($region_id && ($region = $loc->instance($region_id, 'region_id,local_name,p_region_id'))) { array_unshift($arr_regions, $region); if ($region_id = $region['p_region_id']) { $notice = "-"; $data = $loc->get_area_select($region['p_region_id'], $params, $region['region_id']); if (!$data) { $notice = ""; } $ret = '<span class="x-region-child"> ' . $notice . ' ' . $loc->get_area_select($region['p_region_id'], $params, $region['region_id']) . $ret . '</span>'; } else { $ret = '<span package="' . $package . '" class="span _x_ipt"' . $req . '><input type="hidden" value="' . $params['value'] . '" name="' . $params['name'] . '" />' . $loc->get_area_select(null, $params, $region['region_id']) . $ret . '</span>'; } } if (!$ret) { $ret = '<span package="' . $package . '" class="span _x_ipt"' . $req . '><input type="hidden" value="" name="' . $params['name'] . '" />' . $loc->get_area_select(null, $params, $region['region_id']) . '</span>'; } return $ret; } } break; case 'fontset': $params['options'] = array('0' => '', '1' => '粗体', '2' => '斜体', '3' => '中线'); $params['selected'] = $params['value']; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; //return '<select id="'.$params['name'].'" name="'.$params['name'].'">'._comset_set($params['value'],$params['font']).'</select>'; break; case 'arrow': $params['selected'] = $params['value']; $params['options'] = array('arrow_1.gif' => '箭头1', 'arrow_2.gif' => '箭头2', 'arrow_3.gif' => '箭头3', 'arrow_4.gif' => '箭头4', 'arrow_5.gif' => '箭头5', 6 => '自定义'); //return '<select id="'.$params['name'].'" name="'.$params['name'].'" onClick="choosePic()">'._comset_set($params['value'],$params['arrow']).'</select>'; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; break; case 'com_select': $params['from'] = intval($params['from']); $params['options'] = array(); $params['to'] = intval($params['to']); for ($i = $params['from']; $i <= $params['to']; $i++) { array_push($params['options'], $i); } $params['selected'] = $params['value']; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; break; default: return buildTag($params, 'input autocomplete="off"'); } }
function smarty_function_input($params, &$smarty) { if (isset($params['attributes'])) { $params = $params['attributes']; } $params['style'] .= ''; if (isset($params['width'])) { $params['style'] = 'width:' . $params['width'] . 'px;' . $params['style']; unset($params['width']); } $params['class'] = $params['class'] ? $params['class'] . ' _x_ipt' : '_x_ipt' . ' ' . $params['type']; $params['vtype'] = isset($params['vtype']) ? $params['vtype'] : $params['type']; if (isset($smarty->_tpl_vars['disabledElement']) && $smarty->_tpl_vars['disabledElement']) { $params['disabled'] = 'disabled'; } if (substr($params['type'], 0, 4) == 'enum') { $params['type'] = $params['inputType'] ? $params['inputType'] : 'select'; $params['vtype'] = $params['inputType'] ? $params['inputType'] : 'select'; } elseif (substr($params['type'], 0, 7) != 'object:') { $params['type'] = $params['inputType'] ? $params['inputType'] : $params['type']; $params['vtype'] = $params['inputType'] ? $params['inputType'] : $params['type']; } if (substr($params['type'], 0, 7) == 'object:') { include 'objects.php'; $aTmp = explode(':', $params['type']); $params['filter'] = $params['options']; //传递filter参数 added by Ever 20080701 if (!$smarty->_loaded_object_module[$aTmp[1]][$aTmp[2]]['data']) { $mod =& $smarty->system->loadModel($objects[$aTmp[1]]); if ($aTmp[2]) { $params['data'] = $mod->{$aTmp}[2](); $smarty->_loaded_object_module[$aTmp[1]][$aTmp[2]]['data'] = $params['data']; } } else { $mod =& $smarty->system->loadModel($objects[$aTmp[1]]); $params['data'] = $smarty->_loaded_object_module[$aTmp[1]][$aTmp[2]]['data']; } return $mod->inputElement($params); } else { switch ($params['type']) { case 'text': return buildTag($params, 'input autocomplete="off"'); break; case 'password': return buildTag($params, 'input autocomplete="off"'); break; case 'search': return buildTag($params, 'input autocomplete="off"'); break; case 'date': if (!$params['id']) { $domid = 'mce_' . substr(md5(rand(0, time())), 0, 6); $params['id'] = $domid; } else { $domid = $params['id']; } if (is_int($params['value'])) { $params['value'] = mydate('Y-m-d', $params['value']); } // $params['value'] = mydate('Y-m-d',$params['value']); $params['type'] = 'text'; return buildTag($params, 'input autocomplete="off"') . '<script>$("' . $domid . '").makeCalable();</script>'; break; case 'color': if (!$params['id']) { $domid = 'colorPicker_' . substr(md5(rand(0, time())), 0, 6); $params['id'] = $domid; } else { $domid = $params['id']; } if ($params['value'] == '') { $params['value'] = 'default'; // $params['style']='background-color:#ffffff;cursor:pointer'; } else { // $params['style']='background-color:'.$params['value'].';cursor:pointer'; } // $params['readonly']='false'; return buildTag($params, 'input autocomplete="off"') . ' <input type="button" id="c_' . $domid . '" style="width:22px;height:22px;background-color:' . $params['value'] . ';border:0px #ccc solid;cursor:pointer"/><script> new GoogColorPicker("c_' . $domid . '",{ onSelect:function(hex,rgb,el){ $("' . $domid . '").set("value",hex); el.setStyle("background-color",hex); } })</script>'; break; case 'time': if (is_int($params['value'])) { $params['value'] = mydate('Y-m-d H:i', $params['value']); } return buildTag($params, 'input autocomplete="off"'); break; case 'file': if ($params['backend'] == 'public') { if (!$GLOBALS['storager']) { $system =& $GLOBALS['system']; $GLOBALS['storager'] = $system->loadModel('system/storager'); } $storager =& $GLOBALS['storager']; $url = $storager->getUrl($params['value']); $img = array('png' => 1, 'gif' => 1, 'jpg' => 1, 'jpeg' => 1); if ($img[strtolower(substr($url, strrpos($url, '.') + 1))]) { $html = '<img src="' . $url . '?' . time() . '" style="float:none" />'; } else { $html = $url; } } else { $html = ''; } return $html . buildTag($params, 'input autocomplete="off"'); break; case 'bool': $params['type'] = 'checkbox'; if ($params['value'] == 'true' || intval($params['value']) > 0) { $params['checked'] = 'checked'; } if ($params['value'] === '0' || $params['value'] === '1') { $params['value'] = 1; } else { $params['value'] = 'true'; } return buildTag($params, 'input'); break; case 'combox': return buildTag($params, 'input autocomplete="off"'); break; case 'html': $id = 'mce_' . substr(md5(rand(0, time())), 0, 6); $system =& $GLOBALS['system']; $editor_type = $system->getConf("system.editortype"); $editor_type == '' ? $editor_type = 'textarea' : ($editor_type = 'wysiwyg'); if ($editor_type == 'textarea' || $params['editor_type'] == 'textarea') { $smarty->_smarty_include(array('smarty_include_tpl_file' => 'editor/style_2.html', 'smarty_include_vars' => array('var' => $id, 'for' => $id))); } else { $smarty->_smarty_include(array('smarty_include_tpl_file' => 'editor/style_1.html', 'smarty_include_vars' => array('var' => $id, 'for' => $id, 'includeBase' => $params['includeBase'] ? $params['includeBase'] : true))); } $params['id'] = $id; $params['editor_type'] = $params['editor_type'] ? $params['editor_type'] : $editor_type; $smarty->_smarty_include(array('smarty_include_tpl_file' => 'editor/body.html', 'smarty_include_vars' => $params)); break; case 'textarea': $value = $params['value']; if ($params['width']) { $params['style'] .= ';width:' . $params['width']; unset($params['width']); } if ($params['height']) { $params['style'] .= ';height:' . $params['height']; unset($params['height']); } unset($params['value']); return buildTag($params, 'textarea', false) . htmlspecialchars($value) . '</textarea>'; break; case 'checkbox': $params['selected'] = $params['value']; smarty_core_load_plugins(array('plugins' => array(array('function', 'html_checkboxes', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return smarty_function_html_checkboxes($params, $smarty); break; case 'radio': $params['selected'] = $params['value']; unset($params['value']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_radios', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return smarty_function_html_radios($params, $smarty); break; case 'select': if (isset($params['rows'])) { foreach ($params['rows'] as $item) { $params['options'][$item[$params['valueColumn']]] = $item[$params['labelColumn']] . $out; } } if ($params['nulloption']) { $params['options'] = array_merge2(array('' => __('- 请选择 -')), $params['options']); } $params['selected'] = $params['value']; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; break; case 'fontset': $params['options'] = array('0' => '默认', '1' => '粗体', '2' => '斜体', '3' => '中线'); $params['selected'] = $params['value']; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; //return '<select id="'.$params['name'].'" name="'.$params['name'].'">'._comset_set($params['value'],$params['font']).'</select>'; break; case 'region': $SYSTEM =& $GLOBALS['system']; $loc =& $SYSTEM->loadModel('system/local'); if ($params['required'] == 'true') { $req = ' vtype="area"'; } else { $req = ' vtype=' . $params['pptype']; } if (!$params['value']) { $package = $params['package'] ? $params['package'] : $SYSTEM->getConf('system.location'); $package = $package ? $package : 'mainland'; return '<span package="' . $package . '" class="span _x_ipt"' . $req . '><input type="hidden" name="' . $params['name'] . '" />' . $loc->get_area_select(null, $params) . '</span>'; } else { list($package, $regions, $region_id) = explode(':', $params['value']); if (!is_numeric($region_id)) { if (!$package) { $package = $SYSTEM->getConf('system.location'); } return '<span package="' . $package . '" class="span _x_ipt"' . $req . '><input type="hidden" name="' . $params['name'] . '" />' . $loc->get_area_select(null, $params) . '</span>'; } else { $arr_regions = array(); $ret = ''; while ($region_id && ($region = $loc->instance($region_id, 'region_id,local_name,p_region_id'))) { array_unshift($arr_regions, $region); if ($region_id = $region['p_region_id']) { $ret = '<span class="x-region-child"> - ' . $loc->get_area_select($region['p_region_id'], $params, $region['region_id']) . $ret . '</span>'; } else { $ret = '<span package="' . $package . '" class="span _x_ipt"' . $req . '><input type="hidden" value="' . $params['value'] . '" name="' . $params['name'] . '" />' . $loc->get_area_select(null, $params, $region['region_id']) . $ret . '</span>'; } } return $ret; } } break; case 'arrow': $params['selected'] = $params['value']; $params['options'] = array('arrow_1.gif' => '箭头1', 'arrow_2.gif' => '箭头2', 'arrow_3.gif' => '箭头3', 'arrow_4.gif' => '箭头4', 'arrow_5.gif' => '箭头5', 6 => '自定义'); //return '<select id="'.$params['name'].'" name="'.$params['name'].'" onClick="choosePic()">'._comset_set($params['value'],$params['arrow']).'</select>'; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; break; case 'rank': $params['selected'] = $params['value']; $params['options'] = array('view_w_count' => '周访问次数', 'view_count' => '总访问次数', 'buy_w_count' => '周购买次数', 'buy_count' => '总购买次数', 'comments_count' => '评论次数'); //return '<select id="'.$params['name'].'" name="'.$params['name'].'" onClick="choosePic()">'._comset_set($params['value'],$params['arrow']).'</select>'; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; break; case 'com_select': $params['from'] = intval($params['from']); $params['options'] = array(); $params['to'] = intval($params['to']); for ($i = $params['from']; $i <= $params['to']; $i++) { array_push($params['options'], $i); } $params['selected'] = $params['value']; $t = buildTag($params, 'select', false); unset($params['name']); smarty_core_load_plugins(array('plugins' => array(array('function', 'html_options', $smarty->_current_file, $smarty->_current_line_no, 20, false))), $smarty); return $t . smarty_function_html_options($params, $smarty) . '</select>'; break; case 'viewIMG': return "<a style='text-decoration:none;' class='viewIMG' href='javascript:void(0);' onclick='viewIMG(\"" . $params['value'] . "\",this);this.blur();' title='点击查看图片'> </a>"; break; default: return buildTag($params, 'input autocomplete="off"'); } } }
/** * Process dependencies * * @param array $options * @return array */ public static function process_deps_all($options = []) { $result = ['success' => false, 'error' => [], 'data' => []]; do { // processing main dependency file $main_dep_filename = 'config/application.ini'; if (!file_exists($main_dep_filename)) { $result['error'][] = "Main dep. file not found!"; break; } // some array arrangements $data = system_config::ini($main_dep_filename, 'dependencies'); $data = $data['dep'] ?? []; $data['composer'] = $data['composer'] ?? []; $data['submodule'] = $data['submodule'] ?? []; $data['submodule_dirs'] = []; $data['apache'] = $data['apache'] ?? []; $data['php'] = $data['php'] ?? []; $data['model'] = $data['model'] ?? []; $data['__model_dependencies'] = []; $data['model_import'] = []; $data['override'] = $data['override'] ?? []; $data['acl'] = $data['acl'] ?? []; $data['media'] = $data['media'] ?? []; $data['model_processed'] = []; $data['unit_tests'] = []; $data['__submodule_dependencies'] = []; $dummy = []; // we have small chicken and egg problem with composer $composer_data = []; $composer_dirs = []; $composer_dirs[] = 'config/'; if (file_exists('../libraries/composer.json')) { $composer_data = json_decode(file_get_contents('../libraries/composer.json'), true); } // if we have composer or submodules from main dep file if (!empty($data['composer']) || !empty($data['submodules'])) { $composer_data['require'] = []; if (!empty($data['composer'])) { self::process_deps_array($data['composer'], $composer_data['require'], $composer_dirs, 'dummy', $dummy); } if (!empty($data['submodule'])) { self::process_deps_array($data['submodule'], $composer_data['require'], $composer_dirs, 'dummy', $dummy); } } // processing submodules $mutex = []; $__any = []; if (!empty($composer_dirs)) { for ($i = 0; $i < 3; $i++) { foreach ($composer_dirs as $k => $v) { if (isset($mutex[$k])) { continue; } else { $mutex[$k] = 1; } if (file_exists($v . 'module.ini')) { $data['submodule_dirs'][$v] = $v; $sub_data = system_config::ini($v . 'module.ini', 'dependencies'); $sub_data = isset($sub_data['dep']) ? $sub_data['dep'] : []; if (!empty($sub_data['composer'])) { self::process_deps_array($sub_data['composer'], $composer_data['require'], $composer_dirs, $k, $dummy); $data['composer'] = array_merge2($data['composer'], $sub_data['composer']); } if (!empty($sub_data['submodule'])) { self::process_deps_array($sub_data['submodule'], $composer_data['require'], $composer_dirs, $k, $data['__submodule_dependencies']); $data['submodule'] = array_merge2($data['submodule'], $sub_data['submodule']); } if (!empty($sub_data['apache'])) { $data['apache'] = array_merge2($data['apache'], $sub_data['apache']); } if (!empty($sub_data['php'])) { $data['php'] = array_merge2($data['php'], $sub_data['php']); } if (!empty($sub_data['model'])) { $data['model'] = array_merge2($data['model'], $sub_data['model']); $temp = []; array_keys_to_string($sub_data['model'], $temp); foreach ($temp as $k0 => $v0) { $data['__model_dependencies'][$k][$k0] = $k0; } } if (!empty($sub_data['override'])) { $data['override'] = array_merge2($data['override'], $sub_data['override']); } if (!empty($sub_data['acl'])) { $data['acl'] = array_merge2($data['acl'], $sub_data['acl']); } if (!empty($sub_data['media'])) { $data['media'] = array_merge2($data['media'], $sub_data['media']); } // processing unit tests if (file_exists($v . 'unit_tests')) { // we have to reload the module.ini file to get module name $sub_data_temp = system_config::ini($v . 'module.ini', 'module'); $data['unit_tests'][$sub_data_temp['module']['name']] = $v . 'unit_tests/'; } } else { $keys = explode('/', $k); $last = end($keys); if ($last == '__any') { $temp2 = []; foreach ($keys as $v2) { if ($v2 != '__any') { $temp2[] = $v2; } } $__any[$k] = $temp2; } else { if ($keys[0] == 'numbers') { $result['error'][] = " - Submodule not found in {$v}module.ini"; } } } } } } // processing any dependencies if (!empty($__any)) { foreach ($__any as $k => $v) { $temp = array_key_get($data['submodule'], $v); unset($temp['__any']); if (empty($temp)) { $result['error'][] = " - Any dependency required {$k}!"; } } } // processing composer if (!empty($composer_data['require'])) { foreach ($composer_data['require'] as $k => $v) { if (!file_exists('../libraries/vendor/' . $k)) { $result['error'][] = " - Composer library \"{$k}\" is not loaded!"; } } } // sometimes we need to make sure we have functions available $func_per_extension = ['pgsql' => 'pg_connect']; // proceccing php extensions if (!empty($data['php']['extension'])) { foreach ($data['php']['extension'] as $k => $v) { if (isset($func_per_extension[$k]) && function_exists($func_per_extension[$k]) == false || !extension_loaded($k)) { $result['error'][] = " - PHP extension \"{$k}\" is not loaded!"; } } } // processing php ini settings if (!empty($data['php']['ini'])) { foreach ($data['php']['ini'] as $k => $v) { foreach ($v as $k2 => $v2) { $temp = ini_get($k . '.' . $k2); if (ini_get($k . '.' . $k2) != $v2) { $result['error'][] = " - PHP ini setting {$k}.{$k2} is \"{$temp}\", should be {$v2}!"; } } } } // processing apache modules if (!empty($data['apache']['module'])) { if (function_exists('apache_get_modules')) { $ext_have = array_map('strtolower', apache_get_modules()); } else { $temp = `apachectl -t -D DUMP_MODULES`; $ext_have = array_map('strtolower', explode("\n", $temp)); $temp = array(); foreach ($ext_have as $k => $v) { $temp[] = trim(str_replace(array('(shared)', '(static)'), '', $v)); } $ext_have = $temp; } foreach ($data['apache']['module'] as $k => $v) { if (!in_array($k, $ext_have)) { $result['error'][] = " - Apache module \"{$k}\" is not loaded!"; } } } // processing models if (!empty($data['model'])) { array_keys_to_string($data['model'], $data['model_processed']); } // processing imports, we need to sort them in order of dependencies $imports = []; foreach ($data['model_processed'] as $k => $v) { if ($v != 'object_import') { continue; } // find submodule foreach ($data['__model_dependencies'] as $k2 => $v2) { if (!empty($v2[$k])) { $imports[$k2][$k] = $k; break; } } } // clean up unused dependencies foreach ($data['__submodule_dependencies'] as $k2 => $v2) { if (empty($imports[$k2])) { $data['__submodule_dependencies'][$k2] = []; } else { foreach ($v2 as $k3 => $v3) { if (empty($imports[$k3])) { unset($data['__submodule_dependencies'][$k2][$k3]); } } } } // we need to go though an array few times to fix dependency issues for ($i = 0; $i < 3; $i++) { foreach ($imports as $k => $v) { if (empty($data['__submodule_dependencies'][$k])) { $data['model_import'][$k] = $v; // we need to remove file from dependency foreach ($data['__submodule_dependencies'] as $k2 => $v2) { unset($data['__submodule_dependencies'][$k2][$k]); } } } } foreach ($data['model_import'] as $k => $v) { foreach ($v as $k2 => $v2) { unset($data['model_processed'][$k2]); $data['model_processed'][$k2] = 'object_import'; } } unset($data['__submodule_dependencies'], $data['__model_dependencies'], $data['model_import']); // handling overrides, cleanup directory first helper_file::rmdir('./overrides/class', ['only_contents' => true, 'skip_files' => ['.gitkeep']]); $data['override'] = array_merge_hard($data['override'], $data['acl']); if (!empty($data['override'])) { array_keys_to_string($data['override'], $data['override_processed']); $override_classes = []; $override_found = false; foreach ($data['override_processed'] as $k => $v) { if (!isset($override_classes[$v])) { $override_classes[$v] = ['object' => new object_override_blank(), 'found' => false]; } $override_class = str_replace('.', '_', $k); $override_object = new $override_class(); $vars = get_object_vars($override_object); if (!empty($vars)) { $override_classes[$v]['found'] = true; $override_found = true; object_merge_values($override_classes[$v]['object'], $vars); } } // we need to write overrides to disk if ($override_found) { foreach ($override_classes as $k => $v) { if ($v['found']) { $class_code = "<?php\n\n" . '$object_override_blank_object = ' . var_export($v['object'], true) . ';'; helper_file::write('./overrides/class/override_' . $k . '.php', $class_code); } } } } // unit tests helper_file::rmdir('./overrides/unit_tests', ['only_contents' => true, 'skip_files' => ['.gitkeep']]); // submodule tests first if (!empty($data['unit_tests'])) { $xml = ''; $xml .= '<phpunit bootstrap="../../../libraries/vendor/numbers/framework/system/managers/unit_tests.php">'; $xml .= '<testsuites>'; foreach ($data['unit_tests'] as $k => $v) { $xml .= '<testsuite name="' . $k . '">'; foreach (helper_file::iterate($v, ['recursive' => true, 'only_extensions' => ['php']]) as $v2) { $xml .= '<file>../../' . $v2 . '</file>'; } $xml .= '</testsuite>'; } $xml .= '</testsuites>'; $xml .= '</phpunit>'; helper_file::write('./overrides/unit_tests/submodules.xml', $xml); } // application test last $application_tests = helper_file::iterate('misc/unit_tests', ['recursive' => true, 'only_extensions' => ['php']]); if (!empty($application_tests)) { $xml = ''; $xml .= '<phpunit bootstrap="../../../libraries/vendor/numbers/framework/system/managers/unit_tests.php">'; $xml .= '<testsuites>'; $xml .= '<testsuite name="application/unit/tests">'; foreach ($application_tests as $v) { $xml .= '<file>../../' . $v . '</file>'; } $xml .= '</testsuite>'; $xml .= '</testsuites>'; $xml .= '</phpunit>'; helper_file::write('./overrides/unit_tests/application.xml', $xml); } // updating composer.json file if ($options['mode'] == 'commit') { helper_file::write('../libraries/composer.json', json_encode($composer_data, JSON_PRETTY_PRINT)); } // assinging variables to return to the caller $result['data'] = $data; if (empty($result['error'])) { $result['success'] = true; } } while (0); return $result; }
function array_merge2($a1, $a2) { foreach ($a2 as $k2 => $v2) { if (is_array($v2) && $v2 != array()) { $a1[$k2] = array_merge2($a1[$k2], $a2[$k2]); } else { $a1[$k2] = $a2[$k2]; } } return $a1; }
/** * Merge multiple arrays recursivly * * @param array $arr1 * @param array $arr2 * @return array */ function array_merge2($arr1, $arr2) { $arrays = func_get_args(); $merged = array(); while ($arrays) { $array = array_shift($arrays); if (!is_array($array) || !$array) { continue; } foreach ($array as $key => $value) { if (is_string($key)) { if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) { $merged[$key] = array_merge2($merged[$key], $value); } else { $merged[$key] = $value; } } else { $merged[] = $value; } } } return $merged; }
/** * Add array to JavaScript data * * @param array $data */ public static function js_data($data) { self::$js_data = array_merge2(self::$js_data, $data); }