Index: page_title.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/page_title/page_title.module,v retrieving revision 1.18.2.2 diff -u -p -r1.18.2.2 page_title.module --- page_title.module 25 Sep 2008 15:48:03 -0000 1.18.2.2 +++ page_title.module 25 Sep 2008 22:37:08 -0000 @@ -79,6 +79,23 @@ function page_title_menu() { 'access arguments' => array('administer page titles'), 'type' => MENU_LOCAL_TASK, ); + $items['admin/content/page_title/url'] = array( + 'title' => 'Per URL Settings', + 'description' => 'Control the display of the Page title based on a per-URL basis.', + 'page callback' => 'page_title_admin_url', + 'access callback' => 'user_access', + 'access arguments' => array('administer page titles'), + 'type' => MENU_LOCAL_TASK, + ); + $items['admin/content/page_title/url/delete'] = array( + 'title' => 'Confirm Delete', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('page_title_admin_url_delete'), + 'access callback' => 'user_access', + 'access arguments' => array('administer page titles'), + 'type' => MENU_CALLBACK, + ); + return $items; } @@ -157,6 +174,159 @@ function page_title_admin_types() { } +function page_title_admin_url($id = NULL) { + $settings = variable_get('page_title_url', array()); + + if (!is_null($id)) { + if (!isset($settings[$id])) { + echo drupal_not_found(); + exit; + } + } + + $rows = array(); + foreach ($settings as $key => $conf) { + $ops = l(t('edit'), 'admin/content/page_title/url/'. $key) .' | '; + $ops .= l(t('delete'), 'admin/content/page_title/url/delete/'. $key); + + $rows[] = array( + check_plain($conf['path']), + check_plain($conf['pattern']), + check_plain($conf['scope']), + $ops + ); + } + $headers = array( + t('Path'), + t('Page Title Pattern'), + t('Scope'), + t('Actions'), + ); + + $output = theme('table', $headers, $rows); + + $output .= drupal_get_form('page_title_admin_url_form', $id); + + return $output; +} + + +function page_title_admin_url_form($form_state, $id = NULL) { + $form = array(); + + $settings = variable_get('page_title_url', array()); + + $form['page_title_url'] = array( + '#type' => 'fieldset', + '#title' => isset($id) ? t('Edit Path Pattern') : t('Add Path Pattern'), + '#tree' => TRUE, + '#collapsible' => !isset($id), + '#collapsed' => !isset($id), + ); + + $form['page_title_url']['path'] = array( + '#type' => 'textfield', + '#title' => t('Path'), + '#description' => t('Enter the source path you want to path page title patterns to, for example taxonomy/term/%'), + '#size' => 20, + '#maxlength' => 100, + '#required' => TRUE, + '#default_value' => isset($settings[$id]['path']) ? $settings[$id]['path'] : '', + ); + + $form['page_title_url']['pattern'] = array( + '#type' => 'textfield', + '#title' => t('Pattern'), + '#description' => t('Enter the token pattern you would like to use for this path, for example Category: [term]'), + '#size' => 30, + '#maxlength' => 100, + '#required' => TRUE, + '#default_value' => isset($settings[$id]['pattern']) ? $settings[$id]['pattern'] : '', + ); + + $tokens = token_get_list(); + $scopes = array_flip(array_keys($tokens)); + + foreach ($scopes as $k => $v) { + $scopes[$k] = ucwords($k); + } + + $form['page_title_url']['scope'] = array( + '#type' => 'select', + '#title' => t('Scope'), + '#description' => t('Select the Scope of the pattern. This defines which tokens are available, for example in Comment scope there are no user tokens; only comment and global would be available.'), + '#options' => $scopes, + '#default_value' => isset($settings[$id]['scope']) ? $settings[$id]['scope'] : 'global', + ); + + if (isset($id)) { + $form['page_title_url']['actions'] = array('#prefix' => '
', '#suffix' => '
'); + + $form['page_title_url']['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save Changes'), + ); + + $form['page_title_url']['actions']['cancel'] = array( + '#value' => l(t('Cancel Edit'), 'admin/content/page_title/url'), + ); + + $form['page_title_url']['id'] = array( + '#type' => 'value', + '#value' => $id, + ); + } + else { + $form['page_title_url']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save New Path'), + ); + } + + return $form; +} + + + +function page_title_admin_url_form_submit($form, &$form_state) { + $settings = variable_get('page_title_url', array()); + + if ($form_state['values']['page_title_url']['id']) { + $settings[$form_state['values']['page_title_url']['id']] = array( + 'path' => $form_state['values']['page_title_url']['path'], + 'pattern' => $form_state['values']['page_title_url']['pattern'], + 'scope' => $form_state['values']['page_title_url']['scope'], + ); + } + else { + $settings[] = array( + 'path' => $form_state['values']['page_title_url']['path'], + 'pattern' => $form_state['values']['page_title_url']['pattern'], + 'scope' => $form_state['values']['page_title_url']['scope'], + ); + } + variable_set('page_title_url', $settings); +} + + + +function page_title_admin_url_delete($form_state, $id) { + $form = array(); + $form['path_id'] = array('#type' => 'value', '#value' => $id); + + return confirm_form($form, t('Do you really want to remove this path configuration?'), 'admin/content/page_title/url'); +} + + +function page_title_admin_url_delete_submit($form, &$form_state) { + $settings = variable_get('page_title_url', array()); + unset($settings[$form_state['values']['path_id']]); + variable_set('page_title_url', $settings); + $form_state['redirect'] = 'admin/content/page_title/url'; +} + + + /** * Implementation of hook_node_type(). * @@ -297,11 +467,34 @@ function page_title_page_get_title() { } //Otherwise this is a non-frontpage page title. else { - //Get the node for this page - $node = ((arg(0) == 'node') && (is_numeric(arg(1)))) ? menu_get_object() : NULL; - - //Get the pattern for the node type. If no node type available, assume blank - $page_title_pattern = variable_get('page_title_type_'. (isset($node->type) ? $node->type : ''), ''); + if (arg(0) == 'node' && is_numeric(arg(1))) { + //Get the node for this page + $obj = ((arg(0) == 'node') && (is_numeric(arg(1)))) ? menu_get_object() : NULL; + + //Get the pattern for the node type. If no node type available, assume blank + $page_title_pattern = variable_get('page_title_type_'. (isset($obj->type) ? $obj->type : ''), ''); + $scope = 'node'; + } + elseif ($path_id = _page_title_get_title_pattern_by_path($_GET['q'])) { + $settings = variable_get('page_title_url', array()); + $page_title_pattern = $settings[$path_id]['pattern']; + $scope = $settings[$path_id]['scope']; + switch ($scope) { + case 'taxonomy' : + $obj = taxonomy_get_term(arg(2)); + break; + + case 'user' : + $obj = menu_get_object('user'); + break; + + default : + case 'global' : + $scope = 'global'; + $obj = NULL; + break; + } + } //If pattern is emtpy (either if the type is not overridable or simply not set) fallback to the default pattern if (empty($page_title_pattern)) { @@ -309,8 +502,8 @@ function page_title_page_get_title() { } // Return the title using the node scope if node is set, otherwise default to global scope. - if (isset($node)) { - $title = token_replace($page_title_pattern, 'node', $node); + if ($scope != 'global') { + $title = token_replace($page_title_pattern, $scope, $obj); } else { $title = token_replace($page_title_pattern); @@ -322,6 +515,19 @@ function page_title_page_get_title() { } + +function _page_title_get_title_pattern_by_path($path) { + $settings = variable_get('page_title_url', array()); + + foreach ($settings as $path_id => $conf) { + if (drupal_match_path($path, $conf['path'])) { + return $path_id; + } + } + return FALSE; +} + + /** * Implementation of hook_token_values(). *