本文整理汇总了PHP中CUrl类的典型用法代码示例。如果您正苦于以下问题:PHP CUrl类的具体用法?PHP CUrl怎么用?PHP CUrl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CUrl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postUploadFile
/**
* @example
* $content = array(
* 'foo' => 'bar',
* 'file' => array(
* 'content' => 'file content is simple text', // or path, mantatory
* 'name' => 'filename.txt', // optional
* 'type' => 'text/plain' // optional
* ));
*
* @param string $url
* @param array $content
* @return CUrl - call ->exec()
*/
static function postUploadFile($url, array $content)
{
$eol = "\r\n";
$boundary = md5(microtime(TRUE));
$curl = new CUrl($url);
$curl->setOptions(array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => 0, CURLOPT_POST => 1, CURLOPT_VERBOSE => 1, CURLOPT_HTTPHEADER => array('Content-Type: multipart/form-data; charset=utf-8; boundary="' . $boundary . '"')));
$body = '';
foreach ($content as $name => $value) {
$body .= '--' . $boundary . $eol;
$body .= 'Content-Disposition: form-data;name="' . $name . '"';
if (is_array($value)) {
if (file_exists($value['content'])) {
$type = MimeTypeDetector::fromFile($value['content']);
$content = file_get_contents($value['content']);
} else {
$type = MimeTypeDetector::fromString($content = $value['content']);
}
// is file
$body .= '; filename="' . (isset($value['name']) ? $value['name'] : date('YmdHis')) . '"' . $eol;
$body .= 'Content-Type: ' . (isset($value['type']) ? $value['type'] : $type) . $eol;
if (preg_match('~base64~i', $content)) {
$body .= 'Content-Transfer-Encoding: base64' . $eol;
$content = preg_replace('~^base64~i', '', $content);
}
$body .= $eol;
// $body .= chunk_split(base64_encode($content)); // RFC 2045
$body .= trim($content) . $eol;
} else {
$body .= $eol . $eol . $value . $eol;
}
}
$body .= "--{$boundary}--" . $eol . $eol;
$curl->setopt(CURLOPT_POSTFIELDS, $body);
return $curl;
}
示例2: setVars
public function setVars($value = null)
{
$url = '?cancel=1';
if (!empty($value)) {
$url .= $value;
}
$uri = new CUrl($url);
$url = $uri->getUrl();
return $this->setAttribute('onclick', "javascript: return redirect('" . $url . "');");
}
示例3: setAction
public function setAction($value = null)
{
if (!is_null($value)) {
return parent::setAttribute('onclick', $value);
}
global $page;
$confirmation = "Confirm('" . $this->msg . "')";
if (isset($this->vars)) {
$link = $page['file'] . '?' . $this->name . '=1' . $this->vars;
$url = new CUrl($link);
$action = "redirect('" . $url->getUrl() . "')";
} else {
$action = 'true';
}
return parent::setAttribute('onclick', 'if (' . $confirmation . ') { return ' . $action . '; } else { return false; }');
}
示例4: getContextUrl
/**
* Creates new CUrl object based on giver URL (or $_REQUEST if null is given),
* and adds/removes parameters based on current page context.
*
* @param string $sourceUrl
*
* @return CUrl
*/
public static function getContextUrl($sourceUrl = null)
{
$config = self::resolveConfig();
$url = new CUrl($sourceUrl);
if (isset($config['remove'])) {
foreach ($config['remove'] as $key) {
$url->removeArgument($key);
}
}
if (isset($config['add'])) {
foreach ($config['add'] as $key) {
$url->setArgument($key, getRequest($key));
}
}
return $url;
}
示例5: GetRSS
function GetRSS()
{
$this->checkValues();
$rssValue = "<?xml version=\"1.0\"?>\r\n";
$rssValue .= "<rss version=\"2.0\">\r\n";
$rssValue .= "<channel>\r\n";
$rssValue .= "<title>" . $this->channelTitle . "</title>\r\n";
$rssValue .= "<link>" . $this->channelLink . "</link>\r\n";
$rssValue .= "<description>" . $this->channelDesc . "</description>\r\n";
$rssValue .= "<image>\r\n";
$rssValue .= "<title>" . $this->imageTitle . "</title>\r\n";
$rssValue .= "<url>" . $this->imageURL . "</url>\r\n";
$rssValue .= "<link>" . $this->imageLink . "</link>\r\n";
$rssValue .= "</image>\r\n";
$sql = "SELECT * FROM page WHERE etat = 1 ORDER BY date DESC";
$res = CBdd::select($sql);
while($page = mysql_fetch_array($res))
{
$rssValue .= "<item>\r\n";
$rssValue .= "<title>" . $page['nom'] . "</title>\r\n";
$rssValue .= "<description>" . $page['description'] . "</description>\r\n";
$rssValue .= "<link>" .htmlentities(CUrl::get_href('page', $page['id'], $page['nom'])). "</link>\r\n";
$rssValue .= "</item>\r\n";
}
$rssValue .= "</channel>\r\n";
$rssValue .= "</rss>\r\n";
return $rssValue;
}
示例6: create
function create($sitemap_name = '') {
if(!$sitemap_name) $sitemap_name = SS_ADMIN_TO_USERFILE . "/sitemap.xml";
if(empty($sitemap_name)) $sitemap_name = "sitemap_" . $rep_name . ".xml";
$changefreq = array('daily', 'weekly', 'monthly');
$priority = array('0.1', '0.5', '1.0');
$tab_archive = array();
rsort($tab_archive);
$xml = simplexml_load_file(SS_ADMIN_TO_USERFILE . '/google/sitemap_base.xml');
//scan bdd
$sql = "SELECT * FROM page WHERE etat = 1";
$res = CBdd::select($sql);
while($page = mysql_fetch_array($res)) {
$url = $xml->addChild('url');
$url->addChild('loc', CUrl::get_urlsite() . "/" . CFunction::formate_chaine(utf8_decode($page['nom']), '-') . "_p" . $page['id']. ".html");
$url->addChild('lastmod', CDate::formate_date($page['date']));
$url->addChild('changefreq', $changefreq[rand(0, 2)]);
$url->addChild('priority', $priority[rand(0, 2)]);
}
$html = $xml->asXML();
file_put_contents($sitemap_name, $html);
}
示例7: resetGetParams
function resetGetParams($params, $newURL = null)
{
zbx_value2array($params);
$redirect = false;
$url = new CUrl($newURL);
foreach ($params as $num => $param) {
if (!isset($_GET[$param])) {
continue;
}
$redirect = true;
$url->setArgument($param, null);
}
if ($redirect) {
jsRedirect($url->getUrl());
include_once 'include/page_footer.php';
}
}
示例8: __construct
/**
* @param array $options['objectOptions'] an array of parameters to be added to the request URL
*
* @see jQuery.multiSelect()
*/
public function __construct(array $options = [])
{
parent::__construct('div', true);
$this->addClass('multiselect');
$this->setId(zbx_formatDomId($options['name']));
// url
$url = new CUrl('jsrpc.php');
$url->setArgument('type', PAGE_TYPE_TEXT_RETURN_JSON);
$url->setArgument('method', 'multiselect.get');
$url->setArgument('objectName', $options['objectName']);
if (!empty($options['objectOptions'])) {
foreach ($options['objectOptions'] as $optionName => $optionvalue) {
$url->setArgument($optionName, $optionvalue);
}
}
$params = ['url' => $url->getUrl(), 'name' => $options['name'], 'labels' => ['No matches found' => _('No matches found'), 'More matches found...' => _('More matches found...'), 'type here to search' => _('type here to search'), 'new' => _('new'), 'Select' => _('Select')]];
if (array_key_exists('data', $options)) {
$params['data'] = zbx_cleanHashes($options['data']);
}
foreach (['ignored', 'defaultValue', 'disabled', 'selectedLimit', 'addNew'] as $option) {
if (array_key_exists($option, $options)) {
$params[$option] = $options[$option];
}
}
if (array_key_exists('popup', $options)) {
foreach (['parameters', 'width', 'height'] as $option) {
if (array_key_exists($option, $options['popup'])) {
$params['popup'][$option] = $options['popup'][$option];
}
}
}
zbx_add_post_js('jQuery("#' . $this->getAttribute('id') . '").multiSelect(' . CJs::encodeJson($params) . ');');
}
示例9: __construct
/**
* @param array $options['objectOptions'] an array of parameters to be added to the request URL
*
* @see jQuery.multiSelect()
*/
public function __construct(array $options = array())
{
parent::__construct('div', 'yes');
$this->addClass('multiselect');
$this->attr('id', zbx_formatDomId($options['name']));
// url
$url = new CUrl('jsrpc.php');
$url->setArgument('type', PAGE_TYPE_TEXT_RETURN_JSON);
$url->setArgument('method', 'multiselect.get');
$url->setArgument('objectName', $options['objectName']);
if (!empty($options['objectOptions'])) {
foreach ($options['objectOptions'] as $optionName => $optionvalue) {
$url->setArgument($optionName, $optionvalue);
}
}
$params = array('url' => $url->getUrl(), 'name' => $options['name'], 'labels' => array('No matches found' => _('No matches found'), 'More matches found...' => _('More matches found...'), 'type here to search' => _('type here to search'), 'new' => _('new'), 'Select' => _('Select')), 'data' => empty($options['data']) ? array() : zbx_cleanHashes($options['data']), 'ignored' => isset($options['ignored']) ? $options['ignored'] : null, 'defaultValue' => isset($options['defaultValue']) ? $options['defaultValue'] : null, 'disabled' => isset($options['disabled']) ? $options['disabled'] : false, 'selectedLimit' => isset($options['selectedLimit']) ? $options['selectedLimit'] : null, 'addNew' => isset($options['addNew']) ? $options['addNew'] : false, 'popup' => array('parameters' => isset($options['popup']['parameters']) ? $options['popup']['parameters'] : null, 'width' => isset($options['popup']['width']) ? $options['popup']['width'] : null, 'height' => isset($options['popup']['height']) ? $options['popup']['height'] : null, 'buttonClass' => isset($options['popup']['buttonClass']) ? $options['popup']['buttonClass'] : null));
zbx_add_post_js('jQuery("#' . $this->getAttribute('id') . '").multiSelect(' . CJs::encodeJson($params) . ');');
}
示例10: CUrl
}
$req = new CUrl();
$req->setArgument('print', null);
$link = new CLink(bold('«' . S_BACK_BIG), $req->getUrl(), 'small_font', null, 'nosid');
$link->setAttribute('style', 'padding-left: 10px;');
$printview = new CDiv($link, 'printless');
$printview->setAttribute('style', 'border: 1px #333 dotted;');
$printview->Show();
}
if (!defined('ZBX_PAGE_NO_MENU')) {
COpt::compare_files_with_menu($ZBX_MENU);
$help = new CLink(S_HELP, 'http://www.zabbix.com/documentation/', 'small_font', null, 'nosid');
$help->setTarget('_blank');
$support = new CLink(S_GET_SUPPORT, 'http://www.zabbix.com/support.php', 'small_font', null, 'nosid');
$support->setTarget('_blank');
$req = new CUrl($_SERVER['REQUEST_URI']);
$req->setArgument('print', 1);
$printview = new CLink(S_PRINT, $req->getUrl(), 'small_font', null, 'nosid');
$page_header_r_col = array($help, '|', $support, '|', $printview);
if ($USER_DETAILS['alias'] != ZBX_GUEST_USER) {
$page_header_r_col[] = array('|');
array_push($page_header_r_col, new CLink(S_PROFILE, 'profile.php', 'small_font', null, 'nosid'), '|');
if ($USER_DETAILS['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
$debug = new CLink(S_DEBUG, '#debug', 'small_font', null, 'nosid');
$d_script = " if(!isset('state', this)) this.state = 'none'; " . " if(this.state == 'none') this.state = 'block'; " . " else this.state = 'none'; " . " showHideByName('zbx_gebug_info', this.state);";
$debug->setAttribute('onclick', 'javascript: ' . $d_script);
array_push($page_header_r_col, $debug, '|');
}
array_push($page_header_r_col, new CLink(S_LOGOUT, 'index.php?reconnect=1', 'small_font', null, 'nosid'));
} else {
$page_header_r_col[] = array('|', new CLink(S_LOGIN, 'index.php?reconnect=1', 'small_font', null, 'nosid'));
示例11: pathString
/**
* Composes a URL path into a string ready to be used as a part of a URL and returns it.
*
* Any characters that cannot be represented literally in a valid path part of a URL come out percent-encoded. The
* resulting path always starts with "/".
*
* Because the characters in path components are stored in their literal representations, the resulting path string
* is always normalized, with only those characters appearing percent-encoded that really require it for the path
* string to be valid and with the hexadecimal letters in percent-encoded characters appearing uppercased.
*
* @return CUStringObject A string containing the URL path.
*/
public function pathString()
{
$components = CArray::makeCopy($this->m_components);
$len = CArray::length($components);
for ($i = 0; $i < $len; $i++) {
$components[$i] = CUrl::enterTdNew($components[$i]);
}
return "/" . CArray::join($components, "/");
}
示例12: deleteLink
public function deleteLink($controller, $method, $id)
{
$deleteLink = '<a class="remove" onClick="if(!confirm(\'' . JText::_('COM_COMMUNITY_CONFIRM_DELETE_FRIEND') . '\'))return false;" href="' . CUrl::build($controller, $method) . '&fid=' . $id . '"> </a>';
return $deleteLink;
}
示例13: include
----------------------------------------------------------------------*/
$headscript = CHeadscript::get_headscript($id_page_courant);
?>
<title><?php echo $meta->title ?></title>
<meta name="description" content="<?php echo $meta->description ?>" />
<meta name="keywords" content="<?php echo $meta->keywords ?>" />
<?php CUrl::inclure('reset.css'); ?>
<?php CUrl::inclure('default.css'); ?>
<?php CUrl::inclure('css/diaporama.css'); ?>
<?php CUrl::inclure('css/video.css'); ?>
<?php echo $headscript ?>
</head>
<body>
<div id="mainwrap">
<div id="header"><?php include(CUrl::formate('header.php'))?></div>
<div id="contentarea">
<div id="left"><?php include(CUrl::formate('left.php')) ?></div>
<div id="center"><?php include(CUrl::formate('center.php')) ?></div>
<div class="clearfloat"></div>
</div>
<div id="footer"><?php include(CUrl::formate('footer.php')) ?></div>
<script type="text/javascript" src="/plug/panther/accordion.js"></script>
<script type="text/javascript" src="/plug/panther/jquery.li-scroller.1.0.js"></script>
<script type="text/javascript" src="../plug/prototype/prototype.js"></script>
<script type="text/javascript" src="/plug/send_mail_queue/script.js"></script>
<script type="text/javascript" src="/plug/popup/popup.js"></script>
<script type="text/javascript" src="/userfiles/file/module/contact/inc/sendmail.js"></script></div>
</body>
</html>
示例14: getGraphUrl
/**
* Return the URL for the graph.
*
* @param array $itemIds
*
* @return string
*/
protected function getGraphUrl(array $itemIds)
{
$url = new CUrl('chart.php');
$url->setArgument('period', $this->timeline['period']);
$url->setArgument('stime', $this->timeline['stime']);
$url->setArgument('itemids', $itemIds);
$url->setArgument('type', $this->graphType);
if ($this->action == HISTORY_BATCH_GRAPH) {
$url->setArgument('batch', 1);
}
return $url->getUrl() . $this->getProfileUrlParams();
}
示例15: __construct
/**
* Creates a parsed URL from a URL string.
*
* The URL string is expected to be by all means valid, with characters being percent-encoded where it is required
* by the URL standard and without any leading or trailing whitespace. It is only when the URL string does not
* indicate any protocol that the URL may still be considered valid and the default protocol is assigned to the
* URL, which is "http".
*
* @param string $url The URL string.
*/
public function __construct($url)
{
assert('is_cstring($url)', vs(isset($this), get_defined_vars()));
assert('self::isValid($url, true)', vs(isset($this), get_defined_vars()));
$this->m_url = $url;
$parsedUrl = parse_url($url);
assert('is_cmap($parsedUrl)', vs(isset($this), get_defined_vars()));
// should not rise for a valid URL
// Protocol (scheme).
if (CMap::hasKey($parsedUrl, "scheme")) {
$this->m_hasProtocol = true;
$this->m_protocol = $parsedUrl["scheme"];
// Normalize by converting to lowercase.
$this->m_normProtocol = CString::toLowerCase($this->m_protocol);
} else {
$this->m_hasProtocol = false;
$this->m_normProtocol = self::DEFAULT_PROTOCOL;
if (!CMap::hasKey($parsedUrl, "host")) {
// Most likely, `parse_url` function has not parsed the host because the protocol (scheme) is absent
// and there are no "//" in the front, so try parsing the host with the default protocol in the URL.
$parsedUrl = parse_url(self::ensureProtocol($url));
assert('is_cmap($parsedUrl)', vs(isset($this), get_defined_vars()));
CMap::remove($parsedUrl, "scheme");
}
}
// Host (domain).
$this->m_hostIsInBrackets = false;
if (CMap::hasKey($parsedUrl, "host")) {
$this->m_host = $parsedUrl["host"];
if (CRegex::find($this->m_host, "/^\\[.*\\]\\z/")) {
// Most likely, an IPv6 enclosed in "[]".
$this->m_hostIsInBrackets = true;
$this->m_host = CString::substr($this->m_host, 1, CString::length($this->m_host) - 2);
}
// Normalize by converting to lowercase.
$this->m_normHost = CString::toLowerCase($this->m_host);
} else {
// Same as invalid.
assert('false', vs(isset($this), get_defined_vars()));
}
// Port.
if (CMap::hasKey($parsedUrl, "port")) {
$this->m_hasPort = true;
$this->m_port = $parsedUrl["port"];
// Should be `int`, but look into the type just in case.
if (is_cstring($this->m_port)) {
$this->m_port = CString::toInt($this->m_port);
}
} else {
$this->m_hasPort = false;
}
// Path.
if (CMap::hasKey($parsedUrl, "path")) {
$this->m_hasPath = true;
$this->m_path = $parsedUrl["path"];
// Normalize by replacing percent-encoded bytes of unreserved characters with their literal equivalents and
// ensuring that all percent-encoded parts are in uppercase.
$pathDelimitersReEsc = CRegex::enterTd(self::$ms_delimiters);
$this->m_normPath = CRegex::replaceWithCallback($this->m_path, "/[^{$pathDelimitersReEsc}]+/", function ($matches) {
return CUrl::enterTdNew(CUrl::leaveTdNew($matches[0]));
});
} else {
$this->m_hasPath = false;
$this->m_normPath = "/";
}
$this->m_urlPath = new CUrlPath($this->m_normPath);
// Query string.
$this->m_hasQuery = false;
if (CMap::hasKey($parsedUrl, "query")) {
$this->m_hasQuery = true;
$this->m_queryString = $parsedUrl["query"];
$parsingWasFruitful;
$this->m_urlQuery = new CUrlQuery($this->m_queryString, $parsingWasFruitful);
if ($parsingWasFruitful) {
$this->m_hasQuery = true;
$this->m_normQueryString = $this->m_urlQuery->queryString(true);
}
}
// Fragment ID.
if (CMap::hasKey($parsedUrl, "fragment")) {
$this->m_hasFragmentId = true;
$this->m_fragmentId = $parsedUrl["fragment"];
// Normalize by replacing percent-encoded bytes of unreserved characters with their literal equivalents and
// ensuring that all percent-encoded parts are in uppercase.
$fiDelimitersReEsc = CRegex::enterTd(self::$ms_delimiters);
$this->m_normFragmentId = CRegex::replaceWithCallback($this->m_fragmentId, "/[^{$fiDelimitersReEsc}]+/", function ($matches) {
// Use the newer flavor of percent-encoding.
return CUrl::enterTdNew(CUrl::leaveTdNew($matches[0]));
});
} else {
//.........这里部分代码省略.........