Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Monday, September 23, 2013

Send highlighted text to Email Chrome extension


I was looking for extension for several days, but couldn't find it anywhere.

All i could find is tutorials how to make chrome extension and similar topic on stackoverflow with simple code how to make the extension.

So what i did.

  1. Learned some simple chrome extension tutorials
  2. Took the code from stackoverflow
  3. Created simple extension which uses external domain with file which sends emails.
You can download it here:

At first i have tried to make new tab with standart Gmail sender, but i failed at it. Because text in the case can be sent only by $_GET parameters, and Gmail has limits - about 2000 symbols. So it means max length of email is smaller than 2000 symbols.
Solution to this was to use external domain with sender.php.

Thursday, June 20, 2013

Tracking redirects with google analytics

I have tried to use php headers, but no success. Google analytics cant track page with php header location.

meta tag is not good way for me... so i found fastest redirector with javascript.

Here is code:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-******-*']);
_gaq.push(['_trackPageview']);
_gaq.push(function() {
      setTimeout(function() {
        window.location = "http://pilotaz.blogspot.com";
    }, 250);
});
(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
It is a simple google analytics script with window.location method in function. 

Tuesday, July 17, 2012

htaccess file invisible on ftp

Once again i faced with this problem...

I have connected to ftp to edit htaccess file but it is invisible. I use PSPad Editor with ftp client support.

Here is how to fix


Invisible files on ftp in PSPad:
1. Edit your ftp connection
2. Check checkbox with text - "Show hidden files (must be supported by FTP server)"
3. Reconnect
4. Done.

Cureftp fixing hidden files:

1. Open CuteFTP and Enter Hostname , Username and Password.
2. Click Action tab in Settings
3. Click on Filter button
4. tick on Enable server side filtering
5. Enter -a in Remote filter
6. Click on apply & connect.

FileZilla fix to see invisible files:

For FileZilla 2,
1. Click on Settings.
2. Select Edit -> Settings -> Interface settings -> Remote file list
3. Tick check box syas Always show hidden files & press ok.

For FileZilla 3,
1. Click on Server from top navigation.
2. Click on Force showing hidden files at last option
3. Press ok when it shows warning.

Monday, June 25, 2012

Multiple mysql insert quiery

i was trying to insert a lot ( 1.000.000 ) values into single table with single query, because inserting each value takes much longer time.

table looks like:

id , value

so solution is to create array with php of the values:

code:
    $insert = array();
    for($i=0;$i<=950000;$i++)
    {
      $insert[] = "('".md5(rand(0,1000))."')";
    }

and then executing the query:

$sql = "INSERT INTO `skelbimai` ( `value` ) VALUES ".implode(",",$insert)." ";
ALSO

You might have problem with time limit. so i set up this limit:

set_time_limit(1800);
Also you might have problem with memory_limit, so use it:
ini_set('memory_limit', '150M'); 

Good luck. 

Tuesday, April 3, 2012

Disabled input with JQuery

We have in html inputs like text, radio, select and textareas.

In my situation i had radio inputs and i needed to create trigger which should effect other inputs ( disable them ).

My inputs:
<input name="order_type" type="radio" value="2" /><br />
<input name="order_type" type="radio" value="3" /><br />
<input name="order_type" type="radio" value="4" />
Other section which i want to disable:
<input class="viewspereach" name="text" type="text" value="" />

JQuery:
$("input[name=order_type]").change(check_ordertype);
  
  function check_ordertype()
  {
    var order_type = $("input[name=order_type]:checked").attr("value");
    
    if(order_type == 4)
    { 
      $(".viewspereach").prop('disabled', true);

    }
    else
    {
      $(".viewspereach").prop('disabled', false);
    }
  }
Demo: http://igloro.info/demos/disableinput.php

Monday, March 12, 2012

How to remove duplicate values from an array in PHP



If you have duplicated values in array, and you wonder how to clean it.

Easy !

There is a function which solves the problem.

Function calls array_unique

Use:
$clean_array = array_unique($array);
Source: http://php.net/manual/en/function.array-unique.php

Thursday, January 26, 2012

Change prestashop stores google maps zoom


Good day visitor.

In prestashop there is "Stores" section.

To change zoom of the default map which loads up after navigating there, go to:


  • /js/ folder
  • open stores.js
Go to line 196.

You will see code like this:

map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(defaultLat, defaultLong),
zoom: 15,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});

Change Zoom to whatever you like.

Good luck!

Wednesday, January 18, 2012

Days in months of year


Are you lazy to count how many there are days in months of certain year?

I have created small php counter for my self.

Its pretty useful so i want to share it.

http://www.drunksick.com/index.php?p=daysinmonth

Main part of code:

for($year_s;$year_s<$year_f;$year_s++)
{
  for($month=1;$month<=12;$month++)
  {
    echo $month."'th month of ".$year_s." has: ".cal_days_in_month(CAL_GREGORIAN, $month, $year_s)." days
";
  }
}

Tuesday, January 3, 2012

Google web preview bot check PHP

I was faced with problem of google web preview "bot".
Its really not a bot, but a chrome tool which makes preview of site which you hover in google search.

The problem was that google web preview "bot" sees page without cookies in users PC. that means google bot will see all advertises which should popup for new coming user.

So solution for this is to check who is looks at page and don't show anything if its an google bot preview.

PHP code:

$bot_v = false;  
$uAgent=$_SERVER['HTTP_USER_AGENT']; 
if(strpos($uAgent,"Google Web Preview") > 0) 
{ $bot_v=true; }

Thursday, December 15, 2011

htaccess redirect from www to non-www

Code for htaccess to create redirect from site's url with www to site's url without www:
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Source: http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www

Friday, December 9, 2011

HTML crossed text

Easiest thing, but i have never used it before.

Today is my first time so i was searching for html tag code which crosses text.

I found it easily. It calls - "line-through". Its an value for text decoration tag.

tag code looks in html like:

text-decoration: line-through;

Example:

Crossed text here

Friday, November 18, 2011

Explode mysql select value



Today i have faced again with same problem - I was forced to explode value while selecting in MySQL.

Value of the field looks like - Kaina: 60000 LT (17376 EUR)
And i need this - 60000

So i made the select query:


SELECT
SUBSTRING( SUBSTRING_INDEX(`field`,' LT',1), -7) as `field_sub`
FROM `table`


As you can notice, first i have exploded the field value so it be like - Kaina: 60000
After i removed first 7 symbols.

Done... i got 60000

GL

Tuesday, September 27, 2011

Joomla K2 watermark image

We need to edit file - item.php which exists in our administrator folder, full path:
\administrator\components\com_k2\models\item.php

first we need to define the variable:
$img_url_watermark = "../images/watermark.png"; //(line 202)

near the comment line
//Original image

Then we need to paste the lines after each image comment to which we want to add watermark (i recommand not to add to small and xsmall... images )
$handle->image_watermark = $img_url_watermark;
$handle->image_watermark_position = "TL";

Than we need to add the code:
//gallery watermark
if($dir = opendir($savepath.DS.$row->id)) {
while (false !== ($file = readdir($dir))) {
$handle = new Upload ($savepath.DS.$row->id.'/'.$file);
$handle->allowed = array('image/*');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->image_resize = ture;
$handle->image_x = 1024;
$handle->image_ratio_y = true;
$handle->image_watermark = $img_url_watermark;
$handle->image_watermark_position = "TL";
$handle->image_convert = "jpg";
$handle->jpeg_quality = 85;
$handle->Process($savepath.DS.$row->id);
$handle->Clean();
}
closedir($dir);
}
//end

After the code:

if (!JArchive::extract($savepath.DS.$handle->file_dst_name, $savepath.DS.$row->id)) {
$mainframe->redirect('index.php?option=com_k2&view=items', JText::_('Gallery upload error: Cannot extract archive!'), 'error');
} else {
$row->gallery = '{gallery}'.$row->id.'{/gallery}';
}
JFile::delete($savepath.DS.$handle->file_dst_name);
$handle->Clean();

Its about 430~ line

That is all.... done :)

p.s. some sources where the solution was fount

http://api.ning.com/files/HXT6DGp5WSJFHL5RzYp-Jb*WUL4Ep5eAy*opKr8s8KN4pt-DDD92wDPKlmNCmWeQd8msVcosqVIjDLKY3jJ-pZ*6PcJz56pR/diff1.gif
http://api.ning.com/files/*txNFL3oxugapDshDybYqwZ6pM1HRBera8DL7uZp5keDIc40jfg8UZf-SEvT3aVakQ35-yRj-RYTlZXBcGxHOa0R2gQPSkPN/diff2and3.gif
http://api.ning.com/files/2ryzVIrGkDjAz*ZMCXk1aYFdbHTiKTrxNSCfUK97YXCGDhmGv7azhnkMQ1cnJp7EdCivLSbtwdV1HmnwnnjnleMveePM*1LS/diff4.gif
http://community.getk2.org/forum/topics/im-just-trying-to-add-a-png

Thursday, September 15, 2011

Mysql Table rows

Easiest way for me to check how many rows in tables of database is to use the query:
SHOW TABLE STATUS FROM `database_name`
easy.. good luck

Wednesday, August 24, 2011

Posting code on blogger

I faced again with problem of posting PHP code on blogger. So here is very simple and nice Code converter for posting code on Blogger.
http://francois.schnell.free.fr/tools/BloggerPaste/BloggerPaste.html

Simple Google Weather Unofficial Api



Hey guys. If you are searching for very simple google weather Unofficial api, so here is the code for it.

<?php                   
//Created by Roman Losev 2011
//http://pilotaz.blogspot.com/
//email: pilotaz@gmail.com
//Thanks for feedback.

$url = "http://www.google.com/ig/api?weather=Vilnius+Lithuania&hl=lt";

ini_set("user_agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0"); 
ini_set("content_type","text/xml; charset=\"UTF-8\"");                                      
ini_set("accept_charset","utf-8;q=0.7,*;q=0.7");
ini_set("max_execution_time", 0);
ini_set("memory_limit", "1000M");

$xml = simplexml_load_file($url);   

$image_size = "80";
$count = 0;
echo '<div id="weather" align="center">';
$img = IMG_URL."me/hero_bg.gif";
echo "<table border='0' width='400' style=\"background: url(".$img.") bottom left repeat-x #FFF; border: 1px solid #EEE; padding: 20px\">";
foreach($xml->weather as $item) {  
echo "<tr><td colspan=\"4\" align='center'>Vilniuje Å¡iandien: ".$item->current_conditions->temp_c['data']."° C, ".$item->current_conditions->humidity['data'].", ".$item->current_conditions->wind_condition['data']."</td></tr><tr>"; 
    foreach($item->forecast_conditions as $new) {  
         echo '<td style="padding: 4px;" align="center"><div class="weatherIcon">';
         echo '<img src="http://www.google.com/' . $new->icon['data'] . '"/ width="'.$image_size.'" height="'.$image_size.'" style="border: 1px solid #a1a1a1"><br/>';
         echo $new->day_of_week['data'].": ".$new->low['data']." - ".$new->high['data']."° C";
         echo '</div>';
         echo "</td>";
    }
}
echo "</tr></table>";
echo '</div><br>'; 
?>

[Solution] user agent stylesheet override site stylesheet on Chrome but not Firefox


My problem was this: i wanted to put bold on text which was in select's option by putting style - wont-weight. I had succeed only on Firefox. Because chrome user agent stylesheet were overriding my stylesheet.
I tried to solve the problem for hours. Finally with my friend's help i found the website - electrictoolbox. And it says that only firefox allows to do that... that means we cant use wont-weight on chrome for option, select and optgroup.

My solution was for the bold text changing wont-weight style into color, with dark color for normal text and lighter color for bold required. Also i needed disabling option of bold, so i just added " disabled='disabled' ". That is all..

My result:


Good luck.

Thursday, August 4, 2011

PHP string replace all except numbers and chars

Here is PHP function(code) to remove all but not characters and numbers.
$result= preg_replace("/[^a-zA-Z0-9]+/", "", $text);
p.s. If you are looking to delete everything but numbers, than look here:
http://pilotaz.blogspot.com/2011/05/php-remove-all-characters-and-leave_29.html

Monday, August 1, 2011

PHP multidimensional array check

Today i faced with problem that array had array inside it. It means that the array is multidimensional. So i was forced to recheck the array check with function is_array to new check. Here is the code of check:


function is_multi($a) {
    $rv = array_filter($a,'is_array');
    if(count($rv)>0) return true;
    return false;
}

Source: http://stackoverflow.com/questions/145337/checking-if-array-is-multidimensional-or-not
Big thanks to Vinko Vrsalovic

Friday, July 29, 2011

CSS compressor

Today i have created my own css compressor. I often do css compression, but i always used other sites. So today i created my own and using it! All you need just copy your css code, paste into css code field and press compress. The compressor will compress css code for you. Mostly i get 20% compressed code. Compression can be high and can be low, it all depends on your CSS code writing. The more compressed code you write, the less it will be need to compress.
So now you dont need to write it compressed. Just write as you like and after compress into compact size called "min" aka "mini" ( most of programmers use .min tag for jquery files , like jquery.blabla.min.js )

Screenshot:


Source:
CSS compressor