/** * 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(); }
/** * Подготовка вывода * * @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; } }
/** * 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(); }
/** * Активация шестеренки */ 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 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); } } }
/** * 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; }
?> </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 { if (-2 == $info->success) { $output->append('<span class="label label-warning" title="' . t('Несовместимость') . '">' . $info->name . '</span>'); } else { $output->append('<span class="label label-important" title="' . t('Требуется') . '">' . $info->name . ($info->version ? ' ' . $info->version : '') . '</span>'); } } } echo $output; ?> <?php }