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


PHP Gateway::setopt方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: __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

示例6: 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

示例7: __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

示例8: 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

示例9: 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

示例10: getSectionAttachments

 /**
  * Builds the attachment section of a multipart email.
  *
  * Will return a string containing the section. Can be used to send to
  * an email server directly.
  *
  * @throws EmailGatewayException
  * @throws Exception
  * @return string
  */
 protected function getSectionAttachments()
 {
     $output = '';
     foreach ($this->_attachments as $key => $file) {
         $tmp_file = false;
         // If the attachment is a URL, download the file to a temporary location.
         // This prevents downloading the file twice - once for info, once for data.
         if (filter_var($file['file'], FILTER_VALIDATE_URL)) {
             $gateway = new Gateway();
             $gateway->init($file['file']);
             $gateway->setopt('TIMEOUT', 30);
             $file_content = @$gateway->exec();
             $tmp_file = tempnam(TMP, 'attachment');
             General::writeFile($tmp_file, $file_content, Symphony::Configuration()->get('write_mode', 'file'));
             $original_filename = $file['file'];
             $file['file'] = $tmp_file;
             // Without this the temporary filename will be used. Ugly!
             if (is_null($file['filename'])) {
                 $file['filename'] = basename($original_filename);
             }
         } else {
             $file_content = @file_get_contents($file['file']);
         }
         if ($file_content !== false && !empty($file_content)) {
             $output .= $this->boundaryDelimiterLine('multipart/mixed') . $this->contentInfoString($file['mime-type'], $file['file'], $file['filename'], $file['charset']) . EmailHelper::base64ContentTransferEncode($file_content);
         } else {
             if (!$tmp_file === false) {
                 $filename = $original_filename;
             } else {
                 $filename = $file['file'];
             }
             throw new EmailGatewayException(__('The content of the file `%s` could not be loaded.', array($filename)));
         }
         if (!$tmp_file === false) {
             General::deleteFile($tmp_file);
         }
     }
     return $output;
 }
开发者ID:jurajkapsz,项目名称:symphony-2,代码行数:49,代码来源:class.emailgateway.php

示例11: getVideoFeed

 public static function getVideoFeed($video_id)
 {
     // Fetch document:
     $gateway = new Gateway();
     $gateway->init();
     $gateway->setopt('URL', "http://gdata.youtube.com/feeds/api/videos/{$video_id}");
     $gateway->setopt('TIMEOUT', 10);
     $data = $gateway->exec();
     $info = $gateway->getInfoLast();
     if ($data == "Invalid id" || empty($data) || $info['http_code'] != 200) {
         return null;
     }
     return DOMDocument::loadXML($data);
 }
开发者ID:rainerborene,项目名称:youtube_videos,代码行数:14,代码来源:field.youtube_video.php

示例12: __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

示例13: __isValidURL

 /**
  * Given a `$url` and `$timeout`, this function will use the `Gateway`
  * class to determine that it is a valid URL and returns successfully
  * before the `$timeout`. If it does not, an error message will be
  * returned, otherwise true.
  *
  * @since Symphony 2.3
  * @param string $url
  * @param integer $timeout
  *  If not provided, this will default to 6 seconds
  * @param string $error
  *  If this function returns false, this variable will be populated with the
  *  error message.
  * @return array|boolean
  *  Returns an array with the 'data' if it is a valid URL, otherwise a string
  *  containing an error message.
  */
 public static function __isValidURL($url, $timeout = 6, &$error)
 {
     if (!filter_var($url, FILTER_VALIDATE_URL)) {
         $error = __('Invalid URL');
         return false;
     }
     // Check that URL was provided
     $gateway = new Gateway();
     $gateway->init($url);
     $gateway->setopt('TIMEOUT', $timeout);
     $data = $gateway->exec();
     $info = $gateway->getInfoLast();
     // 28 is CURLE_OPERATION_TIMEDOUT
     if ($info['curl_error'] == 28) {
         $error = __('Request timed out. %d second limit reached.', array($timeout));
         return false;
     } elseif ($data === false || $info['http_code'] != 200) {
         $error = __('Failed to load URL, status code %d was returned.', array($info['http_code']));
         return false;
     }
     return array('data' => $data);
 }
开发者ID:jurajkapsz,项目名称:symphony-2,代码行数:39,代码来源:content.blueprintsdatasources.php

示例14: fetch

 /**
  * Given a URL, Format and Timeout, this function will initalise
  * Symphony's Gateway class to retrieve the contents of the URL.
  *
  * @param string $url
  * @param string $format
  * @param integer $timeout
  * @return array
  */
 public static function fetch($url, $format, $timeout)
 {
     $ch = new Gateway();
     $ch->init($url);
     $ch->setopt('TIMEOUT', $timeout);
     // Set the approtiate Accept: headers depending on the format of the URL.
     if ($transformer = self::getTransformer($format)) {
         $accepts = $transformer->accepts();
         $ch->setopt('HTTPHEADER', array('Accept: ' . $accepts));
     }
     // use static here to allow late static binding
     // see http://php.net/manual/en/language.oop5.late-static-bindings.php
     static::prepareGateway($ch);
     return array(trim($ch->exec()), $ch->getInfoLast());
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:24,代码来源:datasource.remote.php

示例15: sendEmail

 public function sendEmail($entry_id, $template_id)
 {
     $template = $this->getTemplate($template_id);
     $conditions = $this->getConditions($template_id);
     $data = $this->getData($template, $entry_id);
     $xpath = new DOMXPath($data);
     $email = null;
     // Find condition:
     foreach ($conditions as $condition) {
         if (empty($condition['expression'])) {
             $email = $condition;
             break;
         }
         $results = $xpath->query($condition['expression']);
         if ($results->length > 0) {
             $email = $condition;
             break;
         }
     }
     if (is_null($email)) {
         return;
     }
     // Replace {xpath} queries:
     foreach ($email as $key => $value) {
         $content = $email[$key];
         $replacements = array();
         // Find queries:
         preg_match_all('/\\{[^\\}]+\\}/', $content, $matches);
         // Find replacements:
         foreach ($matches[0] as $match) {
             $results = @$xpath->query(trim($match, '{}'));
             if ($results->length) {
                 $items = array();
                 foreach ($results as $item) {
                     if (!isset($item->nodeValue)) {
                         continue;
                     }
                     $items[] = $item->nodeValue;
                 }
                 $replacements[$match] = implode(', ', $items);
             } else {
                 $replacements[$match] = '';
             }
         }
         $content = str_replace(array_keys($replacements), array_values($replacements), $content);
         $email[$key] = $content;
     }
     // Find generator:
     $page = $this->getPage($email['page']);
     $generator = URL;
     if ($page->path) {
         $generator .= '/' . $page->path;
     }
     $generator .= '/' . $page->handle;
     $generator = rtrim($generator, '/');
     $params = trim($email['params'], '/');
     $generator = "{$generator}/{$params}/";
     // Fetch generator
     require_once TOOLKIT . '/class.gateway.php';
     $ch = new Gateway();
     $ch->init($generator);
     $ch->setopt('HTTPHEADER', array('X-REQUESTED-WITH: EmailTemplateFilter'));
     $message = $ch->exec();
     // Add values:
     $email['message'] = (string) $message;
     $email['condition_id'] = $email['id'];
     $email['entry_id'] = $entry_id;
     $email['recipients'] = array_unique(preg_split('/\\s*[,]\\s*/', $email['recipients']));
     $email['reply_to'] = isset($email['reply_to']) ? $email['reply_to'] : $email['sender'];
     $email['reply_to_email'] = isset($email['reply_to_email']) ? $email['reply_to_email'] : $email['senders'];
     // Remove junk:
     unset($email['id']);
     unset($email['expression']);
     unset($email['type']);
     unset($email['sortorder']);
     unset($email['page']);
     unset($email['params']);
     $send = Email::create();
     $success = false;
     try {
         $send->recipients = $email['recipients'];
         $send->sender_name = $email['sender'];
         $send->sender_email_address = $email['senders'];
         $send->reply_to_name = $email['reply_to'];
         $send->reply_to_email_address = $email['reply_to_email'];
         $send->subject = $email['subject'];
         $send->text_html = $email['message'];
         $send->attachments = $this->findAttachments($email);
         $send->send();
         $success = true;
     } catch (EmailGatewayException $e) {
         throw new SymphonyErrorPage('Error sending email. ' . $e->getMessage());
     } catch (EmailException $e) {
         throw new SymphonyErrorPage('Error sending email. ' . $e->getMessage());
     }
     // Log the email:
     $email['success'] = $success ? 'yes' : 'no';
     $email['date'] = DateTimeObj::get('c');
     $email['recipients'] = implode(', ', $email['recipients']);
     Symphony::Database()->insert($email, 'tbl_etf_logs');
//.........这里部分代码省略.........
开发者ID:symphonists,项目名称:emailtemplatefilter,代码行数:101,代码来源:extension.driver.php


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