本文整理汇总了PHP中Url类的典型用法代码示例。如果您正苦于以下问题:PHP Url类的具体用法?PHP Url怎么用?PHP Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postShorten
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);
}
}
示例2: testFormatUrlKey
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));
}
示例3: index
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");
}
示例4: index
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");
}
示例5: index
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> <a pdid='{$region->prod_id}' class='btn button btn-danger modalclose'>No</a></p>\n <a class='close-reveal-modal'>×</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'>×</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> </p></div>";
$this->view->myvends = $vendorlist;
$this->view->render("products/index");
}
示例6: addReferer
/**
* 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;
}
示例7: getData
/**
* 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);
}
示例8: resolve
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');
}
}
示例9: set_link
function set_link($value)
{
if (!of_class($value, URL__CLASS)) {
$value = new Url($value);
}
$this->link = $value->absolute();
}
示例10: get_http_response
/**
* 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);
}
示例11: __construct
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');
}
}
示例12: hashBang
/**
* 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();
}
示例13: set_url
/**
* @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();
}
示例14: index
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");
}
示例15: generate
public function generate()
{
$addUrl = new Url();
$addUrl->clearPageParams();
$addUrl->setParam('getfilesystemusage', 1);
Util::valueToXml('getfilesystemusageurl', $addUrl->buildUrlString(), $this->rootNode);
}