"end_date",
"location",
"other_informations",
"related", "@related_posts" => function ($p) {
return (new Pages)->join(new News)->join(new Projects)->is($p->related)->get();
},
"author",
"author_custom",
"@author_person" => function ($p) {
$person = (new People)->is($p->author)->getOne();
if ($person) {
$url = site_url("about/organisation");
$url .= "?people_type=" . implode(" ", (array) $person->people_type->getSlugs());
$url .= "&focus=" . $person->post_name;
}
return [
"picture" => $person ? $person->thumb->url : $p->author_custom["profile_picture"],
"name" => $person ? $person->post_title : $p->author_custom["name"],
"url" => $person ? $url : false,
"job" => $person ? $person->job : $p->author_custom["job"],
];
},
"@event_date" => function ($p) {
if ($p->is_event) {
$start_d = date("d", strtotime($p->start_date));
$start_m = date("F", strtotime($p->start_date));
$start_y = date("Y", strtotime($p->start_date));
$end_d = date("d", strtotime($p->end_date));
$end_m = date("F", strtotime($p->end_date));
$end_y = date("Y", strtotime($p->end_date));
if ($start_y == $end_y && $start_m == $end_m) return $start_d . "-" . $end_d . " " . $end_m . " " . $end_y;
return date("d F Y", strtotime($p->start_date)) . " - " . date("d F Y", strtotime($p->end_date));
}
return date("d F Y", strtotime($p->start_date));
},
Arguments
"Trying to access array offset on value of type null"
"end_date",
"location",
"other_informations",
"related", "@related_posts" => function ($p) {
return (new Pages)->join(new News)->join(new Projects)->is($p->related)->get();
},
"author",
"author_custom",
"@author_person" => function ($p) {
$person = (new People)->is($p->author)->getOne();
if ($person) {
$url = site_url("about/organisation");
$url .= "?people_type=" . implode(" ", (array) $person->people_type->getSlugs());
$url .= "&focus=" . $person->post_name;
}
return [
"picture" => $person ? $person->thumb->url : $p->author_custom["profile_picture"],
"name" => $person ? $person->post_title : $p->author_custom["name"],
"url" => $person ? $url : false,
"job" => $person ? $person->job : $p->author_custom["job"],
];
},
"@event_date" => function ($p) {
if ($p->is_event) {
$start_d = date("d", strtotime($p->start_date));
$start_m = date("F", strtotime($p->start_date));
$start_y = date("Y", strtotime($p->start_date));
$end_d = date("d", strtotime($p->end_date));
$end_m = date("F", strtotime($p->end_date));
$end_y = date("Y", strtotime($p->end_date));
if ($start_y == $end_y && $start_m == $end_m) return $start_d . "-" . $end_d . " " . $end_m . " " . $end_y;
return date("d F Y", strtotime($p->start_date)) . " - " . date("d F Y", strtotime($p->end_date));
}
return date("d F Y", strtotime($p->start_date));
},
update_field($key, $value, $post_id);
}
}
/**
* Take a field key and parse its value
*
* @return array
*/
public static function getAdvanced($key, $value, $post_id = null, $callback_context = false)
{
// Get the key parts (store, meta, filter)
$key_parts = Data::parseDataKey($key);
// get value and filter it as/if suggested
$value = $key_parts["meta"] ? self::get($key_parts["meta"], $post_id, $value, $key_parts["filter"]) : $value;
// Execute callable functions
if (is_callable($value) && !is_string($value)) {
$value = $value($callback_context);
}
return [
"key" => $key_parts["store"],
"value" => $value,
];
}
/**
* Normalize the keys of a list of fields
*
* @param Set|array $fields
* @return Set
*/
public static function normalizeFieldsKeys($fields)
{
return (set($fields))->mapAssoc(function ($key, $value) {
if (is_int($key)) {
return [$value, null];
}
if (empty($this->model->fieldsIndex)) {
return false;
}
return $this->model->fieldsIndex->hasKey($field);
}
/**
* Get a field value and property from the model
*
* @param string $field
* @return array
*/
public function getFieldFromModel($field)
{
return Data::getAdvanced(
$this->model->fieldsIndex[$field],
$this->model->fields[$this->model->fieldsIndex[$field]],
static::FIELD_PREFIX . $this->getID(),
$this,
);
}
/**
* Get a field value and property
*
* @param string $field
* @return array
*/
public function getField($field, $default = "", $filter = false)
{
return Data::get($field, static::FIELD_PREFIX . $this->getID(), $default, $filter);
}
/**
* Pre-fetch all the fields specified in the model
*
* @return self
*/
public function fetchFields($fields = true)
if (!$this->model) {
return $this;
}
if (empty($fields)) {
return $this;
}
// Fetch all fields if "true" given as argument
$fields = $fields === true ? $this->model->fieldsIndex->keys() : $fields;
foreach ($fields as $field) {
$key = $this->model->fieldsIndex[$field] ?? false;
// Field does not exist in the index
if (empty($key)) {
continue;
}
// Force the value fetching, erasing potential existing fields
$data = $this->getFieldFromModel($field);
$this->{$data["key"]} = $data["value"];
}
return $this;
}
// ==================================================
// > GETTERS / SETTERS
// ==================================================
/**
* ID normalizer for all model resuts
*
* @return int
*/
public function getID()
{
return $this->ID;
}
/**
$wp_object_or_id = $wp_object_or_id === 0 ? false : $this->model::getObject($wp_object_or_id);
if (!$wp_object_or_id || (isset($wp_object_or_id->ID) && $wp_object_or_id->ID == 0)) {
$wp_object_or_id = $this->model::getDummyObject();
}
} else {
// Only keep the ID, only allows some simple methods
$this->setID($wp_object_or_id);
}
}
// Extract all properties of the object
if (is_object($wp_object_or_id)) {
foreach (static::filterObjectKeys($wp_object_or_id) as $key => $value) {
$this->{$key} = $value;
}
}
// Fetch all fields if the model requests it
if ($this->model) {
$this->fetchFields($this->model->forceFetchFields);
}
}
/**
* Check that the object was found and exists
*
* @return bool
*/
public function exists()
{
return !empty($this->ID);
}
/**
* Set the model for this item.
* Allow to change the model after it's been initialize, or to prevent useless SQL queries
*
* @param Model $model
* @return self
*/
*
* @param $query
* @return array of Item
*/
protected function getResultsFromQuery($query)
{
return set(array_map(function ($item) {
// Anything else than ITEM_CLASS : return as is
if (!is_object($item) || get_class($item) !== static::OBJECT_CLASS) {
return $item;
}
// Edge case for models that support joins
if ($join_item = $this->parseJoinItem($item)) {
return $join_item;
}
// Wrap objects in Item, return IDs as is
$class = static::ITEM_CLASS;
return new $class($item, $this);
}, $query->{static::OBJECT_KEY} ?: []));
}
/**
* Allow chilidren to support joined model
*
* @return ModelItem of a different model
*/
public function parseJoinItem($item)
{
return false;
}
/**
* Get an object instance
*
* @return WP_...
*/
public static function getObject($id)
{
* @param $query
* @return array of Item
*/
protected function getResultsFromQuery($query)
{
return set(array_map(function ($item) {
// Anything else than ITEM_CLASS : return as is
if (!is_object($item) || get_class($item) !== static::OBJECT_CLASS) {
return $item;
}
// Edge case for models that support joins
if ($join_item = $this->parseJoinItem($item)) {
return $join_item;
}
// Wrap objects in Item, return IDs as is
$class = static::ITEM_CLASS;
return new $class($item, $this);
}, $query->{static::OBJECT_KEY} ?: []));
}
/**
* Allow chilidren to support joined model
*
* @return ModelItem of a different model
*/
public function parseJoinItem($item)
{
return false;
}
/**
* Get an object instance
*
* @return WP_...
*/
public static function getObject($id)
{
$class = static::OBJECT_CLASS;
// ==================================================
/**
* Execute the query and retrive all the found posts
*
* @param int $limit Number of posts to return
* @param int $page Page offset to use
* @return Set of WP_Post
*/
public function get($limit = false, $page = false)
{
$this->limit($limit)->page($page);
// Nothing changed since last query run, return result
if ($this->filters == $this->cachedFilters && $this->cachedResults->count()) {
return $this->cachedResults;
}
// Executre query and parse results
$this->cachedResults = $this->getResultsFromQuery(
$this->run()->cachedQuery
);
return apply_filters("syltaen_get_" . static::TYPE, $this->cachedResults, $this);
}
/**
* Only return the matching items' IDs
*
* @return Set
*/
public function getIDs()
{
$this->filters["fields"] = "ids";
return $this->get();
}
/**
* Extracts results from the query
*
* @param $query
/**
* Get several light item instances
*
* @return ModelItem
*/
public static function getLightItems($ids)
{
return set(array_map(function ($id) {
return static::getLightItem($id);
}, $ids ?: []));
}
/**
* Return only one result
*
* @return Item|bool
*/
public function getOne()
{
$results = $this->get(1);
return $this->found() ? $results[0] : false;
}
/**
* Execute the query with the filters and store the result
*
* @return self
*/
public function run()
{
if ($this->cachedQuery && $this->filters == $this->cachedFilters) {
return $this;
}
$this->clearCache();
$this->applyQueryModifiers();
$class = static::QUERY_CLASS;
$this->cachedQuery = new $class($this->filters);
$this->cachedFilters = $this->filters;
$this->{$this->post->post_type}();
// Populate & add the post to the context
$this->post = new Post($this->post, $this->model);
$this->data["post"] = $this->post;
}
}
// ==================================================
// > POST TYPES
// ==================================================
/**
* Data and view handling for News
*
* @return void
*/
private function news()
{
$this->model = new News;
$p = (new News)->is($this->data["post"]->ID)->status("all")->fetchFields()->getOne();
$this->view = $p->is_event ? "single-events" : "single-news";
$this->addData([
"@sections" => $this->processSections(),
"@sharer" => $this->getSharer(),
"@author" => $p->author_person,
"hide_footer" => false,
]);
}
/**
* Data and view handling for Projects
*
* @return void
*/
private function projects()
{
$this->model = new Projects;
namespace Syltaen;
class SingleController extends PageController
{
/**
* @var string
*/
public $view = "single";
/**
* Populate $this->data
*/
public function __construct($args = [])
{
parent::__construct($args);
// Use the post type as a method
if (method_exists($this, $this->post->post_type)) {
$this->{$this->post->post_type}();
// Populate & add the post to the context
$this->post = new Post($this->post, $this->model);
$this->data["post"] = $this->post;
}
}
// ==================================================
// > POST TYPES
// ==================================================
/**
* Data and view handling for News
*
* @return void
*/
private function news()
{
$this->model = new News;
$p = (new News)->is($this->data["post"]->ID)->status("all")->fetchFields()->getOne();
$this->view = $p->is_event ? "single-events" : "single-news";
// Clear obsolete flash data
if (!$same_session_page) {
Data::goToNextSessionPage();
}
// Class method call
if (is_string($resp)) {
// Extracts method
$method = false;
if (preg_match('/(.*)::(.*)/', $resp, $keys)) {
$resp = $keys[1];
$method = $keys[2];
}
// Add namespace to class
$classname = "Syltaen\\$resp";
// Instanciate the class with the arguments
$class = new $classname($args);
// Lauch mehtod if any
if ($method) {
$class->$method();
}
}
// Closure function call
if (is_callable($resp)) {
$resp($args);
}
exit;
}
// ==================================================
// > RULES
// ==================================================
/**
* @param $resp
* @param boolean $resp
* @param array $args
* @return boolean
*/
public static function is($condition, $resp = false, $args = null)
{
$conditions = (array) $condition;
foreach ($conditions as $condition) {
$argument = null;
if (preg_match('/(.*):(.*)/', $condition, $parts)) {
$condition = $parts[1];
$argument = $parts[2];
}
$condition = "is_" . $condition;
if (function_exists($condition) && $condition($argument)) {
if ($resp) {
static::respond($resp, $args);
}
return true;
};
}
return false;
}
/**
* Website is in maintenance mode
*
* @param boolean $resp
* @return void
*/
public static function maintenance($resp = false)
{
if (Data::get("maintenance_mode", "option") && !current_user_can("administrator")) {
static::respond($resp);
}
}
<?php
namespace Syltaen;
defined("ABSPATH") || exit;
// ==================================================
// > SINGLES
// ==================================================
Route::is("single", "SingleController::render");
Route::is("attachment", "SingleController::render");
// ==================================================
// > SEARCH
// ==================================================
Route::is("search", "PageController::search", ["search" => get_search_query(false)]);
// ==================================================
// > API
// ==================================================
Route::custom("api", "ApiController", ["method", "target", "mode"]);
// ==================================================
// > NINJA FORM PREVIEW
// ==================================================
Route::query("nf_preview_form", "PageController::ninjaFormPreview");
// ==================================================
// > PAGES
// ==================================================
Route::is(["home", "front_page"], "PageController::home");
Route::is("page", "PageController::page");
// ==================================================
// > 404
// ==================================================
Route::is("404", "PageController::error404");
}
break;
}
}
if ( ! $template ) {
$template = get_index_template();
}
/**
* Filters the path of the current template before including it.
*
* @since 3.0.0
*
* @param string $template The path of the template to include.
*/
$template = apply_filters( 'template_include', $template );
if ( $template ) {
include $template;
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
}
return;
}
Arguments
"/var/www/vhosts/effab.hungryminds.host/httpdocs/wp-content/themes/syltaen/index.php"
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( ! isset( $wp_did_header ) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once __DIR__ . '/wp-load.php';
// Set up the WordPress query.
wp();
// Load the theme template.
require_once ABSPATH . WPINC . '/template-loader.php';
}
Arguments
"/var/www/vhosts/effab.hungryminds.host/httpdocs/wp-includes/template-loader.php"
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';
Arguments
"/var/www/vhosts/effab.hungryminds.host/httpdocs/wp-blog-header.php"