/** * sets the properties for class either to defaults or using incoming initialization array * * @access private * @param array $init array on init (keys match properties others ignored) * @return void */ private function _init($init) { $defaults = array('_upload_to' => $this->_get_wp_uploads_dir(), '_upload_from' => '', '_permissions' => 0644, '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'); $props = array_merge($defaults, $init); foreach ($props as $key => $val) { if (EEH_Class_Tools::has_property($this, $key)) { $this->{$key} = $val; } } //make sure we include the required wp file for needed functions require_once ABSPATH . 'wp-admin/includes/file.php'; }
/** * loads and tracks classes * * @param array $file_paths * @param string $class_prefix - EE or EEM or... ??? * @param bool|string $class_name - $class name * @param string $type - file type - core? class? helper? model? * @param mixed $arguments - an argument or array of arguments to pass to the class upon instantiation * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate * @param bool $cache * @param bool $load_only * @internal param string $file_path - file path including file name * @return bool | object */ private function _load($file_paths = array(), $class_prefix = 'EE_', $class_name = FALSE, $type = 'class', $arguments = array(), $from_db = FALSE, $cache = TRUE, $load_only = FALSE) { // strip php file extension $class_name = str_replace('.php', '', trim($class_name)); // does the class have a prefix ? if (!empty($class_prefix) && $class_prefix != 'addon') { // make sure $class_prefix is uppercase $class_prefix = strtoupper(trim($class_prefix)); // add class prefix ONCE!!! $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); } $class_abbreviations = array('EE_Cart' => 'CART', 'EE_Config' => 'CFG', 'EE_Network_Config' => 'NET_CFG', 'EE_Request_Handler' => 'REQ', 'EE_Session' => 'SSN'); // check if class has already been loaded, and return it if it has been if (isset($class_abbreviations[$class_name]) && !is_null($this->{$class_abbreviations}[$class_name])) { return $this->{$class_abbreviations}[$class_name]; } else { if (isset($this->{$class_name})) { return $this->{$class_name}; } else { if (isset($this->LIB->{$class_name})) { return $this->LIB->{$class_name}; } else { if ($class_prefix == 'addon' && isset($this->addons->{$class_name})) { return $this->addons->{$class_name}; } } } } // assume all paths lead nowhere $path = FALSE; // make sure $file_paths is an array $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); // cycle thru paths foreach ($file_paths as $key => $file_path) { // convert all separators to proper DS, if no filepath, then use EE_CLASSES $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; // prep file type $type = !empty($type) ? trim($type, '.') . '.' : ''; // build full file path $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; //does the file exist and can be read ? if (is_readable($file_paths[$key])) { $path = $file_paths[$key]; break; } } // don't give up! you gotta... try { //does the file exist and can it be read ? if (!$path) { // so sorry, can't find the file throw new EE_Error(sprintf(__('The %s file %s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %s', 'event_espresso'), trim($type, '.'), $class_name, implode(', ', $file_paths))); } // get the file require_once $path; // if the class isn't already declared somewhere if (class_exists($class_name, FALSE) === FALSE) { // so sorry, not a class throw new EE_Error(sprintf(__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), $type, $path, $class_name)); } } catch (EE_Error $e) { $e->get_error(); } // don't give up! you gotta... try { // create reflection $reflector = new ReflectionClass($class_name); // instantiate the class and add to the LIB array for tracking // EE_Base_Classes are instantiated via new_instance by default (models call them via new_instance_from_db) if ($reflector->getConstructor() === NULL || $reflector->isAbstract() || $load_only) { // $instantiation_mode = 0; // no constructor = static methods only... nothing to instantiate, loading file was enough } else { if ($from_db && method_exists($class_name, 'new_instance_from_db')) { // $instantiation_mode = 1; $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); } else { if (method_exists($class_name, 'new_instance')) { // $instantiation_mode = 2; $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); } else { if (method_exists($class_name, 'instance')) { // $instantiation_mode = 3; $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); } else { if ($reflector->isInstantiable()) { // $instantiation_mode = 4; $class_obj = $reflector->newInstance($arguments); } else { if (!$load_only) { // heh ? something's not right ! // $instantiation_mode = 5; throw new EE_Error(sprintf(__('The %s file %s could not be instantiated.', 'event_espresso'), $type, $class_name)); } } } } } } } catch (EE_Error $e) { $e->get_error(); } // echo '<h4>$class_name : ' . $class_name . ' <br /><span style="font-size:10px;font-weight:normal;">$instantiation_mode : ' . $instantiation_mode . '<br/>' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; // echo '<h4>$from_db : ' . $from_db . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; // echo '<h4>$cache : ' . $cache . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; // echo '<h4>$load_only : ' . $load_only . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; // printr( $arguments, '$arguments <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); // printr( $class_obj, '$class_obj <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); if (isset($class_obj)) { // return newly instantiated class if (isset($class_abbreviations[$class_name])) { $this->{$class_abbreviations}[$class_name] = $class_obj; } else { if (EEH_Class_Tools::has_property($this, $class_name)) { $this->{$class_name} = $class_obj; } else { if ($class_prefix == 'addon' && $cache) { $this->addons->{$class_name} = $class_obj; } else { if (!$from_db && $cache) { $this->LIB->{$class_name} = $class_obj; } } } } return $class_obj; } return FALSE; }
/** * EE_Event_List_Query Constructor * * sets up a WordPress query * * @param array $args * @return \EE_Event_List_Query */ function __construct($args = array()) { // printr( $args, '$args <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); // incoming args could be a mix of WP query args + EE shortcode args foreach ($args as $key => $value) { $property = '_' . $key; // if the arg is a property of this class, then it's an EE shortcode arg if (EEH_Class_Tools::has_property($this, $property)) { // set the property value $this->{$property} = $value; // then remove it from the array of args that will later be passed to WP_Query() unset($args[$key]); } } // setup the events list query EE_Registry::instance()->load_helper('Event_Query'); EEH_Event_Query::filter_query_parts(); EEH_Event_Query::set_query_params($this->_month, $this->_category_slug, $this->_show_expired, $this->_order_by, $this->_sort); // first off, let's remove any filters from previous queries remove_filter('FHEE__archive_espresso_events_template__upcoming_events_h1', array($this, 'event_list_title')); remove_all_filters('FHEE__content_espresso_events__event_class'); // Event List Title ? add_filter('FHEE__archive_espresso_events_template__upcoming_events_h1', array($this, 'event_list_title'), 10, 1); // add the css class add_filter('FHEE__content_espresso_events__event_class', array($this, 'event_list_css'), 10, 1); // the current "page" we are viewing $paged = max(1, get_query_var('paged')); // Force these args $args = array_merge($args, array('post_type' => 'espresso_events', 'posts_per_page' => $this->_limit, 'update_post_term_cache' => FALSE, 'update_post_meta_cache' => FALSE, 'paged' => $paged, 'offset' => ($paged - 1) * $this->_limit)); // run the query parent::__construct($args); }
public function __construct($setup_array) { foreach ($setup_array as $prop => $value) { if (EEH_Class_Tools::has_property($this, $prop)) { $this->{$prop} = $value; } } }
/** * _question_form_input_property_exists * @access private * @param string $classname * @param string $property * @return boolean */ private function _question_form_input_property_exists($classname, $property) { // first try regular property exists method which works as expected in PHP 5.3+ $prop = EEH_Class_Tools::has_property($classname, $property); if (!$prop) { // use reflection for < PHP 5.3 as a double check when property is not found, possible due to access restriction $reflector = new ReflectionClass($classname); $prop = $reflector->hasProperty($property); } return $prop; }
/** * Constructor. * * @since 4.4.0 * * @param array $menu_args An array of arguments used to setup the menu * properties on construct. * @param array $required An array of keys that should be in the $menu_args, this * is used to validate that the items that should be defined * are present. * @return void */ public function __construct($menu_args, $required) { //verify that required keys are present in the incoming array. $missing = array_diff((array) $required, array_keys((array) $menu_args)); if (!empty($missing)) { throw new EE_Error(sprintf(__('%s is missing some expected keys in the argument array. The following keys are missing: %s', 'event_espresso'), get_class($this), implode(', ', $missing))); } //made it here okay, so let's set the properties! foreach ($menu_args as $prop => $value) { switch ($prop) { case 'show_on_menu': $value = (bool) $value; break; case 'admin_init_page': if (in_array('admin_init_page', $required) && !$value instanceof EE_Admin_Page_Init) { throw new EE_Error(sprintf(__('The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object. Instead %s was given as the value.', 'event_espresso'), print_r($value, TRUE))); } break; case 'menu_callback': break; default: $value = (string) $value; break; } if (!EEH_Class_Tools::has_property($this, $prop)) { throw new EE_Error(sprintf(__('The $menu_args coming into %s has a index key (%s) representing a property that is not defined by the class. Perhaps there is a typo?', 'event_espresso'), get_class($this), $prop)); } $this->{$prop} = $value; } //filter capabilities (both static and dynamic) $this->capability = apply_filters('FHEE_management_capability', $this->capability, NULL); $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, NULL); //Might need to change parent slug depending on maintenance mode. if (!empty($this->maintenance_mode_parent) && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) { $this->parent_slug = $this->maintenance_mode_parent; } //if empty menu_callback let's set default (but only if we have admin page init object) if (empty($this->menu_callback) && $this->admin_init_page instanceof EE_Admin_Page_Init) { $this->menu_callback = array($this->admin_init_page, 'initialize_admin_page'); } }
/** * get_existing_admin_settings * (if needed) sets and returns the _existing_admin_settings property. * * @access public * @return array settings */ public function get_existing_admin_settings($messenger = NULL) { // if admin_settings property empty lets try setting it. if (method_exists($this, '_set_existing_admin_settings') && empty($this->_existing_admin_settings)) { $this->_set_existing_admin_settings($messenger); } return EEH_Class_Tools::has_property($this, '_existing_admin_settings') ? $this->_existing_admin_settings : null; }
protected function _update_settings() { EE_Registry::instance()->load_helper('Class_Tools'); if (isset($_POST['reset_new_addon']) && $_POST['reset_new_addon'] == '1') { $config = new EE_New_Addon_Config(); $count = 1; } else { $config = EE_Config::instance()->get_config('addons', 'EED_New_Addon', 'EE_New_Addon_Config'); $count = 0; //otherwise we assume you want to allow full html foreach ($this->_req_data['new_addon'] as $top_level_key => $top_level_value) { if (is_array($top_level_value)) { foreach ($top_level_value as $second_level_key => $second_level_value) { if (EEH_Class_Tools::has_property($config, $top_level_key) && EEH_Class_Tools::has_property($config->{$top_level_key}, $second_level_key) && $second_level_value != $config->{$top_level_key}->{$second_level_key}) { $config->{$top_level_key}->{$second_level_key} = $this->_sanitize_config_input($top_level_key, $second_level_key, $second_level_value); $count++; } } } else { if (EEH_Class_Tools::has_property($config, $top_level_key) && $top_level_value != $config->{$top_level_key}) { $config->{$top_level_key} = $this->_sanitize_config_input($top_level_key, NULL, $top_level_value); $count++; } } } } EE_Config::instance()->update_config('addons', 'EED_New_Addon', $config); $this->_redirect_after_action($count, 'Settings', 'updated', array('action' => $this->_req_data['return_action'])); }
/** * This simply loops through the data and makes sure that each item is present in the incoming data. If it is then it is assigned to the property. * * @access protected * @return void. */ protected function _set_properties() { foreach ($this->_data as $prop => $value) { if (EEH_Class_Tools::has_property($this, $prop)) { $this->{$prop} = $value; } } //if user_id present we'll use this to set the fname and lname and admin_email. if (!empty($this->user_id)) { $this->user_id = (int) $this->user_id; $user = get_userdata($this->user_id); $this->fname = $user->user_firstname; $this->lname = $user->user_lastname; $this->admin_email = $user->user_email; } }