pickles/classes/API/Google/Profanity.php
Joshua Sherman 9f3ec38d1a Dropped API Common class
The class didn't provide any value and promised that it would in the future.
Any sort of redundant connection logic should simply be contained in a class
that can be extended and not an API-centric common class. Trying to move away
from all common classes in favor of classes that can be reused in different
parts of the core as well as outside of it.
2014-01-11 18:07:50 -05:00

47 lines
1.1 KiB
PHP

<?php
/**
* Google Profanity Class File for PICKLES
*
* PHP version 5
*
* Licensed under The MIT License
* Redistribution of these files must retain the above copyright notice.
*
* @author Joshua Sherman <pickles@joshtronic.com>
* @copyright Copyright 2007-2014, Joshua Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @package PICKLES
* @link https://github.com/joshtronic/pickles
*/
/**
* Google Profanity API Interface
*/
class API_Google_Profanity
{
/**
* Check
*
* Checks if a word is considered profanity.
*
* @usage API_Google_Profanity::check('fuck'); // returns true
* @param string $word word to check
* @return boolean whether or not the word is profanity
*/
public static function check($word)
{
$response = json_decode(file_get_contents('http://www.wdyl.com/profanity?q=' . $word), true);
if ($response == null || !isset($response['response']) || !in_array($response['response'], array('true', 'false')))
{
throw new Exception('Invalid response from API.');
}
else
{
return $response['response'] == 'true';
}
}
}
?>