本文整理汇总了PHP中JHttpFactory类的典型用法代码示例。如果您正苦于以下问题:PHP JHttpFactory类的具体用法?PHP JHttpFactory怎么用?PHP JHttpFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JHttpFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: downloadPackage
/**
* Downloads a package
*
* @param string $url URL of file to download
* @param string $target Download target filename [optional]
*
* @return mixed Path to downloaded package or boolean false on failure
*
* @since 11.1
*/
public static function downloadPackage($url, $target = false)
{
$config = JFactory::getConfig();
// Capture PHP errors
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// Set user agent
$version = new JVersion();
ini_set('user_agent', $version->getUserAgent('Installer'));
$http = JHttpFactory::getHttp();
$response = $http->get($url);
if (200 != $response->code) {
JLog::add(JText::_('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT'), JLog::WARNING, 'jerror');
return false;
}
if ($response->headers['wrapper_data']['Content-Disposition']) {
$contentfilename = explode("\"", $response->headers['wrapper_data']['Content-Disposition']);
$target = $contentfilename[1];
}
// Set the target path if not given
if (!$target) {
$target = $config->get('tmp_path') . '/' . self::getFilenameFromURL($url);
} else {
$target = $config->get('tmp_path') . '/' . basename($target);
}
// Write buffer to file
JFile::write($target, $response->body);
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// Bump the max execution time because not using built in php zip libs are slow
@set_time_limit(ini_get('max_execution_time'));
// Return the name of the downloaded package
return basename($target);
}
开发者ID:houzhenggang,项目名称:cobalt,代码行数:44,代码来源:helper.php
示例2: get
/**
* Request a page and return it as string.
*
* @param string $url A url to request.
* @param string $method Request method, GET or POST.
* @param string $query Query string. eg: 'option=com_content&id=11&Itemid=125'. <br /> Only use for POST.
* @param array $option An option array to override CURL OPT.
*
* @throws \Exception
* @return mixed If success, return string, or return false.
*/
public static function get($url, $method = 'get', $query = '', $option = array())
{
if ((!function_exists('curl_init') || !is_callable('curl_init')) && ini_get('allow_url_fopen')) {
$return = new Object();
$return->body = file_get_contents($url);
return $return;
}
$options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1", CURLOPT_FOLLOWLOCATION => !ini_get('open_basedir') ? true : false, CURLOPT_SSL_VERIFYPEER => false);
// Merge option
$options = $option + $options;
$http = \JHttpFactory::getHttp(new \JRegistry($options), 'curl');
try {
switch ($method) {
case 'post':
case 'put':
case 'patch':
$result = $http->{$method}(UriHelper::safe($url), $query);
break;
default:
$result = $http->{$method}(UriHelper::safe($url));
break;
}
} catch (\Exception $e) {
return new NullObject();
}
return $result;
}
开发者ID:Biromain,项目名称:windwalker-joomla-rad,代码行数:38,代码来源:CurlHelper.php
示例3: getBalance
private function getBalance()
{
$cache = JFactory::getCache('paypal', 'output');
$cache->setCaching(1);
$cache->setLifeTime($this->params->get('cache', 60) * 60);
$key = md5($this->params->toString());
if (!($result = $cache->get($key))) {
try {
$http = JHttpFactory::getHttp();
$data = array('USER' => $this->params->get('apiuser'), 'PWD' => $this->params->get('apipw'), 'SIGNATURE' => $this->params->get('apisig'), 'VERSION' => '112', 'METHOD' => 'GetBalance');
$result = $http->post($this->url, $data);
} catch (Exception $e) {
JFactory::getApplication()->enqueueMessage($e->getMessage());
return $this->output = JText::_('ERROR');
}
$cache->store($result, $key);
}
if ($result->code != 200) {
$msg = __CLASS__ . ' HTTP-Status ' . JHtml::_('link', 'http://wikipedia.org/wiki/List_of_HTTP_status_codes#' . $result->code, $result->code, array('target' => '_blank'));
JFactory::getApplication()->enqueueMessage($msg, 'error');
return $this->output = JText::_('ERROR');
}
parse_str($result->body, $result->body);
if (!isset($result->body['ACK']) || $result->body['ACK'] != 'Success') {
return $this->output = $result->body['L_SHORTMESSAGE0'];
}
$this->success = true;
$this->output = $result->body['L_AMT0'] . ' ' . $result->body['L_CURRENCYCODE0'];
}
开发者ID:b2un0,项目名称:joomla-plugin-quickicon-paypal,代码行数:29,代码来源:paypal.php
示例4: getFeed
/**
* Method to load a URI into the feed reader for parsing.
*
* @param string $uri The URI of the feed to load. Idn uris must be passed already converted to punycode.
*
* @return JFeedReader
*
* @since 12.3
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function getFeed($uri)
{
// Create the XMLReader object.
$reader = new XMLReader();
// Open the URI within the stream reader.
if (!@$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
// Retry with JHttpFactory that allow using CURL and Sockets as alternative method when available
// Adding a valid user agent string, otherwise some feed-servers returning an error
$options = new \joomla\Registry\Registry();
$options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0');
$connector = JHttpFactory::getHttp($options);
$feed = $connector->get($uri);
if ($feed->code != 200) {
throw new RuntimeException('Unable to open the feed.');
}
// Set the value to the XMLReader parser
if (!$reader->xml($feed->body, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
throw new RuntimeException('Unable to parse the feed.');
}
}
try {
// Skip ahead to the root node.
while ($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT) {
break;
}
}
} catch (Exception $e) {
throw new RuntimeException('Error reading feed.', $e->getCode(), $e);
}
// Setup the appopriate feed parser for the feed.
$parser = $this->_fetchFeedParser($reader->name, $reader);
return $parser->parse();
}
开发者ID:adjaika,项目名称:J3Base,代码行数:45,代码来源:factory.php
示例5: send
/**
* Looks for an update to the extension
*
* @return string
*/
public function send()
{
JSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
$statsModel = $this->getModel();
$data = $statsModel->getData();
// Set up our JRegistry object for the BDHttp connector
$options = new JRegistry();
// Use a 30 second timeout
$options->set('timeout', 30);
try {
$transport = JHttpFactory::getHttp($options);
} catch (Exception $e) {
echo '###Something went wrong! We could not even get a transporter!###';
JFactory::getApplication()->close();
}
// We have to provide the user-agent here, because Joomla! 2.5 won't understand it
// If we add it in the $options...
$request = $transport->post('https://stats.compojoom.com', $data, array('user-agent' => 'LibCompojoom/4.0'));
// There is a bug in curl, that we don't have an work-around in j2.5 That's why we
// will asume here that 100 == 200...
if ($request->code == 200 || JVERSION < 3 && $request->code == 100) {
// Let's update the date
$statsModel->dataGathered();
echo '###All Good!###';
} else {
echo '###Something went wrong!###';
}
// Cut the execution short
JFactory::getApplication()->close();
}
开发者ID:compojoom,项目名称:lib_compojoom,代码行数:35,代码来源:stats.php
示例6: getFeed
/**
* Method to load a URI into the feed reader for parsing.
*
* @param string $uri The URI of the feed to load. Idn uris must be passed already converted to punycode.
*
* @return JFeedReader
*
* @since 12.3
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function getFeed($uri)
{
// Create the XMLReader object.
$reader = new XMLReader();
// Open the URI within the stream reader.
if (!@$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
// If allow_url_fopen is enabled
if (ini_get('allow_url_fopen')) {
// This is an error
throw new RuntimeException('Unable to open the feed.');
} else {
// Retry with JHttpFactory that allow using CURL and Sockets as alternative method when available
$connector = JHttpFactory::getHttp();
$feed = $connector->get($uri);
// Set the value to the XMLReader parser
if (!$reader->xml($feed->body, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
throw new RuntimeException('Unable to parse the feed.');
}
}
}
try {
// Skip ahead to the root node.
while ($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT) {
break;
}
}
} catch (Exception $e) {
throw new RuntimeException('Error reading feed.');
}
// Setup the appopriate feed parser for the feed.
$parser = $this->_fetchFeedParser($reader->name, $reader);
return $parser->parse();
}
开发者ID:grlf,项目名称:eyedock,代码行数:45,代码来源:factory.php
示例7: __construct
/**
* Constructor.
*
* @param JRegistry $options OAuth1Client options object.
* @param JHttp $client The HTTP client object.
* @param JInput $input The input object
* @param JApplicationWeb $application The application object
* @param string $version Specify the OAuth version. By default we are using 1.0a.
*
* @since 13.1
*/
public function __construct(JRegistry $options = null, JHttp $client = null, JInput $input = null, JApplicationWeb $application = null, $version = null)
{
$this->options = isset($options) ? $options : new JRegistry();
$this->client = isset($client) ? $client : JHttpFactory::getHttp($this->options);
$this->input = isset($input) ? $input : JFactory::getApplication()->input;
$this->application = isset($application) ? $application : new JApplicationWeb();
$this->version = isset($version) ? $version : '1.0a';
}
开发者ID:fur81,项目名称:zofaxiopeu,代码行数:19,代码来源:client.php
示例8: getContents
public function getContents($url, $fopen = 0)
{
$hash = md5('getByUrl_' . $url . '_' . $fopen);
if (NNCache::has($hash)) {
return NNCache::get($hash);
}
return NNCache::set($hash, JHttpFactory::getHttp()->get($url)->body);
}
开发者ID:naka211,项目名称:malerfirmaet,代码行数:8,代码来源:functions.php
示例9: __construct
/**
*
*/
public function __construct()
{
jimport('joomla.http.factory');
if (!class_exists('JHttpFactory')) {
throw new BadFunctionCallException(JchPlatformUtility::translate('JHttpFactory not present. Please upgrade your version of Joomla. Exiting plugin...'));
}
$aOptions = array('follow_location' => true);
$oOptions = new JRegistry($aOptions);
$this->oHttpAdapter = JHttpFactory::getAvailableDriver($oOptions);
}
开发者ID:naka211,项目名称:myloyal,代码行数:13,代码来源:http.php
示例10: downloadPackage
/**
* Downloads a package
*
* @param string $url URL of file to download
* @param string $target Download target filename [optional]
*
* @return mixed Path to downloaded package or boolean false on failure
*
* @since 11.1
*/
public static function downloadPackage($url, $target = false)
{
$config = JFactory::getConfig();
// Capture PHP errors
$php_errormsg = 'Error Unknown';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// Set user agent
$version = new JVersion();
ini_set('user_agent', $version->getUserAgent('Installer'));
$http = JHttpFactory::getHttp();
// load installer plugins, and allow url and headers modification
$headers = array();
JPluginHelper::importPlugin('installer');
$dispatcher = JDispatcher::getInstance();
$results = $dispatcher->trigger('onInstallerBeforePackageDownload', array(&$url, &$headers));
try {
$response = $http->get($url, $headers);
} catch (Exception $exc) {
$response = null;
}
if (is_null($response)) {
JError::raiseWarning(42, JText::_('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT'));
return false;
}
if (302 == $response->code && isset($response->headers['Location'])) {
return self::downloadPackage($response->headers['Location']);
} elseif (200 != $response->code) {
if ($response->body === '') {
$response->body = $php_errormsg;
}
JError::raiseWarning(42, JText::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $response->body));
return false;
}
// Parse the Content-Disposition header to get the file name
if (isset($response->headers['Content-Disposition']) && preg_match("/\\s*filename\\s?=\\s?(.*)/", $response->headers['Content-Disposition'], $parts)) {
$target = trim(rtrim($parts[1], ";"), '"');
}
// Set the target path if not given
if (!$target) {
$target = $config->get('tmp_path') . '/' . self::getFilenameFromURL($url);
} else {
$target = $config->get('tmp_path') . '/' . basename($target);
}
// Write buffer to file
JFile::write($target, $response->body);
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// bump the max execution time because not using built in php zip libs are slow
@set_time_limit(ini_get('max_execution_time'));
// Return the name of the downloaded package
return basename($target);
}
开发者ID:jimyb3,项目名称:mathematicalteachingsite,代码行数:63,代码来源:helper.php
示例11: getContents
public function getContents($url, $timeout = 20)
{
$hash = md5('getContents_' . $url);
if (NNCache::has($hash)) {
return NNCache::get($hash);
}
try {
$content = JHttpFactory::getHttp()->get($url, null, $timeout)->body;
} catch (RuntimeException $e) {
return '';
}
return NNCache::set($hash, $content);
}
开发者ID:knigherrant,项目名称:decopatio,代码行数:13,代码来源:functions.php
示例12: requestRest
/**
* Get a single row
*
* @return step object
*/
public function requestRest($task = 'total', $table = false)
{
$http = JHttpFactory::getHttp();
$data = $this->getRestData();
// Getting the total
$data['task'] = $task;
$data['table'] = $table != false ? $table : '';
$request = $http->get($this->params->rest_hostname . '/index.php', $data);
$code = $request->code;
if ($code == 500) {
throw new Exception('COM_REDMIGRATOR_REDMIGRATOR_ERROR_REST_REQUEST');
} else {
return $code == 200 || $code == 301 ? $request->body : $code;
}
}
开发者ID:grlf,项目名称:eyedock,代码行数:20,代码来源:rest.php
示例13: _closureCompiler
/**
* @param $code
* @return string
* @throws Exception
*/
private function _closureCompiler($code)
{
if (JString::strlen($code) > 200000) {
return $code;
}
if (!class_exists('JHttpFactory')) {
return $code;
}
$response = JHttpFactory::getHttp()->post($this->_url, array('js_code' => $code, 'output_info' => 'compiled_code', 'output_format' => 'text', 'compilation_level' => 'WHITESPACE_ONLY'), array('Content-type' => 'application/x-www-form-urlencoded', 'Connection' => 'close'), 15);
$result = $response->body;
if (preg_match('/^Error\\(\\d\\d?\\):/', $result)) {
throw new Exception('Google JS Minify: ' . $result);
}
return $result;
}
开发者ID:Cheren,项目名称:JBlank,代码行数:20,代码来源:minify.js.php
示例14: testGet
/**
* Method to test get().
*
* @return void
*
* @covers Windwalker\Helper\CurlHelper::get
*/
public function testGet()
{
$url = 'http://example.com/';
$http = \JHttpFactory::getHttp(new \JRegistry($this->options), 'curl');
// Test with Restful Api 'GET'
$helperOutput = CurlHelper::get($url);
$jHttpOutput = $http->get($url);
$this->assertEquals($helperOutput->code, $jHttpOutput->code);
$this->assertEquals($helperOutput->body, $jHttpOutput->body);
// Test with Restful Api 'POST'
$helperOutput = CurlHelper::get($url, 'post', array('key' => 'value'), array('testHeader'));
$jHttpOutput = $http->post($url, array('key' => 'value'), array('testHeader'));
$this->assertEquals($helperOutput->code, $jHttpOutput->code);
$this->assertEquals($helperOutput->body, $jHttpOutput->body);
}
开发者ID:Biromain,项目名称:windwalker-joomla-rad,代码行数:22,代码来源:CurlHelperTest.php
示例15: downloadPackage
/**
* Downloads a package
*
* @param string $url URL of file to download
* @param string $target Download target filename [optional]
*
* @return mixed Path to downloaded package or boolean false on failure
*
* @since 11.1
*/
public static function downloadPackage($url, $target = false)
{
$config = JFactory::getConfig();
// Capture PHP errors
$php_errormsg = 'Error Unknown';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// Set user agent
$version = new JVersion();
ini_set('user_agent', $version->getUserAgent('Installer'));
$http = JHttpFactory::getHttp();
try {
$response = $http->get($url);
} catch (Exception $exc) {
$response = null;
}
if (is_null($response)) {
JError::raiseWarning(42, JText::_('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT'));
return false;
}
if (302 == $response->code && isset($response->headers['Location'])) {
return self::downloadPackage($response->headers['Location']);
} elseif (200 != $response->code) {
if ($response->body === '') {
$response->body = $php_errormsg;
}
JError::raiseWarning(42, JText::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $response->body));
return false;
}
if (isset($response->headers['Content-Disposition'])) {
$contentfilename = explode("\"", $response->headers['Content-Disposition']);
$target = $contentfilename[1];
}
// Set the target path if not given
if (!$target) {
$target = $config->get('tmp_path') . '/' . self::getFilenameFromURL($url);
} else {
$target = $config->get('tmp_path') . '/' . basename($target);
}
// Write buffer to file
JFile::write($target, $response->body);
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// bump the max execution time because not using built in php zip libs are slow
@set_time_limit(ini_get('max_execution_time'));
// Return the name of the downloaded package
return basename($target);
}
开发者ID:NavaINT1876,项目名称:ccustoms,代码行数:58,代码来源:helper.php
示例16: getEvents
/**
* Get the events from the google calendar api
*
* @param array $options The query parameter options
*
* @return mixed
*
* @throws UnexpectedValueException
*/
protected function getEvents($options)
{
$defaultOptions = array('orderBy' => 'startTime', 'singleEvents' => 'true');
$options = array_merge($defaultOptions, $options);
// Create an instance of a default Http object.
$http = JHttpFactory::getHttp();
$url = 'https://www.googleapis.com/calendar/v3/calendars/' . urlencode($this->calendarId) . '/events?key=' . urlencode($this->apiKey) . '&' . http_build_query($options);
$response = $http->get($url);
$data = json_decode($response->body);
if ($data && isset($data->items)) {
return $data->items;
} elseif ($data) {
return array();
}
throw new UnexpectedValueException("Unexpected data received from Google: `{$response->body}`.");
}
开发者ID:nternetinspired,项目名称:joomlade,代码行数:25,代码来源:helper.php
示例17: downloadPackage
/**
* Downloads a package
*
* @param string $url URL of file to download
* @param mixed $target Download target filename or false to get the filename from the URL
*
* @return string|boolean Path to downloaded package or boolean false on failure
*
* @since 3.1
*/
public static function downloadPackage($url, $target = false)
{
// Capture PHP errors
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// Set user agent
$version = new JVersion();
ini_set('user_agent', $version->getUserAgent('Installer'));
// Load installer plugins, and allow url and headers modification
$headers = array();
JPluginHelper::importPlugin('installer');
$dispatcher = JEventDispatcher::getInstance();
$results = $dispatcher->trigger('onInstallerBeforePackageDownload', array(&$url, &$headers));
try {
$response = JHttpFactory::getHttp()->get($url, $headers);
} catch (RuntimeException $exception) {
JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $exception->getMessage()), JLog::WARNING, 'jerror');
return false;
}
if (302 == $response->code && isset($response->headers['Location'])) {
return self::downloadPackage($response->headers['Location']);
} elseif (200 != $response->code) {
JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $response->code), JLog::WARNING, 'jerror');
return false;
}
// Parse the Content-Disposition header to get the file name
if (isset($response->headers['Content-Disposition']) && preg_match("/\\s*filename\\s?=\\s?(.*)/", $response->headers['Content-Disposition'], $parts)) {
$flds = explode(';', $parts[1]);
$target = trim($flds[0], '"');
}
$tmpPath = JFactory::getConfig()->get('tmp_path');
// Set the target path if not given
if (!$target) {
$target = $tmpPath . '/' . self::getFilenameFromUrl($url);
} else {
$target = $tmpPath . '/' . basename($target);
}
// Write buffer to file
JFile::write($target, $response->body);
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// Bump the max execution time because not using built in php zip libs are slow
@set_time_limit(ini_get('max_execution_time'));
// Return the name of the downloaded package
return basename($target);
}
开发者ID:eshiol,项目名称:joomla-cms,代码行数:56,代码来源:helper.php
示例18: sendStats
protected function sendStats()
{
$http = JHttpFactory::getHttp();
$data = array('unique_id' => $this->params->get('unique_id'), 'php_version' => PHP_VERSION, 'db_type' => $this->db->name, 'db_version' => $this->db->getVersion(), 'cms_version' => JVERSION, 'server_os' => php_uname('s') . ' ' . php_uname('r'));
$uri = new JUri('http://jstats.dongilbert.net/submit');
try {
// Don't let the request take longer than 2 seconds to avoid page timeout issues
$status = $http->post($uri, $data, null, 2);
if ($status->code === 200) {
$this->writeCacheFile();
}
} catch (UnexpectedValueException $e) {
// There was an error sending stats. Should we do anything?
} catch (RuntimeException $e) {
// There was an error connecting to the server or in the post request
}
}
开发者ID:roland-d,项目名称:jstats-plugin,代码行数:17,代码来源:jstats.php
示例19: sendSms
private function sendSms($entry)
{
$params = $this->params;
$user = $params->get("user");
$password = $params->get("password");
$from = $params->get("from");
$to = $params->get("to");
$message = $this->parseMessageBody($params->get("message"), $entry);
$queryparams = http_build_query(array("action" => "sendsms", "user" => $user, "password" => $password, "from" => $from, "to" => $to, "text" => $message));
$response = JHttpFactory::getHttp()->get("http://www.smsglobal.com/http-api.php?" . $queryparams);
if ($response->code == "200" && stripos($response->body, "OK: 0") !== -1) {
return true;
} else {
error_log("failed -- don't save to database");
return false;
}
}
开发者ID:digitalgarage,项目名称:simplelogger,代码行数:17,代码来源:sendlogs.php
示例20: display
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return $this
*/
public function display($cachable = false, $urlparams = [])
{
JFactory::getApplication()->mimeType = 'application/json';
$label = (object) ['label' => JText::_('COM_TRACKERSTATS_WIKI_LABEL_EDITS')];
try {
$response = JHttpFactory::getHttp()->get('https://docs.joomla.org/api.php?action=query&list=allusers&format=json&auexcludegroup=bot&aulimit=100&auprop=editcount&auactiveusers=', ['Content-type: application/json']);
} catch (Exception $e) {
// Error handling?
echo json_encode([[[]], [], [$label], JText::_('COM_TRACKERSTATS_WIKI_LABEL_EDITS_BY_CONTRIBUTOR_IN_PAST_30_DAYS')]);
return $this;
}
// Getting results
$users = json_decode($response->body);
// Convert to array for processing
$workArray = [];
$totalEditsArray = [];
foreach ($users->query->allusers as $user) {
if ($user->name == 'MediaWiki default') {
continue;
}
$workArray[$user->name] = $user->recenteditcount;
$totalEditsArray[$user->name] = $user->editcount;
}
asort($workArray, SORT_NUMERIC);
// Slice the last 25 entries
$maxCount = 25;
$arrayCount = count($workArray);
if ($arrayCount > $maxCount) {
$sliceStart = $arrayCount - $maxCount;
$workArray = array_slice($workArray, $sliceStart, $maxCount);
}
$people = [];
$edits = [];
$i = 0;
foreach ($workArray as $k => $v) {
if ($v > 0 && $i++ < $maxCount) {
$edits[] = $v;
$people[] = JText::sprintf('COM_TRACKERSTATS_WIKI_CHART_PERSON_LABEL', $k, $totalEditsArray[$k]);
}
}
// Send the response.
echo json_encode([[$edits], $people, [$label], JText::_('COM_TRACKERSTATS_WIKI_LABEL_EDITS_BY_CONTRIBUTOR_IN_PAST_30_DAYS')]);
return $this;
}
开发者ID:joomla-projects,项目名称:com_trackerstats,代码行数:52,代码来源:wiki.json.php
注:本文中的JHttpFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论