Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Jun 9, 2014
2 parents 1a2b579 + 792dca9 commit 5a6a566
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
SocialLinks
===========

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/oscarotero/social-links/badges/quality-score.png?s=297eaeb181f11caae68c961095ec67c76a57d4fa)](https://scrutinizer-ci.com/g/oscarotero/social-links/)

Created by Oscar Otero <http://oscarotero.com> <oom@oscarotero.com>

This is a simple library to generate buttons to share an url or count the current shares using multiple providers (facebook, twitter, etc)
Expand Down
60 changes: 60 additions & 0 deletions SocialLinks/Providers/ProviderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public function __construct(Page $page)
}


/**
* Magic method to calculate and store the properties
*/
public function __get($key)
{
switch ($key) {
Expand All @@ -22,12 +25,25 @@ public function __get($key)
}
}


/**
* Default shareApp for all classes extending this class
*/
public function shareApp()
{
return null;
}


/**
* Executes a request and return the response
*
* @param string $url
* @param boolean|string $post
* @param array $headers
*
* @return string
*/
protected static function executeRequest($url, $post = false, array $headers = null)
{
$connection = curl_init();
Expand Down Expand Up @@ -65,23 +81,67 @@ protected static function executeRequest($url, $post = false, array $headers = n
return $content;
}


/**
* Execute and returns a request
*
* @param string $url
* @param array $pageParams
* @param array $getParams
* @param boolean|string $post
* @param array $headers
*
* @return string|false
*/
protected function getText($url, array $pageParams = null, array $getParams = array(), $post = false, array $headers = null)
{
return self::executeRequest($this->buildUrl($url, $pageParams, $getParams), $post, $headers);
}


/**
* Execute and returns a json request
*
* @param string $url
* @param array $pageParams
* @param array $getParams
* @param boolean|string $post
* @param array $headers
*
* @return array|false
*/
protected function getJson($url, array $pageParams = null, array $getParams = array(), $post = false, array $headers = null)
{
return json_decode(self::executeRequest($this->buildUrl($url, $pageParams, $getParams), $post, $headers), true);
}


/**
* Execute and returns a jsonp request
*
* @param string $url
* @param array $pageParams
* @param array $getParams
* @param boolean|string $post
* @param array $headers
*
* @return array|false
*/
protected function getJsonp($url, array $pageParams = null, array $getParams = array(), $post = false, array $headers = null)
{
preg_match("/^\w+\((.*)\)$/", self::executeRequest($this->buildUrl($url, $pageParams, $getParams), $post, $headers), $matches);

return json_decode($matches[1], true);
}


/**
* Generates a valid url
*
* @param string $url
* @param array $pageParams
* @param array $getParams
*/
protected function buildUrl($url, array $pageParams = null, array $getParams = array())
{
if ($pageParams) {
Expand Down
17 changes: 17 additions & 0 deletions SocialLinks/Providers/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@
namespace SocialLinks\Providers;

interface ProviderInterface {
/**
* Returns the share app url
*
* @return string|null
*/
public function shareApp();


/**
* Returns the share url
*
* @return string|null
*/
public function shareUrl();


/**
* Returns the share count
*
* @return integer|null
*/
public function shareCount();
}
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "social-links/social-links",
"type": "library",
"description": "PHP library to generate share buttons",
"keywords": ["image"],
"homepage": "https://github.com/oscarotero/social-links",
"license": "MIT",
"authors": [
{
"name": "Oscar Otero",
"email": "oom@oscarotero.com",
"homepage": "http://oscarotero.com",
"role": "Developer"
}
],
"support": {
"email": "oom@oscarotero.com",
"issues": "https://github.com/oscarotero/social-links/issues"
},
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"SocialLinks": ""
}
}
}
1 change: 1 addition & 0 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'pinterest',
'linkedin',
'meneame',
'chuza',
'cabozo',
'stumbleupon',
];
Expand Down

0 comments on commit 5a6a566

Please sign in to comment.