Index: watcher.module =================================================================== --- watcher.module (revision 767) +++ watcher.module (working copy) @@ -185,6 +185,44 @@ } /** + * Return a toggle watching post link array to be displayed in the node links section + * + * Please note that the JavaScript that handles the AJAX request looks for the class + * attribute so do not change it, rather override it with your own CSS rules if you + * want to change the appearance of this element. + * + * @param $uid + * The user we'd like to toggle watching for + * @param $nid + * The node id we're toggling watching for for this user + * @param $dest + * The URL of the current page, used for redirection afterwards + * @param $user_is_watching + * A boolean denoting whether uid is watching nid + * @param $t + * An associative array of localized strings + * + * @return + * A themed widget for toggling watching of the given nid + * + */ +function theme_watcher_node_links_toggle_watching_link($uid, $nid, $dest, $user_is_watching, $t = array()) { + + // Set up classes + $class_watch_status_link = ( $user_is_watching ? ' watcher_node_toggle_watching_link_watched' : ''); + $class_watch_status_container = ( $user_is_watching ? ' watcher_node_watched' : ''); + + return array( 'href' => "user/$uid/watcher/toggle/$nid", + 'title' => ( $user_is_watching ? $t['watch_toggle_enabled'] : $t['watch_toggle_disabled'] ), + 'attributes' => array( 'class' => "watcher_node_toggle_watching_link$class_watch_status_link", + 'title' => ( $user_is_watching ? $t['watch_toggle_enabled_title'] : $t['watch_toggle_disabled_title'] ), + ), + 'query' => $dest, + ); + +} + +/** * Return the help page * * @param $content @@ -249,6 +287,16 @@ } /** + * Implementation of hook_link(). + */ +function watcher_link($type, $node = NULL, $teaser = FALSE) { + global $user; + if ($user->uid && user_access('use watcher') && _watcher_node_type_enabled($node)) { + return _watcher_node_watch_link($node, $teaser, null); + } +} + +/** * Implementation of hook_menu(). */ function watcher_menu($may_cache) { @@ -542,6 +590,34 @@ '#collapsed' => true, ); + $form['togglelink']['watcher_toggle_link_disabled_text'] = array( + '#type' => 'textfield', + '#title' => t('Link text when node is not being watched'), + '#default_value' => variable_get('watcher_toggle_link_disabled_text', t('You are not watching this post, click to start watching')), + '#size' => 50, + '#maxlength' => 100, + ); + + $form['togglelink']['watcher_toggle_link_enabled_text'] = array( + '#type' => 'textfield', + '#title' => t('Link text when node is being watched'), + '#description' => t('If your site uses many languages, both these strings can be translated to languages other than the default by using the locale module.'), + '#default_value' => variable_get('watcher_toggle_link_enabled_text', t('You are watching this post, click to stop watching')), + '#size' => 50, + '#maxlength' => 100, + ); + + $form['togglelink']['watcher_toggle_link_position'] = array( + '#type' => 'radios', + '#title' => t('Where should "watch this post" toggle links be inserted on each node?'), + '#description' => t('This setting applies for both full page view and teasers (if the "display in teasers" option is checked).'), + '#options' => array( + 'body' => t('At the bottom of the node body'), + 'links' => t('In the node links section'), + ), + '#default_value' => variable_get('watcher_toggle_link_position', 'body'), + ); + $form['togglelink']['watcher_toggle_link_in_teaser'] = array( '#type' => 'checkbox', '#title' => t('Display "watch this post" toggle link in teasers.'), @@ -1681,9 +1757,9 @@ // Make localized strings $tstrings = array(); - $tstrings['watch_toggle_enabled'] = t('You are watching this post, click to stop watching'); + $tstrings['watch_toggle_enabled'] = variable_get('watcher_toggle_link_enabled_text', t('You are watching this post, click to stop watching')); $tstrings['watch_toggle_enabled_title'] = t('This post is being watched. You can track and change email notification setting for this post in your watched posts list (see your user profile)'); - $tstrings['watch_toggle_disabled'] = t('You are not watching this post, click to start watching'); + $tstrings['watch_toggle_disabled'] = variable_get('watcher_toggle_link_disabled_text', t('You are not watching this post, click to start watching')); $tstrings['watch_toggle_disabled_title'] = t('Watch posts to be notified when other users comment on them or the posts are changed'); // Build link to the user's list of watched posts @@ -1704,11 +1780,19 @@ // Add CSS drupal_add_css(drupal_get_path('module', 'watcher') .'/css/watcher.css'); - //Add element to node - $node->content['watcher'] = array( - '#value' => theme('watcher_node_toggle_watching_link', $user->uid, $node->nid, $dest, $watching, $tstrings), - '#weight' => 30, - ); + $position = variable_get('watcher_toggle_link_position', 'body'); + if ($position == 'links') { + // Add toggle element to links array + return array( 'watcher' => theme('watcher_node_links_toggle_watching_link', $user->uid, $node->nid, $dest, $watching, $tstrings) ); + } + else { + //Add element to node + $node->content['watcher'] = array( + '#value' => theme('watcher_node_toggle_watching_link', $user->uid, $node->nid, $dest, $watching, $tstrings), + '#weight' => 30, + ); + } + } /**