Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global functions from autoload class #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions demo/demo1.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?
<?php
$callArray = array (
"func" => "premiumDomain",
//"func" => "allinone",
Expand All @@ -8,11 +8,11 @@
"domain" => "hockey.com",
// These are optional
"selected" => ".com;.net;.org",
"alldomains" => ".com;.net;.org"
"alldomains" => ".com;.net;.org"
)
);

require_once ("../opensrs/openSRS_loader.php");
require_once(__DIR__ . "/openSRS_LoaderWrapper.php");

//JSON
$callstring = json_encode($callArray);
Expand Down
4 changes: 2 additions & 2 deletions demo/demo2.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?
<?php
$callArray = array (
"func" => "subresGet",
"data" => array (
"username" => "clamsub10"
)
);

require_once("../opensrs/openSRS_loader.php");
require_once(__DIR__ . "/openSRS_LoaderWrapper.php");

$callstring = json_encode($callArray);

Expand Down
4 changes: 2 additions & 2 deletions demo/demo3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?
<?php
$callArray = array (
"func" => "cookieSet",
"data" => array (
Expand All @@ -8,7 +8,7 @@
)
);

require_once("..//opensrs/openSRS_loader.php");
require_once(__DIR__ . "/openSRS_LoaderWrapper.php");

$callstring = json_encode($callArray);
$osrsHandler = processOpenSRS ("json", $callstring);
Expand Down
14 changes: 7 additions & 7 deletions demo/demo5p.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
<?php

if (isSet($_POST['func'])) {
// ONLY FOR TESTING PURPOSE!!!
require_once("../opensrs/spyc.php");

// !!!!!!!! --- Proper form values verification --- !!!!!!!!!

$format = $_POST["format"];
$function = $_POST["func"];
$domain = $_POST["domain"];
Expand All @@ -20,12 +20,12 @@
"selected" => $tlds,
)
);

if ($format == "json") $callstring = json_encode($callArray);
if ($format == "yaml") $callstring = Spyc::YAMLDump($callArray);

// Open SRS Call -> Result
require_once ("../opensrs/openSRS_loader.php");
require_once(__DIR__ . "/openSRS_LoaderWrapper.php");
$osrsHandler = processOpenSRS($format, $callstring);

$jsonRet = $osrsHandler->resultRaw;
Expand All @@ -34,4 +34,4 @@
} else {
echo ("<h2>Invalid call!</h2>");
}
?>
?>
28 changes: 14 additions & 14 deletions demo/demo6.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
<?php

if (isSet($_POST['function'])) {
$callstring = "";

$firstname = trim($_POST["firstname"]);
$lastname = trim($_POST["lastname"]);


$searchstring = $firstname . " " . $lastname;

Expand All @@ -14,9 +14,9 @@
"data" => array ("searchstring" => $searchstring)
);

$callstring = json_encode($callArray);
$callstring = json_encode($callArray);
// Open SRS Call -> Result
require_once ("../opensrs/openSRS_loader.php");
require_once(__DIR__ . "/openSRS_LoaderWrapper.php");
$osrsHandler = processOpenSRS ("json", $callstring);
$json_out = $osrsHandler->resultFormatted;

Expand All @@ -31,9 +31,9 @@

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script language="Javascript" type="text/javascript" src="js/runonload.js"></script>
<script language="Javascript" type="text/javascript" src="js/democode.js"></script>
<script language="Javascript" type="text/javascript" src="js/democode.js"></script>



<style media="screen" type="text/css">
.defaultText { width: 205px; height: 39px; font-size: 20px;}
.defaultTextActive { color: #a1a1a1; font-style: italic;}
Expand Down Expand Up @@ -91,7 +91,7 @@

<div id="content">
<table width="540px">
<?php
<?php
if (isSet($json_out)){
$json_a = json_decode($json_out, true);

Expand All @@ -113,21 +113,21 @@
}
}
?>
</table>
</table>
</div>

<!-- Page footer -->
<div id="footer">
<!-- Left links -->
<a href="http://www.facebook.com/home.php#/pages/OpenSRS/127798660660?ref=s">OpenSRS is part of </a><a href="http://www.tucowsinc.com/">Tucows</a>
<span class="separator">|</span> <a href="http://opensrs.com/privacy">Privacy Policy</a> <span class="separator">|</span>
<span class="separator">|</span> <a href="http://opensrs.com/privacy">Privacy Policy</a> <span class="separator">|</span>
<a href="http://opensrs.com/sitemap.php">Sitemap</a> <span class="separator">|</span> &copy; 2010
</div>
</div>

</div></div>
</div>


<script type="text/javascript">
<!--
$(document).ready(function() {
Expand All @@ -145,11 +145,11 @@
}
});

$(".defaultText").blur();
$(".defaultText").blur();
});
//-->
</script>

</body>

</html>
6 changes: 3 additions & 3 deletions demo/demo6p.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

if (isSet($_POST['function'])) {
require_once("../opensrs/spyc.php");
Expand All @@ -14,9 +14,9 @@
);


$callstring = json_encode($callArray);
$callstring = json_encode($callArray);
// Open SRS Call -> Result
require_once ("../opensrs/openSRS_loader.php");
require_once(__DIR__ . "/openSRS_LoaderWrapper.php");
$osrsHandler = processOpenSRS ("json", $callstring);
$json_out = $osrsHandler->resultFormatted;

Expand Down
83 changes: 83 additions & 0 deletions demo/openSRS_LoaderWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
require_once __DIR__ . '/../opensrs/openSRS_loader.php';

// Call parsers and functions of openSRS
function processOpenSRS ($type="", $data="") {

if (empty($data)) {
trigger_error("OSRS Error - No data found.");
return null;
}
else {
$dataArray = array();
switch(strtolower($type)) {
case "array":
$dataArray = $data;
break;
case "json":
$json = str_replace("\\\"", "\"", $data); // Replace \" with " for JSON that comes from Javascript
$dataArray = json_decode($json, true);
break;
case "yaml":
$dataArray = Spyc::YAMLLoad($data);
break;
default:
$dataArray = $data;
}
// Convert associative array to object
$dataObject = array2object($dataArray);
$classCall = null;
if (class_exists($dataObject->func)){
$classCall = new $dataObject->func($type, $dataObject);
}
else {
trigger_error("OSRS Error - Unable to find the function $dataObject->func. Either the function is misspelled or there are incorrect file paths set in openSRS_config.php.");
}
return $classCall;
}
}

function array2object($data) {
if(!is_array($data)) return $data;
$object = new stdClass();

foreach ($data as $name=>$value) {
if (isset($name)) {
$name = strtolower(trim($name));
$object->$name = array2object($value);
}
}
return $object;
}

function object2array($data){
if(!is_object($data) && !is_array($data)) return $data;
if(is_object($data)) $data = get_object_vars($data);
return array_map('object2array', $data);
}

function convertArray2Formatted ($type="", $data="") {
$resultString = "";
if ($type == "json") $resultString = json_encode($data);
if ($type == "yaml") $resultString = Spyc::YAMLDump($data);
return $resultString;
}

function convertFormatted2array ($type="", $data="") {
$resultArray = "";
if ($type == "json") $resultArray = json_decode($data, true);
if ($type == "yaml") $resultArray = Spyc::YAMLLoad($data);;
return $resultArray;
}

function array_filter_recursive($input)
{
foreach ($input as &$value)
{
if (is_array($value))
{
$value = array_filter_recursive($value);
}
}
return array_filter($input);
}
10 changes: 5 additions & 5 deletions demo/testcase/test-allinoneDomain.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

if (isSet($_POST['function'])) {

Expand Down Expand Up @@ -36,7 +36,7 @@


// Open SRS Call -> Result
require_once dirname(__FILE__) . "/../..//opensrs/openSRS_loader.php";
require_once(__DIR__ . "/../openSRS_LoaderWrapper.php");
$osrsHandler = processOpenSRS ($formFormat, $callstring);


Expand Down Expand Up @@ -106,12 +106,12 @@
</form>



</body>
</html>



<?php
<?php
}
?>
?>
8 changes: 4 additions & 4 deletions demo/testcase/test-authChangeOwnership.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

if (isSet($_POST['function'])) {

Expand All @@ -25,7 +25,7 @@


// Open SRS Call -> Result
require_once dirname(__FILE__) . "/../..//opensrs/openSRS_loader.php";
require_once(__DIR__ . "/../openSRS_LoaderWrapper.php");
$osrsHandler = processOpenSRS ($formFormat, $callstring);

// Print out the results
Expand Down Expand Up @@ -76,10 +76,10 @@
</tr>
</table>
</form>

</body>
</html>

<?php
<?php
}
?>
8 changes: 4 additions & 4 deletions demo/testcase/test-authChangePassword.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

if (isSet($_POST['function'])) {

Expand All @@ -23,7 +23,7 @@


// Open SRS Call -> Result
require_once dirname(__FILE__) . "/../..//opensrs/openSRS_loader.php";
require_once(__DIR__ . "/../openSRS_LoaderWrapper.php");
$osrsHandler = processOpenSRS ($formFormat, $callstring);

// Print out the results
Expand Down Expand Up @@ -68,10 +68,10 @@
</tr>
</table>
</form>

</body>
</html>

<?php
<?php
}
?>
8 changes: 4 additions & 4 deletions demo/testcase/test-authCheckVersion.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

if (isSet($_POST['function'])) {

Expand All @@ -19,7 +19,7 @@


// Open SRS Call -> Result
require_once dirname(__FILE__) . "/../..//opensrs/openSRS_loader.php";
require_once(__DIR__ . "/../openSRS_LoaderWrapper.php");
$osrsHandler = processOpenSRS ($formFormat, $callstring);

// Print out the results
Expand Down Expand Up @@ -58,10 +58,10 @@
</tr>
</table>
</form>

</body>
</html>

<?php
<?php
}
?>
Loading