/** * This function is called from the resources index when a user uses the * With Selected, or Apply, menu. The type of resource is given by * `$resource_type`. At this time the only two valid values, * `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DATASOURCE`. * * The function handles 'delete', 'attach', 'detach', 'attach all', * 'detach all' actions. * * @param integer $resource_type * Either `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DATASOURCE` * @throws Exception */ public function __actionIndex($resource_type) { $manager = ResourceManager::getManagerFromType($resource_type); $checked = is_array($_POST['items']) ? array_keys($_POST['items']) : null; $context = Administration::instance()->getPageCallback(); if (isset($_POST['action']) && is_array($_POST['action'])) { /** * Extensions can listen for any custom actions that were added * through `AddCustomPreferenceFieldsets` or `AddCustomActions` * delegates. * * @delegate CustomActions * @since Symphony 2.3.2 * @param string $context * '/blueprints/datasources/' or '/blueprints/events/' * @param array $checked * An array of the selected rows. The value is usually the ID of the * the associated object. */ Symphony::ExtensionManager()->notifyMembers('CustomActions', $context['pageroot'], array('checked' => $checked)); if (is_array($checked) && !empty($checked)) { if ($_POST['with-selected'] == 'delete') { $canProceed = true; foreach ($checked as $handle) { $path = call_user_func(array($manager, '__getDriverPath'), $handle); // Don't allow Extension resources to be deleted. RE: #2027 if (stripos($path, EXTENSIONS) === 0) { continue; } elseif (!General::deleteFile($path)) { $folder = str_replace(DOCROOT, '', $path); $folder = str_replace('/' . basename($path), '', $folder); $this->pageAlert(__('Failed to delete %s.', array('<code>' . basename($path) . '</code>')) . ' ' . __('Please check permissions on %s', array('<code>' . $folder . '</code>')), Alert::ERROR); $canProceed = false; } else { $pages = ResourceManager::getAttachedPages($resource_type, $handle); foreach ($pages as $page) { ResourceManager::detach($resource_type, $handle, $page['id']); } } } if ($canProceed) { redirect(Administration::instance()->getCurrentPageURL()); } } elseif (preg_match('/^(at|de)?tach-(to|from)-page-/', $_POST['with-selected'])) { if (substr($_POST['with-selected'], 0, 6) == 'detach') { $page = str_replace('detach-from-page-', '', $_POST['with-selected']); foreach ($checked as $handle) { ResourceManager::detach($resource_type, $handle, $page); } } else { $page = str_replace('attach-to-page-', '', $_POST['with-selected']); foreach ($checked as $handle) { ResourceManager::attach($resource_type, $handle, $page); } } if ($canProceed) { redirect(Administration::instance()->getCurrentPageURL()); } } elseif (preg_match('/^(at|de)?tach-all-pages$/', $_POST['with-selected'])) { $pages = PageManager::fetch(false, array('id')); if (substr($_POST['with-selected'], 0, 6) == 'detach') { foreach ($checked as $handle) { foreach ($pages as $page) { ResourceManager::detach($resource_type, $handle, $page['id']); } } } else { foreach ($checked as $handle) { foreach ($pages as $page) { ResourceManager::attach($resource_type, $handle, $page['id']); } } } redirect(Administration::instance()->getCurrentPageURL()); } } } }
public function __actionEdit() { if (array_key_exists('save', $_POST['action'])) { return $this->__formAction(); } elseif (array_key_exists('delete', $_POST['action'])) { /** * Prior to deleting the Event file. Target file path is provided. * * @delegate EventPreDelete * @since Symphony 2.2 * @param string $context * '/blueprints/events/' * @param string $file * The path to the Event file */ Symphony::ExtensionManager()->notifyMembers('EventPreDelete', '/blueprints/events/', array('file' => EVENTS . "/event." . $this->_context[1] . ".php")); if (!General::deleteFile(EVENTS . '/event.' . $this->_context[1] . '.php')) { $this->pageAlert(__('Failed to delete %s.', array('<code>' . $this->_context[1] . '</code>')) . ' ' . __('Please check permissions on %s.', array('<code>/workspace/events</code>')), Alert::ERROR); } else { $pages = ResourceManager::getAttachedPages(RESOURCE_TYPE_EVENT, $this->_context[1]); foreach ($pages as $page) { ResourceManager::detach(RESOURCE_TYPE_EVENT, $this->_context[1], $page['id']); } redirect(SYMPHONY_URL . '/blueprints/events/'); } } }
/** * 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']) ? '&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); }
/** * Given a resource type, a handle and an array of pages, this function will * ensure that the resource is attached to the given pages. Note that this * function will also remove the resource from all pages that are not provided * in the `$pages` parameter. * * @since Symphony 2.4 * @param integer $type * The resource type, either `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DS` * @param string $r_handle * The handle of the resource. * @param array $pages * An array of Page ID's to attach this resource to. * @return boolean */ public static function setPages($type, $r_handle, $pages = array()) { if (!is_array($pages)) { $pages = array(); } // Get attached pages $attached_pages = ResourceManager::getAttachedPages($type, $r_handle); $currently_attached_pages = array(); foreach ($attached_pages as $page) { $currently_attached_pages[] = $page['id']; } // Attach this datasource to any page that is should be attached to $diff_to_attach = array_diff($pages, $currently_attached_pages); foreach ($diff_to_attach as $diff_page) { ResourceManager::attach($type, $r_handle, $diff_page); } // Remove this datasource from any page where it once was, but shouldn't be anymore $diff_to_detach = array_diff($currently_attached_pages, $pages); foreach ($diff_to_detach as $diff_page) { ResourceManager::detach($type, $r_handle, $diff_page); } return true; }
/** * This function is called from the resources index when a user uses the * With Selected, or Apply, menu. The type of resource is given by * `$resource_type`. At this time the only two valid values, * `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DATASOURCE`. * * The function handles 'delete', 'attach', 'detach', 'attach all', * 'detach all' actions. * * @param integer $resource_type * Either `RESOURCE_TYPE_EVENT` or `RESOURCE_TYPE_DATASOURCE` */ public function __actionIndex($resource_type) { $manager = ResourceManager::getManagerFromType($resource_type); if (isset($_POST['action']) && is_array($_POST['action'])) { $checked = $_POST['items'] ? @array_keys($_POST['items']) : NULL; if (is_array($checked) && !empty($checked)) { if ($_POST['with-selected'] == 'delete') { $canProceed = true; foreach ($checked as $handle) { $path = call_user_func(array($manager, '__getDriverPath'), $handle); if (!General::deleteFile($path)) { $folder = str_replace(DOCROOT, '', $path); $folder = str_replace('/' . basename($path), '', $folder); $this->pageAlert(__('Failed to delete %s.', array('<code>' . basename($path) . '</code>')) . ' ' . __('Please check permissions on %s', array('<code>' . $folder . '</code>')), Alert::ERROR); $canProceed = false; } else { $pages = ResourceManager::getAttachedPages($resource_type, $handle); foreach ($pages as $page) { ResourceManager::detach($resource_type, $handle, $page['id']); } } } if ($canProceed) { redirect(Administration::instance()->getCurrentPageURL()); } } else { if (preg_match('/^(at|de)?tach-(to|from)-page-/', $_POST['with-selected'])) { if (substr($_POST['with-selected'], 0, 6) == 'detach') { $page = str_replace('detach-from-page-', '', $_POST['with-selected']); foreach ($checked as $handle) { ResourceManager::detach($resource_type, $handle, $page); } } else { $page = str_replace('attach-to-page-', '', $_POST['with-selected']); foreach ($checked as $handle) { ResourceManager::attach($resource_type, $handle, $page); } } if ($canProceed) { redirect(Administration::instance()->getCurrentPageURL()); } } else { if (preg_match('/^(at|de)?tach-all-pages$/', $_POST['with-selected'])) { $pages = PageManager::fetch(false, array('id')); if (substr($_POST['with-selected'], 0, 6) == 'detach') { foreach ($checked as $handle) { foreach ($pages as $page) { ResourceManager::detach($resource_type, $handle, $page['id']); } } } else { foreach ($checked as $handle) { foreach ($pages as $page) { ResourceManager::attach($resource_type, $handle, $page['id']); } } } redirect(Administration::instance()->getCurrentPageURL()); } } } } } }