Beispiel #1
0
function get_integration_settings($set_admin_defaults = FALSE)
{
    global $db, $wpuAbs;
    $config_fields = get_db_schema();
    $wpSettings = array();
    if ($wpuAbs->ver == 'PHPBB3') {
        foreach ($config_fields as $var_name => $field_name) {
            if ($wpuAbs->config('wpu_' . $field_name) !== FALSE) {
                $wpSettings[$var_name] = $wpuAbs->config('wpu_' . $field_name);
                //unset($GLOBALS['config']['wpu_'.$field_name]);
            } elseif ($set_admin_defaults) {
                $wpSettings[$var_name] = set_default($var_name);
            }
        }
        return $wpSettings;
    }
    $sql = 'SELECT * FROM ' . WP_INT_TABLE . ' LIMIT 1';
    if (!($result = $db->sql_query($sql))) {
        //db error -- die
        message_die(GENERAL_ERROR, $lang['WP_DBErr_Retrieve'], __LINE__, __FILE__, $sql);
        return FALSE;
    }
    if (!$db->sql_numrows($result)) {
        // table not populated yet
        return FALSE;
    } else {
        $row = $db->sql_fetchrow($result);
        $fullFieldSet = get_db_schema();
        foreach ($fullFieldSet as $var_name => $field_name) {
            $wpSettings[$var_name] = $row[$field_name];
        }
    }
}
Beispiel #2
0
 public static function generate_statement($statement_type, $list, $list_type, $tables, $conditions, $return_type = 'json')
 {
     //sets list to select all if not provided
     $list = set_default($list, '*');
     $conditions = set_default($conditions, '');
     //retrieve limits for shorthand
     $zero_minimium = Limits::get('zero_minimium');
     $text_limit = Limits::get('text_limit');
     //validate statement type
     $statement_types = Constants::get('statement_types');
     enforce_inputs(array($statement_type, 'string', $statement_types, null, false), array($list, 'array', null, null, true), array($list_type, 'string', Constants::get('statement_list_types'), null, false), array($tables, 'string', $text_limit['min'], $text_limit['max'], false), array($conditions, 'string', $zero_minimium, $text_limit['max'], true), $return_type);
     //conditions are optional
     $statement = '';
     if (compare_string($statement, 'SELECT', false)) {
         $statement = format_select($list, $list_type, $tables, $conditions);
     } else {
         if (compare_string($statement, 'INSERT', false)) {
             $statement = format_insert($list, $list_type, $tables, $conditions);
         } else {
             if (compare_string($statement, 'UPDATE', false)) {
                 $statement = format_update($list, $tables, $list_type, $conditions);
             } else {
                 if (compare_string($statement, 'DELETE', false)) {
                     $statement = format_delete($list, $tables, $list_type, $conditions);
                 }
             }
         }
     }
 }
Beispiel #3
0
 public function __construct($request_path, $request_params, $request_method, $return_type)
 {
     $function = array('class_name' => __NAMESPACE__, 'method_name' => __METHOD__);
     //validating the return type and set default if not found
     if (array_contains($return_type, Constants::get('allowed_return_types') == false)) {
         $return_type = Constants::get('default_return_type');
     } else {
         $this->return_type = set_default($return_type, Constants::get('allowed_return_types'));
     }
     //validate if request path is valid else throw error
     if (is_ready($request_path) == false) {
         $error = Tool::prepare('Request path is invalid, unable to process routing request.', 'Request path is null, verify that index router has parsed the information correctly.', __LINE__, $this->return_type, Constants::get('default_error_code'));
         Tool::error($function, $error, false);
     } else {
         enforce_inputs(array($request_path, 'array', null, null, false), $this->return_type);
         $this->original_path = $request_path;
         $this->request_path = $request_path;
     }
     //validate if request method is valid, else set as default (post takes precendence if both are used)
     $this->request_method = set_default($request_method, Constants::get('default_http_method'));
     $allowed_http_methods = Constants::get('allowed_http_methods');
     if (array_contains($request_method, $allowed_http_methods, false) == false) {
         $request_method = Constants::get('default_http_method');
     }
     $this->request_method = strtolower($request_method);
     //add post params to class if exist
     $this->request_params = $request_params;
     //normalise request_path
     if (is_ready(end($this->request_path)) == false) {
         array_pop($this->request_path);
     }
 }
Beispiel #4
0
 public static function write($http_status_code, $data, $parent_tag, $return_type = 'json')
 {
     $function = array('class_name' => __NAMESPACE__, 'method_name' => __METHOD__);
     //setting default values to the input parameters
     $http_status_code = set_default($http_status_code, 200);
     $data = set_default($data, array());
     $parent_tag = set_default($parent_tag, 'datas');
     $return_type = set_default($return_type, Constants::get('default_return_type'));
     //retrieve required limits from tools/constants/limits
     $text_limit = Limits::get('text_limit');
     //ensuring that inputs are validated against the array list of requirements $enforcement contains the results of the validation and message of the error if any.
     $enforcement = enforce_inputs(array($data, 'string:array', null, null, false), array($parent_tag, 'string', $text_limit['min'], $text_limit['max'], false), array($return_type, 'string', Constants::get('allowed_return_types'), null, false));
     $http_status_codes = Constants::get('http_status_codes');
     if (isset($http_status_codes[$http_status_code])) {
         //validates if the $http_status_code provided is in the list
         //check if data type is an array
         if (!is_array($data)) {
             $error = Tool::prepare('Data provided must be an array.', '', __LINE__, $return_type, Constants::get('default_error_code'));
             Tool::error($function, $error, false);
         }
         //formats the data return with the appropriate http status code.
         header('HTTP/1.0 ' . $http_status_code . ' ' . $http_status_codes[$http_status_code], true, $http_status_code);
         if (compare_string($return_type, Constants::get('xml'))) {
             //checks if the user requested data to be returned in xml (by default json)
             header('Content-type: text/xml');
             echo '<' . $parent_tag . '>';
             foreach ($data as $index => $post) {
                 if (is_array($post)) {
                     foreach ($post as $key => $value) {
                         echo '<', $key, '>';
                         if (is_array($value)) {
                             foreach ($value as $tag => $val) {
                                 echo '<', $tag, '>', htmlentities($val), '</', $tag, '>';
                             }
                         }
                         echo '</', $key, '>';
                     }
                 } else {
                     echo '<' . $index . '>' . $post . '</' . $index . '>';
                 }
             }
             echo '</' . $parent_tag . '>';
         } else {
             //header('Content-type: application/json; charset=UTF-8');
             echo json_encode(array($parent_tag => $data));
         }
     } else {
         Writer::write(400, 'Invalid HTTP status code.', Constants::get('error_tag'), $return_type);
         return;
     }
 }
Beispiel #5
0
 public static function error($info, $error, $loggable = false)
 {
     //preset $info('class_name', 'method_name', 'return_type')
     $class_name = set_default($info['class_name'], '');
     $method_name = set_default($info['method_name'], '');
     $return_type = set_default($error['return_type'], Constants::get('default_return_type'));
     //preset $error('message', 'details', 'line', 'error_code')
     $message = set_default($error['message'], 'Unknown Error Occurred.');
     $details = set_default($error['details'], '');
     $line = set_default($error['line'], '');
     $http_status_code = set_default($error['http_status_code'], Constants::get('default_error_code'));
     $error['function'] = str_replace($class_name . '/', '', $method_name);
     Writer::write($http_status_code, $error, Constants::get('error_tag'), $return_type);
     $debuggable = Config::get('enable_debugging');
     if ($debuggable == true) {
     }
     if ($loggable == true) {
     }
     //write to log
     exit;
 }
Beispiel #6
0
echo '<br/>Passed<br/><hr/>';
/* checks if the variable is unset, null or empty and assign the default value 
 * if the variable is unset, null or empty (if string), the default value will be set to the variable. 
 * $variable will not be able to take in a value for eg. is_ready('abc');, a variable has to be used, eg. $x; is_ready($x);
 */
echo 'Signature: set_default(&$variable, $default)<br/>';
echo '//sets a default if variable is not ready. variable must be passed. value is return and assigned.<br/><br/>';
$default_value = 'defaultvalue';
$normal_item = 'x';
$null_item = null;
$empty_item = '';
$single_space = ' ';
echo 'set_default($normal_item, "default"): ' . set_default($normal_item, 'default') . '<br/>';
echo 'set_default($null_item, "default"): ' . set_default($null_item, 'default') . '<br/>';
echo 'set_default($empty_item, "default"): ' . set_default($empty_item, 'default') . '<br/>';
echo 'set_default($single_space, "default"): ' . set_default($single_space, 'default') . '<br/>';
echo '<br/>Passed<br/><hr/>';
/* Rewrite method of in_array to check if the array contains the item. However, it sanitizes the input before checking */
echo 'Signature: array_contains($item, $allowed_array, $case_sensitive = false)<br/>';
echo '//check if items is in array, but sanitize all input before checking, default not case sensitive<br/><br/>';
echo 'array_contains("x ", array("x", "y", "z")): ' . (array_contains("x ", array("x", "y", "z")) ? 'true' : 'false') . '<br/>';
echo 'array_contains("x ", array("x ", "y", "z")): ' . (array_contains("x ", array("x", "y", "z")) ? 'true' : 'false') . ' - both inputs and list are sanitized<br/>';
echo 'array_contains("X ", array("x ", "y", "z")): ' . (array_contains("X ", array("x", "y", "z")) ? 'true' : 'false') . '<br/>';
echo 'array_contains("X ", array("x ", "y", "z"), true): ' . (array_contains("X ", array("x", "y", "z"), true) ? 'true' : 'false') . '<br/>';
echo '<h3>String Manipulation</h3>';
/* rewrite method of strcmp which sanitizes and trim inputs, including case sensitive comparision */
echo '<hr/>Signature: compare_string($input_one = "", $input_two = "", $case_sensitive = false)<br/>';
echo '//default comparision is not case sensitive, passing variables in works accordingly.<br/><br/>';
echo 'compare_string("", ""): ' . (compare_string('', '') ? 'true' : 'false') . '<br/>';
echo 'compare_string("xyz", "xyz"): ' . (compare_string('xyz', 'xyz') ? 'true' : 'false') . '<br/>';
echo 'compare_string("xyz", "XYZ"): ' . (compare_string('xyz', 'XYZ') ? 'true' : 'false') . '<br/>';
Beispiel #7
0
function enforce_inputs()
{
    $function = array('class_name' => __NAMESPACE__, 'method_name' => __METHOD__);
    $message = '';
    $variable = '';
    $line = '';
    //retrieve last item as return type if available
    $array = func_get_args();
    $return_type = end($array);
    if (is_string($return_type) == false) {
        $return_type = Constants::get('default_return_type');
    } else {
        $allowed_return_types = Constants::get('allowed_return_types');
        if (array_contains($return_type, $allowed_return_types) == false) {
            $return_type = Constants::get('default_return_type');
        }
    }
    //loop through every item to validate, sets a message to throw the error at the end of the method
    foreach ($array as $list) {
        if (is_ready($list)) {
            //every list must be ready
            if (is_array($list)) {
                //ensure that item is an array
                if (count($list) == 5) {
                    //every list contains the required items
                    $variable = set_default($list[0], null);
                    $type = set_default($list[1], ':');
                    $min = set_default($list[2], null);
                    $max = set_default($list[3], null);
                    $nullable = set_default($list[4], false);
                    $validation_list = null;
                    if (isset($variable)) {
                        //ensure that variable is set
                        //ensures that valid variable list type is request
                        if (list_contains($type, Constants::get('variable_list')) == false) {
                            $message = 'Invalid variable validation requirement - type (' . $type . ') unrecognized.';
                            $line = __LINE__;
                        }
                        //if either one is not a numeric, check for array
                        if (validate_type($min, 'numeric') == false || validate_type($max, 'numeric') == false) {
                            if (validate_type($min, 'array') == true || validate_type($max, 'array') == true) {
                                $validation_list = (is_null($min) == true || isset($min) == false) && validate_type($max, 'array') ? $max : $min;
                                if (validate_type($validation_list, 'array') == false) {
                                    $message = 'Invalid variable validation requirement - an array to validate is required.';
                                    $line = __LINE__;
                                }
                            } else {
                                if (is_null($min) == false || is_null($max) == false) {
                                    $message = 'Invalid variable validation requirement - min/max must be numeric or an array of list in either one or both nulls.';
                                    $line = __LINE__;
                                }
                            }
                            //ensure than max is less than min
                        } else {
                            if ($max < $min) {
                                $message = 'Invalid variable validation requirement - min is more than max.';
                                $line = __LINE__;
                            }
                        }
                        //ensure that nullable is boolean
                        if (validate_type($nullable, 'bool') == false) {
                            $message = 'Invalid variable validation requirement - nullable must be boolean.';
                            $line = __LINE__;
                        }
                        //verify variable if not null
                        if (!is_null($variable)) {
                            if (validate_type($variable, $type) == false) {
                                $message = 'Variable is not a ' . $type . '.';
                                $line = __LINE__;
                            }
                            if (is_null($validation_list) == false && isset($validation_list) == true) {
                                if (array_contains($variable, $validation_list) == false) {
                                    $message = 'Variable is not found in the list provided.';
                                    $line = __LINE__;
                                }
                            } else {
                                if (validate_type($variable, 'string:numeric') == true) {
                                    if (is_null($min) == false || is_null($max) == false) {
                                        if (validate_range($variable, $min, $max) == false) {
                                            $message = 'Variable does not meet the min/max requirement.';
                                            $line = __LINE__;
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        if ($nullable == false) {
                            $message = 'Variable is not set, unable to validate variable';
                            $line = __LINE__;
                        }
                    }
                } else {
                    $message = 'Incomplete variable validation list. [variable, type, min, max, nullable*]';
                    $line = __LINE__;
                }
            }
        } else {
            $message = 'Invalid variable validation list, an array is required. [variable, type, min, max, nullable*]';
            $line = __LINE__;
        }
    }
    if (compare_string($message, '') == false) {
        $variable_name = variable_name($variable);
        if (isset($variable_name) == true && $variable_name != '') {
            $variable_name = '$' . $variable_name;
        } else {
            $variable_name = $type != 'password' ? $variable : '*password*';
        }
        if ($variable_name != '') {
            $variable_name = ' [' . $variable_name . ']';
        }
        $error = Tool::prepare($message . $variable_name, '', $line, $return_type, Constants::get('default_error_code'));
        Tool::error($function, $error, false);
    }
}
Beispiel #8
0
    $count = strpos($request, '&') == false ? strlen($request) : strpos($request, '&');
    $request = substr($request, 0, $count);
    $request_path = explode("/", $request);
    //extract return type, check if return type is in the allowed list
    $return_type = end($request_path);
    $return_type = set_default($return_type, Constants::get('default_return_type'));
    $return_type = strrchr($return_type, ".");
    $return_type = substr($return_type, 1);
    $allowed_return_types = Constants::get('allowed_return_types');
    if (array_contains($return_type, $allowed_return_types, false) == false) {
        $return_type = Constants::get('default_return_type');
    } else {
        //remove the return type from the request_path
        $item = end($request_path);
        $item = substr($item, 0, strlen($item) - (strlen($return_type) + 1));
        $request_path[count($request_path) - 1] = $item;
    }
    //extract request_method, can be defined in both get and post reauest, post takes precedence
    $request_method = set_default($_REQUEST['request_method'], $_SERVER['REQUEST_METHOD']);
    $allowed_http_methods = Constants::get('allowed_http_methods');
    if (array_contains($request_method, $allowed_http_methods, false) == false) {
        $request_method = Constants::get('default_http_method');
    }
    $request_params = $_REQUEST;
    //form route and send through router
    $route = new Route($request_path, $request_params, $request_method, $return_type);
    $router = new Router($route);
    $router->route();
    //TODO: Can handle redirection to api introduction if no specific request is made
} else {
}
Beispiel #9
0
     }
 } elseif ($pkeypolicy == 'skip') {
     if (!$existingid) {
         $makeNewId = true;
     }
 } elseif ($pkeypolicy == 'addall') {
     $makeNewId = true;
 }
 // if no Match Field was set, we'll add all records as new ones
 if (!$primaryKeyLine && $pkeypolicy != 'onlyupdate') {
     $makeNewId = true;
 }
 if ($makeNewId) {
     // generate a default record
     $tmpfields = 'gr,gw,er,ew';
     $fieldvalues = set_default($db, $tableinfo, $tmpfields, $USERAS, $system_settings);
     $recordid = add($db, $tableinfo->realname, $tableinfo->fields, $fieldvalues, $USERAS, $tableinfo->id);
 }
 // only continue if we have a record (existing or newly made) to modify
 if (isset($recordid)) {
     $query = "UPDATE {$table} SET ";
     // import data from file into SQL statement
     for ($i = 0; $i < $nrfields; $i++) {
         if ($fields[$i] && $to_fields[$i] && $to_datatypes[$i] != 'file' && $to_datatypes[$i] != 'mpulldown') {
             // if date is an int, assume it is UNIX date, otherwise convert
             if ($to_datatypes[$i] == 'date') {
                 if (!is_int($fields[$i])) {
                     $fields[$i] = mymktime($fields[$i]);
                 }
             }
             $worthit = true;
Beispiel #10
0
 public function delete_accessor($param, $post_params)
 {
     //define tags for parent tags and child tag
     $parent_tag = 'results';
     $child_tag = 'result';
     //handle authentication
     //initalizing and set default for params
     $statement = '';
     $param[0] = set_default($param[0], '');
     //handle $param parsing
     if (is_ready($param[0]) == false) {
         //delete all records
         Writer::write(501, 'Method not implemented.', Constants::get('error_tag'), parent::get_route()->get_return_type());
     } else {
         if (count($param) == 1) {
             if (is_numeric($param[0])) {
                 //delete record based on the id
                 $statement = 'DELETE FROM accessor WHERE _id = ' . $param[0];
             } else {
                 if (is_string($param[0])) {
                     //delete record based on the search term on all columns
                 }
             }
         } else {
             if (count($param) == 2) {
                 //delete record based on the search term on a row column
             }
         }
     }
 }