$(‘img’).each(function(){
var t=$(this);
var src1 = t.attr(‘src’);
var newSrc = “images/play2.png”;
if(src1 == “images/play.png”)
{
$(this).attr(‘src’, newSrc);
}
});
jQuery replace all img tags with certain source…
June 7th, 2010JavaScript URL parse to load multiple versions
June 7th, 2010<script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script>
<script>
$(document).ready(function() {
<!– Version requested START –>
if (location.search != “”)
{
x = location.search.substr(1).split(“;”)
for (var i=0; i<x.length; i++)
{
y = x[i].split(“=”);
//alert(y[0] + ” ” + y[1])
// Version 2 (/?version=2)
if( y[1] == 2 ){
// do things
}
// Version 3 (/?version=3)
if( y[1] == 3 ){
// do things
}
}
}
<!– Version requested END –>
jQuery .css background-image / .attr src examples
June 7th, 2010$(“body”).css(“background-image”, “url(images/bg2.jpg)”);
$(“#header”).css(“background-image”, “url(images/bg-header2.png)”);
$(“#browse”).css(“background-image”, “url(images/bg-browse2.png)”);
$(“#paginate-slider2″).css(“background-image”, “url(images/bg-slide-thumbs2.jpg)”);
$(“#slides”).css(“background-image”, “url(images/bg-slides2.png)”);
$(“#ST-now”).css(“background-image”, “url(images/bg-STnow2.png)”);
$(“#searchBox”).attr(“src”, “images/search-box2.jpg”);
$(“#keywordsBox”).attr(“src”, “images/keywords2.jpg”);
$(“#inBox”).attr(“src”, “images/products2.jpg”);
jQuery add stylesheet dynamically
June 7th, 2010within some logic, a function, elsewhere :
var link = $(“<link>”);
link.attr({
type: ‘text/css’,
rel: ‘stylesheet’,
href: ‘css/contentslider2.css’
});
$(“head”).append( link );
PHP multiple equal case switch syntax
May 4th, 2010switch($holder)
{
case “”:
case “http://www.cuealex.com/digitalcatalog”:
case “http://www.iealex.com/digitalcatalog/”:
echo “<script>alert(‘http referer: none’);</script>”;
if(isset($_SESSION['enews_refer_value']))
{
echo “<script>alert(‘but enews_refer_value WAS set, so it stays’);</script>”;
$enews_refer_value = $_SESSION['enews_refer_value'];
}
else { $enews_refer_value = “”; }
break;
default:
echo “<script>alert(‘set enews_refer_value session to http_referer’);</script>”;
$_SESSION['enews_refer_value'] = $_SERVER['HTTP_REFERER'];
$enews_refer_value = $_SESSION['enews_refer_value'];
break;
}
IE7 php force download FIX
April 30th, 2010Normally, as an accomplished programmer, you use all the headers, follow the guidelines, include what you should…
but, when Microsoft won’t play by the rules, you have to fudge…
IE7 rejects forced downloads (in this example I was using doing PDF, mp3, zip, and m4b files).
It opens the download dialog, chooses a location, and then commences to quit having downloaded 0 bits.
So, instead of the dutiful example elsewhere in this blog that chooses the correct content-type, length, transer encoding and so on…
We … READ MORE
htaccess file to restrict Godaddy
April 30th, 2010I’m using this to lock a directory of assets for a client on a godaddy hosting plan:
order deny,allow
allow from localhost
deny from all
and then accessing files there from with a php file that checks their Zend logged in/file permissions etc.
(search this blog for “file serve” in content to find the php script)
AWESOME!
PHP htaccess file serve script
April 30th, 2010search this blog for the “htaccess” file contents to put in a directory, then use this to serve up pdf files securely from said directory:
file serve php script:
first check Zend permissions…logged in, permissions granted, user active, expirations, etc…..
then:
<?
$file = “path/path/” . $_GET['file'];
//$file = “Broker_Admin/Materials/Course.pdf”;
header(‘Content-type: application/pdf’);
header(“Content-Disposition: inline; filename=”.$file);
/*header(“Content-Disposition: attachment; filename=”.$file);*/
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’) . ‘ GMT’);
header(‘Cache-Control: no-store, no-cache, must-revalidate’);
header(‘Cache-Control: pre-check=0, post-check=0, max-age=0′);
header(‘Pragma: anytextexeptno-cache’, true);
header(‘Cache-control: private’);
header(‘Expires: 0′);
readfile($file);
?>
then from wherever I want to call it I call this script and pass … READ MORE
jQuery bind select change to anchor window.open variable
April 29th, 2010add window.open() to an anchor tag…
HTML:
select dropdown changes the source:
<div class=”name”>
<select name=”tpom” style=”float: left; width: 100px; margin-right:20px; border: 1px solid #5A3C18;” >
<option value=”downloader.php?file=folder/file.mp3″>Mp3</option>
<option value=”downloader.php?file=folder/file.zip”>Zip</option>
<option value=”downloader.php?file=folder/file.m4b”>Ipod</option>
</select>
link or button gets source from dropdown via jQuery onReady function:
$(“div.name select”).bind(“change”,function(){
$(‘#button_download’).attr(‘href’,this.value);
windowUrl = $(this).val();
//console.log(windowUrl);
});
<a onclick=”window.open(windowUrl,’download’);return false;” id=”button_download”>Download</a>
log to the console in firefox firebug javascript
April 29th, 2010console.log(windowUrl);
but remove it once you’ve learned what you need to as it will break things in other browsers…
session_start() php when to do it again!
April 29th, 2010I was stuck for a bit there.
I have a page that loads via AJAX, but I had to modify it to work for Google’s googlebot #! system…
The googlebot logic senses that it’s googlebot, and uses PHP includes instead of the AJAX!
Well the includes don’t need the session_start() again, but the AJAX loads DO!
So, NOT to be forgotten, session_start() will work per LOAD, hard to explain that, but you can wrap your head around it…
fancy!
BETTER SOLUTION: Sessions manager class, framework or … READ MORE
fancy complex php force file download script
April 29th, 2010set_time_limit(0);
$file_path=’blah.pptx’;
output_file($file_path, ‘blah.pptx’, ”);
function dl_file($file){
$file = ‘blah.pptx’;
$filename = realpath($file);
$file_extension = strtolower(substr(strrchr($filename,”.”),1));
if (!file_exists($filename)) { die(“NO FILE HERE”); }
$ctype=”application/vnd.ms-powerpoint”;
header(“Pragma: public”);
header(“Expires: 0″);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0″);
header(“Cache-Control: private”, false);
header(“Content-Type: $ctype”);
header(“Content-Disposition: attachment; filename=\”$filename\”");
header(“Content-Transfer-Encoding: binary”);
header(“Content-Length: “.@filesize($filename));
set_time_limit(0);
@readfile($file);
exit;
}
function output_file($file, $name, $mime_type=”)
{
if(!is_readable($file)) die(‘File not found or inaccessible!’);
$size = filesize($file);
$name = rawurldecode($name);
/* Figure out the MIME type (if not specified) */
$known_mime_types=array(
“pdf” => “application/pdf”,
“txt” => “text/plain”,
“html” => “text/html”,
“htm” => “text/html”,
“exe” => “application/octet-stream”,
“zip” => “application/zip”,
“doc” => “application/msword”,
“xls” => “application/vnd.ms-excel”,
“ppt” => “application/vnd.ms-powerpoint”,
“gif” => “image/gif”,
“png” => “image/png”,
“jpeg”=> “image/jpg”,
“jpg” => “image/jpg”,
“php” => “text/plain”
);
if($mime_type==”){
$file_extension = strtolower(substr(strrchr($file,”.”),1));
if(array_key_exists($file_extension, $known_mime_types)){
$mime_type=$known_mime_types[$file_extension];
} else … READ MORE
basic php force file download script
April 29th, 2010<?php
$filename = $_GET['file'];
// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);
$file_extension = strtolower(substr(strrchr($filename,”.”),1));
if( $filename == “” )
{
echo “<html><title></title><body>ERROR: download file NOT SPECIFIED.</body></html>”;
exit;
}
switch( $file_extension )
{
case “pdf”: $ctype=”application/pdf”; break;
case “txt”: $ctype=”text/plain”; break;
case “html”: $ctype=”text/html”; break;
case “htm”: $ctype=”text/html”; break;
case “exe”: $ctype=”application/octet-stream”; break;
case “zip”: $ctype=”application/zip”; break;
case “doc”: $ctype=”application/msword”; break;
case “xls”: $ctype=”application/vnd.ms-excel”; break;
case “ppt”: $ctype=”application/vnd.ms-powerpoint”; break;
case “gif”: $ctype=”image/gif”; break;
case “png”: $ctype=”image/png”; break;
case “jpeg”: $ctype=”image/jpg”; break;
case “jpg”: $ctype=”image/jpg”; break;
case “php”: $ctype=”text/plain”; break;
default: $ctype=”application/force-download”;
}
header(“Pragma: public”); // required
header(“Expires: 0″);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0″);
header(“Cache-Control: private”,false); // required for certain browsers
header(“Content-Type: … READ MORE
meta no archive tag
April 28th, 2010<META content=”noarchive” NAME=”robots”>
jQuery scrollTo id
April 26th, 2010<style>
.pointer { cursor: pointer; }
</style>
<a class=”pointer” onclick=”$.scrollTo(‘#here1′, 1000); return false;”>Here</a>
<h3 id=”here1″>text</h3>
<h3 id=”here2″>text</h3>
MySQL phpMyAdmin text string find replace Query
April 25th, 2010update TABLE_NAME set FIELD_NAME =
replace(FIELD_NAME,’find this string’,'replace it with this one’);
example (for videodb to turn all “wanted” titles into “DVD” titles):
update videodb_videodata set mediatype =
replace(mediatype,’50’,’1’);
jQuery Javascript CSS gray out faded disabled element fadeTo() onload .ready()
April 23rd, 2010Simply fade the element you’d like faded, grayed, via your .ready onload jQuery function:
$(document).ready(function() {
jQuery(‘#top_button’).fadeTo(0, 0.5);
});
jQuery set tag element disabled
April 23rd, 2010jQuery(‘#element1′).attr(‘disabled’,'disabled’);
jQuery setTimeout fadeOut() fadeIn() show() hide() example
April 23rd, 2010This is a bit of craziness, still it works nicely to hide a element, show another, and then a bit later hide the latter, and again show the original.
$(‘#item1′).bind(‘click’,function() {
$(‘#item1′).fadeOut( function(){
setTimeout( function(){
$(‘#item2′).fadeIn(function() {
setTimeout( function(){
$(‘#item2′).fadeOut(function(){
setTimeout( function() {
$(‘#item1′).fadeIn();
}, 100);
});
}, 2000 );
});
}, 100);
}); return … READ MORE
HTML form field readonly and disable
April 22nd, 2010<input type=”text” readonly=”readonly” …. />
and equally useful
<input type=”text” disabled=’disabled’ …/>
Platform Environments Config for PHP applications example $_SERVER['HTTP_HOST']
April 21st, 2010You have to look at all of your different server returned variables for each platform,
and simply find one that you may reference and set per platform via script similar to:
// PLATFORM CONFIG
if($_SERVER['HTTP_HOST'] == ‘localhost’)
{
define(‘HOME’,'http://localhost/url.com/’);
define(‘PLATFORM_DB’,'localhost’);
}
elseif($_SERVER['HTTP_HOST'] == ‘www-staging.url.com’)
{
define(‘HOME’,'http://www-staging.soundstrue.com/’);
define(‘PLATFORM_DB’,'mktgdb.url.com’);
}
elseif($_SERVER['HTTP_HOST'] == ‘www.url.com’);
{
define(‘HOME’,'http://www.url.com/’);
define(‘PLATFORM_DB’,'mktgdb.url.com’);
}
Then simply access the variable when needed:
header(“Location:” . HOME . “event/forums/site/index.php/”);
$boarddir = HOME . “event/forums/dangerous/index.php/board,1.0.html”;
This way you can develop on your local machine, promote your … READ MORE
Loop through PHP $_SERVER variables / values
April 21st, 2010<?PHP
foreach($_SERVER as $key_name => $key_value) {
print $key_name . ” = ” . $key_value . “<br>”;
}
?>
PHP MySQL date & time reference
April 21st, 2010http://www.eltcalendar.com/stuff/datemysqlphp.html
thank you for this great handy reference!
pasted verbatim:
| Format | PHP | MySQL |
| Time | The function is: date(format) where “format” consists of the letters given below. |
The functions are: date_format(string, format) time_format(string, format) where “format” consists of the letters given below.) |
| hour, 2-digit, 12-hour (01-12) | h | %h |
| hour, 2-digit, 24-hour (00-23) | H | %H |
| hour, numeric, 12-hour (1-12) | g | %l |
| hour, numeric, 24-hour (0-23) | G | %k |
| minute, 2-digit (00-59) | i | %i |
| seconds, 2-digit (00-59) | s | %S |
| time, 24-hour (hh:mm:ss) | none, use date(“H:i:s”) | %T |
| time, 12-hour (hh:mm:ss AM/PM) | none, use date(“g:i:s A”) | %r |
| AM / PM (uppercase letters) | A | %p |
| am / pm (lowercase letters) | a | none |
| Days | ||
day name, full … READ MORE
Firefox password manager asking and asking… turn it offApril 19th, 2010options menu “Security” tab uncheck “Remember passwords for sites” http://robert.accettura.com/blog/2007/05/07/disable-password-manager/ jQuery Fancybox IE width issue don’t forget the doctype!April 14th, 2010Required, a doctype! example: <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” also, it never hurts to go get the latest versions of jquery and fancybox, at the time of this post: http://code.jquery.com/jquery-1.4.2.min.js & fancybox-1.3.1.js worked nicely… Lightwindow IE fixApril 13th, 2010Replace: this.checkImage = new PeriodicalExecuter(function(i) { this.checkImage.stop(); var imageHeight = $(‘lightwindow_image_’+i).getHeight(); $(‘lightwindow_image_’+i).setStyle({ if (this.imageCount == 0) { }.bind(this, i), 1); With: // We have to do this instead of .onload MySQL phpMyAdmin Query change table names syntaxApril 13th, 2010RENAME TABLE database_name.table_name TO database_name.new_table_name, database_name.table2_name TO database_name.new_table2_name; NOTE the comma and the semicolon! Prototype script.aculo.us form simple handlingApril 13th, 2010I’ve pretty much left script.aculo.us for jQuery for the most part, but sometimes I’m still animating with it, thought it would be good to make this easily and quickly reference-able just in case: The Form: <form id=”enewsform” name=”enewsform”> Googlebot make your AJAX crawlable #! simply explainedApril 13th, 2010http://code.google.com/web/ajaxcrawling/ But what? Put simply, in your URLs, that are currently: http://www.site.com/index.php#page90 First, make them: http://www.site.com/index.php#!page90 Your Javascript will just see the ! (bang) as a character, it won’t care, and will continue to work just fine Googlebot though, sees the ! and changes its query to: http://www.site.com/index.php?_escaped_fragment_=page90 So your index simply needs to see $_GET['_escaped_fragment_'] If it’s set, load page90 via PHP instead of AJAX, and there you have it, now Google will link the content it found via: http://www.site.com/index.php?_escaped_fragment_=page90 to the url: READ MORE Javascript HTML form field onFocus onBlurApril 13th, 2010<input name=”email” id=”email” type=”text” value=”Email” onFocus=”if(this.value == ‘Email’) this.value = ”;” onBlur=”if(this.value == ”) this.value = ‘Email’;”/> |





