/** * Sends HttpSocket requests. Builds your uri and formats the response too. * * @param Model $model Model object * @param mixed $requestData Array of request or string uri * @param string $requestMethod read, create, update, delete * * @return array|false $response */ public function request(Model $model = null, $requestData = null, $requestMethod = HttpSource::METHOD_READ) { if ($model === null) { return parent::request($model, $requestData, $requestMethod); } $HtmlHelper = new HtmlHelper(new View()); unset($model->request['uri'], $model->request['virtual']); $model->request['body'] = '<?xml version="1.0" encoding="utf-8"?>' . $HtmlHelper->tag('request', $model->request['body']); return parent::request($model, $requestData, $requestMethod); }
/** * Extend the default tag function by allowing for arrays of text */ function tag($name, $text = null, $options = array()) { if (is_array($text)) { $output = ''; foreach ($text as $t) { $output .= parent::tag($name, $t, $options); } return $output; } else { return parent::tag($name, $text, $options); } }
public function breadcrumb($items, $options = array()) { $default = array('class' => 'breadcrumb'); $options += $default; $count = count($items); $li = array(); for ($i = 0; $i < $count - 1; $i++) { $text = $items[$i]; $text .= ' <span class="divider">/</span>'; $li[] = parent::tag('li', $text); } $li[] = parent::tag('li', end($items), array('class' => 'active')); return parent::tag('ul', implode("\n", $li), $options); }
public function scriptsForLayout($type = null) { $scripts = ''; $files = $this->Baklava->getCombined(); foreach ($files as $t => $file) { if ($type && $type != $t) { continue; } switch ($t) { case 'css': $scripts .= parent::css($file, null, array('inline' => true)); break; case 'js': $scripts .= parent::script($file, array('inline' => true, 'defer' => true)); break; case 'style': $scripts .= parent::tag('style', $file, array('type' => 'text/css')); break; } } return $scripts; }
function create_account() { if (!Configure::read('feature.manage_accounts')) { $this->Session->setFlash(__('This system uses ' . Configure::read('feature.manage_name') . ' to manage user accounts. Account creation through Zuluru is disabled.', true), 'default', array('class' => 'info')); $this->redirect('/'); } if (!$this->is_admin && !$this->is_manager && $this->UserCache->currentId()) { $this->Session->setFlash(__('You are already logged in!', true), 'default', array('class' => 'info')); $this->redirect('/'); } $this->_loadAddressOptions(); $groups = $this->_loadGroupOptions(); $this->_loadAffiliateOptions(); $user_model = $this->Auth->authenticate->name; $this->set(array('user_model' => $user_model, 'id_field' => $this->Auth->authenticate->primaryKey, 'user_field' => $this->Auth->authenticate->userField, 'email_field' => $this->Auth->authenticate->emailField)); if (!empty($this->data)) { // Set the default error message in advance. If it saves successfully, this will be overwritten. $this->Session->setFlash(sprintf(__('The %s could not be saved. Please correct the errors below and try again.', true), __('account', true)), 'default', array('class' => 'warning')); // The presence of data in a field that should not be filled in triggers anti-spam measures. // Also, anyone that fills the form out in under 15 seconds is a spambot. if (Configure::read('feature.antispam') && (!empty($this->data[$user_model]['subject']) || time() - $this->data[$user_model]['timestamp'] < 15)) { sleep(15); return; } // Handle affiliations if (Configure::read('feature.affiliates')) { if (Configure::read('feature.multiple_affiliates')) { if (empty($this->data['Affiliate']['Affiliate'][0])) { $this->Person->Affiliate->validationErrors['Affiliate'] = __('You must select at least one affiliate that you are interested in.', true); } } else { if (empty($this->data['Affiliate']['Affiliate'][0]) || count($this->data['Affiliate']['Affiliate']) > 1) { $this->Person->Affiliate->validationErrors['Affiliate'] = __('You must select an affiliate that you are interested in.', true); } } } else { $this->data['Affiliate']['Affiliate'] = array(1); } // SaveAll doesn't work correctly in this case. Save them separately, to make sure they're all validated. $this->Auth->authenticate->saveAll($this->data[$user_model], array('validate' => 'only')); $this->Person->saveAll($this->data['Person'], array('validate' => 'only')); foreach ($this->data['Person'] as $key => $person) { if (!empty($this->data['Person'][$key]['Skill']) && !$this->Person->Skill->saveAll($this->data['Person'][$key]['Skill'], array('validate' => 'only'))) { $this->Person->validationErrors[$key]['Skill'] = $this->Person->Skill->validationErrors; } } // Make sure someone isn't forging their way into an entirely unauthorized level. if (!$this->is_admin && !empty($this->data['Group']['Group'])) { $selected_groups = $this->Group->find('all', array('contain' => false, 'conditions' => array('id' => $this->data['Group']['Group']))); if ($this->is_manager) { $level = 5; } else { $level = 3; } $invalid_groups = Set::extract("/Group[level>{$level}]", $selected_groups); if (!empty($invalid_groups)) { $this->Person->Group->validationErrors['Group'] = __('You have selected an invalid group.', true); } } else { $selected_groups = array(); } if ($this->Auth->authenticate->validates() && $this->Person->validates() && $this->Person->Group->validates() && $this->Person->Affiliate->validates()) { // User and person records may be in separate databases, so we need a transaction for each $user_transaction = new DatabaseTransaction($this->Auth->authenticate); $person_transaction = new DatabaseTransaction($this->Person); if ($this->Auth->authenticate->save($this->data)) { // Tweak some data to be saved $this->data['Person'][0]['user_id'] = $this->Auth->authenticate->id; foreach ($this->data['Person'] as $key => $person) { $person['complete'] = true; if ($this->is_admin) { if ($key != 0) { $person['status'] = $this->data['Person'][0]['status']; } } else { if (Configure::read('feature.auto_approve')) { if ($key == 0) { // Check the requested groups and do not auto-approve above a certain level $invalid_groups = Set::extract('/Group[level>1]', $selected_groups); if (empty($invalid_groups)) { $person['status'] = 'active'; } } else { $person['status'] = 'active'; } } } $save = array('Person' => $person, 'Affiliate' => $this->data['Affiliate']); if (!empty($person['Skill'])) { $save['Skill'] = $person['Skill']; unset($person['Skill']); } if ($key == 0) { $save['Group'] = $this->data['Group']; } else { // Assume any secondary profiles are players $save['Group'] = array('Group' => array(GROUP_PLAYER)); if (isset($this->data['Person'][0]['status'])) { $save['Person']['status'] = $this->data['Person'][0]['status']; } } $this->Person->create(); if (!$this->Person->saveAll($save)) { return; } if (!isset($parent_id)) { $parent_id = $this->Person->id; } else { $this->Person->PeoplePerson->save(array('person_id' => $parent_id, 'relative_id' => $this->Person->id, 'approved' => true), array('validate' => false)); } } App::import('Helper', 'Html'); $html = new HtmlHelper(); if (Configure::read('feature.auto_approve')) { $msg = $html->tag('h2', __('THANK YOU', true)) . $html->para(null, sprintf(__('for creating an account with %s.', true), Configure::read('organization.name'))); } else { $msg = $html->para(null, __('Your account has been created.', true) . ' ' . __('It must be approved by an administrator before you will have full access to the site.', true) . ' ' . __('However, you can log in and start exploring right away.', true)); } if (isset($this->params['form']['continue'])) { $msg .= $html->para(null, __('Please proceed with entering your next child\'s details below.', true)); } $this->Session->setFlash($msg, 'default', array('class' => 'success')); // There may be callbacks to handle // TODO: How to handle this in conjunction with third-party auth systems? $this->data['Person']['id'] = $this->Person->id; $components = Configure::read('callbacks.user'); foreach ($components as $name => $config) { $component = $this->_getComponent('User', $name, $this, false, $config); $component->onAdd($this->data); } $user_transaction->commit(); $person_transaction->commit(); if (!$this->is_logged_in) { // Automatically log the user in $this->data[$this->Auth->authenticate->alias]['password'] = $this->data[$this->Auth->authenticate->alias]['passwd']; $this->Auth->login($this->Auth->hashPasswords($this->data)); } if (isset($this->params['form']['continue'])) { $this->redirect(array('controller' => 'people', 'action' => 'add_relative')); } $this->redirect('/'); } } } else { // By default, select the first group $this->data = array('Group' => array('Group' => array(current(array_keys($groups))))); } }
/** * create follow me button * * @param string $screen_name * @param string $elementId */ public function followMe($screen_name, $elementId = 'followMe') { $out = $this->Html->tag('span', '', array('id' => $elementId)); $out .= $this->Html->scriptBlock("\n twttr.anywhere(function (T) {\n T('#{$elementId}').followButton('{$screen_name}');\n });"); return $out; }
function ajaxUrl() { if ($this->alreadyPrintedAjaxUrl) { return false; } $attributes = HtmlHelper::attr(array('name' => 'ajax_url', 'type' => 'hidden', 'value' => admin_url('admin-ajax.php'))); echo HtmlHelper::tag("input/", $attributes, null, null); $this->alreadyPrintedAjaxUrl = true; }
function import($type = null, $name = null, $charset = "utf-8") { switch ($type) { case 'style': $attribs = HtmlHelper::attr(array('rel' => 'stylesheet', 'href' => DUP_CORE_STYLES_URL . "{$name}.css", 'type' => 'text/css', 'media' => 'screen', 'title' => phraseize($name), 'charset' => $charset)); return HtmlHelper::tag('link/', $attribs); break; case 'script': $attribs = HtmlHelper::attr(array('src' => DUP_CORE_STYLES_URL . "{$name}.css", 'type' => 'text/javascript', 'charset' => $charset)); return HtmlHelper::tag('script', $attribs, null, null, null) . HtmlHelper::tag('/script', null, null, null); break; } }
public function test_tag() { $h = new HtmlHelper(); $this->assertEquals('<a href="https://github.com/">github</a>', $h->tag('a')->attr('href', 'https://github.com/')->append('github')->toString()); }
/** * Create a Bootstrap Button or Link * * @param string $text text in the button * @param string $url url of the link * @param array $options 'size' => lg, sm or xs, to change the size of the button * 'type' => primary, success, etc, to change the color * 'tag' => to change the tag * and more... (like 'class') * @param array $confirmMessage to add a confirm pop-up * @return string */ public function btn($text, $url = array(), $options = array(), $confirmMessage = false) { $tag = 'a'; if (!empty($options['tag'])) { $tag = $options['tag']; } $class = 'btn'; $class .= !empty($options['type']) ? ' btn-' . $options['type'] : ''; $class .= !empty($options['size']) ? ' btn-' . $options['size'] : ''; $class .= isset($options['class']) ? ' ' . $options['class'] : ''; $options['class'] = $class; if ($tag != 'a') { unset($options['tag']); unset($options['type']); unset($options['size']); } if ($tag != 'a') { return parent::tag($tag, $text, $options); } else { return parent::link($text, $url, $options, $confirmMessage); } }
/** * Returns an icon element followed by a text. * This function is used for generating an icon for internal functions inside this * helper. * * @param string $title * @param string|array $options * @return string * todo We need to refactor this function in order to load an array of icon class with no prefix on the class */ protected function _icon($title, array $options = []) { if (empty($options) || !isset($options['icon'])) { return $title; } $options = $options['icon']; if (is_array($options)) { if (!isset($options['class']) || empty($options['class'])) { return $title; } } if (is_string($options)) { if (empty($options)) { return $title; } $icon = $this->iconPrefix; $options = ["class" => "{$icon} {$icon}-{$options}"]; } $tag = parent::tag('i', '', $options); return trim($tag . ' ' . $title); }
$Html = new HtmlHelper(new View()); $config['SMSFlySource']['config_version'] = 2; $CF = HttpSourceConfigFactory::instance(); $Config = $CF->config(); $Config->add($CF->endpoint()->id(1)->methodCreate()->table('SENDSMS')->path('')->addCondition($CF->condition()->name('startTime')->map(null, 'start_time')->defaults('AUTO'))->addCondition($CF->condition()->name('endTime')->map(null, 'end_time')->defaults('AUTO'))->addCondition($CF->condition()->name('lifetime')->defaults(4))->addCondition($CF->condition()->name('rate')->defaults(120))->addCondition($CF->condition()->name('desc')->defaults(''))->addCondition($CF->condition()->name('source')->required())->addCondition($CF->condition()->name('messages')->required())->queryBuilder(function (Model $model, array $usedConditions, array $queryData) use($Html) { $messagesData = $queryData['conditions']['messages']; array_walk($messagesData, function (&$phones) { $phones = is_array($phones) ? $phones : array($phones); }); $messageOptions = array_intersect_key($queryData['conditions'], array_flip(array('start_time', 'end_time', 'lifetime', 'rate', 'desc', 'source'))); $messages = ''; if (count($messagesData) > 1) { $messageOptions['type'] = 'individual'; foreach ($messagesData as $message => $phones) { foreach ($phones as $phone) { $messages .= $Html->tag('recipient', $phone); $messages .= $Html->tag('body', $message); } } } else { foreach ($messagesData as $message => $phones) { $messages .= $Html->tag('body', $message); $phones = is_array($phones) ? $phones : array($phones); foreach ($phones as $phone) { $messages .= $Html->tag('recipient', $phone); } } } $data = $Html->tag('operation', 'SENDSMS'); $data .= $Html->tag('message', $messages, $messageOptions); $model->request['body'] = $data;
/** * Image Radio Control * * Enhanced Javascript Control, that allows an array of images, to act as radio * * @param string $name * @param string $options * @return void * @author Armando Sosa */ function _imageRadio($name, $options) { $options = set_merge(array('baseDir' => ''), (array) $options); $input = HtmlHelper::tag('div.image-radio-group'); foreach ($options['options'] as $value => $image) { $selected = $value == $options['value'] ? '.selected' : ''; $atts = HtmlHelper::attr(array('title' => $value, 'src' => $options['baseDir'] . $image)); $input .= HtmlHelper::tag('img.radio' . $selected, $atts); } $input .= $this->input($name, array('type' => 'hidden', 'value' => $value), false); $input .= HtmlHelper::tag('/div.image-radio-group'); return $input; }