/** * Set fields for table * * @param mixed $fields * @return Core_ArrayObject */ public function setFields($fields) { if (is_array($fields)) { $fields = Core_ArrayObject::transform($fields); } return $this->fields = $fields; }
/** * Render */ public function render() { $Онлайн = new Db_ORM('Онлайн'); $Онлайн->where('created_date', time() - config('widgets.Онлайн.period', 60), ' < '); $Онлайн->delete(); $data = Core_ArrayObject::transform(array('counters' => array('users' => 0, 'Боты' => 0, 'Гости' => 0, 'all' => 0), 'users' => array(), 'Боты' => array(), 'guest' => array())); if ($result = $Онлайн->findAll()) { foreach ($result as $item) { if ($item->uid) { if (!$data->users->offsetExists($item->uid)) { $data->users->offsetSet($item->uid, user($item->uid)); $data->counters->users++; } } else { if (preg_match('#(yandex|google|rss|bot|rambler|pubsub|parser|spider|feed)#ism', $item->user_agent, $bot)) { if ($data->Боты->offsetExists($bot[0])) { continue; } $data->Боты->offsetSet($bot[0]); $data->counters->Боты++; } else { $data->counters->Гости++; } } } $data->counters->all = $data->counters->users + $data->counters->Боты + $data->counters->Гости; } $tpl = new Template('User/templates/widgets/Онлайн'); $tpl->data = $data; $this->code = $tpl->render(); return parent::render(); }
/** * Загрузка скриптов */ public function load() { $this->toolbar = Core_ArrayObject::transform($this->toolbar); $folder = cogear()->redactor->folder . DS . 'redactor' . DS; $options = new Core_ArrayObject(); event('redactor.options', $options); $options->lang = config('i18n.lang', 'ru'); $options->shortcuts = TRUE; $options->minHeight = 300; $options->buttons = array('formatting', 'alignment', '|', 'bold', 'italic', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'table', 'link', 'image', '|', 'fontcolor', 'backcolor', '|', 'horizontalrule', '|', 'html'); // $options->imageUpload = l('/redactor/upload/'); $options->fixed = TRUE; $options->observeImages = TRUE; $options->convertLinks = TRUE; $options->cleanup = FALSE; $options->focus = TRUE; $options->convertDivs = FALSE; role() == 1 && ($options->fixedTop = 40); js($folder . $options->lang . '.js', 'after'); // $this->toolbar->markupSet->uasort('Core_ArrayObject::sortByOrder'); // $(document).ready(function(){ css($folder . 'redactor.css'); js($folder . 'redactor.min.js', 'after'); inline_js("\$('[name={$this->name}]').redactor(" . $options->toJSON() . ")", 'after'); }
/** * Set current object * * @param array|ArrayObject $data */ public function object($data = NULL) { if ($data) { $this->object = is_object($data) ? $data : Core_ArrayObject::transform($data); } else { return $this->object; } }
/** * Load scripts */ public function load() { $folder = cogear()->markitup->folder . '/'; css($folder . 'skins/simple/style.css'); css($folder . 'sets/default/style.css'); js($folder . 'js/jquery.markitup.js', 'after'); $toolbar = Core_ArrayObject::transform($toolbar = array('nameSpace' => 'html', 'onCtrlEnter' => array('keepDefault' => FALSE, 'openWith' => "\n<p>", 'closeWith' => "</p>\n"), 'onTab' => array('keepDefault' => false, 'openWith' => ' '), 'markupSet' => array(array('name' => t('Bold'), 'key' => 'B', 'openWith' => '<b>', 'closeWith' => '</b>', 'className' => 'markItUpBold'), array('name' => t('Italic'), 'key' => 'I', 'openWith' => '<i>', 'closeWith' => '</i>', 'className' => 'markItUpItalic'), array('name' => t('Underlined'), 'key' => 'U', 'openWith' => '<u>', 'closeWith' => '</u>', 'className' => 'markItUpUndeline'), array('name' => t('Strike through'), 'key' => 'S', 'openWith' => '<s>', 'closeWith' => '</s>', 'className' => 'markItUpStrike'), array('name' => t('Heading 1'), 'key' => '1', 'openWith' => '<h1>', 'closeWith' => '</h1>', 'className' => 'markItUpH1'), array('name' => t('Heading 2'), 'key' => '2', 'openWith' => '<h2>', 'closeWith' => '</h2>', 'className' => 'markItUpH2'), array('name' => t('Heading 3'), 'key' => '3', 'openWith' => '<h3>', 'closeWith' => '</h3>', 'className' => 'markItUpH3'), array('name' => t('UL'), 'multiline' => true, 'openBlockWith' => "<ul>\n", 'closeBlockWith' => "\n</ul>\n", 'openWith' => " <li>", 'closeWith' => "</li>", 'className' => 'markItUpUl'), array('name' => t('OL'), 'multiline' => true, 'openBlockWith' => "<ol>\n", 'closeBlockWith' => "\n</ol>\n", 'openWith' => " <li>", 'closeWith' => "</li>", 'className' => 'markItUpOl'), array('name' => t('Picture'), 'key' => 'P', 'replaceWith' => '<img src="[![Source:!:http://]!]" alt="" />', 'className' => 'markItUpPicture'), array('name' => t('Link'), 'key' => 'L', 'openWith' => '<a href="[![Link:!:http://]!]">', 'closeWith' => '</a>', 'className' => 'markItUpLink'), array('name' => t('User'), 'key' => 'U', 'openWith' => '[user=[![User]!]]', 'className' => 'markItUpUser'), array('name' => t('Code'), 'key' => 'O', 'openWith' => '<pre class="prettyprint linenums"><code>', 'closeWith' => '</code></pre>', 'className' => 'markItUpCode')))); event('markitup.toolbar', $toolbar); inline_js("\$('[name={$this->name}]').markItUp(" . $toolbar->toJSON() . ")", 'after'); }
/** * Read config from file * * @param string $file */ public static function read($file, $mode = NULL) { $mode or $mode = self::AS_OBJECT; if (!file_exists($file)) { return NULL; } elseif ($mode === self::AS_OBJECT) { return Core_ArrayObject::transform(include $file); } elseif ($mode === self::AS_ARRAY) { return include $file; } }
/** * Конструктор */ public function __construct($config) { parent::__construct($config); $this->info = Core_ArrayObject::transform($this->info); $this->info->title->append(config('site.name', SITE_URL)); }
/** * Result * * @return NULL|Core_ArrayObject — filtered and validated data */ public function result() { // Define if form is requested via ajaxed $this->ajaxed = $this->options->ajax && Ajax::is() && cogear()->input->post('ajaxed') === $this->getId(); $method = strtolower($this->options->method); $result = array(); $is_valid = TRUE; if (cogear()->input->{$method}() or $_FILES) { foreach ($this->elements as $name => $element) { $value = $element->result(); if ($value !== NULL) { $result[$name] = $value; } if ($value === FALSE) { $is_valid = FALSE; } } } if ($this->ajaxed) { $data = array(); $data['success'] = $is_valid && $result; if ($data['success']) { $data['result'] = $result; } else { foreach ($this->elements as $key => $element) { $element->errors->count() > 0 && ($data['errors'][$key] = $element->errors); } $ajax = new Ajax(); $ajax->json($data); } } if ($is_valid && $result) { $result = Core_ArrayObject::transform($result); } if (!event('form.result.' . $this->options->name, $this, $is_valid, $result)->check() or !event('form.result', $this, $is_valid, $result)->check()) { return FALSE; } return $is_valid ? $result : FALSE; }
/** * Row * * @return Core_ArrayObject|NULL */ public function row() { return $this->result ? Core_ArrayObject::transform(mysqli_fetch_assoc($this->result)) : NULL; }
/** * Magic __set method * * @param string * @param mixed */ public function __set($name, $value) { $this->offsetSet($name, Core_ArrayObject::transform($value)); }
/** * Set rights for user */ public function setRights() { $cogear = getInstance(); DEVELOPMENT && $this->reset(); if ($cogear->session->access !== NULL) { return; } if (!$access = $cogear->system_cache->read('access/user_group/' . $cogear->user->user_group)) { if ($access = $cogear->db->get_where('access', array('gid' => $cogear->user->user_group))->result()) { $cogear->system_cache->write('access/user_group/' . $cogear->user->user_group, $access, array('access', 'user_groups', 'access/user_groups')); } } if (!$user_access = $cogear->system_cache->read('access/users/' . $cogear->user->id)) { if ($user_access = $cogear->db->get_where('access', array('uid' => $cogear->user->id))->result()) { $cogear->system_cache->write('access/users/' . $cogear->user->id, $user_access, array('access', 'access/users', 'user/' . $cogear->user->id)); } } $user_access && $access->mix($user_access); $cogear->session->access = Core_ArrayObject::transform($this->prepare($access)); }
/** * Получение одной записи из результата запроса * * @return object|NULL */ public function row() { if ($this->result instanceof PDOStatement) { if ($result = $this->result->fetch(PDO::FETCH_ASSOC)) { return Core_ArrayObject::transform($result); } return FALSE; } }
/** * Constructor */ public function __construct() { parent::__construct(); $this->info = Core_ArrayObject::transform($this->info); }
/** * Result * * @return NULL|Core_ArrayObject — filtered and validated data */ public function result() { $this->init(); event('form.result.before', $this); event('form.' . $this->name . '.result.before', $this); $this->request = $this->method == 'POST' ? $_POST : $_GET; $result = array(); $is_valid = TRUE; if (sizeof($this->request) > 0) { foreach ($this->elements as $name => $element) { $value = $element->result(); if ($value !== FALSE) { $result[$name] = $value; } else { $is_valid = FALSE; } } } if ($this->is_ajaxed) { $response = array(); foreach ($this->elements as $name => $element) { if ($name == Ajax::get('element')) { if ($result = $element->ajax()) { $response[$name] = $result; } } } event('form.ajax.before', $this, $response); event('form.' . $this->name . '.ajax.before', $this, $response); $response && Ajax::json($response); } event('form.result.after', $this, $is_valid, $result); event('form.' . $this->name . '.result.after', $this, $is_valid, $result); return $is_valid && $result ? Core_ArrayObject::transform($result) : FALSE; }