function addLink($item, $name = null) { $item = arrize($item, 'url') + compact('name'); $item['url'] = static::expand($item['url']); if (!isset($item['caption'])) { $item['caption'] = "{$name}" === '' ? $url : static::caption($name); } return $this->add(new MenuItem($item)); }
function overrideHTMLki($path, $overrides) { $override = function () use($path, $overrides) { $overrides = arrize($overrides, 'ns'); if (!empty($overrides['ns'])) { $overrides += array('compiledHeader' => "<?namespace {$overrides['ns']}?>\n", 'evalPrefix' => "namespace {$overrides['ns']};\n"); } \overrideHTMLki($path, $overrides); }; if (\Bundle::started('htmlki')) { $override(); } else { \Event::listen('laravel.started: htmlki', $override); } }
static function all($ids = null, $columns = '*') { if (head((array) $columns) !== '*') { return parent::all($ids, $columns); } elseif (!$ids) { return static::cacheAll(parent::all($ids)); } else { $cached = $new = array(); foreach (arrize($ids) as $id) { ($model = static::cached($id)) ? $cached[] = $model : ($new[] = $id); } $new and $new = static::cacheAll(parent::all($new)); return array_merge($cached, $new); } }
function __construct($handler, $options = array()) { $this->extractTagTo($this->tag, $handler); list($handler, $args) = explode(' ', ltrim("{$handler} "), 2); $this->args = trim($args); if (strrchr($handler, '@') === false) { // ctl[.sub[....]] - dots separating not classes but controller's name. $this->controller = $handler; } else { // ctl[.sub[....]]@[actn][.class[.....]] $this->controller = strtok($handler, '@'); $this->action = '' . strtok('.'); $this->classes = static::splitClasses(strtok(null)); } $this->options = $options === '!' ? null : arrize($options); }
static function execCustom($block, array $options = array()) { $options += array('args' => array(), 'verb' => null, 'ajax' => null, 'input' => null, 'layout' => null, 'prepare' => null, 'response' => false, 'return' => null); $input =& $options['input']; if (isset($input)) { $input = arrize($input); isset($options['verb']) or $options['verb'] = 'get'; } $obj = static::factory($block); if ($obj instanceof self) { $obj->input = $input; $obj->top = $options['layout']; } $options['prepare'] and call_user_func($options['prepare'], $obj); // Substituting Symfony's request method as Laravel is explicitly using // global Request::method() when executing a controller's method. if ($verb = $options['verb'] and $verb != Request::method()) { $oldVerb = Request::foundation()->getMethod(); Request::foundation()->setMethod($verb); } if (isset($options['ajax'])) { $oldAJAX = Request::ajax(); Request::ajax($options['ajax']); } try { $exec = $obj->execute(static::actionFrom($block), arrizeAny($options['args'])); } catch (\Exception $e) { $exception = $e; } // Reverting old (current) request state. isset($oldAJAX) and Request::ajax($oldAJAX); isset($oldVerb) and Request::foundation()->setMethod($oldVerb); if (isset($exception)) { throw $exception; } if ($options['response']) { $response = with(new static())->toResponse($exec); } return array_get(compact('obj', 'exec', 'response'), $options['return']); }
function ajax_post_index() { $input = $this->in(); $rules = array('email' => 'required|email', 'name' => 'required', 'surname' => 'required', 'address' => 'min:5', 'phone' => 'required|min:7|vanemart_phone'); $rules += (array) \Vane\Current::config('general.user_fields.order'); $valid = Validator::make($input, $rules); if ($this->can('checkout.deny')) { return false; } elseif (!Cart::has() or Cart::isTooSmall()) { return E_INPUT; } elseif ($valid->fails()) { return $valid; } else { \DB::transaction(function () use(&$input, &$user, &$order) { $user = User::findOrCreate($input); $order = Order::createBy(head(arrize($user)), $input); $goods = S(Cart::all(), function ($qty, $product) use($order) { return compact('qty', 'product') + array('order' => $order->id); }); OrderProduct::insert($goods); }); $newUser = is_array($user); if ($newUser) { list($user, $password) = $user; } $options = compact('user', 'order') + array('block' => $this); if ($newUser) { $options += compact('password'); $event = 'checkout.reg_user'; } else { $event = 'checkout.old_user'; } Event::fire($event, array($user, &$options)); Event::fire('checkout.done', array($user, &$options)); return $order; } }
function addGetSingle($id = null) { $goods = static::fromSKU($this->in('sku', null)); $goods += arrize($this->in('id', null)); $id and $goods += array($id => 1); $single = null; foreach ($goods as $id => $item) { $result = Cart::put($id, is_object($item) ? $item->qty : $item); $result and $single = $single ? true : $result; } return $single; }
function response() { $ajax = Request::ajax(); $ajax === 'd' and Request::ajax(true); $naked = Input::get(Block::$nakedVar, $ajax); $onlyBlocks = Input::get('_blocks'); if (!isset($onlyBlocks) and $ajax) { $onlyBlocks = ''; } $singleBlock = (isset($onlyBlocks) and !is_array($onlyBlocks)); $firstServed = in_array(head((array) $onlyBlocks), array('!', '1', '')); if ($singleBlock and !$naked) { // preventing DoubleEdge from wrapping response into $fullView. Input::merge(array(Block::$nakedVar => 1)); } $rendering = new Rendering($this, $onlyBlocks); $rendering->slugs = $this->slugs; $response = null; if ($singleBlock and $firstServed or $this->breaksout()) { isset($this->served) or Log::info_Layout('No specific server on this route.'); $rendering->result = array($this->servedResponse()); $ajax and $response = $rendering->result[0]; } elseif ($singleBlock) { $rendering->render($this); $rendering->result = array_slice($rendering->result, 1, -1, true); foreach ($rendering->result as $block) { foreach (arrize($block) as $blockResponse) { is_object($blockResponse) and $blockResponse->isServed = true; } } } else { $rendering->render($this); } Request::ajax(null); if ($response) { // do nothing. } elseif ($onlyBlocks and !$rendering->result) { $paths = join(', ', (array) $onlyBlocks); Log::warn_Layout("No blocks to render have matched given path(s): {$paths}."); $response = $this->servedResponse(E_INPUT); } else { $naked and $rendering->unwrap(); $response = $rendering->served ?: Response::adapt(''); $content = $rendering->join($ajax); if (!$naked and !$singleBlock and is_scalar($content) and $full = $this->view()) { $content = $full->with(compact('content')); } if (method_exists($response, 'set')) { $response->set($content); } else { $response->content = $content; } } // restoring value that could have been set in the beginning. Input::merge(array(Block::$nakedVar => $naked)); return Response::postprocess($response); }
$max = -1; } else { $max = \Config::get('vanemart::post.add.max_attaching_files', 10); } $attached = $options['post']->attach('attach', $max, $block->user()); $models = array_merge($models, $attached); } }); // Fired after successfully adding a post with attachments and all required database // and other changes. // //* $options hash - the same as in post.attach plus 'attachments' hash of File. Event::listen(VANE_NS . 'post.added', function (array $options) { extract($options, EXTR_SKIP); $poster = $block->user(false); $to = User::all(arrize(\Vane\Current::config('general.post_notify_users'))); if ($type === 'order' and $order = Order::find($object)) { foreach (array('user', 'manager') as $field) { $to[] = $order->{$field}()->first(); } } foreach ($to as $recipient) { if (!$poster or $poster->email != $recipient->email) { \Vane\Mail::sendTo($recipient->emailRecipient(), 'vanemart::mail.order.post', array('order' => $order->to_array(), 'user' => $block->user()->to_array(), 'recipient' => $recipient->to_array(), 'post' => $post->to_array(), 'files' => func('to_array', $attachments))); } } }); // Fired after post.added if post is attached to an object. // //* $object Eloquent //* $options hash - the same as in post.added.
function unwrap() { $this->result = S($this->result)->keep(function ($block) { return is_array($block) or is_object($block); })->map(function ($block) { $block = S::keep(arrize($block), 'is_object'); return count($block) > 1 ? $block : reset($block); })->get(); return $this; }
static function number($num, $options = null) { return Str::number($num, array('html' => true) + arrize($options, 'point')); }