/** * @return string */ protected function unparse_array($src, $prefix) { if (Core_Types::is_iterable($src)) { $out = ''; foreach ($src as $key => $value) { if (Core_Types::is_iterable($value)) { $value = $this->unparse_array($value, "\t{$prefix}"); $out .= "{$prefix}{$key} = {\n{$value}{$prefix}}\n"; } else { $value = (string) $value; $out .= "{$prefix}{$key} = {$value}\n"; } } return $out; } else { return (string) $src; } }
protected function get_items_keys($name, $parms) { $keys = isset($parms['__items_keys']) ? $parms['__items_keys'] : array(); if (!empty($keys)) { return $keys; } $items = isset($parms['__items']) ? $parms['__items'] : CMS::items_for_select($parms['items']); foreach ($items as $key => $data) { if (!$data instanceof DB_ORM_Entity && Core_Types::is_iterable($data)) { foreach ($data as $key => $value) { $keys[] = $this->checkbox_name($name, $key); } } else { $keys[] = $this->checkbox_name($name, $key); } } return $keys; }
static function transform($src, $config = false) { if (Core_Types::is_iterable($config)) { foreach ($config as $key => $value) { self::${$key} = $value; } } $out = ''; $src = strip_tags($src); $src = str_replace("[quote]", "\n[quote]\n", $src); $src = str_replace("[/quote]", "\n[/quote]\n", $src); $lines = explode("\n", $src); foreach ($lines as $line) { $line = trim($line); if ($line != '') { $out .= self::$lclass->line($line); } } return self::process_codes($out); }
/** * @param Net_HTTP_Response $response */ public function process_response(Net_HTTP_Response $response, $quiet = false) { ob_start(); $body = $response->body; if (Core_Types::is_iterable($body)) { foreach ($body as $line) { print $line; } } else { print $body instanceof Core_StringifyInterface ? $body->as_string() : (string) $body; } $response->body = ob_get_contents(); ob_end_clean(); if (!$quiet) { Events::call('ws.response', $response); } if ((int) $response->status->code != 200) { header('HTTP/1.0 ' . $response->status); } foreach ($response->headers->as_array(true) as $v) { header($v); } print $response->body; }
public function key() { if ($mapper = $this->get_mapper()) { $key = $mapper->options['key']; if (Core_Types::is_iterable($key)) { return current($key); } } return 'id'; }
public function get($var, $values = false) { Core::load('Mail'); if (!Core_Types::is_iterable($values)) { $values = array(); } $mailtext = $var->value; if (Core_Types::is_iterable($values)) { foreach ($values as $key => $val) { $mailtext = str_replace("%{{$key}}", $val, $mailtext); } } $body = CMS::render_mail('empty', array('content' => $mailtext)); $this->multipart = false; $this->attaches = array(); $body = preg_replace_callback('{(src)="(/[^"]+)"}', array($this, 'attaches_cb'), $body); $parms = unserialize($var->parms); $mail = Mail::Message()->subject($parms['subject'])->from($parms['from'])->to($parms['to']); if (!$this->multipart) { $mail->html($body); } else { if ($this->multipart == 'mixed') { $mail->multipart_mixed(); } if ($this->multipart == 'related') { $mail->multipart_related(); } $mail->html_part($body); foreach ($this->attaches as $id => $part) { $mail->part($part); } } return $mail; }
public function form_field($form, $name, $parms) { $items = CMS::items_for_select($parms['items']); foreach ($items as $key => $data) { if (Core_Types::is_iterable($data)) { foreach ($data as $key => $value) { $form->checkbox($name . $key); } } else { $form->checkbox($name . $key); } } }
public static function encode_value($value) { $enc = ''; if (is_null($value)) { return 'e:1'; } else { if (is_numeric($value)) { $enc = 'n:' . $value; } else { if (is_bool($value)) { $enc = 'b:' . ($value ? '1' : '0'); } else { if ($value instanceof Time_DateTime) { $enc = 'd:' . $value->format('%D, %d %M %Y %H:%M:%S %e'); } else { if (Core_Types::is_iterable($value)) { $is_array = true; foreach (array_keys($value) as $key) { $is_array = is_numeric($key) && $is_array; } if ($is_array) { $flat = array(); foreach ($value as $i => $v) { $flat[] = self::encode_value($v); } $enc = 'a:' . implode('^', $flat); } else { $flat = array(); foreach ($value as $k => $v) { $flat[] = $k . '=' . self::encode_value($v); } $enc = 'o:' . implode('^', $flat); } } else { $enc = 's:' . $value; } } } } } return rawurlencode($enc); }
public function add($title, $item) { if (!Core_Types::is_iterable($item)) { $item = array('uri' => $item, 'url' => $item); } if (isset($item['title'])) { $title = $item['title']; } $title = CMS::lang($title); //Events::dispatch('cms.navigation.add', $ev = Events::Event(array('title' => $title, 'data' => $item, 'url' => $item['url']))); //$title = $ev['title']; //$item = $ev['data']; //$item['url'] = $ev['url']; $url = $item['url']; Events::call('cms.navigation.add', $title, $item, $url); $item['url'] = $url; $access = isset($item['access']) ? trim($item['access']) : ''; if ($access != '' && !CMS::check_globals_or($access)) { return $this; } if (isset($item['disabled'])) { if (CMS::check_yes($item['disabled'])) { return $this; } } $uri = ''; if (isset($item['uri'])) { $uri = $item['uri']; } if (isset($item['url'])) { $uri = $item['url']; } $id = isset($item['id']) ? $item['id'] : md5($title . $uri); if (isset($item['navigation_id'])) { $id = trim($item['navigation_id']); } $selected = false; $disabled = false; if (isset($item['match'])) { if (preg_match($item['match'], CMS_Navigation3::$uri)) { $selected = true; } } if (isset($item['flag'])) { if (CMS::$navigation->is_flag($item['flag'])) { $selected = true; } } if ($uri == CMS_Navigation3::$uri) { $selected = true; } $item['selected'] = $selected; $item['disabled'] = $disabled; $sub = isset($item['sub']) ? $item['sub'] : null; if (is_string($sub)) { $sub = trim($sub); $_component = $sub; $_parms = $uri; if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $sub)) { $_component = trim($m[1]); $_parms = trim($m[2]); } if (CMS::component_exists($_component)) { $_class = CMS::$component_names[$_component]; $_classref = Core_Types::reflection_for($_class); $sub = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms, $item)) : false; } } if (Core_Types::is_iterable($sub)) { $set = new CMS_Navigation3_LinkSet(); $set->level_num = $this->level_num + 1; $set->process($sub); $this->link($id, $uri, $title, $item, $set); } else { $this->link($id, $uri, $title, $item); } return $this; }
static function file($id) { if (!isset(CMS::env()->files)) { return false; } if (!Core_Types::is_iterable(CMS::env()->files)) { return false; } if (isset(CMS::env()->files[$id])) { return CMS::env()->files[$id]; } foreach (CMS::env()->files as $file) { if ($file['alias'] == $id) { return $file; } } return false; }
/** * @return Dev_Unit_TestLoader */ public function from() { $args = func_get_args(); foreach (Core_Types::is_iterable($args[0]) ? $args[0] : $args as $class) { $class = "{$this->prefix}{$class}"; if (Core_Types::class_exists($class)) { $this->from_class($class); } else { try { Core::load($class); } catch (Core_ModuleException $e) { var_dump($e); Core::load(Core_Regexps::replace('{\\.[a-zA-Z0-9]+$}', '', $class)); $this->from_class($class); continue; } if (Core_Types::is_subclass_of('Dev.Unit.TestCase', $class)) { $this->from_class($class); } elseif (Core_Types::is_subclass_of('Dev.Unit.TestModuleInterface', $class)) { $this->from_suite(call_user_func(array(Core_Types::real_class_name_for($class), 'suite'))); } } } return $this; }
static function items_for_select_generate($s) { if (Core_Types::is_callable($s)) { $s = Core::invoke($s); } if (is_string($s)) { if ($m = Core_Regexps::match_with_results('/^:(.+)$/', $s)) { $method = trim($m[1]); $s = CMS::$current_controller->{$method}(); } } if (Core_Types::is_iterable($s)) { $items = array(); foreach ($s as $k => $v) { if ($v == '' && (is_string($k) && Core_Regexps::match('/^(var|db|orm)/', $k))) { $items += self::items_for_select($k); } elseif ($v instanceof DB_ORM_Mapper) { $items += self::items_for_select($v->select()); } else { if ($v instanceof DB_ORM_Entity) { $items[$v->id()] = $v; } else { if (is_int($k) && (Core_Types::is_callable($v) || is_string($v) && Core_Regexps::match('/^(var|db|orm)/', $v))) { $items += self::items_for_select($v); } else { $items[$k] = $v; } } } } return $items; } else { if ($m = Core_Regexps::match_with_results('/^var:(.+)$/', $s)) { return self::get_var_value($m[1]); } else { if ($m = Core_Regexps::match_with_results('/^orm:(.+)$/', $s)) { $items = array(); foreach (self::orm()->downto($m[1]) as $row) { $items[$row->id] = $row; } return $items; } else { if ($m = Core_Regexps::match_with_results('/^(.+)::(.+)$/', $s)) { $class = str_replace('.', '_', trim($m[1])); $method = trim($m[2]); $ref = new ReflectionMethod($class, $method); return $ref->invoke(null); } else { if ($m = Core_Regexps::match_with_results('/^db:([a-z0-9_]+)(.*)$/i', $s)) { $table = $m[1]; $s = $m[2]; $value = 'id'; $title = 'title'; $query = 'select'; if ($m = Core_Regexps::match_with_results('/^->([a-z0-9_]+)(.*)$/', $s)) { $query = $m[1]; $s = $m[2]; } if ($m = Core_Regexps::match_with_results('/^\\((.+),(.+)\\)$/', $s)) { $value = $m[1]; $title = $m[2]; } $rows = DB_SQL::db()->{$table}->{$query}->run(); $items = array(); foreach ($rows as $row) { $items[$row->{$value}] = $row->{$title}; } return $items; } else { return array(); } } } } } }
/** * @param WebKit_HTTP_Request $request * * @return WebKit_Controller_Route */ public function route($request) { $this->request = $request; $uri = $this->clean_url($request->urn); $controllers = $this->controllers(); if (Core_Types::is_iterable($controllers)) { foreach ($controllers as $name => $info) { if (isset($info['module'])) { $name = $info['module']; } $path = trim($this->admin_path_replace($info['path'])); if ($path != '' && $path[0] == '{') { $regexp = $path; } else { $regexp = '{^(' . $path . ')(.*)$}'; } $matched = false; if ($m = Core_Regexps::match_with_results($regexp, $uri)) { $this->path_prefix = $m[1]; $path = $m[2]; $matched = true; } if (isset($info['host'])) { $host = strtolower(trim($info['host'])); if ($host != '') { if ($host[0] == '{') { if (!Core_Regexps::match($host, strtolower($request->host))) { $matched = false; } } else { if (strtolower($request->host) != $host) { $matched = false; } } } } if (isset($info['site']) && $info['site'] != CMS::site()) { $matched = false; } if ($matched) { $this->active_controller = $name; if (isset($info['table-admin']) && $info['table-admin']) { $rules = array_merge(!empty($info['rules']) ? $info['rules'] : array(), array('{^$}' => array('default', 1, 'func' => 'default', 'parms' => 1), '{^list\\.json$}' => array('list_json', 'func' => 'list_json', 'parms' => 1), '{^([^/]+)/(.*)}' => array('{1}', '{2}', 'func' => '{1}', 'parms' => '{2}'))); } else { $rules = $info['rules']; } if (is_array($rules)) { foreach ($rules as $rule => $parms) { $match = false; if (trim($rule) != '') { $match = $mr = Core_Regexps::match_with_results(trim($rule), $path); } if ($rule == '' && $path == '' || $match) { foreach ($parms as $key => $value) { if ($mm = Core_Regexps::match_with_results('/^\\{(\\d+)\\}$/', $value)) { $parms[$key] = isset($mr[$mm[1]]) ? $mr[$mm[1]] : null; } } $parms['controller'] = $name; return $parms; } } } else { return array('controller' => $name, 'path' => $path); } } } } return false; }
protected static function auth_parms($mp, $client) { $auth_parms = array(); if ($mp) { if (is_string($mp)) { $mp = explode(',', $mp); } if (Core_Types::is_iterable($mp)) { foreach ($mp as $_mp) { $_mp = trim($_mp); if ($_mp != '') { $_v = true; if ($m = Core_Regexps::match_with_results('{^([^=]+)=(.+)$}', $_mp)) { $_mp = trim($m[1]); $_v = trim($m[2]); } if ($_mp == 'lang') { CMS::site_set_lang($_v); } if ($_mp == 'admin_sites') { $_asites = explode('|', $_v); $_v = array(); $_las = '__'; foreach ($_asites as $_asite) { $_asite = trim($_asite); if ($_asite != '') { $_v[$_asite] = $_asite; $_las = $_asite; } } if (CMS::admin()) { if (!isset($_v[CMS_Admin::site()])) { header("location: /cms-actions/subsite/{$_las}"); die; } } } CMS::$globals[$_mp] = $_v; $auth_parms[$_mp] = $_v; } } } if ($client) { CMS::$globals['full'] = false; } } return $auth_parms; }
protected function get_form_tabs($action, $item = false) { $tabs = $this->form_tabs($action, $item); $out = array(); if (!Core_Types::is_iterable($tabs)) { return $out; } $weight = 0; $delta = 0.0001; foreach ($tabs as $tab => $data) { if (!$this->access_tab($tab, $data, $action, $item)) { continue; } if (is_string($data)) { $data = array('caption' => $data); } $valid = true; if (isset($data['edit_only']) && $data['edit_only'] && $action != 'edit') { $valid = false; } if (isset($data['add_only']) && $data['add_only'] && $action != 'add') { $valid = false; } if (!isset($data['weight'])) { $weight += $delta; $data['weight'] = $weight; } if ($valid) { $out[$tab] = $data; } } uasort($out, array($this, 'sort_by_weight')); return $out; }