vineri, 10 martie 2017
Sample sr_feuser_register typo3 template configuration.
From http://lists.typo3.org/pipermail/typo3-english/2006-September/030773.html
A sample good configuration of sr_feuser_register :
# ---------- front-end user registration CONSTANTS -----------
# --- folder where FE users are contained ---
plugin.tx_srfeuserregister_pi1.pid = 1826
# --- different groups: unprivilaged users ---
plugin.tx_srfeuserregister_pi1.userGroupUponRegistration = 1
# --- different groups: privilaged users ---
plugin.tx_srfeuserregister_pi1.userGroupAfterConfirmation = 2
# --- page ID of page with login box and FE registration (Login) --
plugin.tx_srfeuserregister_pi1.loginPID = 1822
# --- page ID of second page with FE registration (Second Page) --
plugin.tx_srfeuserregister_pi1.registerPID = 1825
# --- page ID of third page with FE registration (Third Page) --
plugin.tx_srfeuserregister_pi1.editPID = 1828
# --- page ID of fourth page with FE registration (Fourth Page) --
plugin.tx_srfeuserregister_pi1.confirmPID = 1829
plugin.tx_srfeuserregister_pi1.formFields = username, password, gender,
first_name,last_name, email, address, city, zip, telephone, fax, title,
company, www,module_sys_dmail_html, image, disable, comments
plugin.tx_srfeuserregister_pi1.requiredFields =
username,password,first_name,last_name,email,comments
# ---------- front-end user registration SETUP -----------
# -------------- sr_feuser_register (start) --------------
plugin.tx_srfeuserregister_pi1 {
templateFile = {$plugin.tx_srfeuserregister_pi1.file.templateFile}
wrap1.wrap = {$plugin.tx_srfeuserregister_pi1.wrap1}
wrap2.wrap = {$plugin.tx_srfeuserregister_pi1.wrap2}
wrap3.wrap = {$plugin.tx_srfeuserregister_pi1.wrap3}
color1.wrap = {$plugin.tx_srfeuserregister_pi1.color1}
color2.wrap = {$plugin.tx_srfeuserregister_pi1.color2}
color3.wrap = {$plugin.tx_srfeuserregister_pi1.color3}
icon_delete = {$plugin.tx_srfeuserregister_pi1.file.icon_delete}
pid = {$plugin.tx_srfeuserregister_pi1.pid}
registerPID = {$plugin.tx_srfeuserregister_pi1.registerPID}
editPID = {$plugin.tx_srfeuserregister_pi1.editPID}
confirmPID = {$plugin.tx_srfeuserregister_pi1.confirmPID}
confirmType = {$plugin.tx_srfeuserregister_pi1.confirmType}
loginPID = {$plugin.tx_srfeuserregister_pi1.loginPID}
defaultCODE = {$plugin.tx_srfeuserregister_pi1.defaultCODE}
formName = {$plugin.tx_srfeuserregister_pi1.formName}
onChangeCountryAttribute =
{$plugin.tx_srfeuserregister_pi1.onChangeCountryAttribute}
# you may modify here the conditions under which an attachment file
will be added to the email
addAttachment = {$plugin.tx_srfeuserregister_pi1.enableEmailAttachment}
addAttachment.cmd = setfixed
addAttachment.sFK = APPROVE
addAttachment.file = {$plugin.tx_srfeuserregister_pi1.file.attachmentFile}
create = 1
create {
preview = {$plugin.tx_srfeuserregister_pi1.enablePreviewRegister}
fields = {$plugin.tx_srfeuserregister_pi1.formFields}
required = {$plugin.tx_srfeuserregister_pi1.requiredFields}
defaultValues {
redemptionCode =
module_sys_dmail_html = 1
disable = {$plugin.tx_srfeuserregister_pi1.enableEmailConfirmation}
}
overrideValues {
# usergroup = {$plugin.tx_srfeuserregister_pi1.userGroupUponRegistration}
disable = {$plugin.tx_srfeuserregister_pi1.enableEmailConfirmation}
processed = 0
paid = 0
}
evalValues {
password = twice,
atLeast[{$plugin.tx_srfeuserregister_pi1.passwordAtLeast}],
atMost[{$plugin.tx_srfeuserregister_pi1.passwordAtMost}]
username = uniqueLocal,
atLeast[{$plugin.tx_srfeuserregister_pi1.usernameAtLeast}],
atMost[{$plugin.tx_srfeuserregister_pi1.usernameAtMost}]
usergroup =
# email = email,atMost[255],uniqueLocal
email = email,atMost[255]
name = atMost[{$plugin.tx_srfeuserregister_pi1.nameAtMost}]
first_name = atMost[50]
last_name = atMost[50]
date_of_birth = date
company = atMost[50]
city = atMost[40]
zip = atMost[20]
telephone = atMost[25]
fax = atMost[25]
image = upload
title =
address =
www = wwwURL
payment_method =
zone = pco
cc_number = creditcard,atMost[20]
cc_expiry = expiry,atMost[7]
cc_name = atMost[255],trim
cc_type = atMost[20]
ach_routing = routing,atMost[9]
ach_account = int,atMost[17]
join_agree =
referrer_uri =
starttime =
endtime =
redemptionCode = redemptionCode
tt_products =
tx_securityquestion_question = int
tx_securityquestion_answer = atMost[255],trim
}
}
setfixed = {$plugin.tx_srfeuserregister_pi1.enableEmailConfirmation}
setfixed.APPROVE {
_FIELDLIST = uid,pid,usergroup
# usergroup = {$plugin.tx_srfeuserregister_pi1.userGroupAfterConfirmation}
disable = 0
}
enableAutoLoginOnConfirmation =
{$plugin.tx_srfeuserregister_pi1.enableAutoLoginOnConfirmation}
autoLoginRedirect_url =
{$plugin.tx_srfeuserregister_pi1.autoLoginRedirect_url}
setfixed.DELETE {
_FIELDLIST = uid,pid
}
authcodeFields = {$plugin.tx_srfeuserregister_pi1.authcodeFields}
authcodeFields.codeLength = {$plugin.tx_srfeuserregister_pi1.codeLength}
invite < .create
edit < .create
edit {
preview = {$plugin.tx_srfeuserregister_pi1.enablePreviewEdit}
defaultValues {
disable = 0
module_sys_dmail_html >
}
overrideValues {
usergroup >
disable = 0
}
evalValues {
usergroup = unsetEmpty
}
}
infomail = 0
forceFileDelete = {$plugin.tx_srfeuserregister_pi1.forceFileDelete}
parseValues {
username = nospace,trim
usergroup = trim
email = lower,nospace,trim
password = trim,nospace
name = trim
first_name = trim
last_name = trim
date_of_birth = date
title = trim
company = trim
city = trim
zip =
image = files
module_sys_dmail_html = setEmptyIfAbsent
www = wwwURL
zone =
cc_number = trim
cc_expiry =
cc_name = trim
cc_type = trim
payment_method = trim
ach_routing = trim
ach_account = trim
join_agree = trim
referrer_uri = trim
starttime = trim
endtime = trim
redemptionCode =
tt_products =
tx_securityquestion_question =
tx_securityquestion_answer = trim
}
parseFromDBValues {
date_of_birth = adodb_date
}
parseToDBValues {
date_of_birth = adodb_date
}
email.from = {$plugin.tx_srfeuserregister_pi1.email}
email.fromName = {$plugin.tx_srfeuserregister_pi1.siteName}
email.admin = {$plugin.tx_srfeuserregister_pi1.email}
email.field = email
email.HTMLMail = {$plugin.tx_srfeuserregister_pi1.enableHTMLMail}
email.HTMLMailCSS = {$plugin.tx_srfeuserregister_pi1.HTMLMailCSS}
email.CREATE_SAVED =
{$plugin.tx_srfeuserregister_pi1.enableEmailOnRegister}
email.EDIT_SAVED = {$plugin.tx_srfeuserregister_pi1.enableEmailOnUpdate}
email.DELETE_SAVED = {$plugin.tx_srfeuserregister_pi1.enableEmailOnDelete}
email.SETFIXED_APPROVE =
{$plugin.tx_srfeuserregister_pi1.enableEmailOnApprove}
email.SETFIXED_DELETE =
{$plugin.tx_srfeuserregister_pi1.enableEmailOnRefuse}
notify.CREATE_SAVED =
{$plugin.tx_srfeuserregister_pi1.enableAdminNotifyOnRegister}
notify.EDIT_SAVED =
{$plugin.tx_srfeuserregister_pi1.enableAdminNotifyOnUpdate}
notify.DELETE_SAVED =
{$plugin.tx_srfeuserregister_pi1.enableAdminNotifyOnDelete}
notify.SETFIXED_CREATE =
{$plugin.tx_srfeuserregister_pi1.enableAdminNotifyConfirmation}
notify.SETFIXED_INVITE =
{$plugin.tx_srfeuserregister_pi1.enableAdminNotifyConfirmation}
notify.SETFIXED_APPROVE =
{$plugin.tx_srfeuserregister_pi1.enableAdminNotifyOnApprove}
notify.SETFIXED_DELETE =
{$plugin.tx_srfeuserregister_pi1.enableAdminNotifyOnRefuse}
ccAllowedTypes = {$plugin.tx_srfeuserregister_pi1.ccAllowedTypes}
tempuserTimelimit = {$plugin.tx_srfeuserregister_pi1.tempuserTimelimit}
timelimit = {$plugin.tx_srfeuserregister_pi1.timelimit}
enableAutoLoginTempuser =
{$plugin.tx_srfeuserregister_pi1.enableAutoLoginTempuser}
enableAutoLogin = {$plugin.tx_srfeuserregister_pi1.enableAutoLogin}
enableCreditcardSave =
{$plugin.tx_srfeuserregister_pi1.enableCreditcardSave}
userGroupUponRegistration =
{$plugin.tx_srfeuserregister_pi1.userGroupUponRegistration}
dropFields = {$plugin.tx_srfeuserregister_pi1.dropFields}
corporateGroup = 16
professionalGroup = 2
complimentaryGroup = 4
memberGroup = 1
corporateMembershipCharge = 2000
professionalMembershipCharge = 249
corporateMembershipProductID = 8
professionalMembershipProductID = 13
_CSS_DEFAULT_STYLE (
.tx-srfeuserregister-pi1 P { font-family:Verdana, sans-serif;
font-size:12px; line-height:125%; color:#35006d; margin-top:8px;
margin-bottom:0px; padding-top:0px; padding-bottom:0px;
padding-right:3px; padding-left:3px; text-indent:0px; }
.tx-srfeuserregister-pi1 A:link { background-color:transparent;
color:navy; text-decoration:none; font-weight:bold;}
.tx-srfeuserregister-pi1 A:visited { background-color:transparent;
color:navy; font-weight:bold; text-decoration:none; }
.tx-srfeuserregister-pi1 A:hover { background-color:transparent;
color:#333333; text-decoration:none; }
.tx-srfeuserregister-pi1 A:active { background-color:transparent;
color:navy; font-weight:bold; text-decoration:none; }
.tx-srfeuserregister-pi1 TD { vertical-align:top; font-family:Verdana,
sans-serif; font-size:12px; line-height:125%; color:#35006d;
margin-top:8px; margin-bottom:0px; padding-top:0px; padding-bottom:0px;
padding-right:3px; padding-left:3px; text-indent:0px;}
.tx-srfeuserregister-pi1 INPUT { font-size:10px; font-family:Verdana;
background-color:#35006d; color:#ffffff; font-weight:bold; }
.tx-srfeuserregister-pi1 INPUT.tx-srfeuserregister-pi1-submit {
font-size:10px; font-family:Verdana; background-color:#35006d;
color:#ffffff; font-weight:bold; }
.tx-srfeuserregister-pi1 INPUT.tx-srfeuserregister-pi1-uploader {
font-size:10px; font-family:Verdana; background-color:#35006d;
color:#ffffff; font-weight:bold; }
.tx-srfeuserregister-pi1 INPUT.tx-srfeuserregister-pi1-icon {
font-size:10px; font-family:Verdana; background-color:transparent;}
.tx-srfeuserregister-pi1 SELECT { font-size:10px; font-family:Verdana;
background-color:#35006d; color:#ffffff; font-weight:bold; }
.tx-srfeuserregister-pi1 TEXTAREA { font-size:10px;
font-family:Verdana; background-color:#35006d; color:#ffffff;
font-weight:bold; }
.tx-srfeuserregister-pi1 .tx-srfeuserregister-pi1-radio INPUT {
font-size:10px; font-family:Verdana; background-color:transparent;
color:#35006d; font-weight:bold; vertical-align:middle; }
.tx-srfeuserregister-pi1 .tx-srfeuserregister-pi1-checkbox INPUT {
font-size:10px; font-family:Verdana; background-color:transparent;
color:#35006d; font-weight:bold; vertical-align:middle; }
)
_DEFAULT_PI_VARS {
}
enableCanspamLogging =
{$plugin.tx_srfeuserregister_pi1.enableCanspamLogging}
}
# -------------- sr_feuser_register (end) --------------
marți, 7 martie 2017
Typo3 hook when user logs in
best is to have your own extension under a folder like vendor_name (notice the underscore and the camelcasing below).
in your extensions ext_localconf.php, configure your hook like:
// hooks when logging in
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'][] = 'VendorName\Classes\Hooks\AfterRegistrationHook->postLogin';
and our file vendor_name/Classes/Hooks/AfterRegistrationHook.php should look like:
function postLogin(&$params, &$pObj) {
if ($pObj->loginType === 'FE' &&
$pObj->loginFailure === false &&
is_array($pObj->user) &&
$pObj->loginSessionStarted === true
) {
print_r($params);
die("here we are just after the user has logged in");
}
}
luni, 26 septembrie 2016
What is the current mysql license, how to find it?
Hi,
You're wondering how to find the current mysql license?
One should just query the instance variables, it's as easy as this:
SHOW VARIABLES LIKE '%license%';That's it! (of course one needs first to connect to the instance like : mysql -u your_username -p )
vineri, 19 august 2016
ASP Classic Recursively Delete Files (older than) and folders
In ASP Classic (VBScript), this piece of script will recursively walk through all subfolders and remove all files older than 6 hours (change it to days, weeks, months), and all empty subdirectories.
DeleteFiles("C:\cleanThisSub")
dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
' recursively deletes files older than 6 hours and the empty directories
Sub DeleteFiles(ByVal sFolder)
Set folderObj = fso.GetFolder(sFolder)
dim aFiles, aSubFolders, aSubFolders2, file, folder, folderObj2
Set aFiles = folderObj.Files
Set aSubFolders = folderObj.SubFolders
For Each file in aFiles
if ( DateDiff("s", file.DateLastModified, Now()) > 6 * 3600 ) then
'delete files older than 6 hours
response.write "del " & file.Path & "<br>"
fso.deleteFile(file.Path)
End If
Next
For Each folder in aSubFolders
Set folderObj2 = fso.GetFolder(folder.Path)
DeleteFiles(folder.Path)
Set aFiles = folderObj2.Files
if aFiles.Count<1 then
set asubfolders2 = folderObj2.SubFolders
if aSubFolders2.Count<1 then
' subfolder is empty, can be removed
response.write "rmdir " & folder.Path & "<br>"
fso.deleteFolder(folder.Path)
end if
end if
Next
End Sub
vineri, 13 mai 2016
Windows 10 Unable to open Link in Mail
For a while now, every time i clicked a link inside any email , within the Windows 10 Mail app,
this failed with the warning 'Unable to open Link: http://... '.
After some research i've figured it is due to the fact that i stopped&disabled the windows Firewall service.
As soon as i opened services.msc , scrolled down to windows firewall, and started it - all windows 10 mail Links started opening up immediately, like magic!
Thanks Microsoft + Windows 10.
You're doing a great job.
this failed with the warning 'Unable to open Link: http://... '.
After some research i've figured it is due to the fact that i stopped&disabled the windows Firewall service.
As soon as i opened services.msc , scrolled down to windows firewall, and started it - all windows 10 mail Links started opening up immediately, like magic!
Thanks Microsoft + Windows 10.
You're doing a great job.
joi, 6 august 2015
Backup Database and Website in PHP without MYSQLDUMP
On some configurations, mysqldump is not available.
So how does one backup his database without mysqldump, but only PHP at hand?
Here is a workaround in pure PHP (just a little additional help from tar and zip - can be completely skipped). This piece of script will create its own backup directories if they don't exist (yes it needs write rights to the destination directory), get a backup of the database (in chunks, not to break or stall the database), tar-zips the backups, and the cherry on top: it will delete old files - so they don't build up to use your whole disk space.
To run it, of course you need to configure it correctly with your database name, username, password, hostname, authorization password, and perhaps the paths to the directories to the backup output files.
If you're gonna use this piece of script, please drop me a line, i'll be happy to hear about it!
So how does one backup his database without mysqldump, but only PHP at hand?
Here is a workaround in pure PHP (just a little additional help from tar and zip - can be completely skipped). This piece of script will create its own backup directories if they don't exist (yes it needs write rights to the destination directory), get a backup of the database (in chunks, not to break or stall the database), tar-zips the backups, and the cherry on top: it will delete old files - so they don't build up to use your whole disk space.
To run it, of course you need to configure it correctly with your database name, username, password, hostname, authorization password, and perhaps the paths to the directories to the backup output files.
If you're gonna use this piece of script, please drop me a line, i'll be happy to hear about it!
<?php
// set up a password access - so to prevent abuses
if ( $_GET['p']=='SOMe_Str0ng_Pa55word')
{
set_time_limit(60*6); // 6 minutes
$dbname = 'PuT_Your_DB_Name_Here'; // like wordpress
$user = 'PuT_Your_Username_Here'; // like root
$pass = 'PuT_Your_Password_Here'; // like 12345
$host = 'PuT_Your_DB_HOST_Here'; // like localhost or db.mysql.server.org
// check or create directory for DB backup
if ( !is_dir('/backup/DB') ) {
mkdir('/backup/DB');
chmod('/backup/DB', 0755);
}
// check or create directory for site backup
if ( !is_dir('/backup/html') ) {
mkdir('/backup/html');
chmod('/backup/html', 0755);
}
/************************************
CREATE A BACKUP OF THE DATABASE
************************************/
// check if a recent backup exists and clean up old files
$haveRecent = false;
$dp = opendir('/backup/DB');
while ( $fname = readdir($dp) )
{
if ( $fname && $fname!='.' && $fname!='..' )
{
if ( substr($fname, -11)=='.sql.tar.gz' && preg_match('/^[0-9]{14}_/i', $fname) && !preg_match('/[^a-z0-9\_\.]/i', $fname) )
{
$dt = substr($fname, 0, 8);
if ( $dt<=date("Ymd", time()-(86400*30*2) ) )
{
// delete all older than 90 days
@unlink('/backup/DB/'.$fname);
}
elseif ( (int)$dt>date("Ymd", time()-86400*15) )
{
// we have a recent backup (last 15 days)
$haveRecent = true;
}
}
}
}
//if ( !$haveRecent )
{
// dump the DB in the appropriate DB backup directory
$fn = '/backup/DB/'.date("YmdHis") . '_' . $dbname . '.sql';
$tfn = $fn . '.tar.gz';
if ( !is_file($fn) && !is_file($tfn) )
{
$MB = new mysqlBackup();
$MB->backup_tables($host, $user, $pass, $dbname, '*', $fn);
exec('tar -czf ' . $tfn . ' -C ' . dirname($tfn) . ' ' . basename($fn));
@unlink($fn);
}
}
/************************************
END CREATE A BACKUP OF THE DATABASE
************************************/
/************************************
CREATE A BACKUP OF THE WEBSITE FILES
************************************/
// check if a recent backup exists and clean up old files
$haveRecent = false;
$dp = opendir('/backup/html/');
while ( $fname = readdir($dp) )
{
if ( $fname && $fname!='.' && $fname!='..' )
{
if ( preg_match('/^[0-9]{14}\.tar\.gz$/', $fname) )
{
$dt = substr($fname, 0, 8);
if ( (int)$dt<=(int)date("Ymd", time()-(86400*30*2) ) )
{
// delete all older than 90 days
@unlink('/backup/html/'.$fname);
}
elseif ( (int)$dt>(int)date("Ymd", time()-86400*15) )
{
// we have a recent backup (last 15 days)
$haveRecent = true;
}
}
}
}
//if ( !$haveRecent )
{
// dump the DB in the appropriate DB backup directory
$fn = '/backup/html/' . date("YmdHis") . '.tar.gz';
if ( !is_file($fn) )
{
exec('tar -czf ' . $fn . ' -C / html');
}
}
/************************************
END CREATE A BACKUP OF THE WEBSITE FILES
************************************/
}
class mysqlBackup
{
//backup_tables('localhost','username','password','blog');
/* backup the db OR just a table */
function backup_tables($host, $user, $pass, $name, $tables = '*', $ofile ='')
{
$link = mysql_connect($host, $user, $pass) or die("could not connect");
mysql_select_db($name, $link);
//save file
$handle = fopen($ofile, 'w');
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$exhaustedTable = false; $iteration = 0; $pageSize = 1000; // to dump the tables in batches of 1000 lines
$colsRes = mysql_query('SHOW COLUMNS FROM `'.$table.'`');
$cols = array(); $colsStr = '';
while ( $colRow = mysql_fetch_row($colsRes) )
{
$cols[] = $colRow[0];
$colsStr.= ($colsStr!=''?',':'') . '`' . $colRow[0] . '`';
}
$num_fields = count($cols);
$n1 = ($num_fields-1);
fwrite($handle, 'DROP TABLE IF EXISTS `'.$table.'`;'. "\n");
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE `'.$table.'`'));
fwrite($handle, $row2[1].";\n");
while (!$exhaustedTable)
{
$result = mysql_query('SELECT * FROM `'.$table. '` LIMIT '.($iteration*$pageSize).','.$pageSize);
if ( mysql_num_rows($result) )
{
fwrite($handle, 'INSERT INTO `'.$table.'` (' . $colsStr . ') VALUES');
$nc = false;
while($row = mysql_fetch_row($result))
{
if ( $nc )
{
fwrite($handle, ', ');
}
fwrite($handle, '(');
for($j=0; $j<$num_fields; $j++)
{
if ( $row[$j] === NULL )
{
fwrite($handle, 'NULL');
}
elseif ( $row[$j]==='' )
{
fwrite($handle, '""');
}
else
{
$row[$j] = mysql_real_escape_string(stripslashes($row[$j]));
$row[$j] = preg_replace("/\n/m","\\n",$row[$j]);
fwrite($handle, '"'.$row[$j].'"');
}
if ($j<$n1)
{
fwrite($handle, ',');
}
}
fwrite($handle, ')');
$nc = true;
}
fwrite($handle, ";\n");
}
else
{
$exhaustedTable = true;
}
$iteration++;
}
}
fclose($handle);
}
}
?>
// set up a password access - so to prevent abuses
if ( $_GET['p']=='SOMe_Str0ng_Pa55word')
{
set_time_limit(60*6); // 6 minutes
$dbname = 'PuT_Your_DB_Name_Here'; // like wordpress
$user = 'PuT_Your_Username_Here'; // like root
$pass = 'PuT_Your_Password_Here'; // like 12345
$host = 'PuT_Your_DB_HOST_Here'; // like localhost or db.mysql.server.org
// check or create directory for DB backup
if ( !is_dir('/backup/DB') ) {
mkdir('/backup/DB');
chmod('/backup/DB', 0755);
}
// check or create directory for site backup
if ( !is_dir('/backup/html') ) {
mkdir('/backup/html');
chmod('/backup/html', 0755);
}
/************************************
CREATE A BACKUP OF THE DATABASE
************************************/
// check if a recent backup exists and clean up old files
$haveRecent = false;
$dp = opendir('/backup/DB');
while ( $fname = readdir($dp) )
{
if ( $fname && $fname!='.' && $fname!='..' )
{
if ( substr($fname, -11)=='.sql.tar.gz' && preg_match('/^[0-9]{14}_/i', $fname) && !preg_match('/[^a-z0-9\_\.]/i', $fname) )
{
$dt = substr($fname, 0, 8);
if ( $dt<=date("Ymd", time()-(86400*30*2) ) )
{
// delete all older than 90 days
@unlink('/backup/DB/'.$fname);
}
elseif ( (int)$dt>date("Ymd", time()-86400*15) )
{
// we have a recent backup (last 15 days)
$haveRecent = true;
}
}
}
}
//if ( !$haveRecent )
{
// dump the DB in the appropriate DB backup directory
$fn = '/backup/DB/'.date("YmdHis") . '_' . $dbname . '.sql';
$tfn = $fn . '.tar.gz';
if ( !is_file($fn) && !is_file($tfn) )
{
$MB = new mysqlBackup();
$MB->backup_tables($host, $user, $pass, $dbname, '*', $fn);
exec('tar -czf ' . $tfn . ' -C ' . dirname($tfn) . ' ' . basename($fn));
@unlink($fn);
}
}
/************************************
END CREATE A BACKUP OF THE DATABASE
************************************/
/************************************
CREATE A BACKUP OF THE WEBSITE FILES
************************************/
// check if a recent backup exists and clean up old files
$haveRecent = false;
$dp = opendir('/backup/html/');
while ( $fname = readdir($dp) )
{
if ( $fname && $fname!='.' && $fname!='..' )
{
if ( preg_match('/^[0-9]{14}\.tar\.gz$/', $fname) )
{
$dt = substr($fname, 0, 8);
if ( (int)$dt<=(int)date("Ymd", time()-(86400*30*2) ) )
{
// delete all older than 90 days
@unlink('/backup/html/'.$fname);
}
elseif ( (int)$dt>(int)date("Ymd", time()-86400*15) )
{
// we have a recent backup (last 15 days)
$haveRecent = true;
}
}
}
}
//if ( !$haveRecent )
{
// dump the DB in the appropriate DB backup directory
$fn = '/backup/html/' . date("YmdHis") . '.tar.gz';
if ( !is_file($fn) )
{
exec('tar -czf ' . $fn . ' -C / html');
}
}
/************************************
END CREATE A BACKUP OF THE WEBSITE FILES
************************************/
}
class mysqlBackup
{
//backup_tables('localhost','username','password','blog');
/* backup the db OR just a table */
function backup_tables($host, $user, $pass, $name, $tables = '*', $ofile ='')
{
$link = mysql_connect($host, $user, $pass) or die("could not connect");
mysql_select_db($name, $link);
//save file
$handle = fopen($ofile, 'w');
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$exhaustedTable = false; $iteration = 0; $pageSize = 1000; // to dump the tables in batches of 1000 lines
$colsRes = mysql_query('SHOW COLUMNS FROM `'.$table.'`');
$cols = array(); $colsStr = '';
while ( $colRow = mysql_fetch_row($colsRes) )
{
$cols[] = $colRow[0];
$colsStr.= ($colsStr!=''?',':'') . '`' . $colRow[0] . '`';
}
$num_fields = count($cols);
$n1 = ($num_fields-1);
fwrite($handle, 'DROP TABLE IF EXISTS `'.$table.'`;'. "\n");
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE `'.$table.'`'));
fwrite($handle, $row2[1].";\n");
while (!$exhaustedTable)
{
$result = mysql_query('SELECT * FROM `'.$table. '` LIMIT '.($iteration*$pageSize).','.$pageSize);
if ( mysql_num_rows($result) )
{
fwrite($handle, 'INSERT INTO `'.$table.'` (' . $colsStr . ') VALUES');
$nc = false;
while($row = mysql_fetch_row($result))
{
if ( $nc )
{
fwrite($handle, ', ');
}
fwrite($handle, '(');
for($j=0; $j<$num_fields; $j++)
{
if ( $row[$j] === NULL )
{
fwrite($handle, 'NULL');
}
elseif ( $row[$j]==='' )
{
fwrite($handle, '""');
}
else
{
$row[$j] = mysql_real_escape_string(stripslashes($row[$j]));
$row[$j] = preg_replace("/\n/m","\\n",$row[$j]);
fwrite($handle, '"'.$row[$j].'"');
}
if ($j<$n1)
{
fwrite($handle, ',');
}
}
fwrite($handle, ')');
$nc = true;
}
fwrite($handle, ";\n");
}
else
{
$exhaustedTable = true;
}
$iteration++;
}
}
fclose($handle);
}
}
?>
marți, 21 aprilie 2015
How to add a toolbar to your Windows 8.1 taskbar (for example, QuickLaunch)
I personally was missing in my rather new Windows 8.1, the Quick Launch Toolbar - that used to exist in older Windows versions. So i created my own, new, custom QuickLaunch toolbar. Here's how:
Basically any valid Windows folder can become a new toolbar. So all you need to do is create a folder, wherever you wish on your hard-disk, with any name of your choice. I personally went to the Documents folder (start screen, type Documents, press enter), right-clicked and created a New -> Folder, which i have named 'QuickLaunch'.
Right-Click on an empty area of your Win 8.1 taskbar. From the menu, choose Toolbars -> New Toolbar and just select the folder of your choice - in my case it was C:\Users\luciancostin\Documents\QuickLaunchToolbar
There it goes - the toolbar already appears on our taskbar. Whatever shortcuts or programs we put in there, they will be automatically displayed (here's how to create for example, a 'show desktop' icon).
For adding my Firefox icon, i've browsed to C:\Program Files (x86)\Mozilla Firefox , right-clicked on the 'firefox' program, chose 'Create shortcut' from the context-menu, cut (ctrl+x) this shortcut, and pasted it in my newly created folder.
For further customization of the toolbar (because by default, it has a rather strange appearance, showing the title, and the names of the links in here), one must:
1. unlock the taskbar: right-click your taskbar ,make sure the 'Lock the taskbar' menu item is not checked.
2. feel free to drag the margins and the whole toolbar wherever you like it, and to your preferred size.
3. right-click the toolbar for options, uncheck the 'show title' and 'show text' menu items - to get to the original 'quicklaunch' toolbar look & feel.
4. lock back the taskbar: preferably you'd want it to stay in place, so better to lock it back. Just right-click your taskbar and check the menu item 'Lock the taskbar'
That's it! :-) our new toolbar:
Basically any valid Windows folder can become a new toolbar. So all you need to do is create a folder, wherever you wish on your hard-disk, with any name of your choice. I personally went to the Documents folder (start screen, type Documents, press enter), right-clicked and created a New -> Folder, which i have named 'QuickLaunch'.
Right-Click on an empty area of your Win 8.1 taskbar. From the menu, choose Toolbars -> New Toolbar and just select the folder of your choice - in my case it was C:\Users\luciancostin\Documents\QuickLaunchToolbar
There it goes - the toolbar already appears on our taskbar. Whatever shortcuts or programs we put in there, they will be automatically displayed (here's how to create for example, a 'show desktop' icon).
For adding my Firefox icon, i've browsed to C:\Program Files (x86)\Mozilla Firefox , right-clicked on the 'firefox' program, chose 'Create shortcut' from the context-menu, cut (ctrl+x) this shortcut, and pasted it in my newly created folder.
For further customization of the toolbar (because by default, it has a rather strange appearance, showing the title, and the names of the links in here), one must:
1. unlock the taskbar: right-click your taskbar ,make sure the 'Lock the taskbar' menu item is not checked.
2. feel free to drag the margins and the whole toolbar wherever you like it, and to your preferred size.
3. right-click the toolbar for options, uncheck the 'show title' and 'show text' menu items - to get to the original 'quicklaunch' toolbar look & feel.
4. lock back the taskbar: preferably you'd want it to stay in place, so better to lock it back. Just right-click your taskbar and check the menu item 'Lock the taskbar'
That's it! :-) our new toolbar:
Abonați-vă la:
Postări (Atom)
