h4x3d.com

- h4x3d.com

Archive
Tag "code"

I am not discussing whether it should be done or not, but just saying where to do it.
W3 Total Cache is a great plugin and they surely deserve some SEO juice / kudos for their work, but I have seen questions unanswered on the net of people not knowing where to delete pieces of comments that are inserted into their pages. Again, I am not touching the ethics of removing credits, but just offer the tools. Use as liked.

/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php

and uncomment/change as desired.

from

/wp-content/plugins/w3-total-cache/w3-total-cache.php

you can find the lead (the references to the above mentioned file).
find the lines using the search for the html comment…

Read More

Today I wanted to publish a real quick post about how to embed a paypal button into your wordpress post. A topic that has been covered many times elsewhere (if you consult google), but yet many paypal buttons failed to hide the merchant’s email address which would result in evil spam to be sent. Anyhow, I thought posting this quick article would take max 5 minutes or so, but it turned out to be more difficult: WordPress MU for security purposes does not allow specific HTML code to be included in posts or pages.
This is for security reasons, as mentioned before, because in a multi-blog environment people could post all sorts of crap to compromise your site, server and work, ultimately driving you nuts and causing all sorts of havoc.

After some Googling I found several interesting articles, most of them repeated themselves and said “well.. edit the ksas.php file in wp-includes” and then stated a long-list with many interesting HTML pieces. This works, but a plugin is more fancy I thought: so I googled on and found a plugin called “unfiltered” content WordPress MU, released by the WordPress guys. This is in so far cool, as you can either stick it in the mu-plugins folder and have it sidewide, or in the regular plugins folder and just activate it on a blog by blog basis. Since I am running this WordPress MU installation on my own and do not have posts to monitor for “havoc causing script includes”, I decided to go for the plugin and enable it side-wide. This way I can upgrade my wordpress mu next time a new version comes out and keep my sanity (because by then I would probably have forgotten about the includes folder and the php file that I need to update every time…)

Hope this helps,
best,
jez

Read More

update: f§*king wordpress mu won’t let me enter tags in my posts. I have tried the wordpress RAW plugin and other filters, but still. more updates on this tomorrow -> solution

There are different approaches to doing this (adding a paypal button to your wordpress page, or any html or php website):

You can copy&paste the code you find on most pages and wonder why you get really a lot of spam emails
or you can use the “secure merchant id” code from paypal
or you can grab a plugin at wordpress.org

To explain the first (revealing code)

<form name=”_xclick” action=”https://www.paypal.com/cgi-bin/webscr” method=”post”>
<input type=”hidden” name=”cmd” value=”_xclick”/>
<input type=”hidden” name=”business” value=”user@spam-me-please.com”/>
<input type=”hidden” name=”item_name” value=”Customer Service”/>
<input type=”hidden” name=”currency_code” value=”USD”/>
<input type=”hidden” name=”amount” value=”1.00″/>
<input type=”image” src=”http://www.paypal.com/en_US/i/btn/btn_donate_LG.gif” border=”0″ name=”submit” alt=”Make payments with PayPal - it’s fast, free and secure!”/>
</form>

While this has its advantages: you can easily specify the parameters, it also has the problem that your email address is very likely to be scraped and spammed by bots. So next time you receive one of those fake paypal “you need to click here to reactivate your account” emails… guess why you are receiving it.

I use the second version, the paypal secured id, because I am not too keen to exposing (any) email address to spam bots. The code below will generate a paypal button with my id in it. To change that or to get your code you need to login to paypal and get it from the merchant tab. Or you can enter “paypal button” in the search field top right of the page.

2) Click on Merchant services.
3) Click on websites payment standards.
4) Click on accept contributions.
5) Click on get donation button.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick"/>
<input type="hidden" name="hosted_button_id" value="10155388"/>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" style="width: 100px; float: right;" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"/>
</form>

And now to the fun part actually: you will not be able to copy and paste the code(s) mentioned above, because wordpress will strip the input fields and nothing will display. So unless you are putting this code into your template (e.g. by including it in a separate php file), it won’t work, I believe.

You can however grab a wordpress plugin, like this paypal plugin to help you out.

Also of help – this support post at wordpress

hope this helps anyone,
best,
jez

Read More

I always laugh at sites that have “old” copyright information on them and I almost forgot to update mine.
No-longer shall I be doing that with thanks to PHP´s little helper in form of the following one-line (I call it) “New Year Update Copyright script” in PHP:

What it does is quite obvious: it outputs the current year, so for instance you could have it say:
(c) 2006 – (php block here)

this would render (c) 2006 – 2008

- hope this helps anyone.
Now as I look at this issue, I wonder if I was smart enough to build that into all my themes. If not, I got some revising to do after I have finished my next exam in January (11th).

Update: bleh I put

in pretty much all my themes, which is stupid I fear – but for now it is noted on my to-do list and will be sorted out with the next wave of updates!

Update: Lorelle put the_time(); too, so I guess I might as well leave it like that.

Read More

Do you know the following situation- You are downloading thousands of (small) files from your ftp (server) and it is annoyingly slow and time consuming… If you have shell access to your server, e.g. you can use Putty, logon and cd to your file directory (often httpdocs or www) and execute the following code:

tar -pczf fatfile.tar.gz *

This will create a tar.hz archive with the name of fatfile.tar.gz
It will include all files of the current directory and all sub-directories.

Now you can easily download this file instead of many small files (as experienced before).
If you don’t have shell access (look- even Dreamhost offers this feature for $6,95/month),
you might consider getting your own Virtual Private Server as I did.

Read More

Hi, one of the people commenting here asked for a way of displaying code in one of my themes.
For ages I have been using the following code and it worked flawless in connection with the code markup plugin for wordpress:


.primary pre#hack {
		white-space: pre-wrap;		/* css-3 */
		white-space: -moz-pre-wrap !important;		/* Mozilla, since 1999 */
		white-space: -pre-wrap;		/* Opera 4-6 */
		white-space: -o-pre-wrap;	/* Opera 7 */
		word-wrap: break-word;		/* Internet Explorer 5.5+ */
}

.primary pre {
  overflow: auto;
  cursor:pointer;
  position:relative;
}

.primary pre code {
  display: block;
  margin:10px;
  padding:4px;
  border:1px solid #ddd;
  background:#F5F5F5;
  font:10px Lucida Sans Typewriter, Courier, monospace;
}
.primary can be changed to what you need, e.g. .post or .entry

Usage within WordPress
Simply go to the “code” editor of WordPress and paste your code.
Surround it by a

 and  tag and add the id of "hack" to the
.
(
 stuff here  
Read More

Hey all, in case you wondered why the 21 from my short bio turned to 22 overnight…
… I am now one year older. I really liked the 21, kind of- 22 looks stupid, doesn’t it?

Anyhow I am currently still on the road and will be reading through all the comments and mails from the past 10 days.
Feel free to leave your greetings here, I will be thankfully replying one-by-one.

If you are interested in the age-script code behind the age-calculation I use on this page, here it is (I found it on Google after some research):


< ?php

  //calculate years of age (input string: YYYY-MM-DD)
  function age($age){
    list($year,$month,$day) = explode("-",$age);
    $year_diff  = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff   = date("d") - $day;
    if ($day_diff < 0 || $month_diff

This should return 22 today!

If you want to output the age AGAIN, do not use the full function again, but only:



Read More

Moo.tools is neat, I love it and use it whenever I can, but one thing is still bugging me: its size.
Even though moo.tools can be downloaded compressed (using the great php5 version of dean edward’s packer), I personally find 18kb of javascript too much.

So I started researching a bit with Google and found out different way of compressing moo.tools (or actually whatever javascript you have) even further:

The first method, which I am using works like this:
+ You rename your javascript file (moo.tools) from the original filename.js to filename.js.php
+ Open the file with your favourite editor and add the following line just at the very TOP of the code:



+ Next, scroll down to the end of the file in your editor and add the following to the bottom:



+ Save your file and upload it.

Now add it to your website using the old HTML code, but keep in mind to add the .php-file extension.
It might look like this:



I was able to reduce the whooping 18kb moo.tools down to 9kb this way. Well, actually I did not do anything, but the server and its php and zlib.

Other methods:
At the top of Javascript:



.htaccess method
Save a compressed javascript file as *.jgz, and write .htaccess like this.


RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ".*Safari.*" [OR]
RewriteCond %{HTTP:Accept-Encoding} !gzip
RewriteRule (.*)\.jgz$ $1\.js [L]

AddType "text/javascript;charset=UTF-8" .jgz
AddEncoding gzip .jgz

Filesmatch .htaccess method:



ForceType text/javascript
Header set Content-Encoding: gzip

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*)\.js$ $1\.js.gz [L]
ForceType text/javascript

Sources / Ideas:
1. paulstamatiou.com
2. randomnetworks.com

Read More

I am now using the WordPress Loop to output my asides, details below

Okay, so first of all to clarify things, I am not going to actually code or build a (new) sideblog plugin for wordpress here, I am going to comment on existing sideblog plugins and compare them. In regard to the promising title, I will than come up with a sideblog alternative, which will (definatly) work on everyone’s blog.

You probably wonder how people display those small articles about their daily ramblings, quick notes or links they have found on the internet on their blogs. You might also have read something about ‘asides’ in WordPress on other blogs.

In order to display those miniblog articles (or sidenotes/asides) on your WordPress blog, you could either

  1. Use a special sideblog plugin (examples listed below)
  2. Hard code a piece of content into your theme template
  3. Include a php file which is updated externally
  4. Do a mixture of all those three things (which I do)

1. Existing Sideblog or Miniblog plugins for WordPress

At first I have tried out KatesGasis’ sideblog (v.3), but for me it did not work out like the author described his plugin. The sideblog showed, but the pages however disappeared and my blog was creating random 404 errors. Some months later, other bloggers were also facing this problem. Finally, the 404 issue would be addressed by the plugin author himself. Future versions of the Sideblog plugin were released, but without any effect. It is currently in built 3.6 or so, but still does not work for me. It is rather nice and simple, but without a fix to the 404 issue, worthless for on-site use.

The next plugin I have tried out was Miniblog. The original author of this plugin was Ryan Poe, but he gave up the coding on this project and turned it over to Joe. After some juggling through the right site, finding the right version and getting it installed correctly (the docs were missing in the first zip file, which made the plugin display dodgy) I tried it out and was quite satiesfied. The tagging system (simpletagging) still worked, no 404s, pages were loading fine and the sideblog showed. After having posted another entry to my miniblog, it also showed up. How gross, because I set it to display only one record. Fiddling with the source code solved this problem, but another problem was added: In combination with the in-series plugin (by REM state), entries that are part of a series are shown above the miniblog entries.

2. Quite confusing, and annoying. Since I did not want to drop the in-series plugin, I decided to hard-code my asides into my theme templates. Soon I was annoyed as well, also I did not have an archiving function of my posts as I was adding them in direct html code to the template.

3. I used the following code to ease the update process by only having to edit one external file, rather than navigating all the way up to my theme folder:


This of course was also no solution to the missing asides/sideblog problem, as the archiving option was missing.

4. Recently I came across a plugin called Front Page Excluded Categories, Instructions and FAQ can be found on the official wordpress.org website. It does what its name suggests: Exclude on specific category from showing on your blog frontpage. I figured out (nothing new to some I guess), that I could use this to hide my asides category from the frontpage. Then use the categories feed and re-insert this RSS-Feed into the main site template (theme) using another RSS-Feed plugin or some magpie-feed code. Voila, problem blown away! It works out of the box. You can use a RSS Importing Plugin such as Friends RSS Aggregator or FirstRSS or (what I am currently using) jRSS. If your feed is getting “douged” up, run it through Feedburner and import the (cleaned) feedburner RSS.

This guy (geeked.org) had a similar idea, but did not get it to run.


have_posts()) : $my_query->the_post(); ?> < a href="" rel="bookmark" title="Permanent Link to ">

Is what I use now to display my asides!

(you need to fix the php tags though! e.g. move the brackets. I need a better code highlighter, seriously!)

Read More