public function postShorten()
 {
     //get url input
     $url = Input::get('url');
     //validate url
     $val = Url::validate(array('url' => $url));
     //if error, return with error message
     if ($val !== true) {
         return Redirect::to('/')->withErrors($val);
     }
     //check whether url is shortened or not
     $record = Url::whereUrl($url)->first();
     if ($record) {
         $url = url('/' . $record->given, $parameters = array(), $secure = null);
         return View::make('shorturl.result')->with('url', $url);
     }
     //create new short url
     $data = new Url();
     $data->url = $url;
     $data->given = Url::getShortenedUrl();
     //if successfully saved to db
     if ($data->save()) {
         $row = Url::whereUrl($url)->first();
         $url = url('/' . $row->given, $parameters = array(), $secure = null);
         return View::make('shorturl.result')->with('url', $url);
     }
 }
Example #2
0
 public function testFormatUrlKey()
 {
     $strIn = 'Some string';
     $resultString = 'some';
     $this->filter->expects($this->once())->method('translitUrl')->with($strIn)->will($this->returnValue($resultString));
     $this->assertEquals($resultString, $this->model->formatUrlKey($strIn));
 }
Example #3
0
 public function index($mid = 1)
 {
     $vendorlist = "";
     if (empty($mid)) {
         redirect_to($this->uri->link("error/index"));
         exit;
     }
     $this->loadModel("Subregion");
     $datum = $this->model->getList("", "subregion");
     $this->view->mysubregion = $datum['subregion'];
     $uri = new Url("");
     $vendorlist .= "<table  width='100%'>\n<thead><tr>\n\t<th>S/N</th><th>Area ID</th><th> Name </th><th>Description </th><th>Date Created </th><th>Date Modified </th><th></th><th></th>\n</tr>\n</thead>\n<tbody>";
     if ($this->view->mysubregion) {
         $x = 1;
         foreach ($this->view->mysubregion as $region) {
             $vendorlist .= "<tr>\n    \t<td>{$x}</td><td>{$region->id}</td><td>{$region->name} </td><td>{$region->des}</td><td>{$region->datecreated}</td><td>{$region->datemodified}</td><td><a href='" . $uri->link("subregion/edit/" . $region->id . "") . "'>Edit</a></td><td><a href='" . $uri->link("subregion/doDelete/" . $region->id . "") . "'>Delete</a></td>\n    </tr>";
             $x++;
         }
     } else {
         $vendorlist .= "<tr><td colspan='7'>No record to display</td></tr>";
     }
     $vendorlist .= "</tbody>\n</table>";
     $this->view->myvends = $vendorlist;
     $this->view->render("subregion/index");
 }
Example #4
0
 public function index($mid = 1)
 {
     $itemlist = "";
     if (empty($mid)) {
         redirect_to($this->uri->link("error/index"));
         exit;
     }
     $this->loadModel("Stockitems");
     $datum = $this->model->getList("", "Stockitems");
     $this->view->myitems = $datum['items'];
     $uri = new Url("");
     $itemlist .= "<table  width='100%'>\n<thead><tr>\n\t<th>S/N</th><th>Item ID</th><th>Item Name </th><th>Description </th><th>Qty In Stock </th><th>Date Modified </th><th></th><th></th>\n</tr>\n</thead>\n<tbody>";
     if ($this->view->myitems) {
         $x = 1;
         foreach ($this->view->myitems as $item) {
             $itemlist .= "<tr>\n    \t<td>{$x}</td><td>{$item->item_id}</td><td>{$item->item_name} </td><td>{$item->item_description}</td><td>{$item->item_quantity}</td><td>{$item->item_datemodified}</td><td><a href='" . $uri->link("stockitems/edit/" . $item->id . "") . "'>Edit</a></td><td><a href='" . $uri->link("stockitems/doDelete/" . $item->id . "") . "'>Delete</a></td>\n    </tr>";
             $x++;
         }
     } else {
         $itemlist .= "<tr><td colspan='7'>No record to display</td></tr>";
     }
     $itemlist .= "</tbody>\n</table>";
     $this->view->myitems = $itemlist;
     $this->view->render("stockitems/index");
 }
Example #5
0
 public function index($mid = 1)
 {
     $vendorlist = "";
     if (empty($mid)) {
         redirect_to($this->uri->link("error/index"));
         exit;
     }
     $this->loadModel("Products");
     $datum = $this->model->getList("", "products");
     $this->view->myproducts = $datum['products'];
     $uri = new Url("");
     $vendorlist .= "<div class='row'><div class='large-12 columns'>" . $datum['mypagin'];
     $vendorlist .= "</div></div><div class='row'><div class='large-12 columns'><table  width='100%'>\n<thead><tr>\n\t<th>S/N</th><th>ProdID</th><th> Name </th><th>Description </th><th>Date Created </th><th>Date Modified </th><th></th><th></th>\n</tr>\n</thead>\n<tbody>";
     if ($this->view->myproducts) {
         $x = 1;
         foreach ($this->view->myproducts as $region) {
             $vendorlist .= "<tr>\n    \t<td>{$x}</td><td>{$region->prod_id}</td><td>{$region->prod_name} </td><td>{$region->prod_desc}</td><td>{$region->prod_created}</td><td>{$region->Prod_modified}</td><td><a href='" . $uri->link("products/edit/" . $region->prod_id . "") . "'>Edit</a></td><td><a class='dataDelete' data-reveal-id='firstModal{$region->prod_id}' href='#'>Delete</a>\n        \n        \n        <div id='firstModal{$region->prod_id}' class='reveal-modal small' style='background-image: linear-gradient(0deg, #f2f9fc, #addcf0 20.0em); border-radius:5px'>\n    <h2>Data Delete Console.</h2>\n    <hr />\n    <p>You are about to delete a record. Any record deleted will not longer be available in the database <br /> Are you sure you want to delete <b>{$region->prod_name}</b> from the database?</p>\n    <p><a href='?url=products/doCheckTransLog/{$region->main_id}' data-reveal-id='secondModal{$region->prod_id}' class='btn button btn-danger' data-reveal-ajax='true'>Yes</a>&nbsp; &nbsp; &nbsp;<a pdid='{$region->prod_id}' class='btn button btn-danger modalclose'>No</a></p>\n    <a class='close-reveal-modal'>&#215;</a>\n  </div>\n\n  <div id='secondModal{$region->prod_id}' class='reveal-modal small' style='background-image: linear-gradient(0deg, #f2f9fc, #addcf0 20.0em); border-radius:5px'>\n    <h2>This is a second modal.</h2>\n    <hr />\n    <p></p>\n    <a class='close-reveal-modal closemodal'>&#215;</a>\n  </div>\n        \n        \n        \n        </td>\n    </tr>";
             $x++;
         }
     } else {
         $vendorlist .= "<tr><td colspan='7'>No record to display</td></tr>";
     }
     $vendorlist .= "</tbody>\n</table></div></div><div class='row'><div class='large-12 columns'>";
     $vendorlist .= $datum['mypagin'] . "</div><p>&nbsp;</p></div>";
     $this->view->myvends = $vendorlist;
     $this->view->render("products/index");
 }
 /**
  * Adds a referer to the database.
  *
  * @param refererHeader The referer header as was received by PHP.
  * @param articleId The article being hit by this referer.
  * @return Returns true if successful or false otherwise.
  */
 function addReferer($refererHeader, $articleId, $blogId)
 {
     // quit inmediately if this is not enabled...
     if (!$this->_enabled) {
         return;
     }
     // we only add a new referer if we come from somewhere else than our own server
     $ourHost = $_SERVER["HTTP_HOST"];
     $refererUrl = new Url($refererHeader);
     // if they're the same, we quit
     if ($refererUrl->getHost() == $ourHost || $refererUrl->getHost() == "") {
         return;
     }
     // we have to check if a referer with that information exists
     // in the database
     $query = "UPDATE " . $this->getPrefix() . "referers SET hits = hits + 1 WHERE url = '" . Db::qstr($refererHeader) . "' AND article_id = '" . Db::qstr($articleId) . "' AND blog_id = '" . Db::qstr($blogId) . "';";
     $result = $this->Execute($query);
     if (!$result) {
         return false;
     }
     // check how many rows were updated this time.
     if ($this->_db->Affected_Rows() == 0) {
         // we have to insert the row manually
         $query2 = "INSERT INTO " . $this->getPrefix() . "referers (url,article_id,blog_id) \n                           VALUES ('" . Db::qstr($refererHeader) . "','" . Db::qstr($articleId) . "','" . Db::qstr($blogId) . "');";
         $result2 = $this->Execute($query2);
     }
     return true;
 }
Example #7
0
 /**
  * Search and returns all data retrieved by the providers.
  *
  * @param null|array $providers The providers used to retrieve the data
  * @param string     $name      The data name (title, description, image, etc)
  * @param Url        $url       The base url used to resolve relative urls
  *
  * @return array
  */
 public static function getData(array $providers, $name, Url $url = null)
 {
     $method = 'get' . $name;
     $values = [];
     foreach ($providers as $key => $provider) {
         $value = $provider->{$method}();
         if (empty($value)) {
             continue;
         }
         if (!is_array($value)) {
             $value = [$value];
         }
         foreach ($value as $v) {
             if ($url) {
                 $v = $url->getAbsolute($v);
             }
             if (!isset($values[$v])) {
                 $values[$v] = ['value' => $v, 'providers' => [$key]];
             } elseif (!in_array($key, $values[$v]['providers'], true)) {
                 $values[$v]['providers'][] = $key;
             }
         }
     }
     return array_values($values);
 }
Example #8
0
 public function resolve(ResourceLocator $locator)
 {
     if ($locator->hasResourceId()) {
         $context = Claro_Context::getCurrentContext();
         $context[CLARO_CONTEXT_COURSE] = $locator->getCourseId();
         if ($locator->inGroup()) {
             $context[CLARO_CONTEXT_GROUP] = $locator->getGroupId();
         }
         $path = get_path('coursesRepositorySys') . claro_get_course_path($locator->getCourseId());
         // in a group
         if ($locator->inGroup()) {
             $groupData = claro_get_group_data($context);
             $path .= '/group/' . $groupData['directory'];
             $groupId = $locator->getGroupId();
         } else {
             $path .= '/document';
         }
         $path .= '/' . $this->urlDecodePath(ltrim($locator->getResourceId(), '/'));
         $resourcePath = '/' . $this->urlDecodePath(ltrim($locator->getResourceId(), '/'));
         $path = secure_file_path($path);
         if (!file_exists($path)) {
             // throw new Exception("Resource not found {$path}");
             return false;
         } elseif (is_dir($path)) {
             $url = new Url(get_module_entry_url('CLDOC'));
             $url->addParam('cmd', 'exChDir');
             $url->addParam('file', base64_encode($resourcePath));
             return $url->toUrl();
         } else {
             return claro_get_file_download_url($resourcePath, Claro_Context::getUrlContext($context));
         }
     } else {
         return get_module_entry_url('CLDOC');
     }
 }
Example #9
0
 function set_link($value)
 {
     if (!of_class($value, URL__CLASS)) {
         $value = new Url($value);
     }
     $this->link = $value->absolute();
 }
Example #10
0
/**
 * GET an HTTP URL to retrieve its content
 *
 * @param string $url      URL to get (http://...)
 * @param int    $timeout  network timeout (in seconds)
 * @param int    $maxBytes maximum downloaded bytes (default: 4 MiB)
 *
 * @return array HTTP response headers, downloaded content
 *
 * Output format:
 *  [0] = associative array containing HTTP response headers
 *  [1] = URL content (downloaded data)
 *
 * Example:
 *  list($headers, $data) = get_http_response('http://sebauvage.net/');
 *  if (strpos($headers[0], '200 OK') !== false) {
 *      echo 'Data type: '.htmlspecialchars($headers['Content-Type']);
 *  } else {
 *      echo 'There was an error: '.htmlspecialchars($headers[0]);
 *  }
 *
 * @see http://php.net/manual/en/function.file-get-contents.php
 * @see http://php.net/manual/en/function.stream-context-create.php
 * @see http://php.net/manual/en/function.get-headers.php
 */
function get_http_response($url, $timeout = 30, $maxBytes = 4194304)
{
    $urlObj = new Url($url);
    $cleanUrl = $urlObj->idnToAscii();
    if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) {
        return array(array(0 => 'Invalid HTTP Url'), false);
    }
    $options = array('http' => array('method' => 'GET', 'timeout' => $timeout, 'user_agent' => 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:45.0)' . ' Gecko/20100101 Firefox/45.0', 'accept_language' => substr(setlocale(LC_COLLATE, 0), 0, 2) . ',en-US;q=0.7,en;q=0.3'));
    stream_context_set_default($options);
    list($headers, $finalUrl) = get_redirected_headers($cleanUrl);
    if (!$headers || strpos($headers[0], '200 OK') === false) {
        $options['http']['request_fulluri'] = true;
        stream_context_set_default($options);
        list($headers, $finalUrl) = get_redirected_headers($cleanUrl);
    }
    if (!$headers || strpos($headers[0], '200 OK') === false) {
        return array($headers, false);
    }
    try {
        // TODO: catch Exception in calling code (thumbnailer)
        $context = stream_context_create($options);
        $content = file_get_contents($finalUrl, false, $context, -1, $maxBytes);
    } catch (Exception $exc) {
        return array(array(0 => 'HTTP Error'), $exc->getMessage());
    }
    return array($headers, $content);
}
Example #11
0
 public function __construct(Kernel $kernel)
 {
     $this->kernel = $kernel;
     if (Util::isAjaxRequest()) {
         return;
     }
     if (Sessionmanager::isLogged()) {
         $menuUrl = new Url();
         $menuUrl->clearPageParams();
         $menuUrl->setPage('Mainpage');
         $this->kernel->addMenuItem($menuUrl, 'Mainpage');
         $menuUrl->clearPageParams();
         $menuUrl->setPage('Movies');
         $this->kernel->addMenuItem($menuUrl, 'Movies');
         $menuUrl->clearPageParams();
         $menuUrl->setPage('Series');
         $this->kernel->addMenuItem($menuUrl, 'Series');
         $menuUrl->clearPageParams();
         $menuUrl->setPage('Unhandled');
         $this->kernel->addMenuItem($menuUrl, 'Unhandled');
         $menuUrl->clearPageParams();
         $menuUrl->setPage('Seeking');
         $this->kernel->addMenuItem($menuUrl, 'Seeking');
         $menuUrl->clearPageParams();
         $menuUrl->setPage('Statistics');
         $this->kernel->addMenuItem($menuUrl, 'Statistics');
         $menuUrl->clearPageParams();
         $menuUrl->setPage('Login');
         $menuUrl->setParam('logout', 1);
         $this->kernel->addMenuItem($menuUrl, 'Logout');
     }
 }
Example #12
0
 /**
  * Resolve an url with hashbang.
  *
  * @param Url $url
  *
  * @return string
  */
 protected static function hashBang(Url $url)
 {
     if ($path = preg_replace('|^(/?!)|', '', $url->getFragment())) {
         return $url->withPath($url->getPath() . $path)->getUrl();
     }
     return $url->getUrl();
 }
 /**
  * @desc Defines the URL to the media file
  * @param mixed $url a string url or an Url object
  */
 public function set_url($url)
 {
     if (!$url instanceof Url) {
         $url = new Url($url);
     }
     $this->url = $url->rel();
 }
Example #14
0
 public function index($mid = 1)
 {
     $vendorlist = "";
     if (empty($mid)) {
         redirect_to($this->uri->link("error/index"));
         exit;
     }
     $this->loadModel("Vendors");
     $datum = $this->model->getList("", "Vendors");
     $this->view->myvendors = $datum['vendors'];
     $uri = new Url("");
     $vendorlist .= "<table  width='100%'>\n<thead><tr>\n\t<th>S/N</th><th>Vendor ID</th><th>Vendor Name </th><th>Email </th><th>Telephone </th><th>Date Modified </th><th></th><th></th>\n</tr>\n</thead>\n<tbody>";
     if ($this->view->myvendors) {
         $x = 1;
         foreach ($this->view->myvendors as $vendor) {
             $vendorlist .= "<tr>\n    \t<td>{$x}</td><td>{$vendor->vend_id}</td><td>{$vendor->vend_name} </td><td>{$vendor->vend_email}</td><td>{$vendor->vend_phone}</td><td>{$vendor->vend_datemodified}</td><td><a href='" . $uri->link("vendors/edit/" . $vendor->id . "") . "'>Edit</a></td><td><a href='" . $uri->link("vendors/doDelete/" . $vendor->id . "") . "'>Delete</a></td>\n    </tr>";
             $x++;
         }
     } else {
         $vendorlist .= "<tr><td colspan='7'>No record to display</td></tr>";
     }
     $vendorlist .= "</tbody>\n</table>";
     $this->view->myvends = $vendorlist;
     $this->view->render("vendors/index");
 }
Example #15
0
 public function generate()
 {
     $addUrl = new Url();
     $addUrl->clearPageParams();
     $addUrl->setParam('getfilesystemusage', 1);
     Util::valueToXml('getfilesystemusageurl', $addUrl->buildUrlString(), $this->rootNode);
 }
Example #16
0
 public static function dispatch()
 {
     $url = new Url();
     $uri = $url->getPath();
     foreach (array_reverse(self::$routes, true) as $route => $class) {
         if (preg_match("~^{$route}\$~", $uri, $params)) {
             Router::$current = $class;
             $return = call_user_func_array(array('Controller', 'dispatch'), array_merge(array($class), array_slice($params, 1)));
             if (!(false === $return)) {
                 $vars = get_class_vars($class);
                 $type = 'text/html';
                 if (isset($vars['type'])) {
                     $type = $vars['type'];
                 }
                 # PHP >= 5.3
                 # if ( isset($class::$type) )
                 #     $type = $class::$type;
                 //Response::setHeader('Content-Type', 'application/xhtml+xml');
                 Response::setHeader('Content-Type', "{$type};charset=UTF-8");
                 Response::setBody($class, $return);
                 return;
             }
             Router::$current = null;
         }
     }
     if (Response::getHttpResponseCode() == 200) {
         $class = 'Error404';
         $return = Controller::dispatch($class);
         Response::setHeader('Content-Type', 'text/html;charset=UTF-8');
         Response::setBody($class, $return);
         //Response::setHeader('HTTP/1.0 404 Not Found');
         //Response::setHttpResponseCode(404);
         //Response::setBody('404', 'Error 404');
     }
 }
Example #17
0
 public static function redirect($url)
 {
     if (!$url instanceof Url) {
         $url = new Url($url);
     }
     Response::getInstance()->setRedirect($url->__toString());
 }
 public function index($mid = 1)
 {
     $productlist = "";
     if (empty($mid)) {
         redirect_to($this->uri->link("error/index"));
         exit;
     }
     $this->loadModel("Clientproduct");
     $datum = $this->model->getList("", "Clientproduct");
     $this->view->myclientsproducts = $datum['clientproduct'];
     $uri = new Url("");
     $productlist .= "<table  width='100%'>\n            <thead><tr>\n            \t<th>S/N</th><th>Product </th><th>Client</th><th>Location</th><th>City </th><th></th><th></th>\n            </tr>\n            </thead>\n            <tbody>";
     if ($this->view->myclientsproducts) {
         $x = 1;
         foreach ($this->view->myclientsproducts as $products) {
             $productlist .= "<tr>\n                \t<td>{$x}</td><td><a href='" . $uri->link("clientproduct/detail/" . $products->id) . "'>{$products->prod_name}</a> </td><td>{$products->client_name}</td><td>{$products->install_address}</td><td>{$products->install_city}</td><td><a href='" . $uri->link("clientproduct/edit/" . $products->id . "") . "'>Edit</a></td><td><a href='" . $uri->link("clientproduct/doDelete/" . $products->id . "") . "'>Delete</a></td>\n                </tr>";
             $x++;
         }
     } else {
         $productlist .= "<tr><td colspan='7'>No record to display</td></tr>";
     }
     $productlist .= "</tbody>\n            </table>";
     $this->view->myprods = $productlist;
     $this->view->render("clientproduct/index");
 }
Example #19
0
 public function __construct()
 {
     parent::__construct(null, new Image("images/icones/xdcc.png"));
     $url = new Url('index.php');
     $url->setQueryVar("page", "xdcc");
     parent::setUrl($url);
     $this->setClass("xdccLink");
 }
Example #20
0
 public function testValidateType()
 {
     $field = new Url("test", "Test");
     $result = $field->validateType("https://www.google.com");
     $this->assertTrue($result);
     $result = $field->validateType("www.google.com");
     $this->assertFalse($result);
 }
Example #21
0
 /**
  * @return string
  */
 function Body()
 {
     $activationUrl = new Url(Configuration::Instance()->GetScriptUrl());
     $activationUrl->Add(Pages::ACTIVATION)->AddQueryString(QueryStringKeys::ACCOUNT_ACTIVATION_CODE, $this->activationCode);
     $this->Set('FirstName', $this->user->FirstName());
     $this->Set('EmailAddress', $this->user->EmailAddress());
     $this->Set('ActivationUrl', $activationUrl);
     return $this->FetchTemplate('AccountActivation.tpl');
 }
Example #22
0
 public function testApiPartial()
 {
     $expected = "api/2/kanui/product";
     $urlParts = ['path' => ['api', 'version' => 'version', 'partnerCode' => 'partner-code', 'product']];
     $url = new Url($urlParts);
     $replace = ['version' => 2, 'partnerCode' => 'kanui'];
     $url->replacePath($replace);
     $this->assertSame($expected, $url->getFullUrl());
 }
Example #23
0
 function get_url($relative = false)
 {
     import('util/url');
     $url = new Url('/syndication.php?m=' . $this->module_id . '&amp;cat=' . $this->category . '&amp;name=' . $this->name);
     if ($relative) {
         return $url->relative();
     }
     return $url->absolute();
 }
Example #24
0
 public function testFilter()
 {
     $filter = new Url();
     $this->assertEquals('http://google.de', $filter->apply('http://google.de'));
     $this->assertEquals(false, $filter->apply('www.google.de'));
     $this->assertEquals(false, $filter->apply('foobar'));
     // test error message
     $this->assertErrorMessage($filter->getErrorMessage());
 }
 function _get_url($string_url, $compute_relative_url = true)
 {
     $url = new Url($string_url);
     if ($compute_relative_url) {
         return $url->relative();
     } else {
         return $url->absolute();
     }
 }
Example #26
0
 /**
  * @covers Xoops\Form\Url::render
  */
 public function testRender()
 {
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<input'));
     $this->assertTrue(false !== strpos($value, 'type="url"'));
     $this->assertTrue(false !== strpos($value, 'name="name"'));
     $this->assertTrue(false !== strpos($value, 'size="80"'));
     $this->assertTrue(false !== strpos($value, 'maxlength="200"'));
 }
Example #27
0
 public function toAbsoluteUrl(Url $url)
 {
     if ($this->isAbsolute()) {
         return $this;
     }
     if ($this->isRoot()) {
         return new Url($url->getRootDomain() . mb_substr((string) $this->uri, 1));
     }
     return new Url($url->getLastDir() . $this->uri);
 }
Example #28
0
 public static function searchDataProvider()
 {
     $model = new Url('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['Url'])) {
         $model->attributes = $_GET['Url'];
     }
     return $model->search();
 }
Example #29
0
 public function fetch(Url $url)
 {
     if ($url->isImage()) {
         return new Resource($url, '', '', $url, null, 'image');
     }
     $browser = new \Buzz\Browser(new \Buzz\Client\Curl());
     $response = $browser->get((string) $url);
     $parsedData = (new Parser())->parse($response->getContent(), $url);
     return new Resource($url, $parsedData->title, $parsedData->description, null !== $parsedData->imageUrl ? new Url($parsedData->imageUrl) : null, null !== $parsedData->videoUrl ? new Url($parsedData->videoUrl) : null, $parsedData->type);
 }
Example #30
0
 public function addMenuItem(Url $url, $text)
 {
     $itemNode = $this->doc->createElement('item');
     $this->menuNode->appendChild($itemNode);
     Util::valueToXml('href', $url->buildUrlString(), $itemNode);
     Util::valueToXml('text', $text, $itemNode);
     if ($this->template == $url->getPage()) {
         Util::valueToXml('current', true, $itemNode);
     }
 }