Skip to content

Commit

Permalink
Check for CURL extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Neumann committed Jul 11, 2013
1 parent 9d210f3 commit 139218e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Version history
* 0.1 Initial Version
* 0.2 Icon changes colour when clicked
* 0.3 Added a hotkey (thanks to Bas1c), since 0.31 change icon colour for hotkey, too.
* 0.32 Check for CURL and throw error if missing.

Credits
-------
Expand Down
45 changes: 27 additions & 18 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function init($host) {
}

function about() {
return array(0.31,
return array(0.32,
"Add articles to Pocket with a single click",
"fxneumann");
}
Expand Down Expand Up @@ -66,26 +66,30 @@ function getInfo() {


//Call Pocket API
$postfields = array(
'consumer_key' => $consumer_key,
'access_token' => $pocket_access_token,

if (function_exists('curl_init')) {
$postfields = array(
'consumer_key' => $consumer_key,
'access_token' => $pocket_access_token,
'url' => $article_link,
'title' => $title
);
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, 'https://getpocket.com/v3/add');
curl_setopt($cURL, CURLOPT_HEADER, 1);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_TIMEOUT, 5);
curl_setopt($cURL, CURLOPT_POST, 4);
curl_setopt($cURL, CURLOPT_POSTFIELDS, http_build_query($postfields));
$apicall = curl_exec($cURL);
curl_close($cURL);

//Store error code in $status
$status = preg_match('/^X-Error: .*$/m', $apicall, $matches) ? $matches[0] : 1;

$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, 'https://getpocket.com/v3/add');
curl_setopt($cURL, CURLOPT_HEADER, 1);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_TIMEOUT, 5);
curl_setopt($cURL, CURLOPT_POST, 4);
curl_setopt($cURL, CURLOPT_POSTFIELDS, http_build_query($postfields));
$apicall = curl_exec($cURL);
curl_close($cURL);

//Store error code in $status
$status = preg_match('/^X-Error: .*$/m', $apicall, $matches) ? $matches[0] : 1;
} else {
$status = 'For the plugin to work you need to <strong>enable PHP extension CURL</strong>!';
}
//Return information on article and status
print json_encode(array(
"title" => $title,
Expand Down Expand Up @@ -125,6 +129,11 @@ function hook_prefs_tab($args) {
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"oneclickpocket\">";
print "<table width=\"100%\" class=\"prefPrefsList\">";

if (!function_exists('curl_init')) {
print '<tr><td colspan="3" style="color:red;font-size:large">For the plugin to work you need to <strong>enable PHP extension CURL</strong>!</td></tr>';
}

print "<tr><td width=\"20%\">".__("Pocket Consumer Key")."</td>";
print '<td width=\"20%\">Get a <a href="http://getpocket.com/developer/apps/new">Pocket Consumer Key</a></td>';
print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"pocket_consumer_key\" value=\"$pocket_consumer_key\"></td>";
Expand Down

0 comments on commit 139218e

Please sign in to comment.