fimms
Junior Member
- Apr 30, 2009
- 179
- 59
Here are two classes and procedure to use free SpinnerChief API with PHP to get spintax formatted text from your original text. You could also get spun text directly, but I rather get text in spintax format, save it for later usage and spin text unlimited times on my end.
I have The Best Spinner class also ready, but I dont have account to test it yet, so I'll come back with it later. As well I will post spin class on different thread bit later to keep code as short as possible.
You need username, password and api key from SpinnerChiefs. I managed to get it by creating two accounts:
1) http://developer.spinnerchief.com to get api key and
2) http://account.spinnerchief.com to get username and password
Using these in combination I have access to SpinnerChiefs API arsenal. On example I use everyones favorites to get spintax formatted text. For some reason quota check doesnt work, donnou reason yet. But other parameters seems to work well. You can investigate their PAI documentation from: http://developer.spinnerchief.com/API_Document.aspx
Hope this helps people to create some cool PHP web apps using SpinnerChiefs fantastic synonym database.
Usage:
- get accounts from SC
- paste whole code n php script and run on your server
Shortly explained you initialize class by giving it user credentials and call format method by giving your text on argument.
Note: at the moment class implements only quota, rewrite and favorites API calls.
So here the code for free usage:
I have The Best Spinner class also ready, but I dont have account to test it yet, so I'll come back with it later. As well I will post spin class on different thread bit later to keep code as short as possible.
You need username, password and api key from SpinnerChiefs. I managed to get it by creating two accounts:
1) http://developer.spinnerchief.com to get api key and
2) http://account.spinnerchief.com to get username and password
Using these in combination I have access to SpinnerChiefs API arsenal. On example I use everyones favorites to get spintax formatted text. For some reason quota check doesnt work, donnou reason yet. But other parameters seems to work well. You can investigate their PAI documentation from: http://developer.spinnerchief.com/API_Document.aspx
Hope this helps people to create some cool PHP web apps using SpinnerChiefs fantastic synonym database.
Usage:
- get accounts from SC
- paste whole code n php script and run on your server
Shortly explained you initialize class by giving it user credentials and call format method by giving your text on argument.
PHP:
$sc = new SpinnerChief($username, $password, $api_key);
echo $sc->format($text);
Note: at the moment class implements only quota, rewrite and favorites API calls.
So here the code for free usage:
PHP:
class Spinner
{
var $timeout = 10; # set timeout for curl post
var $keywords; # comma separated list of keywords you dont want to spin
var $maxsyns = 3; # enter the maximum number of synonyms you want to get for a word/phrase.
var $errors; # any errors that occurs are stored in this variable
var $api; # api url
var $api_key; # api key if needed
function _init($username, $password, $api_key = NULL) {
$this->username = $username;
$this->password = $password;
$this->api_key = $api_key;
}
function keywords($kws) {
$this->keywords = is_array($kws) ? implode(',', $kws) : $kws;
}
function format($text) {
return $this->favorites($text);
}
function call($method = NULL, $text = NULL) {
if ($result = $this->_call($method, $text)) {
if ($result['success'] == 'true') {
return $result['output'];
}
}
$this->errors = $result['error'];
}
function _post($data, $url_components = array()) {
$url = $url_components ? rtrim($this->api, '?') . '?' . http_build_query($url_components) : $this->api;
$post_fields = '';
if (is_array($data)) {
foreach ($data as $key => $value) {
$post_fields .= $key.'='.urlencode($value).'&';
}
$post_fields = rtrim($post_fields, '&');
} else {
$post_fields = $data;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_POST, TRUE);
if ($post_fields) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $this->api);
$result = trim(curl_exec($ch));
curl_close($ch);
return $result;
}
}
class SpinnerChief extends Spinner
{
var $api = 'http://api.spinnerchief.com:9001/'; #8000, 8080 and 443 ports work too
function __construct($username, $password, $api_key) {
$this->_init($username, $password, $api_key);
}
function _call($method = NULL, $text = NULL) {
$this->data['api_key'] = $this->api_key;
$this->data['username'] = $this->username;
$this->data['password'] = $this->password;
if ($this->keywords) {
$this->data['protectwords'] = $this->keywords;
}
$result = $this->_post($text, $this->data);
if (strpos($result, 'error=') === 0) {
return array('error' => str_replace('error=', '', $result), 'success' => 'false', 'output' => '');
}
return array('error' => '', 'success' => 'true', 'output' => $result);
}
function rewrite($text) {
$this->data = array();
$this->data['spintype'] = 1;
return $this->call(NULL, $text);
}
function favorites($text) {
$this->data = array();
$this->data['wordquality'] = 9;
$this->data['wordscount'] = $this->maxsyns;
return $this->call(NULL, $text);
}
function quota() {
$this->data = array();
$this->data['querytimes'] = 2;
$quota = $this->call();
return $quota != '' ? (int)$quota : 'na';
}
}
#not implemented yet because of lack of good publicly available api documentation
class TheBestSpinner extends Spinner
{
var $api = 'http://thebestspinner.com/api.php';
}
$original = <<<EOF
Home Remedies for Large Pores
Large pores are simply a genetic problem. Large pores are often an indication of oily skin. Large pores (sometimes referred to as enlarged pores) are likewise more common in the T-zone and occur most often on those with oily skin. Though not always, large pores and blackheads tend to go hand in hand. Blackheads and large pores usually come together. This is because the pores are larger, so oil and dead skin sits inside of them. This becomes a blackhead and stretches the pore even larger.
If enlarged pores are due to blackheads stretching the entrance of the pore, then firstly remove blackheads using one of the above methods, then to contract pores, blend (one or your preferred mixture) of camphor, sage and / or thyme in a base of jojoba oil. Use as a compress or mix in with your moisturiser and apply to affected areas. Jojoba is easily absorbed into the skin and balances oil levels (which may assist in reducing blackheads as sebum production is regulated).
Oatmeal and gram flour are good toning substance. You can add a little lemon juice, rose water and curd to them and apply on the skin. Wash this pack off when it dries. It tones the pores and enhances the complexion.
Honey is equally good to tone up the pores and reduce the oiliness from the skin. It can be applied in any of the facemask or can be directly applied on the skin with a little lemon juice and sugar to it. You can massage it on face and leave it for few minutes. Then rinse it off with lukewarm water. Honey added to milk powder too helps if applied on the skin. A paste made of salt and butter is helpful in reducing pore size if applied on them.
Add tomato juice to calamine powder or sandalwood powder, as they help in reducing the size of the pores and even tone up the skin well. These packs help skin to reduce the sebum production and thus help in reducing the size of the pores.
Boire strips help with blackhead removal, so if you have blackheads, use them. They are effective. Also, scrub your face regularly to prevent your pores from getting clogged. Make sure you use a scrub that suits you, because certain scrubs can cause a rash.
Egg skin is a pore-shrinker that also helps bring skin eruptions to a head. Break an egg, reserve its contents for other use, and then carefully remove the membrane from the inside of the shell. Smooth this egg skin over the enlarged pores; let dry before peeling off.
Sunburn is better prevented than treated. Effective sunscreens are available in a wide variety of strengths. Most doctors recommend a sunscreen SPF level of 30 or greater.
Large pores are simply a genetic problem, but you can temporarily reduce large pores by clearing away dirt and debris. Large pores are often an indication of oily skin. Use one after the other for cleansing and exfoliating the skin. Mix 2 egg whites with a few drops of lemon juice. Apply on face and leave on for 5-7 minutes, then rinse with hands. As egg whites dry, they lighten the skin and pull debris out of pores.
Mix almond meal with enough water to make a paste. Apply to pores for 20 minutes. Rinse with warm water, and then apply witch hazel or a solution of apple cider vinegar and water.
EOF;
$username = '__username__';
$password = '__password__';
$api_key = '__apikey__';
$sc = new SpinnerChief($username, $password, $api_key);
$sc->keywords('large pores');
$spintax = $sc->format($original);
echo $spintax;
Last edited: