[VB.NET] Notify icon with transparency

Hi,

today a small code snippet for the subject notify icon with transparency.

I couldn’t figure out how to create a normal *.ico with transparency. At least my program wasn’t supporting this feature. So I was creating my own code and needed to trick around a bit :-) The code can be used also for some other work, I think.

It works very easy. In my case I have an image list with several pictures. I just select one and set it up as notify icon.

The sub looks like that. It need to be run with the program start of course.

That’s it. Now your program has an notify icon with background transparency ;-)

' sets a new icon from the imagelist. because of the transparens
    Sub createNotifyIcon()
        Try
            Dim img As Bitmap = Me.ImageList1.Images(1)
            Dim hIcon As IntPtr = img.GetHicon()
            Dim icn As Icon = Drawing.Icon.FromHandle(hIcon)
            Me.NotifyIcon1.Icon = icn
            icn = Nothing
            hIcon = Nothing
            img = Nothing
        Catch exc As Exception
            'ups, error... hope the icon is still there...
        End Try
    End Sub

Magento – Admin login doesn’t work

Hi together,

and again a problem with a software. This time is the the online shop software Magento.
Direct after the installation you should be able to log in to the administration area. Theoretically. But I couldn’t. Username and password was entered correctly. There was also no error message, that something is wrong – not like I would have entered really wrong data, then an error message would occur.
Like that I stuck on the log in page and didn’t got forwarded to the administration area.

That is very annoying and of course I was searching the mistake first by myself… and entered the information again and again.
But there is really an error in the software (in the cookie handling).
Just search the following code in the file “app/code/core/Mage/Core/Model/Session/Abstract/Varien.php“:

// session cookie params
        $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath(),
            'domain'   => $cookie->getConfigDomain(),
            'secure'   => $cookie->isSecure(),
            'httponly' => $cookie->getHttponly()
        );

(approx. line 77) and replace it with:

// session cookie params
		$cookieParams = array(
			'lifetime' => $cookie->getLifetime(),
			'path' => $cookie->getPath(),
			'domain' => '',
			'secure' => '',
			'httponly' => ''
		);

Now it should work.

Integrate affiliate tracking codes in Prestashop

Hi,

I’ve opened now my first online shop and quickly the question came up… how to find customer. Or who could help me with it.
Quickly I found one possible answer… affiliate marketing. It’s anyway my preferred method from all I know and for which my wallet is big enough. Everything else is not economical or just to expensive… most both.

So, I started a campaign at my favorite affiliate network. And then the big question… how to integrate the tracking code in my Presta shop system? :o
That is not so easy, because there are variables to send.

Luckily we have the internet. :) And I found the answer in a forum. Here the quote summary of PaoloPinkel:

 

1.) Add this to the init.php:

@session_start();
if(Tools::getValue('belboon')){
  $_SESSION['belboonSession'] = Tools::getValue('belboon');
}

2.) And this to the order-confirmation.php:

$smarty->assign('belboon',$order->getTotalProductsWithTaxes());
$smarty->assign('belboonSession',$_SESSION['belboonSession']);

3.) The code from Belboon has to be added into the order-confirmation.tpl. In this sniped you need to replace NETTOWARENWERT (sorry, don’t know what is written in the english version ‘Net value’?) with {$belboon}, ORDERCODE with {$id_order} and xxxx,yyyy with {$belboonSession}.

That’s it. If you have to transfer VAT then you have to reduce it from getTotalProductsWithTaxes() somehow. Else they pay to much commission.

(Quote from http://www.homepage-community.de/…)

PaoloPinkel is using the affiliate network Belboon. I use a different network. But the concept is the same. You just need to customize the variables.

Thank you to PaoloPinkel and Chris.

Best wishes
Gordon

[PHP] Show/print all variables in use.

Hi,

today I asked myself how the variables look like at the end of my script. I mean I use variables, include scripts, make database requests… and I always try to care to unset the variables again when I don’t need them anymore. But to I get all… or does my script use more and more memory? And how can I control it?

PHP have also for this question a solution. get_defined_vars() shows all variables which are currently in use.

print_r(get_defined_vars());

Call this function at the end (or somewhere between) and you know exactly which variables are in use and where you have to clean up.

Very nice :-)

Best regards
Gordon

[PHP] Generate a random password

Hi,

because I need that from time to time and always looking again for a good function… here my memory aid. :-)

$pwZeichen = 'wertzupasdfghkyxcvbnmWERTZUPLKJHGFDSAYXCVBNM23456789';
srand ((double)microtime()*1000000);
for($i = 0; $i < 5; $i++) {
$passwort .= substr( $pwZeichen, (rand()%(strlen ($pwZeichen) ) ), 1);
}

In the variable $pwZeichen are all signs which can be used in the password. ‘srand’ starts the random generator (else the password would include always the same signs) ;-)
The ‘for’ loop set how long the password will be. Here 5 digits. You can change the value of course. And last but not least are the signs added to the variable $passwort.

That’s it :)

[CSS] Tooltip without Javascript!

Hi,

today another code snippet for the daily usage :)
As mentioned already in the subject, it’s about a tooltip without Javascript. Everybody know this small windows (or also known as speech bubble) which open when you dwell on an object. If they show information or a small help… it can be used in many ways.

Mostly this windows will be initiated with Javascript. But that can also occur problems. Like I had to realize now. I wanted to run in this Jacascript bubble another Javascript… not possible. It is also helpful if the user has Javascript deaktivated. And it doesn’t look worse with CSS.

This code sniped is not from me this time. It can be found at: Trent Richardson

Have fun with it ;)

Best regards
Gordon

[PHP] Check if eMail address is correct / validation

Hello together,

on almost every webpage is a field where the user have to enter his email address. Doesn’t matter if it is a contact form, the registration form for a newsletter or the registration for a member area.

We need to check in every case the email address. If the structure is correct (not that the user accidentally entered the URL of his homepage) and we can check if the domain exist. But unfortunately we can’t check spelling mistakes… or just with an effort which wouldn’t be worthwhile anymore.

Here the simple function to check the email address:

function mailCheck($email) { 
	return preg_match("/^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-.]+.([a-zA-Z]{2,4})$/", $email); 
}

This function will just check if the structure of the email address is correct. It means if the “@” sign is on the right position and if a TLD is in the string. It will not check if the domain (TLD) exist or not.

And here the extended function:

function mailcheckDNS($mail) { 
	$email = htmlspecialchars($mail); 
	$r = false; 
	if(preg_match('/(.*?)@(.*?).(w){2,6}/i', $email)) { 
		$split = explode('@', $email); 
		$split2 = explode('.', $split[1]); 
		if(preg_match('/([a-z]){3,64}/i', $split2[0])) { 
			if(preg_match('/([a-z0-9!"$&/()?~#+.:_-]+){1,64}[^@]/i', $split[0])) { 
				$MXCheck = getmxrr($split[1], $mxhosts); 
				if(!empty($MXCheck)) { 
					$r = true; 
				} 
			} 
		} 
	} 
	return $r; 
}

This function checks now also if the domain exist, with trying to reach it. If it is possible then the result will be positive, if not negative.

There is no 100% sure email check, but what we can check, we should check. Spelling mistakes can’t be checked. But therefore we could let the user enter his email address a second time, to make sure it’s correct.

Best regards
Gordon


Attention: Using my code snippets at your own risk! I assume no warranty for functionality (each server is configured differently. If you have problems then you can leave a comment and we look for a solution.;)

Nextgen Gallery – Resizing images according to the aspect ratio

Soooo… after postponing it for quite a while… I sat down and solved finally the aspect ratio problem when Nextgen Gallery shall resize/shrink an image.

The problem is… If I set as picture size e.g. 800×600 px (width x height), then Nextgen Gallery resizes a picture from e.g. 1024x768px to this format. All good. But if the original picture is 768x1024px then the result is not a picture with 600x800px, no, it will be a picture of 450x600px. And that is not what we want. (Isn’t it?)

So, I sat down today and checked the sources. Actually its simple. The picture will be uploaded and checked on its size. The values will be re-calculated be the settings and the aspect ratio should be checked as well. They just forgot to adjust the settings. We’ll do that now…

Open the file “/wp-content/plugins/nextgen-gallery/admin/wp25/functions.php” in an editor and search for the function “function resizeImages()”. Here you’ll see:

function resizeImages($gallery_absfolder, $pictures) {
// ** $gallery_absfolder must contain abspath !!

if(! class_exists(‘ngg_Thumbnail’))
require_once(NGGALLERY_ABSPATH.’/lib/thumbnail.inc.php’);

$ngg_options = get_option(‘ngg_options’);

if (is_array($pictures)) {

$bar = new wpProgressBar(__(‘Running… Please wait’,’nggallery’));
$bar->setHeader(__(‘Resize images’,’nggallery’));
//total number of elements to process
$elements = count($pictures);
// wait a little bit after finished
if ($elements > 5) $bar->setSleepOnFinish(2);
//print the empty bar
$bar->initialize($elements);

foreach($pictures as $picture) {

if (!is_writable($gallery_absfolder.”/”.$picture)) {
$messagetext .= $gallery_absfolder.”/”.$picture.”<br />”;
$bar->increase();
continue;
}

$thumb = new ngg_Thumbnail($gallery_absfolder.”/”.$picture, TRUE);
// echo $thumb->errmsg;
// skip if file is not there
if (!$thumb->error) {
$thumb->resize($ngg_options[‘imgWidth’],$ngg_options[‘imgHeight’], $ngg_options[‘imgResampleMode’]);
if ( $thumb->save($gallery_absfolder.”/”.$picture,$ngg_options[‘imgQuality’]) ) {
// do not flush the buffer with useless messages
if ($elements < 100)
$bar->addNote($picture. __(‘ : Image resized…’,’nggallery’));
} else
$bar->addNote($picture . ” : Error : <strong>”.$thumb->errmsg.”</strong>”);
$bar->increase();
}
$thumb->destruct();
}
}

if(!empty($messagetext)) nggallery::show_error(‘<strong>’.__(‘Some pictures are not writeable :’,’nggallery’).'</strong><br /><ul>’.$messagetext.'</ul>’);
return;
}

This is the function which resizes our original pictures. We’ll replace this function now with this modified one:

function resizeImages($gallery_absfolder, $pictures) {
// ** $gallery_absfolder must contain abspath !!

if(! class_exists(‘ngg_Thumbnail’))
require_once(NGGALLERY_ABSPATH.’/lib/thumbnail.inc.php’);

$ngg_options = get_option(‘ngg_options’);

if (is_array($pictures)) {

$bar = new wpProgressBar(__(‘Running… Please wait’,’nggallery’));
$bar->setHeader(__(‘Resize images’,’nggallery’));
//total number of elements to process
$elements = count($pictures);
// wait a little bit after finished
if ($elements > 5) $bar->setSleepOnFinish(2);
//print the empty bar
$bar->initialize($elements);

foreach($pictures as $picture) {

if (!is_writable($gallery_absfolder.”/”.$picture)) {
$messagetext .= $gallery_absfolder.”/”.$picture.”<br />”;
$bar->increase();
continue;
}

$thumb = new ngg_Thumbnail($gallery_absfolder.”/”.$picture, TRUE);
// echo $thumb->errmsg;
// skip if file is not there

if (!$thumb->error) {
//$thumb->resize($ngg_options[‘imgWidth’], $ngg_options[‘imgHeight’], $ngg_options[‘imgResampleMode’]);

if ($thumb->currentDimensions[‘height’] > $ngg_options[‘imgHeight’] || $thumb->currentDimensions[‘width’] > $ngg_options[‘imgWidth’]) {

// check for portrait format
if ($thumb->currentDimensions[‘height’] > $thumb->currentDimensions[‘width’]) {
//vorgaben checken
if ($ngg_options[‘imgWidth’] > $ngg_options[‘imgHeight’]) {
$y = $ngg_options[‘imgWidth’];
$x = $ngg_options[‘imgHeight’];
} else {
$y = $ngg_options[‘imgHeight’];
$x = $ngg_options[‘imgWidth’];
}
$thumb->resize($x, 0, $ngg_options[‘imgResampleMode’]);
// get optimal y startpos
$ypos = ($thumb->currentDimensions[‘height’] – $y) / 2;
$thumb->crop(0, $ypos, $x,$y,$ngg_options[‘imgResampleMode’]);
} else {
//vorgaben checken
if ($ngg_options[‘imgWidth’] < $ngg_options[‘imgHeight’]) {
$y = $ngg_options[‘imgWidth’];
$x = $ngg_options[‘imgHeight’];
} else {
$y = $ngg_options[‘imgHeight’];
$x = $ngg_options[‘imgWidth’];
}
$thumb->resize(0,$y,$ngg_options[‘imgResampleMode’]);
// get optimal x startpos
$xpos = ($thumb->currentDimensions[‘width’] – $x) / 2;
$thumb->crop($xpos, 0, $x,$y,$ngg_options[‘imgResampleMode’]);
}

} else {
$thumb->resize($ngg_options[‘imgWidth’], $ngg_options[‘imgHeight’], $ngg_options[‘imgResampleMode’]);
}

if ( $thumb->save($gallery_absfolder.”/”.$picture,$ngg_options[‘imgQuality’]) ) {
// do not flush the buffer with useless messages
if ($elements < 100)
$bar->addNote($picture. __(‘ : Image resized…’,’nggallery’));
} else
$bar->addNote($picture . ” : Error : <strong>”.$thumb->errmsg.”</strong>”);
$bar->increase();
}
$thumb->destruct();
}
}

if(!empty($messagetext)) nggallery::show_error(‘<strong>’.__(‘Some pictures are not writeable :’,’nggallery’).'</strong><br /><ul>’.$messagetext.'</ul>’);
return;
}

Ok, what is this doing now?

if ($thumb->currentDimensions[‘height’] > $ngg_options[‘imgHeight’] || $thumb->currentDimensions[‘width’] > $ngg_options[‘imgWidth’]) {

First of all we check if the uploaded image is bigger then the settings. If not, then we don’t need to do anything anyway.

if ($thumb->currentDimensions[‘height’] > $thumb->currentDimensions[‘width’])

Here we check the aspect ratio… horizontal or vertical format.

if ($ngg_options[‘imgWidth’] > $ngg_options[‘imgHeight’]) {
$y = $ngg_options[‘imgWidth’];
$x = $ngg_options[‘imgHeight’];
} else {
$y = $ngg_options[‘imgHeight’];
$x = $ngg_options[‘imgWidth’];
}

And that is basically the new thing… after we know if we have a horizontal or vertical picture, we can adjust the setting values… like 800x600px or 600x800px (for my example).

And thats it already. Looks a lot, but its more explaining then anything else :)
Maybe that is not the best solution (especially it is not ‘update save’), but it works for now. If you know a better solution, then let me have it in the comments. ;)

Please notice that all code snippets and examples on this page are on your own risk. I am not responsible for anything you do!

Cheers
Gordon

Image resize problem with the NextGEN Gallery plugin

Hi,

and I had a problem again. If you use WordPress with the “NextGEN Gallery” plugin, then you may also stumble over this problem after some time.
In the options of the plugin you can set a picture size to shrink the pictures, in case they are to big.
I’ve added there the value of 640 x 480 px. Because to big pictures need too long to load and use unnecessarily much disk space. A few minutes ago I was wondering why the pictures still need ages to load and in the full screen mode I saw it … the pictures haven’t been resized by the plugin.

After a while consulting Google I found help.

Edit the file “/wp-content/plugins/nextgen-gallery/admin/wp25/functions.php” and search the function “function upload_images()“. Scroll to the end of this function and search for:

//create thumbnails
nggAdmin::generatethumbnail(WINABSPATH.$gallerypath,$imageslist);

Write before this:

//create resized pictures
nggAdmin::resizeImages(WINABSPATH.$gallerypath,$imageslist);

Save it, upload the file to the web-space again and then it should work.

Source: http://wordpress.org/support/topic/177782

But something is still disturbing me. Wenn I set as size 640 x 480px then is it horizontal format. But the function doesn’t automatically recognize vertical format. I mean it recognize it of course… but the height is still 480px and the width will be calculated by the height. Like this the resulting image is a bit small then. Would be nice if the function would change the values according to the format of the picture.
Maybe I will check it next week. Then I’ll have more time. :)

[UPDATE] The article is ready, the problem is solved: To the article

Cheers
Gordon