} } } echo gettpl('sqls_done.html'); } else { $urlsite = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('install', '', dirname($_SERVER['PHP_SELF'])); echo gettpl('data.html'); } break; case 'plugins': //connect .. for check $SQL = new SSQL($dbserver, $dbuser, $dbpass, $dbname); //install built in plugins $pl_path = "includes/plugins"; include PATH . 'includes/plugins.php'; $XML = new kxml(); if (isset($_POST['datasubmit'])) { $p = $_POST['plugin_file']; if (empty($p)) { header('Location: ' . $_SERVER['PHP_SELF'] . '?step=end&' . getlang(1)); exit; } $plg = new kplugins(); //search for plugins foreach ($p as $file) { if (file_exists($pl_path . '/' . $file)) { $contents = @file_get_contents($pl_path . '/' . $file); $gtree = $XML->xml_to_array($contents); if ($gtree != false) { $plg_dsc = $gtree['kleeja']['info']['plugin_description']; if (isset($plg_dsc)) {
function add_plugin($contents) { global $dbprefix, $SQL, $lang, $config, $STYLE_PATH_ADMIN, $STYLE_PATH, $THIS_STYLE_PATH, $olang; //initiate file handler if (empty($this->f) && $this->f_method != '') { $this->f = new $this->f_method(); } //parse xml content $XML = new kxml(); $gtree = $XML->xml_to_array($contents); //sekelton of Kleeja plugin file $tree = empty($gtree['kleeja']) ? null : $gtree['kleeja']; $plg_info = empty($tree['info']) ? null : $tree['info']; $plg_install = empty($tree['install']) ? null : $tree['install']; $plg_uninstall = empty($tree['uninstall']) ? null : $tree['uninstall']; $plg_tpl = empty($tree['templates']) ? null : $tree['templates']; $plg_hooks = empty($tree['hooks']) ? null : $tree['hooks']; $plg_langs = empty($tree['langs']) ? null : $tree['langs']; $plg_updates = empty($tree['updates']) ? null : $tree['updates']; $plg_instructions = empty($tree['instructions']) ? null : $tree['instructions']; $plg_phrases = empty($tree['phrases']) ? null : $tree['phrases']; $plg_options = empty($tree['options']) ? null : $tree['options']; $plg_files = empty($tree['files']) ? null : $tree['files']; //important tags not exists if (empty($plg_info)) { big_error('Error', $lang['ERR_XML_NO_G_TAGS'] . (defined('DEV_STAGE') ? __FILE__ . ':' . __LINE__ : '')); } if (!empty($plg_info['plugin_kleeja_version']['value']) && version_compare(strtolower($plg_info['plugin_kleeja_version']['value']), strtolower(KLEEJA_VERSION), '>=') == false) { big_error('Error', $lang['PLUGIN_N_CMPT_KLJ']); } $plg_errors = array(); $plg_new = true; $plugin_name = preg_replace("/[^a-z0-9-_]/", "-", strtolower($plg_info['plugin_name']['value'])); //is this plugin exists before ! $is_query = array('SELECT' => 'plg_id, plg_name, plg_ver', 'FROM' => "{$dbprefix}plugins", 'WHERE' => 'plg_name="' . $plugin_name . '"'); $res = $SQL->build($is_query); if ($SQL->num_rows($res)) { //it's not new one ! , let's see if it same version $plg_new = false; $cur_ver = $SQL->fetch_array($res); $this->plg_id = $cur_ver['plg_id']; $cur_ver = $cur_ver['plg_ver']; $new_ver = $SQL->escape($plg_info['plugin_version']['value']); if (version_compare(strtolower($cur_ver), strtolower($new_ver), '>=')) { return 'xyz'; } else { if (!empty($plg_updates)) { if (is_array($plg_updates['update'])) { if (array_key_exists("attributes", $plg_updates['update'])) { $plg_updates['update'] = array($plg_updates['update']); } } foreach ($plg_updates['update'] as $up) { if (version_compare(strtolower($cur_ver), strtolower($up['attributes']['to']), '<')) { eval($up['value']); } } } } } $there_is_intruct = false; if (isset($plg_instructions)) { if (is_array($plg_instructions['instruction']) && array_key_exists("attributes", $plg_instructions['instruction'])) { $plg_instructions['instruction'] = array($plg_instructions['instruction']); } $instarr = array(); foreach ($plg_instructions['instruction'] as $in) { if (empty($in['attributes']['lang']) || !isset($in['attributes']['lang'])) { big_error('Error', $lang['ERR_XML_NO_G_TAGS'] . (defined('DEV_STAGE') ? __FILE__ . ':' . __LINE__ : '')); } $instarr[$in['attributes']['lang']] = $in['value']; } $there_is_intruct = isset($instarr) && !empty($instarr) ? true : false; } $there_is_files = false; if (isset($plg_files)) { if (is_array($plg_files['file']) && array_key_exists("attributes", $plg_files['file'])) { $plg_files['file'] = array($plg_files['file']); } $newfiles = array(); foreach ($plg_files['file'] as $in) { if (empty($in['attributes']['path']) || !isset($in['attributes']['path'])) { big_error('Error', $lang['ERR_XML_NO_G_TAGS'] . (defined('DEV_STAGE') ? __FILE__ . ':' . __LINE__ : '')); } $newfiles[$in['attributes']['path']] = $in['value']; } $there_is_files = isset($newfiles) && !empty($newfiles) ? true : false; } if (isset($plg_info['plugin_description'])) { if (is_array($plg_info['plugin_description']['description']) && array_key_exists("attributes", $plg_info['plugin_description']['description'])) { $plg_info['plugin_description']['description'] = array($plg_info['plugin_description']['description']); } $p_desc = array(); foreach ($plg_info['plugin_description']['description'] as $in) { if (empty($in['attributes']['lang']) || !isset($in['attributes']['lang'])) { big_error('Error', $lang['ERR_XML_NO_G_TAGS'] . (defined('DEV_STAGE') ? __FILE__ . ':' . __LINE__ : '')); } $p_desc[$in['attributes']['lang']] = $in['value']; } } //store important tags (for now only "install" and "templates" tags) $store = ''; //storing unreached elements if (isset($plg_install) && trim($plg_install['value']) != '') { $store .= '<install><![CDATA[' . $plg_install['value'] . ']]></install>' . "\n\n"; } if (isset($plg_updates)) { $updates = explode("<updates>", $contents); $updates = explode("</updates>", $updates[1]); $store .= '<updates>' . $updates[0] . '</updates>' . "\n\n"; } if (isset($plg_tpl)) { $templates = explode("<templates>", $contents); $templates = explode("</templates>", $templates[1]); $store .= '<templates>' . $templates[0] . '</templates>' . "\n\n"; } //eval install code if (isset($plg_install) && trim($plg_install['value']) != '' && $plg_new) { eval($plg_install['value']); } //if there is an icon with the plugin $plugin_icon = false; if (!empty($plg_info['plugin_icon']['value'])) { $plugin_icon = $SQL->escape($plg_info['plugin_version']['value']); } //if the plugin was new if ($plg_new) { //insert in plugin table $insert_query = array('INSERT' => 'plg_name, plg_ver, plg_author, plg_dsc, plg_icon, plg_uninstall, plg_instructions, plg_store, plg_files', 'INTO' => "{$dbprefix}plugins", 'VALUES' => "'" . $SQL->escape($plugin_name) . "','" . $SQL->escape($plg_info['plugin_version']['value']) . "','" . $SQL->escape($plg_info['plugin_author']['value']) . "','" . $SQL->escape(kleeja_base64_encode(serialize($p_desc))) . "','" . ($plugin_icon ? $plugin_icon . "','" : '') . $SQL->real_escape($plg_uninstall['value']) . "','" . ($there_is_intruct ? $SQL->escape(kleeja_base64_encode(serialize($instarr))) : '') . "','" . $SQL->real_escape($store) . "','" . ($there_is_files ? $SQL->escape(kleeja_base64_encode(serialize(array_keys($newfiles)))) : '') . "'"); $SQL->build($insert_query); $this->plg_id = $SQL->insert_id(); } else { //update language delete_olang('', '', $this->plg_id); $update_query = array('UPDATE' => "{$dbprefix}plugins", 'SET' => "plg_ver='" . $new_ver . "', plg_author='" . $SQL->escape($plg_info['plugin_author']['value']) . "', plg_dsc='" . $SQL->escape($plg_info['plugin_description']['value']) . "', plg_uninstall='" . $SQL->real_escape($plg_uninstall['value']) . ($plugin_icon ? "', plg_icon='" . $plugin_icon : '') . "', plg_instructions='" . ($there_is_intruct ? $SQL->escape(kleeja_base64_encode(serialize($instarr))) : '') . "', plg_files='" . ($there_is_files ? $SQL->escape(kleeja_base64_encode(serialize(array_keys($newfiles)))) : '') . "', plg_store='" . $SQL->escape($store) . "'", 'WHERE' => "plg_id=" . $this->plg_id); $SQL->build($update_query); } if (isset($plg_phrases)) { if (is_array($plg_phrases['lang']) && array_key_exists("attributes", $plg_phrases['lang'])) { $plg_phrases['lang'] = array($plg_phrases['lang']); } $phrases = array(); foreach ($plg_phrases['lang'] as $in) { if (empty($in['attributes']['name']) || !isset($in['attributes']['name'])) { big_error('Error', $lang['ERR_XML_NO_G_TAGS']); } //first we create a new array that can carry language phrases $phrases[$in['attributes']['name']] = array(); if (is_array($in['phrase']) && array_key_exists("attributes", $in['phrase'])) { $in['phrase'] = array($in['phrase']); } //get phrases value foreach ($in['phrase'] as $phrase) { $phrases[$in['attributes']['name']][$phrase['attributes']['name']] = $phrase['value']; } //finally we add it to the database add_olang($phrases[$in['attributes']['name']], $in['attributes']['name'], $this->plg_id); } } if (isset($plg_options)) { if (is_array($plg_options['option']) && array_key_exists("attributes", $plg_options['option'])) { $plg_options['option'] = array($plg_options['option']); } foreach ($plg_options['option'] as $in) { add_config($in['attributes']['name'], $in['attributes']['value'], $in['attributes']['order'], $in['value'], $in['attributes']['menu'], $this->plg_id); } //delete_cache('data_config'); } //add new files if ($there_is_files) { foreach ($newfiles as $path => $content) { $this->f->_write($this->_fixpath_newfile($path), kleeja_base64_decode($content)); } unset($newfiles); } //cache important instruction $cached_instructions = array(); //some actions with tpls if (isset($plg_tpl)) { //edit template if (isset($plg_tpl['edit'])) { include_once "s_strings.php"; $finder = new sa_srch(); if (is_array($plg_tpl['edit']['template']) && array_key_exists("attributes", $plg_tpl['edit']['template'])) { $plg_tpl['edit']['template'] = array($plg_tpl['edit']['template']); } foreach ($plg_tpl['edit']['template'] as $temp) { $template_name = $SQL->real_escape($temp['attributes']['name']); if (isset($temp['find']['value']) && isset($temp['findend']['value'])) { $finder->find_word = array(1 => $temp['find']['value'], 2 => $temp['findend']['value']); } else { $finder->find_word = $temp['find']['value']; } $finder->another_word = $temp['action']['value']; switch ($temp['action']['attributes']['type']) { case 'add_after': $action_type = 3; break; case 'add_after_same_line': $action_type = 4; break; case 'add_before': $action_type = 5; break; case 'add_before_same_line': $action_type = 6; break; case 'replace_with': $action_type = 1; break; } $style_path = substr($template_name, 0, 6) == 'admin_' ? $STYLE_PATH_ADMIN : $THIS_STYLE_PATH; //if template not found and default style is there and not admin tpl $template_path = $style_path . $template_name . '.html'; if (!file_exists($template_path)) { if (trim($config['style_depend_on']) != '') { $depend_on = $config['style_depend_on']; $template_path_alternative = str_replace('/' . $config['style'] . '/', '/' . trim($depend_on) . '/', $template_path); if (file_exists($template_path_alternative)) { $template_path = $template_path_alternative; } } else { if ($config['style'] != 'default' && !$is_admin_template) { $template_path_alternative = str_replace('/' . $config['style'] . '/', '/default/', $template_path); if (file_exists($template_path_alternative)) { $template_path = $template_path_alternative; } } } } $d_contents = file_exists($template_path) ? file_get_contents($template_path) : ''; $finder->text = trim($d_contents); $finder->do_search($action_type); if ($d_contents != '' && $finder->text != $d_contents) { //update $this->f->_write($style_path . $template_name . '.html', $finder->text); //delete cache .. delete_cache('tpl_' . $template_name); } else { $cached_instructions[$template_name] = array('action' => $temp['action']['attributes']['type'], 'find' => $temp['find']['value'], 'action_text' => $temp['action']['value']); } } } #end edit //new templates if (isset($plg_tpl['new'])) { if (is_array($plg_tpl['new']['template'])) { if (array_key_exists("attributes", $plg_tpl['new']['template'])) { $plg_tpl['new']['template'] = array($plg_tpl['new']['template']); } } foreach ($plg_tpl['new']['template'] as $temp) { $style_path = substr($template_name, 0, 6) == 'admin_' ? $STYLE_PATH_ADMIN : $THIS_STYLE_PATH; $template_name = $temp['attributes']['name']; $template_content = trim($temp['value']); $this->f->_write($style_path . $template_name . '.html', $template_content); /** $cached_instructions[$template_name] = array( 'action' => 'new', 'find' => '', 'action_text' => $template_content, ); **/ } } #end new } #ens tpl //hooks if (isset($plg_hooks['hook'])) { $plugin_author = strip_tags($plg_info['plugin_author']['value'], '<a><span>'); $plugin_author = $SQL->real_escape($plugin_author); //if the plugin is not new then replace the old hooks with the new hooks if (!$plg_new) { //delete old hooks ! $query_del = array('DELETE' => "{$dbprefix}hooks", 'WHERE' => "plg_id=" . $this->plg_id); $SQL->build($query_del); } //then if (is_array($plg_hooks['hook'])) { if (array_key_exists("attributes", $plg_hooks['hook'])) { $plg_hooks['hook'] = array($plg_hooks['hook']); } } foreach ($plg_hooks['hook'] as $hk) { $hook_for = $SQL->real_escape($hk['attributes']['name']); $hk_value = $SQL->real_escape($hk['value']); $insert_query = array('INSERT' => 'plg_id, hook_name, hook_content', 'INTO' => "{$dbprefix}hooks", 'VALUES' => "'" . $this->plg_id . "','" . $hook_for . "', '" . $hk_value . "'"); $SQL->build($insert_query); } //delete cache .. //delete_cache('data_hooks'); } //done ! if (sizeof($plg_errors) < 1) { //add cached instuctions to cache if there if (sizeof($cached_instructions) > 0) { //fix if (file_exists(PATH . 'cache/styles_cached.php')) { $cached_content = file_get_contents(PATH . 'cache/styles_cached.php'); $cached_content = kleeja_base64_decode($cached_content); $cached_content = unserialize($cached_content); $cached_instructions += $cached_content; } $filename = @fopen(PATH . 'cache/styles_cached.php', 'w'); fwrite($filename, kleeja_base64_encode(serialize($cached_instructions))); fclose($filename); } if ($this->f_method === 'zfile') { if ($this->f->check()) { $this->zipped_files = $this->f->push($plugin_name); return $there_is_intruct ? 'zipped/inst' : 'zipped'; } } return $plg_new ? $there_is_intruct ? 'inst' : 'done' : 'upd'; } else { return $plg_errors; } return false; }