当前位置: 首页>>代码示例>>PHP>>正文


PHP Gateway::init方法代码示例

本文整理汇总了PHP中Gateway::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Gateway::init方法的具体用法?PHP Gateway::init怎么用?PHP Gateway::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Gateway的用法示例。


在下文中一共展示了Gateway::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: commit

 function commit()
 {
     if (!parent::commit()) {
         return false;
     }
     $id = $this->get('id');
     if ($id === false) {
         return false;
     }
     $fields = array();
     $fields['field_id'] = $id;
     $fields['default_location'] = $this->get('default_location');
     if (!$fields['default_location']) {
         $fields['default_location'] = 'Brisbane, Australia';
     }
     include_once TOOLKIT . '/class.gateway.php';
     $ch = new Gateway();
     $ch->init();
     $ch->setopt('URL', 'http://maps.google.com/maps/geo?q=' . urlencode($fields['default_location']) . '&output=xml&key=' . $this->_engine->Configuration->get('google-api-key', 'map-location-field'));
     $response = $ch->exec();
     if (!preg_match('/<Placemark/i', $response)) {
         $fields['default_location'] = 'Brisbane, Australia';
         $fields['default_location_coords'] = '-27.46, 153.025';
     } else {
         $xml = new SimpleXMLElement($response);
         $coords = preg_split('/,/', $xml->Response->Placemark[0]->Point->coordinates, -1, PREG_SPLIT_NO_EMPTY);
         $fields['default_location_coords'] = $coords[1] . ',' . $coords[0];
     }
     $this->_engine->Database->query("DELETE FROM `tbl_fields_" . $this->handle() . "` WHERE `field_id` = '{$id}' LIMIT 1");
     return $this->_engine->Database->insert($fields, 'tbl_fields_' . $this->handle());
 }
开发者ID:pointybeard,项目名称:maplocationfield,代码行数:31,代码来源:field.maplocation.php

示例2: notify

 function notify($context)
 {
     var_dump($context);
     include_once TOOLKIT . '/class.gateway.php';
     $ch = new Gateway();
     $ch->init();
     $ch->setopt('URL', 'http://rpc.pingomatic.com/');
     $ch->setopt('POST', 1);
     $ch->setopt('CONTENTTYPE', 'text/xml');
     $ch->setopt('HTTPVERSION', '1.0');
     ##Create the XML request
     $xml = new XMLElement('methodCall');
     $xml->appendChild(new XMLElement('methodName', 'weblogUpdates.ping'));
     $params = new XMLElement('params');
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', $this->_Parent->Configuration->get('sitename', 'general')));
     $params->appendChild($param);
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', URL));
     $params->appendChild($param);
     $xml->appendChild($params);
     ####
     $ch->setopt('POSTFIELDS', $xml->generate(true, 0));
     //Attempt the ping
     $ch->exec(GATEWAY_FORCE_SOCKET);
 }
开发者ID:bauhouse,项目名称:sym-extensions,代码行数:26,代码来源:extension.driver.php

示例3: __geocodeAddress

 private function __geocodeAddress($address, $can_return_default = true)
 {
     $coordinates = null;
     $cache_id = md5('maplocationfield_' . $address);
     $cache = new Cacheable(Symphony::Database());
     $cachedData = $cache->check($cache_id);
     // no data has been cached
     if (!$cachedData) {
         include_once TOOLKIT . '/class.gateway.php';
         $ch = new Gateway();
         $ch->init();
         $ch->setopt('URL', '//maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=false&v=3.13');
         $response = json_decode($ch->exec());
         $coordinates = $response->results[0]->geometry->location;
         if ($coordinates && is_object($coordinates)) {
             $cache->write($cache_id, $coordinates->lat . ', ' . $coordinates->lng, $this->_geocode_cache_expire);
             // cache lifetime in minutes
         }
     } else {
         $coordinates = $cachedData['data'];
     }
     // coordinates is an array, split and return
     if ($coordinates && is_object($coordinates)) {
         return $coordinates->lat . ', ' . $coordinates->lng;
     } elseif ($coordinates) {
         return $coordinates;
     } elseif ($return_default) {
         return $this->_default_coordinates;
     }
 }
开发者ID:stuartgpalmer,项目名称:maplocationfield,代码行数:30,代码来源:field.maplocation.php

示例4: search

 private function search()
 {
     $results = array();
     $url = "http://symphonyextensions.com/api/extensions/?keywords={$this->query}&type=&compatible-with={$this->compatibleVersion}&sort=updated&order=desc";
     // create the Gateway object
     $gateway = new Gateway();
     // set our url
     $gateway->init($url);
     // get the raw response, ignore errors
     $response = @$gateway->exec();
     if (!$response) {
         throw new Exception(__("Could not read from %s", array($url)));
     }
     // parse xml
     $xml = @simplexml_load_string($response);
     if (!$xml) {
         throw new Exception(__("Could not parse xml from %s", array($url)));
     }
     $extensions = $xml->xpath('/response/extensions/extension');
     foreach ($extensions as $index => $ext) {
         $name = $ext->xpath('name');
         $id = $ext->xpath('@id');
         $developer = $ext->xpath('developer/name');
         $version = $ext->xpath('version');
         $status = $ext->xpath('status');
         $compatible = $ext->xpath("compatibility/symphony[@version='{$this->version}']");
         $res = array('handle' => (string) $id[0], 'name' => (string) $name[0], 'by' => (string) $developer[0], 'version' => (string) $version[0], 'status' => (string) $status[0], 'compatible' => $compatible != null);
         $results[] = $res;
     }
     // set results array
     $this->_Result['results'] = $results;
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:32,代码来源:content.search.php

示例5: getValuesFromXML

 function getValuesFromXML()
 {
     $xml_location = $this->get('xml_location');
     $cache_life = (int) $this->get('cache');
     require TOOLKIT . '/util.validators.php';
     // allow use of choice params in URL
     $xml_location = preg_replace('/{\\$root}/', URL, $xml_location);
     $xml_location = preg_replace('/{\\$workspace}/', WORKSPACE, $xml_location);
     $doc = new DOMDocument();
     if (preg_match($validators['URI'], $xml_location)) {
         // is a URL, check cache
         $cache_id = md5('xml_selectbox_' . $xml_location);
         $cache = new Cacheable($this->_Parent->_Parent->Database);
         $cachedData = $cache->check($cache_id);
         if (!$cachedData) {
             $ch = new Gateway();
             $ch->init();
             $ch->setopt('URL', $xml_location);
             $ch->setopt('TIMEOUT', 6);
             $xml = $ch->exec();
             $writeToCache = true;
             $cache->write($cache_id, $xml, $cache_life);
             // Cache life is in minutes not seconds e.g. 2 = 2 minutes
             $xml = trim($xml);
             if (empty($xml) && $cachedData) {
                 $xml = $cachedData['data'];
             }
         } else {
             $xml = $cachedData['data'];
         }
         $doc->loadXML($xml);
     } elseif (substr($xml_location, 0, 1) == '/') {
         // relative to DOCROOT
         $doc->load(DOCROOT . $this->get('xml_location'));
     } else {
         // in extension's /xml folder
         $doc->load(EXTENSIONS . '/xml_selectbox/xml/' . $this->get('xml_location'));
     }
     $xpath = new DOMXPath($doc);
     $options = array();
     foreach ($xpath->query($this->get('item_xpath')) as $item) {
         $option = array();
         $option['text'] = $this->run($xpath, $item, $this->get('text_xpath'));
         $option['value'] = $this->run($xpath, $item, $this->get('value_xpath'));
         if (is_null($option['value'])) {
             $option['value'] = $option['text'];
         }
         $options[] = $option;
         if ($item->hasChildNodes()) {
             foreach ($xpath->query('*', $item) as $child) {
                 $text = $this->run($xpath, $child, $this->get('text_xpath'));
                 $value = $this->run($xpath, $child, $this->get('value_xpath'));
                 $options[] = array('text' => $option['text'] . " / " . $text, 'value' => $option['value'] . "-" . (!is_null($value) ? $value : $text));
             }
         }
     }
     return $options;
 }
开发者ID:brendo,项目名称:xml_selectbox,代码行数:58,代码来源:field.xml_selectbox.php

示例6: getValuesFromXML

 function getValuesFromXML()
 {
     $xml_location = $this->get('xml_location');
     $cache_life = (int) $this->get('cache');
     require TOOLKIT . '/util.validators.php';
     // allow use of choice params in URL
     $xml_location = preg_replace('/{\\$root}/', URL, $xml_location);
     $xml_location = preg_replace('/{\\$workspace}/', WORKSPACE, $xml_location);
     if (preg_match($validators['URI'], $xml_location)) {
         // is a URL, check cache
         $cache_id = md5('xml_selectbox_' . $xml_location);
         $cache = new Cacheable($this->_Parent->_Parent->Database);
         $cachedData = $cache->check($cache_id);
         if (!$cachedData) {
             $ch = new Gateway();
             $ch->init();
             $ch->setopt('URL', $xml_location);
             $ch->setopt('TIMEOUT', 6);
             $xml = $ch->exec();
             $writeToCache = true;
             $cache->write($cache_id, $xml, $cache_life);
             // Cache life is in minutes not seconds e.g. 2 = 2 minutes
             $xml = trim($xml);
             if (empty($xml) && $cachedData) {
                 $xml = $cachedData['data'];
             }
         } else {
             $xml = $cachedData['data'];
         }
         $xml = simplexml_load_string($xml);
     } elseif (substr($xml_location, 0, 1) == '/') {
         // relative to DOCROOT
         $xml = simplexml_load_file(DOCROOT . $this->get('xml_location'));
     } else {
         // in extension's /xml folder
         $xml = simplexml_load_file(EXTENSIONS . '/xml_selectbox/xml/' . $this->get('xml_location'));
     }
     $options = array();
     if (!$xml) {
         return $options;
     }
     $items = $xml->xpath($this->get('item_xpath'));
     foreach ($items as $item) {
         $option = array();
         $text_xpath = $item->xpath($this->get('text_xpath'));
         $option['text'] = General::sanitize((string) $text_xpath[0]);
         if ($this->get('value_xpath') != '') {
             $value_xpath = $item->xpath($this->get('value_xpath'));
             $option['value'] = General::sanitize((string) $value_xpath[0]);
         }
         if ((string) $option['value'] == '') {
             $option['value'] = $option['text'];
         }
         $options[] = $option;
     }
     return $options;
 }
开发者ID:bzerangue,项目名称:xml_selectbox,代码行数:57,代码来源:field.xml_selectbox.php

示例7: getValuesFromXML

 function getValuesFromXML()
 {
     $xml_location = $this->get('xml_location');
     if (General::validateURL($xml_location) != '') {
         // is a URL, check cache
         $cache_id = md5($xml_location);
         $cache = new Cacheable($this->_Parent->_Parent->Database);
         $cachedData = $cache->check($cache_id);
         $creation = DateTimeObj::get('c');
         if (!$cachedData || time() - $cachedData['creation'] > 5 * 60) {
             if (Mutex::acquire($cache_id, 6, TMP)) {
                 $ch = new Gateway();
                 $ch->init();
                 $ch->setopt('URL', $xml_location);
                 $ch->setopt('TIMEOUT', 6);
                 $xml = $ch->exec();
                 $writeToCache = true;
                 Mutex::release($cache_id, TMP);
                 $xml = trim($xml);
                 if (empty($xml) && $cachedData) {
                     $xml = $cachedData['data'];
                 }
             } elseif ($cachedData) {
                 $xml = $cachedData['data'];
             }
         } else {
             $xml = $cachedData['data'];
         }
         $xml = simplexml_load_string($xml);
     } elseif (substr($xml_location, 0, 1) == '/') {
         // relative to DOCROOT
         $xml = simplexml_load_file(DOCROOT . $this->get('xml_location'));
     } else {
         // in extension's /xml folder
         $xml = simplexml_load_file(EXTENSIONS . '/xml_selectbox/xml/' . $this->get('xml_location'));
     }
     if (!$xml) {
         return;
     }
     $items = $xml->xpath($this->get('item_xpath'));
     $options = array();
     foreach ($items as $item) {
         $option = array();
         $text_xpath = $item->xpath($this->get('text_xpath'));
         $option['text'] = General::sanitize((string) $text_xpath[0]);
         if ($this->get('value_xpath') != '') {
             $value_xpath = $item->xpath($this->get('value_xpath'));
             $option['value'] = General::sanitize((string) $value_xpath[0]);
         }
         if ((string) $option['value'] == '') {
             $option['value'] = $option['text'];
         }
         $options[] = $option;
     }
     return $options;
 }
开发者ID:bauhouse,项目名称:sym-extensions,代码行数:56,代码来源:field.xml_selectbox.php

示例8: log

 public function log($item_type, $item_id, $action_type, $user_id, $timestamp)
 {
     /**
      * Build author string for the fallback username. If we've got
      * a valid author, grab the full name. Otherwise, determine
      * whether it's an anonymous front-end user or a potentially
      * malicious person trying to access the back end. In the latter
      * case, output the IP or email we captured for reference. 
      */
     $author = AuthorManager::fetchByID($user_id);
     $members = $_SESSION['sym-members'];
     if ($author instanceof Author) {
         $username = $author->getFullName();
     } else {
         if (!empty($members)) {
             if ($members['members-section-id'] && $members['id']) {
                 $members_section = SectionManager::fetch($members['members-section-id'])->get('handle');
                 $members_link = SYMPHONY_URL . '/publish/' . $members_section . '/edit/' . $members['id'] . '/';
                 $username = __('The front-end member %s', array('<a href="' . $members_link . '">' . $members['username'] . '</a>'));
             } else {
                 $username = __('The front-end member %s', array($members['username']));
             }
         } else {
             if (is_numeric($item_type)) {
                 $username = __('A front-end user');
             } else {
                 $username = __('An unidentified user (%s)', array($item_id));
             }
         }
     }
     // Build the $data array for our table columns
     $data = array('item_type' => $item_type, 'item_id' => $item_id, 'action_type' => $action_type, 'user_id' => $user_id, 'timestamp' => $timestamp, 'fallback_username' => $username);
     /**
      * Build the fallback description. Used if the item gets deleted.
      * If the item type is numeric, we're dealing with an entry,
      * otherwise it's some other system element. They're formatted
      * differently.
      */
     if (is_numeric($item_type)) {
         $data['fallback_description'] = Tracker::formatEntryItem($data, TRUE);
     } else {
         $data['fallback_description'] = Tracker::formatElementItem($data, TRUE);
     }
     // Push it into the DB.
     Symphony::Database()->insert($data, 'tbl_tracker_activity');
     // Send the event to the URL if specificed
     $notify_url = Symphony::Configuration()->get('notify_url', 'tracker');
     $notify_urls_array = preg_split('/[\\s,]+/', $notify_url);
     foreach ($notify_urls_array as $url) {
         $gateway = new Gateway();
         $gateway->init($url . "?" . http_build_query($data));
         $gateway->exec();
     }
 }
开发者ID:symphonists,项目名称:tracker,代码行数:54,代码来源:class.tracker.php

示例9: __actionIndex

 public function __actionIndex()
 {
     // Use external data:
     if ($this->_fields['source']) {
         $gateway = new Gateway();
         $gateway->init();
         $gateway->setopt('URL', $this->_fields['source']);
         $gateway->setopt('TIMEOUT', 6);
         // Validate data:
         $this->_status = $this->_importer->validate($gateway->exec());
         if ($this->_status == Importer::__OK__) {
             $this->_importer->commit();
         }
     }
 }
开发者ID:psychoticmeowArchives,项目名称:importmanager,代码行数:15,代码来源:content.import.php

示例10: displayPublishPanel

 function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL)
 {
     if (!isset(Administration::instance()->Page)) {
         return;
     }
     // work out what page we are on, get portions of the URL
     $callback = Administration::instance()->getPageCallback();
     $entry_id = $callback['context']['entry_id'];
     // get an Entry object for this entry
     $entries = EntryManager::fetch($entry_id);
     if (is_array($entries)) {
         $entry = reset($entries);
     }
     // parse dynamic portions of the panel URL
     $url = $this->parseExpression($entry, $this->get('url_expression'));
     if (!preg_match('/^http/', $url)) {
         $url = URL . $url;
     }
     // create Symphony cookie to pass with each request
     $cookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
     session_write_close();
     $gateway = new Gateway();
     $gateway->init($url);
     $gateway->setopt('TIMEOUT', 10);
     $gateway->setopt(CURLOPT_COOKIE, $cookie);
     $gateway->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
     $result = $gateway->exec();
     // a unique name for this panel instance
     $instance_id = $callback['context']['section_handle'] . '_' . $this->get('element_name');
     $container = new XMLELement('div', $result);
     $container->setAttribute('id', $instance_id);
     $container->setAttribute('class', 'inline frame');
     $label = new XMLElement('label', $this->get('label'));
     $label->appendChild($container);
     $wrapper->appendChild($label);
     $asset_index = $this->get('id') * rand(10, 100);
     // add panel-specific styling
     $instance_css = '/html-panel/' . $instance_id . '.css';
     if (file_exists(WORKSPACE . $instance_css)) {
         Administration::instance()->Page->addStylesheetToHead(URL . '/workspace' . $instance_css, 'screen', $asset_index++);
     }
     // add panel-specific behaviour
     $instance_js = '/html-panel/' . $instance_id . '.js';
     if (file_exists(WORKSPACE . $instance_js)) {
         Administration::instance()->Page->addScriptToHead(URL . '/workspace' . $instance_js, $asset_index++);
     }
 }
开发者ID:rc1,项目名称:WebAppsWithCmsStartHere,代码行数:47,代码来源:field.html_panel.php

示例11: download

 private function download()
 {
     // create the Gateway object
     $gateway = new Gateway();
     // set our url
     $gateway->init($this->downloadUrl);
     // get the raw response, ignore errors
     $response = @$gateway->exec();
     if (!$response) {
         throw new Exception(__("Could not read from %s", array($this->downloadUrl)));
     }
     // write the output
     $tmpFile = MANIFEST . '/tmp/' . Lang::createHandle($this->extensionHandle);
     if (!General::writeFile($tmpFile, $response)) {
         throw new Exception(__("Could not write file."));
     }
     // open the zip
     $zip = new ZipArchive();
     if (!$zip->open($tmpFile)) {
         General::deleteFile($tmpFile, true);
         throw new Exception(__("Could not open downloaded file."));
     }
     // get the directory name
     $dirname = $zip->getNameIndex(0);
     // extract
     $zip->extractTo(EXTENSIONS);
     $zip->close();
     // delete tarbal
     General::deleteFile($tmpFile, false);
     // prepare
     $curDir = EXTENSIONS . '/' . $dirname;
     $toDir = $this->getDestinationDirectory();
     // delete current version
     if (!General::deleteDirectory($toDir)) {
         throw new Exception(__('Could not delete %s', array($toDir)));
     }
     // rename extension folder
     if (!@rename($curDir, $toDir)) {
         throw new Exception(__('Could not rename %s to %s', array($curDir, $toDir)));
     }
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:41,代码来源:content.download.php

示例12: notify

 public function notify($context)
 {
     include_once TOOLKIT . '/class.gateway.php';
     $ch = new Gateway();
     $ch->init();
     $ch->setopt('URL', 'http://rpc.pingomatic.com/');
     $ch->setopt('POST', 1);
     $ch->setopt('CONTENTTYPE', 'text/xml');
     $xml = new XMLElement('methodCall');
     $xml->appendChild(new XMLElement('methodName', 'weblogUpdates.ping'));
     $params = new XMLElement('params');
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', Symphony::Configuration()->get('sitename', 'general')));
     $params->appendChild($param);
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', URL));
     $params->appendChild($param);
     $xml->appendChild($params);
     $ch->setopt('POSTFIELDS', $xml->generate(true, 0));
     $ch->exec(GATEWAY_FORCE_SOCKET);
 }
开发者ID:symphonists,项目名称:pingomatic,代码行数:21,代码来源:extension.driver.php

示例13: getExtensionAsXML

 public static function getExtensionAsXML($handle)
 {
     $url = self::URL_ROOT . "extensions/{$handle}/";
     // create the Gateway object
     $gateway = new Gateway();
     // set our url
     $gateway->init($url);
     // get the raw response, ignore errors
     $response = @$gateway->exec();
     if (!$response) {
         throw new Exception(__("Could not read from %s", array($this->downloadUrl)));
     }
     // parse xml
     $xml = @simplexml_load_string($response);
     if (!$xml) {
         throw new Exception(__("Could not parse xml from %s", array($url)));
     }
     $extension = $xml->xpath('/response/extension');
     if (empty($extension)) {
         throw new Exception(__("Could not find extension %s", array($query)));
     }
     return $extension;
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:23,代码来源:class.symphonyextensions.php

示例14: execute

 public function execute(array &$param_pool = null)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     // When DS is called out of the Frontend context, this will enable
     // {$root} and {$workspace} parameters to be evaluated
     if (empty($this->_env)) {
         $this->_env['env']['pool'] = array('root' => URL, 'workspace' => WORKSPACE);
     }
     try {
         require_once TOOLKIT . '/class.gateway.php';
         require_once TOOLKIT . '/class.xsltprocess.php';
         require_once CORE . '/class.cacheable.php';
         $this->dsParamURL = $this->parseParamURL($this->dsParamURL);
         if (isset($this->dsParamXPATH)) {
             $this->dsParamXPATH = $this->__processParametersInString(stripslashes($this->dsParamXPATH), $this->_env);
         }
         // Builds a Default Stylesheet to transform the resulting XML with
         $stylesheet = new XMLElement('xsl:stylesheet');
         $stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform'));
         $output = new XMLElement('xsl:output');
         $output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes'));
         $stylesheet->appendChild($output);
         $template = new XMLElement('xsl:template');
         $template->setAttribute('match', '/');
         $instruction = new XMLElement('xsl:copy-of');
         // Namespaces
         if (isset($this->dsParamNAMESPACES) && is_array($this->dsParamNAMESPACES)) {
             foreach ($this->dsParamNAMESPACES as $name => $uri) {
                 $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : null), $uri);
             }
         }
         // XPath
         $instruction->setAttribute('select', $this->dsParamXPATH);
         $template->appendChild($instruction);
         $stylesheet->appendChild($template);
         $stylesheet->setIncludeHeader(true);
         $xsl = $stylesheet->generate(true);
         // Check for an existing Cache for this Datasource
         $cache_id = self::buildCacheID($this);
         $cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
         $cachedData = $cache->check($cache_id);
         $writeToCache = null;
         $isCacheValid = true;
         $creation = DateTimeObj::get('c');
         // Execute if the cache doesn't exist, or if it is old.
         if (!is_array($cachedData) || empty($cachedData) || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) {
             if (Mutex::acquire($cache_id, $this->dsParamTIMEOUT, TMP)) {
                 $ch = new Gateway();
                 $ch->init($this->dsParamURL);
                 $ch->setopt('TIMEOUT', $this->dsParamTIMEOUT);
                 // Set the approtiate Accept: headers depending on the format of the URL.
                 if ($this->dsParamFORMAT == 'xml') {
                     $ch->setopt('HTTPHEADER', array('Accept: text/xml, */*'));
                 } elseif ($this->dsParamFORMAT == 'json') {
                     $ch->setopt('HTTPHEADER', array('Accept: application/json, */*'));
                 } elseif ($this->dsParamFORMAT == 'csv') {
                     $ch->setopt('HTTPHEADER', array('Accept: text/csv, */*'));
                 }
                 self::prepareGateway($ch);
                 $data = $ch->exec();
                 $info = $ch->getInfoLast();
                 Mutex::release($cache_id, TMP);
                 $data = trim($data);
                 $writeToCache = true;
                 // Handle any response that is not a 200, or the content type does not include XML, JSON, plain or text
                 if ((int) $info['http_code'] != 200 || !preg_match('/(xml|json|csv|plain|text)/i', $info['content_type'])) {
                     $writeToCache = false;
                     $result->setAttribute('valid', 'false');
                     // 28 is CURLE_OPERATION_TIMEOUTED
                     if ($info['curl_error'] == 28) {
                         $result->appendChild(new XMLElement('error', sprintf('Request timed out. %d second limit reached.', $timeout)));
                     } else {
                         $result->appendChild(new XMLElement('error', sprintf('Status code %d was returned. Content-type: %s', $info['http_code'], $info['content_type'])));
                     }
                     return $result;
                 } else {
                     if (strlen($data) > 0) {
                         // Handle where there is `$data`
                         // If it's JSON, convert it to XML
                         if ($this->dsParamFORMAT == 'json') {
                             try {
                                 require_once TOOLKIT . '/class.json.php';
                                 $data = JSON::convertToXML($data);
                             } catch (Exception $ex) {
                                 $writeToCache = false;
                                 $errors = array(array('message' => $ex->getMessage()));
                             }
                         } elseif ($this->dsParamFORMAT == 'csv') {
                             try {
                                 require_once EXTENSIONS . '/remote_datasource/lib/class.csv.php';
                                 $data = CSV::convertToXML($data);
                             } catch (Exception $ex) {
                                 $writeToCache = false;
                                 $errors = array(array('message' => $ex->getMessage()));
                             }
                         } elseif ($this->dsParamFORMAT == 'txt') {
                             $txtElement = new XMLElement('entry');
                             $txtElement->setValue(General::wrapInCDATA($data));
                             $data = $txtElement->generate();
                             $txtElement = null;
//.........这里部分代码省略.........
开发者ID:beaubbe,项目名称:remote_datasource,代码行数:101,代码来源:datasource.remote.php

示例15: __actionEditNormal

 public function __actionEditNormal()
 {
     // Validate -----------------------------------------------------------
     $fields = $_POST['fields'];
     // Name:
     if (!isset($fields['about']['name']) || trim($fields['about']['name']) == '') {
         $this->_errors['name'] = __('Name must not be empty.');
     }
     // Source:
     if (!isset($fields['source']) || trim($fields['source']) == '') {
         $this->_errors['source'] = __('Source must not be empty.');
     } else {
         // Support {$root}
         $evaluated_source = str_replace('{$root}', URL, $fields['source']);
         if (!filter_var($evaluated_source, FILTER_VALIDATE_URL)) {
             $this->_errors['source'] = __('Source is not a valid URL.');
         }
     }
     // Namespaces ---------------------------------------------------------
     if (isset($fields['discover-namespaces']) && $fields['discover-namespaces'] == 'yes' && !isset($this->_errors['source'])) {
         $gateway = new Gateway();
         $gateway->init();
         $gateway->setopt('URL', $evaluated_source);
         $gateway->setopt('TIMEOUT', (int) $fields['timeout']);
         $data = $gateway->exec();
         if ($data === false) {
             $this->_errors['discover-namespaces'] = __('Error loading data from URL, make sure it is valid and that it returns data within 60 seconds.');
         } else {
             preg_match_all('/xmlns:([a-z][a-z-0-9\\-]*)="([^\\"]+)"/i', $data, $matches);
             if (isset($matches[2][0])) {
                 $namespaces = array();
                 if (!is_array($fields['namespaces'])) {
                     $fields['namespaces'] = array();
                 }
                 foreach ($fields['namespaces'] as $namespace) {
                     $namespaces[] = $namespace['name'];
                     $namespaces[] = $namespace['uri'];
                 }
                 foreach ($matches[2] as $index => $uri) {
                     $name = $matches[1][$index];
                     if (in_array($name, $namespaces) or in_array($uri, $namespaces)) {
                         continue;
                     }
                     $namespaces[] = $name;
                     $namespaces[] = $uri;
                     $fields['namespaces'][] = array('name' => $name, 'uri' => $uri);
                 }
             }
         }
     }
     // Included elements:
     if (!isset($fields['included-elements']) || trim($fields['included-elements']) == '') {
         $this->_errors['included-elements'] = __('Included Elements must not be empty.');
     } else {
         try {
             $this->_driver->validateXPath($fields['included-elements'], $fields['namespaces']);
         } catch (Exception $e) {
             $this->_errors['included-elements'] = $e->getMessage();
         }
     }
     // Fields:
     if (isset($fields['fields']) && is_array($fields['fields'])) {
         foreach ($fields['fields'] as $index => $field) {
             try {
                 $this->_driver->validateXPath($field['xpath'], $fields['namespaces']);
             } catch (Exception $e) {
                 if (!isset($this->_errors['fields'])) {
                     $this->_errors['fields'] = array();
                 }
                 $this->_errors['fields'][$index] = $e->getMessage();
             }
         }
     }
     $fields['about']['file'] = isset($this->_fields['about']['file']) ? $this->_fields['about']['file'] : null;
     $fields['about']['created'] = isset($this->_fields['about']['created']) ? $this->_fields['about']['created'] : null;
     $fields['about']['updated'] = isset($this->_fields['about']['updated']) ? $this->_fields['about']['updated'] : null;
     $fields['can-update'] = isset($fields['can-update']) && $fields['can-update'] == 'yes' ? 'yes' : 'no';
     $this->_fields = $fields;
     if (!empty($this->_errors)) {
         $this->_valid = false;
         return;
     }
     // Save ---------------------------------------------------------------
     $name = $this->_handle;
     if (!$this->_driver->setXMLImporter($name, $error, $this->_fields)) {
         $this->_valid = false;
         $this->_errors['other'] = $error;
         return;
     }
     if ($this->_editing) {
         redirect("{$this->_uri}/importers/edit/{$name}/saved/");
     } else {
         redirect("{$this->_uri}/importers/edit/{$name}/created/");
     }
 }
开发者ID:symphonists,项目名称:xmlimporter,代码行数:95,代码来源:content.importers.php


注:本文中的Gateway::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。