public static function saveVersion($entry, $fields, $is_update) { // list existing versions of this entry $existing_versions = General::listStructure(MANIFEST . '/versions/' . $entry->get('id') . '/', '/.xml$/'); // create folder if (!file_exists(MANIFEST . '/versions/' . $entry->get('id'))) { General::realiseDirectory(MANIFEST . '/versions/' . $entry->get('id')); } // max version number $new_version_number = count($existing_versions['filelist']); $new_version_number++; if ($is_update) { $new_version_number--; } if ($new_version_number == 0) { $new_version_number++; } unset($fields['entry-versions']); // run custom DS to get the built XML of this entry $ds = new EntryVersionsXMLDataSource(self::Context(), null, false); $ds->dsParamINCLUDEDELEMENTS = array_keys($fields); $ds->dsParamFILTERS['id'] = $entry->get('id'); $ds->dsSource = (string) $entry->get('section_id'); $param_pool = array(); $entry_xml = $ds->grab($param_pool); // get text value of the entry $proc = new XsltProcess(); $data = $proc->process($entry_xml->generate(), file_get_contents(EXTENSIONS . '/entry_versions/lib/entry-version.xsl'), array('version' => $new_version_number, 'created-by' => self::Context()->Author ? self::Context()->Author->getFullName() : '', 'created-date' => date('Y-m-d', time()), 'created-time' => date('H:i', time()))); $write = General::writeFile(MANIFEST . '/versions/' . $entry->get('id') . '/' . $new_version_number . '.xml', $data); General::writeFile(MANIFEST . '/versions/' . $entry->get('id') . '/' . $new_version_number . '.dat', self::serializeEntry($entry)); return $new_version_number; }
public function build() { $this->_root = DOCROOT . '/'; $this->_path = @realpath(strlen(trim($_GET['browse'])) == 0 ? $this->_root : $_GET['browse']); $this->_xsl = @file_get_contents($this->_pagedata['filelocation']); // Keep everything within DOCROOT: if (strpos($this->_path, $this->_root) !== 0) { $this->_path = $this->_root; } $this->_item = new PathListItem($this->_path); if ($this->_path != $this->_root) { $this->_link = '=' . $this->_item->path($this->_root); } // Toggle bookmarks: if (isset($_GET['bookmark'])) { $configuration = Frontend::instance()->Configuration; $bookmarks = $configuration->get('browsedevkit-bookmarks'); $path = realpath($_GET['bookmark']); if (strpos($path, $this->_root) !== 0) { $path = $this->_root; } if (!is_array($bookmarks)) { $bookmarks = array(); } if (in_array($path, $bookmarks)) { $bookmarks = array_diff($bookmarks, array($path)); } else { $bookmarks[] = $path; } $configuration->set('browsedevkit-bookmarks', $bookmarks); General::writeFile(CONFIG, "<?php\n\t\$settings = {$configuration};\n", $configuration->get('write_mode', 'file')); redirect("?browse{$this->_link}{$this->_query_string}"); } return parent::build(); }
public function install() { // create tables Symphony::Database()->query("CREATE TABLE `tbl_elasticsearch_logs` (\n\t\t\t\t `id` varchar(255) NOT NULL DEFAULT '',\n\t\t\t\t `date` datetime NOT NULL,\n\t\t\t\t `keywords` varchar(255) DEFAULT NULL,\n\t\t\t\t `keywords_raw` varchar(255) DEFAULT NULL,\n\t\t\t\t `sections` varchar(255) DEFAULT NULL,\n\t\t\t\t `page` int(11) NOT NULL,\n\t\t\t\t `results` int(11) DEFAULT NULL,\n\t\t\t\t `session_id` varchar(255) DEFAULT NULL,\n\t\t\t\t `user_agent` varchar(255) DEFAULT NULL,\n\t\t\t\t `ip` varchar(255) DEFAULT NULL,\n\t\t\t\t PRIMARY KEY (`id`),\n\t\t\t\t UNIQUE KEY `id` (`id`),\n\t\t\t\t KEY `keywords` (`keywords`),\n\t\t\t\t KEY `date` (`date`),\n\t\t\t\t KEY `session_id` (`session_id`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); // create config defaults Symphony::Configuration()->setArray(array('elasticsearch' => array('host' => '', 'index-name' => '', 'reindex-batch-size' => 20, 'reindex-batch-delay' => 0, 'per-page' => 20, 'sort' => '_score', 'direction' => 'desc', 'highlight-fragment-size' => 200, 'highlight-per-field' => 1, 'build-entry-xml' => 'no', 'default-sections' => '', 'default-language' => '', 'log-searches' => 'yes'))); Administration::instance()->saveConfig(); // create workspace structure $config = (object) Symphony::Configuration()->get('directory'); General::realiseDirectory(WORKSPACE . '/elasticsearch', $config->{'write_mode'}); General::writeFile(WORKSPACE . '/elasticsearch/.htaccess', file_get_contents(EXTENSIONS . '/elasticsearch/templates/.htaccess'), $config->{'write_mode'}); General::writeFile(WORKSPACE . '/elasticsearch/index.json', file_get_contents(EXTENSIONS . '/elasticsearch/templates/index.json'), $config->{'write_mode'}); General::realiseDirectory(WORKSPACE . '/elasticsearch/mappings', $config->{'write_mode'}); }
private function persist($url, $result) { $cache = array(); $cache[] = array(); if (file_exists(BITLY_CACHE)) { $cache = file_get_contents(BITLY_CACHE); $cache = json_decode($cache, true); } $token = md5($url); if (!array_key_exists($token, $cache)) { $cache[0][$token] = array("url" => $url, "tinyurl" => $result); } $cache = json_encode($cache); General::writeFile(BITLY_CACHE, $cache); }
function writeConfig($dest, $conf, $mode) { $string = "<?php\n"; $string .= "\n\t\$settings = array("; foreach ($conf as $group => $data) { $string .= "\r\n\r\n\r\n\t\t###### " . strtoupper($group) . " ######"; $string .= "\r\n\t\t'{$group}' => array("; foreach ($data as $key => $value) { $string .= "\r\n\t\t\t'{$key}' => " . (strlen($value) > 0 ? "'" . addslashes($value) . "'" : 'NULL') . ","; } $string .= "\r\n\t\t),"; $string .= "\r\n\t\t########"; } $string .= "\r\n\t);\n\n"; return General::writeFile($dest . '/config.php', $string, $mode); }
/** * Changes the source of navigation datasources. * * @static * * @param string $mode - flag for datasource status. */ public static function editAllNavDssTo($mode) { $datasources = array_keys(DatasourceManager::listAll()); if (is_array($datasources) && !empty($datasources)) { foreach ($datasources as $value) { $filename = WORKSPACE . '/data-sources/data.' . $value . '.php'; if (is_file($filename) && is_writable($filename)) { $old_content = file_get_contents($filename); if (self::_isDsTypeNavigation($old_content)) { if (method_exists(get_class(), "setNavDsTo{$mode}")) { $new_content = call_user_func(array(self, "setNavDsTo{$mode}"), $old_content); General::writeFile($filename, $new_content); } } } } } }
public function install() { if (file_exists(MANIFEST . '/jit-precaching.php')) { return; } $string = "<?php\n"; $string .= "\n\t\$cached_recipes = array("; $string .= "\r\n\r\n\t\t/*"; $string .= "\r\n\t\tarray("; $string .= "\r\n\t\t\t'section' => 'section-handle',"; $string .= "\r\n\t\t\t'field' => 'field-handle',"; $string .= "\r\n\t\t\t//'recipes' => array('*'),"; $string .= "\r\n\t\t\t'recipes' => array('gallery', 'profile-small', 'profile-large'),"; $string .= "\r\n\t\t),"; $string .= "\r\n\t\t*/"; $string .= "\r\n\t);\n\n"; return General::writeFile(MANIFEST . '/jit-precaching.php', $string, Symphony::Configuration()->get('write_mode', 'file')); }
public function __actionIndex() { $sections_post = @$_POST['sections']; if (empty($this->_driver)) { $this->_driver = $this->_Parent->ExtensionManager->create('section_schemas'); } if (@isset($_POST['action']['save'])) { $blueprint = new contentBlueprintsDatasources(); $sm = new SectionManager($this->_Parent); $sections = $sm->fetch(); foreach ($sections as $section) { $file = DATASOURCES . '/data.section_schema_' . str_replace('-', '_', $section->_data['handle']) . '.php'; General::deleteFile($file); if (in_array($section->_data['handle'], $sections_post)) { $dsShell = file_get_contents(TEMPLATE . '/datasource.tpl'); $dsShell = str_replace("require_once(TOOLKIT . '/class.datasource.php');", "require_once(TOOLKIT . '/class.datasource.php');\n\trequire_once(TOOLKIT . '/class.sectionmanager.php');\n\trequire_once(TOOLKIT . '/class.fieldmanager.php');\n\trequire_once(TOOLKIT . '/class.entrymanager.php');", $dsShell); $dsShell = str_replace('<!-- CLASS NAME -->', 'section_schema_' . str_replace('-', '_', $section->_data['handle']), $dsShell); $dsShell = str_replace('<!-- FILTERS -->', '', $dsShell); $dsShell = str_replace('<!-- INCLUDED ELEMENTS -->', '', $dsShell); $dsShell = str_replace('<!-- DS DEPENDANCY LIST -->', '""', $dsShell); $params['rootelement'] = 'section-schema'; $blueprint->__injectVarList($dsShell, $params); $about = array('name' => 'Section Schema: ' . $section->_data['name'], 'version' => '1.0', 'release date' => DateTimeObj::getGMT('c'), 'author name' => $this->_Parent->Author->getFullName(), 'author website' => URL, 'author email' => $this->_Parent->Author->get('email')); $blueprint->__injectAboutInformation($dsShell, $about); $dsShell = str_replace('<!-- SOURCE -->', $section->_data['id'], $dsShell); $dsShell = str_replace('return true;', 'return false;', $dsShell); $dsShell = str_replace('<!-- GRAB -->', "\$extension = \$this->_Parent->ExtensionManager->create('section_schemas');" . self::CRLF . "\t\t\t\t\$extension->getSectionSchema(\$result, \$this->getSource());", $dsShell); $dsShell = str_replace('<!-- EXTRAS -->', '', $dsShell); if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $dsShell, $this->_Parent->Configuration->get('write_mode', 'file')))) { $this->pageAlert(__('Failed to write data sources to <code>%s</code>. Please check permissions.', array(DATASOURCES)), Alert::ERROR); } else { $this->pageAlert('Section Schema data sources saved.', Alert::SUCCESS); } } } } }
/** * This function will write the given message to the log file. Messages will be appended * the existing log file. * * @param string $message * The message to add to the Log * @param boolean $addbreak * To be used in conjunction with `$writeToLog`, this will add a line break * before writing this message in the log file. Defaults to true. * @return boolean * Returns true if the message was written successfully, false otherwise */ public function writeToLog($message, $addbreak = true) { if (file_exists($this->_log_path) && !is_writable($this->_log_path)) { $this->pushToLog('Could Not Write To Log. It is not readable.'); return false; } $permissions = class_exists('Symphony') ? Symphony::Configuration()->get('write_mode', 'file') : '0664'; return General::writeFile($this->_log_path, $message . ($addbreak ? PHP_EOL : ''), $permissions, 'a+'); }
public static function migrateSection($section_id) { self::$sectionManager->flush(); $section = self::$sectionManager->fetch($section_id); // Ensures that section has a guid value if (!$section->get('guid')) { $section->set('guid', uniqid()); $section->commit(); } $meta = $section->get(); $fields = array(); $field_objects = $section->fetchFields(); if (is_array($field_objects) && !empty($field_objects)) { foreach ($field_objects as $f) { // Ensures that fields has guid values if (!$f->get('guid')) { $f->set('guid', uniqid()); self::$fieldManager->edit($f->get('id'), array('guid' => $f->get('guid'))); } $fields[] = $f->get(); } } // Creates DOMDocument object $xml = new DOMDocument('1.0', 'UTF-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; // Section element $section = $xml->createElement('section'); $section->setAttribute('guid', $meta['guid']); // Section meta data $section_meta = $xml->createElement('meta'); foreach ($meta as $key => $value) { if ($key == 'id') { continue; } $element = $xml->createElement($key, $value); $section_meta->appendChild($element); } // Section fields $section_fields = $xml->createElement('fields'); foreach ($fields as $f) { $field = $xml->createElement('entry'); foreach ($f as $key => $value) { if ($key == 'id' || $key == 'field_id') { continue; } $data = $xml->createElement($key, $value); $field->appendChild($data); } $section_fields->appendChild($field); } $section->appendChild($section_meta); $section->appendChild($section_fields); $xml->appendChild($section); // Saves output in an external file $location = WORKSPACE . "/sections/{$meta['handle']}.xml"; $output = $xml->saveXML(); General::writeFile($location, $output, Symphony::Configuration()->get('write_mode', 'file')); }
public function save(MessageStack $errors) { $editing = isset($this->parameters()->{'root-element'}) ? $this->parameters()->{'root-element'} : false; // About info: if (!isset($this->about()->name) || empty($this->about()->name)) { $errors->append('about::name', __('This is a required field')); } try { $existing = self::loadFromHandle($this->handle); } catch (DataSourceException $e) { // Datasource not found, continue! } if ($existing instanceof Datasource && $editing != $this->handle) { throw new DataSourceException(__('A Datasource with the name <code>%s</code> already exists', array($this->about()->name))); } // Save type: if ($errors->length() <= 0) { $user = Administration::instance()->User; if (!file_exists($this->getTemplate())) { $errors->append('write', __("Unable to find Data Source Type template '%s'.", array($this->getTemplate()))); throw new DataSourceException(__("Unable to find Data Source Type template '%s'.", array($this->getTemplate()))); } $this->parameters()->{'root-element'} = $this->handle; $classname = Lang::createHandle(ucwords($this->about()->name), '_', false, true, array('/[^a-zA-Z0-9_\\x7f-\\xff]/' => NULL), true); $pathname = DATASOURCES . "/" . $this->handle . ".php"; $data = array($classname, var_export($this->about()->name, true), var_export($user->getFullName(), true), var_export(URL, true), var_export($user->email, true), var_export('1.0', true), var_export(DateTimeObj::getGMT('c'), true)); foreach ($this->parameters() as $value) { $data[] = trim(General::var_export($value, true, is_array($value) ? 5 : 0)); } if (General::writeFile($pathname, vsprintf(file_get_contents($this->getTemplate()), $data), Symphony::Configuration()->core()->symphony->{'file-write-mode'})) { if ($editing !== false && $editing != $this->handle) { General::deleteFile(DATASOURCES . '/' . $editing . '.php'); } return $pathname; } $errors->append('write', __('Failed to write datasource "%s" to disk.', array($filename))); } throw new DataSourceException('Errors were encountered whilst attempting to save.'); }
function __actionEdit() { if (!($page_id = $this->_context[1])) { redirect(URL . '/symphony/blueprints/pages/'); } if (@array_key_exists('delete', $_POST['action'])) { ## TODO: Fix Me ### # Delegate: Delete # Description: Prior to deletion. Provided with Page's database ID //$ExtensionManager->notifyMembers('Delete', getCurrentPage(), array('page' => $page_id)); $page = $this->_Parent->Database->fetchRow(0, "SELECT * FROM tbl_pages WHERE `id` = '{$page_id}'"); $filename = $page['path'] . '_' . $page['handle']; $filename = trim(str_replace('/', '_', $filename), '_'); $this->_Parent->Database->delete('tbl_pages', " `id` = '{$page_id}'"); $this->_Parent->Database->delete('tbl_pages_types', " `page_id` = '{$page_id}'"); $this->_Parent->Database->query("UPDATE tbl_pages SET `sortorder` = (`sortorder` + 1) WHERE `sortorder` < '{$page_id}'"); General::deleteFile(PAGES . "/{$filename}.xsl"); redirect(URL . '/symphony/blueprints/pages/'); } elseif (@array_key_exists('save', $_POST['action'])) { $fields = $_POST['fields']; $this->_errors = array(); if (!isset($fields['body']) || trim($fields['body']) == '') { $this->_errors['body'] = __('Body is a required field'); } elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) { $this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message'])); } if (!isset($fields['title']) || trim($fields['title']) == '') { $this->_errors['title'] = __('Title is a required field'); } if (trim($fields['type']) != '' && preg_match('/(index|404|403)/i', $fields['type'])) { $haystack = strtolower($fields['type']); if (preg_match('/\\bindex\\b/i', $haystack, $matches) && ($row = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages_types` WHERE `page_id` != '{$page_id}' AND `type` = 'index' LIMIT 1"))) { $this->_errors['type'] = __('An index type page already exists.'); } elseif (preg_match('/\\b404\\b/i', $haystack, $matches) && ($row = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages_types` WHERE `page_id` != '{$page_id}' AND `type` = '404' LIMIT 1"))) { $this->_errors['type'] = __('A 404 type page already exists.'); } elseif (preg_match('/\\b403\\b/i', $haystack, $matches) && ($row = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages_types` WHERE `page_id` != '{$page_id}' AND `type` = '403' LIMIT 1"))) { $this->_errors['type'] = __('A 403 type page already exists.'); } } if (empty($this->_errors)) { ## Manipulate some fields //$fields['sortorder'] = $this->_Parent->Database->fetchVar('next', 0, "SELECT MAX(sortorder) + 1 as `next` FROM `tbl_pages` LIMIT 1"); // //if(empty($fields['sortorder']) || !is_numeric($fields['sortorder'])) $fields['sortorder'] = 1; $autogenerated_handle = false; if (trim($fields['handle']) == '') { $fields['handle'] = $fields['title']; $autogenerated_handle = true; } $fields['handle'] = Lang::createHandle($fields['handle']); if ($fields['params']) { $fields['params'] = trim(preg_replace('@\\/{2,}@', '/', $fields['params']), '/'); } ## Clean up type list $types = preg_split('/,\\s*/', $fields['type'], -1, PREG_SPLIT_NO_EMPTY); $types = @array_map('trim', $types); unset($fields['type']); //if(trim($fields['type'])) $fields['type'] = preg_replace('/\s*,\s*/i', ', ', $fields['type']); //else $fields['type'] = NULL; ## Manipulate some fields $fields['parent'] = $fields['parent'] != 'None' ? $fields['parent'] : NULL; $fields['data_sources'] = @implode(',', $fields['data_sources']); $fields['events'] = @implode(',', $fields['events']); $fields['path'] = NULL; if ($fields['parent']) { $fields['path'] = $this->_Parent->resolvePagePath(intval($fields['parent'])); } $new_filename = trim(str_replace('/', '_', $fields['path'] . '_' . $fields['handle']), '_'); $current = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages` WHERE `id` = '{$page_id}' LIMIT 1"); $current_filename = $current['path'] . '_' . $current['handle']; $current_filename = trim(str_replace('/', '_', $current_filename), '_'); ## Duplicate if ($this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages` \r\n\t\t\t\t\t\t\t\t\t\t WHERE `handle` = '" . $fields['handle'] . "' \r\n\t\t\t\t\t\t\t\t\t\t AND `id` != '{$page_id}' \r\n\t\t\t\t\t\t\t\t\t\t AND `path` " . ($fields['path'] ? " = '" . $fields['path'] . "'" : ' IS NULL') . " \r\n\t\t\t\t\t\t\t\t\t\t LIMIT 1")) { if ($autogenerated_handle) { $this->_errors['title'] = __('A page with that title %s already exists', array($fields['parent'] ? __('and parent') : '')); } else { $this->_errors['handle'] = __('A page with that handle %s already exists', array($fields['parent'] ? __('and parent') : '')); } } else { ## Write the file if (!($write = General::writeFile(PAGES . "/{$new_filename}.xsl", $fields['body'], $this->_Parent->Configuration->get('write_mode', 'file')))) { $this->pageAlert(__('Page could not be written to disk. Please check permissions on <code>/workspace/pages</code>.'), Alert::ERROR); } else { if ($new_filename != $current_filename) { @unlink(PAGES . "/{$current_filename}.xsl"); } ## No longer need the body text unset($fields['body']); ## Insert the new data if (!$this->_Parent->Database->update($fields, 'tbl_pages', "`id` = '{$page_id}'")) { $this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your <a href="%s">activity log</a>.', array(URL . '/symphony/system/log/')), Alert::ERROR); } else { $this->_Parent->Database->delete('tbl_pages_types', " `page_id` = '{$page_id}'"); if (is_array($types) && !empty($types)) { foreach ($types as $type) { $this->_Parent->Database->insert(array('page_id' => $page_id, 'type' => $type), 'tbl_pages_types'); } } ## TODO: Fix Me ### # Delegate: Edit # Description: After saving the page. The Page's database ID is provided. //$ExtensionManager->notifyMembers('Edit', getCurrentPage(), array('page_id' => $page_id)); redirect(URL . "/symphony/blueprints/pages/edit/{$page_id}/saved/"); } } } } if (is_array($this->_errors) && !empty($this->_errors)) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } } }
function saveConfig() { if (!defined('DOMAIN')) { $clean_path = $_SERVER["HTTP_HOST"] . dirname($_SERVER["PHP_SELF"]); $clean_path = rtrim($clean_path, '/\\'); $clean_path = preg_replace('/\\/{2,}/i', '/', $clean_path); ## Strip the /symphony part from the URL $clean_path = substr($clean_path, 0, strlen($clean_path) - 9); define('DOMAIN', $clean_path); } $string = '<?php' . CRLF . "define('DOCROOT','" . DOCROOT . "');" . CRLF . "define('DOMAIN','" . DOMAIN . "');" . CRLF . CRLF . '$settings = array();' . CRLF; $string .= $this->_config->create("php"); $string .= CRLF . "require_once(DOCROOT . '/symphony/lib/boot/bundle.php');" . CRLF . '?>'; return General::writeFile(CONFIG, $string, $this->getConfigVar("write_mode", "file")); }
/** * A wrapper for `General::writeFile`, this function takes a `$path` * and a `$data` and writes the new template to disk. * * @param string $path * The path to write the template to * @param string $data * The contents of the template * @return boolean * True when written successfully, false otherwise */ public static function writePageFiles($path, $data) { return General::writeFile($path, $data, Symphony::Configuration()->get('write_mode', 'file')); }
public function __formAction() { $fields = $_POST['fields']; $this->_errors = array(); $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::EVENT); $providerClass = null; if (trim($fields['name']) == '') { $this->_errors['name'] = __('This is a required field'); } if (trim($fields['source']) == '') { $this->_errors['source'] = __('This is a required field'); } $filters = isset($fields['filters']) ? $fields['filters'] : array(); // See if a Provided Datasource is saved if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getSource'))) { call_user_func_array(array($providerClass, 'validate'), array(&$fields, &$this->_errors)); break; } unset($providerClass); } } $classname = Lang::createHandle($fields['name'], 255, '_', false, true, array('@^[^a-z\\d]+@i' => '', '/[^\\w-\\.]/i' => '')); $rootelement = str_replace('_', '-', $classname); $extends = 'SectionEvent'; // Check to make sure the classname is not empty after handlisation. if (empty($classname) && !isset($this->_errors['name'])) { $this->_errors['name'] = __('Please ensure name contains at least one Latin-based character.', array($classname)); } $file = EVENTS . '/event.' . $classname . '.php'; $isDuplicate = false; $queueForDeletion = NULL; if ($this->_context[0] == 'new' && is_file($file)) { $isDuplicate = true; } else { if ($this->_context[0] == 'edit') { $existing_handle = $this->_context[1]; if ($classname != $existing_handle && is_file($file)) { $isDuplicate = true; } else { if ($classname != $existing_handle) { $queueForDeletion = EVENTS . '/event.' . $existing_handle . '.php'; } } } } // Duplicate if ($isDuplicate) { $this->_errors['name'] = __('An Event with the name %s already exists', array('<code>' . $classname . '</code>')); } if (empty($this->_errors)) { $multiple = in_array('expect-multiple', $filters); $elements = NULL; $placeholder = '<!-- GRAB -->'; $source = $fields['source']; $params = array('rootelement' => $rootelement); $about = array('name' => $fields['name'], 'version' => 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), 'release date' => DateTimeObj::getGMT('c'), 'author name' => Administration::instance()->Author->getFullName(), 'author website' => URL, 'author email' => Administration::instance()->Author->get('email')); // If there is a provider, get their template if ($providerClass) { $eventShell = file_get_contents(call_user_func(array($providerClass, 'getTemplate'))); } else { $eventShell = file_get_contents($this->getTemplate('blueprints.event')); $about['trigger condition'] = $rootelement; } $this->__injectAboutInformation($eventShell, $about); // Replace the name $eventShell = str_replace('<!-- CLASS NAME -->', $classname, $eventShell); // Build the templates if ($providerClass) { $eventShell = call_user_func(array($providerClass, 'prepare'), $fields, $params, $eventShell); } else { $this->__injectFilters($eventShell, $filters); // Add Documentation $documentation = NULL; $documentation_parts = array(); $documentation_parts[] = new XMLElement('h3', __('Success and Failure XML Examples')); $documentation_parts[] = new XMLElement('p', __('When saved successfully, the following XML will be returned:')); if ($multiple) { $code = new XMLElement($rootelement); $entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'success', 'type' => 'create | edit')); $entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.'))); $code->appendChild($entry); } else { $code = new XMLElement($rootelement, NULL, array('result' => 'success', 'type' => 'create | edit')); $code->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.'))); } $documentation_parts[] = self::processDocumentationCode($code); $documentation_parts[] = new XMLElement('p', __('When an error occurs during saving, due to either missing or invalid fields, the following XML will be returned') . ($multiple ? ' (<strong> ' . __('Notice that it is possible to get mixtures of success and failure messages when using the ‘Allow Multiple’ option') . '</strong>)' : NULL) . ':'); if ($multiple) { $code = new XMLElement($rootelement); $entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'error')); $entry->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'))); $entry->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing'))); $code->appendChild($entry); $entry = new XMLElement('entry', NULL, array('index' => '1', 'result' => 'success', 'type' => 'create | edit')); $entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.'))); $code->appendChild($entry); } else { $code = new XMLElement($rootelement, NULL, array('result' => 'error')); $code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'))); $code->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing'))); } $code->setValue('...', false); $documentation_parts[] = self::processDocumentationCode($code); if (is_array($filters) && !empty($filters)) { $documentation_parts[] = new XMLElement('p', __('The following is an example of what is returned if any options return an error:')); $code = new XMLElement($rootelement, NULL, array('result' => 'error')); $code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'))); $code->appendChild(new XMLElement('filter', NULL, array('name' => 'admin-only', 'status' => 'failed'))); $code->appendChild(new XMLElement('filter', __('Recipient not found'), array('name' => 'send-email', 'status' => 'failed'))); $code->setValue('...', false); $documentation_parts[] = self::processDocumentationCode($code); } $documentation_parts[] = new XMLElement('h3', __('Example Front-end Form Markup')); $documentation_parts[] = new XMLElement('p', __('This is an example of the form markup you can use on your frontend:')); $container = new XMLElement('form', NULL, array('method' => 'post', 'action' => '', 'enctype' => 'multipart/form-data')); $container->appendChild(Widget::Input('MAX_FILE_SIZE', (string) min(ini_size_to_bytes(ini_get('upload_max_filesize')), Symphony::Configuration()->get('max_upload_size', 'admin')), 'hidden')); if (is_numeric($fields['source'])) { $section = SectionManager::fetch($fields['source']); if ($section instanceof Section) { $section_fields = $section->fetchFields(); if (is_array($section_fields) && !empty($section_fields)) { foreach ($section_fields as $f) { if ($f->getExampleFormMarkup() instanceof XMLElement) { $container->appendChild($f->getExampleFormMarkup()); } } } } } $container->appendChild(Widget::Input('action[' . $rootelement . ']', __('Submit'), 'submit')); $code = $container->generate(true); $documentation_parts[] = self::processDocumentationCode($multiple ? str_replace('fields[', 'fields[0][', $code) : $code); $documentation_parts[] = new XMLElement('p', __('To edit an existing entry, include the entry ID value of the entry in the form. This is best as a hidden field like so:')); $documentation_parts[] = self::processDocumentationCode(Widget::Input('id' . ($multiple ? '[0]' : NULL), '23', 'hidden')); $documentation_parts[] = new XMLElement('p', __('To redirect to a different location upon a successful save, include the redirect location in the form. This is best as a hidden field like so, where the value is the URL to redirect to:')); $documentation_parts[] = self::processDocumentationCode(Widget::Input('redirect', URL . '/success/', 'hidden')); if (in_array('send-email', $filters)) { $documentation_parts[] = new XMLElement('h3', __('Send Notification Email')); $documentation_parts[] = new XMLElement('p', __('Upon the event successfully saving the entry, this option takes input from the form and send an email to the desired recipient.') . ' <strong>' . __('It currently does not work with ‘Allow Multiple’') . '</strong>. ' . __('The following are the recognised fields:')); $documentation_parts[] = self::processDocumentationCode('send-email[sender-email] // ' . __('Optional') . PHP_EOL . 'send-email[sender-name] // ' . __('Optional') . PHP_EOL . 'send-email[reply-to-email] // ' . __('Optional') . PHP_EOL . 'send-email[reply-to-name] // ' . __('Optional') . PHP_EOL . 'send-email[subject]' . PHP_EOL . 'send-email[body]' . PHP_EOL . 'send-email[recipient] // ' . __('list of comma-separated author usernames.')); $documentation_parts[] = new XMLElement('p', __('All of these fields can be set dynamically using the exact field name of another field in the form as shown below in the example form:')); $documentation_parts[] = self::processDocumentationCode('<form action="" method="post"> <fieldset> <label>' . __('Name') . ' <input type="text" name="fields[author]" value="" /></label> <label>' . __('Email') . ' <input type="text" name="fields[email]" value="" /></label> <label>' . __('Message') . ' <textarea name="fields[message]" rows="5" cols="21"></textarea></label> <input name="send-email[sender-email]" value="fields[email]" type="hidden" /> <input name="send-email[sender-name]" value="fields[author]" type="hidden" /> <input name="send-email[reply-to-email]" value="fields[email]" type="hidden" /> <input name="send-email[reply-to-name]" value="fields[author]" type="hidden" /> <input name="send-email[subject]" value="You are being contacted" type="hidden" /> <input name="send-email[body]" value="fields[message]" type="hidden" /> <input name="send-email[recipient]" value="fred" type="hidden" /> <input id="submit" type="submit" name="action[save-contact-form]" value="Send" /> </fieldset> </form>'); } /** * Allows adding documentation for new filters. A reference to the $documentation * array is provided, along with selected filters * @delegate AppendEventFilterDocumentation * @param string $context * '/blueprints/events/(edit|new|info)/' * @param array $selected * An array of all the selected filters for this Event * @param array $documentation * An array of all the documentation XMLElements, passed by reference */ Symphony::ExtensionManager()->notifyMembers('AppendEventFilterDocumentation', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'documentation' => &$documentation_parts)); $documentation = join(PHP_EOL, array_map(create_function('$x', 'return rtrim($x->generate(true, 4));'), $documentation_parts)); $documentation = str_replace('\'', '\\\'', $documentation); $eventShell = str_replace('<!-- CLASS EXTENDS -->', $extends, $eventShell); $eventShell = str_replace('<!-- DOCUMENTATION -->', General::tabsToSpaces($documentation, 2), $eventShell); } $eventShell = str_replace('<!-- ROOT ELEMENT -->', $rootelement, $eventShell); $eventShell = str_replace('<!-- CLASS NAME -->', $classname, $eventShell); $eventShell = str_replace('<!-- SOURCE -->', $source, $eventShell); // Remove left over placeholders $eventShell = preg_replace(array('/<!--[\\w ]++-->/'), '', $eventShell); if ($this->_context[0] == 'new') { /** * Prior to creating an Event, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate EventsPreCreate * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $contents * The contents for this Event as a string passed by reference * @param array $filters * An array of the filters attached to this event */ Symphony::ExtensionManager()->notifyMembers('EventPreCreate', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters)); } else { /** * Prior to editing an Event, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate EventPreEdit * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $contents * The contents for this Event as a string passed by reference * @param array $filters * An array of the filters attached to this event */ Symphony::ExtensionManager()->notifyMembers('EventPreEdit', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters)); } // Write the file if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $eventShell, Symphony::Configuration()->get('write_mode', 'file')))) { $this->pageAlert(__('Failed to write Event to disk.') . ' ' . __('Please check permissions on %s.', array('<code>/workspace/events</code>')), Alert::ERROR); } else { if ($queueForDeletion) { General::deleteFile($queueForDeletion); $pages = PageManager::fetch(false, array('events', 'id'), array("\n\t\t\t\t\t\t\t`events` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]'\n\t\t\t\t\t\t")); if (is_array($pages) && !empty($pages)) { foreach ($pages as $page) { $page['events'] = preg_replace('/\\b' . $existing_handle . '\\b/i', $classname, $page['events']); PageManager::edit($page['id'], $page); } } } if ($this->_context[0] == 'new') { /** * After creating the Event, the path to the Event file is provided * * @delegate EventPostCreate * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file */ Symphony::ExtensionManager()->notifyMembers('EventPostCreate', '/blueprints/events/', array('file' => $file)); } else { /** * After editing the Event, the path to the Event file is provided * * @delegate EventPostEdit * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $previous_file * The path of the previous Event file in the case where an Event may * have been renamed. To get the handle from this value, see * `EventManager::__getHandleFromFilename` */ Symphony::ExtensionManager()->notifyMembers('EventPostEdit', '/blueprints/events/', array('file' => $file, 'previous_file' => $queueForDeletion ? $queueForDeletion : null)); } redirect(SYMPHONY_URL . '/blueprints/events/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } }
function action() { $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) { $fields = $_POST['fields']; $this->_errors = array(); if (!isset($fields['name']) || trim($fields['name']) == '') { $this->_errors['name'] = __('Name is a required field.'); } if (!isset($fields['body']) || trim($fields['body']) == '') { $this->_errors['body'] = __('Body is a required field.'); } elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) { $this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message'])); } if (empty($this->_errors)) { $fields['name'] = Lang::createFilename($fields['name']); if (General::right($fields['name'], 4) != '.xsl') { $fields['name'] .= '.xsl'; } $file = UTILITIES . '/' . $fields['name']; ##Duplicate if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } elseif ($this->_context[0] == 'new' && is_file($file)) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } elseif (!($write = General::writeFile($file, $fields['body'], $this->_Parent->Configuration->get('write_mode', 'file')))) { $this->pageAlert(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), Alert::ERROR); } else { ## Remove any existing file if the filename has changed if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) { General::deleteFile(UTILITIES . '/' . $this->_existing_file); } ## TODO: Fix me ### # Delegate: Edit # Description: After saving the asset, the file path is provided. //$ExtensionManager->notifyMembers('Edit', getCurrentPage(), array('file' => $file)); redirect(URL . '/symphony/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } } elseif ($this->_context[0] == 'edit' && @array_key_exists('delete', $_POST['action'])) { ## TODO: Fix me ### # Delegate: Delete # Description: Prior to deleting the asset file. Target file path is provided. //$ExtensionManager->notifyMembers('Delete', getCurrentPage(), array('file' => WORKSPACE . '/' . $this->_existing_file_rel)); General::deleteFile(UTILITIES . '/' . $this->_existing_file); redirect(URL . '/symphony/blueprints/components/'); } }
public function __formAction() { $fields = $_POST['fields']; $this->_errors = array(); if (trim($fields['name']) == '') { $this->_errors['name'] = __('This is a required field'); } if (trim($fields['source']) == '') { $this->_errors['source'] = __('This is a required field'); } $filters = is_array($fields['filters']) ? $fields['filters'] : array(); $classname = Lang::createHandle($fields['name'], NULL, '_', false, true, array('@^[^a-z]+@i' => '', '/[^\\w-\\.]/i' => '')); $rootelement = str_replace('_', '-', $classname); $file = EVENTS . '/event.' . $classname . '.php'; $isDuplicate = false; $queueForDeletion = NULL; if ($this->_context[0] == 'new' && is_file($file)) { $isDuplicate = true; } elseif ($this->_context[0] == 'edit') { $existing_handle = $this->_context[1]; if ($classname != $existing_handle && is_file($file)) { $isDuplicate = true; } elseif ($classname != $existing_handle) { $queueForDeletion = EVENTS . '/event.' . $existing_handle . '.php'; } } ##Duplicate if ($isDuplicate) { $this->_errors['name'] = __('An Event with the name <code>%s</code> name already exists', array($classname)); } if (empty($this->_errors)) { $multiple = in_array('expect-multiple', $filters); $eventShell = file_get_contents(TEMPLATE . '/event.tpl'); $about = array('name' => $fields['name'], 'version' => '1.0', 'release date' => DateTimeObj::getGMT('c'), 'author name' => Administration::instance()->Author->getFullName(), 'author website' => URL, 'author email' => Administration::instance()->Author->get('email'), 'trigger condition' => $rootelement); $source = $fields['source']; $filter = NULL; $elements = NULL; $this->__injectAboutInformation($eventShell, $about); $this->__injectFilters($eventShell, $filters); $documentation = NULL; $documentation_parts = array(); $documentation_parts[] = new XMLElement('h3', __('Success and Failure XML Examples')); $documentation_parts[] = new XMLElement('p', __('When saved successfully, the following XML will be returned:')); if ($multiple) { $code = new XMLElement($rootelement); $entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'success', 'type' => 'create | edit')); $entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.'))); $code->appendChild($entry); } else { $code = new XMLElement($rootelement, NULL, array('result' => 'success', 'type' => 'create | edit')); $code->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.'))); } $documentation_parts[] = self::processDocumentationCode($code); ### $documentation_parts[] = new XMLElement('p', __('When an error occurs during saving, due to either missing or invalid fields, the following XML will be returned') . ($multiple ? __(' (<b>Notice that it is possible to get mixtures of success and failure messages when using the "Allow Multiple" option</b>)') : NULL) . ':'); if ($multiple) { $code = new XMLElement($rootelement); $entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'error')); $entry->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'))); $entry->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing'))); $code->appendChild($entry); $entry = new XMLElement('entry', NULL, array('index' => '1', 'result' => 'success', 'type' => 'create | edit')); $entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.'))); $code->appendChild($entry); } else { $code = new XMLElement($rootelement, NULL, array('result' => 'error')); $code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'))); $code->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing'))); } $code->setValue('...', false); $documentation_parts[] = self::processDocumentationCode($code); ### if (is_array($filters) && !empty($filters)) { $documentation_parts[] = new XMLElement('p', __('The following is an example of what is returned if any options return an error:')); $code = new XMLElement($rootelement, NULL, array('result' => 'error')); $code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'))); $code->appendChild(new XMLElement('filter', NULL, array('name' => 'admin-only', 'status' => 'failed'))); $code->appendChild(new XMLElement('filter', __('Recipient not found'), array('name' => 'send-email', 'status' => 'failed'))); $code->setValue('...', false); $documentation_parts[] = self::processDocumentationCode($code); } ### $documentation_parts[] = new XMLElement('h3', __('Example Front-end Form Markup')); $documentation_parts[] = new XMLElement('p', __('This is an example of the form markup you can use on your frontend:')); $container = new XMLElement('form', NULL, array('method' => 'post', 'action' => '', 'enctype' => 'multipart/form-data')); $container->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden')); $sectionManager = new SectionManager($this->_Parent); $section = $sectionManager->fetch($fields['source']); $section_fields = $section->fetchFields(); if (is_array($section_fields) && !empty($section_fields)) { foreach ($section_fields as $f) { if ($f->getExampleFormMarkup() instanceof XMLElement) { $container->appendChild($f->getExampleFormMarkup()); } } } $container->appendChild(Widget::Input('action[' . $rootelement . ']', __('Submit'), 'submit')); $code = $container->generate(true); $documentation_parts[] = self::processDocumentationCode($multiple ? str_replace('fields[', 'fields[0][', $code) : $code); $documentation_parts[] = new XMLElement('p', __('To edit an existing entry, include the entry ID value of the entry in the form. This is best as a hidden field like so:')); $documentation_parts[] = self::processDocumentationCode(Widget::Input('id' . ($multiple ? '[0]' : NULL), 23, 'hidden')); $documentation_parts[] = new XMLElement('p', __('To redirect to a different location upon a successful save, include the redirect location in the form. This is best as a hidden field like so, where the value is the URL to redirect to:')); $documentation_parts[] = self::processDocumentationCode(Widget::Input('redirect', URL . '/success/', 'hidden')); if (in_array('send-email', $filters)) { $documentation_parts[] = new XMLElement('h3', __('Send Notification Email')); $documentation_parts[] = new XMLElement('p', __('Upon the event successfully saving the entry, this option takes input from the form and send an email to the desired recipient. <b>It currently does not work with "Allow Multiple".</b> The following are the recognised fields:')); $documentation_parts[] = self::processDocumentationCode('send-email[sender-email] // ' . __('Optional') . self::CRLF . 'send-email[sender-name] // ' . __('Optional') . self::CRLF . 'send-email[reply-to-email] // ' . __('Optional') . self::CRLF . 'send-email[reply-to-name] // ' . __('Optional') . self::CRLF . 'send-email[subject]' . self::CRLF . 'send-email[body]' . self::CRLF . 'send-email[recipient] // ' . __('list of comma-separated author usernames.')); $documentation_parts[] = new XMLElement('p', __('All of these fields can be set dynamically using the exact field name of another field in the form as shown below in the example form:')); $documentation_parts[] = self::processDocumentationCode('<form action="" method="post"> <fieldset> <label>' . __('Name') . ' <input type="text" name="fields[author]" value="" /></label> <label>' . __('Email') . ' <input type="text" name="fields[email]" value="" /></label> <label>' . __('Message') . ' <textarea name="fields[message]" rows="5" cols="21"></textarea></label> <input name="send-email[sender-email]" value="fields[email]" type="hidden" /> <input name="send-email[sender-name]" value="fields[author]" type="hidden" /> <input name="send-email[reply-to-email]" value="fields[email]" type="hidden" /> <input name="send-email[reply-to-name]" value="fields[author]" type="hidden" /> <input name="send-email[subject]" value="You are being contacted" type="hidden" /> <input name="send-email[body]" value="fields[message]" type="hidden" /> <input name="send-email[recipient]" value="fred" type="hidden" /> <input id="submit" type="submit" name="action[save-contact-form]" value="Send" /> </fieldset> </form>'); } /** * Allows adding documentation for new filters. A reference to the $documentation * array is provided, along with selected filters * @delegate AppendEventFilterDocumentation * @param string $context * '/blueprints/events/(edit|new|info)/' * @param array $selected * An array of all the selected filters for this Event * @param array $documentation * An array of all the documentation XMLElements, passed by reference */ Symphony::ExtensionManager()->notifyMembers('AppendEventFilterDocumentation', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'documentation' => &$documentation_parts)); $documentation = join(self::CRLF, array_map(create_function('$x', 'return rtrim($x->generate(true, 4));'), $documentation_parts)); $documentation = str_replace('\'', '\\\'', $documentation); $eventShell = str_replace('<!-- CLASS NAME -->', $classname, $eventShell); $eventShell = str_replace('<!-- SOURCE -->', $source, $eventShell); $eventShell = str_replace('<!-- DOCUMENTATION -->', General::tabsToSpaces($documentation, 2), $eventShell); $eventShell = str_replace('<!-- ROOT ELEMENT -->', $rootelement, $eventShell); ## Remove left over placeholders $eventShell = preg_replace(array('/<!--[\\w ]++-->/'), '', $eventShell); if ($this->_context[0] == 'new') { /** * Prior to creating an Event, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate EventsPreCreate * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $contents * The contents for this Event as a string passed by reference * @param array $filters * An array of the filters attached to this event */ Symphony::ExtensionManager()->notifyMembers('EventPreCreate', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters)); } else { /** * Prior to editing an Event, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate EventPreEdit * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $contents * The contents for this Event as a string passed by reference * @param array $filters * An array of the filters attached to this event */ Symphony::ExtensionManager()->notifyMembers('EventPreEdit', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters)); } // Write the file if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $eventShell, Symphony::Configuration()->get('write_mode', 'file')))) { $this->pageAlert(__('Failed to write Event to <code>%s</code>. Please check permissions.', array(EVENTS)), Alert::ERROR); } else { if ($queueForDeletion) { General::deleteFile($queueForDeletion); $sql = "SELECT * FROM `tbl_pages` WHERE `events` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]' "; $pages = Symphony::Database()->fetch($sql); if (is_array($pages) && !empty($pages)) { foreach ($pages as $page) { $page['events'] = preg_replace('/\\b' . $existing_handle . '\\b/i', $classname, $page['events']); Symphony::Database()->update($page, 'tbl_pages', "`id` = '" . $page['id'] . "'"); } } } if ($this->_context[0] == 'new') { /** * After creating the Event, the path to the Event file is provided * * @delegate EventPostCreate * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file */ Symphony::ExtensionManager()->notifyMembers('EventPostCreate', '/blueprints/events/', array('file' => $file)); } else { /** * After editing the Event, the path to the Event file is provided * * @delegate EventPostEdit * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file */ Symphony::ExtensionManager()->notifyMembers('EventPostEdit', '/blueprints/events/', array('file' => $file)); } redirect(SYMPHONY_URL . '/blueprints/events/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } }
/** * Writes the current Symphony Configuration object to a file in the * CONFIG directory. This will overwrite any existing configuration * file every time this function is called. * * @see core.Configuration#__toString() * @return boolean * True if the Configuration object was successfully written, false otherwise */ public function saveConfig() { $string = "<?php\n\t\$settings = " . (string) self::Configuration() . ";\n"; return General::writeFile(CONFIG, $string, self::Configuration()->get('write_mode', 'file')); }
public static function save(self $view, MessageStack &$messages, $simulate = false) { if (!isset($view->title) || strlen(trim($view->title)) == 0) { $messages->append('title', __('Title is required.')); } $pathname = sprintf('%s/%s/%s.config.xml', VIEWS, $view->path, $view->handle); if (file_exists($pathname)) { $existing = self::loadFromPath($view->path); if ($existing->guid != $view->guid) { $messages->append('handle', 'A view with that handle already exists.'); } unset($existing); } if (isset($view->types) && is_array($view->types) && (bool) array_intersect($view->types, array('index', '404', '403'))) { foreach ($view->types as $t) { switch ($t) { case 'index': case '404': case '403': $views = self::findFromType($t); if (isset($views[$view->guid])) { unset($views[$view->guid]); } if (!empty($views)) { $messages->append('types', __('A view of type "%s" already exists.', array($t))); break 2; } break; } } } if (strlen(trim($view->template)) == 0) { $messages->append('template', 'Template is required, and cannot be empty.'); } elseif (!General::validateXML($view->template, $errors)) { $fragment = Administration::instance()->Page->createDocumentFragment(); $fragment->appendChild(new DOMText(__('This document is not well formed. The following error was returned: '))); $fragment->appendChild(Administration::instance()->Page->createElement('code', $errors->current()->message)); $messages->append('template', $fragment); } if ($messages->length() > 0) { throw new ViewException(__('View could not be saved. Validation failed.'), self::ERROR_MISSING_OR_INVALID_FIELDS); } if ($simulate != true) { if (!is_dir(dirname($pathname)) && !mkdir(dirname($pathname), intval(Symphony::Configuration()->core()->symphony->{'directory-write-mode'}, 8), true)) { throw new ViewException(__('Could not create view directory. Please check permissions on <code>%s</code>.', $view->path), self::ERROR_FAILED_TO_WRITE); } // Save the config if (!General::writeFile($pathname, (string) $view, Symphony::Configuration()->core()->symphony->{'file-write-mode'})) { throw new ViewException(__('View configuration XML could not be written to disk. Please check permissions on <code>%s</code>.', $view->path), self::ERROR_FAILED_TO_WRITE); } // Save the template file $result = General::writeFile(sprintf('%s/%s/%s.xsl', VIEWS, $view->path, $view->handle), $view->template, Symphony::Configuration()->core()->symphony->{'file-write-mode'}); if (!$result) { throw new ViewException(__('Template could not be written to disk. Please check permissions on <code>%s</code>.', $view->path), self::ERROR_FAILED_TO_WRITE); } } return true; }
public function action() { if (!array_key_exists('save', $_POST['action']) && !array_key_exists('done', $_POST['action'])) { return; } $fields = $_POST['fields']; $this->_errors = array(); if (!isset($fields['name']) || strlen(trim($fields['name'])) == 0) { $this->_errors['name'] = 'Name is a required field.'; } else { $filename = strtolower(Lang::createFilename($fields['name'] . '.task')); $file = realpath(MANIFEST . '/cron') . '/' . $filename; ##Duplicate if (file_exists($file)) { $this->_errors['name'] = __('A task with that name already exists. Please choose another.'); } } if (!isset($fields['command']) || strlen(trim($fields['command'])) == 0) { $this->_errors['command'] = 'Command is a required field.'; } if (!isset($fields['interval']) || strlen(trim($fields['interval'])) == 0) { $this->_errors['interval'] = 'Interval is a required field.'; } elseif (!is_numeric($fields['interval']) || (int) $fields['interval'] == 0) { $this->_errors['interval'] = 'Interval must be a positive integer value.'; } if (isset($fields['start']) && strlen(trim($fields['start'])) > 0) { $time = strtotime($fields['start']); $info = getdate($time); if ($time == false || $info == false || !checkdate($info['mon'], $info['mday'], $info['year'])) { $this->_errors['start'] = 'Start Date is invalid.'; } } if (isset($fields['finish']) && strlen(trim($fields['finish'])) > 0) { $time = strtotime($fields['finish']); $info = getdate($time); if ($time == false || $info === false || !checkdate($info['mon'], $info['mday'], $info['year'])) { $this->_errors['finish'] = 'Finish Date is invalid.'; } elseif (!isset($this->_errors['start']) && isset($fields['start']) && strlen(trim($fields['start'])) > 0) { if (strtotime($fields['finish']) <= strtotime($fields['start'])) { $this->_errors['finish'] = 'Finish Date must occur <strong>after</strong> Start Date.'; } } } if (empty($this->_errors)) { $task = new Lib\CronTask(Symphony::Database()); $task->path = $file; $task->filename = $filename; $task->name = $fields['name']; $task->command = $fields['command']; $task->setInterval($fields['interval'], $fields['interval-type']); $task->start = strlen(trim($fields['start'])) > 0 ? strtotime($fields['start']) : null; $task->finish = strlen(trim($fields['finish'])) > 0 ? strtotime($fields['finish']) : null; $task->description = $fields['description']; $task->enabled = isset($fields['enabled']) ? true : false; try { $task->save(function ($file, $data) { return General::writeFile($file, $data, Symphony::Configuration()->get('write_mode', 'file')); }); redirect(sprintf("%sedit/%s/created/", preg_replace('/new\\/$/', '', Administration::instance()->getCurrentPageURL()), $filename)); } catch (\Exception $e) { $this->pageAlert($e->getMessage()); } } }
public function __formAction() { $fields = $_POST['fields']; $this->_errors = array(); $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::EVENT); $providerClass = null; if (trim($fields['name']) == '') { $this->_errors['name'] = __('This is a required field'); } if (trim($fields['source']) == '') { $this->_errors['source'] = __('This is a required field'); } $filters = isset($fields['filters']) ? $fields['filters'] : array(); // See if a Provided Datasource is saved if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getSource'))) { call_user_func_array(array($providerClass, 'validate'), array(&$fields, &$this->_errors)); break; } unset($providerClass); } } $classname = Lang::createHandle($fields['name'], 255, '_', false, true, array('@^[^a-z\\d]+@i' => '', '/[^\\w-\\.]/i' => '')); $rootelement = str_replace('_', '-', $classname); $extends = 'SectionEvent'; // Check to make sure the classname is not empty after handlisation. if (empty($classname) && !isset($this->_errors['name'])) { $this->_errors['name'] = __('Please ensure name contains at least one Latin-based character.', array($classname)); } $file = EVENTS . '/event.' . $classname . '.php'; $isDuplicate = false; $queueForDeletion = null; if ($this->_context[0] == 'new' && is_file($file)) { $isDuplicate = true; } elseif ($this->_context[0] == 'edit') { $existing_handle = $this->_context[1]; if ($classname != $existing_handle && is_file($file)) { $isDuplicate = true; } elseif ($classname != $existing_handle) { $queueForDeletion = EVENTS . '/event.' . $existing_handle . '.php'; } } // Duplicate if ($isDuplicate) { $this->_errors['name'] = __('An Event with the name %s already exists', array('<code>' . $classname . '</code>')); } if (empty($this->_errors)) { $multiple = in_array('expect-multiple', $filters); $elements = null; $placeholder = '<!-- GRAB -->'; $source = $fields['source']; $params = array('rootelement' => $rootelement); $about = array('name' => $fields['name'], 'version' => 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), 'release date' => DateTimeObj::getGMT('c'), 'author name' => Symphony::Author()->getFullName(), 'author website' => URL, 'author email' => Symphony::Author()->get('email')); // If there is a provider, get their template if ($providerClass) { $eventShell = file_get_contents(call_user_func(array($providerClass, 'getTemplate'))); } else { $eventShell = file_get_contents($this->getTemplate('blueprints.event')); $about['trigger condition'] = $rootelement; } $this->__injectAboutInformation($eventShell, $about); // Replace the name $eventShell = str_replace('<!-- CLASS NAME -->', $classname, $eventShell); // Build the templates if ($providerClass) { $eventShell = call_user_func(array($providerClass, 'prepare'), $fields, $params, $eventShell); } else { $this->__injectFilters($eventShell, $filters); // Add Documentation require_once CONTENT . '/content.ajaxeventdocumentation.php'; $ajaxEventDoc = new contentAjaxEventDocumentation(); $documentation = null; $doc_parts = array(); // Add Documentation (Success/Failure) $ajaxEventDoc->addEntrySuccessDoc($doc_parts, $rootelement, $fields['source'], $filters); $ajaxEventDoc->addEntryFailureDoc($doc_parts, $rootelement, $fields['source'], $filters); // Filters $ajaxEventDoc->addDefaultFiltersDoc($doc_parts, $rootelement, $fields['source'], $filters); // Frontend Markup $ajaxEventDoc->addFrontendMarkupDoc($doc_parts, $rootelement, $fields['source'], $filters); $ajaxEventDoc->addSendMailFilterDoc($doc_parts, $rootelement, $fields['source'], $filters); /** * Allows adding documentation for new filters. A reference to the $documentation * array is provided, along with selected filters * @delegate AppendEventFilterDocumentation * @param string $context * '/blueprints/events/(edit|new|info)/' * @param array $selected * An array of all the selected filters for this Event * @param array $documentation * An array of all the documentation XMLElements, passed by reference */ Symphony::ExtensionManager()->notifyMembers('AppendEventFilterDocumentation', '/blueprints/events/' . $rootelement . '/', array('selected' => $filters, 'documentation' => &$doc_parts)); $documentation = join(PHP_EOL, array_map(create_function('$x', 'return rtrim($x->generate(true, 4));'), $doc_parts)); $documentation = str_replace('\'', '\\\'', $documentation); $eventShell = str_replace('<!-- CLASS EXTENDS -->', $extends, $eventShell); $eventShell = str_replace('<!-- DOCUMENTATION -->', General::tabsToSpaces($documentation, 4), $eventShell); } $eventShell = str_replace('<!-- ROOT ELEMENT -->', $rootelement, $eventShell); $eventShell = str_replace('<!-- CLASS NAME -->', $classname, $eventShell); $eventShell = str_replace('<!-- SOURCE -->', $source, $eventShell); // Remove left over placeholders $eventShell = preg_replace(array('/<!--[\\w ]++-->/'), '', $eventShell); if ($this->_context[0] == 'new') { /** * Prior to creating an Event, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate EventsPreCreate * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $contents * The contents for this Event as a string passed by reference * @param array $filters * An array of the filters attached to this event */ Symphony::ExtensionManager()->notifyMembers('EventPreCreate', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters)); } else { /** * Prior to editing an Event, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate EventPreEdit * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $contents * The contents for this Event as a string passed by reference * @param array $filters * An array of the filters attached to this event */ Symphony::ExtensionManager()->notifyMembers('EventPreEdit', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters)); } // Write the file if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $eventShell, Symphony::Configuration()->get('write_mode', 'file')))) { $this->pageAlert(__('Failed to write Event to disk.') . ' ' . __('Please check permissions on %s.', array('<code>/workspace/events</code>')), Alert::ERROR); // Write successful } else { if (function_exists('opcache_invalidate')) { opcache_invalidate($file, true); } // Attach this event to pages $connections = $fields['connections']; ResourceManager::setPages(RESOURCE_TYPE_EVENT, is_null($existing_handle) ? $classname : $existing_handle, $connections); if ($queueForDeletion) { General::deleteFile($queueForDeletion); $pages = PageManager::fetch(false, array('events', 'id'), array("\n `events` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]'\n ")); if (is_array($pages) && !empty($pages)) { foreach ($pages as $page) { $page['events'] = preg_replace('/\\b' . $existing_handle . '\\b/i', $classname, $page['events']); PageManager::edit($page['id'], $page); } } } if ($this->_context[0] == 'new') { /** * After creating the Event, the path to the Event file is provided * * @delegate EventPostCreate * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file */ Symphony::ExtensionManager()->notifyMembers('EventPostCreate', '/blueprints/events/', array('file' => $file)); } else { /** * After editing the Event, the path to the Event file is provided * * @delegate EventPostEdit * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file * @param string $previous_file * The path of the previous Event file in the case where an Event may * have been renamed. To get the handle from this value, see * `EventManager::__getHandleFromFilename` */ Symphony::ExtensionManager()->notifyMembers('EventPostEdit', '/blueprints/events/', array('file' => $file, 'previous_file' => $queueForDeletion ? $queueForDeletion : null)); } redirect(SYMPHONY_URL . '/blueprints/events/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } }
public function generatePDFAttachments(&$output) { $params = Frontend::Page()->_param; $dom = new DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $dom->loadHTML($output); if ($dom === false) { return $output; } $xpath = new DOMXPath($dom); // Copy any <link rel='stylesheet'/> or <style type='text/css'> prepend to the blocks $css = ''; $styling = $xpath->query('//link[@rel="stylesheet"] | //style[@type="text/css"]'); if ($styling->length !== 0) { foreach ($styling as $style) { $css .= $dom->saveXML($style); } } // Find anything with @data-utp attribute set to attachment $blocks = $xpath->query('//*[@data-utp = "attachment"]'); if ($blocks->length !== 0) { foreach ($blocks as $block) { // Get the content in those blocks $data = $dom->saveXML($block); // Send the block to the PDF generator, saving it in /TMP $data = $css . $data; $pdf = self::initPDF(); // output the HTML content $pdf->writeHTML($data, true, false, true, false, ''); // reset pointer to the last page $pdf->lastPage(); // get the output of the PDF as a string and save it to a file // attempt to find the filename if it's provided with @data-utp-filename if (!($filename = $xpath->evaluate('string(//@data-utp-filename)'))) { $filename = md5(sprintf('%s - %s', $params['website-name'], $params['page-title'])); } $filename = TMP . '/' . Lang::createFilename($filename) . '.pdf'; General::writeFile($filename, $pdf->Output($filename, 'S'), Symphony::Configuration()->get('write_mode', 'file')); // Replace the attachment node with <link rel='attachment' href='{path/to/file}' /> $link = $dom->createElement('link'); $link->setAttribute('rel', 'attachment'); $link->setAttribute('href', str_replace(DOCROOT, URL, $filename)); $block->parentNode->replaceChild($link, $block); } } $output = $dom->saveHTML(); }
private static function __install() { $fields = $_POST['fields']; $start = time(); Symphony::Log()->writeToLog(PHP_EOL . '============================================', true); Symphony::Log()->writeToLog('INSTALLATION PROCESS STARTED (' . DateTimeObj::get('c') . ')', true); Symphony::Log()->writeToLog('============================================', true); // MySQL: Establishing connection Symphony::Log()->pushToLog('MYSQL: Establishing Connection', E_NOTICE, true, true); try { Symphony::Database()->connect($fields['database']['host'], $fields['database']['user'], $fields['database']['password'], $fields['database']['port'], $fields['database']['db']); } catch (DatabaseException $e) { self::__abort('There was a problem while trying to establish a connection to the MySQL server. Please check your settings.', $start); } // MySQL: Setting prefix & character encoding Symphony::Database()->setPrefix($fields['database']['tbl_prefix']); Symphony::Database()->setCharacterEncoding(); Symphony::Database()->setCharacterSet(); // MySQL: Importing schema Symphony::Log()->pushToLog('MYSQL: Importing Table Schema', E_NOTICE, true, true); try { Symphony::Database()->import(file_get_contents(INSTALL . '/includes/install.sql'), true); } catch (DatabaseException $e) { self::__abort('There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), $start); } // MySQL: Creating default author Symphony::Log()->pushToLog('MYSQL: Creating Default Author', E_NOTICE, true, true); try { Symphony::Database()->insert(array('id' => 1, 'username' => Symphony::Database()->cleanValue($fields['user']['username']), 'password' => Cryptography::hash(Symphony::Database()->cleanValue($fields['user']['password'])), 'first_name' => Symphony::Database()->cleanValue($fields['user']['firstname']), 'last_name' => Symphony::Database()->cleanValue($fields['user']['lastname']), 'email' => Symphony::Database()->cleanValue($fields['user']['email']), 'last_seen' => NULL, 'user_type' => 'developer', 'primary' => 'yes', 'default_area' => NULL, 'auth_token_active' => 'no'), 'tbl_authors'); } catch (DatabaseException $e) { self::__abort('There was an error while trying create the default author. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), $start); } // Configuration: Populating array $conf = Symphony::Configuration()->get(); foreach ($conf as $group => $settings) { foreach ($settings as $key => $value) { if (isset($fields[$group]) && isset($fields[$group][$key])) { $conf[$group][$key] = $fields[$group][$key]; } } } // Create manifest folder structure Symphony::Log()->pushToLog('WRITING: Creating ‘manifest’ folder (/manifest)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/manifest', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘manifest’ directory. Check permission on the root folder.', $start); } Symphony::Log()->pushToLog('WRITING: Creating ‘logs’ folder (/manifest/logs)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/manifest/logs', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘logs’ directory. Check permission on /manifest.', $start); } Symphony::Log()->pushToLog('WRITING: Creating ‘cache’ folder (/manifest/cache)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/manifest/cache', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘cache’ directory. Check permission on /manifest.', $start); } Symphony::Log()->pushToLog('WRITING: Creating ‘tmp’ folder (/manifest/tmp)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/manifest/tmp', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘tmp’ directory. Check permission on /manifest.', $start); } // Writing configuration file Symphony::Log()->pushToLog('WRITING: Configuration File', E_NOTICE, true, true); Symphony::Configuration()->setArray($conf); if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { self::__abort('Could not create config file ‘' . CONFIG . '’. Check permission on /manifest.', $start); } // Writing htaccess file Symphony::Log()->pushToLog('CONFIGURING: Frontend', E_NOTICE, true, true); $rewrite_base = ltrim(preg_replace('/\\/install$/i', NULL, dirname($_SERVER['PHP_SELF'])), '/'); $htaccess = str_replace('<!-- REWRITE_BASE -->', $rewrite_base, file_get_contents(INSTALL . '/includes/htaccess.txt')); if (!General::writeFile(DOCROOT . "/.htaccess", $htaccess, $conf['file']['write_mode'], 'a')) { self::__abort('Could not write ‘.htaccess’ file. Check permission on ' . DOCROOT, $start); } // Writing /workspace folder if (!is_dir(DOCROOT . '/workspace')) { // Create workspace folder structure Symphony::Log()->pushToLog('WRITING: Creating ‘workspace’ folder (/workspace)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/workspace', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘workspace’ directory. Check permission on the root folder.', $start); } Symphony::Log()->pushToLog('WRITING: Creating ‘data-sources’ folder (/workspace/data-sources)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/workspace/data-sources', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘workspace/data-sources’ directory. Check permission on the root folder.', $start); } Symphony::Log()->pushToLog('WRITING: Creating ‘events’ folder (/workspace/events)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/workspace/events', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘workspace/events’ directory. Check permission on the root folder.', $start); } Symphony::Log()->pushToLog('WRITING: Creating ‘pages’ folder (/workspace/pages)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/workspace/pages', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘workspace/pages’ directory. Check permission on the root folder.', $start); } Symphony::Log()->pushToLog('WRITING: Creating ‘utilities’ folder (/workspace/utilities)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/workspace/utilities', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘workspace/utilities’ directory. Check permission on the root folder.', $start); } } else { Symphony::Log()->pushToLog('An existing ‘workspace’ directory was found at this location. Symphony will use this workspace.', E_NOTICE, true, true); // MySQL: Importing workspace data Symphony::Log()->pushToLog('MYSQL: Importing Workspace Data...', E_NOTICE, true, true); if (is_file(DOCROOT . '/workspace/install.sql')) { try { Symphony::Database()->import(file_get_contents(DOCROOT . '/workspace/install.sql'), $fields['database']['use-server-encoding'] != 'yes' ? true : false, true); } catch (DatabaseException $e) { self::__abort('There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), $start); } } } // Write extensions folder if (!is_dir(DOCROOT . '/extensions')) { // Create extensions folder Symphony::Log()->pushToLog('WRITING: Creating ‘extensions’ folder (/extensions)', E_NOTICE, true, true); if (!General::realiseDirectory(DOCROOT . '/extensions', $conf['directory']['write_mode'])) { self::__abort('Could not create ‘extension’ directory. Check permission on the root folder.', $start); } } // Install existing extensions Symphony::Log()->pushToLog('CONFIGURING: Installing existing extensions', E_NOTICE, true, true); $disabled_extensions = array(); foreach (new DirectoryIterator(EXTENSIONS) as $e) { if ($e->isDot() || $e->isFile() || !is_file($e->getRealPath() . '/extension.driver.php')) { continue; } $handle = $e->getBasename(); try { if (!ExtensionManager::enable($handle)) { $disabled_extensions[] = $handle; Symphony::Log()->pushToLog('Could not enable the extension ‘' . $handle . '’.', E_NOTICE, true, true); } } catch (Exception $ex) { $disabled_extensions[] = $handle; Symphony::Log()->pushToLog('Could not enable the extension ‘' . $handle . '’. ' . $ex->getMessage(), E_NOTICE, true, true); } } // Loading default language if (isset($_REQUEST['lang']) && $_REQUEST['lang'] != 'en') { Symphony::Log()->pushToLog('CONFIGURING: Default language', E_NOTICE, true, true); $language = Lang::Languages(); $language = $language[$_REQUEST['lang']]; // Is the language extension enabled? if (in_array('lang_' . $language['handle'], ExtensionManager::listInstalledHandles())) { Symphony::Configuration()->set('lang', $_REQUEST['lang'], 'symphony'); if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { Symphony::Log()->pushToLog('Could not write default language ‘' . $language['name'] . '’ to config file.', E_NOTICE, true, true); } } else { Symphony::Log()->pushToLog('Could not enable the desired language ‘' . $language['name'] . '’.', E_NOTICE, true, true); } } // Installation completed. Woo-hoo! Symphony::Log()->writeToLog('============================================', true); Symphony::Log()->writeToLog(sprintf('INSTALLATION COMPLETED: Execution Time - %d sec (%s)', max(1, time() - $start), date('d.m.y H:i:s')), true); Symphony::Log()->writeToLog('============================================' . PHP_EOL . PHP_EOL . PHP_EOL, true); return $disabled_extensions; }
public function __formAction() { $fields = $_POST['fields']; $this->_errors = array(); $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::DATASOURCE); $providerClass = null; if (trim($fields['name']) == '') { $this->_errors['name'] = __('This is a required field'); } if ($fields['source'] == 'static_xml') { if (trim($fields['static_xml']) == '') { $this->_errors['static_xml'] = __('This is a required field'); } else { $xml_errors = null; include_once TOOLKIT . '/class.xsltprocess.php'; General::validateXML($fields['static_xml'], $xml_errors, false, new XsltProcess()); if (!empty($xml_errors)) { $this->_errors['static_xml'] = __('XML is invalid.'); } } } elseif (is_numeric($fields['source'])) { if (strlen(trim($fields['max_records'])) == 0 || is_numeric($fields['max_records']) && $fields['max_records'] < 1) { if ($fields['paginate_results'] === 'yes') { $this->_errors['max_records'] = __('A result limit must be set'); } } elseif (!self::__isValidPageString($fields['max_records'])) { $this->_errors['max_records'] = __('Must be a valid number or parameter'); } if (strlen(trim($fields['page_number'])) == 0 || is_numeric($fields['page_number']) && $fields['page_number'] < 1) { if ($fields['paginate_results'] === 'yes') { $this->_errors['page_number'] = __('A page number must be set'); } } elseif (!self::__isValidPageString($fields['page_number'])) { $this->_errors['page_number'] = __('Must be a valid number or parameter'); } // See if a Provided Datasource is saved } elseif (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getSource'))) { call_user_func_array(array($providerClass, 'validate'), array(&$fields, &$this->_errors)); break; } unset($providerClass); } } $classname = Lang::createHandle($fields['name'], 255, '_', false, true, array('@^[^a-z\\d]+@i' => '', '/[^\\w-\\.]/i' => '')); $rootelement = str_replace('_', '-', $classname); // Check to make sure the classname is not empty after handlisation. if (empty($classname) && !isset($this->_errors['name'])) { $this->_errors['name'] = __('Please ensure name contains at least one Latin-based character.', array($classname)); } $file = DATASOURCES . '/data.' . $classname . '.php'; $isDuplicate = false; $queueForDeletion = null; if ($this->_context[0] == 'new' && is_file($file)) { $isDuplicate = true; } elseif ($this->_context[0] == 'edit') { $existing_handle = $this->_context[1]; if ($classname != $existing_handle && is_file($file)) { $isDuplicate = true; } elseif ($classname != $existing_handle) { $queueForDeletion = DATASOURCES . '/data.' . $existing_handle . '.php'; } } // Duplicate if ($isDuplicate) { $this->_errors['name'] = __('A Data source with the name %s already exists', array('<code>' . $classname . '</code>')); } if (empty($this->_errors)) { $filters = array(); $elements = null; $source = $fields['source']; $params = array('rootelement' => $rootelement); $about = array('name' => $fields['name'], 'version' => 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), 'release date' => DateTimeObj::getGMT('c'), 'author name' => Symphony::Author()->getFullName(), 'author website' => URL, 'author email' => Symphony::Author()->get('email')); // If there is a provider, get their template if ($providerClass) { $dsShell = file_get_contents(call_user_func(array($providerClass, 'getTemplate'))); } else { $dsShell = file_get_contents($this->getTemplate('blueprints.datasource')); } // Author metadata self::injectAboutInformation($dsShell, $about); // Do dependencies, the template file must have <!-- CLASS NAME --> $dsShell = str_replace('<!-- CLASS NAME -->', $classname, $dsShell); // If there is a provider, let them do the prepartion work if ($providerClass) { $dsShell = call_user_func(array($providerClass, 'prepare'), $fields, $params, $dsShell); } else { switch ($source) { case 'authors': $extends = 'AuthorDatasource'; if (isset($fields['filter']['author'])) { $filters = $fields['filter']['author']; } $elements = $fields['xml_elements']; $params['order'] = $fields['order']; $params['redirectonempty'] = $fields['redirect_on_empty']; $params['redirectonforbidden'] = $fields['redirect_on_forbidden']; $params['redirectonrequired'] = $fields['redirect_on_required']; $params['requiredparam'] = trim($fields['required_url_param']); $params['negateparam'] = trim($fields['negate_url_param']); $params['paramoutput'] = $fields['param']; $params['sort'] = $fields['sort']; break; case 'navigation': $extends = 'NavigationDatasource'; if (isset($fields['filter']['navigation'])) { $filters = $fields['filter']['navigation']; } $params['order'] = $fields['order']; $params['redirectonempty'] = $fields['redirect_on_empty']; $params['redirectonforbidden'] = $fields['redirect_on_forbidden']; $params['redirectonrequired'] = $fields['redirect_on_required']; $params['requiredparam'] = trim($fields['required_url_param']); $params['negateparam'] = trim($fields['negate_url_param']); break; case 'static_xml': $extends = 'StaticXMLDatasource'; $fields['static_xml'] = trim($fields['static_xml']); if (preg_match('/^<\\?xml/i', $fields['static_xml']) == true) { // Need to remove any XML declaration $fields['static_xml'] = preg_replace('/^<\\?xml[^>]+>/i', null, $fields['static_xml']); } $params['static'] = sprintf('%s', trim($fields['static_xml'])); break; default: $extends = 'SectionDatasource'; $elements = $fields['xml_elements']; if (is_array($fields['filter']) && !empty($fields['filter'])) { $filters = array(); foreach ($fields['filter'] as $f) { foreach ($f as $key => $val) { $filters[$key] = $val; } } } $params['order'] = $fields['order']; $params['group'] = $fields['group']; $params['paginateresults'] = $fields['paginate_results']; $params['limit'] = $fields['max_records']; $params['startpage'] = $fields['page_number']; $params['redirectonempty'] = $fields['redirect_on_empty']; $params['redirectonforbidden'] = $fields['redirect_on_forbidden']; $params['redirectonrequired'] = $fields['redirect_on_required']; $params['requiredparam'] = trim($fields['required_url_param']); $params['negateparam'] = trim($fields['negate_url_param']); $params['paramoutput'] = $fields['param']; $params['sort'] = $fields['sort']; $params['htmlencode'] = $fields['html_encode']; $params['associatedentrycounts'] = $fields['associated_entry_counts']; break; } $this->__injectVarList($dsShell, $params); $this->__injectIncludedElements($dsShell, $elements); self::injectFilters($dsShell, $filters); if (preg_match_all('@(\\$ds-[0-9a-z_\\.\\-]+)@i', $dsShell, $matches)) { $dependencies = General::array_remove_duplicates($matches[1]); $dsShell = str_replace('<!-- DS DEPENDENCY LIST -->', "'" . implode("', '", $dependencies) . "'", $dsShell); } $dsShell = str_replace('<!-- CLASS EXTENDS -->', $extends, $dsShell); $dsShell = str_replace('<!-- SOURCE -->', $source, $dsShell); } if ($this->_context[0] == 'new') { /** * Prior to creating the Datasource, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate DatasourcePreCreate * @since Symphony 2.2 * @param string $context * '/blueprints/datasources/' * @param string $file * The path to the Datasource file * @param string $contents * The contents for this Datasource as a string passed by reference * @param array $params * An array of all the `$dsParam*` values * @param array $elements * An array of all the elements included in this datasource * @param array $filters * An associative array of all the filters for this datasource with the key * being the `field_id` and the value the filter. * @param array $dependencies * An array of dependencies that this datasource has */ Symphony::ExtensionManager()->notifyMembers('DatasourcePreCreate', '/blueprints/datasources/', array('file' => $file, 'contents' => &$dsShell, 'params' => $params, 'elements' => $elements, 'filters' => $filters, 'dependencies' => $dependencies)); } else { /** * Prior to editing a Datasource, the file path where it will be written to * is provided and well as the contents of that file. * * @delegate DatasourcePreEdit * @since Symphony 2.2 * @param string $context * '/blueprints/datasources/' * @param string $file * The path to the Datasource file * @param string $contents * The contents for this Datasource as a string passed by reference * @param array $dependencies * An array of dependencies that this datasource has * @param array $params * An array of all the `$dsParam*` values * @param array $elements * An array of all the elements included in this datasource * @param array $filters * An associative array of all the filters for this datasource with the key * being the `field_id` and the value the filter. */ Symphony::ExtensionManager()->notifyMembers('DatasourcePreEdit', '/blueprints/datasources/', array('file' => $file, 'contents' => &$dsShell, 'dependencies' => $dependencies, 'params' => $params, 'elements' => $elements, 'filters' => $filters)); } // Remove left over placeholders $dsShell = preg_replace(array('/<!--[\\w ]++-->/', '/(\\t+[\\r\\n]){2,}/', '/(\\r\\n){2,}/'), '$1', $dsShell); // Write the file if (!is_writable(dirname($file)) || !General::writeFile($file, $dsShell, Symphony::Configuration()->get('write_mode', 'file'), 'w', true)) { $this->pageAlert(__('Failed to write Data source to disk.') . ' ' . __('Please check permissions on %s.', array('<code>/workspace/data-sources</code>')), Alert::ERROR); // Write successful } else { if (function_exists('opcache_invalidate')) { opcache_invalidate($file, true); } // Attach this datasources to pages $connections = $fields['connections']; ResourceManager::setPages(ResourceManager::RESOURCE_TYPE_DS, is_null($existing_handle) ? $classname : $existing_handle, $connections); // If the datasource has been updated and the name changed, then adjust all the existing pages that have the old datasource name if ($queueForDeletion) { General::deleteFile($queueForDeletion); // Update pages that use this DS $pages = PageManager::fetch(false, array('data_sources', 'id'), array("\n `data_sources` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]'\n ")); if (is_array($pages) && !empty($pages)) { foreach ($pages as $page) { $page['data_sources'] = preg_replace('/\\b' . $existing_handle . '\\b/i', $classname, $page['data_sources']); PageManager::edit($page['id'], $page); } } } if ($this->_context[0] == 'new') { /** * After creating the Datasource, the path to the Datasource file is provided * * @delegate DatasourcePostCreate * @since Symphony 2.2 * @param string $context * '/blueprints/datasources/' * @param string $file * The path to the Datasource file */ Symphony::ExtensionManager()->notifyMembers('DatasourcePostCreate', '/blueprints/datasources/', array('file' => $file)); } else { /** * After editing the Datasource, the path to the Datasource file is provided * * @delegate DatasourcePostEdit * @since Symphony 2.2 * @param string $context * '/blueprints/datasources/' * @param string $file * The path to the Datasource file * @param string $previous_file * The path of the previous Datasource file in the case where a Datasource may * have been renamed. To get the handle from this value, see * `DatasourceManager::__getHandleFromFilename` */ Symphony::ExtensionManager()->notifyMembers('DatasourcePostEdit', '/blueprints/datasources/', array('file' => $file, 'previous_file' => $queueForDeletion ? $queueForDeletion : null)); } redirect(SYMPHONY_URL . '/blueprints/datasources/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } }
function __formAction() { $fields = $_POST['fields']; $this->_errors = array(); if (trim($fields['name']) == '') { $this->_errors['name'] = __('This is a required field'); } if ($fields['source'] == 'static_xml') { if (trim($fields['static_xml']) == '') { $this->_errors['static_xml'] = __('This is a required field'); } else { $xml_errors = NULL; include_once TOOLKIT . '/class.xsltprocess.php'; General::validateXML($fields['static_xml'], $xml_errors, false, new XsltProcess()); if (!empty($xml_errors)) { $this->_errors['static_xml'] = __('XML is invalid'); } } } elseif ($fields['source'] == 'dynamic_xml') { if (trim($fields['dynamic_xml']['url']) == '') { $this->_errors['dynamic_xml']['url'] = __('This is a required field'); } if (trim($fields['dynamic_xml']['xpath']) == '') { $this->_errors['dynamic_xml']['xpath'] = __('This is a required field'); } if (!is_numeric($fields['dynamic_xml']['cache'])) { $this->_errors['dynamic_xml']['cache'] = __('Must be a valid number'); } elseif ($fields['dynamic_xml']['cache'] < 1) { $this->_errors['dynamic_xml']['cache'] = __('Must be greater than zero'); } } else { if ($fields['source'] != 'navigation') { if (strlen(trim($fields['max_records'])) == 0 || is_numeric($fields['max_records']) && $fields['max_records'] < 1) { $this->_errors['max_records'] = __('A result limit must be set'); } elseif (!self::__isValidPageString($fields['max_records'])) { $this->_errors['max_records'] = __('Must be a valid number or parameter'); } if (strlen(trim($fields['page_number'])) == 0 || is_numeric($fields['page_number']) && $fields['page_number'] < 1) { $this->_errors['page_number'] = __('A page number must be set'); } elseif (!self::__isValidPageString($fields['page_number'])) { $this->_errors['page_number'] = __('Must be a valid number or parameter'); } } } $classname = Lang::createHandle($fields['name'], NULL, '_', false, true, array('@^[^a-z]+@i' => '', '/[^\\w-\\.]/i' => '')); $rootelement = str_replace('_', '-', $classname); $file = DATASOURCES . '/data.' . $classname . '.php'; $isDuplicate = false; $queueForDeletion = NULL; if ($this->_context[0] == 'new' && @is_file($file)) { $isDuplicate = true; } elseif ($this->_context[0] == 'edit') { $existing_handle = $this->_context[1]; if ($classname != $existing_handle && @is_file($file)) { $isDuplicate = true; } elseif ($classname != $existing_handle) { $queueForDeletion = DATASOURCES . '/data.' . $existing_handle . '.php'; } } ##Duplicate if ($isDuplicate) { $this->_errors['name'] = __('A Data source with the name <code>%s</code> name already exists', array($classname)); } if (empty($this->_errors)) { $dsShell = file_get_contents(TEMPLATE . '/datasource.tpl'); //$oDate = $this->_Parent->getDateObj(); $params = array('rootelement' => $rootelement); $about = array('name' => $fields['name'], 'version' => '1.0', 'release date' => DateTimeObj::getGMT('c'), 'author name' => $this->_Parent->Author->getFullName(), 'author website' => URL, 'author email' => $this->_Parent->Author->get('email')); $source = $fields['source']; $filter = NULL; $elements = NULL; switch ($source) { case 'authors': $filters = $fields['filter']['author']; $elements = $fields['xml_elements']; $params['order'] = $fields['order']; $params['limit'] = $fields['max_records']; $params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no'; $params['requiredparam'] = $fields['required_url_param']; $params['paramoutput'] = $fields['param']; $params['sort'] = $fields['sort']; $params['startpage'] = $fields['page_number']; $dsShell = str_replace('<!-- GRAB -->', "include(TOOLKIT . '/data-sources/datasource.author.php');", $dsShell); break; case 'navigation': $filters = $fields['filter']['navigation']; $params['order'] = $fields['order']; $params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no'; $params['requiredparam'] = $fields['required_url_param']; $dsShell = str_replace('<!-- GRAB -->', "include(TOOLKIT . '/data-sources/datasource.navigation.php');", $dsShell); break; case 'dynamic_xml': $namespaces = $fields['dynamic_xml']['namespace']; $filters = array(); for ($ii = 0; $ii < count($namespaces['name']); $ii++) { $filters[$namespaces['name'][$ii]] = $namespaces['uri'][$ii]; } $params['url'] = $fields['dynamic_xml']['url']; $params['xpath'] = $fields['dynamic_xml']['xpath']; $params['cache'] = $fields['dynamic_xml']['cache']; $dsShell = str_replace('<!-- GRAB -->', "include(TOOLKIT . '/data-sources/datasource.dynamic_xml.php');", $dsShell); break; case 'static_xml': $value = sprintf('$result = "%s";', addslashes($fields['static_xml'])); $dsShell = str_replace('<!-- GRAB -->', $value, $dsShell); break; default: $elements = $fields['xml_elements']; if (is_array($fields['filter']) && !empty($fields['filter'])) { $filters = array(); foreach ($fields['filter'] as $f) { foreach ($f as $key => $val) { $filters[$key] = $val; } } } $params['order'] = $fields['order']; $params['group'] = $fields['group']; $params['limit'] = $fields['max_records']; $params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no'; $params['requiredparam'] = $fields['required_url_param']; $params['paramoutput'] = $fields['param']; $params['sort'] = $fields['sort']; $params['startpage'] = $fields['page_number']; $params['htmlencode'] = $fields['html_encode']; $dsShell = str_replace('<!-- GRAB -->', "include(TOOLKIT . '/data-sources/datasource.section.php');", $dsShell); break; } $this->__injectVarList($dsShell, $params); $this->__injectAboutInformation($dsShell, $about); $this->__injectIncludedElements($dsShell, $elements); $this->__injectFilters($dsShell, $filters); $dsShell = str_replace('<!-- CLASS NAME -->', $classname, $dsShell); $dsShell = str_replace('<!-- SOURCE -->', $source, $dsShell); if (preg_match_all('@{(\\$ds-[^}]+)}@i', $dsShell, $matches)) { $dependancies = array(); foreach ($matches[1] as $match) { if (preg_match_all('/(\\$ds-[^:]+)/i', $match, $inner_matches)) { $dependancies = array_merge($dependancies, $inner_matches[1]); } } $dependancies = General::array_remove_duplicates($dependancies); $dsShell = str_replace('<!-- DS DEPENDANCY LIST -->', "'" . implode("', '", $dependancies) . "'", $dsShell); } ## Remove left over placeholders $dsShell = preg_replace(array('/<!--[\\w ]++-->/', '/(\\r\\n){2,}/', '/(\\t+[\\r\\n]){2,}/'), '', $dsShell); ##Write the file if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $dsShell, $this->_Parent->Configuration->get('write_mode', 'file')))) { $this->pageAlert(__('Failed to write Data source to <code>%s</code>. Please check permissions.', array(DATASOURCES)), Alert::ERROR); } else { if ($queueForDeletion) { General::deleteFile($queueForDeletion); ## Update pages that use this DS $sql = "SELECT * FROM `tbl_pages` WHERE `data_sources` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]' "; $pages = $this->_Parent->Database->fetch($sql); if (is_array($pages) && !empty($pages)) { foreach ($pages as $page) { $page['data_sources'] = preg_replace('/\\b' . $existing_handle . '\\b/i', $classname, $page['data_sources']); $this->_Parent->Database->update($page, 'tbl_pages', "`id` = '" . $page['id'] . "'"); } } } ### TODO: Fix me ### # Delegate: Create # Description: After saving the datasource, the file path is provided and an array # of variables set by the editor #$ExtensionManager->notifyMembers('Create', getCurrentPage(), array('file' => $file, 'defines' => $defines, 'var' => $var)); redirect(URL . '/symphony/blueprints/datasources/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } }
} else { ##Manipulate some fields $datasources = $fields['data_source']; $events = $fields['events']; unset($fields['data_source']); unset($fields['events']); $fields['name'] = General::sanitize($fields['name']); $fields['handle'] = preg_replace('/[\\s]++/', '-', $fields['name']); $fields['handle'] = preg_replace('/[^-_\\w\\d]++/', '', $fields['handle']); $fields['handle'] = strtolower($fields['handle']); ##Duplicate if ($DB->fetchRow(0, "SELECT * FROM `tbl_utilities` WHERE `handle` = '" . $fields['handle'] . "' LIMIT 1")) { $Admin->pageAlert("duplicate", array("A Utility", "name"), false, 'error'); } else { ##Write the file if (!($write = General::writeFile(WORKSPACE . "/utilities/" . $fields['handle'] . ".xsl", $fields['body'], $Admin->getConfigVar("write_mode", "file")))) { $Admin->pageAlert("write-failed", array("Utility"), false, 'error'); } else { ##No longer need the body text unset($fields['body']); ##Insert the new data if (!$DB->insert($fields, "tbl_utilities")) { define("__SYM_DB_INSERT_FAILED__", true); } else { $id = $DB->getInsertID(); ## Datasources $DB->query("DELETE FROM `tbl_utilities2datasources` WHERE `utility_id` = '{$id}'"); if (is_array($datasources) && !empty($datasources)) { foreach ($datasources as $d) { $DB->query("INSERT INTO tbl_utilities2datasources VALUES ('', '{$id}', '{$d}')"); }
protected function __updatePageFiles($new_path, $new_handle, $old_path = null, $old_handle = null) { $new = PAGES . '/' . $this->__createHandle($new_path, $new_handle) . '.xsl'; $old = PAGES . '/' . $this->__createHandle($old_path, $old_handle) . '.xsl'; $data = null; // Nothing to do: if (file_exists($new) && $new == old) { return true; } // Old file doesn't exist, use template: if (!file_exists($old)) { $data = file_get_contents(TEMPLATE . '/page.xsl'); } else { $data = file_get_contents($old); @unlink($old); } return General::writeFile($new, $data, $this->_Parent->Configuration->get('write_mode', 'file')); }
/** * 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; }
/** * Fetch all subsection elements included in a data source and * join modes into a single call to `appendFormattedElement()`. * Preprocess all subsection entry for performance reasons. * * @see http://symphony-cms.com/learn/api/2.3/delegates/#DataSourceEntriesBuilt */ public function __prepareSubsection(&$context) { $parent = get_parent_class($context['datasource']); // Default Data Source if ($parent == 'DataSource' || $parent == 'SectionDatasource') { $this->__parseSubsectionFields($context['datasource']->dsParamINCLUDEDELEMENTS, $context['datasource']->dsParamROOTELEMENT, $context['datasource']); } elseif ($parent == 'UnionDatasource') { foreach ($context['datasource']->datasources as $datasource) { $this->__parseSubsectionFields($datasource['datasource']->dsParamINCLUDEDELEMENTS, $datasource['datasource']->dsParamROOTELEMENT, $datasource['datasource']); } } // Update field cache if (self::$updateCache == true) { $cache = self::$storage; unset($cache['entries']); General::writeFile(CACHE . '/subsectionmanager-storage', serialize($cache), Symphony::Configuration()->get('write_mode', 'file')); } // Preload entries self::preloadSubsectionEntries($context['entries']['records']); }
public function action() { $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) { $fields = $_POST['fields']; $this->_errors = array(); if (!isset($fields['name']) || trim($fields['name']) == '') { $this->_errors['name'] = __('Name is a required field.'); } if (!isset($fields['body']) || trim($fields['body']) == '') { $this->_errors['body'] = __('Body is a required field.'); } elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) { $this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message'])); } $fields['name'] = Lang::createFilename($fields['name']); if (General::right($fields['name'], 4) != '.xsl') { $fields['name'] .= '.xsl'; } $file = UTILITIES . '/' . $fields['name']; ##Duplicate if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } elseif ($this->_context[0] == 'new' && is_file($file)) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } if (empty($this->_errors)) { if ($this->_context[0] == 'new') { /** * Just before the Utility has been created * * @delegate UtilityPreCreate * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file * @param string $contents * The contents of the `$fields['body']`, passed by reference */ Symphony::ExtensionManager()->notifyMembers('UtilityPreCreate', '/blueprints/utilities/', array('file' => $file, 'contents' => &$fields['body'])); } else { /** * Just before the Utility has been updated * * @delegate UtilityPreEdit * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file * @param string $contents * The contents of the `$fields['body']`, passed by reference */ Symphony::ExtensionManager()->notifyMembers('UtilityPreEdit', '/blueprints/utilities/', array('file' => $file, 'contents' => &$fields['body'])); } ##Write the file if (!($write = General::writeFile($file, $fields['body'], Symphony::Configuration()->get('write_mode', 'file')))) { $this->pageAlert(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), Alert::ERROR); } else { ## Remove any existing file if the filename has changed if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) { General::deleteFile(UTILITIES . '/' . $this->_existing_file); } if ($this->_context[0] == 'new') { /** * Just after the Utility has been written to disk * * @delegate UtilityPostCreate * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file */ Symphony::ExtensionManager()->notifyMembers('UtilityPostCreate', '/blueprints/utilities/', array('file' => $file)); } else { /** * Just after a Utility has been edited and written to disk * * @delegate UtilityPostEdit * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file */ Symphony::ExtensionManager()->notifyMembers('UtilityPostEdit', '/blueprints/utilities/', array('file' => $file)); } redirect(SYMPHONY_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } } elseif ($this->_context[0] == 'edit' && @array_key_exists('delete', $_POST['action'])) { /** * Prior to deleting the Utility * * @delegate UtilityPreDelete * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file */ Symphony::ExtensionManager()->notifyMembers('UtilityPreDelete', '/blueprints/utilities/', array('file' => $this->_existing_file)); General::deleteFile(UTILITIES . '/' . $this->_existing_file); redirect(SYMPHONY_URL . '/blueprints/components/'); } }