本文整理汇总了PHP中FD::connector方法的典型用法代码示例。如果您正苦于以下问题:PHP FD::connector方法的具体用法?PHP FD::connector怎么用?PHP FD::connector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FD
的用法示例。
在下文中一共展示了FD::connector方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResult
public function getResult($queries = array())
{
$this->setQueries($queries);
// There is 2 parts to this
// nearbysearch
// textsearch
$nearbysearchUrl = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json';
$textsearchUrl = 'https://maps.googleapis.com/maps/api/place/textsearch/json';
$nearbysearchOptions = array('location' => $this->queries['location'], 'radius' => $this->queries['radius'], 'key' => $this->queries['key'], 'keyword' => $this->queries['keyword']);
$textsearchOptions = array('query' => $this->queries['query'], 'key' => $this->queries['key']);
$connector = FD::connector();
$connector->setMethod('GET');
$connector->addUrl($nearbysearchUrl . '?' . http_build_query($nearbysearchOptions));
if (!empty($this->queries['query'])) {
$connector->addUrl($textsearchUrl . '?' . http_build_query($textsearchOptions));
}
$connector->execute();
$results = $connector->getResults();
$venues = array();
foreach ($results as $result) {
$obj = json_decode($result->contents);
foreach ($obj->results as $row) {
$obj = new SocialLocationData();
$obj->latitude = $row->geometry->location->lat;
$obj->longitude = $row->geometry->location->lng;
$obj->name = $row->name;
$obj->address = isset($row->formatted_address) ? $row->formatted_address : '';
$obj->fulladdress = !empty($obj->address) ? $obj->name . ', ' . $obj->address : '';
$venues[$row->id] = $obj;
}
}
$venues = array_values($venues);
return $venues;
}
示例2: getLanguages
/**
* Retrieves a list of languages from API server
*
* @since 1.0
* @access public
*/
public function getLanguages()
{
// Check for request forgeries here
FD::checkToken();
// Get the stored key
$key = $this->config->get('general.key');
// Start connecting
$connector = FD::connector();
$connector->addUrl(SOCIAL_UPDATER_LANGUAGE);
$connector->setMethod('POST');
$connector->addQuery('key', $key);
$connector->connect();
$result = $connector->getResult(SOCIAL_UPDATER_LANGUAGE);
$obj = json_decode($result);
if (!$obj || !isset($obj->code) || $obj->code != 200) {
return $this->view->call(__FUNCTION__, $obj);
}
// Go through each of the languages now
foreach ($obj->languages as $language) {
// Check if the language was previously installed thorugh our system.
// If it does, load it instead of overwriting it.
$table = FD::table('Language');
$exists = $table->load(array('locale' => $language->locale));
// We do not want to bind the id
unset($language->id);
// Since this is the retrieval, the state should always be disabled
if (!$exists) {
$table->state = SOCIAL_STATE_UNPUBLISHED;
}
// If the language file has been installed, we want to check the last updated time
if ($exists && $table->state == SOCIAL_LANGUAGES_INSTALLED) {
// Then check if the language needs to be updated. If it does, update the ->state to SOCIAL_LANGUAGES_NEEDS_UPDATING
// We need to check if the language updated time is greater than the local updated time
$languageTime = strtotime($language->updated);
$localLanguageTime = strtotime($table->updated);
if ($languageTime > $localLanguageTime && $table->state == SOCIAL_LANGUAGES_INSTALLED) {
$table->state = SOCIAL_LANGUAGES_NEEDS_UPDATING;
}
}
// Set the title
$table->title = $language->title;
// Set the locale
$table->locale = $language->locale;
// Set the translator
$table->translator = $language->translator;
// Set the updated time
$table->updated = $language->updated;
// Update the progress
$table->progress = $language->progress;
// Update the table with the appropriate params
$params = FD::registry();
$params->set('download', $language->download);
$params->set('md5', $language->md5);
$table->params = $params->toString();
$table->store();
}
return $this->view->call(__FUNCTION__, $obj);
}
示例3: getResult
public function getResult($queries = array())
{
$this->setQueries($queries);
// If the latitude and longitude isn't set, we need to unset it here.
if (!$this->queries['ll']) {
unset($this->queries['ll']);
}
$url = $this->buildUrl();
$connector = FD::connector();
$connector->setMethod('GET');
$connector->addUrl($url);
if (!empty($this->queries['query'])) {
$this->setQuery('intent', 'global');
$url = $this->buildUrl();
$connector->addUrl($url);
}
$connector->execute();
$result = $connector->getResult($url);
// Stores the list of available venues
$venues = array();
if (!$result) {
return $venues;
}
$result = json_decode($result);
if (!isset($result->meta) || !isset($result->meta->code)) {
$this->setError(JText::_('COM_EASYSOCIAL_LOCATION_PROVIDERS_FOURSQUARE_UNKNOWN_ERROR'));
return $venues;
}
// If foursquare returns an error, we should log this down
if ($result->meta->code != 200) {
$this->setError($result->meta->errorDetail);
return $venues;
}
// If there is no venues, skip this altogether.
if (!$result->response->venues) {
return $venues;
}
foreach ($result->response->venues as $item) {
$venue = new SocialLocationData();
$venue->latitude = $item->location->lat;
$venue->longitude = $item->location->lng;
$venue->address = isset($item->location->address) ? $item->location->address : '';
$venue->name = $item->name;
$venue->fulladdress = $venue->address ? $venue->name . ', ' . $venue->address : '';
$venues[] = $venue;
}
return $venues;
}
示例4: crawl
/**
* Invoke the crawling.
*
* @since 1.0
* @access public
*/
public function crawl($url)
{
// Ensure that urls always contains a protocol
$url = $this->normalizeUrl($url);
// Load up the connector first.
$connector = FD::connector();
$connector->addUrl($url);
$connector->connect();
// Get the result and parse them.
$content = $connector->getResult($url);
// Normalize the contents
$this->contents = $this->normalizeContent($url, $content);
// Get the final url, if there's any redirection.
$originalUrl = $url;
$url = $connector->getFinalUrl($url);
$this->parse($originalUrl, $url);
return $this;
}
示例5: getResult
public function getResult($queries = array())
{
$this->setQueries($queries);
// If address is empty, then we only do a latlng search
// If address is not empty, then we do an address search
$options = array();
if (!empty($this->queries['key'])) {
$options['key'] = $this->queries['key'];
}
if (!empty($this->queries['address'])) {
$options['address'] = $this->queries['address'];
} else {
$options['latlng'] = $this->queries['latlng'];
}
$connector = FD::connector();
$connector->setMethod('GET');
$connector->addUrl($this->url . '?' . http_build_query($options));
$connector->execute();
$result = $connector->getResult();
$result = json_decode($result);
if (!isset($result->status) || $result->status != 'OK') {
$error = isset($result->error_message) ? $result->error_message : JText::_('COM_EASYSOCIAL_LOCATION_PROVIDERS_MAPS_UNKNOWN_ERROR');
$this->setError($error);
return array();
}
$venues = array();
foreach ($result->results as $row) {
$obj = new SocialLocationData();
$obj->latitude = $row->geometry->location->lat;
$obj->longitude = $row->geometry->location->lng;
$obj->name = $row->address_components[0]->long_name;
$obj->address = $row->formatted_address;
$obj->fulladdress = $row->formatted_address;
$venues[] = $obj;
}
return $venues;
}
示例6: onRegisterOAuthAfterSave
/**
* Processes before the user account is created when user signs in with oauth.
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function onRegisterOAuthAfterSave(&$data, &$oauthClient, SocialUser &$user)
{
$cover = isset($data['cover']) ? $data['cover'] : '';
// If cover is not provided, skip this.
if (!$cover) {
return;
}
// Get the cover URL
$coverUrl = $cover->url;
// Get the session object.
$uid = SocialFieldsUserCoverHelper::genUniqueId($this->inputName);
// Get the user object.
$user = FD::user();
// Store the cover internally first.
$tmpPath = SOCIAL_TMP . '/' . $uid . '_cover';
$tmpFile = $tmpPath . '/' . $uid;
// Now we need to get the image data.
$connector = FD::connector();
$connector->addUrl($coverUrl);
$connector->connect();
$contents = $connector->getResult($coverUrl);
jimport('joomla.filesystem.file');
if (!JFile::write($tmpFile, $contents)) {
FD::logError(__FILE__, __LINE__, 'AVATAR: Unable to store oauth cover to tmp folder, ' . $tmpPath);
return;
}
// Ensure that the image is valid.
if (!SocialFieldsUserCoverHelper::isValid($tmpFile)) {
FD::logError(__FILE__, __LINE__, 'AVATAR: Invalid image provided for cover ' . $tmpFile);
return;
}
// Create the default album for this cover.
$album = SocialFieldsUserCoverHelper::getDefaultAlbum($user->id);
// Once the album is created, create the photo object.
$photo = SocialFieldsUserCoverHelper::createPhotoObject($user->id, SOCIAL_TYPE_USER, $album->id, $data['oauth_id'], true);
// Set the new album with the photo as the cover.
$album->cover_id = $photo->id;
$album->store();
// Generates a unique name for this image.
$name = md5($data['oauth_id'] . $this->inputName . FD::date()->toMySQL());
// Load our own image library
$image = FD::image();
// Load up the file.
$image->load($tmpFile, $name);
// Load up photos library
$photos = FD::get('Photos', $image);
$storage = $photos->getStoragePath($album->id, $photo->id);
// Create avatars
$sizes = $photos->create($storage);
foreach ($sizes as $size => $path) {
// Now we will need to store the meta for the photo.
$meta = SocialFieldsUserCoverHelper::createPhotoMeta($photo, $size, $path);
}
// Once all is done, we just need to update the cover table so the user
// will start using this cover now.
$coverTable = FD::table('Cover');
$state = $coverTable->load(array('uid' => $user->id, 'type' => SOCIAL_TYPE_USER));
// User does not have a cover.
if (!$state) {
$coverTable->uid = $user->id;
$coverTable->type = SOCIAL_TYPE_USER;
$coverTable->y = $cover->offset_y;
}
// Set the cover to pull from photo
$coverTable->setPhotoAsCover($photo->id);
// Save the cover.
$coverTable->store();
}
示例7: install
/**
* Installs a language file
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function install()
{
$params = $this->getParams();
// Get the api key
$config = FD::config();
$key = $config->get('general.key');
// Get the download url
$url = $params->get('download');
if (!$url) {
$this->setError(JText::_('COM_EASYSOCIAL_LANGUAGES_DOWNLOAD_URL_EMPTY'));
return false;
}
// Download the language file
$connector = FD::connector();
$connector->addUrl($url);
$connector->setMethod('POST');
$connector->addQuery('key', $key);
$connector->connect();
// Get the contents of the zip file
$result = $connector->getResult($url);
// Create a temporary storage for this file
$md5 = md5(FD::date()->toSql());
$storage = SOCIAL_TMP . '/' . $md5 . '.zip';
$state = JFile::write($storage, $result);
// Set the path for the extracted folder
$extractedFolder = SOCIAL_TMP . '/' . $md5;
jimport('joomla.filesystem.archive');
// Extract the language's archive file
$state = JArchive::extract($storage, $extractedFolder);
// Throw some errors when we are unable to extract the zip file.
if (!$state) {
return false;
}
$metaPath = $extractedFolder . '/meta.json';
// Read the meta data file
$obj = FD::makeObject($metaPath);
// Get the resources
$resources = $obj->resources;
foreach ($resources as $file) {
// Get the correct path based on the meta's path
$languageFolder = $this->getPath($file->path);
$languageFolder = $languageFolder . '/language';
// Construct the absolute path
$path = $languageFolder . '/' . $this->locale;
// If the folder does not exist, create it first
if (!JFolder::exists($path)) {
JFolder::create($path);
}
// Set the destination path
$destFile = $path . '/' . $this->locale . '.' . $file->title;
$sourceFile = $extractedFolder . '/' . $file->path . '/' . $this->locale . '.' . $file->title;
// Try to copy the file
$state = JFile::copy($sourceFile, $destFile);
if (!$state) {
$this->setError(JText::_('COM_EASYSOCIAL_LANGUAGES_ERROR_COPYING_FILES'));
return false;
}
}
// After everything is copied, ensure that the extracted folder is deleted to avoid dirty filesystem
JFile::delete($storage);
JFolder::delete($extractedFolder);
// Once the language files are copied accordingly, update the state
$this->state = SOCIAL_LANGUAGES_INSTALLED;
return $this->store();
}