Last active
December 22, 2015 09:59
-
-
Save SoftCreatR/6456115 to your computer and use it in GitHub Desktop.
StopForumSpam-Plugin for WoltLab Community Framework 1 - Testscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Imports | |
require_once('./global.php'); | |
/** | |
* Simulate a default api call. If no errors occur, the SFS plugin should work | |
* | |
* @author Sascha Greuel <sascha@softcreatr.de> | |
* @copyright 2010-2013 Sascha Greuel | |
* @license Creative Commons BY-SA <http://creativecommons.org/licenses/by-sa/3.0/> | |
* @category Community Framework | |
*/ | |
$content = null; | |
// Testdata | |
$testuser = 'Spammer'; | |
$testmail = 'test@test.com'; | |
$testip = '1.2.3.4'; | |
// --- | |
// Build the request | |
$params = array( | |
'unix' => 1, | |
'confidence' => 1, | |
'f' => 'serial', | |
'username' => $testuser, | |
'email' => $testmail, | |
'ip' => $testip | |
); | |
// Call the SFS api and save the result in a tempfile | |
// If anything goes wrong, it should produce a fatal error | |
$remoteXML = 'http://www.stopforumspam.com/api?' . http_build_query($params, '&'); | |
// Print the result | |
try { | |
$localXML = FileUtil::downloadFileFromHttp($remoteXML, 'sfs_cache'); | |
$content = file_get_contents($localXML); | |
@unlink($localXML); | |
} | |
catch (SystemException $e) { | |
@unlink($localXML); | |
echo 'Ein Fehler ist aufgetreten (1).'; | |
} | |
$retArray = @unserialize($content); | |
if (!is_array($retArray) || !array_key_exists('success', $retArray) || intval($retArray['success']) !== 1) { | |
echo 'Ein Fehler ist aufgetreten (2):'; | |
echo '<pre>'; | |
print_r($retArray); | |
echo '</pre>'; | |
} | |
echo 'Kein Fehler aufgetreten. Das Plugin sollte ordnungsgemäß funktionieren:'; | |
echo '<pre>'; | |
print_r($retArray); | |
echo '</pre>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Imports | |
require_once('./global.php'); | |
use wcf\util\HTTPRequest; | |
use wcf\util\JSON; | |
/** | |
* Simulate a default api call. If no errors occur, the SFS plugin should work | |
* | |
* @author Sascha Greuel <sascha@softcreatr.de> | |
* @copyright 2010-2013 Sascha Greuel | |
* @license Creative Commons BY-SA <http://creativecommons.org/licenses/by-sa/3.0/> | |
* @category Community Framework | |
*/ | |
$content = null; | |
// Testdata | |
$testuser = 'Spammer'; | |
$testmail = 'test@test.com'; | |
$testip = '1.2.3.4'; | |
// --- | |
// Build the request | |
$params = array( | |
'f' => 'json', | |
'username' => $testuser, | |
'email' => $testmail, | |
'ip' => $testip | |
); | |
// Call the SFS api | |
// If anything goes wrong, it should produce a fatal error | |
$api = 'http://www.stopforumspam.com/api?' . http_build_query($params, '&'); | |
// Print the result | |
try { | |
$request = new HTTPRequest($api); | |
$request->execute(); | |
$reply = $request->getReply(); | |
$content = $reply['body']; | |
} | |
catch (\Exception $e) { | |
die('Ein Fehler ist aufgetreten (1).'); | |
} | |
$retArray = @JSON::decode($content, true); | |
if(!is_array($retArray) || !array_key_exists('success', $retArray) || intval($retArray['success']) !== 1) { | |
die('Ein Fehler ist aufgetreten (2).'); | |
} | |
echo 'Kein Fehler aufgetreten. Das Plugin sollte ordnungsgemäß funktionieren.'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment