static function do_the_methods($view, $model, $method_name, $args)
{
$value = null;
$suffix = $has_html_suffix = false;
if (preg_match('#^the_(.+)_template$#', $method_name, $match)) {
/*
* Put the $template name at the beginning of the $args array
*/
array_unshift($args, str_replace('_', '-', $match[1]));
/**
* Now call 'the_template' with $template as first element in $args
*/
$value = call_user_func_array(array($view, 'the_template'), $args);
if (preg_match('#^<\\{WPLib:(.+)\\}>#', $value, $match)) {
/**
* Check to see if their is a content type indicator
*/
switch ($match[1]) {
case 'JSON':
$suffix = '_json';
break;
case 'HTML':
default:
$suffix = '_html';
/*
* Indicate that this content need not be run through wp_kses_post()
* since it was loaded by a template which can be reviewed for security.
*/
$has_html_suffix = true;
break;
}
}
} else {
if (method_exists($view, $method_name) && is_callable($callable = array($view, $method_name))) {
/**
* Call the view method directly.
*/
$value = call_user_func_array($callable, $args);
} else {
if (preg_match('#^the_(.+?)(_attr|_url|_html|_link)?$#', $method_name, $match)) {
$method_name = $match[1];
$suffix = 3 === count($match) ? $match[2] : false;
$has_html_suffix = self::has_html_suffix($suffix);
if ($callable = self::get_callable($view, "get_{$method_name}{$suffix}")) {
/*
* Call the $view method: 'get_whatever_suffix()'
*/
$value = call_user_func_array($callable, $args);
} else {
if ($callable = self::get_callable($view, "{$method_name}{$suffix}")) {
/*
* Call the $view method: 'whatever_suffix()'
*/
$value = call_user_func_array($callable, $args);
} else {
if ($callable = self::get_callable($model, "get_{$method_name}{$suffix}")) {
$has_html_suffix = self::has_html_suffix($suffix);
/*
* Call the $model method: 'get_whatever_suffix()'
*/
$value = call_user_func_array($callable, $args);
} else {
if ($callable = self::get_callable($model, "get_{$method_name}")) {
$has_html_suffix = self::has_html_suffix($suffix);
/*
* Call the $model method: 'get_whatever()'
*/
$value = call_user_func_array($callable, $args);
} else {
if (!$has_html_suffix && ($callable = self::get_callable($model, "{$method_name}{$suffix}"))) {
/*
* Call the $model method: 'whatever_suffix()'
*/
$value = call_user_func_array($callable, $args);
} else {
if ($callable = self::get_callable($model, $method_name)) {
$has_html_suffix = false;
/*
* Call the $model method: "{$method_name}" (as passed)
*/
$value = call_user_func_array($callable, $args);
} else {
$has_html_suffix = false;
/*
* Not found, throw an error.
* $match[0] should have original $method_name
*/
$class_name = is_object($view) ? get_class($view) : $view;
$message = sprintf(__('Method %s not found for class %s.', 'wplib'), $match[0], $class_name);
self::trigger_error($message, E_USER_ERROR);
}
}
}
}
}
}
}
}
}
/**
* Auto-escape output
*/
switch ($suffix) {
case '_attr':
echo $value = esc_attr($value);
break;
case '_url':
echo $value = esc_url($value);
break;
case '_html':
case '_link':
echo $has_html_suffix ? $value : wp_kses_post($value);
break;
default:
echo $value = esc_html($value);
}
}