/**
  * Returns all the page types that exist in this Symphony install.
  * There are 5 default system page types, and new types can be added
  * by Developers via the Page Editor.
  *
  * @return array
  *  An array of strings of the page types used in this Symphony
  *  install. At the minimum, this will be an array with the values
  * 'index', 'XML', 'admin', '404' and '403'.
  */
 public function __fetchAvailablePageTypes()
 {
     $system_types = array('index', 'XML', 'admin', '404', '403');
     if (!($types = Symphony::Database()->fetchCol('type', "SELECT `type` FROM `tbl_pages_types` ORDER BY `type` ASC"))) {
         return $system_types;
     }
     return is_array($types) && !empty($types) ? General::array_remove_duplicates(array_merge($system_types, $types)) : $system_types;
 }
 function fetchTypes()
 {
     $structure = General::listStructure(TOOLKIT . '/fields', '/field.[a-z0-9_-]+.php/i', false, 'asc', TOOLKIT . '/fields');
     $extensions = $this->_Parent->ExtensionManager->listInstalledHandles();
     if (is_array($extensions) && !empty($extensions)) {
         foreach ($extensions as $handle) {
             if (is_dir(EXTENSIONS . '/' . $handle . '/fields')) {
                 $tmp = General::listStructure(EXTENSIONS . '/' . $handle . '/fields', '/field.[a-z0-9_-]+.php/i', false, 'asc', EXTENSIONS . '/' . $handle . '/fields');
                 if (is_array($tmp['filelist']) && !empty($tmp['filelist'])) {
                     $structure['filelist'] = array_merge($structure['filelist'], $tmp['filelist']);
                 }
             }
         }
         $structure['filelist'] = General::array_remove_duplicates($structure['filelist']);
     }
     $types = array();
     for ($ii = 0; $ii < count($structure['filelist']); $ii++) {
         $types[] = str_replace(array('field.', '.php'), '', $structure['filelist'][$ii]);
     }
     return $types;
 }
Пример #3
0
 public static function fetchUsedTypes()
 {
     $types = array();
     foreach (new ViewIterator() as $v) {
         $types = array_merge((array) $v->types, $types);
     }
     return General::array_remove_duplicates($types);
 }
Пример #4
0
 function processRawFieldData($data, &$status, $simulate = false, $entry_id = NULL)
 {
     $status = self::__OK__;
     $data = preg_split('/\\,\\s*/i', $data, -1, PREG_SPLIT_NO_EMPTY);
     $data = array_map('trim', $data);
     if (empty($data)) {
         return;
     }
     $data = General::array_remove_duplicates($data);
     sort($data);
     $result = array();
     foreach ($data as $value) {
         $result['value'][] = $value;
         $result['handle'][] = Lang::createHandle($value);
     }
     return $result;
 }
 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') . '/');
         }
     }
 }
 public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = NULL)
 {
     $status = self::__OK__;
     $data = preg_split('/\\' . $this->get('delimiter') . '\\s*/i', $data, -1, PREG_SPLIT_NO_EMPTY);
     $data = array_map('trim', $data);
     if (empty($data)) {
         return;
     }
     $data = General::array_remove_duplicates($data);
     if ($this->get('ordered') != 'yes') {
         sort($data);
     }
     $result = array();
     foreach ($data as $value) {
         $result['value'][] = $value;
         $result['handle'][] = Lang::createHandle($value);
     }
     return $result;
 }
Пример #8
0
 function buildXSL($page_handle = NULL, $utilities = NULL, $param = NULL)
 {
     $xsl = array();
     $sql = "SELECT t1.*,\n\t\t\t\t\t\t   t2.events as `master_events`,\n\t\t\t\t\t\t   t2.data_sources as `master_data_sources`\n\n\t\t\t\t\tFROM `tbl_pages` AS `t1`\n\t\t\t\t\tLEFT JOIN `tbl_masters` AS `t2` ON t1.`master` = concat(t2.`name`, '.xsl')\n\t\t\t\t\tWHERE t1.`handle` = '" . $this->_page . "' LIMIT 1";
     if (!($page = $this->_db->fetchRow(0, $sql))) {
         $this->fatalError("Requested page '" . $this->_page . "' could not be found");
     }
     $page_data = preg_split('/,/', $page['data_sources'] . "," . $page['master_data_sources'], -1, PREG_SPLIT_NO_EMPTY);
     $page_data = General::array_remove_duplicates($page_data);
     $page_events = preg_split('/,/', $page['events'] . "," . $page['master_events'], -1, PREG_SPLIT_NO_EMPTY);
     $page_events = General::array_remove_duplicates($page_events);
     $master = $page['master'];
     if (!is_array($utilities) || empty($utilities)) {
         $utilities = $this->_db->fetch("SELECT DISTINCT t1.*\n\t\t\t\t\t\t\t\t\t\t FROM `tbl_utilities` as t1\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN `tbl_utilities2datasources` as t2 ON t1.id = t2.utility_id\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN `tbl_utilities2events` as t3 ON t1.id = t3.utility_id\n\t\t\t\t\t\t\t\t\t\t WHERE (t2.`data_source` IS NULL AND t3.`event` IS NULL)\n\t\t\t\t\t\t\t\t\t\t OR (t2.`data_source` IN ('" . @implode("', '", $page_data) . "')\n\t\t\t\t\t\t\t\t\t\t OR t3.`event` IN ('" . @implode("', '", $page_events) . "'))");
         $utilities = General::array_remove_duplicates($utilities);
     }
     if (!($xsl['page'] = @file_get_contents(WORKSPACE . "/pages/" . $this->_page . ".xsl"))) {
         $this->fatalError("Specified page '" . $this->_page . "' could not be loaded");
     }
     if (is_array($utilities) && !empty($utilities)) {
         foreach ($utilities as $u) {
             if (!@file_exists(WORKSPACE . "/utilities/" . $u['handle'] . ".xsl")) {
                 $this->fatalError("Specified utility '" . $u['name'] . "' could not be loaded");
             }
             $xsl['utilities'][] = file_get_contents(WORKSPACE . "/utilities/" . $u['handle'] . ".xsl");
         }
     }
     if ($master != NULL) {
         if (!($xsl['master'] = @file_get_contents(WORKSPACE . "/masters/" . $master))) {
             $this->fatalError("Specified master '" . $master . "' could not be loaded");
         }
         $xsl['master'] = trim($xsl['master']);
         $xsl['master'] = str_replace("</xsl:stylesheet>", "", trim($xsl['master']));
     } else {
         $xsl['page'] = str_replace("</xsl:stylesheet>", "", trim($xsl['page']));
     }
     $this->_xsl_final = trim($xsl['master']) . CRLF . $xsl['page'] . CRLF . @implode(CRLF, array_map("trim", $xsl['utilities'])) . "\n</xsl:stylesheet>";
     ##Compile the final stylesheet
     $xsl_param = NULL;
     if (is_array($param) && !empty($param)) {
         foreach ($param as $key => $val) {
             $val = preg_replace('/[\'"]/', '', stripslashes($val));
             $xsl_param .= '    <xsl:param name="' . $key . '" select="\'' . $val . '\'" />' . CRLF;
         }
         if (!_USING_SABLOTRON_) {
             $xsl_param = '<!--' . CRLF . '    // Parameters are defined via PHP in the background //' . CRLF . $xsl_param . '-->';
         }
         preg_match_all('/(<xsl:output[\\s\\w="\'-\\/:.@]*\\/>)/', $this->_xsl_final, $result, PREG_SET_ORDER);
         $this->_xsl_final = str_replace($result[0][1], $result[0][1] . CRLF . CRLF . $xsl_param, $this->_xsl_final);
     }
     $this->_xsl_final = trim($this->_xsl_final);
     return $this->_xsl_final;
 }
 public function __formAction()
 {
     $fields = $_POST['fields'];
     $this->_errors = array();
     $providers = Symphony::ExtensionManager()->getProvidersOf('data-sources');
     $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 ($fields['source'] == 'dynamic_xml') {
         if (trim($fields['dynamic_xml']['url']) == '') {
             $this->_errors['dynamic_xml']['url'] = __('This is a required field');
         }
         // Use the TIMEOUT that was specified by the user for a real world indication
         $timeout = isset($fields['dynamic_xml']['timeout']) ? (int) $fields['dynamic_xml']['timeout'] : 6;
         // If there is a parameter in the URL, we can't validate the existence of the URL
         // as we don't have the environment details of where this datasource is going
         // to be executed.
         if (!preg_match('@{([^}]+)}@i', $fields['dynamic_xml']['url'])) {
             $valid_url = self::__isValidURL($fields['dynamic_xml']['url'], $timeout, $error);
             if ($valid_url) {
                 $data = $valid_url['data'];
             } else {
                 $this->_errors['dynamic_xml']['url'] = $error;
             }
         }
         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');
         }
     } elseif (is_numeric($fields['source'])) {
         if (strlen(trim($fields['max_records'])) == 0 || is_numeric($fields['max_records']) && $fields['max_records'] < 1) {
             if (isset($fields['paginate_results'])) {
                 $this->_errors['max_records'] = __('A result limit must be set');
             }
         } else {
             if (!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 (isset($fields['paginate_results'])) {
                 $this->_errors['page_number'] = __('A page number must be set');
             }
         } else {
             if (!self::__isValidPageString($fields['page_number'])) {
                 $this->_errors['page_number'] = __('Must be a valid number or parameter');
             }
         }
     } elseif (!empty($providers)) {
         foreach ($providers as $providerClass => $provider) {
             if ($fields['source'] == call_user_func(array($providerClass, 'getSource'))) {
                 call_user_func(array($providerClass, 'validate'), &$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;
         $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) {
             $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 -->
         // and <!-- DS DEPENDENCY LIST --> tokens
         $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'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no';
                     $params['requiredparam'] = trim($fields['required_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'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no';
                     $params['requiredparam'] = trim($fields['required_url_param']);
                     break;
                 case 'dynamic_xml':
                     $extends = 'DynamicXMLDatasource';
                     // Automatically detect namespaces
                     if (isset($data)) {
                         preg_match_all('/xmlns:([a-z][a-z-0-9\\-]*)="([^\\"]+)"/i', $data, $matches);
                         if (!is_array($fields['dynamic_xml']['namespace'])) {
                             $fields['dynamic_xml']['namespace'] = array();
                         }
                         if (isset($matches[2][0])) {
                             $detected_namespaces = array();
                             foreach ($fields['dynamic_xml']['namespace'] as $name => $uri) {
                                 $detected_namespaces[] = $name;
                                 $detected_namespaces[] = $uri;
                             }
                             foreach ($matches[2] as $index => $uri) {
                                 $name = $matches[1][$index];
                                 if (in_array($name, $detected_namespaces) or in_array($uri, $detected_namespaces)) {
                                     continue;
                                 }
                                 $detected_namespaces[] = $name;
                                 $detected_namespaces[] = $uri;
                                 $fields['dynamic_xml']['namespace'][] = array('name' => $name, 'uri' => $uri);
                             }
                         }
                     }
                     $filters = array();
                     if (is_array($fields['dynamic_xml']['namespace'])) {
                         foreach ($fields['dynamic_xml']['namespace'] as $index => $data) {
                             $filters[$data['name']] = $data['uri'];
                         }
                     }
                     $params['url'] = $fields['dynamic_xml']['url'];
                     $params['xpath'] = $fields['dynamic_xml']['xpath'];
                     $params['cache'] = $fields['dynamic_xml']['cache'];
                     $params['format'] = $fields['dynamic_xml']['format'];
                     $params['timeout'] = isset($fields['dynamic_xml']['timeout']) ? (int) $fields['dynamic_xml']['timeout'] : '6';
                     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', addslashes(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'] = isset($fields['paginate_results']) ? 'yes' : 'no';
                     $params['limit'] = $fields['max_records'];
                     $params['startpage'] = $fields['page_number'];
                     $params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no';
                     $params['requiredparam'] = trim($fields['required_url_param']);
                     $params['paramoutput'] = $fields['param'];
                     $params['sort'] = $fields['sort'];
                     $params['htmlencode'] = $fields['html_encode'];
                     $params['associatedentrycounts'] = $fields['associated_entry_counts'];
                     if ($params['associatedentrycounts'] == NULL) {
                         $params['associatedentrycounts'] = 'no';
                     }
                     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 ]++-->/', '/(\\r\\n){2,}/', '/(\\t+[\\r\\n]){2,}/'), '', $dsShell);
         // Write the file
         if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $dsShell, Symphony::Configuration()->get('write_mode', 'file')))) {
             $this->pageAlert(__('Failed to write Data source to disk.') . ' ' . __('Please check permissions on %s.', array('<code>/workspace/data-sources</code>')), Alert::ERROR);
         } else {
             if ($queueForDeletion) {
                 General::deleteFile($queueForDeletion);
                 // Update pages that use this DS
                 $pages = PageManager::fetch(false, array('data_sources', 'id'), array("\n\t\t\t\t\t\t\t`data_sources` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]'\n\t\t\t\t\t\t"));
                 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
                  */
                 Symphony::ExtensionManager()->notifyMembers('DatasourcePostEdit', '/blueprints/datasources/', array('file' => $file));
             }
             redirect(SYMPHONY_URL . '/blueprints/datasources/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/');
         }
     }
 }
 public function appendDataSourceConditions(&$context)
 {
     /*
     						'file' => $file,
     						'contents' => &$dsShell,
     						'params' => $params,
     						'elements' => $elements,
     						'filters' => $filters,
     						'dependencies' => $dependencies
     */
     if (!isset($_POST['conditionalizer']) || empty($_POST['conditionalizer'])) {
         return;
     }
     $data = var_export($_POST['conditionalizer'], true) . ";\n";
     // Store condition in data-source
     $context['contents'] = preg_replace('/public \\$dsParamROOTELEMENT [^\\n]+\\n/', '$0		public \\$dsParamConditionalizer = ' . $data, $context['contents']);
     // Update dependencies
     // From content.blueprintsdatasources.php
     if (preg_match_all('@(\\$ds-[-_0-9a-z]+)@i', $data, $matches)) {
         if (!is_array($context['dependencies'])) {
             $context['dependencies'] = array();
         }
         $context['dependencies'] = General::array_remove_duplicates(array_merge($matches[1], $context['dependencies']));
         $context['contents'] = preg_replace('/' . preg_quote('$this->_dependencies = array(') . '[^\\)]*\\);/', '$this->_dependencies = array(\'' . implode("', '", $context['dependencies']) . '\');', $context['contents']);
     }
 }
 public 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');
         }
     } elseif (is_numeric($fields['source'])) {
         if (strlen(trim($fields['max_records'])) == 0 || is_numeric($fields['max_records']) && $fields['max_records'] < 1) {
             if (isset($fields['paginate_results'])) {
                 $this->_errors['max_records'] = __('A result limit must be set');
             }
         } else {
             if (!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 (isset($fields['paginate_results'])) {
                 $this->_errors['page_number'] = __('A page number must be set');
             }
         } else {
             if (!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\\d]+@i' => '', '/[^\\w-\\.]/i' => ''));
     $rootelement = str_replace('_', '-', $classname);
     ##Check to make sure the classname is not empty after handlisation.
     if (empty($classname)) {
         $this->_errors['name'] = __('Please ensure name contains at least one Latin-based alphabet.', 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 <code>%s</code> name already exists', array($classname));
     }
     if (empty($this->_errors)) {
         $dsShell = file_get_contents(TEMPLATE . '/datasource.tpl');
         $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'));
         $source = $fields['source'];
         $filter = NULL;
         $elements = NULL;
         switch ($source) {
             case 'authors':
                 $filters = $fields['filter']['author'];
                 $elements = $fields['xml_elements'];
                 $params['order'] = $fields['order'];
                 $params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no';
                 $params['requiredparam'] = trim($fields['required_url_param']);
                 $params['paramoutput'] = $fields['param'];
                 $params['sort'] = $fields['sort'];
                 $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'] = trim($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'];
                 $params['timeout'] = isset($fields['dynamic_xml']['timeout']) ? (int) $fields['dynamic_xml']['timeout'] : '6';
                 $dsShell = str_replace('<!-- GRAB -->', "include(TOOLKIT . '/data-sources/datasource.dynamic_xml.php');", $dsShell);
                 break;
             case 'static_xml':
                 $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']);
                 }
                 $value = sprintf('$this->dsSTATIC = \'%s\';', addslashes(trim($fields['static_xml'])));
                 $dsShell = str_replace('<!-- GRAB -->', $value . PHP_EOL . "include(TOOLKIT . '/data-sources/datasource.static.php');", $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['paginateresults'] = isset($fields['paginate_results']) ? 'yes' : 'no';
                 $params['limit'] = $fields['max_records'];
                 $params['startpage'] = $fields['page_number'];
                 $params['redirectonempty'] = isset($fields['redirect_on_empty']) ? 'yes' : 'no';
                 $params['requiredparam'] = trim($fields['required_url_param']);
                 $params['paramoutput'] = $fields['param'];
                 $params['sort'] = $fields['sort'];
                 $params['htmlencode'] = $fields['html_encode'];
                 $params['associatedentrycounts'] = $fields['associated_entry_counts'];
                 if ($params['associatedentrycounts'] == NULL) {
                     $params['associatedentrycounts'] = 'no';
                 }
                 $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-[-_0-9a-z]+)@i', $dsShell, $matches)) {
             $dependencies = General::array_remove_duplicates($matches[1]);
             $dsShell = str_replace('<!-- DS DEPENDENCY LIST -->', "'" . implode("', '", $dependencies) . "'", $dsShell);
         }
         ## Remove left over placeholders
         $dsShell = preg_replace(array('/<!--[\\w ]++-->/', '/(\\r\\n){2,}/', '/(\\t+[\\r\\n]){2,}/'), '', $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 $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('DatasourcePreEdit', '/blueprints/datasources/', array('file' => $file, 'contents' => &$dsShell, 'params' => $params, 'elements' => $elements, 'filters' => $filters, 'dependencies' => $dependencies));
         }
         // Write the file
         if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $dsShell, Symphony::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 = Symphony::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']);
                         Symphony::Database()->update($page, 'tbl_pages', "`id` = '" . $page['id'] . "'");
                     }
                 }
             }
             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
                  */
                 Symphony::ExtensionManager()->notifyMembers('DatasourcePostEdit', '/blueprints/datasources/', array('file' => $file));
             }
             redirect(SYMPHONY_URL . '/blueprints/datasources/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/');
         }
     }
 }
Пример #12
0
 /**
  * Give the field some data and ask it to return a value.
  *
  * @param mixed $data
  * @param integer $entry_id
  * @return array|null
  */
 public function prepareImportValue($data, $entry_id = null)
 {
     $data = preg_split('/\\,\\s*/i', $data, -1, PREG_SPLIT_NO_EMPTY);
     $data = array_map('trim', $data);
     $result = array();
     if (empty($data)) {
         return null;
     }
     $result = array('value' => array(), 'handle' => array());
     // Do a case insensitive removal of duplicates:
     $data = General::array_remove_duplicates($data, true);
     sort($data);
     foreach ($data as $value) {
         $result['value'][] = $value;
         $result['handle'][] = Lang::createHandle($value);
     }
     return $result;
 }
Пример #13
0
 public static function fetchUsedNavigationGroups()
 {
     $groups = array();
     foreach (new SectionIterator() as $s) {
         $groups[] = $s->{'navigation-group'};
     }
     return General::array_remove_duplicates($groups);
 }
Пример #14
0
 private static function __fetchAvailableViewTypes()
 {
     // TODO: Delegate here so extensions can add custom view types?
     $types = array('index', 'XML', 'admin', '404', '403');
     foreach (View::fetchUsedTypes() as $t) {
         $types[] = $t;
     }
     return General::array_remove_duplicates($types);
 }
Пример #15
0
 public function appendDataSourceParameters(&$context)
 {
     /*
     						'file' => $file,
     						'contents' => &$dsShell,
     						'params' => $params,
     						'elements' => $elements,
     						'filters' => $filters,
     						'dependencies' => $dependencies
     */
     if (!isset($_POST['parametrisator']['xpaths']) || empty($_POST['parametrisator']['xpaths'])) {
         return;
     }
     if (!empty($_POST['parametrisator']['xslt'])) {
         $XSLT = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $_POST['parametrisator']['xslt']);
         if (file_exists($XSLT)) {
             $parametrisator['xslt'] = $_POST['parametrisator']['xslt'];
         }
     } else {
         $parametrisator['xslt'] = false;
     }
     $parametrisator['xpaths'] = array_filter(array_combine(array_map(array('Lang', 'createHandle'), $_POST['parametrisator']['xpaths']['name']), $_POST['parametrisator']['xpaths']['xpath']));
     if (empty($parametrisator['xpaths'])) {
         return;
     }
     $parametrisator = preg_replace(array("/\n  /", "/\n\\)\\s*\$/"), array("\n\t\t\t", "\n\t\t);"), var_export($parametrisator, true)) . "\n";
     // Store XPaths in data-source
     $context['contents'] = preg_replace('/public \\$dsParamROOTELEMENT [^\\n]+\\n/', '$0		public \\$dsParamParametrisator = ' . $parametrisator, $context['contents']);
     // Update dependencies
     // From content.blueprintsdatasources.php
     if (preg_match_all('@(\\$ds-[-_0-9a-z]+)@i', $parametrisator, $matches)) {
         if (!is_array($context['dependencies'])) {
             $context['dependencies'] = array();
         }
         $context['dependencies'] = General::array_remove_duplicates(array_merge($matches[1], $context['dependencies']));
         $context['contents'] = preg_replace('/' . preg_quote('$this->_dependencies = array(') . '[^\\)]*\\);/', '$this->_dependencies = array(\'' . implode("', '", $context['dependencies']) . '\');', $context['contents']);
     }
     // Modify data-source grab() to make it output additional parameters
     $this->injectPHP($context['contents']);
 }
Пример #16
0
 public function saveData(MessageStack $errors, Entry $entry, $data = null)
 {
     // Since we are dealing with multiple
     // values, must purge the existing data first
     Symphony::Database()->delete(sprintf('tbl_data_%s_%s', $entry->section, $this->{'element-name'}), array($entry->id), "`entry_id` = %s");
     $data = preg_split('/' . preg_quote($this->{'delimiter'}) . '/i', $data->value, -1, PREG_SPLIT_NO_EMPTY);
     $data = array_map('trim', $data);
     if (!is_array($data)) {
         $data = array($data);
     }
     $data = General::array_remove_duplicates($data, true);
     foreach ($data as $tag) {
         $tag = $this->processData($tag, $entry);
         parent::saveData($errors, $entry, $tag);
     }
     return Field::STATUS_OK;
 }
 /**
  * Returns all the page types that exist in this Symphony install.
  * There are 6 default system page types, and new types can be added
  * by Developers via the Page Editor.
  *
  * @since Symphony 2.3 introduced the JSON type.
  * @return array
  *  An array of strings of the page types used in this Symphony
  *  install. At the minimum, this will be an array with the values
  * 'index', 'XML', 'JSON', 'admin', '404' and '403'.
  */
 public static function fetchAvailablePageTypes()
 {
     $system_types = array('index', 'XML', 'JSON', 'admin', '404', '403');
     $types = PageManager::fetchPageTypes();
     return !empty($types) ? General::array_remove_duplicates(array_merge($system_types, $types)) : $system_types;
 }
Пример #18
0
 /**
  * Returns an array of all available field handles discovered in the
  * `TOOLKIT . /fields` or `EXTENSIONS . /{}/fields`.
  *
  * @return array
  *  A single dimensional array of field handles.
  */
 public function fetchTypes()
 {
     $structure = General::listStructure(TOOLKIT . '/fields', '/field.[a-z0-9_-]+.php/i', false, 'asc', TOOLKIT . '/fields');
     $extensions = Symphony::ExtensionManager()->listInstalledHandles();
     if (is_array($extensions) && !empty($extensions)) {
         foreach ($extensions as $handle) {
             if (is_dir(EXTENSIONS . '/' . $handle . '/fields')) {
                 $tmp = General::listStructure(EXTENSIONS . '/' . $handle . '/fields', '/field.[a-z0-9_-]+.php/i', false, 'asc', EXTENSIONS . '/' . $handle . '/fields');
                 if (is_array($tmp['filelist']) && !empty($tmp['filelist'])) {
                     $structure['filelist'] = array_merge($structure['filelist'], $tmp['filelist']);
                 }
             }
         }
         $structure['filelist'] = General::array_remove_duplicates($structure['filelist']);
     }
     $types = array();
     foreach ($structure['filelist'] as $filename) {
         $types[] = FieldManager::__getHandleFromFilename($filename);
     }
     return $types;
 }
Пример #19
0
 public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
 {
     $status = self::__OK__;
     $data = preg_split('/\\,\\s*/i', $data, -1, PREG_SPLIT_NO_EMPTY);
     $data = array_map('trim', $data);
     $result = array('value' => array(), 'handle' => array());
     if (empty($data)) {
         return null;
     }
     // Do a case insensitive removal of duplicates
     $data = General::array_remove_duplicates($data, true);
     sort($data);
     $result = array();
     foreach ($data as $value) {
         $result['value'][] = $value;
         $result['handle'][] = Lang::createHandle($value);
     }
     return $result;
 }
 public function processRawFieldData($data, &$status, $simulate = false, $entry_id = null)
 {
     $status = self::__OK__;
     $result = array();
     if (is_array($data)) {
         $data = implode(',', $data);
     }
     $data = preg_split('/\\,\\s*/i', $data, -1, PREG_SPLIT_NO_EMPTY);
     $data = array_map('trim', $data);
     $data = General::array_remove_duplicates($data);
     if (empty($data)) {
         return;
     }
     // Convert to timestamps:
     foreach ($data as &$value) {
         $value = strtotime($value);
     }
     foreach ($data as $timestamp) {
         $result['value'][] = DateTimeObj::get('c', $timestamp);
         $result['local'][] = $timestamp;
         $result['gmt'][] = strtotime(DateTimeObj::getGMT('c', $timestamp));
     }
     return $result;
 }