Struggeling with relocating
Dieser Commit ist enthalten in:
Commit
89ea01c429
301 geänderte Dateien mit 59926 neuen und 0 gelöschten Zeilen
51
inc/classes/helper/File.php
Normale Datei
51
inc/classes/helper/File.php
Normale Datei
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Helper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
/**
|
||||
* File-Helper Class
|
||||
*
|
||||
* Class offers some methods for file handling
|
||||
*/
|
||||
class File
|
||||
{
|
||||
/**
|
||||
* Get CHMOD of a file
|
||||
*
|
||||
* @param string $file The file to get chmod for
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getChmod($file)
|
||||
{
|
||||
clearstatcache();
|
||||
return @substr(decoct(fileperms($file)), -3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if file or directory is writable and trys to chmod it.
|
||||
*
|
||||
* Returns if file or directory is writable after chmodding.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $chmod
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWritable($path, $chmod)
|
||||
{
|
||||
if (!is_writable($path)) {
|
||||
@chmod($path, $chmod);
|
||||
}
|
||||
return is_writable($path);
|
||||
}
|
||||
|
||||
}
|
||||
218
inc/classes/helper/Html.php
Normale Datei
218
inc/classes/helper/Html.php
Normale Datei
|
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
/**
|
||||
* HTML-Helper Class
|
||||
*
|
||||
* Class has some static methods for building HTML-output
|
||||
*/
|
||||
class Html
|
||||
{
|
||||
/**
|
||||
* Build HTML option list from array.
|
||||
*
|
||||
* @param array $arr Array $array[key]=value
|
||||
* @param string $selected Selected key
|
||||
* @param string $valuePattern Pattern to format value output
|
||||
*
|
||||
* @return string HTML option list
|
||||
*/
|
||||
public static function getOptionlist($arr, $selected, $valuePattern = false)
|
||||
{
|
||||
$r = '';
|
||||
foreach ($arr as $key => $val) {
|
||||
$r .= '<option value="' . $key . '"';
|
||||
$r .= Html::getSelected($key, $selected) . '>';
|
||||
if ($valuePattern) $r .= sprintf($valuePattern, $val);
|
||||
else $r .= $val;
|
||||
$r .= '</option>' . "\n";
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML output for attribute "checked"
|
||||
*
|
||||
* @param string $val The current value
|
||||
* @param string $checked The value for the element if it should be checked
|
||||
* @return string Html attribute "checked" or empty string
|
||||
*/
|
||||
public static function getChecked($val, $checked)
|
||||
{
|
||||
return $val == $checked ? ' checked="checked"' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML output for attribute "disable"
|
||||
*
|
||||
* @param string $val The current value
|
||||
* @param string $disabled The value for the element if disabled
|
||||
*
|
||||
* @return string Html attribute "disabled" or empty string
|
||||
*/
|
||||
public static function getDisabled($val, $disabled)
|
||||
{
|
||||
return $val == $disabled ? ' disabled="disabled"' : '';
|
||||
}
|
||||
/**
|
||||
* Get HTML output for attribute "selected"
|
||||
*
|
||||
* @param string $val The current value
|
||||
* @param string $selected The value for the element if selected
|
||||
*
|
||||
* @return string Html attribute "selected" or empty string
|
||||
*/
|
||||
public static function getSelected($val, $selected)
|
||||
{
|
||||
return $val == $selected ? ' selected="selected"' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert HTML br's to new lines.
|
||||
*
|
||||
* @param string $str The string to convert
|
||||
* @return string Converted string
|
||||
*/
|
||||
public static function br2nl($str)
|
||||
{
|
||||
$search = array('<br>', '<br />', '<br/>');
|
||||
$replace = array("\n", "\n", "\n");
|
||||
return str_replace($search, $replace, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape quotes and/or slashes and double quotes.
|
||||
*
|
||||
* Used for escaping strings in JS-alerts and config-files.
|
||||
*
|
||||
* @param string $string String to escape
|
||||
* @param boolean $escapeSlashes Escape slashes and double quotes
|
||||
*
|
||||
* @return string Escaped string
|
||||
*/
|
||||
public static function getJsQuote($string, $escapeSlashes = false)
|
||||
{
|
||||
if ($escapeSlashes) {
|
||||
$string = str_replace('/', '\/', $string);
|
||||
$string = str_replace('"', '\"', $string);
|
||||
}
|
||||
$string = str_replace("\n", '\n', $string);
|
||||
return str_replace("'", '\\\'', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace quotes with their Html entity.
|
||||
*
|
||||
* Used for outputing values in HTML attributes without breaking HTML
|
||||
*
|
||||
* @param string $string String with quotes
|
||||
*
|
||||
* @return string String with replaced quotes
|
||||
*/
|
||||
public static function replaceQuotes($string)
|
||||
{
|
||||
$string = str_replace("\n", '\n', $string);
|
||||
return str_replace('"', '"', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape special chars according to Perl syntax.
|
||||
*
|
||||
* @param string $text The string to escape
|
||||
*
|
||||
* @return string Escaped string
|
||||
*/
|
||||
public static function escapeSpecialchars($string)
|
||||
{
|
||||
$search = array('@', '$', '\\\\', '"');
|
||||
$replace = array('\@', '\$', '\\', '\"');
|
||||
return str_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove added slashes recursively.
|
||||
*
|
||||
* @param mixed $values Array or string to remove added slashes from
|
||||
*
|
||||
* @return mixed Array or String with recursively removed slashes
|
||||
*/
|
||||
public static function stripslashesDeep($values)
|
||||
{
|
||||
if (is_array($values)) {
|
||||
$values = array_map('Html::stripslashesDeep', $values);
|
||||
} else {
|
||||
$values = stripslashes($values);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove whitespaces before and after string or array.
|
||||
*
|
||||
* @param mixed $values Array or string to remove whitespaces from
|
||||
*
|
||||
* @return mixed Recursively trimmed array or string
|
||||
*/
|
||||
public static function trimDeep($values)
|
||||
{
|
||||
if (is_array($values)) {
|
||||
$values = array_map('Html::trimDeep', $values);
|
||||
} else {
|
||||
$values = trim($values);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
/**
|
||||
* Build HTML-Message-String for success messages
|
||||
*
|
||||
* @param string $text Message to print
|
||||
*
|
||||
* @return string Message surrounded by HTML-Container
|
||||
*/
|
||||
public static function getOkMsg($text)
|
||||
{
|
||||
$html= sprintf('<span class="ok">%s</span>', $text);
|
||||
$html .= '<span style="float:right">';
|
||||
$html .= '<img src="./css/msd/icons/ok.gif" title="" alt="">';
|
||||
$html .= '</span><br />';
|
||||
return $html;
|
||||
}
|
||||
/**
|
||||
* Build HTML-Message-String for error messages
|
||||
*
|
||||
* @param string $text Message to print
|
||||
*
|
||||
* @return string Message surrounded by HTML-Container
|
||||
*/
|
||||
public static function getErrorMsg($text)
|
||||
{
|
||||
$html= sprintf('<span class="error">%s</span>', $text);
|
||||
$html .= '<span style="float:right">';
|
||||
$html .= '<img src="./css/msd/icons/notok.gif" title="" alt="">';
|
||||
$html .= '</span><br />';
|
||||
return $html;
|
||||
}
|
||||
/**
|
||||
* Create IMG-Tag
|
||||
*
|
||||
* @param string $pic Filename of picture
|
||||
* @param string $title Title for the picture (will alsobe used for alt-tag)
|
||||
*
|
||||
* @return string Built img-tag
|
||||
*/
|
||||
public static function getIcon($pic, $title = '')
|
||||
{
|
||||
//TODO get value from a config class and get rid of global
|
||||
global $config;
|
||||
$img = '<img src="%s%s" alt="%s" title="%s" />';
|
||||
return sprintf($img, $config['files']['iconpath'], $pic, $title, $title);
|
||||
}
|
||||
}
|
||||
87
inc/classes/helper/Sql.php
Normale Datei
87
inc/classes/helper/Sql.php
Normale Datei
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Helper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sql-Helper Class
|
||||
*
|
||||
* Class offers some methods to wrap some common Sql-commands
|
||||
*/
|
||||
class Sql
|
||||
{
|
||||
/**
|
||||
* Optimize a table and write returned message to log file.
|
||||
*
|
||||
* Returns true on success or MySQL-Error.
|
||||
*
|
||||
* @param MsdDbFactory $dbo Database object
|
||||
* @param string $table Name of table
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function optimizeTable(MsdDbFactory $dbo, $table)
|
||||
{
|
||||
global $lang, $log;
|
||||
$res = $dbo->optimizeTable($table);
|
||||
if (false !== $res) {
|
||||
$success=array('status', 'info','warning','note');
|
||||
if (in_array($res['Msg_type'], $success)) {
|
||||
$logMsg = $lang['L_OPTIMIZE'].' `'.$dbo->dbSelected. '`.`';
|
||||
$logMsg .= $table.'`: '.$res['Msg_text'];
|
||||
$log->write(Log::PHP, $logMsg);
|
||||
return true;
|
||||
} else {
|
||||
$logMsg = sprintf($lang['L_OPTIMIZE_TABLE_ERR'], $table);
|
||||
writeToErrorLog($dbo->dbSelected, $logMsg, $res['msg_text'], 0);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$logMsg = sprintf($lang['L_OPTIMIZE_TABLE_ERR'], $table);
|
||||
writeToErrorLog($dbo->dbSelecte, $logMsg, $res['msg_text'], 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a INSERT INTO-string
|
||||
*
|
||||
* "INSERT INTO (`field1`,`field2`,..)"-Command for the given table
|
||||
* by looking up the meta-information. Table must exists.
|
||||
* Note: Only used when restoring a backup not from MySQLDumper containing
|
||||
* extended inserts.
|
||||
*
|
||||
* @param MsdDbFactory Database object
|
||||
* @param string $table Name of table to analyze
|
||||
*
|
||||
* @return string $insert The name of the table extracted from the Query
|
||||
**/
|
||||
public static function getInsertSyntax(MsdDbFactory $dbo, $table)
|
||||
{
|
||||
$insert = '';
|
||||
$columns=$dbo->getTableColumns($table);
|
||||
$fields=array_keys($columns);
|
||||
$insert = 'INSERT INTO `' . $table . '` (`';
|
||||
$insert .=implode('`,`', $fields) . '`)';
|
||||
return $insert;
|
||||
}
|
||||
/**
|
||||
* Disables keys for given table
|
||||
*
|
||||
* @param MsdDbFactory $dbo Database object
|
||||
* @param string $table Name of table
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function disableKeys(MsdDbFactory $dbo, $table)
|
||||
{
|
||||
$query = '/*!40000 ALTER TABLE `' . $table . '` DISABLE KEYS */';
|
||||
return $dbo->query($query, MsdDbFactory::SIMPLE);
|
||||
}
|
||||
}
|
||||
37
inc/classes/helper/String.php
Normale Datei
37
inc/classes/helper/String.php
Normale Datei
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
/**
|
||||
* String-Helper Class
|
||||
*
|
||||
* Class has some static methods to modify String-output
|
||||
*/
|
||||
class String
|
||||
{
|
||||
/**
|
||||
* Format the given number to better readable number
|
||||
*
|
||||
* @param float|int $number Number to format
|
||||
* @param int $precision Selected format precision
|
||||
*
|
||||
* @return string Formatted number
|
||||
*/
|
||||
public static function formatNumber($number, $precision = 0)
|
||||
{
|
||||
$formattedNumber = number_format(
|
||||
(float) $number,
|
||||
(int) $precision,
|
||||
',',
|
||||
'.'
|
||||
);
|
||||
return $formattedNumber;
|
||||
}
|
||||
}
|
||||
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren