/**
  * Initialize contextual XML (formerly params)
  */
 public function initializeContext()
 {
     $this->View->context->register(array('system' => array('site-name' => Symphony::Configuration()->core()->symphony->sitename, 'site-url' => URL, 'admin-url' => URL . '/symphony', 'symphony-version' => Symphony::Configuration()->core()->symphony->version), 'date' => array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => date_default_timezone_get())));
     if ($this->User) {
         $this->View->context->register(array('session' => self::instance()->User->fields()));
     }
 }
Example #2
0
 /**
  * The constructor for `JSONPage`. This sets the page status to `Page::HTTP_STATUS_OK`,
  * the default content type to `application/json` and initialises `$this->_Result`
  * with an `array`. The constructor also starts the Profiler for this
  * page template.
  *
  * @see toolkit.Profiler
  */
 public function __construct()
 {
     $this->_Result = array();
     $this->setHttpStatus(self::HTTP_STATUS_OK);
     $this->addHeaderToPage('Content-Type', 'application/json');
     Symphony::Profiler()->sample('Page template created', PROFILE_LAP);
 }
Example #3
0
    public static function upgrade()
    {
        if (version_compare(self::$existing_version, '2.3.4beta1', '<=')) {
            // Detect mod_rewrite #1808
            try {
                $htaccess = file_get_contents(DOCROOT . '/.htaccess');
                if ($htaccess !== false && !preg_match('/SetEnv HTTP_MOD_REWRITE No/', $htaccess)) {
                    $rewrite = '
<IfModule !mod_rewrite.c>
    SetEnv HTTP_MOD_REWRITE No
</IfModule>

<IfModule mod_rewrite.c>';
                    $htaccess = str_replace('<IfModule mod_rewrite.c>', $rewrite, $htaccess);
                    file_put_contents(DOCROOT . '/.htaccess', $htaccess);
                }
            } catch (Exception $ex) {
            }
            // Extend token field to enable more secure tokens
            try {
                Symphony::Database()->query('ALTER TABLE `tbl_forgotpass` CHANGE `token` `token` VARCHAR(16);');
            } catch (Exception $ex) {
            }
        }
        if (version_compare(self::$existing_version, '2.3.4beta2', '<=')) {
            // Extend session_id field for default Suhosin installs
            try {
                Symphony::Database()->query('ALTER TABLE `tbl_sessions` CHANGE `session` `session` VARCHAR(128);');
            } catch (Exception $ex) {
            }
        }
        // Update the version information
        return parent::upgrade();
    }
 public function processDependencies(array $params = array())
 {
     $datasources = $this->getDependencies();
     if (!is_array($datasources) || empty($datasources)) {
         return;
     }
     $datasources = array_map(create_function('$a', "return str_replace('\$ds-', '', \$a);"), $datasources);
     $datasources = array_map(create_function('$a', "return str_replace('-', '_', \$a);"), $datasources);
     $env = array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => DateTimeObj::get('P'), 'enm-newsletter-id' => $this->newsletter_id);
     $this->_env['param'] = $env;
     $this->_env['env']['pool'] = $params;
     $dependencies = array();
     foreach ($datasources as $handle) {
         $profiler = Symphony::Profiler();
         $profiler->seed();
         $pool[$handle] =& DatasourceManager::create($handle, NULL, false);
         $dependencies[$handle] = $pool[$handle]->getDependencies();
     }
     $dsOrder = $this->__findDatasourceOrder($dependencies);
     foreach ($dsOrder as $handle) {
         $ds = $pool[$handle];
         $ds->processParameters($this->_env);
         $ds->grab($this->_env['env']['pool']);
         unset($ds);
     }
     $this->processParameters($this->_env);
 }
Example #5
0
 public function __construct($add, $orderable = true)
 {
     $this->child_name = $child_name;
     $this->page = Symphony::Parent()->Page;
     $this->duplicator = $this->page->createElement('div');
     $this->duplicator->addClass('duplicator-widget');
     $controls = $this->page->createElement('ol');
     $controls->addClass('controls');
     $this->duplicator->appendChild($controls);
     $add_item = $this->page->createElement('li', $add);
     $add_item->addClass('add');
     $controls->appendChild($add_item);
     $this->templates = $this->page->createElement('ol');
     $this->templates->setAttribute('class', 'templates');
     $this->duplicator->appendChild($this->templates);
     $content = $this->page->createElement('div');
     $content->addClass('content');
     $this->duplicator->appendChild($content);
     $this->tabs = $this->page->createElement('ol');
     $this->tabs->addClass('tabs');
     $content->appendChild($this->tabs);
     if ($orderable) {
         $this->duplicator->addClass('orderable-widget');
     }
     $this->instances = $this->page->createElement('ol');
     $this->instances->addClass('instances');
     $content->appendChild($this->instances);
     $this->reflection = new ReflectionObject($this->duplicator);
 }
Example #6
0
 /**
  * The constructor for the `XSLTPage` ensures that an `XSLTProcessor`
  * is available, and then sets an instance of it to `$this->Proc`, otherwise
  * it will throw a `SymphonyErrorPage` exception.
  */
 public function __construct()
 {
     if (!XsltProcess::isXSLTProcessorAvailable()) {
         Symphony::Engine()->throwCustomError(__('No suitable XSLT processor was found.'));
     }
     $this->Proc = new XsltProcess();
 }
 public static function lookup($ip)
 {
     $ch = curl_init();
     // Notice: the request back to the service API includes your domain name
     // and the version of Symphony that you're using
     $version = Symphony::Configuration()->get('version', 'symphony');
     $domain = $_SERVER[SERVER_NAME];
     curl_setopt($ch, CURLOPT_URL, "http://api.josephdenne.com/_geoloc/array/?symphony=" . $version . "&domain=" . $domain . "&ip=" . $ip);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $geoinfo = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     if ($geoinfo === false || $info['http_code'] != 200) {
         return;
     } else {
         $geoinfo = explode(',', $geoinfo);
     }
     $result = new XMLElement("geolocation");
     $included = array('id', 'lookups', 'country', 'region', 'city', 'lat', 'lon', 'error');
     $i = 0;
     foreach ($included as $geoloc) {
         $result->appendChild(new XMLElement($geoloc, $geoinfo[$i]));
         $i++;
     }
     return $result;
 }
Example #8
0
 public function action()
 {
     if (isset($_POST['action']['save'])) {
         $fields = $_POST['fields'];
         $permissions = $fields['permissions'];
         $name = trim($fields['name']);
         $page_access = $fields['page_access'];
         if (strlen($name) == 0) {
             $this->_errors['name'] = __('This is a required field');
             return;
         } elseif ($this->_driver->roleExists($name)) {
             $this->_errors['name'] = __('A role with the name <code>%s</code> already exists.', array($name));
             return;
         }
         ASDCLoader::instance()->query("INSERT INTO `tbl_members_roles` VALUES (NULL, '{$name}')");
         $role_id = ASDCLoader::instance()->lastInsertID();
         if (is_array($page_access) && !empty($page_access)) {
             foreach ($page_access as $page_id) {
                 ASDCLoader::instance()->query("INSERT INTO `tbl_members_roles_forbidden_pages` VALUES (NULL, {$role_id}, {$page_id})");
             }
         }
         if (is_array($permissions) && !empty($permissions)) {
             $sql = "INSERT INTO `tbl_members_roles_event_permissions` VALUES ";
             foreach ($permissions as $event_handle => $p) {
                 foreach ($p as $action => $level) {
                     $sql .= "(NULL,  {$role_id}, '{$event_handle}', '{$action}', '{$level}'),";
                 }
             }
             Symphony::Database()->query(trim($sql, ','));
         }
         redirect(extension_members::baseURL() . 'roles_edit/' . $role_id . '/created/');
     }
 }
 public function entrySaved($context)
 {
     require_once MANIFEST . '/jit-recipes.php';
     require_once MANIFEST . '/jit-precaching.php';
     require_once TOOLKIT . '/class.fieldmanager.php';
     $fm = new FieldManager(Symphony::Engine());
     $section = $context['section'];
     if (!$section) {
         require_once TOOLKIT . '/class.sectionmanager.php';
         $sm = new SectionManager(Symphony::Engine());
         $section = $sm->fetch($context['entry']->get('section_id'));
     }
     // iterate over each field in this entry
     foreach ($context['entry']->getData() as $field_id => $data) {
         // get the field meta data
         $field = $fm->fetch($field_id);
         // iterate over the field => recipe mapping
         foreach ($cached_recipes as $cached_recipe) {
             // check a mapping exists for this section/field combination
             if ($section->get('handle') != $cached_recipe['section']) {
                 continue;
             }
             if ($field->get('element_name') != $cached_recipe['field']) {
                 continue;
             }
             // iterate over the recipes mapped for this section/field combination
             foreach ($cached_recipe['recipes'] as $cached_recipe_name) {
                 // get the file name, includes path relative to workspace
                 $file = $data['file'];
                 if (!isset($file) || is_null($file)) {
                     continue;
                 }
                 // trim the filename from path
                 $uploaded_file_path = explode('/', $file);
                 array_pop($uploaded_file_path);
                 // image path relative to workspace
                 if (is_array($uploaded_file_path)) {
                     $uploaded_file_path = implode('/', $uploaded_file_path);
                 }
                 // iterate over all JIT recipes
                 foreach ($recipes as $recipe) {
                     // only process if the recipe has a URL Parameter (name)
                     if (is_null($recipe['url-parameter'])) {
                         continue;
                     }
                     // if not using wildcard, only process specified recipe names
                     if ($cached_recipe_name != '*' && $cached_recipe_name != $recipe['url-parameter']) {
                         continue;
                     }
                     // process the image using the usual JIT URL and get the result
                     $image_data = file_get_contents(URL . '/image/' . $recipe['url-parameter'] . $file);
                     // create a directory structure that matches the JIT URL structure
                     General::realiseDirectory(WORKSPACE . '/image-cache/' . $recipe['url-parameter'] . $uploaded_file_path);
                     // save the image to disk
                     file_put_contents(WORKSPACE . '/image-cache/' . $recipe['url-parameter'] . $file, $image_data);
                 }
             }
         }
     }
 }
 private function __geocodeAddress($address, $can_return_default = true)
 {
     $coordinates = null;
     $cache_id = md5('maplocationfield_' . $address);
     $cache = new Cacheable(Symphony::Database());
     $cachedData = $cache->check($cache_id);
     // no data has been cached
     if (!$cachedData) {
         include_once TOOLKIT . '/class.gateway.php';
         $ch = new Gateway();
         $ch->init();
         $ch->setopt('URL', 'https://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&key=' . $this->get('api_key'));
         $response = json_decode($ch->exec());
         if ($response->status === 'OK') {
             $coordinates = $response->results[0]->geometry->location;
         } else {
             return false;
         }
         if ($coordinates && is_object($coordinates)) {
             // cache lifetime in minutes
             $cache->write($cache_id, $coordinates->lat . ', ' . $coordinates->lng, $this->_geocode_cache_expire);
         }
     } else {
         $coordinates = $cachedData['data'];
     }
     // coordinates is an array, split and return
     if ($coordinates && is_object($coordinates)) {
         return $coordinates->lat . ', ' . $coordinates->lng;
     } elseif ($coordinates) {
         return $coordinates;
     } elseif ($can_return_default) {
         return $this->_default_coordinates;
     }
 }
 public function grab(&$param_pool)
 {
     self::__init();
     $result = new XMLElement($this->dsParamROOTELEMENT);
     $rows = Symphony::Database()->fetch("SELECT *\n\t\t\t\tFROM `tbl_sessions` \n\t\t\t\tWHERE `session_data` != 'sym-|a:0:{}sym-members|a:0:{}' \n\t\t\t\tAND `session_data` REGEXP 'sym-members'\n\t\t\t\tAND `session_expires` > (UNIX_TIMESTAMP() - " . self::AGE . ") \n\t\t\t\tORDER BY `session_expires` DESC");
     $added = array();
     if (count($rows) > 0) {
         foreach ($rows as $r) {
             $raw = $r['session_data'];
             $data = self::session_real_decode($raw);
             if (!isset($data['sym-members'])) {
                 continue;
             }
             $record = ASDCLoader::instance()->query(sprintf("SELECT\n\t\t\t\t\t\t\t\temail.value AS `email`,\n\t\t\t\t\t\t\t\tMD5(email.value) AS `hash`,\n\t\t\t\t\t\t\t\tcreated_by.username AS `username`\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tFROM `tbl_entries_data_%d` AS `created_by`\n\t\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `email` ON created_by.member_id = email.entry_id\n\t\t\t\t\t\t\tWHERE `created_by`.username = '******'\n\t\t\t\t\t\t\tLIMIT 1", self::findFieldID('created-by', 'comments'), self::findFieldID('email-address', 'members'), ASDCLoader::instance()->escape($data['sym-members']['username'])));
             if ($record->length() == 0) {
                 continue;
             }
             $member = $record->current();
             // This is so we dont end up with accidental duplicates. No way to select
             // distinct via the SQL since we grab raw session data
             if (in_array($member->username, $added)) {
                 continue;
             }
             $added[] = $member->username;
             $result->appendChild(new XMLElement('member', General::sanitize($member->username), array('email-hash' => $member->hash)));
         }
     } else {
         $result->setValue('No Records Found.');
         //This should never happen!
     }
     return $result;
 }
Example #12
0
 /**
  * Given a Member ID, return Member
  *
  * @param integer $member_id
  * @return Entry
  */
 public function fetchMemberFromID($member_id)
 {
     if (!Identity::$driver instanceof Extension) {
         Identity::$driver = Symphony::ExtensionManager()->create('members');
     }
     return Identity::$driver->getMemberDriver()->initialiseMemberObject($member_id);
 }
Example #13
0
 public static function save(Utility $utility)
 {
     $file = UTILITIES . "/{$utility->name}";
     FileWriter::write($file, $utility->body, Symphony::Configuration()->core()->symphony->{'file-write-mode'});
     //General::writeFile($file, $utility->body,Symphony::Configuration()->core()->symphony->{'file-write-mode'});
     return file_exists($file);
 }
 public function saveVersion(&$context)
 {
     $section = $context['section'];
     $entry = $context['entry'];
     $fields = $context['fields'];
     // if saved from an event, no section is passed, so resolve
     // section object from the entry
     if (is_null($section)) {
         $sm = new SectionManager(Symphony::Engine());
         $section = $sm->fetch($entry->get('section_id'));
     }
     // if we *still* can't resolve a section then something is
     // probably quite wrong, so don't try and save version history
     if (is_null($section)) {
         return;
     }
     // does this section have en Entry Version field, should we store the version?
     $has_entry_versions_field = FALSE;
     // is this an update to an existing version, or create a new version?
     $is_update = $fields['entry-versions'] != 'yes';
     // find the Entry Versions field in the section and remove its presence from
     // the copied POST array, so that its value is not saved against the version
     foreach ($section->fetchFields() as $field) {
         if ($field->get('type') == 'entry_versions') {
             unset($fields[$field->get('element_name')]);
             $has_entry_versions_field = TRUE;
         }
     }
     if (!$has_entry_versions_field) {
         return;
     }
     $version = EntryVersionsManager::saveVersion($entry, $fields, $is_update, $entry_version_field_name);
     $context['messages'][] = array('version', 'passed', $version);
 }
 /**
  * Process the data so it can be imported into the entry.
  * @param  $value   The value to import
  * @param  $entry_id    If a duplicate is found, an entry ID will be provided.
  * @return The data returned by the field object
  */
 public function import($value, $entry_id = null)
 {
     $destination = $this->field->get('destination');
     $filename = str_replace('/workspace/', '/', $destination) . '/' . str_replace($destination, '', trim($value));
     // Check if the file exists:
     if (file_exists(DOCROOT . $destination . '/' . trim($value))) {
         // File exists, create the link:
         // Check if there already exists an entry with this filename. If so, this entry will not be stored (filename must be unique)
         $sql = 'SELECT COUNT(*) AS `total` FROM `tbl_entries_data_' . $this->field->get('id') . '` WHERE `file` = \'' . $filename . '\';';
         $total = Symphony::Database()->fetchVar('total', 0, $sql);
         if ($total == 0) {
             $fileData = $this->field->processRawFieldData($value, $this->field->__OK__);
             $fileData['file'] = trim($filename);
             $fileData['size'] = filesize(DOCROOT . $destination . '/' . $value);
             $fileData['mimetype'] = mime_content_type(DOCROOT . $destination . '/' . $value);
             $fileData['meta'] = serialize($this->field->getMetaInfo(DOCROOT . $destination . '/' . $value, $fileData['mimetype']));
             return $fileData;
         } else {
             // File already exists, don't store:
             return false;
         }
     } else {
         // File is stored in the CSV, but does not exists. Save it anyway, for database sake:
         if (!empty($value)) {
             $fileData = $this->field->processRawFieldData($value, $this->field->__OK__);
             $fileData['file'] = trim($filename);
             $fileData['size'] = filesize(DOCROOT . $destination . '/' . $value);
             $fileData['mimetype'] = '';
             // mime_content_type(DOCROOT . $destination . '/' . $value);
             $fileData['meta'] = serialize($this->field->getMetaInfo(DOCROOT . $destination . '/' . $value, $fileData['mimetype']));
             return $fileData;
         }
     }
     return false;
 }
 public function isLoggedIn()
 {
     if ($_REQUEST['auth-token'] && in_array(strlen($_REQUEST['auth-token']), array(6, 8))) {
         return $this->loginFromToken($_REQUEST['auth-token']);
     }
     return parent::isLoggedIn();
 }
 public function delete($section_id)
 {
     $query = "SELECT `id`, `sortorder` FROM tbl_sections WHERE `id` = '{$section_id}'";
     $details = Symphony::Database()->fetchRow(0, $query);
     ## Delete all the entries
     include_once TOOLKIT . '/class.entrymanager.php';
     $entryManager = new EntryManager($this->_Parent);
     $entries = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_entries` WHERE `section_id` = '{$section_id}'");
     $entryManager->delete($entries);
     ## Delete all the fields
     $fieldManager = new FieldManager($this->_Parent);
     $fields = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '{$section_id}'");
     if (is_array($fields) && !empty($fields)) {
         foreach ($fields as $field_id) {
             $fieldManager->delete($field_id);
         }
     }
     ## Delete the section
     Symphony::Database()->delete('tbl_sections', " `id` = '{$section_id}'");
     ## Update the sort orders
     Symphony::Database()->query("UPDATE tbl_sections SET `sortorder` = (`sortorder` - 1) WHERE `sortorder` > '" . $details['sortorder'] . "'");
     ## Delete the section associations
     Symphony::Database()->delete('tbl_sections_association', " `parent_section_id` = '{$section_id}'");
     return true;
 }
 public function view()
 {
     $section_handle = (string) $this->context[0];
     $page = isset($this->context[1]) ? (int) $this->context[1] : 1;
     if (empty($section_handle)) {
         die('Invalid section handle');
     }
     $config = (object) Symphony::Configuration()->get('elasticsearch');
     ElasticSearch::init();
     $type = ElasticSearch::getTypeByHandle($section_handle);
     if ($page === 1) {
         // delete all documents in this index
         $query = new Elastica_Query(array('query' => array('match_all' => array())));
         $type->type->deleteByQuery($query);
     }
     // get new entries
     $em = new EntryManager(Symphony::Engine());
     $entries = $em->fetchByPage($page, $type->section->get('id'), (int) $config->{'reindex-batch-size'}, NULL, NULL, FALSE, FALSE, TRUE);
     foreach ($entries['records'] as $entry) {
         ElasticSearch::indexEntry($entry, $type->section);
     }
     $entries['total-entries'] = 0;
     // last page, count how many entries in the index
     if ($entries['remaining-pages'] == 0) {
         // wait a few seconds, allow HTTP requests to complete...
         sleep(5);
         $entries['total-entries'] = $type->type->count();
     }
     header('Content-type: application/json');
     echo json_encode(array('pagination' => array('total-pages' => (int) $entries['total-pages'], 'total-entries' => (int) $entries['total-entries'], 'remaining-pages' => (int) $entries['remaining-pages'], 'next-page' => $page + 1)));
     exit;
 }
Example #19
0
 /**
  * Given a CSV file, generate a resulting XML tree
  *
  * @param  string $data
  * @return string
  */
 public static function convertToXML($data)
 {
     $headers = array();
     // Get CSV settings
     $settings = array('csv-delimiter' => ',', 'csv-enclosure' => '"', 'csv-escape' => '\\');
     $settings = array_merge($settings, (array) Symphony::Configuration()->get('remote_datasource'));
     // DOMDocument
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     $root = $doc->createElement('data');
     $doc->appendChild($root);
     foreach (str_getcsv($data, PHP_EOL) as $i => $row) {
         if (empty($row)) {
             continue;
         }
         if ($i == 0) {
             foreach (str_getcsv($row, $settings['csv-delimiter'], $settings['csv-enclosure'], $settings['csv-escape']) as $i => $head) {
                 if (class_exists('Lang')) {
                     $head = Lang::createHandle($head);
                 }
                 $headers[] = $head;
             }
         } else {
             self::addRow($doc, $root, str_getcsv($row, $settings['csv-delimiter'], $settings['csv-enclosure'], $settings['csv-escape']), $headers);
         }
     }
     $output = $doc->saveXML($doc->documentElement);
     return trim($output);
 }
    public static function render($e)
    {
        $lines = NULL;
        foreach (self::__nearByLines($e->getLine(), $e->getFile()) as $line => $string) {
            $lines .= sprintf('%d: %s', ++$line, $string);
        }
        $trace = NULL;
        foreach ($e->getTrace() as $t) {
            $trace .= sprintf('[%s:%d] %s%s%s();' . "\n", isset($t['file']) ? $t['file'] : NULL, isset($t['line']) ? $t['line'] : NULL, isset($t['class']) ? $t['class'] : NULL, isset($t['type']) ? $t['type'] : NULL, $t['function']);
        }
        $queries = NULL;
        if (is_object(Symphony::Database())) {
            $debug = Symphony::Database()->debug();
            if (count($debug['query']) > 0) {
                foreach ($debug['query'] as $query) {
                    $queries .= sprintf('%s; [%01.4f]' . "\n", preg_replace('/[\\r\\n\\t]+/', ' ', $query['query']), isset($query['time']) ? $query['time'] : NULL);
                }
            }
        }
        return sprintf('%s: %s
			
An error occurred in %s around line %d
%s

Backtrace
===========================
%s

Database Query Log
===========================
%s', $e instanceof ErrorException ? GenericErrorHandler::$errorTypeStrings[$e->getSeverity()] : 'Fatal Error', $e->getMessage(), $e->getFile(), $e->getLine(), $lines, $trace, $queries);
    }
 public function frontendPrePageResolve($context)
 {
     if (!self::$resolved) {
         // get languages from configuration
         if (self::$languages = Symphony::Configuration()->get('languages', 'multilingual')) {
             self::$languages = explode(',', str_replace(' ', '', self::$languages));
             // detect language from path
             if (preg_match('/^\\/([a-z]{2})\\//', $context['page'], $match)) {
                 // set language from path
                 self::$language = $match[1];
             } else {
                 // detect language from browser
                 self::$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
             }
             // check if language is supported
             if (!in_array(self::$language, self::$languages)) {
                 // set to default otherwise
                 self::$language = self::$languages[0];
             }
             // redirect root page
             if (!$context['page']) {
                 header('Location: ' . URL . '/' . self::$language . '/');
                 exit;
             }
         }
         self::$resolved = true;
     }
 }
Example #22
0
 function action()
 {
     if (@array_key_exists('save', $_POST['action'])) {
         $this->_errors = array();
         // Polish up some field content
         $fields = $_POST['fields'];
         if (isset($fields['pages'])) {
             $fields['pages'] = implode(',', $fields['pages']);
         }
         $fields['content_formatted'] = DocumentationForm::applyFormatting($fields['content'], true, $this->_errors);
         if ($fields['content_formatted'] === false) {
             $fields['content_formatted'] = General::sanitize(DocumentationForm::applyFormatting($fields['content']));
         }
         if (!isset($fields['title']) || trim($fields['title']) == '') {
             $this->_errors['title'] = __('Title is a required field');
         }
         if (!isset($fields['pages']) || trim($fields['pages']) == '') {
             $this->_errors['pages'] = __('Page is a required field');
         }
         if (!isset($fields['content']) || trim($fields['content']) == '') {
             $this->_errors['content'] = __('Content is a required field');
         }
         if (empty($this->_errors)) {
             if (!Symphony::Database()->insert($fields, 'tbl_documentation')) {
                 $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 {
                 $doc_id = Symphony::Database()->getInsertID();
                 redirect(URL . "/symphony/extension/documenter/edit/{$doc_id}/created/");
             }
         }
     }
     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);
     }
 }
Example #23
0
 public function __construct($name = 'div', $child_name = 'div')
 {
     $this->child_name = $child_name;
     $this->class = 'columns type-';
     $this->page = Symphony::Parent()->Page;
     $this->layout = $this->page->createElement($name);
 }
Example #24
0
 public static function upgrade()
 {
     // 2.2.2 Beta 1
     if (version_compare(self::$existing_version, '2.2.2 Beta 1', '<=')) {
         Symphony::Configuration()->set('version', '2.2.2 Beta 1', 'symphony');
         // Rename old variations of the query_caching configuration setting
         if (Symphony::Configuration()->get('disable_query_caching', 'database')) {
             $value = Symphony::Configuration()->get('disable_query_caching', 'database') == "no" ? "on" : "off";
             Symphony::Configuration()->set('query_caching', $value, 'database');
             Symphony::Configuration()->remove('disable_query_caching', 'database');
         }
         // Add Session GC collection as a configuration parameter
         Symphony::Configuration()->set('session_gc_divisor', '10', 'symphony');
         // Save the manifest changes
         Symphony::Configuration()->write();
     }
     // 2.2.2 Beta 2
     if (version_compare(self::$existing_version, '2.2.2 Beta 2', '<=')) {
         Symphony::Configuration()->set('version', '2.2.2 Beta 2', 'symphony');
         try {
             // Change Textareas to be MEDIUMTEXT columns
             $textarea_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_textarea`");
             foreach ($textarea_tables as $field) {
                 Symphony::Database()->query(sprintf("ALTER TABLE `tbl_entries_data_%d` CHANGE `value` `value` MEDIUMTEXT, CHANGE `value_formatted` `value_formatted` MEDIUMTEXT", $field));
                 Symphony::Database()->query(sprintf('OPTIMIZE TABLE `tbl_entries_data_%d`', $field));
             }
         } catch (Exception $ex) {
         }
         // Save the manifest changes
         Symphony::Configuration()->write();
     }
     // Update the version information
     return parent::upgrade();
 }
 public function isLoggedIn()
 {
     if (isset($_REQUEST['auth-token']) && $_REQUEST['auth-token'] && strlen($_REQUEST['auth-token']) == 8) {
         return $this->loginFromToken($_REQUEST['auth-token']);
     }
     return parent::isLoggedIn();
 }
Example #26
0
 public function view()
 {
     $destination = self::kREORDER_UNKNOWN;
     if ($this->_context[0] == 'blueprints' && $this->_context[1] == 'pages') {
         $destination = self::kREORDER_PAGES;
     }
     $items = $_REQUEST['items'];
     if (!is_array($items) || empty($items)) {
         return;
     }
     switch ($destination) {
         case self::kREORDER_SECTIONS:
             foreach ($items as $id => $position) {
                 if (!Symphony::Database()->update('tbl_sections', array('sortorder' => $postion), array($id), "`id` = %d LIMIT 1")) {
                     $this->_status = self::STATUS_ERROR;
                     $this->_Result->setValue(__('A database error occurred while attempting to reorder.'));
                     break;
                 }
             }
             break;
         case self::kREORDER_UNKNOWN:
         default:
             $this->_status = self::STATUS_BAD;
             break;
     }
 }
 public function __processAuthorFilter($field, $filter)
 {
     //, $filtertype=DS_FILTER_OR){
     //$bits = preg_split('/'.($filtertype == DS_FILTER_AND ? '\+' : ',').'\s*/', $filter);
     if (!is_array($filter)) {
         $bits = preg_split('/,\\s*/', $filter, -1, PREG_SPLIT_NO_EMPTY);
         $bits = array_map('trim', $bits);
     } else {
         $bits = $filter;
     }
     //switch($filtertype){
     /*case DS_FILTER_AND:
     
     					$sql = "SELECT `a`.`id`
     							FROM (
     
     								SELECT `tbl_authors`.id, COUNT(`tbl_authors`.id) AS `count`
     								FROM  `tbl_authors`
     								WHERE `tbl_authors`.`".$field."` IN ('".implode("', '", $bits)."')
     								GROUP BY `tbl_authors`.`id`
     
     							) AS `a`
     							WHERE `a`.`count` >= " . count($bits);
     
     					break;*/
     //case DS_FILTER_OR:
     $sql = "SELECT `id` FROM `tbl_authors` WHERE `" . $field . "` IN ('" . implode("', '", $bits) . "')";
     //break;
     //}
     $authors = Symphony::Database()->fetchCol('id', $sql);
     return is_array($authors) && !empty($authors) ? $authors : NULL;
 }
 public function update($previousVersion)
 {
     if (version_compare($previousVersion, '1.4', '<')) {
         try {
             Symphony::Database()->query("ALTER TABLE `tbl_fields_referencelink` ADD COLUMN `show_association` enum('yes','no') NOT NULL default 'yes'");
         } catch (Exception $e) {
             // Discard
         }
     }
     if (version_compare($previousVersion, '1.3.1', '<')) {
         try {
             $fields = Symphony::Database()->fetchCol('field_id', "SELECT `field_id` FROM `tbl_fields_referencelink`");
         } catch (Exception $e) {
             // Discard
         }
         if (is_array($fields) && !empty($fields)) {
             foreach ($fields as $field_id) {
                 try {
                     Symphony::Database()->query("ALTER TABLE `tbl_entries_data_{$field_id}`\n\t\t\t\t\t\t\t\tCHANGE `relation_id` `relation_id` INT(11) UNSIGNED NULL DEFAULT NULL");
                 } catch (Exception $e) {
                     // Discard
                 }
             }
         }
     }
     if (version_compare($previousVersion, '1.2', '<')) {
         Symphony::Database()->query("ALTER TABLE `tbl_fields_referencelink` ADD `limit` INT(4) UNSIGNED NOT NULL DEFAULT '20'");
         Symphony::Database()->query("ALTER TABLE `tbl_fields_referencelink` CHANGE `related_field_id` `related_field_id` VARCHAR(255) NOT NULL");
     }
     return true;
 }
 public function execute(&$param_pool)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     $type_sql = $parent_sql = null;
     if (trim($this->dsParamFILTERS['type']) != '') {
         $type_sql = $this->__processNavigationTypeFilter($this->dsParamFILTERS['type'], $this->__determineFilterType($this->dsParamFILTERS['type']));
     }
     if (trim($this->dsParamFILTERS['parent']) != '') {
         $parent_sql = $this->__processNavigationParentFilter($this->dsParamFILTERS['parent']);
     }
     // Build the Query appending the Parent and/or Type WHERE clauses
     $pages = Symphony::Database()->fetch(sprintf("\n\t\t\t\t\tSELECT DISTINCT p.id, p.title, p.handle, (SELECT COUNT(id) FROM `tbl_pages` WHERE parent = p.id) AS children\n\t\t\t\t\tFROM `tbl_pages` AS p\n\t\t\t\t\tLEFT JOIN `tbl_pages_types` AS pt ON (p.id = pt.page_id)\n\t\t\t\t\tWHERE 1 = 1\n\t\t\t\t\t%s\n\t\t\t\t\t%s\n\t\t\t\t\tORDER BY p.`sortorder` ASC\n\t\t\t\t", !is_null($parent_sql) ? $parent_sql : " AND p.parent IS NULL ", !is_null($type_sql) ? $type_sql : ""));
     if (!is_array($pages) || empty($pages)) {
         if ($this->dsParamREDIRECTONEMPTY == 'yes') {
             throw new FrontendPageNotFoundException();
         }
         $result->appendChild($this->__noRecordsFound());
     } else {
         // Build an array of all the types so that the page's don't have to do
         // individual lookups.
         $page_types = PageManager::fetchAllPagesPageTypes();
         foreach ($pages as $page) {
             $result->appendChild($this->__buildPageXML($page, $page_types));
         }
     }
     return $result;
 }
 public function action()
 {
     ##Do not proceed if the config file is read only
     if (!is_writable(CONFIG)) {
         redirect(URL . '/symphony/system/preferences/');
     }
     ###
     # Delegate: CustomActions
     # Description: This is where Extensions can hook on to custom actions they may need to provide.
     $this->_Parent->ExtensionManager->notifyMembers('CustomActions', '/system/preferences/');
     if (isset($_POST['action']['save'])) {
         $settings = $_POST['settings'];
         ###
         # Delegate: Save
         # Description: Saving of system preferences.
         $this->_Parent->ExtensionManager->notifyMembers('Save', '/system/preferences/', array('settings' => &$settings, 'errors' => &$this->_errors));
         if (!is_array($this->_errors) || empty($this->_errors)) {
             foreach ($settings as $set => $values) {
                 foreach ($values as $key => $val) {
                     Symphony::Configuration()->set($key, $val, $set);
                 }
             }
             $this->_Parent->saveConfig();
             redirect(URL . '/symphony/system/preferences/success/');
         }
     }
 }