diff --git a/classes/model.php b/classes/model.php index cffeea76..a62161ce 100644 --- a/classes/model.php +++ b/classes/model.php @@ -23,7 +23,7 @@ class Model { protected $class_name; // Arguments of this instance - private $args; + private $args = array(); // Instances of all submodels initiated from this class private $submodels; @@ -40,6 +40,12 @@ class Model { // Is execution terminated private $terminated; + private $ttl; + + private $called_subs; + + private $api; + /** * Constructor for DustPress model class. * @@ -47,8 +53,8 @@ class Model { * @date 10/8/2015 * @since 0.2.0 * - * @param load (boolean) - * @return N/A + * @param array $args + * @param mixed $parent */ public function __construct( $args = [], $parent = null ) { $this->fix_deprecated(); @@ -69,7 +75,7 @@ public function __construct( $args = [], $parent = null ) { * @date 3/6/2016 * @since 0.4.0 * - * @return void + * @return array */ public function get_args() { return $this->args; @@ -109,7 +115,7 @@ public function get_data() { * @date 3/6/2016 * @since 0.4.0 * - * @return Dustpress\Model + * @return \Dustpress\Model */ public function get_submodel( $name ) { return $this->submodels->{$name}; @@ -135,7 +141,7 @@ public function get_submodels() { * @date 3/6/2016 * @since 0.4.0 * - * @return Dustpress\Model + * @return \Dustpress\Model */ public function get_ancestor( $model = null ) { if ( ! isset( $model ) ) { @@ -157,9 +163,6 @@ public function get_ancestor( $model = null ) { * @type function * @date 16/02/2017 * @since 1.5.5 - * - * @param N/A - * @return N/A */ public function fix_deprecated() { // Reassign deprecated "allowed_functions" to "api". @@ -176,14 +179,16 @@ public function fix_deprecated() { * @date 15/10/2015 * @since 0.2.0 * - * @param N/A - * @return N/A + * @param string $functions + * @param bool $tidy + * + * @return mixed */ public function fetch_data( $functions = null, $tidy = false ) { $this->class_name = get_class( $this ); // Create a place to store the wanted data in the global data structure. - if ( ! isset( $this->data[ $this->class_name ] ) ) $this->data[ $this->class_name ] = new \StdClass(); + if ( ! isset( $this->data[ $this->class_name ] ) ) $this->data[ $this->class_name ] = new \stdClass(); // Fetch all methods from given class and in its parents. $methods = $this->get_class_methods( $this->class_name ); @@ -213,7 +218,7 @@ public function fetch_data( $functions = null, $tidy = false ) { } else { if ( ! $this->is_function_allowed( $method_item ) ) { - die( json_encode( [ "error" => "Method '". $function ."' is not allowed to be run via AJAX or does not exist." ] ) ); + die( json_encode( [ "error" => "Method '". $method_item ."' is not allowed to be run via AJAX or does not exist." ] ) ); } else if ( $reflection->isProtected() || $reflection->isPrivate() ) { $private_methods[] = $method_item; @@ -353,8 +358,8 @@ public function fetch_data( $functions = null, $tidy = false ) { * @date 19/3/2015 * @since 0.0.1 * - * @param $class_name (string) - * @param $methods (array) + * @param string $class_name + * @param array $methods * @return $methods (array) */ private function get_class_methods( $class_name, $methods = array() ) { @@ -448,7 +453,7 @@ public function bind_sub( $name, $args = null, $cache_sub = true ) { } if ( $model->terminated == true ) { - $this-terminate(); + $this->terminate(); } } @@ -460,9 +465,9 @@ public function bind_sub( $name, $args = null, $cache_sub = true ) { * @date 17/3/2015 * @since 0.0.1 * - * @param $data (N/A) - * @param $key (string) - * @param $model (string) + * @param N/A $data + * @param string $key + * @param string $model * @return true/false (boolean) */ public function bind( $data, $key = null, $model = null ) { @@ -476,7 +481,7 @@ public function bind( $data, $key = null, $model = null ) { if ( $model ) { // Create a place to store the wanted data in the global data structure. - if ( ! isset( $this->data[ $model ] ) ) $this->data[ $model ] = new \StdClass(); + if ( ! isset( $this->data[ $model ] ) ) $this->data[ $model ] = new \stdClass(); if ( ! isset( $this->data[ $model ] ) ) { $this->data[ $model ] = (object)[]; @@ -485,7 +490,7 @@ public function bind( $data, $key = null, $model = null ) { } else { // Create a place to store the wanted data in the global data structure. - if ( ! isset( $this->data[ $this->class_name ] ) ) $this->data[ $this->class_name ] = new \StdClass(); + if ( ! isset( $this->data[ $this->class_name ] ) ) $this->data[ $this->class_name ] = new \stdClass(); if ( ! $this->parent ) { if ( is_array( $data ) ) { @@ -534,8 +539,7 @@ public function get_template() { * @date 15/10/2015 * @since 0.2.0 * - * @param $template (string) - * @return N/A + * @param string $template */ public function set_template( $template ) { $ancestor = $this->get_ancestor(); @@ -561,8 +565,9 @@ public function set_template( $template ) { * @date 29/01/2016 * @since 0.3.1 * - * @param $m (string) - * @return N/A + * @param string $m + * + * @return mixed */ private function run_function( $m, $class = null ) { $cached = $this->get_cached( $m ); @@ -607,8 +612,9 @@ private function run_function( $m, $class = null ) { * @date 29/01/2016 * @since 0.3.1 * - * @param $m (string) - * @return N/A + * @param string $m + * + * @return mixed|bool */ private function get_cached( $m ) { @@ -644,42 +650,42 @@ private function get_cached( $m ) { * @date 29/01/2016 * @since 0.3.1 * - * @param $m (string), $data (any), $subs (array) - * @return N/A + * @param string $m + * @param mixed $data + * @param array $subs */ private function maybe_cache( $m, $data, $subs ) { // Check whether cache is enabled and model has ttl-settings. - if ( dustpress()->get_setting('cache') && $this->is_cacheable_function( $m ) ) { + if ( ! dustpress()->get_setting('cache') || ! $this->is_cacheable_function( $m ) ) { + return; + } - // Extend data with submodels - $to_cache = (object)[ 'data' => $data, 'subs' => $subs ]; + // If no hash key exists, bail out + if ( empty( $this->hash ) ) { + return; + } - set_transient( $this->hash, $to_cache, $this->ttl[ $m ] ); + // Extend data with submodels + $to_cache = (object)[ 'data' => $data, 'subs' => $subs ]; - // If no hash key exists, bail - if ( ! isset( $this->hash ) ) { - return; - } + set_transient( $this->hash, $to_cache, $this->ttl[ $m ] ); - // Index key for cache clearing - $index = $this->generate_cache_key( $this->class_name, $m ); - $hash_index = get_transient( $index ); + // Index key for cache clearing + $index = $this->generate_cache_key( $this->class_name, $m ); + $hash_index = get_transient( $index ); - if ( ! is_array( $hash_index ) ) { - $hash_index = []; - } - - // Set the data hash key to the index array of this model function - if ( ! in_array( $this->hash, $hash_index ) ) { - $hash_index[] = $this->hash; - } + if ( ! is_array( $hash_index ) ) { + $hash_index = []; + } - // Store transient for 30 days - set_transient( $index, $hash_index, 30 * DAY_IN_SECONDS ); + // Set the data hash key to the index array of this model function + if ( ! in_array( $this->hash, $hash_index ) ) { + $hash_index[] = $this->hash; } - return false; + // Store transient for 30 days + set_transient( $index, $hash_index, 30 * DAY_IN_SECONDS ); } /** @@ -712,7 +718,7 @@ private function is_cacheable_function( $m ) { * @date 17/12/2015 * @since 0.3.0 * - * @param $function (string) + * @param string $function * @return $allowed (boolean) */ private function is_function_allowed( $function ) { @@ -740,7 +746,7 @@ private function is_function_allowed( $function ) { * @date 17/12/2015 * @since 0.3.0 * - * @param $args (ellipsis) + * @param ellipsis $args * @return $key (string) */ private function generate_cache_key() { @@ -765,8 +771,8 @@ private function generate_cache_key() { * @since 0.3.0 * * - * @param $function (string) - * @param $args (array) + * @param string $function + * @param array $args * @return mixed */ public function run_restricted( $function ) { @@ -786,8 +792,8 @@ public function run_restricted( $function ) { * @since 1.2.0 * * - * @param $function (string) - * @param $args (array) + * @param string $function + * @param array $args * @return mixed */ protected function rename_model( $name ) { @@ -811,7 +817,7 @@ protected function rename_model( $name ) { /** * A recursive array search. * - * @param any $needle + * @param mixed $needle * @param array $haystack * @param boolean $strict * @return boolean diff --git a/classes/query.php b/classes/query.php index 7154634b..c891330c 100644 --- a/classes/query.php +++ b/classes/query.php @@ -29,8 +29,8 @@ class Query { * @date 20/3/2015 * @since 0.0.1 * - * @param $id (int) - * @param $args (array) + * @param int $id + * @param array $args * * @return array|object|null Type corresponding to output type on success or null on failure. */ @@ -87,8 +87,8 @@ public static function get_post( $id = null, $args = array() ) { * @date 20/3/2015 * @since 0.0.1 * - * @param $id (int) - * @param $args (array) + * @param int $id + * @param array $args * * @return array|object|null Type corresponding to output type on success or null on failure. */ @@ -107,6 +107,7 @@ public static function get_acf_post( $id = null, $args = array() ) { $options = array_merge( $defaults, $args ); +// FIXME -> WP func. extract( $options ); // Throw error if we have no post to fetch @@ -175,10 +176,10 @@ public static function get_acf_post( $id = null, $args = array() ) { * @date 16/8/2016 * @since 1.1.5 * - * @param array|object $field The current ACF field object. - * @param object $options Recurion options. + * @param array|object $field The current ACF field object. + * @param object $options Recurion options. * - * @return any $field Returns the same type it is given, possibly extended. + * @return mixed Returns the same type it is given, possibly extended. */ private static function handle_field( $field, $options ) { // No recursion for these post types @@ -236,6 +237,7 @@ public static function get_posts( $args ) { $options = array_merge( $defaults, $args ); +// FIXME -> WP function extract( $options ); self::$query = new WP_Query( $options ); @@ -262,9 +264,9 @@ public static function get_posts( $args ) { // Return in the desired format. return self::query_return_value_format( self::$query , $query_object, $no_found_rows ); - } else { - return false; - } + } + + return false; } /** @@ -277,7 +279,7 @@ public static function get_posts( $args ) { * * @param array $args Arguments to override the defaults defined in get_wp_query_defaults. * - * @return array/boolean Array of posts as an associative array with acf fields and meta data + * @return array|boolean Array of posts as an associative array with acf fields and meta data */ public static function get_acf_posts( $args ) { @@ -347,11 +349,11 @@ public static function get_acf_posts( $args ) { /** * A wrapper for posts query function return value formatting. * - * @param objecy $query The WP_Query object. - * @param boolean $query_object Do we want the whole query object? - * @param boolean $no_found_rows Was the query paginated? + * @param \WP_Query $query The WP_Query object. + * @param boolean $query_object Do we want the whole query object? + * @param boolean $no_found_rows Was the query paginated? * - * @return object|array + * @return \WP_Query|array */ private static function query_return_value_format( $query, $query_object, $no_found_rows ) { // Maybe return the whole query object diff --git a/dustpress.php b/dustpress.php index 907a00c1..cd799156 100644 --- a/dustpress.php +++ b/dustpress.php @@ -44,6 +44,10 @@ final class DustPress { // Custom routes private $custom_routes = []; + private $request_data; + + private $autoload_paths; + public static function instance() { if ( ! isset( self::$instance ) ) { self::$instance = new DustPress(); @@ -57,9 +61,6 @@ public static function instance() { * @type function * @date 10/8/2015 * @since 0.2.0 - * - * @param N/A - * @return N/A */ protected function __construct() { @@ -162,9 +163,6 @@ protected function __construct() { * @type function * @date 19/3/2019 * @since 1.13.1 - * - * @param N/A - * @return N/A */ public function rewrite_tags() { // Register custom route rewrite tag @@ -180,9 +178,6 @@ public function rewrite_tags() { * @type function * @date 19/3/2015 * @since 0.0.1 - * - * @param N/A - * @return N/A */ public function create_instance() { global $post, $wp_query; @@ -274,7 +269,6 @@ public function create_instance() { * @date 8/1/2019 * @since 1.20.0 * - * @param N/A * @return string|boolean */ public function get_custom_route() { @@ -301,8 +295,7 @@ public function get_custom_route() { * @date 19/3/2015 * @since 0.0.1 * - * @param N/A - * @return $filename (string) + * @return string */ private function get_template_filename( &$debugs = array() ) { @@ -579,9 +572,6 @@ function() { * @type function * @date 17/3/2015 * @since 0.0.1 - * - * @param N/A - * @return N/A */ private function populate_data_collection() { $wp_data = array(); @@ -663,14 +653,12 @@ private function populate_data_collection() { * @date 17/3/2015 * @since 0.0.1 * - * @param $partial (string) - * @param $data (N/A) - * @param $type (string) - * @return true/false (boolean) + * @param array $args + * @return bool */ public function render( $args = array() ) { - global $dustpress; - $hash; + global $dustpress; + global $hash; $defaults = [ 'data' => false, @@ -687,6 +675,7 @@ public function render( $args = array() ) { $options = array_merge( $defaults, (array) $args ); +// FIXME -> WP function extract( $options ); if ( 'default' == $type && ! get_option( 'dustpress_default_format' ) ) { @@ -833,7 +822,7 @@ public function render( $args = array() ) { * @date 17/3/2015 * @since 0.0.1 * - * @param $partial (string) + * @param string $partial * @return $template (string) */ private function get_template( $partial ) { @@ -867,8 +856,6 @@ private function get_template( $partial ) { * @type function * @date 01/04/2016 * @since 0.4.0 - * - * @return N/A */ public function init_settings() { @@ -918,8 +905,7 @@ public function get_setting( $key ) { * @date 9/4/2015 * @since 0.0.7 * - * @param N/A - * @return true/false (boolean) + * @return bool */ public function is_login_page() { @@ -934,8 +920,8 @@ public function is_login_page() { * @date 15/6/2015 * @since 0.1.0 * - * @param $string (string) - * @param $char (string) + * @param string $string + * @param string $char * @return (string) */ public function camelcase_to_dashed( $string, $char = '-' ) { @@ -956,8 +942,8 @@ public function camelcase_to_dashed( $string, $char = '-' ) { * @date 1/10/2016 * @since 1.2.9 * - * @param $string (string) - * @param $char (string) + * @param string $string + * @param string $char * @return (string) */ public function dashed_to_camelcase( $string, $char = '-' ) { @@ -1070,8 +1056,8 @@ private function is_dustpress_ajax() { * @date 25/11/2016 * @since 1.3.2 * - * @param $key (string) - * @param $callable (mixed) + * @param string $key + * @param mixed $callable * * @return void */ @@ -1099,9 +1085,6 @@ public function ajax_function_exists( $key ) { * @type function * @date 17/12/2015 * @since 0.3.0 - * - * @param N/A - * @return N/A */ public function create_ajax_instance() { global $post; @@ -1299,7 +1282,7 @@ public function create_ajax_instance() { * @date 17/12/2015 * @since 0.3.0 * - * @param $partial (string) + * @param string $partial * @param $already (array|string) (optional) * @return $helpers (array|string) */ @@ -1353,7 +1336,7 @@ public function prerender( $partial, $already = [] ) { * @date 17/12/2015 * @since 0.3.0 * - * @param $partial (string) + * @param string $partial * @return $file (string) */ public function get_prerender_file( $partial ) { @@ -1374,8 +1357,7 @@ public function get_prerender_file( $partial ) { * @date 17/12/2015 * @since 0.3.0 * - * @param $helpers (array|string) - * @return N/A + * @param array|string $helpers */ public function prerun_helpers( $helpers ) { if ( is_array( $helpers ) ) { @@ -1404,7 +1386,7 @@ public function prerun_helpers( $helpers ) { * @date 21/03/2018 * @since 1.14.0 * - * @param N/A + * @param bool $force * @return array */ public function get_templates( $force = false ) { @@ -1443,7 +1425,7 @@ public function get_templates( $force = false ) { * @date 02/06/2016 * @since 0.3.3 * - * @param $param (mixed) + * @param mixed $param * @return $param */ public function disable( $param = null ) { @@ -1459,7 +1441,7 @@ public function disable( $param = null ) { * @date 08/06/2016 * @since 0.4.0 * - * @param $param (mixed) + * @param mixed $param * @return $param */ public function add_helper( $name, $instance ) { @@ -1472,9 +1454,6 @@ public function add_helper( $name, $instance ) { * @type function * @date 08/06/2016 * @since 0.04.0 - * - * @param N/A - * @return N/A */ private function register_autoloaders() { // Autoload DustPHP classes diff --git a/helpers/contains.php b/helpers/contains.php index 41bf6a75..320fd99e 100644 --- a/helpers/contains.php +++ b/helpers/contains.php @@ -14,8 +14,8 @@ class Contains extends \Dust\Helper\Comparison { * Implements the isValid function of the Comparison class. * Checks whether a given value is in an array/object. * - * @param object/array $key The array/object to look from. - * @param any $value The value to look for. + * @param object|array $key The array or object to look in. + * @param mixed $value The value to look for. * @return boolean */ public function isValid( $key, $value ) { diff --git a/helpers/pagination.php b/helpers/pagination.php index 88a00b6e..557b9fe9 100644 --- a/helpers/pagination.php +++ b/helpers/pagination.php @@ -191,7 +191,7 @@ public function output() { // Add this data to DustPress debuggers output. $debugger_class = __NAMESPACE__ . '\Debugger'; if ( \class_exists( $debugger_class ) && \method_exists( $debugger_class, 'set_debugger_data' ) ) { - Debugger::set_debugger_data( 'Pagination', $data ); + $debugger_class::set_debugger_data( 'Pagination', $data ); } return dustpress()->render( diff --git a/models/user-activate.php b/models/user-activate.php index 65fe763f..05125446 100644 --- a/models/user-activate.php +++ b/models/user-activate.php @@ -7,6 +7,7 @@ class UserActivate extends \DustPress\Model { private $state; private $print; + private $signup; /** * Returns the state of the page and sets the right strings for printing. @@ -57,6 +58,7 @@ public function State() { } } else { +// FIXME $user, $url $this->print['username'] = $user->user_login; $this->print['password'] = $result['password']; $state = "account-active-no-mail"; @@ -80,8 +82,6 @@ public function State() { return $state; } - - /** * Returns strings for printing. * @@ -99,4 +99,4 @@ public function Print() { return $this->print; } -} \ No newline at end of file +}