public function __construct($message, $http_status, array $options = array()) { // Set message $this->message = $message; // Set defaults $this->http_status = self::DEFAULT_HTTP_STATUS; // Set options $this->data = new Collection(); $this->data->set($options); }
/** * Sets default labels based on singular and plural names * * @return void */ private function __setDefaultLabels() { $singular = $this->config->get('singular_name'); $plural = $this->config->get('plural_name'); $labels = array('name' => _x($plural, 'taxonomy general name'), 'singular_name' => _x($singular, 'taxonomy singular name'), 'search_items' => __('Search ' . $plural), 'all_items' => __('All ' . $plural), 'parent_item' => __('Parent ' . $singular), 'parent_item_colon' => __('Parent ' . $singular . ':'), 'edit_item' => __('Edit ' . $singular), 'update_item' => __('Update ' . $singular), 'add_new_item' => __('Add New ' . $singular), 'new_item_name' => __('New ' . $singular . ' Name'), 'menu_name' => __($plural)); $this->setLabels($labels); }
/** * Sets a single default attribute * * @param string $key Attribute key * @param mixed $value Attribute value * @return Ponticlaro\Bebop\Cms\Shortcode This class instance */ public function setDefaultAttr($key, $value) { if (is_string($key)) { $this->default_attributes->set($key, $value); } return $this; }
/** * Build configuration * * @return object This class instance */ public function build() { // Making sure we do not run this twice if ($this->already_built) { return $this; } // Run configuration hooks $this->runHooks(); // Build configuration items if ($build_config = $this->config->get('build.all')) { foreach ($build_config as $section_name => $configs) { foreach ($configs as $config_obj) { // Merge with current environment configuration, if it exists $env_config_path = "build.{$this->current_env}.{$section_name}." . $config_obj->getId(); if ($env_config = $this->config->get($env_config_path)) { $config_obj = $config_obj->merge($env_config); } // Build configuration item $config_obj->build(); } } } // Mark configuration as built $this->already_built = true; return $this; }
/** * Returns built configuration array * * @return array */ public function getFullConfig() { $config = $this->config->getAll(); $config['labels'] = $this->getLabels(); $config['supports'] = $this->getFeatures(); $config['capabilities'] = $this->getCapabilities(); $config['taxonomies'] = $this->getTaxonomies(); $config['rewrite'] = $this->getRewrite(); return $config; }
/** * Adds a single list * * @param \Ponticlaro\Bebop\UI\Plugins\ContentList $list ContentList instance */ public function addList(\Ponticlaro\Bebop\UI\Plugins\ContentList\ContentList $list, array $data = array()) { // Override list data if ($data) { $list->setData($data); } // Store list $this->__lists->push($list); return $this; }
/** * Returns a single context container by ID * * @param string $id ID of the target context container * @return Ponticlaro\Bebop\Common\ContextContainer Target context container */ private function __getContextById($id) { $target_context = null; foreach ($this->contexts->getAll() as $context) { if ($context->getId() == $id) { $target_context = $context; break; } } return $target_context; }
/** * Renders tab content * * @return void */ public function render() { $this->__setData(); // Execute callable if ($function = $this->getFunction()) { call_user_func_array($function, array($this->data, $this)); } // Render sections $sections = $this->getAllSections(); if ($sections) { foreach ($sections as $section) { $section->render($this->data->getAll()); } } }
/** * Returns query metadata * * @return array */ protected function __getQueryMeta() { $args = $this->clean_args->getAll(); $meta = array(); $meta['items_total'] = (int) $this->query->found_posts; $meta['items_returned'] = (int) $this->query->post_count; $meta['total_pages'] = (int) $this->query->max_num_pages; $meta['current_page'] = $this->query->max_num_pages === 0 ? 0 : (int) max(1, $this->query->query_vars['paged']); $meta['has_more'] = $meta['current_page'] == $meta['total_pages'] || $meta['total_pages'] == 0 ? false : true; // Remove post_type parameter when not querying the /posts resource if (isset($resource_name) && $resource_name != 'posts' && isset($args['post_type'])) { unset($args['post_type']); } $meta['previous_page'] = in_array($meta['current_page'], [0, 1]) ? null : $this->__buildPreviousPageUrl($this->raw_args->getAll()); $meta['next_page'] = $meta['current_page'] == $meta['total_pages'] || $meta['total_pages'] == 0 ? null : $this->__buildNextPageUrl($this->raw_args->getAll()); return $meta; }
/** * Returns element children HTML * * @return string Element children HTML */ public function getChildrenHtml() { $html = ''; if (!$this->isSelfClosing()) { $children = $this->config->get('children') ?: []; if ($children) { foreach ($children as $child) { if (is_string($child)) { $html .= $child; } else { $html .= $child->getHtml(); } } } } return $html; }
/** * Renders single page UI * * @return void */ protected function renderSinglePage() { echo '<div style="padding-top:30px;">'; settings_fields($this->getId()); $this->__setData(); // Execute callable if ($function = $this->getFunction()) { call_user_func_array($function, array($this->data, $this)); } // Render sections $sections = $this->getAllSections(); if ($sections) { foreach ($sections as $section) { $section->render($this->data->getAll()); } } echo '</div>'; }
/** * Saves meta data * * @param int $post_id ID of the post currently being edited * @return void */ public function __saveMeta($post_id) { // Return if this is a quick edition if (isset($_POST['_inline_edit']) && wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce')) { return; } $id = $this->getId(); $nonce_name = 'metabox_' . $id . '_nonce'; $nonce = isset($_POST[$nonce_name]) ? $_POST[$nonce_name] : ''; // Check if $_POST is not empty and nonce is there if (!empty($_POST) && wp_verify_nonce($nonce, 'metabox_' . $id . '_saving_meta')) { $post = get_post($post_id); if (isset($_POST['post_type']) && $_POST['post_type'] == $post->post_type) { // Get out if current post is in the middle of an auto-save if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Get out if current user cannot edit this post if (!current_user_can('edit_post', $post_id)) { return $post_id; } // Get fields from callback function $this->__setMetaFields(); foreach ($this->meta_fields->getAll() as $field) { $value = isset($_POST[$field]) ? $_POST[$field] : ''; // Empty values if ($value === '') { delete_post_meta($post_id, $field); } elseif (is_array($value)) { // Delete all entries delete_post_meta($post_id, $field); foreach ($value as $v) { // Add single entry with same meta_key add_post_meta($post_id, $field, $v); } } else { update_post_meta($post_id, $field, $value); } } } } }
/** * Renders this view * * @param string $template Template relative path, without file extension * @param array $vars List of vars for rendering * @param boolean $merge True if these vars should merge with existing ones, false otherwise * @return void */ public function render($template = null, array $vars = array(), $merge = true) { // Throw error if we neither already have a template // or one is not provided in this method if (is_null($this->template) && (!$template || !is_string($template))) { throw new \Exception('You must defined a template to be rendered'); } elseif ($this->template && is_array($template)) { $vars = $template; $merge = is_bool($vars) ? $vars : true; } // Set template and variables $this->setTemplate($template); $this->setVars($vars, $merge); // Expose variables to template foreach ($this->vars->getAll() as $key => $value) { ${$key} = $value; } // Include template include $this->__getTemplatePath($this->getTemplate()); }
/** * Starts router * * @return void */ public function run() { // Remove WordPress Content-Type header & Set Slim response content-type header header_remove('Content-Type'); $this->slim->response()->header('Content-Type', 'application/json'); $this->handleErrors()->preFlightCheck()->handleNotFound()->handleResponse(); $rewrite_tag = $this->getRewriteTag(); $base_url = $this->getBaseUrl(); // Loop through all defined routes foreach ($this->routes->getAll() as $route) { $this->slim->{$route->getMethod()}('/' . $base_url . trim($route->getPath(), '/'), function () use($route, $rewrite_tag) { // Get data from route function $data = call_user_func_array($route->getFunction(), func_get_args()); // Enable developers to modify global response $data = apply_filters($rewrite_tag . ':response', $data); // Send response $this->slim->applyHook('handle_response', $data); }); } $this->slim->run(); }
/** * Returns all data * * @return array */ public function getAll() { return $this->data->getAll(); }
/** * Returns all routes * * @return array Routes list */ public function getAll() { return $this->routes->getAll(); }
/** * Returns Api URL prefix * * @return string */ public function getBaseUrl() { return trim($this->config->get('base_url'), '/') . '/'; }