Slidernav

Slidernav is een jQuery plugin dat met behulp van jQuery en CSS een iPhone Stijl Contacten Lijst maakt. Kan vast van pas komen voor je eigen website.

Posted in Javascript | Leave a comment

How to: Related Posts with Thumbnails in WordPress without Plugins

Related posts can be easily displayed with plugins, but did you ever wonder how you could display related posts with a Thumbnail without using a Plugin? In this article, we will share two different algorithm which you can use to generate related posts with thumbnails and avoid using any plugin.

Note: We will utilize the built-in WordPress Post Thumbnail Function. So it is best if you implement this.

Related Posts by Tags

WordPress has this amazing taxonomy known as “Post Tags” which you can use. You can tag each of your posts with multiple keywords. This algorithm would find other posts with any one of the tag that the current post has and will list them.

<?php $orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
‘tag__in’ => $tag_ids,
‘post__not_in’ => array($post->ID),
‘posts_per_page’=>5, // Number of related posts that will be shown.
‘caller_get_posts’=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {

echo ‘<div id=”relatedposts”><h3>Related Posts</h3><ul>’;

while( $my_query->have_posts() ) {
$my_query->the_post(); ?>

<li><div><a href=”<? the_permalink()?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_post_thumbnail(); ?></a></div>
<div>
<h3><a href=”<? the_permalink()?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a></h3>
<?php the_time(‘M j, Y’) ?>
</div>
</li>
<? }
echo ‘</ul></div>’;
}
}
$post = $orig_post;
wp_reset_query(); ?>

The above code is looking at the current post ID and all tags which are associated with it and it uses the wp_query function to look for all other posts that matches any original tag and display them. You can style the post anyway you want them.

Advantage: Most codes on the web cannot be used within the main post loop. Because the related posts are placed right after the main post and above the comments, this code is very helpful. We are saving the current post ID of the main loop and then recalling it at the end of our related posts code. Usually when you don’t do it this way, the two post ID codes gets mixed up and then the comments start acting weird which can break the comments, other plugins related to comments such as numbering system etc. So this code is good and it works.

Usage: Place this code anywhere you like in your single.php and it will work. But most of the time it is placed right above the comments in the main loop.

Related Posts by Category

This algorithm would find other posts within the same category as the current post, and it will list them as related posts. The advantage of this technique is that you will never have a blank spot for your related posts section.

<?php $orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

$args=array(
‘category__in’ => $category_ids,
‘post__not_in’ => array($post->ID),
‘posts_per_page’=> 2, // Number of related posts that will be shown.
‘caller_get_posts’=>1
);

$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo ‘<div id=”related_posts”><h3>Related Posts</h3><ul>’;
while( $my_query->have_posts() ) {
$my_query->the_post();?>

<li><div><a href=”<? the_permalink()?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_post_thumbnail(); ?></a></div>
<div>
<h3><a href=”<? the_permalink()?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a></h3>
<?php the_time(‘M j, Y’) ?>
</div>
</li>
<?
}
echo ‘</ul></div>’;
}
}
$post = $orig_post;
wp_reset_query(); ?>

This technique utilizes the same functions as the one above except we are just using the different criteria.

If you are creating a new project, or working on a client’s site, this could be very helpful.

Posted in Programmeren | Leave a comment

Wat doet geld met ons?

Ik kan iets niet toegeven als het niet zo is. Geld is niet belangrijk. Als je weet dat geld vooral draait om gezondheid van de mensen en macht. En niet om olie zoals men ons probeert wijs te maken.
Voorbeelden wat geld doet:
- De tandarts luistert niet naar de cliënt maar voert de behandeling gewoon uit.
- De huisarts verkoopt pillen die zogezegd wetenschappelijk zijn onderzocht van een groot farma concern waar biljoenen in omgaat. Natuurlijk kan sommig medicijn wel je leven redden!
- Er wordt van een ziekte een epidemie gemaakt, zoals de Mexicaanse griep, terwijl het geen epidemie is.
- Overheid redt de banken als reden om extra bezuinigingen door te voeren.
- Bank verdient rente aan geld wat niet bestaat.
- Agressieve verkopers aan deur of telefoon.
- Oplichting, bedriegen, afzetten.
- Ongeoorloofde besparingen op veiligheid.
En zo zijn er nog veel meer dingen! Kijk al die rampen die gebeuren.
Maar stel je voor dat andere dat niet inzien. Stel je voor wij doen niets? Stel je voor mensen die werken in deze tak hebben dit niet door?
Iedereen heeft wel iets. Ik ook! Als iedereen door heeft dat gezondheid aan geld is gekoppeld wilt iedereen van zijn geld af. Een zwerver die uit de vuilnisbak eet nooit ziek? Vertel mij eens hoe dat kan? Eten weggooien is niet nodig!
Internet is gelukkig iets van ons! Maar wist je dat er een groot geheim is? Iets dat waarschijnlijk bijna niemand weet. Ik weet niet hoe ik het het beste kan uitleggen. Het is heel ingewikkeld. Maar communicatie met de andere kant van de wereld is zo snel mogelijk omdat er geen plaats is. Of wel geen beperking in ons doen en laten… Ik ben nog niet zover. Misschien is dat de vierde dimensie (eind december volgens maja kalender) ofzo…
Maar wie weet komt je wat bekend voor. Het kan zo zijn dat andere mensen ook bezig zijn met deze bewustwording. Of op een andere manier. Ik weet het niet.
Kan ook dat ik nu allemaal onzin eruit kwak van andere kwakzalvers waar ik dingen van heb gelezen.
Posted in Kredietcrisis | Leave a comment

Tips voor Adsense sites of Amazon websites

Extra inkomen met WordPress blogs is te halen via de integratie van Amazon Widget advertenties en Clickbank affiliate advertenties op een Adsense site.

O juist het tegenovergestelde: Adsense advertentie blokken en Clickbank advertenties op een Amazon site.

Met Adsense sites je automatisch berichten plaatsen met Shopzilla en Clickbank ads.
Met Amazon websites kun je automatisch berichten plaatsen van Amazon product reviews.

Posted in Geld verdienen | 1 Comment

Schaduw in tekst

Maak een schaduw in een tekst. Voorbeeld:
text-shadow:#000 2px 1px;

Posted in Programmeren | Leave a comment

Highscore bijwerken met Flash en PHP

Het is lastig om dit op veilige manier te doen.

Een paar links die informatie hierover geven:
http://www.phpfreaks.com/forums/index.php?topic=246534.0
http://ricardocabello.com/blog/post/286
http://stackoverflow.com/questions/467449/when-posting-a-form-with-urlrequest-how-to-include-cookies-from-browser-session
http://blinkdagger.com/flash/creating-high-score-table-in-adobe-flash-cs3/

En op Youtube verschillende videos met de naam “World of Webcraft – Ready Member PHP Session Variables On Your Flash Game Page”.

Posted in PHP, Programmeren | Leave a comment

Hoe gebruik je Microsoft Translator API met PHP?

Hierbij 2 goede links met meer informatie:
http://grilla.co.uk/2011/09/microsoft-translator-and-php/
http://www.viawindowslive.com/Articles/Translator/GetStartedusingtheTranslatorwithPHP.aspx

Microsoft have been offering an alternative to the Google Translator for a while now, and I’ve been using it commercially for one of our clients. It’s been free to use since forever, and it’s a good offering.

In the recent Microsoft BUILD conference, the Azure Marketplace was announced. It’s a centralized portal where you can purchase access to Microsoft’s offerings. This means that there is a system of tiered payment schemes for access to their applications. In the case of Microsoft Translator, you now have to purchase API access on a PER translation or PER transaction basis.

Nothing wrong with that, even Microsoft has to make their services sustainable. (It’s also a bit cheaper than the Google Translate API too, so that’s always a winner!) However, it’s not quite so straightforward!

I’ve been using the Microsoft Translator API freely for about a year now. Previously, you would generate your application ID, and simply connect to either their SOAP, HTTP or AJAX APIs with the app ID, and query away until your hearts content.

However, with the advent of the Azure Marketplace, Microsoft have done away with the appID and have introduced an OAuth authentication system. Now before you start worrying – don’t. If like me, you’ve had a nightmare with OAuth in the past, then you would be right to be dismayed. But Microsoft have delivered an authentication method that is very simple to query. We’re not actually having to consider much in terms of OAuth for ourselves – we’re just required to make an HTTP POST to a URL, and retrieve a token which we then use in our application.

In this article, I’m going to provide all of the code to get a complete translation working, along with a bit of discussion about why we’re doing certain things.
The authentication class
We need an OAuth token to authenticate ourselves with Microsoft, before using any of their services. When I originally read about this – I’ll be honest with you – I was concerned. I’ve heard horror stories about OAuth, and how it can cause more problems than it solves.
Luckily, that isn’t the case here, as it’s very easy to retrieve and use the authentication token. As such, the class that I’ve written is relatively simple, while having a number of features that will make your life easier. It’s also been designed to be used globally across the whole of the Azure Marketplace, so it’s largely reusable for other Microsoft services that use OAuth.AzureMarketplaceAuthenticator.class.php
I’m going to assume that you’ve already got your account set up correctly on the Azure Marketplace, and that you have a DataMarket account set up. In this, you will have a Client ID and a Client Secret, both of which are used to request the token.
The token has an expiry time, so we retrieve the it and store it for that period (minus ten seconds, for safety). When we then need to use it, we either use the stored version, or request a new one. This is handled by calling a single method (get_token):123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 * @version $Id: $ */ /** * AzureMarketplaceAuthenticator * * Description: * * @author David Wilcock  */class AzureMarketplaceAuthenticator {    /**    * Directory of the token file    */   const TOKEN_DIRECTORY = ‘/tmp/’;    /**    * Grant type    */   const GRANT_TYPE = ‘client_credentials’;    /**    * OAuth query URL    */   const QUERY_URL = ‘https://datamarket.accesscontrol.windows.net/v2/OAuth2-13′;    /**    * The application scope    *    * @var String    */   private $str_application_scope;    /**    * Client ID from your application in Azure DataMarket    *    * @var String    */   private $str_client_id;    /**    * Client Secret from your application in Azure DataMarket    *    * @var String    */   private $str_client_secret;    /**    * The file where the token is stored    *    * @var String    */   private $str_token_file;    /**    * Both arguments are required for ANY operation, which is why they are in    * the constructor.    *    * @param String $str_client_id    * @param String $str_client_secret    */   public function __construct($str_client_id, $str_client_secret, $str_application_scope) {       $this->str_client_id = $str_client_id;      $this->str_client_secret = $str_client_secret;      $this->str_application_scope = $str_application_scope;       $this->str_token_file = self::TOKEN_DIRECTORY . sha1($this->str_client_id . $this->str_client_secret);    }    /**    * Retrieve the OAuth token to be used in Microsoft Datamarket Applications    *    * @return String    */   public function get_token(){       if ($this->token_has_expired()) {         $str_token = $this->request_new_token();      } else {         $str_token = $this->get_current_token_data();      }       return $str_token;    }    /**    * Has the token expired?    *    * @return Boolean    */   private function token_has_expired() {      if (file_exists($this->str_token_file)){         if ($this->get_current_expiry() <= time()){            return TRUE;         } else {            return FALSE;         }      } else {         return TRUE;      }   }    /**    * Gets a new token, stores and returns it    *    * @return String    */   private function request_new_token() {      $obj_connection = curl_init();      $arr_query_bits = array (         ’grant_type’ => self::GRANT_TYPE,         ’scope’ => $this->str_application_scope,         ’client_id’ => $this->str_client_id,         ’client_secret’ => $this->str_client_secret      );      $str_query = http_build_query($arr_query_bits);       curl_setopt($obj_connection, CURLOPT_URL, self::QUERY_URL);      curl_setopt($obj_connection, CURLOPT_HEADER, 0);      curl_setopt($obj_connection, CURLOPT_FOLLOWLOCATION, 1);      curl_setopt($obj_connection, CURLOPT_RETURNTRANSFER, 1);      curl_setopt($obj_connection, CURLOPT_POSTFIELDS, $str_query);      curl_setopt($obj_connection, CURLOPT_POST, TRUE);       $str_response = curl_exec($obj_connection);      $obj_response = json_decode($str_response);       if (is_null($obj_response)){         throw new Exception(“Response wasn’t VALID  - {$str_response}”);      }       if (isset($obj_response->error)){         throw new Exception($obj_response->error_description);      }       $this->store_token_response($obj_response);      return $obj_response->access_token;   }    /**    * Reads the token file.    * Forces a re-read using clearstatcache for thread safety    *    * @return String    */   private function read_token_file() {      $str_token = file_get_contents($this->str_token_file);      clearstatcache();      return $str_token;   }    /**    * Stores the token and expiry time as a json encoded string    *    * @param StdClass $obj_response    */   private function store_token_response($obj_response){      $arr_token_data = array(        ‘expires’ => time() + ($obj_response->expires_in – 10),        ‘data’ => $obj_response->access_token      );      file_put_contents($this->str_token_file, json_encode($arr_token_data));   }    /**    * Gets the token from the current file    *    * @return String    */   private function get_current_token_data(){      $arr_token = json_decode($this->read_token_file());      return $arr_token->data;   }    /**    * Gets the expiry time from the current file    *    * @return String    */   private function get_current_expiry(){      $arr_token = json_decode($this->read_token_file());      return $arr_token->expires;   } }The translation class

So now that we have a valid authentication token, we can use it to to query the Microsoft Translator API, and make a translation.
MicrosoftTranslator.class.php

In the constructor, we pass in the AzureMarketplaceAuthenticator object. We do this in the constructor, because we absolutely must have this authentication before we can do anything.

Take special note of how we’re using the token in the constructor – it’s passed in the HTTP header, and prefixed with the string “Authorization: Bearer “. This is a requirement of the OAuth 2.0 authorization specification.

Also note the workaround for the PHP bug, which in certain cases, can prevent the HTTP header being set correctly in a SOAP request.

The translate method accepts three parameters; source text, source language and target language. The source text is the text that you want translating. The source and target language, are two letter ISO 639-1 codes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

/**
* MicrosoftTranslator.class.php
*
* @author David Wilcock
* @version $Id: $
*/

class MicrosoftTranslator {

/**
* The WSDL URL
*/
const STR_WSDL_URL = ‘http://api.microsofttranslator.com/V2/Soap.svc’;

/**
* Constructor – requires an instance of AzureMarketplaceAuthenticator, prepares
* a SoapClient with the client credentials
*
* @param AzureMarketplaceAuthenticator $obj_auth
*/
public function __construct(AzureMarketplaceAuthenticator $obj_auth){
$str_auth_header = “Authorization: Bearer “. $obj_auth->get_token();
$arr_context = array(
‘http’ =>array(
‘header’ => $str_auth_header
)
);
/**
* This is here because of a bug:
* https://bugs.php.net/bug.php?id=49853
*/
ini_set(‘user_agent’, ‘PHP-SOAP/’ . PHP_VERSION . “\r\n” . $str_auth_header);
$obj_context = stream_context_create($arr_context);
$arr_options = array (
‘soap_version’ => ‘SOAP_1_2′,
‘encoding’ => ‘UTF-8′,
‘exceptions’ => true,
‘trace’ => true,
‘cache_wsdl’ => ‘WSDL_CACHE_NONE’,
‘stream_context’ => $obj_context
);
$this->obj_soap_connection = new SoapClient(self::STR_WSDL_URL, $arr_options);
}

/**
* Performs a translation request, returns the translated text
*
* @param string $str_source_text
* @param string $str_source_language
* @param string $str_target_language
* @return string
*/
public function translate($str_source_text = NULL, $str_source_language = NULL, $str_target_language = NULL) {
if (is_null($str_source_text) || is_null($str_source_language) || is_null($str_target_language)){
throw new Exception(“Invalid argument”);
}
$arr_request_arguments = array (
‘appId’ => ”, // no longer used, but pass it anyway
‘text’ => $str_source_text,
‘from’ => $str_source_language,
‘to’ => $str_target_language
);
$obj_soap_response = $this->obj_soap_connection->Translate($arr_request_arguments);
return $obj_soap_response->TranslateResult;
}

}

Executing some code!

So now that we have two classes, we need a script to trigger the translation. You’ll see how easy this is to implement, and incude in an existing project.
trigger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

/**
* trigger.php
*
* @author David Wilcock
* @version $Id: $
*/

require_once ‘AzureMarketplaceAuthenticator.class.php’;
require_once ‘MicrosoftTranslator.class.php’;

try {

$obj_translator_auth = new AzureMarketplaceAuthenticator(‘azure_client_id’, ‘azure_client_secret’ ,’http://api.microsofttranslator.com’);
$obj_translator = new MicrosoftTranslator($obj_translator_auth);

echo $obj_translator->translate(‘This is a test for the Microsoft Translator API’, ‘en’, ‘de’) . PHP_EOL;

} catch (Exception $obj_exception) {
echo “Exception: ” . $obj_exception->getMessage() . PHP_EOL;
}

After running this, you should see something like this:

Dies ist ein Test für die Microsoft Translator API

Conclusion

It really is that simple!

You can build on this code very easily – I have myself written a large application around this, that uses queuing, retries, callbacks, etc. and if I do say so myself, it’s pretty slick.
Links

OAuth 2.0 authorization specification
PHP bug
ISO 639-1
Microsoft Translator at Microsoft Azure Marketplace

Files

I have attached a zip file containing all the files used in this article:

microsoft_translator_api.zip
More

If you have spotted a bug, or have a query, just reply to this post, and I’ll do my best to reply as soon as possible. Enjoy.

Microsoft Translator API schijnt een goed alternatief te zijn voor Google Translate. Die zou niet altijd goede resultaten geven.

Posted in PHP | Leave a comment

Hulpvolle Android links voor connectie met MySQL

Android login authenticatie met externe database:
http://webdesignergeeks.com/mobile/android/android-login-authentication-with-remote-db/

Android REST XML implementatie:
http://www.smnirven.com/?p=15


Posted in MySQL | Leave a comment

Doorsturen naar mobiele website (Android, Ipad, etc.)

Je kunt je gewone website doorsturen naar een mobiele website als een gebruiker gebruik maakt van een mobiel.
Dit Javascriptje detecteert zowat alle mobiele telefoons. Het is ook mogelijk dit te doen met .htaccess of PHP.
Ik heb gekozen het te doen met Javascript, omdat ik slechts 1 pagina heb willen doorsturen.

Posted in Javascript | Tagged , , , , , , , , , , , | Leave a comment

Met behulp van HTML SMSlink SMS-jes sturen

Het is mogelijk tekstberichten (SMS) zonder gebruik van software of de toegang tot een website. Dit kan via smsdiscount.com door een account aan te maken. Gebruik de volgende link en vul de gewenste gegevens:
https://www.smsdiscount.com/myaccount/sendsms.php?username=xxxxxxxxxx​&password=xxxxxxxxxx&from=xxxxxxxxxx&to=xxxxxxxxxx&text=xxxxxxxxxx

Verklaring van de variabelen:
username: je SMS Discount gebruikersnaam
password: je SMS-Discount wachtwoord
from: uw gebruikersnaam of uw geverifieerd telefoonnummer. Gebruik altijd het internationale formaat voor de nummer beginnend met +, bijvoorbeeld +491701234567
to: het nummer dat je wilt de sms te sturen naar. Gebruik altijd internationaal formaat beginnend met +, bijvoorbeeld +491701234567
text: het bericht dat je wilt verzenden

Na het aanmaken van de koppeling in een tekst-editor kun je die kopiëren in de adresbalk van je internet browser en daarna krijg je een melding dat je SMS is verzonden.
Posted in PHP, Programmeren | Tagged , , , , | Leave a comment