public function html() { $this->_view->set_var('tag', 'form'); !$this->_view->attr('action') and URL::site(Request::current()->detect_uri()); !$this->_view->attr('method') and $this->_view->attr('method', 'post'); !$this->_view->attr('action') and $this->_view->attr('action', ''); }
public function before() { parent::before(); $this->assign('seoinfo', Common::getChannelSeo(3)); $this->assign('cmsurl', URL::site()); $this->assign('website', Common::getWebUrl()); }
public function action_login() { // Проверям, вдруг пользователь уже зашел if (Auth::instance()->logged_in()) { // И если это так, то отправляем его сразу на страницу администратора return $this->request->redirect('member'); } // Если же пользователь не зашел, но данные на страницу пришли, то: if ($_POST) { // Создаем переменную, отвечающую за связь с моделью данных User $user = ORM::factory('user'); // в $status помещаем результат функции login $status = Auth::instance()->login($_POST['username'], $_POST['password']); // Если логин успешен, то if ($status) { // Отправляем пользователя на его страницу $this->request->redirect('member'); } else { // Иначе ничего не получилось, пишем failed $this->template->messages['err_msg'] = 'Ошибка входа!'; } } // Грузим view логина $this->template->content = View::factory(URL::site('login')); }
public function pay($data, $clientEmail) { if (is_array($data)) { $this->_setDataFromArray($data); } else { if (is_object($data)) { $this->_setDataFromObject($data); } } $this->_dataRequired['id'] = $this->_dotpayID; $this->_dataOptional['email'] = $clientEmail; if (empty($this->_dataOptional['URL'])) { $this->_dataOptional['URL'] = URL::site($this->returnAction(), TRUE); } foreach ($this->_dataRequired as $field) { if (empty($field)) { return FALSE; } } $fields = array_merge($this->_dataRequired, $this->_dataOptional); $hidden = array(); foreach ($fields as $key => $value) { if (!empty($value)) { $hidden[$key] = $value; } } $view = View::factory('dotpay/pay')->set('amount', $this->_amountFormat($this->_dataRequired['amount']))->set('description', $this->_dataRequired['description'])->set('control', $this->_dataRequired['control'])->set('paymentURL', self::PAYMENT_URL)->bind('hidden', $hidden); if ($this->_config->selectChannel) { $view->set('paymentChannels', $this->_config->channels); } return $view; }
/** * Get list of pages * * @uses Config::load * @uses Config_Group::get * @uses URL::site * @uses Cache::set */ public function action_list() { if (empty($this->_items)) { $config = Config::load('page'); // Cache is Empty so Re-Cache $pages = ORM::factory('page')->where('status', '=', 'publish')->order_by('pubdate', 'DESC')->limit($this->_limit)->offset($this->_offset)->find_all(); $items = array(); foreach ($pages as $page) { $item = array(); $item['guid'] = $page->id; $item['title'] = $page->title; $item['link'] = URL::site($page->url, TRUE); if ($config->get('use_submitted', FALSE)) { $item['author'] = $page->user->nick; } $item['description'] = $page->teaser; $item['pubDate'] = $page->pubdate; $items[] = $item; } $this->_cache->set($this->_cache_key, $items, $this->_ttl); $this->_items = $items; } if (isset($this->_items[0])) { $this->_info['title'] = __('Pages - Recent updates'); $this->_info['link'] = Route::url('rss', array('controller' => 'page'), TRUE); $this->_info['pubDate'] = $this->_items[0]['pubDate']; } }
/** * 添加保存 */ public function action_save() { $this->_autoRender = FALSE; $name = Arr::get($_POST, 'name', ''); $describe = Arr::get($_POST, 'describe', ''); if (!$name) { return Prompt::jsonWarning('名称不能为空'); } if (!$describe) { return Prompt::jsonWarning('描述不能为空'); } $values = array('name' => $name, 'describe' => $describe, 'account_id' => 0); try { $result = Model::factory('Project')->create($values)->getArray(); if (!$result) { //TODO 日志 return Prompt::jsonError('添加项目失败'); } } catch (Exception $e) { //TODO 日志 return Prompt::jsonError('添加项目失败'); } //TODO 日志 return Prompt::jsonSuccess('添加项目成功', URL::site('project/add')); }
/** * Action login */ public function action_login() { $post = $this->request->post(); $username = Arr::get($post, 'username'); $password = Arr::get($post, 'password'); $remember = Arr::get($post, 'remember') ?: 0; // If there is post login if ($this->request->post('login')) { // ログインチェック if (Auth::instance()->login($username, $password, $remember)) { // ロールチェック if (Auth::instance()->logged_in('direct') or Auth::instance()->logged_in('admin') or Auth::instance()->logged_in('edit')) { // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('auth', 'login_success'), array(':user' => $username)); // Redirect to home $this->redirect(URL::site($this->settings->backend_name, 'http')); } else { // Add error notice Notice::add(Notice::ERROR, Kohana::message('auth', 'login_refusal'), NULL, Kohana::message('auth', 'login_refusal_messages')); } } else { // Add error notice Notice::add(Notice::ERROR, Kohana::message('auth', 'login_failed'), NULL, Kohana::message('auth', 'login_failed_messages')); } } /** * View */ // Get content $content_file = Tpl::get_file('login', $this->settings->back_tpl_dir . '/auth'); $this->content = Tpl::factory($content_file)->set('post', $post); }
function walkTree($nodes, $level = 0) { static $i = 1; foreach ($nodes as $key => $value) { if ($value['start'] == 1) { echo '<tr> <td>' . $i . '</td> <td>' . $value['display_name'] . '</td> <td>' . $value['dir'] . '</td> <td>' . $value['date_create'] . '</td> <td> <a href="' . URL::site(Request::current()->param('language') . '/admin/folders/edit/' . $value['id']) . '">Edit</a> | <a href="' . URL::site(Request::current()->param('language') . '/admin/folders/delete/' . $value['id']) . '">Delete</a> </td> </tr>' . "\n"; } else { echo '<tr> <td>' . $i . '</td> <td>' . str_repeat('---', $level) . $value['display_name'] . '</td> <td>' . $value['dir'] . '</td> <td>' . $value['date_create'] . '</td> <td> <a href="' . URL::site(Request::current()->param('language') . '/admin/folders/edit/' . $value['id']) . '">Edit</a> | <a href="' . URL::site(Request::current()->param('language') . '/admin/folders/delete/' . $value['id']) . '">Delete</a> </td> </tr>' . "\n"; } $i++; if ($value['children']) { walkTree($value['children'], $level + 1); } } }
public function action_permissions() { $view = View::factory('role/permissions')->bind('acl', $acl)->set('action', URL::site('role/permissions'))->bind('role_id', $role_id)->bind('is_current_role', $is_current_role)->bind('role_name', $role_name)->set('cancel', URL::site('role')); $post = array(); if ($this->request->method() === 'POST' && $this->request->post()) { $post = $this->request->post(); $role_id = $post['role_id']; $role = ORM::factory('role', $role_id); $role->permissions = serialize($post['acl']); $role->save(); Session::instance()->set('success', 'User permissions saved successfully.'); Request::current()->redirect('role/index'); } $role_id = $this->request->param('params'); $role = ORM::factory('role', $role_id); $role_name = $role->name; $permissions = $role->permissions && $role->permissions !== NULL ? unserialize($role->permissions) : array(); $acl_array = Acl::acl_array($permissions); ${$acl} = array(); foreach ($acl_array as $resource => $levels) { $acl[$resource] = array(); $text_resource = Kohana::message('acl', $resource); foreach ($levels as $level => $permission) { $acl[$resource][$level] = array('resource' => $text_resource, 'level' => Inflector::humanize($level), 'permission' => $permission, 'repr_key' => Acl::repr_key($resource, $level)); } } // check whether the role being edited is the role of the current user // if yes, show a warning before user tries to deny all permissions $user_role_id = Auth::instance()->get_user()->roles->find()->id; $is_current_role = $role_id == $user_role_id; Breadcrumbs::add(array('Role', Url::site('role'))); Breadcrumbs::add(array('Set Permission', Url::site('role/permissions/' . $role_id))); $this->content = $view; }
/** * Returns a string with a backend url string based on arguments * * @param string $controller * @param string $action * @param mixed $id * @return string */ public static function backend($controller = null, $action = null, $id = null) { if (!is_array($controller)) { $controller = array('controller' => $controller, 'action' => $action, 'id' => $id); } return URL::site(Route::get('backend')->uri($controller)); }
public function getUrl($id, $typeid) { $cmsUrl = URL::site(); $url = ''; switch ($typeid) { case 1: $url = $cmsUrl . 'lines/show/id/' . $id; break; case 2: $url = $cmsUrl . 'hotels/show/id/' . $id; break; case 3: $url = $cmsUrl . 'cars/show/id/' . $id; break; case 4: $url = $cmsUrl . 'raider/show/id/' . $id; break; case 5: $url = $cmsUrl . 'spot/show/id/' . $id; break; case 6: $url = $cmsUrl . 'photo/show/id/' . $id; break; case 8: $url = $cmsUrl . 'visa/show/id/' . $id; break; case 13: $url = $cmsUrl . 'tuan/show/id/' . $id; break; } return $url; }
/** * Get the URL to redirect to. * @return string */ public function redirect_url($return_url) { $this->provider->identity = Provider_OpenID::$config[$this->provider_name]['url']; $this->provider->returnUrl = URL::site($return_url, true); $this->provider->required = array('namePerson', 'namePerson/first', 'namePerson/last', 'contact/email'); return $this->provider->authUrl(); }
function walkTree($nodes, $level = 0) { static $i = 1; foreach ($nodes as $key => $value) { if ($value['start'] == 1) { echo '<tr> <td>' . $i . '</td> <td>' . $value['name'] . '</td> <td>' . $value['u_name'] . ' ' . $value['u_surname'] . '</td> <td>' . $value['create_date'] . '</td> <td> <a href="' . URL::site(Request::current()->param('language') . '/admin/categories/edit/' . $value['id']) . '">' . __('EDIT') . '</a> | <a href="' . URL::site(Request::current()->param('language') . '/admin/categories/delete/' . $value['id']) . '">' . __('DELETE') . '</a> </td> </tr>' . "\n"; } else { echo '<tr> <td>' . $i . '</td> <td>' . str_repeat('---', $level) . $value['name'] . '</td> <td>' . $value['u_name'] . ' ' . $value['u_surname'] . '</td> <td>' . $value['create_date'] . '</td> <td> <a href="' . URL::site(Request::current()->param('language') . '/admin/categories/edit/' . $value['id']) . '">' . __('EDIT') . '</a> | <a href="' . URL::site(Request::current()->param('language') . '/admin/categories/delete/' . $value['id']) . '">' . __('DELETE') . '</a> </td> </tr>' . "\n"; } $i++; if ($value['children']) { walkTree($value['children'], $level + 1); } } }
public function before() { $this->ttl = 3600; $template = $this->template; $this->template = NULL; parent::before(); if ($this->auto_render === TRUE) { $this->template = View_Theme::factory($template); } $this->config = Kohana::$config->load($this->config)->as_array(); $this->assets = '/assets/' . $this->config['theme'] . '/'; $this->template->page = URL::site(rawurldecode(Request::$initial->uri())); $this->template->code = $this->request->action(); $this->template->message = ''; // Internal request only! if (Request::$initial !== Request::$current) { // Скрываем, т.к. выводится лишняя информация // if ($message = rawurldecode( $this->request->param('message') )) // { // $this->template->message = $message; // } } else { $this->request->action(404); } if ($this->request->initial()->is_ajax() === TRUE) { $this->response->status((int) $this->request->action()); $this->response->body(isset($message) ? $message : 'Page not found'); } }
/** * Generates an opening HTML form tag. * * // Form will submit back to the current page using POST * echo Form::open(); * * // Form will submit to 'search' using GET * echo Form::open('search', array('method' => 'get')); * * // When "file" inputs are present, you must include the "enctype" * echo Form::open(NULL, array('enctype' => 'multipart/form-data')); * * @param mixed form action, defaults to the current request URI, or [Request] class to use * @param array html attributes * @return string * @uses Request::instance * @uses URL::site * @uses HTML::attributes */ public static function open($action = NULL, array $attributes = NULL) { if ($action instanceof Request) { // Use the current URI $action = $action->uri(); } if (!$action) { // Allow empty form actions (submits back to the current url). $action = ''; } elseif (strpos($action, '://') === FALSE) { // Make the URI absolute $action = URL::site($action); } // Add the form action to the attributes $attributes['action'] = $action; // Only accept the default character set $attributes['accept-charset'] = Kohana::$charset; if (!isset($attributes['method'])) { // Use POST method $attributes['method'] = 'post'; } // Only render the CSRF field when the POST method is used $hidden_csrf_field = $attributes['method'] == 'post' ? self::hidden('form_auth_id', CSRF::token()) : ''; return '<form' . HTML::attributes($attributes) . '>' . $hidden_csrf_field; }
public function on_page_load() { $email_ctx_id = $this->get('email_id_ctx', 'email'); $email = $this->_ctx->get($email_ctx_id); $referrer_page = Request::current()->referrer(); $next_page = $this->get('next_url', Request::current()->referrer()); if (!Valid::email($email)) { Messages::errors(__('Use a valid e-mail address.')); HTTP::redirect($referrer_page); } $user = ORM::factory('user', array('email' => $email)); if (!$user->loaded()) { Messages::errors(__('No user found!')); HTTP::redirect($referrer_page); } $reflink = ORM::factory('user_reflink')->generate($user, 'forgot', array('next_url' => URL::site($this->next_url, TRUE))); if (!$reflink) { Messages::errors(__('Reflink generate error')); HTTP::redirect($referrer_page); } Observer::notify('admin_login_forgot_before', $user); try { Email_Type::get('user_request_password')->send(array('username' => $user->username, 'email' => $user->email, 'reflink' => Route::url('reflink', array('code' => $reflink)), 'code' => $reflink)); Messages::success(__('Email with reflink send to address set in your profile')); } catch (Exception $e) { Messages::error(__('Something went wrong')); } HTTP::redirect($next_page); }
/** * Constructs a new model and loads a record if given * * @param mixed $id Parameter for find or object to load [Optional] */ public function __construct($id = NULL) { // Set primary image defaults $this->_image_path = APPPATH . 'media/posts/'; $this->_image_url = trim(URL::site('media/posts'), '/') . '/'; parent::__construct($id); }
public function action_vars() { $this->response->headers('Content-Type', 'application/javascript; charset=utf-8'); echo 'url = "' . URL::site('/', true) . '";'; echo 'ajaxurl = "' . URL::site('ajax/', true) . '";'; echo 'cronurl = "' . URL::site('cron/', true) . '";'; }
/** * @return mixed */ public function send($to, $message, $title = "") { // Always try to send emails! // if (!$this->_is_provider_available()) { // Kohana::$log->add(Log::ERROR, 'The email data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.'); // return array(Message_Status::FAILED, FALSE); // } $provider_options = $this->options(); $driver = $provider_options['outgoing_type']; $options = array('hostname' => $provider_options['outgoing_server'], 'port' => $provider_options['outgoing_port'], 'encryption' => $provider_options['outgoing_security'] != 'none' ? $provider_options['outgoing_security'] : '', 'username' => $provider_options['outgoing_username'], 'password' => $provider_options['outgoing_password']); $config = Kohana::$config->load('email'); $config->set('driver', $driver); $config->set('options', $options); $tracking_id = self::tracking_id('email'); $body = View::factory('email/layout'); $body->message = $message; $body->tracking_id = $tracking_id; $body->site_url = rtrim(URL::site(), '/'); $from = $this->from(); if (!$from) { $from = Kohana::$config->load('site.email') ?: '*****@*****.**'; } $from_name = !empty($provider_options['from_name']) ? $provider_options['from_name'] : $from; try { $result = Email::factory($title, $body->render(), 'text/html')->to($to)->from($from, $from_name)->send(); return array(Message_Status::SENT, $tracking_id); } catch (Exception $e) { Kohana::$log->add(Log::ERROR, $e->getMessage()); // Failed return array(Message_Status::FAILED, FALSE); } }
/** * Create HTML link anchors. Note that the title is not escaped, to allow * HTML elements within links (images, etc). * * @param string URL or URI string * @param string link text * @param array HTML anchor attributes * @param string use a specific protocol * @return string */ public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL) { if ($title === NULL) { // Use the URI as the title $title = $uri; } // Translate the title $title = __($title); if ($uri === '') { // Only use the base URL $uri = URL::base(FALSE, $protocol); } else { if (strpos($uri, '://') !== FALSE) { if (HTML::$windowed_urls === TRUE and empty($attributes['target'])) { // Make the link open in a new window $attributes['target'] = '_blank'; } } elseif ($uri[0] !== '#') { // Make the URI absolute for non-id anchors $uri = URL::site($uri, $protocol); } } // Add the sanitized link to the attributes $attributes['href'] = $uri; return '<a' . HTML::attributes($attributes) . '>' . $title . '</a>'; }
/** * Generates an opening HTML form tag. * * // Form will submit back to the current page using POST * echo Form::open(); * * // Form will submit to 'search' using GET * echo Form::open('search', array('method' => 'get')); * * // When "file" inputs are present, you must include the "enctype" * echo Form::open(NULL, array('enctype' => 'multipart/form-data')); * * @param string form action, defaults to the current request URI * @param array html attributes * @return string * @uses Request::instance * @uses URL::site * @uses HTML::attributes */ public static function open($action = NULL, array $attributes = NULL) { if ($action === NULL) { // Use the current URI $action = Request::current()->uri; } if ($action === '') { // Use only the base URI $action = Kohana::$base_url; } elseif (strpos($action, '://') === FALSE) { // Make the URI absolute $action = URL::site($action); } // Add the form action to the attributes $attributes['action'] = $action; // Only accept the default character set $attributes['accept-charset'] = Kohana::$charset; if ( ! isset($attributes['method'])) { // Use POST method $attributes['method'] = 'post'; } return '<form'.HTML::attributes($attributes).'>'; }
public function pay($data, $clientEmail) { if (is_array($data)) { $this->_setDataFromArray($data); } else { if (is_object($data)) { $this->_setDataFromObject($data); } } $this->_dataRequired['id'] = $this->_id; $this->_dataOptional['email'] = $clientEmail; if (empty($this->_dataOptional['pow_url'])) { $this->_dataOptional['pow_url'] = URL::site($this->returnAction(), TRUE); } if (empty($this->_dataOptional['wyn_url'])) { $this->_dataOptional['wyn_url'] = URL::site($this->incomingAction(), TRUE); } if (empty($this->_dataOptional['jezyk'])) { $this->_dataOptional['jezyk'] = $this->_lang; } foreach ($this->_dataRequired as $field) { if (empty($field)) { return FALSE; } } $fields = array_merge($this->_dataRequired, $this->_dataOptional); $hidden = array(); foreach ($fields as $key => $value) { if (!empty($value) || !is_null($value)) { $hidden[$key] = $value; } } $view = View::factory('transferuj/pay')->set('kwota', $this->_amountFormat($this->_dataRequired['kwota']))->set('nazwa', $this->_dataOptional['nazwa'])->set('opis', $this->_dataRequired['opis'])->set('crc', $this->_dataRequired['crc'])->set('paymentURL', self::PAYMENT_URL)->bind('hidden', $hidden); return $view; }
public function before() { if ($this->request->action === 'media') { // Do not template media files $this->auto_render = FALSE; } else { // Grab the necessary routes $this->media = Route::get('docs/media'); $this->api = Route::get('docs/api'); $this->guide = Route::get('docs/guide'); if (isset($_GET['lang'])) { $lang = $_GET['lang']; // Load the accepted language list $translations = array_keys(Kohana::message('userguide', 'translations')); if (in_array($lang, $translations)) { // Set the language cookie Cookie::set('userguide_language', $lang, Date::YEAR); } // Reload the page $this->request->redirect($this->request->uri); } // Set the translation language I18n::$lang = Cookie::get('userguide_language', Kohana::config('userguide')->lang); // Use customized Markdown parser define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown'); // Load Markdown support require Kohana::find_file('vendor', 'markdown/markdown'); // Set the base URL for links and images Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/'; Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/'; } parent::before(); }
public function __invoke($entities) { if (!is_array($entities)) { throw new FormatterException('Collection formatter requries an array of entities'); } $output = ['type' => 'FeatureCollection', 'features' => []]; foreach ($entities as $entity) { $geometries = []; foreach ($entity->values as $attribute => $values) { foreach ($values as $value) { if ($geometry = $this->valueToGeometry($value)) { $geometries[] = $geometry; } } } if (!empty($geometries)) { $output['features'][] = ['type' => 'Feature', 'geometry' => ['type' => 'GeometryCollection', 'geometries' => $geometries], 'properties' => ['title' => $entity->title, 'description' => $entity->content, 'id' => $entity->id, 'url' => URL::site(Ushahidi_Rest::url($entity->getResource(), $entity->id), Request::current())]]; } } if ($this->search->bbox) { if (is_array($this->search->bbox)) { $bbox = $this->search->bbox; } else { $bbox = explode(',', $this->search->bbox); } $output['bbox'] = $bbox; } return $output; }
public function action_index($supplychain_id) { if (!is_numeric($supplychain_id)) { $supplychain_id = $this->_match_alias($supplychain_id); } $supplychain = ORM::factory('supplychain', $supplychain_id); $sc = $supplychain->kitchen_sink($supplychain_id); if ($supplychain->loaded()) { $current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0; $owner_id = (int) $supplychain->user_id; if ($supplychain->user_can($current_user_id, Sourcemap::READ)) { $this->layout->supplychain_id = $supplychain_id; // pass supplychain metadeta to template $this->template->supplychain_id = $supplychain_id; $this->template->supplychain_date = date('F j, Y', $sc->created); $this->template->supplychain_name = isset($sc->attributes->name) ? $sc->attributes->name : ""; $this->template->supplychain_owner = isset($sc->owner->name) ? $sc->owner->name : ""; $this->template->supplychain_ownerid = isset($sc->owner->id) ? $sc->owner->id : ""; $this->template->supplychain_avatar = isset($sc->owner->avatar) ? $sc->owner->avatar : ""; $this->template->supplychain_desc = isset($sc->attributes->description) ? $sc->attributes->description : ""; $this->layout->scripts = array('blog-view'); $this->layout->styles = array('sites/default/assets/styles/reset.css', 'assets/styles/base.less', 'assets/styles/general.less'); // qrcode url $qrcode_query = URL::query(array('q' => URL::site('view/' . $supplychain->id, true), 'sz' => 8)); $this->template->qrcode_url = URL::site('services/qrencode', true) . $qrcode_query; } else { Message::instance()->set('That map is private.'); $this->request->redirect('browse'); } } else { Message::instance()->set('That map could not be found.'); $this->request->redirect('browse'); } }
public function action_index() { header('Access-Control-Allow-Origin: *'); $search = Security::xss_clean(isset($_GET['search']) ? $_GET['search'] : ''); if (!empty($search)) { $query_b = '%' . $search . '%'; $this->searchText = Database::instance()->escape($search); $query_a = DB::expr(' AGAINST(' . $this->searchText . ') '); $list = ORM::factory('Publication')->distinct('true')->where(DB::expr('MATCH(title_' . $this->language . ')'), '', $query_a)->or_where(DB::expr('MATCH(desc_' . $this->language . ')'), '', $query_a)->or_where(DB::expr('MATCH(text_' . $this->language . ')'), '', $query_a)->or_where('title_' . $this->language, 'like', $query_b)->and_where('published', '=', 1)->limit($this->limit)->offset($this->offset)->find_all(); } else { $list = ORM::factory('Publication')->where('title_' . $this->language, '<>', '')->where('published', '=', 1)->order_by('order', 'DESC'); $this->data['page_count'] = Paginate::factory($list)->paginate(NULL, NULL, 10)->page_count(); $list = $list->find_all(); } $pub = array(); $this->data['search'] = $search; foreach ($list as $k => $v) { $pub['id'] = $v->id; $pub['url'] = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $this->language . URL::site('api/smartpublications/view/' . $v->id); $pub['title'] = $v->title; $pub['desc'] = strip_tags($v->desc); $pub['image'] = 'http://' . $_SERVER['HTTP_HOST'] . URL::media('/images/w205-h160/' . $v->picture->file_path); $this->data['publications'][] = $pub; } $this->response->body(json_encode($this->data)); }
/** * 保存账号 */ public function action_save() { $this->_autoRender = FALSE; $givenName = Arr::get($_POST, 'given_name', ''); $name = Arr::get($_POST, 'name', ''); $password = Arr::get($_POST, 'password', ''); $email = Arr::get($_POST, 'email', ''); $mobile = Arr::get($_POST, 'mobile', ''); $phone = Arr::get($_POST, 'phone', ''); if ($givenName == '') { return Prompt::jsonWarning('姓名不能为空'); } if ($name == '') { return Prompt::jsonWarning('用户名不能为空'); } if ($password == '') { return Prompt::jsonWarning('密码不能为空'); } if ($email == '') { return Prompt::jsonWarning('邮箱不能为空'); } $values = array('given_name' => $givenName, 'name' => $name, 'password' => md5($password), 'email' => $email, 'mobile' => $mobile, 'phone' => $phone); try { $result = Model::factory('Account')->create($values)->getArray(); if (!$result[0]) { //TODO 日志 return Prompt::jsonError('添加账号失败'); } } catch (Exception $e) { //TODO 日志 return Prompt::jsonError('添加账号失败'); } //TODO 日志 return Prompt::jsonSuccess('添加账号成功', URL::site('account/add')); }
public function before() { parent::before(); $action = $this->request->action(); if ($action == 'index') { $param = $this->params['action']; $right = array('read' => 'slook', 'save' => 'smodify', 'delete' => 'sdelete', 'update' => 'smodify'); $user_action = $right[$param]; if (!empty($user_action)) { Common::getUserRight('advertise', $user_action); } } if ($action == 'add') { Common::getUserRight('advertise', 'sadd'); } if ($action == 'edit') { Common::getUserRight('advertise', 'smodify'); } if ($action == 'ajax_save') { Common::getUserRight('advertise', 'smodify'); } $this->assign('cmsurl', URL::site()); $this->assign('parentkey', $this->params['parentkey']); $this->assign('itemid', $this->params['itemid']); $this->assign('weblist', Common::getWebList()); }
public function action_get_index_collection() { // Get the post query $posts_query = $this->_build_query(); // Get the count of ALL records $count_query = clone $posts_query; $total_records = (int) $count_query->select(array(DB::expr('COUNT(DISTINCT `post`.`id`)'), 'records_found'))->limit(NULL)->offset(NULL)->find_all()->get('records_found'); // Fetch posts from db $posts = $posts_query->find_all(); // Get query count $post_query_sql = $posts_query->last_query(); // Generate filename using hashed query params and ids $filename = 'export-' . hash('sha256', implode('-', $this->request->query()) . '~' . '-' . $this->request->param('id')) . '.csv'; // Get existing tsv file $tsv_file = Kohana::$config->load('media.media_upload_dir') . $filename; // Only generate a new if the file doesn't exist if (!file_exists($tsv_file)) { // Supported headers for the TSV file $tsv_headers = array("ID", "PARENT", "USER", "FORM", "TITLE", "CONTENT", "TYPE", "STATUS", "SLUG", "LOCALE", "CREATED", "UPDATED", "TAGS", "SETS"); // Generate tab separated values (tsv) $tsv_text = $this->_generate_tsv($tsv_headers, $posts); // Write tsv to file $this->_write_tsv_to_file($tsv_text, $filename); } // Relative path $relative_path = str_replace(APPPATH . 'media' . DIRECTORY_SEPARATOR, '', Kohana::$config->load('media.media_upload_dir')); // Build download link $download_link = URL::site(Media::uri($relative_path . $filename), Request::current()); // Respond with download link and record count $this->_response_payload = array('total_count' => $total_records, 'link' => $download_link); }
public function action_index() { header('Access-Control-Allow-Origin: *'); $category = (int) $this->request->param('id', 0); //SEO. закрываем сортировку if ($category != 0) { $sort = 1; Kotwig_View::set_global('sort', $sort); } //end_SEO $categories = ORM::factory('Photosets_Category')->find_all(); foreach ($categories as $c) { $this->data['categories'][] = array('id' => $c->id, 'name' => $c->name); } $this->data['category'] = $category; $photosets = ORM::factory('Photoset')->where('published', '=', 1)->where('show_' . $this->language, '=', 1)->order_by('order', 'asc'); if ($category != 0) { $photosets = $photosets->where('category_id', '=', $category); } $photosets = $photosets->order_by('order', 'ASC'); $paginate = Paginate::factory($photosets)->paginate(NULL, NULL, 12)->page_count(); $photosets = $photosets->find_all(); if (count($photosets) < 1) { $this->data['error'] = 'Error photo'; } $this->data['pagecount'] = $paginate; foreach ($photosets as $p) { $img = $p->isCover() ? 'http://' . $_SERVER['HTTP_HOST'] . URL::media('images/w300-h225-ccc-si/' . $p->pathCover()) : 'http://' . $_SERVER['HTTP_HOST'] . URL::media('images/w300-h225-ccc-si/media/images/nocover.jpg'); $this->data['photosets'][] = array('url' => 'http://' . $_SERVER['HTTP_HOST'] . '/' . $this->language . URL::site('api/smartphoto/view/' . $p->id), 'image' => $img, 'name' => $p->name(), 'category' => $p->category->name); } $this->response->body(json_encode($this->data)); }