ACC SHELL
<?php
// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is 100% my work. Do not copy.
class Invocation
{
const STATUS_CHECK = -2;
const STATUS_PREPARE = -2;
const STATUS_ERROR = -1;
const STATUS_OK = 0;
const STATUS_SUCCESS = 1;
public $invoker = null;
public $action = null;
public $module = null;
public $active = false;
public $status = self::STATUS_OK;
public $options = array();
public $mappings = array();
public $messages = array();
public $output = array();
public $icon = null;
public $text = null;
public $textInUrl = null;
public $iconInUrl = null;
public $context = null;
public $panel = null;
public static function instantiate($action, $module = null, $text = null)
{
return new Invocation($action, $module, $text);
}
public static function current()
{
return $GLOBALS['invocation'];
}
public function __construct($action, $module = null, $text = null, $id = null, $invoker = null)
{
$a = Action::find($action, $module);
if ($a)
{
$this->action = $a->id;
$this->module = $a->module;
$this->context = $this->action()->context;
}
else
{
$this->action = $action;
$this->module = $module;
}
$this->text = $text;
$this->invoker = $invoker;
}
public function action()
{
return a($this->action, $this->module);
}
public function module()
{
if ($this->action())
return $this->action()->module();
else if ($this->module)
return m($this->module);
else
return null;
}
public function invoker()
{
return $this->invoker;
}
public function icon()
{
if ($this->icon)
{
foreach (array($this->icon, $this->module.'_'.$this->icon) as $icon)
if (U::fef(($temp = 'web/_administration/icons/' . $icon . '.png')))
return $icon;
return null;
}
else if ($this->action())
return $this->action()->icon();
else
return null;
}
public function log($message)
{
lll('modules', $this->module . '/' . $this->action, $message);
}
public function status($status, $result = null)
{
$this->status = $status;
return $result;
}
public function error($message = null, $result = null)
{
if ($message === null)
$message = __('unspecified-error', '@core');
if ($message)
$this->message($message, 'error');
$this->status = self::STATUS_ERROR;
return $result;
}
public function set($key, $value = null)
{
$this->options[$key] = $value;
}
public function get($key, $value = null)
{
if (isset($this->options[$key]))
return $this->options[$key];
else if ($this->action())
return $this->action()->get($key, $value);
else
return $value;
}
public function getS($key, $value = null)
{
return $this->action()->getS($key, $value);
}
public function setS($key, $value)
{
$this->action()->setS($key, $value);
}
public function getV($key, $value = null)
{
return $this->action()->getV($key, $value);
}
public function setV($key, $value)
{
$this->action()->setV($key, $value);
}
public function getUP($key, $value = null)
{
return $this->action()->getUP($key, $value);
}
public function setUP($key, $value)
{
$this->action()->setUP($key, $value);
}
public function message($text, $type = 'information')
{
$this->messages[] = array('type' => $type, 'text' => $text);
}
public function output($x, $block = 0)
{
if (is_object($x) && method_exists($x, 'output'))
$o = $x->output();
else if (is_object($x) && method_exists($x, 'toHtml'))
$o = $x->toHtml();
else if (is_object($x) && method_exists($x, 'toString'))
$o = $x->toString();
else
$o = (string) $x;
if (!isset($this->output[$block]))
$this->output[$block] = '';
$this->output[$block] .= $o;
}
public function dispatch($options = array(), $activate = false, $clone = false)
{
if ($clone)
{
$clone = clone($this);
return $clone->dispatch($options, $activate);
}
$result = null;
if ($activate)
$this->active = true;
$this->status = self::STATUS_OK;
if (!$this->active)
return $result;
if (!$this->prepare($options, false))
{
$this->status = self::STATUS_PREPARE;
if (isset($GLOBALS['invocation']) && ($GLOBALS['invocation'] === $this) && page()->administration)
$this->message(__('access-denied', '@core'), 'error');
$result = false;
}
else
$result = $this->call($options, false);
return $result;
}
public function prepare($options = array(), $clone = true)
{
if ($clone)
{
$clone = clone($this);
return $clone->prepare($options, false);
}
if ($options === null)
$options = array();
$this->options = array_merge($this->options, $options);
$action = $this->action();
$module = $this->module();
Locale::module($module->id);
$callback = $this->get('prepare');
if (($callback === true) || ($callback === false))
$result = $callback;
else if ($callback)
$result = callback($callback, array_merge(array('invocation' => $this)));
else
{
$result = null;
for ($phase = 0; $phase < 10; $phase++)
{
$temp = $module->prepare($this, $action, $phase, $result);
if ($temp !== null)
$result = $temp;
}
}
return $result;
}
public function call($options = array(), $clone = true)
{
if ($clone)
{
$clone = clone($this);
return $clone->call($options, false);
}
if ($options === null)
$options = array();
$this->options = array_merge($this->options, $options);
$action = $this->action();
$module = $this->module();
$method = $action->method;
Locale::module($module->id);
ob_start();
$this->output = array(0 => '');
Event::invoke(array("module.action.before", "{$module->id}.action.before", "module.{$action->id}.before", "{$module->id}.{$action->id}.before"),
array('invocation' => $this));
$this->log('call');
$result = $module->$method($this, $action);
Event::invoke(array("module.action.after", "{$module->id}.action.after", "module.{$action->id}.after", "{$module->id}.{$action->id}.after"),
array('invocation' => $this, 'result' => $result));
$this->output[0] .= ob_get_clean();
if (isset($GLOBALS['invocation']) && ($GLOBALS['invocation'] === $this))
{
foreach ($this->output as $k => $v)
view()->templates['invocation_'.$k] = new Template('invocation_'.$k, $v, 'string', 'html', Template::TYPE_INVOCATION);
$this->output = array();
$GLOBALS['result'] = $result;
}
return $result;
}
public function urlBase($options = array(), $flags = 0)
{
if ($options === null)
$options = array();
$action = $this->action();
$module = $this->module();
if (!($result = $this->get('request-uri-0')))
{
$this->options = array_merge($this->options, $options);
$mappings = array_merge($action->mappings, $this->mappings);
foreach ($mappings as $key => $expression)
if ($expression)
$this->options[$key] = $expression->evaluate(array_merge($this->options, array('invocation' => $this, 'action' => $action, 'module' => $module, '__url' => true)));
$this->options = array_merge($this->options, $options);
$result = '&page.invocation=' . $module->id . '/' . $action->id;
foreach ($this->options as $k => $v)
if (!is_array($v) && !is_object($v) && !is_null($v))
$result .= '&' . $k . '=' . urlencode($v);
}
for ($i = 1; $i < 10; $i++)
if ($temp = $this->get('request-uri-'.$i, ''))
$result .= $temp;
if ($this->invoker && $this->invoker())
$result .= $this->invoker()->url();
return $result;
}
public function urlAnchor($result, $text = null, $flags = 0)
{
$href = '';
$panel = (($this->panel === null) ? page()->panel : $this->panel);
if (($flags & 1))
{
$href = $_SERVER['SCRIPT_NAME'] . '?page.location=' . page()->location;
if (page()->viewstate)
$href .= '&page.viewstate=' . page()->viewstate;
}
$href .= $result;
if (($flags & 2) == 0)
return $href;
$action = $this->action();
$module = $this->module();
if ($text === null)
$text = ($this->text ? $this->text : __($action->id, $module->id));
if ($text === '')
$text = ' ';
if (substr($text, 0, 1) == chr(255))
{
$text = substr($text, 1);
$tttt = HTML::e(trim(strip_tags($text)));
}
else
$tttt = $text = HTML::e($text);
$class = 'link_module_'.$this->module . ' link_action_'.$this->action.' link_module_'.$this->module.'_action_'.$this->action;
$result = '<a href="' . HTML::e($href) . '" class="'.$class.'"';
if ($flags & 4)
{
if ($panel === false)
$result .= ' onclick="return application.load(this.href);"';
else if ($panel)
$result .= ' onclick="return application.loadPanel(this.href, \'' . $panel . '\');"';
}
$result .= 'title="' . $tttt . '">';
if ($icon = $this->icon())
$icon = '<img src="'.PATH.'web/_administration/icons/'.$icon.'.png" alt="' . $tttt . '" title="' . $tttt . '" />';
if (($this->iconInUrl === true) || ($icon && ($this->iconInUrl === null)))
$result .= '<span class="link_icon">' . $icon . '</span>';
if (($this->textInUrl === true) || (!$icon && ($this->textInUrl === null)))
$result .= '<span class="link_text">' . $text . '</span>';
$result .= '</a>';
return $result;
}
public function url($options = array(), $text = null, $flags = 0, $clone = true)
{
if ($clone)
{
$clone = clone($this);
return $clone->url($options, $text, $flags, false);
}
if (is_string($text))
$flags = $flags | 7;
$result = $this->urlBase($options, $flags);
$result = $this->urlAnchor($result, $text, $flags);
return $result;
}
public function form($id = null)
{
if ($id === null)
$id = $this->action()->id;
$form = new Form($this->module()->id . '/' . $id);
$form->invocation = $this;
if ($temp = $this->get('form-action'))
$form->action = $temp;
else
$form->action = $this->url(null, null, 1);
return $form;
}
public function forward($options = array())
{
$panel = (($this->panel === null) ? page()->panel : $this->panel);
$url = $this->url($options, null, 1);
if ($panel)
{
echo '<script type="text/javascript"><!--//--><![CDATA[//><!--' . "\n";
if ($panel === true)
echo "\t" . 'setTimeout("application.load(\'' . $url . '\')", 1000);' . "\n";
else
echo "\t" . 'setTimeout("application.loadPanel(\'' . $url . '\', \'' . $panel . '\')", 1000);' . "\n";
echo '//--><!]]></script>' . "\n";
}
else
U::redirect($url);
}
public function actionsTop($refs, $options = array(), $get = array())
{
if (!$options)
{
if ($this->context == 'object')
{
$options['object'] = $this->get('object');
$options['parent'] = $this->get('parent');
}
}
$panel = (($this->panel === null) ? page()->panel : $this->panel);
$class = 'actions_top ';
if ($panel)
$class .= ' actions_top_' . $panel;
$output = '';
$output .= '<div class="'.$class.'">';
foreach ($refs as $ref)
{
$temp0 = clone($ref);
$temp0->iconInUrl = true;
$temp0->textInUrl = true;
$output .= $temp0->url($options, null, 7, false);
}
$output .= '</div><!-- /actions_top -->';
$this->output($output);
}
}
class WebInvocation extends Invocation
{
public function urlBase($options = array(), $flags = 0)
{
if ($options === null)
$options = array();
$this->options = array_merge($this->options, $options);
foreach ($this->mappings as $key => $expression)
if ($expression)
$this->options[$key] = $expression->evaluate(array_merge($this->options, array('invocation' => $this, 'action' => $this->action(), 'module' => $this->module(), '__url' => true)));
$this->options = array_merge($this->options, $options);
$url = '{$routerUrl}{$urlOptions}';
if ($temp0 = $this->get('url-template'))
$url = $temp0;
$routerUrl = '[error]';
if (!($location = $this->get('url-location')))
$location = $this->module . (($this->module && $this->action) ? '/' : '') . $this->action;
$routerUrl = Router::urlGeneric($location, $this->options);
$url = str_replace('{$routerUrl}', $routerUrl, $url);
$urlOptions = (strpos($url, '?') ? '' : '?');
foreach ($this->options as $k => $v)
if (!is_array($v) && !is_object($v) && !is_null($v))
$urlOptions .= '&' . $k . '=' . urlencode($v);
$url = str_replace('{$urlOptions}', $urlOptions, $url);
if (strpos($url, '{$') !== false)
$url = Template::pseudoSmarty($url, $this->options);
return $url;
}
public function url($options = array(), $text = null, $flags = 0, $clone = true)
{
if ($flags & 1)
$flags = $flags - 1;
return parent::url($options, $text, $flags, $clone);
}
public function prepare($options = array(), $clone = true)
{
return true;
}
}
function i()
{
return Invocation::current();
}
?>
ACC SHELL 2018