本文整理汇总了PHP中Symphony类的典型用法代码示例。如果您正苦于以下问题:PHP Symphony类的具体用法?PHP Symphony怎么用?PHP Symphony使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Symphony类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initializeContext
/**
* Initialize contextual XML (formerly params)
*/
public function initializeContext()
{
$this->View->context->register(array('system' => array('site-name' => Symphony::Configuration()->core()->symphony->sitename, 'site-url' => URL, 'admin-url' => URL . '/symphony', 'symphony-version' => Symphony::Configuration()->core()->symphony->version), 'date' => array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => date_default_timezone_get())));
if ($this->User) {
$this->View->context->register(array('session' => self::instance()->User->fields()));
}
}
示例2: __construct
/**
* The constructor for `JSONPage`. This sets the page status to `Page::HTTP_STATUS_OK`,
* the default content type to `application/json` and initialises `$this->_Result`
* with an `array`. The constructor also starts the Profiler for this
* page template.
*
* @see toolkit.Profiler
*/
public function __construct()
{
$this->_Result = array();
$this->setHttpStatus(self::HTTP_STATUS_OK);
$this->addHeaderToPage('Content-Type', 'application/json');
Symphony::Profiler()->sample('Page template created', PROFILE_LAP);
}
示例3: upgrade
public static function upgrade()
{
if (version_compare(self::$existing_version, '2.3.4beta1', '<=')) {
// Detect mod_rewrite #1808
try {
$htaccess = file_get_contents(DOCROOT . '/.htaccess');
if ($htaccess !== false && !preg_match('/SetEnv HTTP_MOD_REWRITE No/', $htaccess)) {
$rewrite = '
<IfModule !mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE No
</IfModule>
<IfModule mod_rewrite.c>';
$htaccess = str_replace('<IfModule mod_rewrite.c>', $rewrite, $htaccess);
file_put_contents(DOCROOT . '/.htaccess', $htaccess);
}
} catch (Exception $ex) {
}
// Extend token field to enable more secure tokens
try {
Symphony::Database()->query('ALTER TABLE `tbl_forgotpass` CHANGE `token` `token` VARCHAR(16);');
} catch (Exception $ex) {
}
}
if (version_compare(self::$existing_version, '2.3.4beta2', '<=')) {
// Extend session_id field for default Suhosin installs
try {
Symphony::Database()->query('ALTER TABLE `tbl_sessions` CHANGE `session` `session` VARCHAR(128);');
} catch (Exception $ex) {
}
}
// Update the version information
return parent::upgrade();
}
示例4: processDependencies
public function processDependencies(array $params = array())
{
$datasources = $this->getDependencies();
if (!is_array($datasources) || empty($datasources)) {
return;
}
$datasources = array_map(create_function('$a', "return str_replace('\$ds-', '', \$a);"), $datasources);
$datasources = array_map(create_function('$a', "return str_replace('-', '_', \$a);"), $datasources);
$env = array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => DateTimeObj::get('P'), 'enm-newsletter-id' => $this->newsletter_id);
$this->_env['param'] = $env;
$this->_env['env']['pool'] = $params;
$dependencies = array();
foreach ($datasources as $handle) {
$profiler = Symphony::Profiler();
$profiler->seed();
$pool[$handle] =& DatasourceManager::create($handle, NULL, false);
$dependencies[$handle] = $pool[$handle]->getDependencies();
}
$dsOrder = $this->__findDatasourceOrder($dependencies);
foreach ($dsOrder as $handle) {
$ds = $pool[$handle];
$ds->processParameters($this->_env);
$ds->grab($this->_env['env']['pool']);
unset($ds);
}
$this->processParameters($this->_env);
}
示例5: __construct
public function __construct($add, $orderable = true)
{
$this->child_name = $child_name;
$this->page = Symphony::Parent()->Page;
$this->duplicator = $this->page->createElement('div');
$this->duplicator->addClass('duplicator-widget');
$controls = $this->page->createElement('ol');
$controls->addClass('controls');
$this->duplicator->appendChild($controls);
$add_item = $this->page->createElement('li', $add);
$add_item->addClass('add');
$controls->appendChild($add_item);
$this->templates = $this->page->createElement('ol');
$this->templates->setAttribute('class', 'templates');
$this->duplicator->appendChild($this->templates);
$content = $this->page->createElement('div');
$content->addClass('content');
$this->duplicator->appendChild($content);
$this->tabs = $this->page->createElement('ol');
$this->tabs->addClass('tabs');
$content->appendChild($this->tabs);
if ($orderable) {
$this->duplicator->addClass('orderable-widget');
}
$this->instances = $this->page->createElement('ol');
$this->instances->addClass('instances');
$content->appendChild($this->instances);
$this->reflection = new ReflectionObject($this->duplicator);
}
示例6: __construct
/**
* The constructor for the `XSLTPage` ensures that an `XSLTProcessor`
* is available, and then sets an instance of it to `$this->Proc`, otherwise
* it will throw a `SymphonyErrorPage` exception.
*/
public function __construct()
{
if (!XsltProcess::isXSLTProcessorAvailable()) {
Symphony::Engine()->throwCustomError(__('No suitable XSLT processor was found.'));
}
$this->Proc = new XsltProcess();
}
示例7: lookup
public static function lookup($ip)
{
$ch = curl_init();
// Notice: the request back to the service API includes your domain name
// and the version of Symphony that you're using
$version = Symphony::Configuration()->get('version', 'symphony');
$domain = $_SERVER[SERVER_NAME];
curl_setopt($ch, CURLOPT_URL, "http://api.josephdenne.com/_geoloc/array/?symphony=" . $version . "&domain=" . $domain . "&ip=" . $ip);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$geoinfo = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($geoinfo === false || $info['http_code'] != 200) {
return;
} else {
$geoinfo = explode(',', $geoinfo);
}
$result = new XMLElement("geolocation");
$included = array('id', 'lookups', 'country', 'region', 'city', 'lat', 'lon', 'error');
$i = 0;
foreach ($included as $geoloc) {
$result->appendChild(new XMLElement($geoloc, $geoinfo[$i]));
$i++;
}
return $result;
}
示例8: action
public function action()
{
if (isset($_POST['action']['save'])) {
$fields = $_POST['fields'];
$permissions = $fields['permissions'];
$name = trim($fields['name']);
$page_access = $fields['page_access'];
if (strlen($name) == 0) {
$this->_errors['name'] = __('This is a required field');
return;
} elseif ($this->_driver->roleExists($name)) {
$this->_errors['name'] = __('A role with the name <code>%s</code> already exists.', array($name));
return;
}
ASDCLoader::instance()->query("INSERT INTO `tbl_members_roles` VALUES (NULL, '{$name}')");
$role_id = ASDCLoader::instance()->lastInsertID();
if (is_array($page_access) && !empty($page_access)) {
foreach ($page_access as $page_id) {
ASDCLoader::instance()->query("INSERT INTO `tbl_members_roles_forbidden_pages` VALUES (NULL, {$role_id}, {$page_id})");
}
}
if (is_array($permissions) && !empty($permissions)) {
$sql = "INSERT INTO `tbl_members_roles_event_permissions` VALUES ";
foreach ($permissions as $event_handle => $p) {
foreach ($p as $action => $level) {
$sql .= "(NULL, {$role_id}, '{$event_handle}', '{$action}', '{$level}'),";
}
}
Symphony::Database()->query(trim($sql, ','));
}
redirect(extension_members::baseURL() . 'roles_edit/' . $role_id . '/created/');
}
}
示例9: entrySaved
public function entrySaved($context)
{
require_once MANIFEST . '/jit-recipes.php';
require_once MANIFEST . '/jit-precaching.php';
require_once TOOLKIT . '/class.fieldmanager.php';
$fm = new FieldManager(Symphony::Engine());
$section = $context['section'];
if (!$section) {
require_once TOOLKIT . '/class.sectionmanager.php';
$sm = new SectionManager(Symphony::Engine());
$section = $sm->fetch($context['entry']->get('section_id'));
}
// iterate over each field in this entry
foreach ($context['entry']->getData() as $field_id => $data) {
// get the field meta data
$field = $fm->fetch($field_id);
// iterate over the field => recipe mapping
foreach ($cached_recipes as $cached_recipe) {
// check a mapping exists for this section/field combination
if ($section->get('handle') != $cached_recipe['section']) {
continue;
}
if ($field->get('element_name') != $cached_recipe['field']) {
continue;
}
// iterate over the recipes mapped for this section/field combination
foreach ($cached_recipe['recipes'] as $cached_recipe_name) {
// get the file name, includes path relative to workspace
$file = $data['file'];
if (!isset($file) || is_null($file)) {
continue;
}
// trim the filename from path
$uploaded_file_path = explode('/', $file);
array_pop($uploaded_file_path);
// image path relative to workspace
if (is_array($uploaded_file_path)) {
$uploaded_file_path = implode('/', $uploaded_file_path);
}
// iterate over all JIT recipes
foreach ($recipes as $recipe) {
// only process if the recipe has a URL Parameter (name)
if (is_null($recipe['url-parameter'])) {
continue;
}
// if not using wildcard, only process specified recipe names
if ($cached_recipe_name != '*' && $cached_recipe_name != $recipe['url-parameter']) {
continue;
}
// process the image using the usual JIT URL and get the result
$image_data = file_get_contents(URL . '/image/' . $recipe['url-parameter'] . $file);
// create a directory structure that matches the JIT URL structure
General::realiseDirectory(WORKSPACE . '/image-cache/' . $recipe['url-parameter'] . $uploaded_file_path);
// save the image to disk
file_put_contents(WORKSPACE . '/image-cache/' . $recipe['url-parameter'] . $file, $image_data);
}
}
}
}
}
示例10: __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', 'https://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&key=' . $this->get('api_key'));
$response = json_decode($ch->exec());
if ($response->status === 'OK') {
$coordinates = $response->results[0]->geometry->location;
} else {
return false;
}
if ($coordinates && is_object($coordinates)) {
// cache lifetime in minutes
$cache->write($cache_id, $coordinates->lat . ', ' . $coordinates->lng, $this->_geocode_cache_expire);
}
} 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 ($can_return_default) {
return $this->_default_coordinates;
}
}
示例11: grab
public function grab(&$param_pool)
{
self::__init();
$result = new XMLElement($this->dsParamROOTELEMENT);
$rows = Symphony::Database()->fetch("SELECT *\n\t\t\t\tFROM `tbl_sessions` \n\t\t\t\tWHERE `session_data` != 'sym-|a:0:{}sym-members|a:0:{}' \n\t\t\t\tAND `session_data` REGEXP 'sym-members'\n\t\t\t\tAND `session_expires` > (UNIX_TIMESTAMP() - " . self::AGE . ") \n\t\t\t\tORDER BY `session_expires` DESC");
$added = array();
if (count($rows) > 0) {
foreach ($rows as $r) {
$raw = $r['session_data'];
$data = self::session_real_decode($raw);
if (!isset($data['sym-members'])) {
continue;
}
$record = ASDCLoader::instance()->query(sprintf("SELECT\n\t\t\t\t\t\t\t\temail.value AS `email`,\n\t\t\t\t\t\t\t\tMD5(email.value) AS `hash`,\n\t\t\t\t\t\t\t\tcreated_by.username AS `username`\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tFROM `tbl_entries_data_%d` AS `created_by`\n\t\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `email` ON created_by.member_id = email.entry_id\n\t\t\t\t\t\t\tWHERE `created_by`.username = '%s'\n\t\t\t\t\t\t\tLIMIT 1", self::findFieldID('created-by', 'comments'), self::findFieldID('email-address', 'members'), ASDCLoader::instance()->escape($data['sym-members']['username'])));
if ($record->length() == 0) {
continue;
}
$member = $record->current();
// This is so we dont end up with accidental duplicates. No way to select
// distinct via the SQL since we grab raw session data
if (in_array($member->username, $added)) {
continue;
}
$added[] = $member->username;
$result->appendChild(new XMLElement('member', General::sanitize($member->username), array('email-hash' => $member->hash)));
}
} else {
$result->setValue('No Records Found.');
//This should never happen!
}
return $result;
}
示例12: fetchMemberFromID
/**
* Given a Member ID, return Member
*
* @param integer $member_id
* @return Entry
*/
public function fetchMemberFromID($member_id)
{
if (!Identity::$driver instanceof Extension) {
Identity::$driver = Symphony::ExtensionManager()->create('members');
}
return Identity::$driver->getMemberDriver()->initialiseMemberObject($member_id);
}
示例13: save
public static function save(Utility $utility)
{
$file = UTILITIES . "/{$utility->name}";
FileWriter::write($file, $utility->body, Symphony::Configuration()->core()->symphony->{'file-write-mode'});
//General::writeFile($file, $utility->body,Symphony::Configuration()->core()->symphony->{'file-write-mode'});
return file_exists($file);
}
示例14: saveVersion
public function saveVersion(&$context)
{
$section = $context['section'];
$entry = $context['entry'];
$fields = $context['fields'];
// if saved from an event, no section is passed, so resolve
// section object from the entry
if (is_null($section)) {
$sm = new SectionManager(Symphony::Engine());
$section = $sm->fetch($entry->get('section_id'));
}
// if we *still* can't resolve a section then something is
// probably quite wrong, so don't try and save version history
if (is_null($section)) {
return;
}
// does this section have en Entry Version field, should we store the version?
$has_entry_versions_field = FALSE;
// is this an update to an existing version, or create a new version?
$is_update = $fields['entry-versions'] != 'yes';
// find the Entry Versions field in the section and remove its presence from
// the copied POST array, so that its value is not saved against the version
foreach ($section->fetchFields() as $field) {
if ($field->get('type') == 'entry_versions') {
unset($fields[$field->get('element_name')]);
$has_entry_versions_field = TRUE;
}
}
if (!$has_entry_versions_field) {
return;
}
$version = EntryVersionsManager::saveVersion($entry, $fields, $is_update, $entry_version_field_name);
$context['messages'][] = array('version', 'passed', $version);
}
示例15: import
/**
* Process the data so it can be imported into the entry.
* @param $value The value to import
* @param $entry_id If a duplicate is found, an entry ID will be provided.
* @return The data returned by the field object
*/
public function import($value, $entry_id = null)
{
$destination = $this->field->get('destination');
$filename = str_replace('/workspace/', '/', $destination) . '/' . str_replace($destination, '', trim($value));
// Check if the file exists:
if (file_exists(DOCROOT . $destination . '/' . trim($value))) {
// File exists, create the link:
// Check if there already exists an entry with this filename. If so, this entry will not be stored (filename must be unique)
$sql = 'SELECT COUNT(*) AS `total` FROM `tbl_entries_data_' . $this->field->get('id') . '` WHERE `file` = \'' . $filename . '\';';
$total = Symphony::Database()->fetchVar('total', 0, $sql);
if ($total == 0) {
$fileData = $this->field->processRawFieldData($value, $this->field->__OK__);
$fileData['file'] = trim($filename);
$fileData['size'] = filesize(DOCROOT . $destination . '/' . $value);
$fileData['mimetype'] = mime_content_type(DOCROOT . $destination . '/' . $value);
$fileData['meta'] = serialize($this->field->getMetaInfo(DOCROOT . $destination . '/' . $value, $fileData['mimetype']));
return $fileData;
} else {
// File already exists, don't store:
return false;
}
} else {
// File is stored in the CSV, but does not exists. Save it anyway, for database sake:
if (!empty($value)) {
$fileData = $this->field->processRawFieldData($value, $this->field->__OK__);
$fileData['file'] = trim($filename);
$fileData['size'] = filesize(DOCROOT . $destination . '/' . $value);
$fileData['mimetype'] = '';
// mime_content_type(DOCROOT . $destination . '/' . $value);
$fileData['meta'] = serialize($this->field->getMetaInfo(DOCROOT . $destination . '/' . $value, $fileData['mimetype']));
return $fileData;
}
}
return false;
}