Esempio n. 1
0
 /**
  * Get full url including query string if exist.
  *
  * @return string
  */
 public function getFullUrl()
 {
     if (null !== ($queryString = $this->queryString)) {
         $queryString = '?' . $queryString;
     }
     return $this->getBaseUrl() . $this->uri->getPathInfo() . $queryString;
 }
Esempio n. 2
0
 /**
  * Parses the string and returns the {@link Uri}.
  * 
  * Parses the string and returns the {@link Uri}. If parsing fails, null is returned.
  * 
  * @param String $string The url.
  * 
  * @return \Bumble\Uri\Uri The Uri object.
  */
 public function parse($string)
 {
     $data = parse_url($string);
     //helper function gets $a[$k], checks if exists
     function get($a, $k)
     {
         if (array_key_exists($k, $a)) {
             return empty($a[$k]) ? null : $a[$k];
         }
         return null;
     }
     if ($data === null) {
         return null;
     }
     $uri = new Uri();
     $uri->setProtocol(get($data, 'scheme'));
     $uri->setUsername(get($data, 'user'));
     $uri->setPassword(get($data, 'pass'));
     $uri->setHost(get($data, 'host'));
     $uri->setPort(get($data, 'port'));
     $uri->setPath(get($data, 'path'));
     $uri->setQuery(get($data, 'query'));
     $uri->setAnchor(get($data, 'anchor'));
     return $uri;
 }
 /**
  * @param \Components\Http_Scriptlet_Context $context_
  * @param \Components\Uri $uri_
  */
 public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_)
 {
     $key = $uri_->getFilename();
     if (!($path = Cache::get($key))) {
         throw new Http_Exception('ui/scriptlet/image', null, Http_Exception::NOT_FOUND);
     }
     // TODO Cache headers.
     readfile($path);
 }
 public function match(FilterableUri $uri)
 {
     /*
      * if the URI does not contain the seed, it is not allowed
      */
     if (false === stripos($uri->toString(), $this->seed->toString())) {
         $uri->setFiltered(true, 'Doesn\'t match base URI');
         return true;
     }
     return false;
 }
 public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_)
 {
     $params = $uri_->getPathParams();
     $storeName = array_shift($params);
     $categoryName = array_shift($params);
     $file = Io::fileUpload();
     $store = Media::store($storeName);
     $store->add($file, $file->getName(), $categoryName);
     // TODO JSON
     echo $store->uri($file->getName(), $categoryName);
 }
Esempio n. 6
0
 public function testGettersAndSetters()
 {
     $uri1 = new Uri('');
     $uri2 = $uri1->withScheme('HTTP')->withUserInfo('foo', 'bar')->withHost('EXAMPLE.com')->withPort(81)->withPath('/FOO/bar')->withQuery('a=2&b=3')->withFragment('foobar');
     $this->assertEquals('http', $uri2->getScheme());
     $this->assertEquals('foo:bar', $uri2->getUserInfo());
     $this->assertEquals('example.com', $uri2->getHost());
     $this->assertEquals(81, $uri2->getPort());
     $this->assertEquals('/foo/bar', $uri2->getPath());
     $this->assertEquals('a=2&b=3', $uri2->getQuery());
     $this->assertEquals('foobar', $uri2->getFragment());
 }
 /**
  * @param \Components\Http_Scriptlet_Context $context_
  * @param \Components\Uri $uri_
  */
 public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_)
 {
     $params = $uri_->getPathParams();
     $base64 = end($params);
     $info = unserialize(\str\decodeBase64Url($base64));
     $path = array_shift($info);
     $id = array_shift($info);
     $category = array_shift($info);
     $scheme = array_shift($info);
     $store = Media::store($path);
     $file = $store->findByScheme($scheme, $id, $category);
     header('Content-Length: ' . $file->getSize()->bytes());
     readfile((string) $file);
 }
Esempio n. 8
0
 private function getSegments()
 {
     $uri = $this->uri;
     foreach ($this->route as $key => $val) {
         if (preg_match('#^' . $key . '$#', $uri)) {
             if (strpos($val, '$') !== false && strpos($key, '(') !== false) {
                 $uri = preg_replace('#^' . $key . '$#', $val, $this->uri);
             }
         }
     }
     $uri = new Uri($uri);
     $segments = $uri->explodeSegments();
     return $segments;
 }
Esempio n. 9
0
 /**
  * Returns a pattern representing an uri. It can be used to check if two urls have the same
  * equivalence class.
  *
  * @return string
  */
 public function getPattern()
 {
     // file type
     $pattern = $this->getFileType() . ':';
     // schema (http, https)
     $pattern .= $this->uri->getScheme() . ':';
     // host
     $pattern .= $this->uri->getHost() . ':';
     $path = $this->uri->getPath() . '?' . $this->uri->getQuery();
     $pathNew = preg_replace("^[a-f0-9]{32}^", "<h>", $path);
     $pathNew = preg_replace("^[a-z\\-\\_]{1,}^i", "<s>", $pathNew);
     $pathNew = preg_replace("^[0-9]{1,}^", "<i>", $pathNew);
     $pattern .= $pathNew;
     return $pattern;
 }
Esempio n. 10
0
 public static function Anchor($uri, $title = NULL, $attributes = NULL, $protocol = NULL, $escape_title = FALSE)
 {
     /**
      * Create HTML link anchors.
      *
      * @param   string  URL or URI string
      * @param   string  link text
      * @param   array   HTML anchor attributes
      * @param   string  non-default protocol, eg: https
      * @param   boolean option to escape the title that is output
      * @return  string
      */
     if ($protocol === NULL) {
         $protocol = getenv('HTTPS') == 'on' ? 'https' : 'http';
     }
     if (strpos($uri, '#') === 0) {
         // This is an id target link, not a URL
         $site_url = $uri;
     } elseif (strpos($uri, '://') === FALSE) {
         $site_url = Uri::baseUrl() . $uri;
     } else {
         //$attributes['target'] = '_blank';
         $site_url = $uri;
     }
     return '<a href="' . $site_url . '"' . (is_array($attributes) ? htmlAttributes($attributes) : '') . '>' . ($escape_title ? htmlspecialchars($title === NULL ? $site_url : $title, ENT_QUOTES, 'UTF-8', FALSE) : ($title === NULL ? $site_url : $title)) . '</a>';
 }
Esempio n. 11
0
 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
         }
     }
 }
 /**
  * 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
 }
 public function action_index()
 {
     $this->template = View::forge("teachers/template");
     $this->template->auth_status = false;
     $this->template->title = "Forgotpassword";
     // login
     if (Input::post("email", null) !== null and Security::check_token()) {
         $email = Input::post('email', null);
         $user = Model_User::find("first", ["where" => [["email", $email]]]);
         if ($user != null) {
             $token = Model_Forgotpasswordtoken::forge();
             $token->user_id = $user->id;
             $token->token = sha1("asadsada23424{$user->email}" . time());
             $token->save();
             $url = Uri::base() . "teachers/forgotpassword/form/{$token->token}";
             $body = View::forge("email/forgotpassword", ["url" => $url]);
             $sendmail = Email::forge("JIS");
             $sendmail->from(Config::get("statics.info_email"), Config::get("statics.info_name"));
             $sendmail->to($email);
             $sendmail->subject("forgot password");
             $sendmail->html_body(htmlspecialchars_decode($body));
             $sendmail->send();
         }
         $view = View::forge("teachers/forgotpassword/sent");
         $this->template->content = $view;
     } else {
         $view = View::forge("teachers/forgotpassword/index");
         $this->template->content = $view;
     }
 }
 /**
  * @test
  * @profile
  */
 public function testDispatch()
 {
     split_time('reset');
     Rest_Test_Unit_Case_Resource_Foo::serve('resource/foo');
     split_time('Invoke Rest_Test_Unit_Case_Resource_Foo::serve(resource/foo)');
     Http_Scriptlet_Context::push(new Http_Scriptlet_Context(Environment::uriComponents()));
     split_time('Initialize Components\\Http_Scriptlet_Context');
     $uri = Uri::valueOf(Environment::uriComponents('rest', 'resource', 'foo', 'poke', '1234.json'));
     split_time("Invoke Uri::valueOf({$uri})");
     ob_start();
     split_time('reset');
     Http_Scriptlet_Context::current()->dispatch($uri, Http_Scriptlet_Request::METHOD_GET);
     split_time("Invoke Components\\Http_Scriptlet_Context\$dispatch([{$uri}], GET)");
     $result = ob_get_clean();
     assertEquals(json_encode(true), $result);
     split_time('reset');
     $uri = Uri::valueOf(Environment::uriComponents('rest', 'resource', 'foo', 'poke', '1234.json'));
     $uri->setQueryParam('log', 'false');
     split_time("Invoke Uri::valueOf({$uri})");
     ob_start();
     split_time('reset');
     Http_Scriptlet_Context::current()->dispatch($uri, Http_Scriptlet_Request::METHOD_GET);
     split_time("Invoke Components\\Http_Scriptlet_Context\$dispatch([{$uri}], GET)");
     $result = ob_get_clean();
     assertEquals(json_encode(false), $result);
 }
Esempio n. 15
0
 /**
  * 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;
     }
 }
Esempio n. 16
0
 public function index()
 {
     Cache::loadPage('', 30);
     $inputData = array();
     $postid = 0;
     Model::loadWithPath('page', System::getThemePath() . 'model/');
     if (!($match = Uri::match('page\\/(.*?)\\.html$'))) {
         Redirect::to('404page');
     }
     $friendly_url = addslashes($match[1]);
     $loadData = Pages::get(array('cacheTime' => 30, 'where' => "where friendly_url='{$friendly_url}'"));
     if (!isset($loadData[0]['pageid'])) {
         Redirect::to('404page');
     }
     $inputData = $loadData[0];
     $postid = $loadData[0]['pageid'];
     if (Uri::isNull()) {
         System::setTitle(ucfirst($loadData[0]['title']));
     }
     $keywords = isset($loadData[0]['keywords'][4]) ? $loadData[0]['keywords'] : System::getKeywords();
     System::setKeywords($keywords);
     if ($loadData[0]['page_type'] == 'fullwidth') {
         self::makeContent('pageFullWidth', $inputData);
     } else {
         self::makeContent('page', $inputData);
     }
     Cache::savePage();
 }
Esempio n. 17
0
 /**
  * Parse url and reroute with routes.xml rules if found
  * 
  * @return Uri      Return the instance of Uri (rerouted or not) 
  */
 public function parseUrl()
 {
     // Get new instance of Uri
     $uriInst = Uri::getInstance();
     // Remove first / from uri
     $uri = trim($uriInst->getUri(false), '/');
     // Init vars
     $defaultRedirect = null;
     // Parse routes
     foreach ($this->_routes as $route) {
         // Converts shortcuts to regexp
         $rule = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $route->attributes()->rule));
         // Rule match to uri
         if (preg_match('#^' . $rule . '$#', $uri)) {
             // Is there any back reference
             if (strpos($route->attributes()->redirect, '$') !== false && strpos($rule, '(') !== false) {
                 $uri = preg_replace('#^' . $rule . '$#', $route->attributes()->redirect, $uri);
             } else {
                 $uri = $route->attributes()->redirect;
             }
             // Define rerouted uri to current instance of Uri
             return $uriInst->setUri($uri);
         }
         if ($rule === 'default') {
             $defaultRedirect = (string) $route->attributes()->redirect . '/' . $uri;
         }
     }
     if (!$uriInst->isDefined() && $defaultRedirect !== null) {
         $uriInst->setUri($defaultRedirect);
     }
     return $uriInst;
 }
Esempio n. 18
0
 public static function find($type, $path = false, $keys = null)
 {
     self::current();
     if (!array_key_exists($type, self::$files)) {
         return false;
     }
     // If no keys are specfied, use the page URI
     if (empty($keys)) {
         $keys = array_keys(Uri::get());
     } elseif (is_string($keys)) {
         $keys = explode('_', $keys);
     }
     // Add the first section, if its not listed
     if (!array_key_exists($type, $keys)) {
         array_unshift($keys, $type);
     }
     $total = count($keys);
     for ($i = 0; $i < $total; $i++) {
         $name = implode($keys, '_');
         $file = self::exists($type, $name);
         // if ($file) return $file;
         if ($file) {
             if ($path) {
                 return $file;
             } else {
                 return self::capitalize($name);
             }
         }
         // Remove the last section on each pass
         array_pop($keys);
     }
 }
Esempio n. 19
0
 /**
  * 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);
 }
Esempio n. 20
0
 /**
  * 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);
 }
Esempio n. 21
0
function listRss()
{
    header("Content-Type: application/xml; charset=UTF-8");
    $location = Url::rss();
    if ($match = Uri::match('^(.*?)$')) {
        $location = ROOT_URL . $match[1];
        $reLocation = base64_encode($location);
        if ($loadData = Cache::loadKey($reLocation, 60)) {
            $loadData = json_decode($loadData, true);
            return $loadData;
        }
    }
    $inputData = array('limitShow' => 15, 'limitPage' => 0);
    if ($match = Uri::match('\\/page\\/(\\d+)')) {
        $inputData['limitPage'] = $match[1];
    }
    if ($match = Uri::match('\\/category\\/(\\d+)')) {
        $id = $match[1];
        $inputData['where'] = "where catid='{$id}'";
    }
    if ($match = Uri::match('rss\\/products')) {
        $loadData = Products::get($inputData);
    } else {
        $loadData = Post::get($inputData);
    }
    $reLocation = base64_encode($location);
    Cache::saveKey($reLocation, json_encode($loadData));
    return $loadData;
}
Esempio n. 22
0
 public function action_usercp()
 {
     if (!$this->current_user->logged_in()) {
         Session::set_flash('error', 'You need to be logged in to access is page');
         Session::set_flash('login_redirect', Uri::current());
         Response::redirect('login');
     }
     $this->title('UserCP');
     $this->view = $this->theme->view('users/usercp');
     if (Input::param() != array()) {
         // Set name and email
         $this->current_user->name = Input::param('name');
         $this->current_user->email = Input::param('email');
         // Set new password
         if (Input::param('new_password')) {
             $this->current_user->password = Input::param('new_password');
         }
         // Check if the current password is valid...
         $auth = Model_User::authenticate_login($this->current_user->username, Input::param('current_password'));
         if ($this->current_user->is_valid() and $auth) {
             $this->current_user->save();
             Session::set_flash('success', 'Details saved');
             Response::redirect('usercp');
         } else {
             $errors = $this->current_user->errors();
             if (!$auth) {
                 $errors = array('Current password is invalid.') + $errors;
             }
         }
         $this->view->set('errors', isset($errors) ? $errors : array());
     }
 }
 /**
  * Get menu
  *
  * @param string $category Category name
  */
 public static function get($category = '')
 {
     // Get menu table
     $menu = new Table('menu');
     // Display view
     View::factory('box/menu/views/frontend/index')->assign('items', $menu->select('[category="' . $category . '"]', 'all', null, array('id', 'name', 'link', 'target', 'order', 'category'), 'order', 'ASC'))->assign('uri', Uri::segments())->assign('defpage', Option::get('defaultpage'))->display();
 }
Esempio n. 24
0
 public static function paginate($page = 1, $perpage = 10)
 {
     $query = Query::table(static::table());
     $count = $query->count();
     $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('title')->get();
     return new Paginator($results, $count, $page, $perpage, Uri::to('admin/companies'));
 }
Esempio n. 25
0
 /**
  * Gets the singleton instance
  * @return Uri
  */
 public static function &instance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Esempio n. 26
0
 public static function get($foldername)
 {
     if (!($match = Uri::match($foldername . '\\/(\\w+)'))) {
         throw new Exception("Not match valid route.");
     }
     $routeName = $match[1];
     $pluginPath = ROOT_PATH . 'contents/themes/' . $foldername . '/api.php';
     define("THIS_URL", ROOT_URL . 'contents/themes/' . $foldername . '/');
     define("THIS_PATH", ROOT_PATH . 'contents/themes/' . $foldername . '/');
     if (!file_exists($pluginPath)) {
         return false;
     }
     include $pluginPath;
     $routes = SelfApi::route();
     if (!isset($routes[$routeName])) {
         throw new Exception("Theme not support this route.");
     }
     $func = $routes[$routeName];
     if (!method_exists('SelfApi', $func)) {
         throw new Exception('Route ' . $routeName . ' not ready for runc.');
     }
     try {
         $result = SelfApi::$func();
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     return $result;
 }
Esempio n. 27
0
 public static function render($app, $ref_id, $title = 'Comments')
 {
     if (!isset($app)) {
         throw new \FuelException('Petro_Comment : Invalid $app = ' . $app);
     }
     $query = \DB::query('SELECT ' . static::$_table . '.*, users.username FROM ' . static::$_table . ', users' . ' WHERE ' . static::$_table . '.user_id = users.id' . ' AND ' . static::$_table . '.app = "' . $app . '"' . ' AND ' . static::$_table . '.ref_id = ' . $ref_id . ' ORDER BY ' . static::$_table . '.created_at asc')->execute();
     $data['title'] = $title;
     $data['app'] = $app;
     $data['ref_id'] = $ref_id;
     $data['total_comments'] = count($query);
     if ($data['total_comments'] <= 0) {
         $data['comments'] = str_replace('{text}', 'No comments yet.', \Config::get('petro.template.comment.empty'));
     } else {
         $t = \Config::get('petro.template.comment.item');
         $out = '';
         foreach ($query as $item) {
             $author = isset($item['username']) ? $item['username'] : '******';
             $date = empty($item['created_at']) ? '' : \Date::forge($item['created_at'])->format(\Config::get('petro.date_format', '%Y-%m-%d %H:%M'));
             $cost = empty($item['cost']) ? '' : number_format($item['cost']);
             $out .= str_replace(array('{comment_id}', '{comment_author}', '{comment_date}', '{comment_text}', '{comment_cost}'), array($item['id'], $author, $date, nl2br($item['text']), $cost), $t);
         }
         $data['comments'] = $out;
     }
     $data['last_url'] = \Uri::current();
     return \View::forge('petro/comments/_form', $data, false)->render();
 }
Esempio n. 28
0
 /**
  * @author NamNT
  * action index
  */
 public function action_index()
 {
     $model = new \Model_Person();
     $filter = array();
     $data = array();
     if (Input::get()) {
         $filter = Input::get();
         $query_string = http_build_query($filter);
         \Session::set('url_filter_persons', $query_string);
         $person_url = $query_string ? '?' . $query_string : '';
     } else {
         $person_url = '';
     }
     if (Input::get('export', false)) {
         $filter['per_page'] = 100000;
         $download_his = new \Model_Downloadhis();
         $download = array('param' => json_encode($filter), 'content' => json_encode(Input::server()));
         $download_his->set_data($download);
         if ($download_his->save_data()) {
             $this->export($model->get_filter_person($filter));
         }
     }
     $config = ['pagination_url' => \Uri::base() . 'job/persons/index' . $person_url, 'total_items' => $model->count_data($filter), 'per_page' => \Constants::$default_limit_pagination, 'uri_segment' => 'page', 'num_links' => \Constants::$default_num_links, 'show_last' => true];
     \Fuel\Core\Cookie::set('person_url', \Uri::main() . $person_url, 30 * 60);
     $pagination = \Uospagination::forge('mypagination', $config);
     $filter['offset'] = $pagination->offset;
     $filter['limit'] = $pagination->per_page;
     $data['listPerson'] = $model->get_filter_person($filter);
     $data['groups'] = (new \Model_Mgroups())->get_type(1);
     $this->template->title = 'UOS求人システム';
     $this->template->content = \View::forge('persons/persons', $data);
 }
Esempio n. 29
0
 /**
  * Check if the URI is a valid File URI
  * 
  * This applies additional specific validation rules beyond the ones 
  * required by the generic URI syntax.
  * 
  * @return boolean
  * @see    Uri::isValid()
  */
 public function isValid()
 {
     if ($this->query) {
         return false;
     }
     return parent::isValid();
 }
Esempio n. 30
0
 public function before()
 {
     parent::before();
     $auth = \Auth::instance('SimpleAuth');
     if (\Input::get('logout')) {
         $auth->logout();
         \Response::redirect(\Uri::base(false) . 'admin/login');
     }
     $uri = explode('/', \Uri::string());
     if ($auth->check()) {
         if (count($uri) < 3 && (empty($uri[1]) || $uri[1] == 'login')) {
             \Response::redirect(\Uri::base(false) . 'admin/list');
         }
         // Load admin Config for List View and default to first tab
         $this->data['tabs'] = $this->template->tabs = \Config::get('admin.tabs');
         $this->data['table'] = $this->param('item', '');
         // get item from URI
         if (!$this->data['table']) {
             list($this->data['table']) = array_slice(array_keys($this->data['tabs']), 0, 1);
         }
         $this->template->table = $this->data['table'];
     } elseif (count($uri) > 1 && $uri[1] != 'login') {
         \Response::redirect(\Uri::base(false) . 'admin/login');
     }
     if ($this->auto_render === true) {
         // set up defaults
         $this->template->body = '';
     }
     return true;
 }