Archive for March, 2010

jQuery change anchor tag href url via select option

Tuesday, March 30th, 2010

<select name=”tpom” onchange=”$(‘#tpom_download’).attr(‘href’,this.value);”>
<option value=”media/tpom.mp3″>MP3</option>
<option value=”media/tpom.zip”>ZIP</option>
<option value=”media/tpom.m4a”>IPOD</option>
</select>
<div style=”float:left;width:75px;margin-top:-3px;”>
<ul name=”st_btn” style=”text-align: right; float: right;”>
<li name=”submit”> <a id=”tpom_download” title=”blah” href=”media/tpom.mp3″ onclick=”return false;”>Download</a></li>
</ul>
</div>

Moving WordPress DB changes and/or functions.php

Thursday, March 25th, 2010

change DB values

table:
wp-options

column:
option_name

fields:
siteurl
home

also to note in here:
blogname
upload_url_path
comment_moderation
rss_language
admin_email

ALTERNATE OPTION, (db inaccessible)
add a few lines to:
wp-content/themes/default/functions.php

lines:
update_option(‘siteurl’,’http://yourUrl‘);
update_option(‘home’,’http://yourUrl/soundstrue.com/podcast‘);

If the second option used not to be forgotten, as it will overwrite DB every time App loads…

WordPress Akismet (spam)

Monday, March 22nd, 2010

WordPress comes with the Akismet plugin.

Use it.

Reference: http://akismet.com/

How:

Create a dashboard.wordpress.com account  if you don’t already have one, & find your API key

then in your blog, activate the Akismet plugin, enter your key, reap the rewards.

This Blog proudly uses the following Widget Plugins

Thursday, March 18th, 2010

Google AdSense Widget

http://wordpress.smullindesign.com/plugins/google-adsense-widget

Google XML Sitemaps

http://www.arnebrachhold.de/redir/sitemap-home/

Simple Hit Counter

http://jungwirths.com/2009/03/simple-wordpress-hit-counter-plugin/

WP Simple Paypal Donation

http://www.tipsandtricks-hq.com/?page_id=942

Exec PHP

http://bluesome.net/post/2005/08/18/50/

Deactivate Visual Editor

http://plugindve.wordpress.com/

Google Analytics for WordPress

http://yoast.com/wordpress/analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=google-analytics-for-wordpress

Export Dreamweaver Sites CS4

Wednesday, March 17th, 2010

You can now multi-select sites in the site manager and export them, easy as pie.

http://www.owenwebs.com/2009/07/07/export-dreamweaver-cs4-site-info/

Runas administrator

Wednesday, March 17th, 2010

If runas isn’t in the menu when you right click on a file, add the runas option to that file type in the registry, here’s how:

http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/

otherwise:

can you run any other program that can edit that file with runas?

example, I wanted to edit C:\xampp\phpMyAdmin\config.inc.php as admin,

first run dreamweaver as admin and it will also be able to save as admin!

phpMyAdmin Server config.inc.php remote database connection

Monday, March 15th, 2010

C:\xampp\phpMyAdmin\config.inc.php

add this (or similar) at the bottom:

$i++;

$cfg[‘Servers’][$i][‘auth_type’] = ‘config’;
$cfg[‘Servers’][$i][‘user’] = ‘user’;
$cfg[‘Servers’][$i][‘password’] = ‘password’;
$cfg[‘Servers’][$i][‘host’] = ‘your_host’;
$cfg[‘Servers’][$i][‘verbose’] = ‘Description to appear in phpMyAdmin’;

//end

params/reference: http://wiki.phpmyadmin.net/pma/Config

And then control remote MySQL databases in your localhost/phpmyadmin

under Actions: Server: dropdown

*note: When connecting to a Godaddy DB, you must enable accessible remotely when creating the database!

PHP copyright year

Saturday, March 13th, 2010
echo date("Y");

Boot Startup Applications MSCONFIG

Monday, March 8th, 2010

Run

MSCONFIG

Perl Regular Expressions cheat sheet

Monday, March 8th, 2010

/.*/ : matches anything
/.*oose/ : wild card .*

[] : class
[a-z] : any lower case letter
[A-Z] : any upper case letter
[a-zA-Z] : any upper or lower case letter, notice runs together
[a-zA-Z0-9] : any upper/lower or zero to nine
[ a-z] : any lower case letter OR a space!
[\-] : any hyphen, notice the excerpting from special inner expression functionality \
[^a] : negated class, match if sentence does NOT have ‘a’

shorthands:
\d = [0-9]
\D = [^0-9]
\w = [a-zA-Z0-9_]
\s = [ \t\n\r\f]
\S = [^ \t\n\r\f]

In search string NOT classes additional things:
^ at beginning means it must start to match
$ at the end means it must end to match
\b then string means must be beginning of word
string then \b means it must be end of word
\B before or after means it must NOT be start or end

example:
my $example = “This is still a very strange sentence”;
if($example =~ m/\bstill\b/){ print “This string HAS the exact word ‘still’ in it somewhere at least once, not a variation thereof such as stillness”; }

example 2:
my $phone = (000) 000-0000;
if($phone =~ /^\(\d\d\d\) \d\d\d\d$/) { print “phone number formatted correctly”; }

Php db connection close()

Monday, March 8th, 2010

@mysql_close($dblink);

or the network persistence traffic cop might come calling…YOU

Php simple phone format

Monday, March 8th, 2010

$phone = 3334449999;
$phone = preg_replace(“/([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/”, “($1) $2-$3”, $phone);

MySQL comments

Monday, March 8th, 2010

start of line left only (must have space after dashes):
— comment

OR
/* */

example:

if(!$result = mysql_query(”
SELECT
products_id,
FROM
runwayProductInfo,
WHERE
products_id IN (‘545′,’100’)
/* hello */
— comment
ORDER BY FIELD(runwayProductInfo.products_id, ‘100’,’545′)
“)){ echo mysql_error(); exit; }

Php MySQL query shortcut syntax

Monday, March 8th, 2010

$query = “SELECT
o.FirstName, o.LastName, o.Addr1, o.Addr2, o.City,
s.Name AS State, s.Abbrv as StateAbbrv, o.ZipCode,
o.Phone1, o.EmailAddr, o.CCLastFour, o.CCExp, o.PromoCode
FROM orders o
INNER JOIN states s ON s.StateID = o.StateID
WHERE o.OrderID = ” . $this->_orderID;

CSS link rollover class change

Monday, March 8th, 2010

<a onMouseOver=”this.className=’on'” onMouseOut=”this.className=’off'” href=”10_9_08 MEETING.mp3″>October 9, 2008</a>

IE height CSS sheet hack example

Monday, March 8th, 2010

.class_name {
min-height: 10px;
height: auto !important;
/*ie6 min-height hack*/
height: 10px;
}

load IE only CSS stylesheet

Monday, March 8th, 2010

<!–[if IE]><style type=”text/css”>@import “css/ie_overide.css”;</style> <![endif]–>

Dreamweaver Turn OFF Design Notes

Monday, March 8th, 2010

Manage Sites
Edit Site
Left hand column ‘Design Notes’
Uncheck!

much cleaner SVN

JavaScript image preloader script

Monday, March 8th, 2010

var myimages = new Array();

function preloading(){

for (x=0; x<preloading.arguments.length; x++)
{

myimages[x] = new Image();
myimages[x].src = preloading.arguments[x];

}

}

preloading(
‘images/1.jpg’,
‘images/2.jpg’,
‘and_so_on.jpg’)
;

script.aculo.us Scroll to top of page

Monday, March 8th, 2010

/* Scroll to Top of Page Functino */
var scroll = { top: function(event) { new Effect.ScrollTo(‘top’, {duration: 1.0}); } }

in html place something like:

<div id=”top” style=”visibility:hidden;”></div>

in onclick or elsewhere place:

scroll.top();

jQuery document ready

Monday, March 8th, 2010

<html>
<head>
<script src=”jquery.1.3.2.min.js” type=”text/javascript”></script>
<script>
$(document).ready(function()
{
// display main_wrapper
$(‘.site_container’).css(‘display’, ‘block’);
});
</script>

</head>
<body>
<div id=”main_wrapper” style=”display:none;”>
Page Content
</div>
</body>
</html>

JavaScript script.aculo.us Fade & Appear + IE Internet Explorer FIX

Monday, March 8th, 2010

new Effect.Fade(‘left_block3’, { duration: 0.5 });
new Effect.Appear(‘left_block4′, { duration: 0.5, queue:’end’ });

FULL CODE:

Blocks that fade and appear look like this:

<div id=”block1″ style=”display:none;”>
<div id=”header3″>
<div style=”position:absolute;top:0px;”><img border=”0″ align=”left” alt=”blah” src=”images/blah.gif”></div>
<div style=”position:absolute;top:110px;right:0px;”><img border=”0″ align=”right” alt=”blah” src=”images/blah.gif”/></div>
<div style=”position:absolute;top:25px;left:50px;margin-right:30px;width:290px;color:#2A5041;”>
<em>copy<div style=”text-align:right;”>&mdash;P.R.</div>
</em>
</div>
</div>
</div>

CSS for blocks:

#block1, #block2, #block3, #block4, #block5, #block6, #block7, #block8, #block9 {
float: left;
position: absolute;
left: 635px;
top: 225px;
height: 375px;
width: 375px;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #000000;
padding-left: 0px;
display: inline;
line-height:1.5em;
text-align:left;
}

.smooth_it {
width: 68px;
height: 50px;
}

Full Javascript function:

/* ROTATING BLOCK */
var spot = 0;
var how_many = 7;
var current_rotator = ‘block1’;

function swap_block()
{
new Effect.Fade(current_rotator, { duration: 0.5, queue: ‘end’ });
spot++;
if(spot == 8){ spot = 1; }
current_rotator = ‘block’ + spot;
new Effect.Appear(current_rotator, { delay: 1.0, duration: 0.5, queue: ‘end’ });
rotatorer = setTimeout(“swap_block()”, 10000);
}

The keys, things to remember:

CSS defines the outermost block div, NOT the inner div, but DO note that it has an inner wrapping div (header3) that is NOT CSS defined.

The Internet Explorer IE fix is that if these things aren’t all perfectly done as described, IE simply won’t fade but will show/hide without transition, and furthermore, if the block’s background isn’t defined it may also granulate text rather than treat it as “has layout”.

JavaScript URL tracker function array

Monday, March 8th, 2010

<script>

/* URL Tracker */
last_page = new Array();
go_here = ”;

function tracker()
{

go_here = location.hash;
go_here = go_here.substr(1);
last_page.unshift(go_here);

}

function visit_last_remove_from_tracker()
{

go_here = last_page.shift();
//alert(go_here);
if(go_here == ”){go_here = ‘state_link_28’;}
if(go_here == ‘undefined’){go_here = ‘state_link_28’;}
return go_here;

}

</script>

JavaScript URL sniffer forward redirect

Monday, March 8th, 2010

<!–Let’s make sure this wasn’t loaded outside the framework! –>
<script src=”../js/forwarder.js” type=”text/javascript”></script>

<script>
function where_are_we(){

var pushoff = “http://url/folder1/base_url_for_site”;
var str = window.location.toString();
var temp = new Array();
temp = str.split(/pages/);
//alert(‘0 ‘ + temp[0] + ‘ 1 ‘ + temp[1]);
switch(temp[1])
{

case ‘/01.php’: window.location = “http://url/folder1/folder2/#state_lesson_more_1”; break;

}
//if(str.search(/pages/) != -1 ){ window.location = push_off; }

}
window.onload = where_are_we();

</script>

JavaScript use img onload tag to set variable

Monday, March 8th, 2010

<img onload=”javascript: number_of_accordians = 5;” src=”<? echo $prefix; ?>images/beauty-2.gif” border=”0″ alt=” ” style=”float:left; margin:0px 20px 15px 0;” />

JavaScript getElementsByTagName anchor tag CSS function

Monday, March 8th, 2010

function anchorcss() {

var elements = document.getElementsByTagName(“a”);
var limit = elements.length;
var i = 0;

for(i=0;i< limit;++i)
{

if(elements[i].getAttribute(“name”)) {

elements[i].onmouseover = elements[i].style.color = “#140b48”;
elements[i].onmouseover = elements[i].style.textDecoration = “none”;

}

}

}

CakePHP Time Helper: how to use it in a view

Monday, March 8th, 2010

First of all, in the controller, add it to the $helpers array:

var $helpers = array(‘Html’, ‘Form’, ‘Time’);

Then in the corresponding view, call it like this:

<p>Date Published: <?=$time->nice($post[‘Post’][‘date’]);?></p>

which effectively (in this case from the database in this example) turns this: 2010-01-02 21:54:00

into this: Sat, Jan 2nd 2010, 21:54

—- note: —-

without the Time helper we could of course do this specific thing with the plain ‘ol PHP date function this way:

<?=date(‘M jS Y, g:i a’,strtotime($post[‘Post’][‘date’]));?>

—-

$post[‘Post’][‘date’] is the value of the object Time will beautify, in this case

sent by the following function in the controller:

function view($id = null) {

if (!$id) {

$this->Session->setFlash(__(‘Invalid Post.’, true));
$this->redirect(array(‘action’=>’index’));

}
$this->set(‘post’, $this->Post->read(null, $id));

}

Semantic value: ul li, ol li vs. dl dt dd

Monday, March 8th, 2010
<dl>
<dt>Name: </dt>
<dd>John Don</dd>

<dt>Age: </dt>
<dd>64</dd>

<dt>Gender: </dt>
<dd>Male</dd>

<dt>Day of Birth:</dt>
<dd>12th May 1946</dd>
</dl>
VS.
Unordered lists
Use a <ul> tag where the order of items is not significant.
Ordered lists
Use an <ol> tag where the order of items is significant, e.g. listing events in time order, or race results

CakePHP debug

Monday, March 8th, 2010

need to see inside that specified array?

to be remembered:

app/views/posts/view.ctp

<? debug($post); ?>

which will also display records from associated models!

WordPress SESSIONS

Thursday, March 4th, 2010

simply add:

session_start();

to the start of:

wp-config.php

right at the top, after <?

If homepage : do a second “Loop” to show current article “post” WordPress

Thursday, March 4th, 2010

<? if(is_front_page()) : ?>
<? query_posts(‘showposts=1’); ?>
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href=”<?php the_permalink(); ?>“>Read more…</a></p>
<?php endwhile; ?>
<? endif; ?>

HTML Meta redirect 301 forward

Wednesday, March 3rd, 2010

<html>
<head>
<meta http-equiv=”refresh” content=”0;url=http://www.google.com”>
</head>
<body>
<a href=”http://www.google.com”>This page has moved</a>
</body>
</html>

Php Header 301 redirect examples

Wednesday, March 3rd, 2010

header(“HTTP/1.1 301 Moved Permanently”);

header(‘Location: ‘ . $new_website_url . $append_qstrings);

//echo $new_website_url . $append_qstrings;
exit;

Location of Windows Hosts Host file

Wednesday, March 3rd, 2010

C:\WINDOWS\system32\drivers\etc\hosts

forward browser requests for www.google.com
instead to IP 192.162.1.1
example:

192.162.1.1 www.google.com

Actionscript 3 Make Cursor a Hand

Tuesday, March 2nd, 2010

The goal:

SIMPLY turn the cursor into a hand
(over something that really isn’t a button, in this case it’s just a dynamic URLREQUEST function/link).

Nice and simple solution:

top of your AS3 package:
import flash.ui.Mouse;

in function reacting to mouse movement or loader success:
this.buttonMode = true;

Actionscript 3 Link

Tuesday, March 2nd, 2010

import flash.net.navigateToURL;
this.addEventListener(MouseEvent.CLICK, fOnClick);

private function fOnClick( e : MouseEvent ):void {
var request:URLRequest = new URLRequest(“http://www.google.com”);
navigateToURL(request);
}

Photoshop .ico plugin / Favicon instructions

Tuesday, March 2nd, 2010

http://www.grafikhaus.co.uk/dwtutsfavicon.htm

save to:

program files/adobe/photoshop/plug-ins/file formats

make it at 64 x 64 or 32 x 32, end at 16 x 16

insert into your doc:

<link rel=”Shortcut Icon” href=”/favicon.ico”>

Regex Expression Password Validation; 1 Uppercase; 1 Lowercase; 1 Number; length of 6 – 20

Tuesday, March 2nd, 2010

function valPassword($Password){

$pRegex = ‘/(?-i)(?m)^(?=.*?\d)(?=.*?[a-z])(?=.*?[A-Z])[a-zA-Z].{6,20}$/’;

if ( preg_match($pRegex, $Password)) { return TRUE; }
return FALSE;

}

Or this also works nicely:

function valPassword($Password)

{

if(
ctype_alnum($Password) // numbers & digits only
&& strlen($Password)>6 // at least 7 chars
//&& strlen($password)<21 // at most 20 chars
&& preg_match(‘`[A-Z]`’,$Password) // at least one upper case
&& preg_match(‘`[a-z]`’,$Password) // at least one lower case
&& preg_match(‘`[0-9]`’,$Password) // at least one digit

)

{

return TRUE;

}
return FALSE;

}

Resource:

http://regexlib.com/REDetails.aspx?regexp_id=31

CakePHP Setting up command line to bake

Monday, March 1st, 2010

http://i.justrealized.com/2009/02/16/how-to-run-xampps-php-cli-and-cakephp-console/

start baking:

C:\xampp\htdocs\project\app>”../cake/console/cake” bake

Inline Javascript CSS properties

Monday, March 1st, 2010

Inline Javascript CSS properties

dash replaced by capital

<a
href=”#”
onmouseover=”this.style.textDecoration=’none'”
onmouseout=”this.style.textDecoration=’underline'”

style=”color:#FFFFFF text-decoration:underline;”
>
Details
</a>