/** * Process posts render * * @param type $posts * @return type */ public function process($posts, $pager) { $output = new Core_ArrayObject(); foreach ($posts as $post) { $post->teaser = TRUE; $output->append($post->render()); } event('post.list', $posts); $output->append($pager->render()); return $output->toString(); }
/** * Render */ public function render() { event('grid.render', $this); event('grid.render.' . $this->name, $this); $output = new Core_ArrayObject(); foreach ($this as $item) { $item->in_grid = TRUE; $output->append($item->render($this->item_template)); } $tpl = new Template('Grid.grid'); $tpl->grid = $this; $tpl->data = $output->toString(); return $tpl->render(); }
/** * 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'); }
/** * Подготовка вывода * * @return string */ public function output() { $output = new Core_ArrayObject(); foreach ($this as $item) { if ($item instanceof Callback) { $output->append($item->run()); } else { $output->append($item); } } if ('widgets' === cogear()->input->get('mode') && access('Theme.widgets')) { echo template('Theme/templates/widgets/wrapper', array('output' => $output, 'name' => $this->name))->render(); } elseif ($output) { echo $output; } }
/** * 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; } }
/** * Transform plain array to multidimensional * @param array $data * @param string $separator * @return array */ public static function plainToMulti($data, $separator = '.') { $result = new Core_ArrayObject(); foreach ($data as $key => $value) { $pieces = new CachingIterator(new ArrayIterator(explode($separator, $key))); $current =& $result; foreach ($pieces as $piece) { if ($pieces->hasNext()) { if (!isset($current->{$piece})) { $current->{$piece} = new Core_ArrayObject(); } $current =& $current->{$piece}; } else { $current->{$piece} = $value; } } } return $result->toArray(); }
/** * Remove rights from user * * @param int $uid * @param array $rights */ public function removeUserRights($rights, $uid = NULL) { $uid or $uid = $this->user->id; !is_array($rights) && ($rights = (array) $rights); $access = $this->getUserRights($uid) or $access = new Core_ArrayObject(); foreach ($rights as $right) { if (!$access->offsetExists($right)) { $access->offsetUnset($right); } } $this->system_cache->write('access/users/' . $uid, $access); }
/** * Magic __set method * * @param string * @param mixed */ public function __set($name, $value) { $this->offsetSet($name, Core_ArrayObject::transform($value)); }
/** * Magic __get method * * @param string $name * @return mixed */ public function __get($name) { return isset($this->{$name}) ? $this->{$name} : parent::__get($name); }
/** * 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)); }
/** * Get gear options */ protected function getSettings() { $this->settings = new Core_ArrayObject($this->settings); if ($config = Config::read(find(basename($this->dir) . DS . 'settings' . EXT))) { return $this->settings ? $this->settings->mix($config) : ($this->settings = $config); } return NULL; }
/** * Get styles * * @return string */ public function getStyles() { return $this->styles->__toString() . "\n"; }
/** * Конструктор */ public function __construct($name) { $this->name = $name; parent::__construct(); $this->results = new Core_ArrayObject(); }
/** * Constructor */ public function __construct() { parent::__construct(); $this->info = Core_ArrayObject::transform($this->info); }
/** * Активация шестеренки */ public function enable() { $result = new Core_ArrayObject(array('success' => TRUE, 'message' => t('Шестеренка активирована!'), 'code' => 1, 'gears' => new Core_ArrayObject())); if ($this->status() != Gears::DISABLED) { $result->message = t('Шестеренка уже активирована!'); $result->success = FALSE; } if ($this->required && FALSE === $this->required->success) { $gears_required = new Core_ArrayObject(); $gears_incomp_version = new Core_ArrayObject(); $gears_incomp = new Core_ArrayObject(); foreach ($this->required->gears as $gear) { // Несовместимые шестерйнки if (Gears::ERROR_INCOMP === $gear->success) { $gears_incomp->append($gear->name); } // Шестерёнки неправильных версий if (Gears::ERROR_VERSION === $gear->success) { $gears_incomp_version->append($gear->name); } // Необходимые шестерёнки if (Gears::ERROR_REQUIRED === $gear->success) { $gears_required->append($gear->name); } } $gears_required->count() && ($result->message = t('Следующие шестерёнки должны быть активированы: ') . '<span class="label label-important">' . $gears_required->toString("</span> <span class='label label-important'>") . "</span>"); $gears_incomp_version->count() && ($result->message .= '<br/>' . t('Следующие шестеренки должны быть соответствующих версий: ') . '<span class="label label-important">' . $gears_incomp_version->toString("</span> <span class='label label-important'>") . "</span>"); $gears_incomp->count() && ($result->message .= t('Следующие шестеренки должны быть отключены: ') . '<span class="label label-important">' . $gears_incomp->toString("</span> <span class='label label-important'>") . "</span>"); $result->success = FALSE; } $result->success && $this->status(Gears::ENABLED); event('gear.enable', $this, $result); return $result; }
public function __construct($options = array()) { $defaults = new Core_ArrayObject(array('name' => 'user', 'render' => FALSE)); $options && $defaults->extend($options); parent::__construct($defaults); }
/** * 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; }
/** * Получение одной записи из результата запроса * * @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; } }
/** * Row * * @return Core_ArrayObject|NULL */ public function row() { return $this->result ? Core_ArrayObject::transform(mysqli_fetch_assoc($this->result)) : NULL; }
/** * Set header * * @param string $name * @param string $data */ public function header($name, $data) { $this->headers->offsetSet($name, $data); }
echo $gear->description; ?> <p class="gear-info"> <b><?php echo t("Автор"); ?> :</b> <a href="<?php echo $gear->site; ?> "><?php echo $gear->author; ?> </a> <?php if ($gear->required) { $output = new Core_ArrayObject(); ?> <br/> <strong><?php echo t('Зависимости'); ?> :</strong> <?php foreach ($gear->required->gears as $info) { if (TRUE === $info->success) { if ($info->disabled) { $output->append('<span class="label label-inverse" title="' . t('Требование выполнено (шестерёнка отключена)') . '">' . $info->name . ($info->version ? ' ' . $info->version : '') . '</span>'); } else { $output->append('<span class="label label-success" title="' . t('Требование выполнено') . '">' . $info->name . ($info->version ? ' ' . $info->version : '') . '</span>'); } } else {
/** * Конструктор */ public function __construct($options = array()) { parent::__construct(); $this->init($options); }
/** * 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; }
/** * Run event * @param string $name * @param mixed $arg_1 * … * @param mixed $arg_N * @return boolean */ public function event($name) { $result = new Core_ArrayObject(); $args = func_get_args(); $args = array_slice($args, 1); if ($this->events->{$name}) { foreach ($this->events->{$name} as $callback) { if ($this->events->{$name}->is_stopped()) { continue; } if ($data = $callback->call($args)) { $result->append($data); } } } return $result; }
/** * Конструктор */ public function __construct($config) { parent::__construct($config); $this->info = Core_ArrayObject::transform($this->info); $this->info->title->append(config('site.name', SITE_URL)); }
/** * Проверка требований и несовместимостей шестерёнок */ public function check() { $remove = new Core_ArrayObject(); foreach ($this as $name => $info) { if ($info->required) { $info->required->success = TRUE; foreach ($info->required->gears as $req_gear) { $req_gear->success = TRUE; // Проверяем статус шестерёнки switch (gear_status($req_gear->name)) { case Gears::ENABLED: // Если шестерёнка включена (нам же нужно, чтобы была выключена) if ($req_gear->disabled) { $req_gear->success = self::ERROR_INCOMP; $info->required->success = FALSE; } case Gears::CORE: // Если такая шестерёнка вообще существует в списке загруженных if ($this->offsetExists($req_gear->name)) { // Если указана версия шестерёнки if ($req_gear->version) { // Версия с условием if ($req_gear->condition && !version_compare($this->{$req_gear->name}->version, $req_gear->version, $req_gear->condition)) { $req_gear->success = self::ERROR_VERSION; $info->required->success = FALSE; } elseif (version_compare($this->{$req_gear->name}->version, $req_gear->version, ' < ')) { $req_gear->success = self::ERROR_REQUIRED; $info->required->success = FALSE; } } } else { $req_gear->success = self::ERROR_REQUIRED; $info->required->success = FALSE; } if (gear_status($name) == Gears::ENABLED) { $this->{$req_gear->name}->depends or $this->{$req_gear->name}->depends = new Core_ArrayObject(); $this->{$req_gear->name}->depends->findByValue($name) !== NULL or $this->{$req_gear->name}->depends->append($name); } break; case Gears::DISABLED: default: if (!$req_gear->disabled) { $req_gear->success = self::ERROR_REQUIRED; $info->required->success = FALSE; } } if (FALSE === $info->required->success) { $remove->append($info->gear); } } } } if ($this->options->remove) { foreach ($remove as $gear) { $this->offsetUnset($gear); } } }