Pages

Monday, November 24, 2014

Bypassing censorship for Wordpress

I came across this cool site:
http://www.daobydesign.com/free-plugins/censortive/. Haven’t tried it out myself yet, but this can be very useful for anyone making critical postings and wants to reach internet users in China (or any other country plagued by a repressive regime).

Saturday, November 22, 2014

Flickr Fallback Thumbnails

In my last post I wrote something about a small plugin for Flickr thumbnails. Well, here it is. It’s a quick-and-dirty version that assumes everything is working (no conditionals) but well, on this site it does as you can see ;)

The class is something like this:

'names' ) );
if (count($tags)==0) return false;
$r = rand(0, count($tags)-1);
return $tags[$r];
}

function get_flickr_img ($tag, $count=1) {
$tag = urlencode($tag);
$thumb_url = “”;
$url = ‘https://api.flickr.com/services/rest/?';
$url .= ‘method=flickr.photos.search&api_key=’.$this->api_key.’&tags=’.$tag.’&per_page=’.$count;
$url .= ‘format=’.$format;

if (!wp_get_http( $url )) return;

$xml = simplexml_load_file($url);
if (!$xml) return false;
# http://www.flickr.com/services/api/misc.urls.html
# http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg

if (count ($xml->photos->photo)>0) {
foreach ($xml->photos->photo as $photo) {
$title = $photo[‘title’];
$farmid = $photo[‘farm’];
$serverid = $photo[‘server’];
$id = $photo[‘id’];
$secret = $photo[‘secret’];
$owner = $photo[‘owner’];
if ($count>1) $thumb_url[] = “http://farm{$farmid}.static.flickr.com/{$serverid}/{$id}_{$secret}_m.jpg”;
else $thumb_url = “http://farm{$farmid}.static.flickr.com/{$serverid}/{$id}_{$secret}_m.jpg”;
}
}

return $thumb_url;
} // get_flickr_img

function flickr_thumb_init( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( empty( $html ) ) {
return sprintf(
‘,
$this->get_flickr_img ( $this->random_tag($post_id) ),
get_option( ‘thumbnail_size_w’ ),
get_option( ‘thumbnail_size_h’ ) );
}
return $html;
}
} //flickr_thumb

$ft = new flickr_thumb();

?>

Todo: integrate with open calais (see tagaroo; it would be great if they would have something like an API because I don’t want to hack their plugin – it could be so much more versatile than just autotagging. This is the kind of computing we need full control of because of bandwidth usage and other issues).

Wordpress doesn't recognize plugins that have spaces in the header declaration

This one took me a while to find out – I hope this post saves you some time. I was working on a simple Flickr API plugin for WordPress (will post and use it here), but all of a sudden my plugin stopped from showing up in my (multisite) admin back-end.

So I headed over to Google and looked if anyone had the same issue. There were a lot of comments about looking at multisite admin rather than the individual network site, some remarks about the contents of the header file – but none about its very syntax.

A few extra spaces. Come on, WordPress, why do you use such a strict parser to look at the plugin directory? Why not adding that extra \s* to that regexp you use to identify plugins?

Thursday, November 20, 2014

Using dashicons in Wordpress

I was working on a theme today, and wanted to use the neat retina-ready icons we see on the WordPress back-end since version 3.8 or thereabout.

This is easy – just load the font “dashicons” in your styles-queue (thanks @Jameskoster):

add_action( 'wp_enqueue_scripts', 'themename_scripts' );
function themename_scripts() {
wp_enqueue_style( 'themename-style', get_stylesheet_uri(), array( 'dashicons' ), '1.0' );
}

…and use the icons by setting the content of the :before pseudoclass to the code. Example:

.comment-link:before {
font-family: "dashicons";
content: "\f101";
}

An overview of all available icons can be found here.

Friday, November 14, 2014

Yandex translation API

Google Translate API does a great job, but it is a paid service. For those who don’t want to spend money on machine translation, or don’t want to go through the hassle of signing up and paying recurring fees, there is an alternative: the yandex API. It works with 30 languages, including Arabic, Azerbaijani, Belarusian, Bulgarian, Bosnian, Catalan, Czech, Danish, German, Greek, English, Spanish, Estonian, Finnish, French, Hebrew, Croatian, Hungarian, Armenian, Indonesian, Icelandic, Italian, Georgian, Lithuanian, Latvian, Macedonian, Malay, Maltese, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Slovak, Slovenian, Albanian, Serbian, Swedish, Thai, Turkish, Ukrainian, Vietnamese, Chinese.

It is an easy-to-use API: signing up and requesting an API key took me under 3 minutes. Just go to http://api.yandex.com/ and follow the instructions. It supports XML, JSON, and JSONP return string.

My English to Russian test translation, “Miru is a sweet girl”, returned

{
"code":200,
"lang":"en-ru",
"text":["Miru-сладкая девочка"]
}

Reference: http://api.yandex.com/translate/doc/dg/reference/translate.xml

Background noise

I found this simple but great idea on addcss.com. If you’re designing a “grungy” feeling web site, you can add some background noise to elements. This can easily be done with an inline transparent noise-png and a CSS-rule to set the right color.

.grunge {
background-color: #EF8;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ2c8TV1mAAAAG3RSTlNAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEAvEOwtAAAFVklEQVR4XpWWB67c2BUFb3g557T/hRo9/WUMZHlgr4Bg8Z4qQgQJlHI4A8SzFVrapvmTF9O7dmYRFZ60YiBhJRCgh1FYhiLAmdvX0CzTOpNE77ME0Zty/nWWzchDtiqrmQDeuv3powQ5ta2eN0FY0InkqDD73lT9c9lEzwUNqgFHs9VQce3TVClFCQrSTfOiYkVJQBmpbq2L6iZavPnAPcoU0dSw0SUTqz/GtrGuXfbyyBniKykOWQWGqwwMA7QiYAxi+IlPdqo+hYHnUt5ZPfnsHJyNiDtnpJyayNBkF6cWoYGAMY92U2hXHF/C1M8uP/ZtYdiuj26UdAdQQSXQErwSOMzt/XWRWAz5GuSBIkwG1H3FabJ2OsUOUhGC6tK4EMtJO0ttC6IBD3kM0ve0tJwMdSfjZo+EEISaeTr9P3wYrGjXqyC1krcKdhMpxEnt5JetoulscpyzhXN5FRpuPHvbeQaKxFAEB6EN+cYN6xD7RYGpXpNndMmZgM5Dcs3YSNFDHUo2LGfZuukSWyUYirJAdYbF3MfqEKmjM+I2EfhA94iG3L7uKrR+GdWD73ydlIB+6hgref1QTlmgmbM3/LeX5GI1Ux1RWpgxpLuZ2+I+IjzZ8wqE4nilvQdkUdfhzI5QDWy+kw5Wgg2pGpeEVeCCA7b85BO3F9DzxB3cdqvBzWcmzbyMiqhzuYqtHR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tUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
}

@import in CSS: no space

I tortured myself over a particular piece of emptiness. Not the existential void we’re thrown in by our creator, but the space I put before url in


@import url ("../twentytwelve/style.css");

This is for wordpress stylesheet development, and with the space, the child theme doesn’t load up the parent style.css. I just corrected it to


@import url("../twentytwelve/style.css");

and it’s working fine. I hope that this post if useful for whoever just stumbled upon it.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan