public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle('Symphony – Importers');
     $tableHead = array(array('Name', 'col'), array('Version', 'col'), array('Author', 'col'));
     $tableBody = array();
     if (!is_array($this->_importers) or empty($this->_importers)) {
         $tableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', null, count($tableHead)))));
     } else {
         foreach ($this->_importers as $importer) {
             $importer = (object) $importer;
             $col_name = Widget::TableData(Widget::Anchor($this->_driver->truncateValue($importer->name), $this->_uri . "/importers/edit/{$importer->handle}/"));
             $col_name->appendChild(Widget::Input("items[{$importer->id}]", null, 'checkbox'));
             $col_version = Widget::TableData($this->_driver->truncateValue($importer->version));
             $col_author = Widget::TableData($this->_driver->truncateValue($importer->version));
             if (isset($importer->author['website']) and preg_match('/^[^\\s:\\/?#]+:(?:\\/{2,3})?[^\\s.\\/?#]+(?:\\.[^\\s.\\/?#]+)*(?:\\/[^\\s?#]*\\??[^\\s?#]*(#[^\\s#]*)?)?$/', $importer->author['website'])) {
                 $col_author = Widget::Anchor($importer->author['name'], General::validateURL($importer->author['website']));
             } elseif (isset($importer->author['email']) and preg_match('/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i', $importer->author['email'])) {
                 $col_author = Widget::Anchor($importer->author['name'], 'mailto:' . $importer->author['email']);
             } else {
                 $col_author = $importer->author['name'];
             }
             $col_author = Widget::TableData($col_author);
             $tableBody[] = Widget::TableRow(array($col_name, $col_version, $col_author));
         }
     }
     $table = Widget::Table(Widget::TableHead($tableHead), null, Widget::TableBody($tableBody));
     $this->Form->appendChild($table);
 }
 function getValuesFromXML()
 {
     $xml_location = $this->get('xml_location');
     if (General::validateURL($xml_location) != '') {
         // is a URL, check cache
         $cache_id = md5($xml_location);
         $cache = new Cacheable($this->_Parent->_Parent->Database);
         $cachedData = $cache->check($cache_id);
         $creation = DateTimeObj::get('c');
         if (!$cachedData || time() - $cachedData['creation'] > 5 * 60) {
             if (Mutex::acquire($cache_id, 6, TMP)) {
                 $ch = new Gateway();
                 $ch->init();
                 $ch->setopt('URL', $xml_location);
                 $ch->setopt('TIMEOUT', 6);
                 $xml = $ch->exec();
                 $writeToCache = true;
                 Mutex::release($cache_id, TMP);
                 $xml = trim($xml);
                 if (empty($xml) && $cachedData) {
                     $xml = $cachedData['data'];
                 }
             } elseif ($cachedData) {
                 $xml = $cachedData['data'];
             }
         } else {
             $xml = $cachedData['data'];
         }
         $xml = simplexml_load_string($xml);
     } elseif (substr($xml_location, 0, 1) == '/') {
         // relative to DOCROOT
         $xml = simplexml_load_file(DOCROOT . $this->get('xml_location'));
     } else {
         // in extension's /xml folder
         $xml = simplexml_load_file(EXTENSIONS . '/xml_selectbox/xml/' . $this->get('xml_location'));
     }
     if (!$xml) {
         return;
     }
     $items = $xml->xpath($this->get('item_xpath'));
     $options = array();
     foreach ($items as $item) {
         $option = array();
         $text_xpath = $item->xpath($this->get('text_xpath'));
         $option['text'] = General::sanitize((string) $text_xpath[0]);
         if ($this->get('value_xpath') != '') {
             $value_xpath = $item->xpath($this->get('value_xpath'));
             $option['value'] = General::sanitize((string) $value_xpath[0]);
         }
         if ((string) $option['value'] == '') {
             $option['value'] = $option['text'];
         }
         $options[] = $option;
     }
     return $options;
 }
 function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Extensions'))));
     $this->appendSubheading(__('Extensions'));
     $this->Form->setAttribute('action', URL . '/symphony/system/extensions/');
     $ExtensionManager = $this->_Parent->ExtensionManager;
     $extensions = $ExtensionManager->listAll();
     ## Sort by extensions name:
     uasort($extensions, array('ExtensionManager', 'sortByName'));
     $aTableHead = array(array(__('Name'), 'col'), array(__('Enabled'), 'col'), array(__('Version'), 'col'), array(__('Author'), 'col'));
     $aTableBody = array();
     if (!is_array($extensions) || empty($extensions)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead)))));
     } else {
         foreach ($extensions as $name => $about) {
             ## Setup each cell
             $td1 = Widget::TableData(!empty($about['table-link']) && $about['status'] == EXTENSION_ENABLED ? Widget::Anchor($about['name'], $this->_Parent->getCurrentPageURL() . 'extension/' . trim($about['table-link'], '/') . '/') : $about['name']);
             $td2 = Widget::TableData($about['status'] == EXTENSION_ENABLED ? __('Yes') : __('No'));
             $td3 = Widget::TableData($about['version']);
             $link = $about['author']['name'];
             if (isset($about['author']['website'])) {
                 $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
             } elseif (isset($about['author']['email'])) {
                 $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
             }
             $td4 = Widget::TableData($link);
             $td4->appendChild(Widget::Input('items[' . $name . ']', 'on', 'checkbox'));
             ## Add a row to the body array, assigning each cell to the row
             $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4), $about['status'] == EXTENSION_NOT_INSTALLED ? 'inactive' : NULL);
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody));
     $this->Form->appendChild($table);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(NULL, false, __('With Selected...')), array('enable', false, __('Enable')), array('disable', false, __('Disable')), array('uninstall', false, __('Uninstall'), 'confirm'));
     $tableActions->appendChild(Widget::Select('with-selected', $options));
     $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit'));
     $this->Form->appendChild($tableActions);
 }
 private function buildTable(array $extensions = NULL, $prefixes = false)
 {
     $aTableHead = array(array(__('Name'), 'col'), array(__('Version'), 'col'), array(__('Author'), 'col'), array(__('Actions'), 'col', array('class' => 'row-actions')));
     $aTableBody = array();
     $colspan = count($aTableHead);
     if (is_null($extensions)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), array('class' => 'inactive', 'colspan' => $colspan))), array('class' => 'odd')));
     } else {
         foreach ($extensions as $handle) {
             $about = $this->lists->extensions[$handle]['object']->about();
             $fragment = $this->createDocumentFragment();
             if (!empty($about->{'table-link'}) && $this->lists->extensions[$handle]['status'] == Extension::STATUS_ENABLED) {
                 $fragment->appendChild(Widget::Anchor($about->{'name'}, Administration::instance()->getCurrentPageURL() . '/extension/' . trim($about->{'table-link'}, '/')));
             } else {
                 $fragment->appendChild(new DOMText($about->{'name'}));
             }
             if ($prefixes && isset($about->{'type'})) {
                 $fragment->appendChild($this->createElement('span', ' · ' . $about->{'type'}[0]));
             }
             ## Setup each cell
             $td1 = Widget::TableData($fragment);
             $td2 = Widget::TableData($about->{'version'});
             $link = $about->author->name;
             if (isset($about->author->website)) {
                 $link = Widget::Anchor($about->author->name, General::validateURL($about->author->website));
             } elseif (isset($about->author->email)) {
                 $link = Widget::Anchor($about->author->name, 'mailto:' . $about->author->email);
             }
             $td3 = Widget::TableData($link);
             $td3->appendChild(Widget::Input('items[' . $handle . ']', 'on', 'checkbox'));
             switch ($this->lists->extensions[$handle]['status']) {
                 case Extension::STATUS_ENABLED:
                     $td4 = Widget::TableData();
                     $td4->appendChild(Widget::Input("action[uninstall][{$handle}]", __('Uninstall'), 'submit', array('class' => 'button delete')));
                     $td4->appendChild(Widget::Input("action[disable][{$handle}]", __('Disable'), 'submit', array('class' => 'button')));
                     break;
                 case Extension::STATUS_DISABLED:
                     $td4 = Widget::TableData(Widget::Input("action[enable][{$handle}]", __('Enable'), 'submit', array('class' => 'button create')));
                     break;
                 case Extension::STATUS_NOT_INSTALLED:
                     $td4 = Widget::TableData(Widget::Input("action[enable][{$handle}]", __('Install'), 'submit', array('class' => 'button create')));
                     break;
                 case Extension::STATUS_REQUIRES_UPDATE:
                     $td4 = Widget::TableData(Widget::Input("action[update][{$handle}]", __('Update'), 'submit', array('class' => 'button create')));
             }
             ## Add a row to the body array, assigning each cell to the row
             $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4), $this->lists->status[$handle] == Extension::STATUS_NOT_INSTALLED ? array('class' => 'inactive') : array());
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody));
     return $table;
 }
 public function __viewInfo()
 {
     $this->setPageType('form');
     $datasource = DatasourceManager::create($this->_context[1], array(), false);
     $about = $datasource->about();
     $this->setTitle(__('%1$s – %2$s – %3$s', array($about['name'], __('Data Source'), __('Symphony'))));
     $this->appendSubheading($this->_context[0] == 'info' ? $about['name'] : __('Untitled'));
     $this->insertBreadcrumbs(array(Widget::Anchor(__('Data Sources'), SYMPHONY_URL . '/blueprints/datasources/')));
     $this->Form->setAttribute('id', 'controller');
     $link = $about['author']['name'];
     if (isset($about['author']['website'])) {
         $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
     } elseif (isset($about['author']['email'])) {
         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
     }
     foreach ($about as $key => $value) {
         $fieldset = null;
         switch ($key) {
             case 'author':
                 if ($link) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Author')));
                     $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
                 }
                 break;
             case 'version':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Version')));
                 $release_date = array_key_exists('release-date', $about) ? $about['release-date'] : filemtime(DatasourceManager::__getDriverPath($this->_context[1]));
                 if (preg_match('/^\\d+(\\.\\d+)*$/', $value)) {
                     $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($value, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__)))));
                 } else {
                     $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($value, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__)))));
                 }
                 break;
             case 'description':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Description')));
                 $fieldset->appendChild(is_object($about['description']) ? $about['description'] : new XMLElement('p', $about['description']));
                 break;
             case 'example':
                 if (is_callable(array($datasource, 'example'))) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Example XML')));
                     $example = $datasource->example();
                     if (is_object($example)) {
                         $fieldset->appendChild($example);
                     } else {
                         $p = new XMLElement('p');
                         $p->appendChild(new XMLElement('pre', '<code>' . str_replace('<', '&lt;', $example) . '</code>'));
                         $fieldset->appendChild($p);
                     }
                 }
                 break;
         }
         if ($fieldset) {
             $fieldset->setAttribute('class', 'settings');
             $this->Form->appendChild($fieldset);
         }
     }
     // Display source
     $file = DatasourceManager::__getClassPath($this->_context[1]) . '/data.' . $this->_context[1] . '.php';
     if (file_exists($file)) {
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Source')));
         $source = file_get_contents($file);
         $code = new XMLElement('code', htmlspecialchars($source));
         $pre = new XMLElement('pre');
         $pre->appendChild($code);
         $fieldset->appendChild($pre);
         $this->Form->appendChild($fieldset);
     }
 }
 public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle(__('%1$s &ndash; %2$s', array(__('Extensions'), __('Symphony'))));
     $this->appendSubheading(__('Extensions'));
     $this->Form->setAttribute('action', SYMPHONY_URL . '/system/extensions/');
     Sortable::initialize($this, $extensions, $sort, $order);
     $columns = array(array('label' => __('Name'), 'sortable' => true, 'handle' => 'name'), array('label' => __('Version'), 'sortable' => false), array('label' => __('Status'), 'sortable' => false), array('label' => __('Links'), 'sortable' => false, 'handle' => 'links'), array('label' => __('Authors'), 'sortable' => true, 'handle' => 'author'));
     $aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, isset($_REQUEST['filter']) ? '&amp;filter=' . $_REQUEST['filter'] : '');
     $aTableBody = array();
     if (!is_array($extensions) || empty($extensions)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead))), 'odd'));
     } else {
         foreach ($extensions as $name => $about) {
             // Name
             $td1 = Widget::TableData($about['name']);
             $td1->appendChild(Widget::Label(__('Select %s Extension', array($about['name'])), null, 'accessible', null, array('for' => 'extension-' . $name)));
             $td1->appendChild(Widget::Input('items[' . $name . ']', 'on', 'checkbox', array('id' => 'extension-' . $name)));
             // Version
             $installed_version = Symphony::ExtensionManager()->fetchInstalledVersion($name);
             if (in_array(Extension::EXTENSION_NOT_INSTALLED, $about['status'])) {
                 $td2 = Widget::TableData($about['version']);
             } elseif (in_array(Extension::EXTENSION_REQUIRES_UPDATE, $about['status'])) {
                 $td2 = Widget::TableData($installed_version . '<i> → ' . $about['version'] . '</i>');
             } else {
                 $td2 = Widget::TableData($installed_version);
             }
             // Status
             $trClasses = array();
             $trStatus = '';
             $tdMessage = __('Status unavailable');
             if (in_array(Extension::EXTENSION_NOT_INSTALLED, $about['status'])) {
                 $tdMessage = __('Not installed');
                 $trClasses[] = 'inactive';
                 $trClasses[] = 'extension-can-install';
             }
             if (in_array(Extension::EXTENSION_DISABLED, $about['status'])) {
                 $tdMessage = __('Disabled');
                 $trStatus = 'status-notice';
             }
             if (in_array(Extension::EXTENSION_ENABLED, $about['status'])) {
                 $tdMessage = __('Enabled');
             }
             if (in_array(Extension::EXTENSION_REQUIRES_UPDATE, $about['status'])) {
                 $tdMessage = __('Update available');
                 $trClasses[] = 'extension-can-update';
                 $trStatus = 'status-ok';
             }
             if (in_array(Extension::EXTENSION_NOT_COMPATIBLE, $about['status'])) {
                 $tdMessage .= ', ' . __('requires Symphony %s', array($about['required_version']));
                 $trStatus = 'status-error';
             }
             $trClasses[] = $trStatus;
             $td3 = Widget::TableData($tdMessage);
             // Links
             $tdLinks = array();
             if ($about['github'] != '') {
                 $tdLinks['github'] = Widget::Anchor(__('GitHub'), General::validateURL($about['github']))->generate();
             }
             if ($about['discuss'] != '') {
                 $tdLinks['discuss'] = Widget::Anchor(__('Discuss'), General::validateURL($about['discuss']))->generate();
                 // Update links to point to our 'new' domain, RE: #1995
                 $tdLinks['discuss'] = str_replace('symphony-cms.com', 'getsymphony.com', $tdLinks['discuss']);
             }
             if ($about['homepage'] != '') {
                 $tdLinks['homepage'] = Widget::Anchor(__('Homepage'), General::validateURL($about['homepage']))->generate();
             }
             if ($about['wiki'] != '') {
                 $tdLinks['wiki'] = Widget::Anchor(__('Wiki'), General::validateURL($about['wiki']))->generate();
             }
             if ($about['issues'] != '') {
                 $tdLinks['issues'] = Widget::Anchor(__('Issues'), General::validateURL($about['issues']))->generate();
             }
             $td4 = Widget::TableData($tdLinks);
             // Authors
             $tdAuthors = array();
             if (!is_array($about['author'])) {
                 $about['author'] = array($about['author']);
             }
             foreach ($about['author'] as $author) {
                 if (isset($author['website'])) {
                     $tdAuthors[] = Widget::Anchor($author['name'], General::validateURL($author['website']))->generate();
                 } elseif (isset($author['github'])) {
                     $tdAuthors[] = Widget::Anchor($author['name'], General::validateURL('https://github.com/' . $author['github']))->generate();
                 } elseif (isset($author['email'])) {
                     $tdAuthors[] = Widget::Anchor($author['name'], 'mailto:' . $author['email'])->generate();
                 } else {
                     $tdAuthors[] = $author['name'];
                 }
             }
             $td5 = Widget::TableData($tdAuthors);
             // Create the table row
             $tr = Widget::TableRow(array($td1, $td2, $td3, $td4, $td5), implode(' ', $trClasses));
             // Add some attributes about the extension
             $tr->setAttribute('data-handle', $name);
             $tr->setAttribute('data-installed-version', $installed_version);
             $tr->setAttribute('data-meta-version', $about['version']);
             // Add a row to the body array, assigning each cell to the row
             $aTableBody[] = $tr;
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), null, Widget::TableBody($aTableBody), 'selectable', null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive'));
     $this->Form->appendChild($table);
     $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array('id' => 'version'));
     $this->Form->appendChild($version);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(null, false, __('With Selected...')), array('enable', false, __('Enable')), array('disable', false, __('Disable')), array('uninstall', false, __('Uninstall'), 'confirm', null, array('data-message' => __('Are you sure you want to uninstall the selected extensions?'))));
     /**
      * Allows an extension to modify the existing options for this page's
      * With Selected menu. If the `$options` parameter is an empty array,
      * the 'With Selected' menu will not be rendered.
      *
      * @delegate AddCustomActions
      * @since Symphony 2.3.2
      * @param string $context
      * '/system/extensions/'
      * @param array $options
      *  An array of arrays, where each child array represents an option
      *  in the With Selected menu. Options should follow the same format
      *  expected by `Widget::__SelectBuildOption`. Passed by reference.
      */
     Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/system/extensions/', array('options' => &$options));
     if (!empty($options)) {
         $tableActions->appendChild(Widget::Apply($options));
         $this->Form->appendChild($tableActions);
     }
 }
 * @licence https://github.com/symphonycms/symphony-1.7/blob/master/LICENCE
 *
 ***/
if (array_key_exists("save", $_POST['action'])) {
    $fields = $_POST['fields'];
    $required = array('author_name', 'body');
    for ($i = 0; $i < count($required); $i++) {
        if (trim($fields[$required[$i]]) == "") {
            $errors[$required[$i]] = true;
        }
    }
    if (is_array($errors)) {
        define("__SYM_ENTRY_MISSINGFIELDS__", true);
    } else {
        $fields['author_name'] = General::sanitize($fields['author_name']);
        $fields['author_url'] = General::validateURL($fields['author_url']);
        $fields['author_email'] = General::sanitize($fields['author_email']);
        $fields['body'] = $fields['body'];
        $fields['spam'] = $fields['spam'] ? "yes" : "no";
        if ($fields['blacklist'] && $fields['author_ip'] != '') {
            $ip = trim($fields['author_ip']);
            $current_blacklist = $Admin->getConfigVar("ip-blacklist", "commenting");
            $current_blacklist = preg_split('/,/', $current_blacklist, -1, PREG_SPLIT_NO_EMPTY);
            $current_blacklist = @array_map("trim", $current_blacklist);
            if (!@in_array($ip, $current_blacklist)) {
                $current_blacklist[] = $ip;
            }
            $Admin->setConfigVar("ip-blacklist", @implode(', ', $current_blacklist), "commenting");
            $Admin->saveConfig();
            $Admin->flush_cache(array("comments", "entries", "authors"));
        } elseif (!$fields['blacklist'] && $fields['author_ip'] != '') {
 function __viewInfo()
 {
     $this->setPageType('form');
     $DSManager = new DatasourceManager($this->_Parent);
     $datasource = $DSManager->create($this->_context[1], NULL, false);
     $about = $datasource->about();
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array(__('Symphony'), __('Data Source'), $about['name'])));
     $this->appendSubheading($about['name']);
     $this->Form->setAttribute('id', 'controller');
     $link = $about['author']['name'];
     if (isset($about['author']['website'])) {
         $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
     } elseif (isset($about['author']['email'])) {
         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
     }
     foreach ($about as $key => $value) {
         $fieldset = NULL;
         switch ($key) {
             case 'author':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', 'Author'));
                 $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
                 break;
             case 'version':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', 'Version'));
                 $fieldset->appendChild(new XMLElement('p', $value . ', released on ' . DateTimeObj::get(__SYM_DATE_FORMAT__, strtotime($about['release-date']))));
                 break;
             case 'description':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', 'Description'));
                 $fieldset->appendChild(is_object($about['description']) ? $about['description'] : new XMLElement('p', $about['description']));
             case 'example':
                 if (is_callable(array($datasource, 'example'))) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', 'Example XML'));
                     $example = $datasource->example();
                     if (is_object($example)) {
                         $fieldset->appendChild($example);
                     } else {
                         $p = new XMLElement('p');
                         $p->appendChild(new XMLElement('pre', '<code>' . str_replace('<', '&lt;', $example) . '</code>'));
                         $fieldset->appendChild($p);
                     }
                 }
                 break;
         }
         if ($fieldset) {
             $fieldset->setAttribute('class', 'settings');
             $this->Form->appendChild($fieldset);
         }
     }
     /*
     $dl->appendChild(new XMLElement('dt', __('URL Parameters')));
     if(!is_array($about['recognised-url-param']) || empty($about['recognised-url-param'])){
     	$dl->appendChild(new XMLElement('dd', '<code>'.__('None').'</code>'));
     }			
     else{
     	$dd = new XMLElement('dd');
     	$ul = new XMLElement('ul');
     	
     	foreach($about['recognised-url-param'] as $f) $ul->appendChild(new XMLElement('li', '<code>' . $f . '</code>'));
     
     	$dd->appendChild($ul);
     	$dl->appendChild($dd);
     }			
     $fieldset->appendChild($dl);
     */
 }
 * Symphony web publishing system
 *
 * Copyright 2004–2006 Twenty One Degrees Pty. Ltd.
 *
 * @version 1.7
 * @licence https://github.com/symphonycms/symphony-1.7/blob/master/LICENCE
 *
 ***/
$EM = new EventManager(array('parent' => &$Admin));
$oEvent =& $EM->create($_REQUEST['file']);
$about = $oEvent->about();
$GLOBALS['pageTitle'] = 'Events > ' . $about['name'];
$date = $Admin->getDateObj();
$link = $about['author']['name'];
if (isset($about['author']['website'])) {
    $link = '<a href="' . General::validateURL($about['author']['website']) . '">' . $about['author']['name'] . '</a>';
} elseif (isset($about['author']['email'])) {
    $link = '<a href="mailto:' . $about['author']['email'] . '">' . $about['author']['name'] . '</a>';
}
?>


<form id="controller" action="" method="post">
  	<h2><?php 
print $about['name'];
?>
</h2>

	<fieldset>
		<dl>
			<dt>Author</dt>
 public function __viewInfo()
 {
     $this->setPageType('form');
     $datasource = DatasourceManager::create($this->_context[1], array(), false);
     $about = $datasource->about();
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array($about['name'], __('Data Source'), __('Symphony'))));
     $this->appendSubheading($about['name']);
     $this->Form->setAttribute('id', 'controller');
     $link = $about['author']['name'];
     if (isset($about['author']['website'])) {
         $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
     } elseif (isset($about['author']['email'])) {
         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
     }
     foreach ($about as $key => $value) {
         $fieldset = NULL;
         switch ($key) {
             case 'author':
                 if ($link) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Author')));
                     $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
                 }
                 break;
             case 'version':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Version')));
                 if (preg_match('/^\\d+(\\.\\d+)*$/', $value)) {
                     $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($value, DateTimeObj::format($about['release-date'], __SYM_DATE_FORMAT__)))));
                 } else {
                     $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($value, DateTimeObj::format($about['release-date'], __SYM_DATE_FORMAT__)))));
                 }
                 break;
             case 'description':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Description')));
                 $fieldset->appendChild(is_object($about['description']) ? $about['description'] : new XMLElement('p', $about['description']));
             case 'example':
                 if (is_callable(array($datasource, 'example'))) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Example XML')));
                     $example = $datasource->example();
                     if (is_object($example)) {
                         $fieldset->appendChild($example);
                     } else {
                         $p = new XMLElement('p');
                         $p->appendChild(new XMLElement('pre', '<code>' . str_replace('<', '&lt;', $example) . '</code>'));
                         $fieldset->appendChild($p);
                     }
                 }
                 break;
         }
         if ($fieldset) {
             $fieldset->setAttribute('class', 'settings');
             $this->Form->appendChild($fieldset);
         }
     }
 }
		<fieldset>
			<label>Comment <textarea name="fields[body]" cols="75" rows="15"><?php 
echo General::sanitize($fields['body']);
?>
</textarea></label>
			<fieldset>
				<label>Name <input name="fields[author_name]" <?php 
print General::fieldValue("value", $fields["author_name"]);
?>
 /></label>
				<label>Email Address <input name="fields[author_email]" <?php 
print General::fieldValue("value", $fields["author_email"]);
?>
 /></label>
				<label>Website <input name="fields[author_url]" <?php 
print General::fieldValue("value", General::validateURL($fields["author_url"]));
?>
 /></label>
				<label><acronym title="Internet Protocol">IP</acronym> Address <input name="fields[author_ip]" <?php 
print General::fieldValue("value", $fields["author_ip"]);
?>
 /></label>
				<label><input name="fields[spam]" type="checkbox" <?php 
print $fields['spam'] == "yes" ? ' checked="checked"' : "";
?>
 /> Flag this comment as spam</label>
				<label><input name="fields[blacklist]" type="checkbox" <?php 
print $fields['blacklist'] == "yes" ? ' checked="checked"' : "";
?>
 /> Blacklist this users <acronym title="Internet Protocol">IP</acronym> Address</label>
			</fieldset>
 /**
  * This function contains the minimal amount of logic for generating the
  * index table of a given `$resource_type`. The table has name, source, pages
  * release date and author columns. The values for these columns are determined
  * by the resource's `about()` method.
  *
  * As Datasources types can be installed using Providers, the Source column
  * can be overridden with a Datasource's `getSourceColumn` method (if it exists).
  *
  * @param integer $resource_type
  *  Either `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DATASOURCE`
  */
 public function __viewIndex($resource_type)
 {
     $manager = ResourceManager::getManagerFromType($resource_type);
     $this->setPageType('table');
     Sortable::initialize($this, $resources, $sort, $order, array('type' => $resource_type));
     $columns = array(array('label' => __('Name'), 'sortable' => true, 'handle' => 'name'), array('label' => __('Source'), 'sortable' => true, 'handle' => 'source'), array('label' => __('Pages'), 'sortable' => false), array('label' => __('Release Date'), 'sortable' => true, 'handle' => 'release-date'), array('label' => __('Author'), 'sortable' => true, 'handle' => 'author'));
     $aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, isset($_REQUEST['filter']) ? '&amp;filter=' . $_REQUEST['filter'] : '');
     $aTableBody = array();
     if (!is_array($resources) || empty($resources)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd'));
     } else {
         foreach ($resources as $r) {
             // Resource name
             $action = $r['can_parse'] ? 'edit' : 'info';
             $name = Widget::TableData(Widget::Anchor($r['name'], SYMPHONY_URL . $_REQUEST['symphony-page'] . $action . '/' . $r['handle'] . '/', $r['handle']));
             // Resource type/source
             if (isset($r['source']['id'])) {
                 $section = Widget::TableData(Widget::Anchor($r['source']['name'], SYMPHONY_URL . '/blueprints/sections/edit/' . $r['source']['id'] . '/', $r['source']['handle']));
             } else {
                 if (class_exists($r['source']['name']) && method_exists($r['source']['name'], 'getSourceColumn')) {
                     $class = call_user_func(array($manager, '__getClassName'), $r['handle']);
                     $section = Widget::TableData(call_user_func(array($class, 'getSourceColumn'), $r['handle']));
                 } else {
                     if (isset($r['source']['name'])) {
                         $section = Widget::TableData($r['source']['name']);
                     } else {
                         $section = Widget::TableData(__('Unknown'), 'inactive');
                     }
                 }
             }
             // Attached pages
             $pages = ResourceManager::getAttachedPages($resource_type, $r['handle']);
             $pagelinks = array();
             $i = 0;
             foreach ($pages as $p) {
                 ++$i;
                 $pagelinks[] = Widget::Anchor($p['title'], SYMPHONY_URL . '/blueprints/pages/edit/' . $p['id'] . '/')->generate() . (count($pages) > $i ? $i % 10 == 0 ? '<br />' : ', ' : '');
             }
             $pages = implode('', $pagelinks);
             if ($pages == '') {
                 $pagelinks = Widget::TableData(__('None'), 'inactive');
             } else {
                 $pagelinks = Widget::TableData($pages, 'pages');
             }
             // Release date
             $releasedate = Widget::TableData(Lang::localizeDate(DateTimeObj::format($r['release-date'], __SYM_DATETIME_FORMAT__)));
             // Authors
             $author = $r['author']['name'];
             if (isset($r['author']['website'])) {
                 $author = Widget::Anchor($r['author']['name'], General::validateURL($r['author']['website']));
             } else {
                 if (isset($r['author']['email'])) {
                     $author = Widget::Anchor($r['author']['name'], 'mailto:' . $r['author']['email']);
                 }
             }
             $author = Widget::TableData($author);
             $author->appendChild(Widget::Input('items[' . $r['handle'] . ']', null, 'checkbox'));
             $aTableBody[] = Widget::TableRow(array($name, $section, $pagelinks, $releasedate, $author));
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'selectable');
     $this->Form->appendChild($table);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete'), 'confirm'));
     $pages = $this->pagesFlatView();
     $group_attach = array('label' => __('Attach to Page'), 'options' => array());
     $group_detach = array('label' => __('Detach from Page'), 'options' => array());
     $group_attach['options'][] = array('attach-all-pages', false, __('All'));
     $group_detach['options'][] = array('detach-all-pages', false, __('All'));
     foreach ($pages as $p) {
         $group_attach['options'][] = array('attach-to-page-' . $p['id'], false, $p['title']);
         $group_detach['options'][] = array('detach-from-page-' . $p['id'], false, $p['title']);
     }
     $options[] = $group_attach;
     $options[] = $group_detach;
     $tableActions->appendChild(Widget::Apply($options));
     $this->Form->appendChild($tableActions);
 }
Exemplo n.º 13
0
 function url2a($str, $nofollow = false)
 {
     preg_match_all("/http:\\/\\/?[^ ][^<]+/i", $str, $lnk);
     $size = sizeof($lnk[0]);
     $i = 0;
     while ($i < $size) {
         $len = strlen($lnk[0][$i]);
         if ($len > 30) {
             $lnk_txt = substr($lnk[0][$i], 0, 30) . "...";
         } else {
             $lnk_txt = $lnk[0][$i];
         }
         $url = General::validateURL($lnk[0][$i]);
         if (!empty($url)) {
             $str = str_replace($url, "<a href=\"{$url}\" " . ($nofollow ? "rel=\"nofollow\"" : "") . ">{$lnk_txt}</a>", $str);
         }
         $i++;
     }
     return $str;
 }
 $required = array('name', 'source');
 for ($i = 0; $i < count($required); $i++) {
     if (trim($fields[$required[$i]]) == "") {
         $errors[$required[$i]] = true;
     }
 }
 if (is_array($errors)) {
     define("__SYM_ENTRY_MISSINGFIELDS__", true);
 } else {
     $defines = array();
     $fields['name'] = str_replace(array('\'', '"'), "", $fields['name']);
     $handle = General::createFileName($fields['name'], $Admin->getConfigVar('handle_length', 'admin'), '_');
     $rootelement = General::createFileName($fields['name'], $Admin->getConfigVar('handle_length', 'admin'), '-');
     $classname = ucfirst($handle);
     $source = $fields['source'];
     $var = array('HANDLE' => $handle, 'ROOT-ELEMENT' => $rootelement, 'CLASS NAME' => $classname, 'NAME' => $fields['name'], 'DESCRIPTION' => "", 'AUTHOR-NAME' => $Admin->getAuthorName(), 'AUTHOR-WEBSITE' => General::validateURL(URL), 'AUTHOR-EMAIL' => $Admin->getAuthorEmail(), 'VERSION' => "1.0", 'RELEASE DATE' => date("Y-m-d H:i:s", $date->get(true, false)));
     $xml_elements = array();
     if (is_array($fields['xml-elements']) && !empty($fields['xml-elements'])) {
         foreach ($fields['xml-elements'] as $f) {
             $f = trim($f, '[]');
             $bits = preg_split('/\\]\\[/i', $f, -1, PREG_SPLIT_NO_EMPTY);
             list($group, $element) = $bits;
             $xml_elements[$group][] = $element;
         }
     }
     switch ($source) {
         case "authors":
             $defines['status'] = $fields['status'];
             $defines['username'] = $fields['username'];
             break;
         case "comments":
 public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle(__('%1$s &ndash; %2$s', array(__('Extensions'), __('Symphony'))));
     $this->appendSubheading(__('Extensions'));
     $this->Form->setAttribute('action', SYMPHONY_URL . '/system/extensions/');
     Sortable::initialize($this, $extensions, $sort, $order);
     $columns = array(array('label' => __('Name'), 'sortable' => true, 'handle' => 'name'), array('label' => __('Installed Version'), 'sortable' => false), array('label' => __('Enabled'), 'sortable' => false), array('label' => __('Authors'), 'sortable' => true, 'handle' => 'author'));
     $aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, isset($_REQUEST['filter']) ? '&amp;filter=' . $_REQUEST['filter'] : '');
     $aTableBody = array();
     if (!is_array($extensions) || empty($extensions)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd'));
     } else {
         foreach ($extensions as $name => $about) {
             $td1 = Widget::TableData($about['name']);
             $installed_version = Symphony::ExtensionManager()->fetchInstalledVersion($name);
             $td2 = Widget::TableData(is_null($installed_version) ? __('Not Installed') : $installed_version);
             // If the extension is using the new `extension.meta.xml` format, check the
             // compatibility of the extension. This won't prevent a user from installing
             // it, but it will let them know that it requires a version of Symphony greater
             // then what they have.
             if (in_array(EXTENSION_NOT_INSTALLED, $about['status'])) {
                 $td3 = Widget::TableData(__('Enable to install %s', array($about['version'])));
             }
             if (in_array(EXTENSION_NOT_COMPATIBLE, $about['status'])) {
                 $td3 = Widget::TableData(__('Requires Symphony %s', array($about['required_version'])));
             }
             if (in_array(EXTENSION_ENABLED, $about['status'])) {
                 $td3 = Widget::TableData(__('Yes'));
             }
             if (in_array(EXTENSION_REQUIRES_UPDATE, $about['status'])) {
                 if (in_array(EXTENSION_NOT_COMPATIBLE, $about['status'])) {
                     $td3 = Widget::TableData(__('New version %1$s, Requires Symphony %2$s', array($about['version'], $about['required_version'])));
                 } else {
                     $td3 = Widget::TableData(__('Enable to update to %s', array($about['version'])));
                 }
             }
             if (in_array(EXTENSION_DISABLED, $about['status'])) {
                 $td3 = Widget::TableData(__('Disabled'));
             }
             $td4 = Widget::TableData(NULL);
             if (isset($about['author'][0]) && is_array($about['author'][0])) {
                 $authors = '';
                 foreach ($about['author'] as $i => $author) {
                     if (isset($author['website'])) {
                         $link = Widget::Anchor($author['name'], General::validateURL($author['website']));
                     } else {
                         if (isset($author['email'])) {
                             $link = Widget::Anchor($author['name'], 'mailto:' . $author['email']);
                         } else {
                             $link = $author['name'];
                         }
                     }
                     $authors .= ($link instanceof XMLElement ? $link->generate() : $link) . ($i != count($about['author']) - 1 ? ", " : "");
                 }
                 $td4->setValue($authors);
             } else {
                 if (isset($about['author']['website'])) {
                     $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
                 } else {
                     if (isset($about['author']['email'])) {
                         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
                     } else {
                         $link = $about['author']['name'];
                     }
                 }
                 $td4->setValue($link instanceof XMLElement ? $link->generate() : $link);
             }
             $td4->appendChild(Widget::Input('items[' . $name . ']', 'on', 'checkbox'));
             // Add a row to the body array, assigning each cell to the row
             $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4), in_array(EXTENSION_NOT_INSTALLED, $about['status']) ? 'inactive' : NULL);
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'selectable');
     $this->Form->appendChild($table);
     $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array('id' => 'version'));
     $this->Form->appendChild($version);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(NULL, false, __('With Selected...')), array('enable', false, __('Enable/Install')), array('disable', false, __('Disable')), array('uninstall', false, __('Uninstall'), 'confirm', null, array('data-message' => __('Are you sure you want to uninstall the selected extensions?'))));
     /**
      * Allows an extension to modify the existing options for this page's
      * With Selected menu. If the `$options` parameter is an empty array,
      * the 'With Selected' menu will not be rendered.
      *
      * @delegate AddCustomActions
      * @since Symphony 2.3.2
      * @param string $context
      * '/system/extensions/'
      * @param array $options
      *  An array of arrays, where each child array represents an option
      *  in the With Selected menu. Options should follow the same format
      *  expected by `Widget::__SelectBuildOption`. Passed by reference.
      */
     Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/system/extensions/', array('options' => &$options));
     if (!empty($options)) {
         $tableActions->appendChild(Widget::Apply($options));
         $this->Form->appendChild($tableActions);
     }
 }
 public function __form($readonly = false)
 {
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if ($formHasErrors) {
         $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR);
     }
     if (isset($this->_context[2])) {
         switch ($this->_context[2]) {
             case 'saved':
                 $this->pageAlert(__('Event updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/events/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Event created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/events/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS);
                 break;
         }
     }
     $isEditing = $readonly ? true : false;
     $fields = array();
     $sectionManager = new SectionManager($this->_Parent);
     if ($this->_context[0] == 'edit' || $this->_context[0] == 'info') {
         $isEditing = true;
         $handle = $this->_context[1];
         $EventManager = new EventManager($this->_Parent);
         $existing =& $EventManager->create($handle);
         $about = $existing->about();
         if ($this->_context[0] == 'edit' && !$existing->allowEditorToParse()) {
             redirect(SYMPHONY_URL . '/blueprints/events/info/' . $handle . '/');
         }
         $fields['name'] = $about['name'];
         $fields['source'] = $existing->getSource();
         $fields['filters'] = $existing->eParamFILTERS;
     }
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
     }
     $this->setPageType('form');
     $this->setTitle(__($isEditing ? '%1$s &ndash; %2$s &ndash; %3$s' : '%1$s &ndash; %2$s', array(__('Symphony'), __('Events'), $about['name'])));
     $this->appendSubheading($isEditing ? $about['name'] : __('Untitled'));
     if (!$readonly) {
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Essentials')));
         $group = new XMLElement('div');
         $group->setAttribute('class', 'group');
         $label = Widget::Label(__('Name'));
         $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name'])));
         $div = new XMLElement('div');
         if (isset($this->_errors['name'])) {
             $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name']));
         } else {
             $div->appendChild($label);
         }
         $group->appendChild($div);
         $label = Widget::Label(__('Source'));
         $sections = $sectionManager->fetch(NULL, 'ASC', 'name');
         $options = array();
         if (is_array($sections) && !empty($sections)) {
             foreach ($sections as $s) {
                 $options[] = array($s->get('id'), $fields['source'] == $s->get('id'), General::sanitize($s->get('name')));
             }
         }
         $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context')));
         $div = new XMLElement('div');
         if (isset($this->_errors['source'])) {
             $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['source']));
         } else {
             $div->appendChild($label);
         }
         $group->appendChild($div);
         $fieldset->appendChild($group);
         $label = Widget::Label(__('Filter Options'));
         $filters = is_array($fields['filters']) ? $fields['filters'] : array();
         $options = array(array('admin-only', in_array('admin-only', $filters), __('Admin Only')), array('send-email', in_array('send-email', $filters), __('Send Notification Email')), array('expect-multiple', in_array('expect-multiple', $filters), __('Allow Multiple')));
         /**
          * Allows adding of new filter rules to the Event filter rule select box
          *
          * @delegate AppendEventFilter
          * @param string $context
          * '/blueprints/events/(edit|new|info)/'
          * @param array $selected
          *  An array of all the selected filters for this Event
          * @param array $options
          *  An array of all the filters that are available, passed by reference
          */
         Symphony::ExtensionManager()->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'options' => &$options));
         $label->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple')));
         $fieldset->appendChild($label);
         $this->Form->appendChild($fieldset);
     }
     if ($readonly) {
         // Author
         if (isset($about['author']['website'])) {
             $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
         } else {
             if (isset($about['author']['email'])) {
                 $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
             } else {
                 $link = $about['author']['name'];
             }
         }
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Author')));
         $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
         $this->Form->appendChild($fieldset);
         // Version
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Version')));
         if (preg_match('/^\\d+(\\.\\d+)*$/', $about['version'])) {
             $fieldset->appendChild(new XMLElement('p', __('%s released on %s', array($about['version'], DateTimeObj::format($about['release-date'], __SYM_DATE_FORMAT__)))));
         } else {
             $fieldset->appendChild(new XMLElement('p', __('Created by %s at %s', array($about['version'], DateTimeObj::format($about['release-date'], __SYM_DATE_FORMAT__)))));
         }
         $this->Form->appendChild($fieldset);
     }
     if ($isEditing) {
         // Description
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $doc = $existing->documentation();
         $fieldset->setValue('<legend>' . __('Description') . '</legend>' . self::CRLF . General::tabsToSpaces(is_object($doc) ? $doc->generate(true) : $doc, 2));
         $this->Form->appendChild($fieldset);
     }
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Event'), 'submit', array('accesskey' => 's')));
     if ($isEditing) {
         $button = new XMLElement('button', __('Delete'));
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this event'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this event?')));
         $div->appendChild($button);
     }
     if (!$readonly) {
         $this->Form->appendChild($div);
     }
 }
 /**
  * This function contains the minimal amount of logic for generating the
  * index table of a given `$resource_type`. The table has name, source, pages
  * release date and author columns. The values for these columns are determined
  * by the resource's `about()` method.
  *
  * As Datasources types can be installed using Providers, the Source column
  * can be overridden with a Datasource's `getSourceColumn` method (if it exists).
  *
  * @param integer $resource_type
  *  Either `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DATASOURCE`
  */
 public function __viewIndex($resource_type)
 {
     $manager = ResourceManager::getManagerFromType($resource_type);
     $this->setPageType('table');
     Sortable::initialize($this, $resources, $sort, $order, array('type' => $resource_type));
     $columns = array(array('label' => __('Name'), 'sortable' => true, 'handle' => 'name'), array('label' => __('Source'), 'sortable' => true, 'handle' => 'source'), array('label' => __('Pages'), 'sortable' => false), array('label' => __('Release Date'), 'sortable' => true, 'handle' => 'release-date'), array('label' => __('Author'), 'sortable' => true, 'handle' => 'author'));
     $aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, isset($_REQUEST['filter']) ? '&amp;filter=' . $_REQUEST['filter'] : '');
     $aTableBody = array();
     if (!is_array($resources) || empty($resources)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd'));
     } else {
         foreach ($resources as $r) {
             // Resource name
             $action = isset($r['can_parse']) && $r['can_parse'] === true ? 'edit' : 'info';
             $name = Widget::TableData(Widget::Anchor($r['name'], SYMPHONY_URL . $_REQUEST['symphony-page'] . $action . '/' . $r['handle'] . '/', $r['handle']));
             // Resource type/source
             if (isset($r['source'], $r['source']['id'])) {
                 $section = Widget::TableData(Widget::Anchor($r['source']['name'], SYMPHONY_URL . '/blueprints/sections/edit/' . $r['source']['id'] . '/', $r['source']['handle']));
             } else {
                 if (isset($r['source']) && class_exists($r['source']['name']) && method_exists($r['source']['name'], 'getSourceColumn')) {
                     $class = call_user_func(array($manager, '__getClassName'), $r['handle']);
                     $section = Widget::TableData(call_user_func(array($class, 'getSourceColumn'), $r['handle']));
                 } else {
                     if (isset($r['source'], $r['source']['name'])) {
                         $section = Widget::TableData($r['source']['name']);
                     } else {
                         $section = Widget::TableData(__('Unknown'), 'inactive');
                     }
                 }
             }
             // Attached pages
             $pages = ResourceManager::getAttachedPages($resource_type, $r['handle']);
             $pagelinks = array();
             $i = 0;
             foreach ($pages as $p) {
                 ++$i;
                 $pagelinks[] = Widget::Anchor($p['title'], SYMPHONY_URL . '/blueprints/pages/edit/' . $p['id'] . '/')->generate() . (count($pages) > $i ? $i % 10 == 0 ? '<br />' : ', ' : '');
             }
             $pages = implode('', $pagelinks);
             if ($pages == '') {
                 $pagelinks = Widget::TableData(__('None'), 'inactive');
             } else {
                 $pagelinks = Widget::TableData($pages, 'pages');
             }
             // Release date
             $releasedate = Widget::TableData(Lang::localizeDate(DateTimeObj::format($r['release-date'], __SYM_DATETIME_FORMAT__)));
             // Authors
             $author = $r['author']['name'];
             if ($author) {
                 if (isset($r['author']['website'])) {
                     $author = Widget::Anchor($r['author']['name'], General::validateURL($r['author']['website']));
                 } else {
                     if (isset($r['author']['email'])) {
                         $author = Widget::Anchor($r['author']['name'], 'mailto:' . $r['author']['email']);
                     }
                 }
             }
             $author = Widget::TableData($author);
             $author->appendChild(Widget::Input('items[' . $r['handle'] . ']', null, 'checkbox'));
             $aTableBody[] = Widget::TableRow(array($name, $section, $pagelinks, $releasedate, $author));
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'selectable');
     $this->Form->appendChild($table);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete'), 'confirm'));
     $pages = $this->pagesFlatView();
     $group_attach = array('label' => __('Attach to Page'), 'options' => array());
     $group_detach = array('label' => __('Detach from Page'), 'options' => array());
     $group_attach['options'][] = array('attach-all-pages', false, __('All'));
     $group_detach['options'][] = array('detach-all-pages', false, __('All'));
     foreach ($pages as $p) {
         $group_attach['options'][] = array('attach-to-page-' . $p['id'], false, $p['title']);
         $group_detach['options'][] = array('detach-from-page-' . $p['id'], false, $p['title']);
     }
     $options[] = $group_attach;
     $options[] = $group_detach;
     /**
      * Allows an extension to modify the existing options for this page's
      * With Selected menu. If the `$options` parameter is an empty array,
      * the 'With Selected' menu will not be rendered.
      *
      * @delegate AddCustomActions
      * @since Symphony 2.3.2
      * @param string $context
      * '/blueprints/datasources/' or '/blueprints/events/'
      * @param array $options
      *  An array of arrays, where each child array represents an option
      *  in the With Selected menu. Options should follow the same format
      *  expected by `Widget::__SelectBuildOption`. Passed by reference.
      */
     Symphony::ExtensionManager()->notifyMembers('AddCustomActions', $_REQUEST['symphony-page'], array('options' => &$options));
     if (!empty($options)) {
         $tableActions->appendChild(Widget::Apply($options));
         $this->Form->appendChild($tableActions);
     }
 }
 public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle(__('%1$s &ndash; %2$s', array(__('Symphony'), __('Extensions'))));
     $this->appendSubheading(__('Extensions'));
     $this->Form->setAttribute('action', SYMPHONY_URL . '/system/extensions/');
     $extensions = Symphony::ExtensionManager()->listAll();
     ## Sort by extensions name:
     uasort($extensions, array('ExtensionManager', 'sortByName'));
     $aTableHead = array(array(__('Name'), 'col'), array(__('Installed Version'), 'col'), array(__('Enabled'), 'col'), array(__('Author'), 'col'));
     $aTableBody = array();
     if (!is_array($extensions) || empty($extensions)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd'));
     } else {
         foreach ($extensions as $name => $about) {
             $td1 = Widget::TableData(!empty($about['table-link']) && $about['status'] == EXTENSION_ENABLED ? Widget::Anchor($about['name'], Administration::instance()->getCurrentPageURL() . 'extension/' . trim($about['table-link'], '/') . '/') : $about['name']);
             $installed_version = Symphony::ExtensionManager()->fetchInstalledVersion($name);
             $td2 = Widget::TableData(is_null($installed_version) ? __('Not Installed') : $installed_version);
             if ($about['status'] == EXTENSION_ENABLED) {
                 $td3 = Widget::TableData(__('Yes'));
             } else {
                 if ($about['status'] == EXTENSION_DISABLED) {
                     $td3 = Widget::TableData(__('Disabled'));
                 } else {
                     if ($about['status'] == EXTENSION_NOT_INSTALLED) {
                         $td3 = Widget::TableData(__('Enable to install %s', array($about['version'])));
                     } else {
                         if ($about['status'] == EXTENSION_REQUIRES_UPDATE) {
                             $td3 = Widget::TableData(__('Enable to update to %s', array($about['version'])));
                         }
                     }
                 }
             }
             $td4 = Widget::TableData(NULL);
             if ($about['author'][0] && is_array($about['author'][0])) {
                 $authors = '';
                 foreach ($about['author'] as $i => $author) {
                     if (isset($author['website'])) {
                         $link = Widget::Anchor($author['name'], General::validateURL($author['website']));
                     } else {
                         if (isset($author['email'])) {
                             $link = Widget::Anchor($author['name'], 'mailto:' . $author['email']);
                         } else {
                             $link = $author['name'];
                         }
                     }
                     $authors .= ($link instanceof XMLElement ? $link->generate() : $link) . ($i != count($about['author']) - 1 ? ", " : "");
                 }
                 $td4->setValue($authors);
             } else {
                 if (isset($about['author']['website'])) {
                     $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
                 } else {
                     if (isset($about['author']['email'])) {
                         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
                     } else {
                         $link = $about['author']['name'];
                     }
                 }
                 $td4->setValue($link instanceof XMLElement ? $link->generate() : $link);
             }
             $td4->appendChild(Widget::Input('items[' . $name . ']', 'on', 'checkbox'));
             ## Add a row to the body array, assigning each cell to the row
             $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4), $about['status'] == EXTENSION_NOT_INSTALLED ? 'inactive' : NULL);
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'selectable');
     $this->Form->appendChild($table);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(NULL, false, __('With Selected...')), array('enable', false, __('Enable')), array('disable', false, __('Disable')), array('uninstall', false, __('Uninstall'), 'confirm', null, array('data-message' => __('Are you sure you want to uninstall the selected extensions?'))));
     $tableActions->appendChild(Widget::Select('with-selected', $options));
     $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit'));
     $this->Form->appendChild($tableActions);
 }
Exemplo n.º 19
0
 public function __form($readonly = false)
 {
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if ($formHasErrors) {
         $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR);
         // These alerts are only valid if the form doesn't have errors
     } elseif (isset($this->_context[2])) {
         $time = Widget::Time();
         switch ($this->_context[2]) {
             case 'saved':
                 $this->pageAlert(__('Event updated at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Event created at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS);
                 break;
         }
     }
     $isEditing = $readonly ? true : false;
     $fields = array("name" => null, "filters" => null);
     $about = array("name" => null);
     $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::EVENT);
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
         if ($this->_context[0] == 'edit') {
             $isEditing = true;
         }
     } elseif ($this->_context[0] == 'edit' || $this->_context[0] == 'info') {
         $isEditing = true;
         $handle = $this->_context[1];
         $existing = EventManager::create($handle);
         $about = $existing->about();
         if ($this->_context[0] == 'edit' && !$existing->allowEditorToParse()) {
             redirect(SYMPHONY_URL . '/blueprints/events/info/' . $handle . '/');
         }
         $fields['name'] = $about['name'];
         $fields['source'] = $existing->getSource();
         $provided = false;
         if (!empty($providers)) {
             foreach ($providers as $providerClass => $provider) {
                 if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) {
                     $fields = array_merge($fields, $existing->settings());
                     $provided = true;
                     break;
                 }
             }
         }
         if (!$provided) {
             if (isset($existing->eParamFILTERS)) {
                 $fields['filters'] = $existing->eParamFILTERS;
             }
         }
     }
     // Handle name on edited changes, or from reading an edited datasource
     if (isset($about['name'])) {
         $name = $about['name'];
     } elseif (isset($fields['name'])) {
         $name = $fields['name'];
     }
     $this->setPageType('form');
     $this->setTitle(__($isEditing ? '%1$s &ndash; %2$s &ndash; %3$s' : '%2$s &ndash; %3$s', array($about['name'], __('Events'), __('Symphony'))));
     $this->appendSubheading($isEditing ? $about['name'] : __('Untitled'));
     $this->insertBreadcrumbs(array(Widget::Anchor(__('Events'), SYMPHONY_URL . '/blueprints/events/')));
     if (!$readonly) {
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Essentials')));
         // Target
         $sources = new XMLElement('div', null, array('class' => 'apply actions'));
         $div = new XMLElement('div');
         $label = Widget::Label(__('Target'), null, 'apply-label-left');
         $sources->appendChild($label);
         $sources->appendChild($div);
         $sections = SectionManager::fetch(null, 'ASC', 'name');
         $options = array();
         $section_options = array();
         $source = isset($fields['source']) ? $fields['source'] : null;
         if (is_array($sections) && !empty($sections)) {
             $section_options = array('label' => __('Sections'), 'options' => array());
             foreach ($sections as $s) {
                 $section_options['options'][] = array($s->get('id'), $source == $s->get('id'), General::sanitize($s->get('name')));
             }
         }
         $options[] = $section_options;
         // Loop over the event providers
         if (!empty($providers)) {
             $p = array('label' => __('From extensions'), 'options' => array());
             foreach ($providers as $providerClass => $provider) {
                 $p['options'][] = array($providerClass, $fields['source'] == $providerClass, $provider);
             }
             $options[] = $p;
         }
         $div->appendChild(Widget::Select('source', $options, array('id' => 'event-context')));
         if (isset($this->_errors['source'])) {
             $this->Context->prependChild(Widget::Error($sources, $this->_errors['source']));
         } else {
             $this->Context->prependChild($sources);
         }
         $this->Form->appendChild(Widget::Input('fields[source]', $options[0]['options'][0][0], 'hidden', array('id' => 'event-source')));
         // Name
         $group = new XMLElement('div');
         $label = Widget::Label(__('Name'));
         $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name'])));
         $div = new XMLElement('div');
         $div->setAttribute('class', 'column');
         if (isset($this->_errors['name'])) {
             $div->appendChild(Widget::Error($label, $this->_errors['name']));
         } else {
             $div->appendChild($label);
         }
         $group->appendChild($div);
         $fieldset->appendChild($group);
         $this->Form->appendChild($fieldset);
         // Filters
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings pickable');
         $fieldset->appendChild(new XMLElement('legend', __('Filters')));
         $p = new XMLElement('p', __('Event Filters add additional conditions or actions to an event.'));
         $p->setAttribute('class', 'help');
         $fieldset->appendChild($p);
         $filters = isset($fields['filters']) ? $fields['filters'] : array();
         $options = array(array('admin-only', in_array('admin-only', $filters), __('Admin Only')), array('send-email', in_array('send-email', $filters), __('Send Notification Email')), array('expect-multiple', in_array('expect-multiple', $filters), __('Allow Multiple')));
         /**
          * Allows adding of new filter rules to the Event filter rule select box
          *
          * @delegate AppendEventFilter
          * @param string $context
          * '/blueprints/events/(edit|new|info)/'
          * @param array $selected
          *  An array of all the selected filters for this Event
          * @param array $options
          *  An array of all the filters that are available, passed by reference
          */
         Symphony::ExtensionManager()->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'options' => &$options));
         $fieldset->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple', 'id' => 'event-filters')));
         $this->Form->appendChild($fieldset);
         // Connections
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Attach to Pages')));
         $p = new XMLElement('p', __('The event will only be available on the selected pages.'));
         $p->setAttribute('class', 'help');
         $fieldset->appendChild($p);
         $div = new XMLElement('div');
         $label = Widget::Label(__('Pages'));
         $pages = PageManager::fetch();
         $event_handle = str_replace('-', '_', Lang::createHandle($fields['name']));
         $connections = ResourceManager::getAttachedPages(RESOURCE_TYPE_EVENT, $event_handle);
         $selected = array();
         foreach ($connections as $connection) {
             $selected[] = $connection['id'];
         }
         $options = array();
         foreach ($pages as $page) {
             $options[] = array($page['id'], in_array($page['id'], $selected), PageManager::resolvePageTitle($page['id']));
         }
         $label->appendChild(Widget::Select('fields[connections][]', $options, array('multiple' => 'multiple')));
         $div->appendChild($label);
         $fieldset->appendChild($div);
         $this->Form->appendChild($fieldset);
         // Providers
         if (!empty($providers)) {
             foreach ($providers as $providerClass => $provider) {
                 if ($isEditing && $fields['source'] !== call_user_func(array($providerClass, 'getSource'))) {
                     continue;
                 }
                 call_user_func_array(array($providerClass, 'buildEditor'), array($this->Form, &$this->_errors, $fields, $handle));
             }
         }
     } else {
         // Author
         if (isset($about['author']['website'])) {
             $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
         } elseif (isset($about['author']['email'])) {
             $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
         } else {
             $link = $about['author']['name'];
         }
         if ($link) {
             $fieldset = new XMLElement('fieldset');
             $fieldset->setAttribute('class', 'settings');
             $fieldset->appendChild(new XMLElement('legend', __('Author')));
             $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
             $this->Form->appendChild($fieldset);
         }
         // Version
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Version')));
         $version = array_key_exists('version', $about) ? $about['version'] : null;
         $release_date = array_key_exists('release-date', $about) ? $about['release-date'] : filemtime(EventManager::__getDriverPath($handle));
         if (preg_match('/^\\d+(\\.\\d+)*$/', $version)) {
             $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__)))));
         } elseif (!is_null($version)) {
             $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__)))));
         } else {
             $fieldset->appendChild(new XMLElement('p', __('Last modified on %s', array(DateTimeObj::format($release_date, __SYM_DATE_FORMAT__)))));
         }
         $this->Form->appendChild($fieldset);
     }
     // If we are editing an event, it assumed that the event has documentation
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('id', 'event-documentation');
     $fieldset->setAttribute('class', 'settings');
     if ($isEditing && method_exists($existing, 'documentation')) {
         $doc = $existing->documentation();
         if ($doc) {
             $fieldset->setValue('<legend>' . __('Documentation') . '</legend>' . PHP_EOL . General::tabsToSpaces(is_object($doc) ? $doc->generate(true, 4) : $doc));
         }
     }
     $this->Form->appendChild($fieldset);
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Event'), 'submit', array('accesskey' => 's')));
     if ($isEditing) {
         $button = new XMLElement('button', __('Delete'));
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this event'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this event?')));
         $div->appendChild($button);
     }
     if (!$readonly) {
         $this->Form->appendChild($div);
     }
 }
Exemplo n.º 20
0
 function trigger()
 {
     $result = new XMLElement("post-comment");
     $comment = array();
     $comment['author_name'] = $_POST['name'];
     $comment['author_url'] = $_POST['website'];
     $comment['author_email'] = $_POST['email'];
     $comment['body'] = $_POST['comment'];
     $comment['entry_handle'] = $_POST['entry-handle'];
     $comment['section'] = $_POST['section'];
     $comment = array_map("stripslashes", $comment);
     ## Create the cookie elements
     $cookie = new XMLElement("cookie");
     $cookie->addChild(new XMLElement("name", General::sanitize($comment['author_name'])));
     $cookie->addChild(new XMLElement("email", General::sanitize($comment['author_email'])));
     $cookie->addChild(new XMLElement("url", General::validateURL($comment['author_url'])));
     $cookie->addChild(new XMLElement("comment", General::sanitize($comment['body'])));
     $result->addChild($cookie);
     $canProceed = true;
     if ($comment['author_name'] == "" || $comment['author_email'] == "" || $comment['body'] == "") {
         $xMissing = new XMLElement("missing");
         if ($comment['author_name'] == "") {
             $missing = new XMLElement("input");
             $missing->setAttribute("name", "name");
             $xMissing->addChild($missing);
         }
         if ($comment['author_email'] == "") {
             $missing = new XMLElement("input");
             $missing->setAttribute("name", "email");
             $xMissing->addChild($missing);
         }
         if ($comment['body'] == "") {
             $missing = new XMLElement("input");
             $missing->setAttribute("name", "comment");
             $xMissing->addChild($missing);
         }
         $result->addChild($xMissing);
         $canProceed = false;
     }
     if ($comment['author_email'] != "" && !ereg('^[a-zA-Z0-9_\\.\\-]+@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.]+$', $comment['author_email'])) {
         $invalid = new XMLElement("invalid");
         $xInvalid = new XMLElement("input");
         $xInvalid->setAttribute("name", "email");
         $invalid->addChild($xInvalid);
         $result->addChild($invalid);
         $canProceed = false;
     }
     if (!$canProceed) {
         $result->setAttribute("sent", "false");
     } else {
         require_once TOOLKIT . "/class.commenting.php";
         $oCommenting = new Commenting(array("parent" => $this->_parent));
         ## By default 'body', 'author_name' and 'author_ip' are required, but we
         ## want an email ('author_email') address as well.
         $oCommenting->setRequiredField('author_email');
         #if(is_array($oCommenting->_notices) && !empty($oCommenting->_notices)){
         if (!$oCommenting->insertComment($comment)) {
             $result->addChild(new XMLElement("notice", $oCommenting->_notices[0]));
             $result->setAttribute("sent", "false");
         } else {
             $result->setAttribute("sent", "true");
             $result->addChild(new XMLElement("notice", "Comment saved successfully"));
         }
         if ($oCommenting->isLastCommentSpam) {
             $result->setAttribute("spam", "true");
         }
         $prefix = $this->_parent->getConfigVar('cookie_prefix', 'symphony');
         if ($_POST['remember'] == 'on') {
             setcookie($prefix . 'comment-remember[name]', $comment['author_name'], time() + TWO_WEEKS, $this->_parent->getCookieDomain());
             setcookie($prefix . 'comment-remember[url]', $comment['author_url'], time() + TWO_WEEKS, $this->_parent->getCookieDomain());
             setcookie($prefix . 'comment-remember[email]', $comment['author_email'], time() + TWO_WEEKS, $this->_parent->getCookieDomain());
         } else {
             setcookie($prefix . 'comment-remember', ' ', time() - TWO_WEEKS, $this->_parent->getCookieDomain());
         }
     }
     return $result;
 }
Exemplo n.º 21
0
 /**
  * This function contains the minimal amount of logic for generating the
  * index table of a given `$resource_type`. The table has name, source, pages
  * release date and author columns. The values for these columns are determined
  * by the resource's `about()` method.
  *
  * As Datasources types can be installed using Providers, the Source column
  * can be overridden with a Datasource's `getSourceColumn` method (if it exists).
  *
  * @param integer $resource_type
  *  Either `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DATASOURCE`
  * @throws InvalidArgumentException
  */
 public function __viewIndex($resource_type)
 {
     $manager = ResourceManager::getManagerFromType($resource_type);
     $friendly_resource = $resource_type === RESOURCE_TYPE_EVENT ? __('Event') : __('DataSource');
     $this->setPageType('table');
     Sortable::initialize($this, $resources, $sort, $order, array('type' => $resource_type));
     $columns = array(array('label' => __('Name'), 'sortable' => true, 'handle' => 'name'), array('label' => __('Source'), 'sortable' => true, 'handle' => 'source'), array('label' => __('Pages'), 'sortable' => false), array('label' => __('Author'), 'sortable' => true, 'handle' => 'author'));
     $aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, isset($_REQUEST['filter']) ? '&amp;filter=' . $_REQUEST['filter'] : '');
     $aTableBody = array();
     if (!is_array($resources) || empty($resources)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead))), 'odd'));
     } else {
         $context = Administration::instance()->getPageCallback();
         foreach ($resources as $r) {
             $action = 'edit';
             $status = null;
             $locked = null;
             // Locked resources
             if (isset($r['can_parse']) && $r['can_parse'] !== true) {
                 $action = 'info';
                 $status = 'status-notice';
                 $locked = array('data-status' => ' — ' . __('read only'));
             }
             // Resource name
             $action = isset($r['can_parse']) && $r['can_parse'] === true ? 'edit' : 'info';
             $name = Widget::TableData(Widget::Anchor($r['name'], SYMPHONY_URL . $context['pageroot'] . $action . '/' . $r['handle'] . '/', $r['handle'], 'resource-' . $action, null, $locked));
             $name->appendChild(Widget::Label(__('Select ' . $friendly_resource . ' %s', array($r['name'])), null, 'accessible', null, array('for' => 'resource-' . $r['handle'])));
             $name->appendChild(Widget::Input('items[' . $r['handle'] . ']', 'on', 'checkbox', array('id' => 'resource-' . $r['handle'])));
             // Resource type/source
             if (isset($r['source'], $r['source']['id'])) {
                 $section = Widget::TableData(Widget::Anchor($r['source']['name'], SYMPHONY_URL . '/blueprints/sections/edit/' . $r['source']['id'] . '/', $r['source']['handle']));
             } elseif (isset($r['source']) && class_exists($r['source']['name']) && method_exists($r['source']['name'], 'getSourceColumn')) {
                 $class = call_user_func(array($manager, '__getClassName'), $r['handle']);
                 $section = Widget::TableData(call_user_func(array($class, 'getSourceColumn'), $r['handle']));
             } elseif (isset($r['source'], $r['source']['name'])) {
                 $section = Widget::TableData($r['source']['name']);
             } else {
                 $section = Widget::TableData(__('Unknown'), 'inactive');
             }
             // Attached pages
             $pages = ResourceManager::getAttachedPages($resource_type, $r['handle']);
             $pagelinks = array();
             $i = 0;
             foreach ($pages as $p) {
                 ++$i;
                 $pagelinks[] = Widget::Anchor($p['title'], SYMPHONY_URL . '/blueprints/pages/edit/' . $p['id'] . '/')->generate() . (count($pages) > $i ? $i % 10 == 0 ? '<br />' : ', ' : '');
             }
             $pages = implode('', $pagelinks);
             if ($pages == '') {
                 $pagelinks = Widget::TableData(__('None'), 'inactive');
             } else {
                 $pagelinks = Widget::TableData($pages, 'pages');
             }
             // Authors
             $author = $r['author']['name'];
             if ($author) {
                 if (isset($r['author']['website'])) {
                     $author = Widget::Anchor($r['author']['name'], General::validateURL($r['author']['website']));
                 } elseif (isset($r['author']['email'])) {
                     $author = Widget::Anchor($r['author']['name'], 'mailto:' . $r['author']['email']);
                 }
             }
             $author = Widget::TableData($author);
             $aTableBody[] = Widget::TableRow(array($name, $section, $pagelinks, $author), $status);
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), null, Widget::TableBody($aTableBody), 'selectable', null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive'));
     $this->Form->appendChild($table);
     $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array('id' => 'version'));
     $this->Form->appendChild($version);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(null, false, __('With Selected...')), array('delete', false, __('Delete'), 'confirm'));
     $pages = $this->pagesFlatView();
     $group_attach = array('label' => __('Attach to Page'), 'options' => array());
     $group_detach = array('label' => __('Detach from Page'), 'options' => array());
     $group_attach['options'][] = array('attach-all-pages', false, __('All'));
     $group_detach['options'][] = array('detach-all-pages', false, __('All'));
     foreach ($pages as $p) {
         $group_attach['options'][] = array('attach-to-page-' . $p['id'], false, $p['title']);
         $group_detach['options'][] = array('detach-from-page-' . $p['id'], false, $p['title']);
     }
     $options[] = $group_attach;
     $options[] = $group_detach;
     /**
      * Allows an extension to modify the existing options for this page's
      * With Selected menu. If the `$options` parameter is an empty array,
      * the 'With Selected' menu will not be rendered.
      *
      * @delegate AddCustomActions
      * @since Symphony 2.3.2
      * @param string $context
      * '/blueprints/datasources/' or '/blueprints/events/'
      * @param array $options
      *  An array of arrays, where each child array represents an option
      *  in the With Selected menu. Options should follow the same format
      *  expected by `Widget::__SelectBuildOption`. Passed by reference.
      */
     Symphony::ExtensionManager()->notifyMembers('AddCustomActions', $context['pageroot'], array('options' => &$options));
     if (!empty($options)) {
         $tableActions->appendChild(Widget::Apply($options));
         $this->Form->appendChild($tableActions);
     }
 }
 public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle('Symphony &ndash; Formatters');
     $this->appendSubheading('Formatters', Widget::Anchor('Create New', "{$this->_uri}/formatters/new/", 'Create a new formatter', 'create button'));
     $tableHead = array();
     $tableBody = array();
     // Columns, with sorting:
     foreach ($this->_table_columns as $column => $values) {
         if ($values[1]) {
             if ($column == $this->_table_column) {
                 if ($this->_table_direction == 'desc') {
                     $direction = 'asc';
                     $label = 'ascending';
                 } else {
                     $direction = 'desc';
                     $label = 'descending';
                 }
             } else {
                 $direction = 'asc';
                 $label = 'ascending';
             }
             $link = $this->generateLink(array('sort' => $column, 'order' => $direction));
             $anchor = Widget::Anchor($values[0], $link, __("Sort by {$label} " . strtolower($values[0])));
             if ($column == $this->_table_column) {
                 $anchor->setAttribute('class', 'active');
             }
             $tableHead[] = array($anchor, 'col');
         } else {
             $tableHead[] = array($values[0], 'col');
         }
     }
     if (!is_array($this->_formatters) or empty($this->_formatters)) {
         $tableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', null, count($tableHead)))));
     } else {
         foreach ($this->_formatters as $formatter) {
             $formatter = (object) $formatter;
             $col_name = Widget::TableData(Widget::Anchor($formatter->name, "{$this->_uri}/formatters/edit/{$formatter->handle}/"));
             $col_name->appendChild(Widget::Input("items[{$formatter->handle}]", null, 'checkbox'));
             $col_date = Widget::TableData(DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($formatter->{'html-formatter-updated'})));
             if (!empty($formatter->description)) {
                 $col_description = Widget::TableData(General::sanitize($formatter->description));
             } else {
                 $col_description = Widget::TableData('None', 'inactive');
             }
             if (isset($formatter->author['website'])) {
                 $col_author = Widget::TableData(Widget::Anchor($formatter->author['name'], General::validateURL($formatter->author['website'])));
             } else {
                 if (isset($formatter->author['email'])) {
                     $col_author = Widget::TableData(Widget::Anchor($formatter->author['name'], 'mailto:' . $formatter->author['email']));
                 } else {
                     $col_author = Widget::TableData($formatter->author['name']);
                 }
             }
             $tableBody[] = Widget::TableRow(array($col_name, $col_description, $col_date, $col_author), null);
         }
     }
     $table = Widget::Table(Widget::TableHead($tableHead), null, Widget::TableBody($tableBody));
     $this->Form->appendChild($table);
     $actions = new XMLElement('div');
     $actions->setAttribute('class', 'actions');
     $options = array(array(null, false, 'With Selected...'), array('delete', false, 'Delete'));
     $actions->appendChild(Widget::Select('with-selected', $options));
     $actions->appendChild(Widget::Input('action[apply]', 'Apply', 'submit'));
     $this->Form->appendChild($actions);
     // Pagination:
     if ($this->_pagination->pages > 1) {
         $ul = new XMLElement('ul');
         $ul->setAttribute('class', 'page');
         // First:
         $li = new XMLElement('li');
         $li->setValue(__('First'));
         if ($this->_pagination->page > 1) {
             $li->setValue(Widget::Anchor(__('First'), $this->generateLink(array('pg' => 1)))->generate());
         }
         $ul->appendChild($li);
         // Previous:
         $li = new XMLElement('li');
         $li->setValue(__('&larr; Previous'));
         if ($this->_pagination->page > 1) {
             $li->setValue(Widget::Anchor(__('&larr; Previous'), $this->generateLink(array('pg' => $this->_pagination->page - 1)))->generate());
         }
         $ul->appendChild($li);
         // Summary:
         $li = new XMLElement('li', __('Page %s of %s', array($this->_pagination->page, max($this->_pagination->page, $this->_pagination->pages))));
         $li->setAttribute('title', __('Viewing %s - %s of %s entries', array($this->_pagination->start, $this->_pagination->end, $this->_pagination->total)));
         $ul->appendChild($li);
         // Next:
         $li = new XMLElement('li');
         $li->setValue(__('Next &rarr;'));
         if ($this->_pagination->page < $this->_pagination->pages) {
             $li->setValue(Widget::Anchor(__('Next &rarr;'), $this->generateLink(array('pg' => $this->_pagination->page + 1)))->generate());
         }
         $ul->appendChild($li);
         // Last:
         $li = new XMLElement('li');
         $li->setValue(__('Last'));
         if ($this->_pagination->page < $this->_pagination->pages) {
             $li->setValue(Widget::Anchor(__('Last'), $this->generateLink(array('pg' => $this->_pagination->pages)))->generate());
         }
         $ul->appendChild($li);
         $this->Form->appendChild($ul);
     }
 }