juust ~ php oddities

Unordered list of one element
  • rss
  • begin
  • about
    • vcard
    • WTF is BroJesus
  • php scripts
    • flickr wp widget
    • google multi key serp tool, php script
    • gwt plugin
  • php classes
    • php pagerank class
    • fibonacci class
    • robots.txt parser php class
  • serp
    • serp dashboard wordpress plugin
  • services

sneak preview

juust | 06/05/2009

I was working on a wordpress install for friends of mine. Marieke Zijlstra and Ruerdtsje made the layout, I stuffed it in a template.

I had to learn a bit of css and jquery and brush up on photoshop.

pallieter small

We still have to add the sidebar slideshow and add some pictures for rotating header graphics, I’ll do that after it goes live, it was a short term. The css does not validate completely, fortunately there are hundreds of css experts that can iron out the glitches in the stylesheet.

Maybe I’ll dig into css some more later and fix it myself, it’s pretty basic stuff.

When the site is live I’ll add a link to it.

Comments
No Comments »
Categories
juust, wordpress
Tags
template, wordpress
Comments rss Comments rss
Trackback Trackback

using wordpress custom pages for service templates

juust |

I was reading a discussion elsewhere on a rest service plugin for wordpress. Problem seemed that wordpress kept rerouting all requests to index.php. Most wordpress installs use server modules for url rewriting, where .htaccess contains a rule that checks first if a file exists on the server that matches the request. If it doesn’t, wordpress handles it. Unless you write an extra .htaccess rule to direct requests to the service endpoint, you have to have all endpoint files present under the request name. That’s awkward.

using custom pages

You can solve that by masking your service as a page. Wordpress tests if the file exists as ’single’ (page or post), and if a page exists with that permalink, wordpress generates the page.

I can write custom templates for pages. That template can be any file, so it can also be the main request handler of the REST service.

If I place my request handler in the template directory with a remark

/* Template Name: XMLServices
  1. */

then wordpress adds it to the custom pages list, that I can use on the backend when I add a new page.

custom content-type headers

Services usually reply with json or xml data, and not with wordpress content pages. I need a custom file header.
black magic

No problem, if I leave get_header(); out of the page template, I can specifiy my own header and use an text/xml content type or vcard text/directory content type.

I made a small example by adding my twitter friends timeline as xml output to the blog menu, by placing a file xmlservices.php in the template directory :

/* Template Name: XMLServices
  1. */
  2.  
  3. $x = simplexml_load_file('http://www.juust.org/friends_timeline.xml');
  4. if($x) {
  5.  
  6. //make the XML-header :
  7. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  8. header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
  9. header("Cache-Control: no-cache, must-revalidate" );
  10. header("Pragma: no-cache" );
  11. header("Content-type: text/xml");
  12.  
  13. //make some xml :
  14. $xml = "< ?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  15. $xml .= "<rows>";
  16. $xml .= "<page>1</page>";
  17. $xml .= "<total>15</total>";
  18. foreach($x->status as $s) {
  19.  $xml .= "<row id='".$s->user->id."'>";
  20.  $xml .= "<cell>< ![CDATA[".$s->source."]]></cell>";  
  21.  $xml .= "<cell>< ![CDATA[".$s->text."]]></cell>";
  22.  //$xml .= "<cell>< ![CDATA[".$s->user->screen_name."]]></cell>";    
  23.  $xml .= "<cell>< ![CDATA[".$s->user->name."]]></cell>";  
  24.  $xml .= "<cell>< ![CDATA[".$s->user->screen_name."]]></cell>";  
  25.  $xml .= "<cell>< ![CDATA[".$s->user->followers_count."]]></cell>";  
  26.  $xml .= "</row>";  
  27. }
  28.  
  29. $xml .= "</rows>";
  30. echo $xml;
  31. } else {
  32. //no data, relocate to the blog index or something
  33. }

Then added a page services with xmlservices as template. I can make a whole tree of xml service pages, as long as I use my XMLServices template when I make the page. You can use both http-get-queries and http-post.

Adding a vCard

wordpress custom page You can also add your  vcard, if you work business to business that comes in very handy.

I picked Troy Wolf’s vcard class of the net, made a file vcard.php with vcard as Template Name and put it in the template directory.

/* Template Name: vcard
  1. */
  2.  
  3. //include the class file
  4. include('../../../classes/vcard.class.php');
  5. //here we go : add my personal data
  6. $vc = new vcard;
  7. $vc-&gt;display_name ='Juust';//….
  8. $vc-&gt;download();

I added a empty new page with ‘about’ as parent and vcard as custom template, published it and now anyone can download my vCard straight from the ‘about’ menu.

Comments
No Comments »
Categories
wordpress
Tags
development, vcard, wordpress
Comments rss Comments rss
Trackback Trackback

faking links & dblclick search

juust | 26/04/2009

Being a noob at jquery, I was very satisfied with these two : the first is a one liner to search the blog when someone doubleclicks on a word, the second is an easy fake anchor.

double click search

If you double click (in some browsers?) you select the word under the cursor. Bind the double click event of a paragraph element to a function that uses the standard worpdress search, using bloginfo(’home’) to get the home url, with the selected text as ?s= search parameter, and relocates to the search result page.

  1. jQuery(document).ready(function() {
  2.  jQuery('p').bind('dblclick', function(e){
  3.   window.location = '&lt;?php bloginfo('home'); ?&gt;/?s='+getSelectedText();
  4.     });
  5.  
  6. });
  7.  
  8. function getSelectedText(){
  9.     if(window.getSelection){
  10.         return window.getSelection().toString();
  11.     }
  12.     else if(document.getSelection){
  13.         return document.getSelection();
  14.     }
  15.     else if(document.selection){
  16.         return document.selection.createRange().text;
  17.     }
  18. }

fake a link

You can also fake a hyperlink, makes seo life easier.

Any surplus inline element will do, in this case the dfn tag, as most have the title attribute that I use to store the url  :

<dfn title="http://elgoog.rb-hosting.de/index.cgi?dir=/Top/News/&amp;page=Satire/">hyperlink</dfn>

Style the dfn element with a bit of css :

  1. dfn {
  2.   color: blue;
  3.  text-decoration: underline;
  4.  font-size: 14px;
  5. }

…and it looks like a hyperlink, add some jQuery to bind a click event on the dfn element to a function that jumps to the title attribute.

  1. jQuery(document).ready(function() {
  2.  
  3.  jQuery('dfn').bind('click', function(e){
  4.   window.location = jQuery(this).attr('title');
  5.     });
  6. });

…and we have the link that search engines do not index as a link, but it does work.

 

Comments
No Comments »
Categories
wordpress
Tags
jquery, wordpress
Comments rss Comments rss
Trackback Trackback

« Previous Entries Next Entries »

Recent Posts

  • geert wilders
  • gone till september
  • socialize me
  • Pagerank sculpting session
  • wish you were here

click me!
rss
Comments rss
Blog Directory
Web Developement Blogs - BlogCatalog Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine
Blog Flux Directory
joopita.com free web directory and search engine
design by jide
sitemap
22258 confirmed spam kills