From 2cdae5662c96e0bba0e9c524cc3c7038722e34e6 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Sat, 5 Sep 2009 23:02:23 +0000 Subject: [PATCH] install packaging now working --- e107_admin/db.php | 131 ++++++++++++++++++------------ e107_admin/includes/infopanel.php | 8 +- e107_handlers/mysql_class.php | 12 +-- e107_handlers/xml_class.php | 59 +++++++++++++- 4 files changed, 148 insertions(+), 62 deletions(-) diff --git a/e107_admin/db.php b/e107_admin/db.php index 43fe73edd..abe93d002 100644 --- a/e107_admin/db.php +++ b/e107_admin/db.php @@ -9,13 +9,15 @@ * Administration - Database Utilities * * $Source: /cvs_backup/e107_0.8/e107_admin/db.php,v $ - * $Revision: 1.28 $ - * $Date: 2009-09-04 14:35:00 $ + * $Revision: 1.29 $ + * $Date: 2009-09-05 23:02:23 $ * $Author: e107coders $ * */ require_once ("../class2.php"); +$theme = e107::getPref('sitetheme'); +define("EXPORT_PATH","{e_THEME}".$theme."/install/"); if(!getperms('0')) { @@ -68,14 +70,18 @@ if(isset($_POST['verify_sql']) || varset($_GET['mode'])=='verify_sql') if(isset($_POST['exportXmlFile'])) { - exportXmlFile($_POST['xml_prefs'],$_POST['xml_tables'],TRUE); - exit(); + if(exportXmlFile($_POST['xml_prefs'],$_POST['xml_tables'])) + { + $emessage = eMessage::getInstance(); + $emessage->add(LAN_SUCCESS, E_MESSAGE_SUCCESS); + } + } require_once ("auth.php"); require_once (e_HANDLER."form_handler.php"); $frm = new e_form(); -$emessage = &eMessage::getInstance(); //nothing wrong with doing it twice + /* No longer needed after XML feature added. @@ -335,11 +341,11 @@ class system_tools */ private function exportXmlForm() { - + $emessage = eMessage::getInstance(); $frm = e107::getSingleton('e_form'); //TODO LANs - $text = "
+ $text = "
Export Options @@ -359,21 +365,23 @@ class system_tools "; - $pref_types = e107::getConfig()->aliases; - $exclusions = array('core_old','core_backup'); + $pref_types = e107::getConfig()->aliases; + unset($pref_types['core_old'],$pref_types['core_backup']); + // $exclusions = array('core_old'=>1,'core_backup'=>1); + // $filteredprefs = array_diff($pref_types,$exclusions); foreach($pref_types as $key=>$description) { - if(!in_array($key,$exclusions)) - { - $text .= " + $checked = ($_POST['xml_prefs'][$key] == $key) ? 1: 0; + + $text .= ""; - } + } $text .= "
- ".$frm->checkbox("xml_prefs[".$key."]", $key)." + ".$frm->checkbox("xml_prefs[".$key."]", $key, $checked)." ".LAN_PREFS.": ".$key."  
@@ -396,10 +404,11 @@ class system_tools $tables = table_list(); foreach($tables as $name=>$count) - { + { + $checked = ($_POST['xml_tables'][$name] == $name) ? 1: 0; $text .= " - ".$frm->checkbox("xml_tables[".$name."]", $name)." Table Data: ".$name." + ".$frm->checkbox("xml_tables[".$name."]", $name, $checked)." Table Data: ".$name." $count "; @@ -423,9 +432,10 @@ class system_tools - - ".$frm->checkbox("package_images",'package_images')." Convert Image-paths and package images. - Destination Path: (not functional) + "; + $checked = (vartrue($_POST['package_images'])) ? 1: 0; + $text .= $frm->checkbox("package_images",'package_images', $checked)." Convert paths and package images and xml into: ".e107::getParser()->replaceConstants(EXPORT_PATH)." + @@ -438,7 +448,7 @@ class system_tools "; - e107::getRender()->tablerender("Export Options", $text); + e107::getRender()->tablerender("Export Options",$emessage->render(). $text); } @@ -703,15 +713,47 @@ function db_adminmenu() function exportXmlFile($prefs,$tables,$debug=FALSE) { $xml = e107::getSingleton('xmlClass'); + $tp = e107::getParser(); + $emessage = eMessage::getInstance(); - if(vartrue($_POST['package_images']) && vartrue($_POST['package_path'])) + if(vartrue($_POST['package_images'])) { - // TODO Conversion of Image paths - in xml-class and e_parse_class? - // $xml->convertImagePaths = TRUE; - // $xml->destinationPath = $_POST['package_path']; + + $xml->convertFilePaths = TRUE; + $xml->filePathDestination = EXPORT_PATH; + + $desinationFolder = $tp->replaceConstants($xml->filePathDestination); + + if(!is_writable($desinationFolder)) + { + + $emessage->add($desinationFolder."is not writable", E_MESSAGE_ERROR); + return ; + } } - $xml->e107Export($prefs,$tables,FALSE); + //TODO LANs + if($xml->e107Export($prefs,$tables,$debug)) + { + $emessage->add("Created: ".$desinationFolder."install.xml", E_MESSAGE_SUCCESS); + if(varset($xml->fileConvertLog)) + { + foreach($xml->fileConvertLog as $oldfile) + { + $file = basename($oldfile); + $newfile = $desinationFolder.$file; + if(copy($oldfile,$newfile)) + { + $emessage->add("Copied: ".$newfile, E_MESSAGE_SUCCESS); + } + else + { + $emessage->add("Couldn't copy: ".$newfile, E_MESSAGE_ERROR); + } + } + } + } + } @@ -721,7 +763,6 @@ function table_list() // grab default language lists. //TODO - a similar function is in db_verify.php. Should probably all be moved to mysql_class.php. - global $mySQLdefaultdb; $exclude = array(); $exclude[] = "core"; $exclude[] = "rbinary"; @@ -731,36 +772,26 @@ function table_list() $exclude[] = "upload"; $exclude[] = "user_extended_country"; $exclude[] = "plugin"; + + $coreTables = e107::getDb()->db_TableList('nolan'); - $tables = mysql_list_tables($mySQLdefaultdb); - while (list($temp) = mysql_fetch_array($tables)) - { - - e107::getDB()->db_Rows(); - $t = mysql_query("SELECT * FROM ".$temp); - $e107tab = str_replace(MPREFIX, "", $temp); - - $count = mysql_num_rows($t); - if($count && (strpos($temp,$prefix)!==TRUE) && !in_array($e107tab,$exclude)) + $tables = array_diff($coreTables,$exclude); + + foreach($tables as $e107tab) + { + $count = e107::getDb()->db_Select_gen("SELECT * FROM #".$e107tab); + + if($count) { - $tabs[$e107tab] = mysql_num_rows($t); - } - $prefix = MPREFIX."lan_"; - $match = array(); - // if(preg_match('/^'.$prefix.'(.*)/', $temp, $match)) - { -// $e107tab = str_replace(MPREFIX, "", $temp); -// $pos = strrpos($match[1],"_")+1; -// $core = substr(str_replace("lan_","",$e107tab),$pos); - // if (str_replace($exclude, "", $e107tab)) - // { - // $tabs[$core] = $e107tab; - // } - } + $tabs[$e107tab] = $count; // mysql_num_rows($t); + } } return $tabs; } + + + /* Still needed? function backup_core() diff --git a/e107_admin/includes/infopanel.php b/e107_admin/includes/infopanel.php index 02fbf63fa..86fc628c0 100644 --- a/e107_admin/includes/infopanel.php +++ b/e107_admin/includes/infopanel.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/includes/infopanel.php,v $ - | $Revision: 1.9 $ - | $Date: 2009-09-04 14:35:01 $ + | $Revision: 1.10 $ + | $Date: 2009-09-05 23:02:23 $ | $Author: e107coders $ +----------------------------------------------------------------------------+ */ @@ -250,11 +250,13 @@ function render_infopanel_menu_options() $frm = e107::getSingleton('e_form'); $text = ""; $menu_qry = 'SELECT * FROM #menus WHERE menu_id!= 0 GROUP BY menu_name ORDER BY menu_name'; + $settings = varset($user_pref['core-infopanel-menus'],array()); + if (e107::getDb()->db_Select_gen($menu_qry)) { while ($row = e107::getDb()->db_Fetch()) { - $checked = (in_array($row['menu_name'], $user_pref['core-infopanel-menus'])) ? true : false; + $checked = (in_array($row['menu_name'], $settings)) ? true : false; $text .= "
"; $text .= $frm->checkbox("e-mymenus[]", $row['menu_name'], $checked); $text .= $row['menu_name']; diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index 0e6cc374c..e89b57536 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -9,8 +9,8 @@ * mySQL Handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $ - * $Revision: 1.46 $ - * $Date: 2009-09-05 18:58:56 $ + * $Revision: 1.47 $ + * $Date: 2009-09-05 23:02:23 $ * $Author: e107coders $ */ @@ -61,7 +61,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s * MySQL Abstraction class * * @package e107 -* @version $Revision: 1.46 $ +* @version $Revision: 1.47 $ * @author $Author: e107coders $ */ class db { @@ -838,8 +838,10 @@ class db { function db_Select_gen($query, $debug = FALSE, $log_type = '', $log_remark = '') { $this->tabset = FALSE; + $query .= " "; // temp fix for failing regex below, when there is no space after the table name; + if(strpos($query,'`#') !== FALSE) - { + { $query = preg_replace_callback("/\s`#([\w]*?)`\W/", array($this, 'ml_check'), $query); } elseif(strpos($query,'#') !== FALSE) @@ -865,7 +867,7 @@ class db { } function ml_check($matches) - { + { $table = $this->db_IsLang($matches[1]); if($this->tabset == false) { diff --git a/e107_handlers/xml_class.php b/e107_handlers/xml_class.php index 127484223..a459762d4 100644 --- a/e107_handlers/xml_class.php +++ b/e107_handlers/xml_class.php @@ -9,8 +9,8 @@ * Simple XML Parser * * $Source: /cvs_backup/e107_0.8/e107_handlers/xml_class.php,v $ - * $Revision: 1.21 $ - * $Date: 2009-09-03 22:27:32 $ + * $Revision: 1.22 $ + * $Date: 2009-09-05 23:02:23 $ * $Author: e107coders $ */ @@ -27,6 +27,7 @@ if (!defined('e107_INIT')) { exit; } */ class xmlClass { + /** * Loaded XML string * @@ -65,6 +66,19 @@ class xmlClass */ public $stripComments = true; + /** + * Log of all paths replaced. + * @var + */ + public $fileConvertLog = array(); + + public $convertFilePaths = FALSE; + + public $filePathDestination = FALSE; + + public $convertFileTypes = array("jpg","gif","png","jpeg"); + + /** * Add root element to the result array * Exmple: @@ -121,6 +135,10 @@ class xmlClass */ protected $_optValueKey = '@value'; + + + + /** * Constructor - set defaults * @@ -526,9 +544,26 @@ class xmlClass return false; } + function replaceFilePaths($text) + { + $fullpath = e107::getParser()->replaceConstants($text[1]); + $this->fileConvertLog[] = $fullpath; + $file = basename($fullpath); + + return $this->filePathDestination.$file; + + } + + private function e107ExportValue($val) { + if($this->convertFilePaths) + { + $types = implode("|",$this->convertFileTypes); + $val = preg_replace_callback("#({e_.*?\.(".$types."))#i", array($this,'replaceFilePaths'), $val); + } + if(is_array($val)) { return "WriteArray($val,FALSE)."]]>"; @@ -604,17 +639,33 @@ class xmlClass if($debug==TRUE) { - echo "
".htmlentities($text)."
"; + echo "
".htmlentities($text)."
"; + return TRUE; } else { + if(!$text) + { + return FALSE; + } + + $path = e107::getParser()->replaceConstants($this->filePathDestination); + if($path) + { + file_put_contents($path."install.xml",$text,FILE_TEXT); + return true; + } + header('Content-type: application/xml', TRUE); header("Content-disposition: attachment; filename= e107Export_" . date("Y-m-d").".xml"); header("Cache-Control: max-age=30"); header("Pragma: public"); echo $text; - exit; + exit; + } + + } /**