public static function uploadPicture() { $user_id = Input::get('object_id'); $type = Input::get('object_type'); $user_id = Input::get('user_id'); $uploader = new Utils_Uploader(array('jpeg', 'jpg', 'png')); $path = DOCROOT . 'assets/uploads' . DS; if (!file_exists($path)) { mkdir($path, 0777, true); } $typeName = Model_Upload_Type::find($type)->types; $pic_name = $typeName . "_" . time(); $original = $path . $pic_name; $output = $uploader->handleUploadRename($path, $pic_name); if (isset($output['success'])) { $original = $path . $output['full_filename']; $uploadAll = Model_Upload::forge(); $uploadAll->user_id = $user_id; $uploadAll->type_id = $type; $uploadAll->name = $output['full_filename']; $uploadAll->original_name = $output['full_filename']; $uploadAll->path = $original; $uploadAll->save(); $output['upload_id'] = $uploadAll->id; Image::load($original)->preset($typeName)->save($original); $localFileName = $path . $output['full_filename']; $remoteFileName = DOCROOT . 'assets/uploads/' . DS . $output['full_filename']; $output['uri'] = Uri::create('upload/get_image/' . $output['full_filename'] . '/' . $output['upload_id']); } return $output; }
public function action_execute() { $database_settings = \Config::load('backup::db'); $backupfile = $database_settings['backup']['database'] . date("Y-m-d") . '.sql'; $backupzip = $backupfile . '.tar.gz'; system('mysqldump -u' . $database_settings['backup']['username'] . ' -p' . $database_settings['backup']['password'] . ' ' . $database_settings['backup']['database'] . ' > ' . $backupfile); system("tar -czvf {$backupzip} {$backupfile}"); // Send autoresponder $autoresponder = \Autoresponder\Autoresponder::forge(); $autoresponder->view_custom = 'database_backup'; $settings = \Config::load('autoresponder.db'); $content['company_name'] = $settings['company_name']; $content['address'] = $settings['address']; $content['website'] = $settings['website']; $content['message'] = 'This is your database backup from ' . \Uri::create('/'); $content['subject'] = 'Database Backup'; $autoresponder->autoresponder_custom($content, 'backup', array(DOCROOT . $backupzip)); if ($autoresponder->send()) { echo 'The mail has been sent successfully.'; } else { echo 'There was an error while trying to sent email.'; } // Delete the file from your server unlink($backupfile); unlink($backupzip); exit; }
/** @inheritdoc */ public static function displayList($value, $edit_link, &$settings, &$model) { if (empty($value) || is_null($value) || strlen($value) === 0) { return '<a href="' . $edit_link . '" class="item-link">(none)</a>'; } return '<a href="' . $edit_link . '" class="item-link"><img src="' . \Uri::create('/admin/assets/img/lang/' . $value . '.png') . '" style="width:24px;height:24px;" /> ' . \Lang::get("languages.{$value}") . '</a>'; }
/** * Because Paypal Ipn is redirected to \Payment\PayPal\ipn * There is no need to notify customer here, we'll do that in Ipn method of Payment module */ public function notify() { $config = array('mode' => $this->config['mode'], 'acct1.UserName' => $this->config['user_name'], 'acct1.Password' => $this->config['password'], 'acct1.Signature' => $this->config['signature']); $paypalService = new \PayPal\Service\PayPalAPIInterfaceServiceService($config); $getExpressCheckoutDetailsRequest = new \PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType(\Session::get('paypal.token')); $getExpressCheckoutDetailsRequest->Version = $this->config['version']; $getExpressCheckoutReq = new \PayPal\PayPalAPI\GetExpressCheckoutDetailsReq(); $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest; $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq); // COMMIT THE PAYMENT $paypalService = new \PayPal\Service\PayPalAPIInterfaceServiceService($config); $paymentDetails = new \PayPal\EBLBaseComponents\PaymentDetailsType(); $orderTotal = new \PayPal\CoreComponentTypes\BasicAmountType($this->config['currency'], $this->getOrderTotal()); $paymentDetails->OrderTotal = $orderTotal; $paymentDetails->PaymentAction = 'Sale'; $paymentDetails->NotifyURL = $this->config['notify_url']; $DoECRequestDetails = new \PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType(); $DoECRequestDetails->PayerID = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID; $DoECRequestDetails->Token = $getECResponse->GetExpressCheckoutDetailsResponseDetails->Token; $DoECRequestDetails->PaymentDetails[0] = $paymentDetails; $DoECRequest = new \PayPal\PayPalAPI\DoExpressCheckoutPaymentRequestType(); $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails; $DoECRequest->Version = $this->config['version']; $DoECReq = new \PayPal\PayPalAPI\DoExpressCheckoutPaymentReq(); $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest; $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq); if ($DoECResponse->Ack == 'Success') { $this->savePayment('Completed', 'Completed', $DoECResponse->toXMLString()); \Response::redirect(\Uri::create('order/checkout/finalise_order')); } $this->savePayment('Failed', 'Transaction failed', $DoECResponse->Errors[0]->LongMessage); return true; // failed }
/** * Tests Uri::create() * * @test */ public function test_create() { Config::set('url_suffix', ''); $prefix = Uri::create(''); $output = Uri::create('controller/method'); $expected = $prefix . "controller/method"; $this->assertEquals($expected, $output); $output = Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and')); $expected = $prefix . "controller/thing?what=more"; $this->assertEquals($expected, $output); Config::set('url_suffix', '.html'); $output = Uri::create('controller/method'); $expected = $prefix . "controller/method.html"; $this->assertEquals($expected, $output); $output = Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and')); $expected = $prefix . "controller/thing.html?what=more"; $this->assertEquals($expected, $output); $output = Uri::create('http://example.com/controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and')); $expected = "http://example.com/controller/thing.html?what=more"; $this->assertEquals($expected, $output); $output = Uri::create('http://example.com/controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'), true); $expected = "https://example.com/controller/thing.html?what=more"; $this->assertEquals($expected, $output); $output = Uri::create('https://example.com/controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'), false); $expected = "http://example.com/controller/thing.html?what=more"; $this->assertEquals($expected, $output); }
/** * Create a form open tag * * @param string|array action string or array with more tag attribute settings * @return string */ public static function open($attributes = array(), array $hidden = array()) { $attributes = !is_array($attributes) ? array('action' => $attributes) : $attributes; // If there is still no action set, Form-post if (!array_key_exists('action', $attributes) or $attributes['action'] === null) { $attributes['action'] = \Uri::main(); } elseif (!strpos($attributes['action'], '://')) { $attributes['action'] = \Uri::create($attributes['action']); } if (empty($attributes['accept-charset'])) { $attributes['accept-charset'] = strtolower(\Fuel::$encoding); } // If method is empty, use POST !empty($attributes['method']) || ($attributes['method'] = \Config::get('form.form_method', 'post')); $form = '<form'; foreach ($attributes as $prop => $value) { $form .= ' ' . $prop . '="' . $value . '"'; } $form .= '>'; // Add hidden fields when given foreach ($hidden as $field => $value) { $form .= PHP_EOL . static::hidden($field, $value); } return $form; }
/** * Tests Html::anchor() * * @test */ public function test_anchor() { // External uri $output = Html::anchor('http://google.com', 'Go to Google'); $expected = '<a href="http://google.com">Go to Google</a>'; $this->assertEquals($expected, $output); $output = Html::anchor('javascript:do();', 'Do()'); $expected = '<a href="javascript:do();">Do()</a>'; $this->assertEquals($expected, $output); $output = Html::anchor('http://google.com', 'Go to Google', array('rel' => 'example', 'class' => 'sample', 'style' => 'color:red;')); $expected = '<a rel="example" class="sample" style="color:red;" href="http://google.com">Go to Google</a>'; $this->assertEquals($expected, $output); // Internal uri $output = Html::anchor('controller/method', 'Method'); $expected = '<a href="' . Uri::create('controller/method') . '">Method</a>'; $this->assertEquals($expected, $output); // Get original values to reset once done $index_file = Config::get('index_file'); $url_suffix = Config::get('url_suffix'); // Query string tests Config::set('url_suffix', ''); Config::set('index_file', ''); $output = Html::anchor('search?q=query', 'Search'); $expected = '<a href="search?q=query">Search</a>'; $this->assertEquals($expected, $output); Config::set('url_suffix', '.html'); $output = Html::anchor('search?q=query', 'Search'); $expected = '<a href="search.html?q=query">Search</a>'; $this->assertEquals($expected, $output); // Reset to original values Config::set('index_file', $index_file); Config::set('url_suffix', $url_suffix); }
/** * Does reverse routing for a named route. This will return the FULL url * (including the base url and index.php). * * WARNING: This is VERY limited at this point. Does not work if there is * any regex in the route. * * Usage: * * <a href="<?php echo Router::get('foo'); ?>">Foo</a> * * @param string $name the name of the route * @param array $named_params the array of named parameters * @return string the full url for the named route */ public static function get($name, $named_params = array()) { if (array_key_exists($name, static::$routes)) { return \Uri::create(static::$routes[$name]->path, $named_params); } }
/** * Sends the instructions to a user's email address. * * @return bool */ private static function _send_instructions($name, Model_User $user) { $config_key = null; switch ($name) { case 'confirmation': $config_key = 'confirmable'; break; case 'reset_password': $config_key = 'recoverable'; break; case 'unlock': $config_key = 'lockable'; break; default: throw new \InvalidArgumentException("Invalid instruction: {$name}"); } $mail = \Email::forge(); $mail->from(\Config::get('email.defaults.from.email'), \Config::get('email.defaults.from.name')); $mail->to($user->email); $mail->subject(__("warden.mailer.subject.{$name}")); $token_name = "{$name}_token"; $mail->html_body(\View::forge("warden/mailer/{$name}_instructions", array('username' => $user->username, 'uri' => \Uri::create(':url/:token', array('url' => rtrim(\Config::get("warden.{$config_key}.url"), '/'), 'token' => $user->{$token_name}))))); $mail->priority(\Email::P_HIGH); try { return $mail->send(); } catch (\EmailSendingFailedException $ex) { logger(\Fuel::L_ERROR, "Warden\\Mailer failed to send {$name} instructions."); return false; } }
public function action_openid_activate($activation_code = null) { $auth = Auth::instance(); $error = false; if ($activation = Input::post('activation')) { // Send the user off to openid provider $auth->request_openid_credentials(Uri::create('auth/openid_activate') . '/' . $activation); $error = true; die('err, not supposed to see this' . $activation); } elseif ($data = $auth->validate_openid_credentials()) { // Try to activate the user if ($auth->activate_user($activation_code, $data['email'], $data['identity'], $data['oauth_token'], $data['oauth_token_secret'])) { // Login if ($auth->login($data['identity'])) { die('logged in!'); } die('You\'re activated!'); } else { var_dump($activation_code); echo '<pre>'; print_r($data); echo '</pre>'; die('failed activation'); } } // Show the form $this->response->body = View::factory('auth/activation', array('error' => $error, 'activation' => Input::post('activation'))); }
/** * Provides the url() functionality. Generates a full url (including * domain and index.php). * * @param string URI to make a full URL for (or name of a named route) * @param array Array of named params for named routes * @return string */ public function url($uri = '', $named_params = array()) { if ($named_uri = \Router::get($uri, $named_params)) { $uri = $named_uri; } return \Uri::create($uri); }
public function action_index() { // clear redirect referrer \Session::delete('submitted_redirect'); // load language \Lang::load('index'); // read flash message for display errors. $form_status = \Session::get_flash('form_status'); if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) { $output['form_status'] = $form_status['form_status']; $output['form_status_message'] = $form_status['form_status_message']; } unset($form_status); // get total accounts $output['total_accounts'] = \Model_Accounts::count(); // <head> output ---------------------------------------------------------------------------------------------- $output['page_title'] = $this->generateTitle(\Lang::get('admin_administrator_dashbord')); // <head> output ---------------------------------------------------------------------------------------------- // breadcrumb ------------------------------------------------------------------------------------------------- $page_breadcrumb = []; $page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')]; $output['page_breadcrumb'] = $page_breadcrumb; unset($page_breadcrumb); // breadcrumb ------------------------------------------------------------------------------------------------- // the admin views or theme should follow this structure. (admin/templates/controller/method) and follow with _v in the end. return $this->generatePage('admin/templates/index/index_v', $output, false); }
public function action_login() { $url_redirect = \Uri::create('system/index/index'); if (\Auth::check()) { \Response::redirect($url_redirect); } if (\Input::is_ajax()) { $val = \Validation::forge('validate_login'); $val->add_field('email', 'Email', 'required|valid_email'); $val->add_field('password', 'Password', 'required'); if ($val->run(array())) { if (\Auth::instance()->login(\Input::param('email'), \Input::param('password'))) { if (\Input::param('remember', false)) { \Auth::remember_me(); } else { \Auth::dont_remember_me(); } $response = array('status' => 'success', 'url' => $url_redirect); } else { $messages = \Auth::get_error(); $response = array('status' => 'error', 'msg' => $messages); } } else { $messages = $val->error_message(); $response = array('status' => 'error', 'msg' => $messages); } return \Response::forge(json_encode($response)); } $this->theme->set_template('login'); $this->theme->get_template()->set('content', \view::forge('default/login', $this->_arrParam)); }
protected function include_client_scripts($scripts = 'default') { if (empty($scripts)) { return; } if (!is_array($scripts)) { $scripts = array($scripts); } foreach ($scripts as $script) { if (empty($this->client_scripts_included[$script])) { switch ($script) { case 'default': $this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"); $this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"); $this->template->css[] = $this->create_css_link("//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css"); $this->template->css[] = $this->create_css_link(Uri::create('assets/css/style.css')); break; case 'jquery_forms': $this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.js"); $this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.min.js"); $this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/additional-methods.min.js"); $this->template->scripts[] = $this->create_js_link("//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"); $this->template->scripts[] = $this->create_js_link(Uri::create('assets/js/jquery-forms-config.js')); array_unshift($this->template->css, $this->create_css_link('//cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.css')); array_unshift($this->template->css, $this->create_css_link("//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css")); break; } $this->client_scripts_included[$script] = true; //don't include the same script more than once } } }
protected function set_twitter($title = '', $tags = [], $url = '') { $title = empty($title) ? Config::get('twitter.title') : $title; $tags = count($tags) == 0 ? Config::get('twitter.tags') : $tags; $twitter = array('title' => $title, 'tags' => implode(',', $tags), 'url' => empty($url) ? Uri::create('/', [], [], false) : $url); $this->template->set_global('twitter', $twitter); }
/** * Returns the customer product option action link. * * @param string $action The action to link to. * * @return string */ public function link($action = '') { $uri = 'customers/' . $this->customer->id . '/products/' . $this->id; if ($action) { $uri .= '/' . $action; } return Uri::create($uri); }
/** * Returns the contact action link. * * @param string $action The base to link to. * @param string $action The action to link to. * * @return string */ public function link($base = '', $action = '') { $uri = $base . '/contacts/' . $this->id; if ($action) { $uri .= '/' . $action; } return Uri::create($uri); }
public static function generate($uri = null, $variables = array(), $get_variables = array(), $secure = null) { $language = Config::get('language'); if (!empty($uri)) { $language .= '/'; } return Uri::create($language . $uri, $variables, $get_variables, $secure); }
/** * Returns the gateway action link. * * @param string $action The action to link to. * * @return string */ public function link($action = '') { $uri = 'settings/gateways/' . $this->id; if ($action) { $uri .= '/' . $action; } return Uri::create($uri); }
/** * Creates an html link * * @param string the url * @param string the text value * @param array the attributes array * @return string the html link */ public static function anchor($href, $text, $attr = array()) { if (!preg_match('#^(\\w+://|javascript:)# i', $href)) { $href = \Uri::create($href); } $attr['href'] = $href; return html_tag('a', $attr, $text); }
/** * Returns the product option action link. * * @param string $action The action to link to. * * @return string */ public function link($action = '') { $uri = 'products/' . $this->product_id . '/options/' . $this->id; if ($action) { $uri .= '/' . $action; } return Uri::create($uri); }
/** inheritdoc */ public static function displayForm($value, &$settings, $model) { // Set up the values for the select $values = array(); if (isset($value) && $value instanceof \Doctrine\Common\Collections\Collection) { foreach ($value as $val) { $values[] = strval($val->get('id')); } } $target_prop = $settings['mapping']['isOwningSide'] === true ? $settings['mapping']['inversedBy'] : $settings['mapping']['mappedBy']; if (empty($target_prop) || is_null($model->id)) { $target_prop = false; } // Set up the values for the template $settings = static::settings($settings); $target_class = $settings['mapping']['targetEntity']; $target_table = \CMF\Admin::getTableForClass($target_class); $options = $target_class::options(\Arr::get($settings, 'filters', array()), array(), null, null, null, is_array($settings['select2']), \Arr::get($settings, 'group_by')); $settings['required'] = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $settings['title'] = $settings['title'] . ($settings['required'] ? ' *' : '') . ($has_errors ? ' - ' . $errors[0] : ''); $settings['cid'] = 'field_' . md5($settings['mapping']['fieldName'] . static::type()); $settings['add_link'] = \Uri::create('/admin/' . $target_table . '/create?_mode=inline&_cid=' . $settings['cid'] . ($target_prop !== false ? '&' . $target_prop . '=' . $model->id : '')); $settings['singular'] = $target_class::singular(); $settings['icon'] = $target_class::icon(); $settings['is_select2'] = false; // Permissions $settings['can_edit'] = \CMF\Auth::can('edit', $target_class); $settings['can_create'] = \CMF\Auth::can('create', $target_class) && $settings['can_edit']; $settings['create'] = $settings['create'] && $settings['can_create']; $settings['edit'] = $settings['edit'] && $settings['can_edit']; if ($settings['transfer'] === true) { $settings['input_attributes']['class'] .= ' input-xxlarge'; $transfer_options = array(); foreach ($options as $key => $value) { $transfer_options[] = array('value' => $key, 'content' => $value); } $content = strval(\View::forge('admin/fields/collection/multiselect.twig', array('settings' => $settings, 'options' => $options, 'values' => $values), false)); return array('content' => $content, 'widget' => $settings['widget'], 'assets' => array('js' => array('/admin/assets/js/bootstrap-transfer.js', '/admin/assets/js/fields/collection/transfer.js'), 'css' => array('/admin/assets/css/bootstrap-transfer.css')), 'js_data' => array('options' => $transfer_options, 'values' => $values, 'edit' => $settings['edit'], 'create' => $settings['create'])); } else { if (is_array($settings['select2'])) { $settings['sortable'] = $settings['select2']['sortable'] = $target_class::sortable() && isset($settings['mapping']['orderBy']) && isset($settings['mapping']['orderBy']['pos']) && $settings['mapping']['orderBy']['pos'] == 'ASC'; $settings['is_select2'] = true; $settings['input_attributes']['class'] .= 'input-xxlarge select2'; $content = strval(\View::forge('admin/fields/collection/multiselect.twig', array('settings' => $settings, 'options' => $options, 'values' => $values), false)); $settings['select2']['placeholder'] = 'click to select a ' . strtolower($settings['singular']) . '...'; $settings['select2']['target_table'] = $target_table; // Permissions $settings['select2']['create'] = $settings['create']; $settings['select2']['edit'] = $settings['edit']; return array('content' => $content, 'widget' => $settings['widget'], 'assets' => array('css' => array('/admin/assets/select2/select2.css'), 'js' => array('/admin/assets/select2/select2.min.js', '/admin/assets/js/fields/select2.js')), 'js_data' => $settings['select2']); } } $settings['input_attributes']['class'] .= ' input-xxlarge'; return array('content' => strval(\View::forge('admin/fields/collection/multiselect.twig', array('settings' => $settings, 'options' => $options, 'values' => $values), false)), 'assets' => array('js' => array('/admin/assets/js/fields/collection/multiselect.js')), 'widget' => false); return; }
/** * Tests Uri::create() * * @test */ public function test_create() { $output = Uri::create('controller/method'); $expected = "index.php/controller/method"; $this->assertEquals($expected, $output); $output = Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and')); $expected = "index.php/controller/thing?what=more"; $this->assertEquals($expected, $output); }
/** * Creates an html image tag * * Sets the alt atribute to filename of it is not supplied. * * @param string the source * @param array the attributes array * @return string the image tag */ public static function img($src, $attr = array()) { if (!preg_match('#^(\\w+://)# i', $src)) { $src = \Uri::create($src); } $attr['src'] = $src; $attr['alt'] = isset($attr['alt']) ? $attr['alt'] : pathinfo($src, PATHINFO_FILENAME); return html_tag('img', $attr); }
/** * get root site url * it is up to configuration with {lang} in url or not. if there is no {lang} in url, the root web may contain // at the end. * * @return string */ function getRootSiteURL() { $root_url = \Uri::create('/'); if (mb_substr($root_url, -2) == '//') { // this case is http://domain/fuelstart// return mb_substr($root_url, 0, -1); } // this case is http://domain/th/fuelstart/ return $root_url; }
public function authenticate() { // Load the provider $provider = \OAuth2\Provider::forge($this->provider, $this->config); // Grab a callback from the config if ($provider->callback === null) { $provider->callback = \Uri::create(\Config::get('ninjauth.urls.callback', \Request::active()->route->segments[0] . '/callback') . '/' . $this->provider); } $provider->authorize(array('redirect_uri' => $provider->callback)); }
public function action_send_verification_email($id, $mailaddress, $key) { $email = Email::forge(); $email->from('*****@*****.**', 'Eventual system'); $email->to($mailaddress, "Eventual system user"); $email->subject('Your registration in Eventual'); $mail_text = "'Thank you for registering at eventual.org'\n\t\t Please, verify your address by clicking this link: " . Uri::create("account/verify/" . $id . "/" . $key . "/"); $email->body($mail_text); $email->send(); }
public function __construct() { parent::__construct(); // validate admin logged in if (\Model_Accounts::isAdminLogin() == false) { \Response::redirect(\Uri::create('admin/login') . '?rdr=' . urlencode(\Uri::main())); } // load global admin language \Lang::load('admin'); }
/** * Creates an html link * * @param string the url * @param string the text value * @param array the attributes array * @return string the html link */ public static function anchor($href, $text, $attributes = array()) { if ( ! preg_match('#^\w+://# i', $href)) { $href = \Uri::create($href); } $attributes['href'] = $href; return html_tag('a', $attributes, $text); }
/** inheritdoc */ public static function displayForm($value, &$settings, $model) { $id = isset($value) ? $value->id : ''; $settings = static::settings($settings); $settings['cid'] = 'field_' . md5($settings['mapping']['fieldName'] . static::type()); $required = isset($settings['required']) ? $settings['required'] : false; $include_label = isset($settings['label']) ? $settings['label'] : true; $target_class = $settings['mapping']['targetEntity']; $target_table = \CMF\Admin::getTableForClass($target_class); $target_prop = $settings['mapping']['isOwningSide'] === true ? $settings['mapping']['inversedBy'] : $settings['mapping']['mappedBy']; if (empty($target_prop) || is_null($model->id)) { $target_prop = false; } $add_link = \Uri::create('/admin/' . $target_table . '/create?_mode=inline&_cid=' . $settings['cid'] . ($target_prop !== false ? '&' . $target_prop . '=' . $model->id : '')); $options = $target_class::options(\Arr::get($settings, 'filters', array()), array(), null, null, null, is_array($settings['select2']), \Arr::get($settings, 'group_by')); $has_controls = $settings['create'] !== false; // Description? $description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : ''; if ($settings['allow_empty']) { $options = array('' => '') + $options; } $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $input_attributes = $settings['input_attributes']; $label = !$include_label ? '' : \Form::label($settings['title'] . ($required ? ' *' : '') . ($has_errors ? ' - ' . $errors[0] : ''), $settings['mapping']['fieldName'], array('class' => 'item-label')); $add_link = html_tag('a', array('href' => $add_link, 'class' => 'btn btn-mini btn-create'), '<i class="fa fa-plus"></i> create ' . strtolower($target_class::singular())); // Permissions $settings['can_edit'] = \CMF\Auth::can('edit', $target_class); $settings['can_create'] = \CMF\Auth::can('create', $target_class) && $settings['can_edit']; $settings['create'] = $settings['create'] && $settings['can_create']; $settings['edit'] = $settings['edit'] && $settings['can_edit']; if ($settings['create'] === false) { $add_link = " "; } $controls_top = html_tag('div', array('class' => 'controls-top'), $add_link); if (is_array($settings['select2'])) { $input_attributes['class'] .= 'input-xxlarge select2'; $input = \Form::select($settings['mapping']['fieldName'], $id, $options, $input_attributes); $settings['select2']['placeholder'] = 'click to select ' . strtolower($target_class::singular()) . '...'; $settings['select2']['target_table'] = $target_table; // Permissions $settings['select2']['create'] = $settings['create']; $settings['select2']['edit'] = $settings['edit']; if (!$required) { $settings['select2']['allowClear'] = true; } return array('content' => html_tag('div', array('class' => 'controls control-group' . ($has_controls ? ' field-with-controls' : '') . ($has_errors ? ' error' : ''), 'id' => $settings['cid']), $label . $description . $input . $controls_top) . '<div class="clear"><!-- --></div>', 'widget' => false, 'assets' => array('css' => array('/admin/assets/select2/select2.css'), 'js' => array('/admin/assets/select2/select2.min.js', '/admin/assets/js/fields/select2.js')), 'js_data' => $settings['select2']); } $input_attributes['class'] .= ' input-xxlarge'; $input = \Form::select($settings['mapping']['fieldName'], $id, $options, $input_attributes); if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } return html_tag('div', array('class' => 'controls control-group' . ($has_controls ? ' field-with-controls' : '') . ($has_errors ? ' error' : ''), 'id' => $settings['cid']), $label . $description . $input . $controls_top) . '<div class="clear"><!-- --></div>'; }