private static function services($methods) { $result = array(); foreach ($methods as $methodName => $method) { if (!$method instanceof \Closure) { $params = array(); if (is_array($method)) { $template = array_shift($method); $params = $method; } else { $template = $method; } $result[$methodName] = ar_pinp::getCallback($template, $params); } else { $result[$methodName] = $method; } } return $result; }
<?php global $AR; require_once $AR->dir->install . "/lib/includes/diff/DiffEngine.php"; require_once $AR->dir->install . "/lib/includes/diff/ariadne.diff.inc"; ar_pinp::allow('ar_beta_diff'); class ar_beta_diff extends arBase { public static function diff($a, $b) { $a = is_array($a) ? $a : explode("\n", $a); $b = is_array($b) ? $b : explode("\n", $b); $diff = new Diff($a, $b); if ($diff) { $formatter = new AriadneDiffFormatter(); $result = $formatter->format($diff); $rows = ar_html::nodes(); foreach ($result as $line) { $cells = ar_html::nodes(); foreach ($line as $content) { if (is_array($content)) { $options = array(); if ($content['class']) { $options['class'] = $content['class']; } if ($content['colspan']) { $options['colspan'] = $content['colspan']; } $cell = ar_html::tag("td", $options, $content['data']); $cells[] = $cell; } else {
<?php //TODO: __toString method in listexpression, with a builtin counter. ar_pinp::allow('ar_listExpression', array('pattern', 'item', 'define', 'getStringIterator', 'setToStringCallback')); ar_pinp::allow('ar_listExpression_Pattern', array('define')); class ar_listExpression_Pattern extends arBase { public $patterns = array(); public $definitions = array('.' => false); public function __construct($patterns) { $this->patterns = $patterns; } public function define($name, $value = null) { if (is_array($name)) { $this->definitions = array_merge($this->definitions, $name); } else { $this->definitions[$name] = $value; } return $this; } } class ar_listExpression extends arBase implements Iterator, Countable, ArrayAccess { private $rootlist = null; private $current = 0; private $patterns = array(); private $nodeLists = array(); private $length = 0; private $toStringCallback = null;
<?php ar_pinp::allow('ar_content_html'); ar_pinp::allow('ar_content_htmlContent'); class ar_content_html extends arBase { public static $editMode = false; public static $editPrefix = 'editable_'; public static $editTemplate = 'user.edit.page.html'; public static $editTarget = '_top'; protected static $editCounter = 0; public static function configure($option, $value) { switch ($option) { case 'editMode': self::$editMode = $value; break; case 'editPrefix': self::$editPrefix = $value; break; case 'editTarget': self::$editTarget = $value; break; case 'editTemplate': self::$editTemplate = $value; break; } } public function __set($name, $value) { self::configure($name, $value);
<?php ar_pinp::allow('ar_cache_redisStore'); class ar_cache_redisStore implements ar_cacheStoreInterface, arKeyValueStoreInterface { private $timeout = 7200; private $redis = null; public function __construct($options, $timeout = 7200, $prefix = 'AR_') { if (is_string($timeout)) { $timeout = strtotime($timeout, 0); } $this->timeout = $timeout; $this->prefix = $prefix; $this->redis = $redis = new Redis(); if (isset($options['port'])) { $redis->pconnect($options['server'], $options['port']); } else { $redis->pconnect($options['server']); } if (isset($options['auth'])) { $redis->auth($options['auth']); } if (isset($options['db'])) { $redis->select($options['db']); } $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); $redis->setOption(Redis::OPT_PREFIX, $prefix); } // key public function get($path)
<?php ar_pinp::allow('ar_filter'); /* '/foo/' -> matches a message with root entry 'foo' '/foo/,/bar/' -> matches a message with both /foo/ and /bar/ '/foo:bar/' -> matches a message with root entry 'foo' with string value 'bar' '/foo/bar/' -> matches a message with root entry 'foo' with a child entry 'bar' '/foo/.../bar/' -> matches a message with root entry 'foo' with a descendant entry 'bar' '/foo:"bar"/' -> matches a message with root entry 'foo' whose value contains the string 'bar' '!/foo/' -> matches a message that has no root entry 'foo' '!/.../foo/' -> matches a message that has no entry 'foo' at any level '/foo:"[a-z][a-z0-9]*"/' -> matches a message that has a root entry foo with a value that matches the regular expression / [a-z][a-z0-9]* /i */ class ar_filter { public static function match($message, $filter) { if (!$filter) {
<?php ar_pinp::allow('ar_connect_twitter'); ar_pinp::allow('ar_connect_twitterClient'); class ar_connect_twitter extends arBase { public static function client($httpClient = null) { return new ar_connect_twitterClient($httpClient); } public static function parse($text, $parseTwitterLinks = true) { // FIXME: allow normal links and mailto links to be specified like the user and argument links // link URLs $text = " " . preg_replace("/(([[:alnum:]]+:\\/\\/)|www\\.)([^[:space:]]*)([[:alnum:]#?\\/&=])/i", "<a href=\"\\1\\3\\4\" target=\"_blank\">\\1\\3\\4</a>", $text); // link mailtos $text = preg_replace("/(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))/i", "<a href=\"mailto:\\1\">\\1</a>", $text); if ($parseTwitterLinks) { if (is_array($parseTwitterLinks)) { $userLink = $parseTwitterLinks['user']; $argumentLink = $parseTwitterLinks['argument']; } else { $userLink = true; $argumentLink = true; } if (is_bool($userLink) && $userLink) { $userLink = '<a href="http://twitter.com/{user}" target="_blank">@{user}</a>'; } if (is_bool($argumentLink) && $argumentLink) { $argumentLink = '<a href="http://twitter.com/search?q=%23{argument}" target="_blank">#{argument}</a>'; }
<?php ar_pinp::allow('ar_html'); ar_pinp::allow('ar_htmlNode'); ar_pinp::allow('ar_htmlElement'); ar_pinp::allow('ar_htmlNodes'); class ar_html extends ar_xml { public static $xhtml = false; public static $preserveWhiteSpace = false; private static $emptyTags = array('input' => 1, 'br' => 1, 'hr' => 1, 'img' => 1, 'link' => 1, 'meta' => 1, 'frame' => 1, 'base' => 1, 'basefont' => 1, 'isindex' => 1, 'area' => 1, 'param' => 1, 'col' => 1, 'embed' => 1); private static $noIndentInside = array('textarea' => 1); public static function configure($option, $value) { switch ($option) { case 'xhtml': self::$xhtml = (bool) $value; break; default: parent::configure($option, $value); break; } } public function __set($name, $value) { ar_html::configure($name, $value); } public function __get($name) { if (isset(ar_html::${$name})) { return ar_html::${$name};
public function __call($name, $arguments) { if ($name[0] === '_') { $realName = substr($name, 1); if (ar_pinp::isAllowed($this, $realName)) { return call_user_func_array(array($this, $realName), $arguments); } else { trigger_error("Method {$realName} not found in class " . get_class($this), E_USER_WARNING); } } else { trigger_error("Method {$name} not found in class " . get_class($this), E_USER_WARNING); } }
<?php ar_pinp::allow('ar_store_files', array('ls', 'get', 'save', 'delete', 'touch', 'exists')); /* * prevent mess detector from warning for the private static fields * @SuppressWarnings(PHPMD.UnusedPrivateField) */ class ar_store_files extends arBase { protected static function parseName($fname) { list($nls, $name) = explode('_', $fname, 2); return array('nls' => $nls, 'name' => $name); } protected static function compileName($name, $nls) { if (!$nls) { $ob = ar::context()->getObject(); $nls = $ob->nls; } return $nls . '_' . $name; } protected static function getStore() { $ob = ar::context()->getObject(); return array($ob, $ob->store->get_filestore("files")); } public static function ls($nls = null) { list($ob, $fstore) = static::getStore(); $files = $fstore->ls($ob->id);
<?php ar_pinp::allow('ar_http'); ar_pinp::allow('ar_httpClientStream'); /* * prevent mess detector from warning for the private static fields * @SuppressWarnings(PHPMD.UnusedPrivateField) */ class ar_http extends arBase { private static $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE; //needed to make __get() work public static $tainting = true; public function __get($var) { switch ($var) { case '_GET': return $this->getvar(null, 'GET'); break; case '_POST': return $this->getvar(null, 'POST'); break; case '_REQUEST': return $this->getvar(); break; case '_SERVER': return $this->getvar(null, 'SERVER'); break; case '_COOKIE': return $this->getvar(null, 'COOKIE'); break;
<?php ar_pinp::allow('ar_html_zen'); class ar_html_zen extends ar_htmlNodes { const T_EOF = 0; const T_IDENT = 1; const T_NUMBER = 2; const T_PLACEHOLDER = 3; const T_EXPRESSION_OPEN = 4; const T_EXPRESSION_CLOSE = 5; const T_OP_ATTRIBUTES_OPEN = 6; const T_OP_ATTRIBUTES_CLOSE = 7; const T_OP_FILTER = 8; const T_OP_MULTIPLIER = 9; const T_OP_ASSIGN = 11; const T_OP_ID = 12; const T_OP_CLASS = 13; const T_OP_CHILDREN = 14; const T_OP_SIBLINGS = 15; const T_OP_SETTING = 16; public function __construct($string) { $parser = new ar_html_zenParser($string); $nodes = $parser->run(); parent::__construct((array) $this->compileNodes($nodes)); } private function compileNodes($nodes, $childNodes = null) { if (!isset($childNodes)) { $childNodes = ar_html::nodes();
<?php ar_pinp::allow('ar_formats_markdown'); ar_pinp::allow('ar_formats_markdown_Parser', array('compile', 'configure')); class ar_formats_markdown extends arBase { static $options = array(); public static function compile($markdown) { $parser = self::parser(); return $parser->compile($markdown); } public static function parser() { $parser = new ar_formats_markdown_Parser(); $parser->configure(self::$options); return $parser; } } class ar_formats_markdown_Parser extends Parsedown { public function compile($markdown) { return $this->text($markdown); } public function _compile($markdown) { return $this->compile($markdown); } public function configure($option, $value = null) {
<?php ar_pinp::allow('ar_connect_ftp'); ar_pinp::allow('ar_connect_ftpClient'); class ar_connect_ftp extends arBase { public static $timeout = 90; public static $pasv = false; public static $transferMode = FTP_BINARY; public static function get($url, $options = array()) { $path = parse_url($url, PHP_URL_PATH); if ($path !== false) { $fileName = basename($path); $client = new ar_connect_ftpClient($url, $options); if (!ar_error::isError($client)) { return $client->get($fileName); } else { return $client; } } else { return ar::error("Could not parse url " . (string) $url, 11); } } public static function put($url, $contents, $options = array()) { $path = parse_url($url, PHP_URL_PATH); if ($path !== false) { $fileName = basename($path); $client = new ar_connect_ftpClient($url, $options); if (!ar_error::isError($client)) {
<?php ar_pinp::allow('ar_cache_memcachedStore'); class ar_cache_memcachedStore implements ar_cacheStoreInterface, arKeyValueStoreInterface { private $timeout = 7200; private $mc = null; public function __construct($servers, $timeout = 7200, $prefix = 'AR_') { if (is_string($timeout)) { $timeout = strtotime($timeout, 0); } $this->timeout = $timeout; $this->mc = $mc = new memCached(); $mc->addServers($servers); } // key public function get($path) { $res = $this->mc->get($path); $code = $this->mc->getResultCode(); if ($code !== MEMCACHED_SUCCESS) { return $res; } return null; } public function getIfFresh($path, $timeout = 0) { // we do not know if it is fresh return $this->get($path); }
public function __call($name, $arguments) { if ($name[0] === '_') { $realName = substr($name, 1); if (ar_pinp::isAllowed($this, $realName)) { return call_user_func_array(array($this, $realName), $arguments); } else { $trace = debug_backtrace(0, 2); trigger_error("Method {$realName} not found in class " . get_class($this) . " Called from line " . $trace[1]['line'] . " in " . $trace[1]['file'], E_USER_WARNING); } } else { $trace = debug_backtrace(0, 2); trigger_error("Method {$name} not found in class " . get_class($this) . " Called from line " . $trace[1]['line'] . " in " . $trace[1]['file'], E_USER_WARNING); } }
ar('cache')->set( $naam, $image, '2 hours' ); } else if ( ar('cache')->wait( $naam ) ) { // lock failed, another process is generating the cache // continues here when the lock to be lifted $image = ar('cache')->get($naam); } else { // couldn't lock the file in a reasonable time, you could generate an error here // or just go with a stale image, or simply do the calculation: $image = expensiveOperation(); } } echo $image; */ ar_pinp::allow('ar_cache'); ar_pinp::allow('ar_cacheStore'); ar_pinp::allow('ar_cacheProxy'); class ar_cache extends arBase { public static $cacheStore = null; public static function config($options) { if ($options['cacheStore']) { self::$cacheStore = $options['cacheStore']; } } public static function create($prefix = null, $timeout = 7200) { // this method is used by pinp scripts to create a specific cache // so it must be more restrictive than the constructor of the cacheStore // which must be able to clear any and all caches if (!$prefix) {
<?php ar_pinp::allow('ar_crypt'); class ar_crypt extends arBase { private $key; private $encoding; private $iv; private $api; private $mode = MCRYPT_MODE_CBC; public function __construct($key = null, $encoding = MCRYPT_RIJNDAEL_256, $api = 0) { global $AR; $this->encoding = $encoding; $this->api = $api; $this->key = $key; if ($this->api === 0) { // this api will be deprecated in the future // we also try to be backwards compatible with pre php 5.6 if ($key == null) { $key = $AR->sgSalt; } $keysizes = mcrypt_module_get_supported_key_sizes($this->encoding, $this->mode); sort($keysizes); $keysize = end($keysizes); foreach ($keysizes as $keysize) { if ($keysize >= strlen($key)) { break; } } $this->key = str_pad(substr($key, 0, $keysize), $keysize, "");
<?php ar_pinp::allow('ar_nls'); ar_pinp::allow('ar_nlsDictionary', array("load", "setLanguage", "getLanguage")); class ar_nls extends arBase { public static function dict($defaultLanguage, $currentLanguage = null, $defaultVarName = "ARnls", $baseDir = null) { if (!$baseDir) { global $store; // FIXME: remove dependency on $store, use arbasedir in some way. $baseDir = $store->get_config("code") . "nls/"; } return new ar_nlsDictionary($baseDir, $defaultLanguage, $currentLanguage, $defaultVarName); } } class ar_nlsDictionary extends arBase implements ArrayAccess, Iterator { private $currentList = null; private $defaultList = null; private $baseDir = null; private $languages = array(); private $loaded = array(); public $currentLanguage = null; public $defaultLanguage = null; public function __construct($baseDir, $defaultLanguage, $currentLanguage = null, $defaultVarName = "ARnls") { $this->baseDir = $baseDir; $this->defaultVarName = $defaultVarName; if (!isset($currentLanguage)) { $currentLanguage = $defaultLanguage;
<?php ar_pinp::allow('ar_store'); ar_pinp::allow('ar_storeFind'); ar_pinp::allow('ar_storeGet'); ar_pinp::allow('ar_storeParents'); class ar_store extends arBase { public static $rememberShortcuts = true; public static $searchObject = false; public static function configure($option, $value) { switch ($option) { case 'rememberShortcuts': self::$rememberShortcuts = $value; break; case 'searchObject': self::$searchObject = $value; break; } } public function __set($name, $value) { ar_store::configure($name, $value); } public function __get($name) { if (isset(ar_store::${$name})) { return ar_store::${$name}; } }
<?php ar_pinp::allow('ar_content_files'); ar_pinp::allow('ar_content_filesFile'); class ar_content_files extends arBase { } interface ar_content_filesFileInterface { public function read($length); public function readfile(); public function write($string, $length = null); public function eof(); public function size(); public function getc(); public function gets($length = null); public function getContents($offset = -1, $maxLen = null); public function seek($offset, $whence = SEEK_SET); public function tell(); public function truncate($size); public function rewind(); } class ar_content_filesFile extends arBase implements ar_content_filesFileInterface { private $resource = null; public function __construct($resource) { $this->resource = $resource; } public function __destruct() {
protected function bindValue($source, $type) { if ($source instanceof ar_xmlNode || $source instanceof ar_xmlNodes) { $nodeValue = $source->nodeValue; if (is_array($nodeValue) && !count($nodeValue)) { $nodeValue = null; } } else { $nodeValue = $source; } if (is_callable($type)) { $nodeValue = call_user_func($type, $source); } else { switch ($type) { case 'int': $nodeValue = (int) $nodeValue; break; case 'float': $nodeValue = (double) $nodeValue; break; case 'string': $nodeValue = (string) $nodeValue; break; case 'bool': $nodeValue = (bool) $nodeValue; break; case 'url': $nodeValue = ar::url($nodeValue); break; case 'xml': case 'html': if ($source instanceof ar_xmlNode || $source instanceof ar_xmlNodes) { $nodeValue = (string) $source; } break; default: if (is_string($type) && class_exists($type) && ar_pinp::isAllowed($type, '__construct')) { $nodeValue = new $type($nodeValue); } break; } } return $nodeValue; }
<?php ar_pinp::allow('ar_connect_rss'); ar::load('xml'); class ar_connect_rss extends arBase { public static function client($url = null, $httpClient = null) { if (!isset($httpClient)) { $httpClient = ar_http::client(); } return new ar_connect_rssClient($url, $httpClient); } public static function parse($xml) { $client = new ar_connect_rssClient(); return $client->parse($xml); } } class ar_connect_rssClient extends ar_xmlDataBinding { private $httpClient = null; private $feed = null; public function __construct($feed = null, $httpClient = null) { $this->feed = $feed; $this->httpClient = $httpClient; if ($feed && $this->httpClient) { $this->get($feed); } }
<?php ar_pinp::allow('ar_http_files'); ar_pinp::allow('ar_http_filesRegistry'); class ar_http_files extends arBase { protected static $store = null; protected static function getStore($store = null) { if (!$store) { $store = self::$store; } if (!$store) { self::$store = ar('loader/session')->get(); if (!self::$store) { self::$store = ar('loader/session')->start(); } $store = self::$store; } return $store; } public static function ls() { return $_FILES; } public static function getFile($filename) { // return opened file if exists, null otherwise $filename = (string) $filename; $file = null; $info = $_FILES[$filename];
<?php /* TODO: - styling: - dropdown: fix hover bg color (is now set on entire submenu instead of single item) add hover fg color add normal fg color */ ar_pinp::allow('ar_html_menu'); class ar_html_menu extends arBase { public static function bar($options = array()) { $options += array('filter' => 'object.implements="pdir"'); $parent = $options['top']; if (!$parent) { $parent = ar::context()->getPath(); } $query = "object.priority>=0 and object.parent = '{$parent}'"; if ($options['filter']) { $query .= ' and ( ' . $options['filter'] . ' )'; } return ar::get($parent)->find($query); } public static function tree($options = array()) { $current = $options['current']; if (!$current) { $current = ar::context()->getPath(); }
<?php ar_pinp::allow('ar_connect_db'); ar_pinp::allow('ar_connect_dbClient'); class ar_connect_db extends arBase { public static function connect($dsn, $username = '', $password = '', $driver_options = array()) { // deprecated return self::client($dsn, $username, $password, $driver_options); } public static function client($dsn, $username = '', $password = '', $driverOptions = array()) { try { return new ar_connect_dbClient(new PDO($dsn, $username, $password, $driverOptions)); } catch (Exception $e) { return ar::error($e->getMessage(), $e->getCode()); } } } // FIXME: define an interface class ar_connect_dbClient extends arWrapper implements Iterator { public function __construct($wrapped) { parent::__construct($wrapped); $this->__class = 'ar_connect_dbClient'; if ($this->wrapped instanceof PDOStatement) { $this->row = $this->wrapped->fetch(); if (!$this->row) { $this->row = null;
public static function registerValidateCheck($name, $check, $message) { if (!is_string($check) || $check[0] != '/' && !is_callable($check)) { $check = ar_pinp::getCallback($check, array('value')); } self::$checks[$name] = array('check' => $check, 'message' => $message); }
<?php ar_pinp::allow('ar_html_table'); class ar_html_table extends ar_htmlElement { private $rowHeaderAttributes = null; private $rowHeaders = null; public function __construct($data = null, $attributes = null, $childNodes = null, $parentNode = null) { parent::__construct('table', $attributes, $childNodes, $parentNode); if (isset($data)) { $this->body($data); } } public function body($data) { if (!is_array($data)) { $data = array($data); } $rows = $this->getRows($data)->setAttribute('class', array('tableFirstLast' => ar::listPattern('tableFirst .*', '.* tableLast'), 'tableOddEven' => ar::listPattern('(tableOdd tableEven?)*'))); $this->appendChild(ar_html::tag('tbody', $rows)); return $this; } private function getRows($list) { $nodes = ar_html::nodes(); foreach ($list as $key => $content) { if (!is_array($content)) { $content = array($content); } $cells = $this->getCells($content, 'td')->setAttribute('class', array('tableOddEven' => ar::listPattern('(tableOdd tableEven?)*'), 'tableFirstLast' => ar::listPattern('tableFirst .*', '.* tableLast')));
<?php ar_pinp::allow('ar_html_edit'); class ar_html_edit extends arBase { protected static $enabled = false; public static function enabled() { return self::$enabled; } public static function enable() { self::$enabled = true; } public static function disable() { self::$enabled = false; } public static function el() { $args = func_get_args(); $el = call_user_func_array('ar_html::el', $args); if (self::$enabled) { switch ($el->tagName) { case 'input': case 'select': $html = false; break; default: $html = isset($el->attributes['data-ar-html']) ? $el->attributes['data-ar-html'] : true; break;
<?php ar_pinp::allow('ar_loader_session'); ar_pinp::allow('ar_loader_sessionStore'); class ar_loader_session extends arBase { public static function start() { global $ARCurrent; ldStartSession(0); return new ar_loader_sessionStore($ARCurrent->session); } public static function get() { global $ARCurrent; if ($ARCurrent->session && $ARCurrent->session->id) { return new ar_loader_sessionStore($ARCurrent->session); } else { return null; } } public static function kill() { global $ARCurrent; if ($ARCurrent->session) { $ARCurrent->session->kill(); unset($ARCurrent->session); } } } class ar_loader_sessionStore extends arBase implements arKeyValueStoreInterface