From ec3462121f6f54cfec0c305fc2557df1419f4539 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Wed, 26 Jul 2017 13:57:55 +0200 Subject: [PATCH] New module 'Watcher' --- sites/all/modules/watcher/CHANGELOG.txt | 104 + sites/all/modules/watcher/LICENSE.txt | 274 ++ sites/all/modules/watcher/README.txt | 253 ++ sites/all/modules/watcher/css/watcher.css | 127 + .../all/modules/watcher/images/important.png | Bin 0 -> 1582 bytes .../watcher/images/send_email_disabled.gif | Bin 0 -> 942 bytes .../watcher/images/send_email_enabled.gif | Bin 0 -> 959 bytes ...end_email_from_disabled_to_enabled_ani.gif | Bin 0 -> 7836 bytes ...end_email_from_enabled_to_disabled_ani.gif | Bin 0 -> 7236 bytes .../modules/watcher/images/stop_watching.png | Bin 0 -> 655 bytes sites/all/modules/watcher/images/unwatch.gif | Bin 0 -> 401 bytes sites/all/modules/watcher/images/watch.gif | Bin 0 -> 616 bytes sites/all/modules/watcher/js/watcher.js | 166 + .../modules/watcher/translations/watcher.pot | 775 ++++ sites/all/modules/watcher/watcher.db.inc | 659 ++++ sites/all/modules/watcher/watcher.info | 14 + sites/all/modules/watcher/watcher.install | 250 ++ sites/all/modules/watcher/watcher.module | 3240 +++++++++++++++++ 18 files changed, 5862 insertions(+) create mode 100644 sites/all/modules/watcher/CHANGELOG.txt create mode 100644 sites/all/modules/watcher/LICENSE.txt create mode 100644 sites/all/modules/watcher/README.txt create mode 100644 sites/all/modules/watcher/css/watcher.css create mode 100644 sites/all/modules/watcher/images/important.png create mode 100644 sites/all/modules/watcher/images/send_email_disabled.gif create mode 100644 sites/all/modules/watcher/images/send_email_enabled.gif create mode 100644 sites/all/modules/watcher/images/send_email_from_disabled_to_enabled_ani.gif create mode 100644 sites/all/modules/watcher/images/send_email_from_enabled_to_disabled_ani.gif create mode 100644 sites/all/modules/watcher/images/stop_watching.png create mode 100644 sites/all/modules/watcher/images/unwatch.gif create mode 100644 sites/all/modules/watcher/images/watch.gif create mode 100644 sites/all/modules/watcher/js/watcher.js create mode 100644 sites/all/modules/watcher/translations/watcher.pot create mode 100644 sites/all/modules/watcher/watcher.db.inc create mode 100644 sites/all/modules/watcher/watcher.info create mode 100644 sites/all/modules/watcher/watcher.install create mode 100644 sites/all/modules/watcher/watcher.module diff --git a/sites/all/modules/watcher/CHANGELOG.txt b/sites/all/modules/watcher/CHANGELOG.txt new file mode 100644 index 0000000..8ceccf7 --- /dev/null +++ b/sites/all/modules/watcher/CHANGELOG.txt @@ -0,0 +1,104 @@ +Note: CHANGELOG is no longer being updated. See the commit history at +drupal.org/project/watcher for a list of changes. + +2009-02-26 + - Fixed #384388 by J-Chance: Autowatching of nodes you make doesn't work. + +2009-02-14 + - Added: Caches 'from' header so it's only generated once. + - #371506: Fixed: Removed apostrophes in permission strings as it seems to cause illegal form + error with some modules enabled. + +2009-02-10 + - Fixed: Improved caching of user's watched posts list, significantly reducing the number of + queries needed. + +2009-02-08 + - Fixed: An issue with mismatching variable names causing some templates not to be editable. + - Refactored form code. + - Added: Introduced a theme function to display the "default settings" message on a user's + settings page. Added an icon to spruce things up a bit :) + - Fixed: Watcher now uses Drupal.behaviors. + +2009-02-07 + - Fixed: #369910 by Sebo: Anonynous notifications are received even for non-watched posts + - Fixed: README file contents not rendered properly on help page. + - Fixed: The current user, not the node's author, is now excluded from receiving + notifications when a node is updated since many users may edit a node and the current + user isn't necessarily author of the node. + +2009-01-30 + - Committing BETA1. + +2009-01-29 + - Fixed bug causing send to fail when time limit set to "unlimited" (to be backported to 5.x branch) + - Bug #361753: Fixed bug causing messages and subjects to be empty + - Fixed not setting correct headers and footers for anonymous users + - Added a template to the settings page for setting notification message footer for anonymous recipients + - Fixed issue with wrong argument passed to function watcher_db_user_set_watching() + +2009-01-18 + - #358709: Fixed. + - #359471: Fixed. + - #360612: Fixed. + - More options for anonymous users, watch for comments, updates or both. + - Introduced watch_for column in the watcher_nodes table. + - Fixed a number of not reported bugs. + - Binder/other users' watcher posts lists now work as they should. + - Statistics page now also shows the number of anonymous users watching nodes. + - Removed hook_user op: view implementation, a menu tab now serves as the link + to a user's list of watched posts + +2009-01-10 + - Removed customization of "My Watched Posts", translation is now handled through the + the translation system. Changes to its title can be made from admin/build/menu. + - Removed cache clearing menu callback. + - Implemented support for letting anonymous users watch posts. + +2009-01-09 + - First working version of 6.x branch. + - Added notice to user settings page indicating whether the settings are default or custom. + - Included cache clearing menu callback. + - A number of minor improvements. + +2008-12-12 + - #319048: Improved fix, filters out RFC2047 especials from site name string + before used as sender name in email messages + - Refactoring. + +2008-11-09 + - #319048: Fixing issue for users using "site name " for site email + - Refactoring of code to improve compliance with coding guidelines + +2008-09-07 + - Improvements to CSS and Javascript. + - #263139: Fix - Implemented workaround for issue with SMTP module + - #268439: Doc - Added additional information about theming to README file. + - Feature - Watcher now adds a log entry to Watchdog every time cron notifications + are successfully sent. + +2008-09-06 + - #299605: Fix - Fixed a bug stopping excerpt length from being changed. + - #263978: Fix - Fixed a bug making uid 0 being notified when anonymous + comment posting is allowed. + +2008-08-19 + - Clicking buttons on the testing page now works. + +2008-04-26 + - #251367: Fix -Fixed a bug that manifested itself when posting comments. + - Cosmetic fix, added margin below the start watching link so that the link + to the user's binder is displayed nicely. + - #251367: Fix - handles hook_comment being passed comments as arrays *and* objects. + +2008-04-23 + - Fixed bug with quotes in comment text being encoded as HTML + character entity tags + - Fixed bug that caused a PHP error referring to array_flip() + - Updated .pot file + + (These changes were carried out over the course of several weeks but + the changelog was lost in a hard drive crash, and they're therefore + noted here.) + + (Dates are YYYY-MM-DD) \ No newline at end of file diff --git a/sites/all/modules/watcher/LICENSE.txt b/sites/all/modules/watcher/LICENSE.txt new file mode 100644 index 0000000..2c095c8 --- /dev/null +++ b/sites/all/modules/watcher/LICENSE.txt @@ -0,0 +1,274 @@ +GNU GENERAL PUBLIC LICENSE + + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, +Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute +verbatim copies of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your freedom to +share and change it. By contrast, the GNU General Public License is +intended to guarantee your freedom to share and change free software--to +make sure the software is free for all its users. This General Public License +applies to most of the Free Software Foundation's software and to any other +program whose authors commit to using it. (Some other Free Software +Foundation software is covered by the GNU Library General Public License +instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our +General Public Licenses are designed to make sure that you have the +freedom to distribute copies of free software (and charge for this service if +you wish), that you receive source code or can get it if you want it, that you +can change the software or use pieces of it in new free programs; and that +you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to +deny you these rights or to ask you to surrender the rights. These restrictions +translate to certain responsibilities for you if you distribute copies of the +software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for +a fee, you must give the recipients all the rights that you have. You must make +sure that they, too, receive or can get the source code. And you must show +them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) +offer you this license which gives you legal permission to copy, distribute +and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that +everyone understands that there is no warranty for this free software. If the +software is modified by someone else and passed on, we want its recipients +to know that what they have is not the original, so that any problems +introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We +wish to avoid the danger that redistributors of a free program will individually +obtain patent licenses, in effect making the program proprietary. To prevent +this, we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification +follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND + MODIFICATION + +0. This License applies to any program or other work which contains a notice +placed by the copyright holder saying it may be distributed under the terms +of this General Public License. The "Program", below, refers to any such +program or work, and a "work based on the Program" means either the +Program or any derivative work under copyright law: that is to say, a work +containing the Program or a portion of it, either verbatim or with +modifications and/or translated into another language. (Hereinafter, translation +is included without limitation in the term "modification".) Each licensee is +addressed as "you". + +Activities other than copying, distribution and modification are not covered +by this License; they are outside its scope. The act of running the Program is +not restricted, and the output from the Program is covered only if its contents +constitute a work based on the Program (independent of having been made +by running the Program). Whether that is true depends on what the Program +does. + +1. You may copy and distribute verbatim copies of the Program's source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and +disclaimer of warranty; keep intact all the notices that refer to this License +and to the absence of any warranty; and give any other recipients of the +Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you +may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, +thus forming a work based on the Program, and copy and distribute such +modifications or work under the terms of Section 1 above, provided that you +also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices stating that +you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in whole or in +part contains or is derived from the Program or any part thereof, to be +licensed as a whole at no charge to all third parties under the terms of this +License. + +c) If the modified program normally reads commands interactively when run, +you must cause it, when started running for such interactive use in the most +ordinary way, to print or display an announcement including an appropriate +copyright notice and a notice that there is no warranty (or else, saying that +you provide a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this License. +(Exception: if the Program itself is interactive but does not normally print such +an announcement, your work based on the Program is not required to print +an announcement.) + +These requirements apply to the modified work as a whole. If identifiable +sections of that work are not derived from the Program, and can be +reasonably considered independent and separate works in themselves, then +this License, and its terms, do not apply to those sections when you distribute +them as separate works. But when you distribute the same sections as part +of a whole which is a work based on the Program, the distribution of the +whole must be on the terms of this License, whose permissions for other +licensees extend to the entire whole, and thus to each and every part +regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to +work written entirely by you; rather, the intent is to exercise the right to +control the distribution of derivative or collective works based on the +Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of a +storage or distribution medium does not bring the other work under the scope +of this License. + +3. You may copy and distribute the Program (or a work based on it, under +Section 2) in object code or executable form under the terms of Sections 1 +and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable source +code, which must be distributed under the terms of Sections 1 and 2 above +on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three years, to give +any third party, for a charge no more than your cost of physically performing +source distribution, a complete machine-readable copy of the corresponding +source code, to be distributed under the terms of Sections 1 and 2 above on +a medium customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer to distribute +corresponding source code. (This alternative is allowed only for +noncommercial distribution and only if you received the program in object +code or executable form with such an offer, in accord with Subsection b +above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source code +means all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation and +installation of the executable. However, as a special exception, the source +code distributed need not include anything that is normally distributed (in +either source or binary form) with the major components (compiler, kernel, +and so on) of the operating system on which the executable runs, unless that +component itself accompanies the executable. + +If distribution of executable or object code is made by offering access to +copy from a designated place, then offering equivalent access to copy the +source code from the same place counts as distribution of the source code, +even though third parties are not compelled to copy the source along with the +object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as +expressly provided under this License. Any attempt otherwise to copy, +modify, sublicense or distribute the Program is void, and will automatically +terminate your rights under this License. However, parties who have received +copies, or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. +However, nothing else grants you permission to modify or distribute the +Program or its derivative works. These actions are prohibited by law if you +do not accept this License. Therefore, by modifying or distributing the +Program (or any work based on the Program), you indicate your acceptance +of this License to do so, and all its terms and conditions for copying, +distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the original +licensor to copy, distribute or modify the Program subject to these terms and +conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), conditions +are imposed on you (whether by court order, agreement or otherwise) that +contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot distribute so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not distribute the Program at all. +For example, if a patent license would not permit royalty-free redistribution +of the Program by all those who receive copies directly or indirectly through +you, then the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply and +the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or +other property right claims or to contest validity of any such claims; this +section has the sole purpose of protecting the integrity of the free software +distribution system, which is implemented by public license practices. Many +people have made generous contributions to the wide range of software +distributed through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing to +distribute software through any other system and a licensee cannot impose +that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Program under this License may add an explicit +geographical distribution limitation excluding those countries, so that +distribution is permitted only in or among countries not thus excluded. In such +case, this License incorporates the limitation as if written in the body of this +License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will be +similar in spirit to the present version, but may differ in detail to address new +problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies +a version number of this License which applies to it and "any later version", +you have the option of following the terms and conditions either of that +version or of any later version published by the Free Software Foundation. If +the Program does not specify a version number of this License, you may +choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs +whose distribution conditions are different, write to the author to ask for +permission. For software which is copyrighted by the Free Software +Foundation, write to the Free Software Foundation; we sometimes make +exceptions for this. Our decision will be guided by the two goals of +preserving the free status of all derivatives of our free software and of +promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT +PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE +STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL +NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR +AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR +ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE +LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, +SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA +OR DATA BEING RENDERED INACCURATE OR LOSSES +SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE +PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN +IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF +THE POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/sites/all/modules/watcher/README.txt b/sites/all/modules/watcher/README.txt new file mode 100644 index 0000000..74fd241 --- /dev/null +++ b/sites/all/modules/watcher/README.txt @@ -0,0 +1,253 @@ +Watcher Module for Drupal 6.x + +Feature overview + + * Lets users watch nodes for changes or new comments being posted without + having to post themselves.+ + * Uses AJAX to toggle watching for a smooth user experience. + * Allows both anonymous and registered users to watch nodes. + * Supports email notifications being sent when both or either of the + above occurs. + * Template-based notification messages using the Token module - edit the + templates to your liking! + * Provides a binder with an overview of the nodes you watch. From the + binder you can also toggle email notifications for each node you watch. + * Users may choose to publish the binder so that other users can see what + they're watching, providing a form of social bookmarking. + * Uses a queue-based email dispatcher to handle large numbers of notifications. + * Users can opt to automatically watch nodes they create or comment on. + * User settings can have default values, set by the site owner, that can be + customized and overridden by the user. + * Highly customizable, configurable user interface and themeable. + * Designed with usability and exceptional user experience as a high priority. + +Watcher was developed to fill a gap that has existed for a long time. Even +though there are several subscription and notification modules out there, +none is both easy to use or particularly specialized and allows instant +(or near instant) notifications. Watcher is not a general solution to +notifications but caters to the needs of community sites. + ++Added in the Drupal 6 version. + + +Requirements +------------ +To install this version of Watcher you need: + +* Drupal 6.x +* Comments module (included in Drupal) +* Node module (included in Drupal) +* Token module (http://drupal.org/project/token) + +There's a version for Drupal 5 as well, available from: +http://drupal.org/project/watcher + + +Installation +------------ +To install Watcher, do the following: + + 1. Download, install and configure the Token module, follow the + instructions for that module. + + 2. Download the latest stable version of Watcher from its project + page: http://drupal.org/project/watcher + + 3. Unpack the file you downloaded into sites/all/modules or the + modules directory of your site. + + 4. Go to Administer » Site building » Modules and enable the module. + + 5. Go to Administer » Site configuration » Watcher and select at least + one content type for the module. + + NOTE: The module will not work and users will not be able to watch + posts unless you select at least *one* content type. + Click "Save configuration" to save your changes. + + +Upgrading from Drupal 5 +----------------------- +If you've been using a previous version of Watcher, make sure you go to update.php +and run the update script after uploading the new module files. + + +Issues +------ +In case Watcher does not appear to work for anonymous users even though the +role Anonymous has been granted the necessary permissions, your users table +may be missing the anonymous user. + +To fix this, first empty your site's cache. You can do that by going to +Administration » Site Settings » Performance + +Secondly, make sure there's a row with uid 0 in your site's users table. +You can confirm that by executing this SQL query: +SELECT * FROM `users` WHERE uid = 0; + +The query should return exactly one row. If no row is returned, the row is +missing and must be restored. Execute this query to add the row: +INSERT INTO `users` VALUES (0, '', '', '', 0, 0, 0, '', '', 0, 0, 0, 0, NULL, '', '', '', NULL); + +See: http://drupal.org/node/370459 + + +CAPTCHA support and preventing spam +----------------------------------- +Since Watcher now supports anonymous users watching nodes, CAPTCHA support has +been added to help prevent spam submissions. Download CAPTCHA module: +http://www.drupal.org/project/captcha + +Watcher is known to work with CAPTCHA 6.x-1.0-rc2 and probably also all subsequent +6.x-1.0 release. Compatibility with 6.x-2.0 and later is not confirmed at this point. + +Install CAPTCHA and set up its permissions as needed. Then go to: +admin/user/captcha/captcha/captcha_point + +Enter "_watcher_watch_toggle_anonymous_form" (quotation marks omitted) in the +"Form ID" field. Select a challenge type and save the form. CAPTCHA will now display +the challenge you selected when anonymous users want to start watching a node. + +To implement a first line of defense against spambots you can use the Bad Behavior +module. It uses heuristics to determine whether the browser is a genuine +human-controlled software application or an automated spambot: +http://drupal.org/project/badbehavior + + +Configuration +------------- +The module can be configured by going to: +Administer » Site configuration » Watcher + +You can customize a wide range of options. Most of this is quite straight-forward +however some things may require an explanation. + +Under "Settings for Email Notifications" you can choose what method to use for +sending emails. This will have an impact on how many messages are sent at once. +Watcher stores notifications to be sent in a message queue and every time messages +are sent they're taken off the queue. The method affects when the queue messages are +actually sent, it can either happen when cron and cron.php is being run or when a +user posts a comment. + +If there are many messages in the queue, the best setting to use is cron and making +sure cron is run frequently enough that the entire queue is being processed. You can +change the time limit for message sending. The server will send as many messages as +possible during this interval. Any messages left unsent will remain in the queue +until it is processed again. + +You may also modify the notification message templates that are used to generate the +notification messages. You can use placeholder tokens to insert the content that +changes, such as recipient name and comment excerpt. + +Watcher also allows every user on your site to customize how the module works for them. +Users may enable or disable email notifications and make it so that they automatically +watch every post they make or comment on. Users who have not yet altered these settings +will be affected by the user settings defaults. These default settings apply until a +user goes to his or her settings page for Watcher and clicks "Save". + +The page titled Statistics shows some basic statistics about the module which may be of +interest to you as a site owner. If there are unsent messages in the message queue, +these can be viewed here as well. + +The Testing page allows you to do testing in case notification messages are not being +delivered. You can create test messages that are sent to your own email address. + + +Retroactively add existing posts +-------------------------------- +If you have a large site and a large quantity of nodes/posts you may want to add the +existing nodes your users have made or commented on to their watched posts lists. + +You can do this by running the SQL queries below. The queries below will do the +following: +- add all posts a user has created to his/her watched posts list +- add the nodes belonging to every comment a user has made to his/her watched posts list + +CAUTION: Make a database dump to keep as a backup copy before attempting this! +CAUTION: The following has only been tested with MySQL 5! + +INSERT IGNORE INTO watcher_nodes (uid, nid, send_email, added) SELECT uid, nid, 1, UNIX_TIMESTAMP() FROM node; +INSERT IGNORE INTO watcher_nodes (uid, nid, send_email, added) SELECT uid, nid, 1, UNIX_TIMESTAMP() FROM comments; + + +Theming +------- +Watcher is entirely themable. Open watcher.module in your editor to see what +theme functions are available to be overridden. The functions are documented in +detail in the code. + +Themable functions of interest: + * watcher_binder($intro_text, $posts_table_header, $posts_table_body) + * watcher_binder_email_icon($t, $type, $url, $dest) + * watcher_binder_stop_watching_icon($url, $dest) + * watcher_node_toggle_watching_link($uid, $nid, $dest, $user_is_watching) + * watcher_help_page($content) + +Watcher outputs the watcher link at the end of the node's body by default. A future +feature will be to make this configurable, allowing the link to be output in the +node's links section, at the beginning or end of body or in a separate template +variable. Until then, you can use the following method to separate the watcher link +from the node's body. + +In node.tpl.php, to display the watcher link: + + content['watcher']['#value']): ?> +
+ content['watcher']['#value']; ?> +
+ + +And the node's body: + +
+
content['body']['#value']; ?>
+
+ +For more info, please see: http://drupal.org/node/11816 + + +Terminology +----------- +I have tried to consistently use the term "post" in the parts of the module that +the end users see as it makes way more sense to non-Drupallers than the word "node". +In the code comments and documentation, I've used the word "node" where I talk +about nodes. + +The word "binder", is used interchangeable with the term "watched posts list". They're +exactly the same thing, "binder" is a term Hans Dekker of Wordsy.com suggested and it's +stayed in the module since its first versions. + + +Author +------ +The module was developed by Jakob Persson of +NodeOne, Sweden's leading Drupal consulting firm. Our goal is to empower the +user by building usable, powerful and effective web solutions for our clients. +Visit us at http://www.nodeone.se + +I am a developer that considers usability and user experience to be some of the +defining properties of successful software applications as well as devices and +appliances. I have a background in cognitive science and HCI and I work with +user experience and usability at NodeOne, building beautiful, usable +web sites and intranet applications for our clients. + +The author can be contacted for paid customizations of this module as well as +Drupal consulting, installation, development and customizations. + + +Sponsors +-------- +The development of this module has been sponsored by + + * Wordsy + * NodeOne + + +Thanks +------ +To Hans Dekker for the idea as well as suggestions +and feedback. + +Some of the icons were either taken directly from the Tango Icon Library or were +derived from Tango icons. +http://tango.freedesktop.org/ \ No newline at end of file diff --git a/sites/all/modules/watcher/css/watcher.css b/sites/all/modules/watcher/css/watcher.css new file mode 100644 index 0000000..b72e6bc --- /dev/null +++ b/sites/all/modules/watcher/css/watcher.css @@ -0,0 +1,127 @@ +@CHARSET "UTF-8"; + +/** + * Intro text in binder + */ + +#watcher_binder_intro { + margin: 1em 0; +} + +/** + * Email notification status link in binder + */ + +.watcher_binder_send_email_status_icon { + background-image: url(../images/send_email_disabled.gif); + background-repeat: no-repeat!important; + width: 47px; + height: 24px; + display: block; + padding-left: 47px; + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; + font-size: 10px; + line-height: 1.2em; +} + +.watcher_binder_send_email_status_icon_disabled { + background-image: url(../images/send_email_disabled.gif); + color: #c00!important; +} + +.watcher_binder_send_email_status_icon_enabled { + background-image: url(../images/send_email_enabled.gif); + color: #0b0!important; +} + +/* + Must be on hover or firefox will not play the animated GIFs asynchronously, + instead they'll all sync and loop at the same time. + The last frame of the GIFs lasts for 10 seconds to handle long latencies. +*/ +.watcher_binder_send_email_status_icon_from_enabled_to_disabled:hover { + background-image: url(../images/send_email_from_enabled_to_disabled_ani.gif)!important; +} +.watcher_binder_send_email_status_icon_from_disabled_to_enabled:hover { + background-image: url(../images/send_email_from_disabled_to_enabled_ani.gif)!important; +} + +/** + * Stop watching link in binder (watch list) + */ +.watcher_binder_stop_watching_icon { + background-image: url(../images/stop_watching.png); + background-repeat: no-repeat!important; + width: 100%; + height: 22px; + display: block; + text-indent: -300em; +} + +/** + * Toggle watching link on nodes + */ +.watcher_node { + background-image: url(../images/unwatch.gif); + background-repeat: no-repeat!important; + background-position: 0% 50%; + padding-left: 22px; + padding-top: 0px; + padding-bottom: 3px; + margin: 0; + font-size: 13px; + height: 18px; +} + +.watcher_node_watched { + background-image: url(../images/watch.gif)!important; +} + +.watcher_node_toggle_watching_link { + display: block; + color: #5F5F5F!important; +} + +.watcher_node_toggle_watching_link_watched { + color: #0c0!important; + font-weight: bold; +} + +.watcher_node_toggle_watching_link_with_link_to_binder { + margin-bottom: 1.5em; +} + +/** mini link, not currently used */ +.watcher_node_toggle_watching_link_mini { + background-image: url(../images/watch.gif); + background-repeat: no-repeat!important; + font-size: 14px; + width: 16px; + height: 16px; + display: inline; + margin: 0 0 0 .5em; +} + +.watcher_node_help_link_to_binder { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 12px; + margin-top: 15px; +} + +/** + * Watcher Help Page + */ + +#watcher_help_page dl dt { + font-weight: bold!important; +} + +/** + * Defaults notice on user's settings page + */ +.watcher_settings_defaults_notice { + font-weight: bold; + padding: 1em 1em 1em 54px; + background: url(../images/important.png) no-repeat 8px 50%; +} + diff --git a/sites/all/modules/watcher/images/important.png b/sites/all/modules/watcher/images/important.png new file mode 100644 index 0000000000000000000000000000000000000000..263fbd5866aef1ce3645d768fbf55def9a091905 GIT binary patch literal 1582 zcmV+}2GRM6P)k@WH7pQF=3=faW zkFSqR=8AIgXBSA;Hc`EO&K^N)42Y`_9UkcY+JOPZzW)_SXY=A^lj%j;c6NwBgJ_tV zm_2r=oma1nQ4OegJG6y4*V7pt+<)-viajx2cgoi@dv1pQz5%6oPs>nSm~*w?TqQVv zob8dII{c&Oe%S1c$Jb4}_O0hohn`**8Ge(}Coiu}Aq2|y9sKoAe_L3{Is>OKFbSRv z1pSn5A0ELYKmLQ6BwuOzH&f_kC zpw7uXeVu-psxJ`U5$EUY>gJ?Py7zS&L7kH>03>~lEiK4GzOF#Bu=x@I$Wn<&a}!AV z0JO@7l0!?lsTn6_uHD-u=x*nv?jh4tOM8aU5Jm$S4XgGI1^n1jw1Qj)a0G^`sW^46 z`zk{v@<5WOf#ro&h@# znjak7C0?~s9=SM_n9NYjv(wK7=2M5YtS{PKY$ zvq{93_SMB}%_$-0$B^l1M4*|BZ#$YIXIuaXZY|uu(-Vrempj=|${=$lGCK?Q%G0#? z`m+#hhFpCs04oQ|EN0RVf?FVz z;UBke#-&y%!v?064Rok zOzr0t(XWi*Ji3QBXXf%JRoe>fIM6Q~a~|x{=CxG~y=Q>o+w;yR!_$*li|?MfjH_0w z4(~z?Yj=n@ipBh~`I%&-^WdPS`V7dV>N~21K#jH|clB`PgWJ~4*uv-kzRU4neaIZ( zs_AL~J|J*?3i;mzZ}f)kj*(jv-9BB_qC@+I5-iVl$9ByRp&N*X5L#OY%C2rk literal 0 HcmV?d00001 diff --git a/sites/all/modules/watcher/images/send_email_disabled.gif b/sites/all/modules/watcher/images/send_email_disabled.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e359657891ebe261946d6ad3a08d6892b8ca7b3 GIT binary patch literal 942 zcmZ?wbhEHb)Mk)ic*elc#=vmp=F^pHHeHX7o@Qk7?%lh+3=C7J&pmPG+EoLC35tr} zyStCc$=!SO^3&(<2alXPV{CjYJ^k^tY1eMte`aEGW74F(d-wkO{b!G~^w-wbdk>z^ zvA6FP61wB$^!)krbC>SjI(zoTo;|lxQjQ)yxxuvzO zJ({7bJ65i}f5HS48}6x7C2d0cCeE2;BPq+dh|?`l#d>y&oUqo~b?Y~5;Ef^}l$!f)EW@o9~ z%wc5Y8o(<4`ODXDpYJTz(fz}!y*RkYByswp2NR`)xwK+VY)IG_=pfU2K(t`N0;w>g zv^fnAI*#=#7~A<6tZV4eQBrVlP;z;&K#DKvl+CBaCZ3rV#m`P$=()ost2xExK~h80 z>2Ay9eF;|;H2owkYo=&09*b`>u!`|82>6oGDE018mo10unh0M0vJVFyx}Ii`DEObq z^3bYYM}){&IyJORktp0Lr4TgTxnEL0-eaE6Pv$12wQS+R7az2? zA5s_4PU|`Nu_wfoZFSgMMsAU-!W*vqc<`j7P0E!`_($QRBh&RmRwP6;9dcU5BpWVY z$i&*n`IJ{`O_|Ycvqsl$5fS@;S3AGIUn^B3?|-lQ2b(|33h{ykorTV($DAt-7VfG2 zdG6%(h7jdloGcs}0(ToB-MgavloSB{v$a5P6PL*ZeINLa=~PSX_$huR_>m=bsy zb2J`xs7&)vVltg^Kv0E0L2yy0!Lc0+x%eN5b#iey2p;IO`S#**zg=AbGt*p=#-q$0 WYAc^`Px86<;0dp(n4qTugEasxYLD^& literal 0 HcmV?d00001 diff --git a/sites/all/modules/watcher/images/send_email_enabled.gif b/sites/all/modules/watcher/images/send_email_enabled.gif new file mode 100644 index 0000000000000000000000000000000000000000..681ca37f20b27576c39b807248d3bfc1ffbed369 GIT binary patch literal 959 zcmZ?wbhEHb)Mk)ic*elM;Ky*~=F`>dHm7Y*v#GLs_wF6TM22k__t+h@n>=~)y+<$Q zr^x^K`TN|ZdkobK2alYqoKiXI^d$Q=_9xC}Stk_rB!)^yAYbM~<*(vlr|sxPIr^hI<>_ zdfmE~bO}xo^xWp@dBOAM&6{&h%+Z>qb@b$AhGvFqH|~G`|DPd^!E~AFnKNh7mu2@KC5iXyuU&p7T8g^Mn|R8RVA9&73)N$L$@y`+PkYd5X^w zfA`^Q_SS5MZiZ`5uURa&c<|&6#}tmkN6(+Xa^JPpW8Rf{&6}Fd=9)ct@Zj0^XTC># zzkdID?%FlaDW3eZ`K6ahZ`i!kcdai^5l`=o-n3n5YKzro%~@o%)(RMSlmo?|ER5_7 ztPDCJqd;-O!2Z91wW+zKwXI#lE3Vs1gVjI4Td;k~)K(99XFZiUdd~7f7KXav)0VY) z#3jkBS*zmh9VKVSt=6KTymQy?J$vPo<{X^k=B6qq=OxZ5+Qc6sb^PL`%a=u*=OlOs zaj4jOACrraPH~T9-JvYTbLGut=cMQ(sv7Zb@mj}?lmx5|o(cQRXjl-`(0H(!Ls;s| zB$ZAP?c)pXSckct>Xo%TBRZpC!=WB2E@!!v8Ap7$3l#f!Cpa-Xu=TR070k5Ue5{4b zr1;gGm0msFyt)l8(VonQd*xfwG9pfGacY+Gnc+3}m1`%rF`LVrFAiHgCMtNaYtCKO z=-w;Hb;2uk(P3|H^@9IfgC;y;Xl|C)KEyRkaKrle{*XVvwtiqZGDFEk=(2#~qjk+n z>UB>%v?2`p1&wuh<{2$wn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)>9)XQ@)=`=BPIi5@GT$X*@QNVP|< zc57r3oZj_u9wV z%$=zJHA<@}u=s`EmlLIZ_mj)MdPlzg9eM68oW21MnSRy1i;f&RxIW;+@NB)Q{5V^0 zMy;-&>^gYy(0e3C1tLcrf%7kNxR%aG5kgz%7|BGgSOfEV37=gMP)3Ufwu%GbJ|YmU zQDvvZE$au5qBT_OdXZ{HR*F=-qZFb^-E<$4=9N*9MBG`|p8?b4#44NBC!ijj3{{!4 zJ$O9SgZt=xuQD^g_29~E!S^1#;oo|2cj9c7`9lx>WaAG#xH56U(SP>fVH$U#wEm$7 zr<`{Bp4LOC?-wTUz2c7-CakWp&C?i=j|#;oV4|?GQC)npG6>AJJ<^yhV5%nEO~)9G zA#N8IH&Np-WPl$;j2Fyap}@1;szK>kLv@hO$~owp@8g#6SsLWr0;_Bu*v!r-!6#bM zjR5;psZP!Vm^z-NbKC43*KeXEeA1brw5FDtdTZFJc~JNwJO&Nwxz$O#SFX!-KRul} zUlpQ`?rmg%0iS@dFt;OGUmAQQK~eU34yJ9wrWqAK$+~R;5G9skZ^HE}VT`&(Yq<=@ z9%H}zTM42+ufgUr^J22zB}msj&tS>t$~9WXJt*i>rA78_{r$S=maHjnwd9G*bGA`C zb1K#gZ}{jC!fOWZGk9w@o&Q=M^Q0^G`lk=dwVgdzb&=Fu0((DELQo=Aig+nYtAmI1 zte)v^5FNZtrSysy>lq5s)G(d8@O&f>p4y}kmpG6XhJ>sJ=k;Tu;;Wo Uo4mW+cEx`e&ZIfig9R-AFDwVRbN~PV literal 0 HcmV?d00001 diff --git a/sites/all/modules/watcher/images/send_email_from_enabled_to_disabled_ani.gif b/sites/all/modules/watcher/images/send_email_from_enabled_to_disabled_ani.gif new file mode 100644 index 0000000000000000000000000000000000000000..c0e4dcbd7f71e3395001a9ee1422ab00e6ca7fc6 GIT binary patch literal 7236 zcma)=3sh2h+x9mHaSK#iGX*sR$pp2+G*hwyJfvi$b~3ZV!;ob;I#y!`8$eVvG@K|k zN%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y9Hi1;J#;>NW#Yj45n86}T9Z$auHO%6`;lPt? z8M?+}FFT6Fq@EfNkbboNO}<`|xbR}^sP69dD`PLFt!_g@eN4hvi~h?9kg!GnJq)oD zumOqpZ_zhb)_8*^|&tTnv_ftb6@7*xYXa4Gn$HF>%HsYJ|b z8J?=<1=_nz(E*UmABDGJ^~megd$&}<&702<=n7#;$n~UQjXp{ZBBbO!gep??t2@%q zf23J^34};wOR3ohiE&t4<{bMj#XLve@xY|zb2mM{SAYeIvtrvuCd4Rp!q>I9w>|kY z!>erjFTB@JR-KIP2(CJyGyAe(_Hov2x-nGViBx_j;I0`a2l{c)kw{mN+{ZgHmG*M3FyXTRbw-LIhY0oMQ1uULrwt6yQo zz@6Q{`xSm4>-2y1D<1#VulU^z_(yO?z^weei(@6A12j9@yG#V|jF=tdj&8|3xwE@M zbEZSka!UXEh={)p` z(AEM6bsHVX?U@IDdOK`Q#B=KHV+=~v#+$7NjOvXMe4{G#8!Ya-{TJPUVk2=)}W(SvAx)XA*j%z=C>~lt_?OWk2?nIW( z9fvnOkr(-*v+?@mSWojw)Pe`e}_>J9U*$YqxlYrgfe1YTtQuTtl+szJ`ZM zhvk`XTR2NkkJJC8)n!a)h_qVUNe>nD-^rqwcDB|s5y%sS1r((z(0>QslDuD-&9mpX*UKl7xq27iLh`=fl|v_= zqCsWmjE>%|EdLSbrkw|4uedpO&ZcE0so~wUUX7u6Lt4xv zqAdUgQl%YEpHn7ZEPjg55_+9^ZqpY(!6J~clq`^yfD06pt&5~utliT%cg4mJX>c=X z=c5QiK@zx`gxJy!Htxu#1aNhBF$Fz$g!(ET9v>tcukLC-yD9>a0P3Zw)md(ED9w&2 z&R+D5QIV^b^)-|R(+1)En7s$%*88y-t{c=n7|3|vP`-E(7IB{Jtr{}W*CfMr!{&X{ zg~HKcIFtg={=$ Hm9G3BbtS29 literal 0 HcmV?d00001 diff --git a/sites/all/modules/watcher/images/stop_watching.png b/sites/all/modules/watcher/images/stop_watching.png new file mode 100644 index 0000000000000000000000000000000000000000..0e0953c73c60adbbc762d0553f95a586f3054aa6 GIT binary patch literal 655 zcmV;A0&x9_P)Cml&2>S!-Vj|(%DY|xv2rmiUs+--iLl+4{ z?G|A~=Ohg>vv9>N%M}DMW!>HPeV%zbm|I~4O9R8eF!SL%Uk3g&6hQCgwr&w;ys}lf zIX1F%*Xv2Q_jYug8SU>IsAzqBV(1P`&UnCRf8PMZ!;e^5{(|GUxUTch+I8+M7rU?V zW_t34vrC+PH%AZz1VKm`?q)<3MMP26&l(YiA-R=YS&0X*u<(|l`}Zn3VP^W}j)^_# z_6NY#uC7z$Rx^mTh**raXl*fCh+`p13_7uhfHnqW4A$CV1<;djx7Tl^S>Kr5@mDOH z8zq#g#&c^~-&kgAv%q#=W$W-maC!CHfe5XaxietSj|8I1&`<#3&|j$e*lNa`-i+0@!$Xe002ovPDHLkV1g_FA-@0s literal 0 HcmV?d00001 diff --git a/sites/all/modules/watcher/images/unwatch.gif b/sites/all/modules/watcher/images/unwatch.gif new file mode 100644 index 0000000000000000000000000000000000000000..0d65a9a86d0a2202af507a7f42818cb9d7eb7741 GIT binary patch literal 401 zcmZ?wbhEHb6krfwxXQpV|ICYruRk1n^y>TfAD8bx|M21C_G_=+fBE_I&%c8YzPxz* z@#)j2TW@_@cKQ9*d*7eD|90lt_tocLT)6-0%g?_z-~PP&^27iC|F1s#@a+5d-8bH? zz50If#rOB#{rLFf@5Lt{_TT?j6nxv9>`A&Z0j7lFBml%m`Ssx809#baQZDj>}jIl%iVnNOqo-U;*;hReCl3F zi>)Qv)VMg56nIpaxy1P;dL&dOS-51}InV&Mk&Qe1zsLGMn*Xv-kWK%3W^?z3YVN68LR=Nm7S^p literal 0 HcmV?d00001 diff --git a/sites/all/modules/watcher/images/watch.gif b/sites/all/modules/watcher/images/watch.gif new file mode 100644 index 0000000000000000000000000000000000000000..ec28d693752c01cacb0ad037fb364921941c572a GIT binary patch literal 616 zcmZ?wbhEHb6krfwc*ek>prEk+>YJ=3mz=wg$`|ige(uHN7q6o>PEGHszxMRg@!K!u zRvLBf-1g(gkHD#?n>SwPN|h_wyn5G-H&36x%vgB-#g{)?)qA#Fcy8oj^#A|=yRW|V z?YY;rwacsT*qMhPi#FYU_WoPq{I;?+*TQF>HElZJGwI~jhc7C&oIZH(^TUsSHeY`5 z_Uo^=Z{Kab{(jo78`t0dT6O-#*PnknHeIP$dwu`ar-yF7x%l#D(Bu;r@4wPnt&=kE z-0M$2@4xxhvh~{g?|%*I_C0_5Y5(0%6`SsuH6J|k;LFy_k0&2^#4vP#;!hSvb_PiX z9gvejal*iUv_Y~-Qh{HVg+-QMp}CjeUPN3i8ZXSzgaY*cjU=2g{cFgcohjKPIDEk;I! HgTWdAJPyp^ literal 0 HcmV?d00001 diff --git a/sites/all/modules/watcher/js/watcher.js b/sites/all/modules/watcher/js/watcher.js new file mode 100644 index 0000000..47ab69b --- /dev/null +++ b/sites/all/modules/watcher/js/watcher.js @@ -0,0 +1,166 @@ +/** + * Watcher JavaScript + * + * By Jakob Persson of NodeOne + */ + +/** + * Register Watcher behavior + */ +Drupal.behaviors.watcher = function (context) { + $('.watcher_binder_send_email_status_icon:not(.watcher-processed)', context) + .click( function () { + ajaxToggleEmailNotifications(this, this.href); + return false; + }) + .addClass('watcher-processed'); + $('.watcher_node_toggle_watching_link:not(.watcher-processed)', context) + .click( function () { + ajaxToggleWatchFade(this, this.href); + return false; + }) + .addClass('watcher-processed'); +} + + +/******************************************************************** + * EMAIL NOTIFICATION TOGGLE + ********************************************************************/ + +/** + * Handles the AJAX toggle request for email notifications + * @param {Object} el The element that triggered the request. + * @param {Object} url The URL to call. + */ +function ajaxToggleEmailNotifications(el, url) { + toggleEmailIconStatusAni(el, false); + $.ajax({ + url: url, + type: 'GET', + data: { async : 'true' }, + dataType: 'json', + timeout: 4000, //set very high to prevent time outs for users with high latency connections + success: function (json) { + toggleNotificationStatus(el, json); + }, + complete: function (json) { + toggleEmailIconStatusAni(el, true); + } + }); +} + +/** + * Toggle email notification status icon + * + * @param {Object} el The element to modify + * @param {Object} rdata A JSON object containing the results of the AJAX request + */ +function toggleNotificationStatus(el, rdata) { + var string_text_enabled = Drupal.settings.watcher.binder_notif_text_enabled; + var string_text_disabled = Drupal.settings.watcher.binder_notif_text_disabled; + var string_title_enabled = Drupal.settings.watcher.binder_notif_title_enabled; + var string_title_disabled = Drupal.settings.watcher.binder_notif_title_disabled; + + if (rdata['status'] == 'enabled') { + $(el).empty().append(string_text_enabled).attr('email_status','enabled').attr('title', string_title_enabled); + } else { + $(el).empty().append(string_text_disabled).attr('email_status','disabled').attr('title', string_title_disabled); + } +} + +/** + * Display an animation to convey to the user that the action has not gone unnoticed + * + * @param {Object} el The element to modify + */ +function toggleEmailIconStatusAni(el, stop) { + if(stop) { + $(el).removeClass('watcher_binder_send_email_status_icon_from_disabled_to_enabled'); + $(el).removeClass('watcher_binder_send_email_status_icon_from_enabled_to_disabled'); + if($(el).attr('email_status')=='enabled') { + $(el).addClass('watcher_binder_send_email_status_icon_enabled'); + $(el).removeClass('watcher_binder_send_email_status_icon_disabled'); + } else { + $(el).addClass('watcher_binder_send_email_status_icon_disabled'); + $(el).removeClass('watcher_binder_send_email_status_icon_enabled'); + } + return true; + } + + if($(el).attr('email_status')=='enabled') { + $(el).addClass('watcher_binder_send_email_status_icon_from_enabled_to_disabled'); + } else { + $(el).addClass('watcher_binder_send_email_status_icon_from_disabled_to_enabled'); + } +} + + +/******************************************************************** + * WATCH TOGGLE + ********************************************************************/ + +/** + * Handles the AJAX toggle request for watching + * @param {Object} el The element that triggered the request. + * @param {Object} url The URL to call. + */ +function ajaxToggleWatchFade(el, url) { + // Fade out the element + $(el).fadeTo(400, 0.01, function(){ + ajaxToggleWatch(el, url) + }); +} + +/** + * Handles the AJAX toggle request for email notifications + * @param {Object} el The element that triggered the request. + * @param {Object} url The URL to call. + */ +function ajaxToggleWatch(el, url) { + $.ajax({ + url: url, + type: 'GET', + data: { async : 'true' }, + dataType: 'json', + timeout: 4000, //set very high to prevent time outs for users with high latency connections + success: function (json) { + toggleWatch(el, json); + }, + error: function(json){ + $(el).fadeTo(400, 1); + } + }); +} + +/*** + * Toggle the watching of a node + */ +function toggleWatch(el, rdata) { + var string_text_enabled = Drupal.settings.watcher.watch_toggle_enabled; + var string_title_enabled = Drupal.settings.watcher.watch_toggle_enabled_title; + var string_text_disabled = Drupal.settings.watcher.watch_toggle_disabled; + var string_title_disabled = Drupal.settings.watcher.watch_toggle_disabled_title; + var string_watched_posts_link = Drupal.settings.watcher.watch_watched_posts_link; + + if (rdata['status'] == 'enabled') { + $(el).empty().append(string_text_enabled).attr('title', string_title_enabled).addClass('watcher_node_toggle_watching_link_watched'); + $(el).parent().addClass('watcher_node_watched'); + } + else if (rdata['status'] == 'disabled') { + $(el).empty().append(string_text_disabled).attr('title', string_title_disabled).removeClass('watcher_node_toggle_watching_link_watched'); + $(el).parent().removeClass('watcher_node_watched'); + } + else { + $(el).parent().fadeOut('fast').replaceWith(rdata['data']).fadeIn('fast'); + } + + //Append link to user's list of watched posts if it doesn't already exist + var parent = $(el).parent(); + if ($(parent).find('a.watcher_node_help_link_to_binder').length == 0) { + $(parent).addClass('watcher_node_toggle_watching_link_with_link_to_binder').append(string_watched_posts_link); + } + + + // Fade in, display the element again + $(el).fadeTo(400, 1); +} \ No newline at end of file diff --git a/sites/all/modules/watcher/translations/watcher.pot b/sites/all/modules/watcher/translations/watcher.pot new file mode 100644 index 0000000..a22d334 --- /dev/null +++ b/sites/all/modules/watcher/translations/watcher.pot @@ -0,0 +1,775 @@ +# $Id: watcher.pot,v 1.1.2.4 2009/02/07 19:30:12 solipsist Exp $ +# +# LANGUAGE translation of Drupal (general) +# Copyright YEAR NAME +# Generated from files: +# watcher.module,v 1.2.2.6.2.14 2009/01/30 11:07:32 solipsist +# watcher.info,v 1.2.4.1 2009/01/09 19:19:22 solipsist +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2009-02-07 19:05+0100\n" +"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" +"Last-Translator: NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + +#: watcher.module:126 +msgid "Stop watching" +msgstr "" + +#: watcher.module:132 +msgid "Stop watching this post." +msgstr "" + +#: watcher.module:630 +msgid "Watchable Content Types" +msgstr "" + +#: watcher.module:631 +msgid "Select the content types that may be watched." +msgstr "" + +#: watcher.module:639 +msgid "You haven't selected any watchable content types. This module will not work until you do so." +msgstr "" + +#: watcher.module:653 +msgid "Watch Toggle Link" +msgstr "" + +#: watcher.module:660 +msgid "Display \"watch this post\" toggle link in teasers." +msgstr "" + +#: watcher.module:661 +msgid "Determines whether or not to show the \"watch this post\" toggle link in node teasers (used on front page and content listings). Teasers are the shortened down version of a node, often shown on a site's frontpage or on pages that summarize content. If disabled, link will only be shown when nodes are shown as pages (full view)." +msgstr "" + +#: watcher.module:669 +msgid "Display Settings for Personal Binder" +msgstr "" + +#: watcher.module:675 +msgid "Click here to view your personal binder" +msgstr "" + +#: watcher.module:680 +msgid "Text at the top of the Personal Binder page" +msgstr "" + +#: watcher.module:681 +msgid "You are recommended to use this space to display brief information about what this page does and how it works to the user." +msgstr "" + +#: watcher.module:688 +msgid "Settings for the table of posts" +msgstr "" + +#: watcher.module:693 +msgid "Display Node Type Column" +msgstr "" + +#: watcher.module:699 +msgid "Display Last Updated Column" +msgstr "" + +#: watcher.module:705 +msgid "Display Post Author Column" +msgstr "" + +#: watcher.module:713 +msgid "Settings for Email Notifications" +msgstr "" + +#: watcher.module:724 +msgid "Enable Email Notifications" +msgstr "" + +#: watcher.module:734 +msgid "Messages are sent" +msgstr "" + +#: watcher.module:735 +msgid "You can select when messages are sent. Using \"on cron\", messages are sent when cron is being run, usually every hour depending on how you have configured crontab, this is preferred for large sites with hundreds of users or more. Using the second method, messages are sent right away for the time limit set (see below). Any messages that remain unsent will be sent next time messages are sent. The second method won't affect loading times since messages are sent after the page has been delivered to the user's browser." +msgstr "" + +#: watcher.module:738 +msgid "on cron (recommended for large sites)" +msgstr "" + +#: watcher.module:739 +msgid "instantaneously and for limited number of seconds (recommended for small to medium sites)" +msgstr "" + +#: watcher.module:751 +msgid "unlimited" +msgstr "" + +#: watcher.module:756 +msgid "Time limit for sending messages in seconds" +msgstr "" + +#: watcher.module:757 +msgid "This setting lets you specify for how many seconds messages should be sent and it applies to both methods. Any messages that remain unsent after this interval will be sent next time messages are sent. This setting will not make your site seem slower to visitors. The maximum value is the max execution time in your PHP configuration." +msgstr "" + +#: watcher.module:765 +msgid "Limit length of comment excerpt in notification email to" +msgstr "" + +#: watcher.module:766 +msgid "It may be wise not to send the entire comment as doing so will tease the user to go to your site to view it which results in traffic. Here you can select how much of the comment you want to include in the email. Percentages refer to the length of the comment. \"Nothing\" means no excerpt will be included in the message." +msgstr "" + +#: watcher.module:769 +msgid "nothing" +msgstr "" + +#: watcher.module:770 +msgid "25% of comment" +msgstr "" + +#: watcher.module:771 +msgid "50% of comment" +msgstr "" + +#: watcher.module:772 +msgid "75% of comment" +msgstr "" + +#: watcher.module:773 +msgid "100 characters of comment" +msgstr "" + +#: watcher.module:774 +msgid "200 characters of comment" +msgstr "" + +#: watcher.module:775 +msgid "300 characters of comment" +msgstr "" + +#: watcher.module:776 +msgid "400 characters of comment" +msgstr "" + +#: watcher.module:777 +msgid "entire comment" +msgstr "" + +#: watcher.module:783 +msgid "Notification Message Templates" +msgstr "" + +#: watcher.module:784 +msgid "These message templates are used for notifications and confirmation messages. You may edit them if you like. Tokens are in [brackets] and act as placeholders for variables, such as URLs, usernames and email addresses, and will be replaced when the email is sent. You cannot use HTML code in your message templates." +msgstr "" + +#: watcher.module:793 +msgid "Message Header" +msgstr "" + +#: watcher.module:795 +msgid "

The text above will be prepended to every message sent. The following tokens are available:

  • [recipient-username]
  • [recipient-user-settings-url]
  • [stop-watching-url]
" +msgstr "" + +#: watcher.module:800 +msgid "Additional Tokens for Header" +msgstr "" + +#: watcher.module:813 +msgid "Message Footer" +msgstr "" + +#: watcher.module:815 +msgid "

The text above will be appended to every message sent. The following tokens are available:

  • [recipient-username]
  • [recipient-user-settings-url]
  • [stop-watching-url]
" +msgstr "" + +#: watcher.module:820 +msgid "Message Footer for Anonymous Users" +msgstr "" + +#: watcher.module:822 +msgid "

The text above will be appended to notification messages messages sent to anonymous users. The following tokens are available:

  • [stop-watching-url]
  • [stop-watching-url]
  • [stop-watching-all-url]
" +msgstr "" + +#: watcher.module:827 +msgid "Message Footer in Confirmation Messages" +msgstr "" + +#: watcher.module:829 +msgid "

The text above will be appended to confirmation messages sent to anonymous users when they start watching a node. Links for stopping watching this or every node the user watches and user's IP address are automatically prepended to this text.

  • [user-ip]
  • [stop-watching-url]
  • [stop-watching-all-url]
" +msgstr "" + +#: watcher.module:834 +msgid "Additional Tokens for Footers" +msgstr "" + +#: watcher.module:847 +msgid "Message Body for Node Updates" +msgstr "" + +#: watcher.module:849 +msgid "

The following tokens are available:

  • [node-url]
" +msgstr "" + +#: watcher.module:854 +msgid "Additional Tokens for Nodes" +msgstr "" + +#: watcher.module:867 +msgid "Message Body for New Comments" +msgstr "" + +#: watcher.module:869 +msgid "

The following tokens are available:

  • [comment-excerpt]
  • [node-url]
  • [comment-url]
  • [comment-reply-url]
" +msgstr "" + +#: watcher.module:874 +msgid "Additional Tokens for Comments" +msgstr "" + +#: watcher.module:887 +msgid "Message Body for Confirmation Messages" +msgstr "" + +#: watcher.module:889 +msgid "

The text above will be included in confirmation messages sent to anonymous users when they start watching a node.:

The following tokens are available:

  • [node-url]
" +msgstr "" + +#: watcher.module:899 +msgid "Default User Settings" +msgstr "" + +#: watcher.module:900 +msgid "These will set the defaults in every user's personal settings. Settings you make here will affect the settings of every user that hasn't customized his or her settings. This setting will currently affect !numusers users who have not customized their settings." +msgstr "" + +#: watcher.module:909;1394 +msgid "Automatically enable email notifications for posts that I start watching" +msgstr "" + +#: watcher.module:910;1404 +msgid "Send email notification when a post is updated or edited" +msgstr "" + +#: watcher.module:911;1410 +msgid "Send email notification when a post receives a new comment" +msgstr "" + +#: watcher.module:912;1425 +msgid "Automatically watch posts that I comment on" +msgstr "" + +#: watcher.module:913;1431 +msgid "Automatically watch posts that I make" +msgstr "" + +#: watcher.module:914;1445 +msgid "Share my list of watched posts" +msgstr "" + +#: watcher.module:922 +msgid "Help Page" +msgstr "" + +#: watcher.module:923 +msgid "This help text is displayed if the user clicks the Help link in the list of watched posts. You can customize it below. To apply your own CSS rules to this page you can use the #watcher_help_page selector." +msgstr "" + +#: watcher.module:930 +msgid "Text on Help Page" +msgstr "" + +#: watcher.module:936 +msgid "Preview help page" +msgstr "" + +#: watcher.module:958 +msgid "Notification Queue Table" +msgstr "" + +#: watcher.module:963 +msgid "Number of notifications in queue" +msgstr "" + +#: watcher.module:964 +msgid "Notification counter (some kind of indication of how many notifications that have been sent)" +msgstr "" + +#: watcher.module:974 +msgid "Table Content" +msgstr "" + +#: watcher.module:975 +msgid "This is the content of the notification queue table." +msgstr "" + +#: watcher.module:985 +msgid "There are no notifications in the queue." +msgstr "" + +#: watcher.module:994 +msgid "Watched Nodes Table" +msgstr "" + +#: watcher.module:998 +msgid "Number of registered users that watch nodes" +msgstr "" + +#: watcher.module:999 +msgid "Number of anonymous users that watch nodes" +msgstr "" + +#: watcher.module:1013 +msgid "User Settings Table" +msgstr "" + +#: watcher.module:1017 +msgid "Number of users that have changed their user settings" +msgstr "" + +#: watcher.module:1018 +msgid "Number of users that use default user settings" +msgstr "" + +#: watcher.module:1041 +msgid "Email notifications are NOT enabled. You can use the diagnostics tools anyway but regular notifications will not be sent." +msgstr "" + +#: watcher.module:1046 +msgid "If you're experiencing problems with the module such as messages not being delivered et c, you can use the diagnostic tools on this page to send test notifications. The statistics page also contains valuable information for troubleshooting." +msgstr "" + +#: watcher.module:1051 +msgid "Create a Test Notification" +msgstr "" + +#: watcher.module:1052 +msgid "Click the buttons below to add a notification to the queue. A notification for a new comment will use content from the newest comment on the site. A notification for a node update will contain a link to the newest node on the site. Notifications will be sent to your email account (!usermail)." +msgstr "" + +#: watcher.module:1057 +msgid "Create test notification for node update" +msgstr "" + +#: watcher.module:1063 +msgid "Create test notification for new comment" +msgstr "" + +#: watcher.module:1069 +msgid "Send Notifications in Queue" +msgstr "" + +#: watcher.module:1070 +msgid "Notifications are stored in a queue. Depending on what method you have chosen in the settings, notifications are either delivered instantaneously (when a comment is posted or a node updated) or when cron is run." +msgstr "" + +#: watcher.module:1076 +msgid "Your currently selected method for sending notifications in queue is !method." +msgstr "" + +#: watcher.module:1082 +msgid "There are currently !num !notification_plural in the queue." +msgstr "" + +#: watcher.module:1088 +msgid "Click here to run cron manually and SEND messages in queue" +msgstr "" + +#: watcher.module:1094 +msgid "Click here to SEND messages in queue" +msgstr "" + +#: watcher.module:1105 +msgid "Click here to EMPTY queue" +msgstr "" + +#: watcher.module:1125 +msgid "TEST: Post has been updated" +msgstr "" + +#: watcher.module:1127 +msgid "A test notification (node update) has been created." +msgstr "" + +#: watcher.module:1131 +msgid "No nodes exist. You need to create at least one." +msgstr "" + +#: watcher.module:1147 +msgid "TEST: New comment posted" +msgstr "" + +#: watcher.module:1149 +msgid "A test notification (new comment) has been created." +msgstr "" + +#: watcher.module:1153 +msgid "No comments exist. You need to make at least one." +msgstr "" + +#: watcher.module:1162 +msgid "Notifications have been sent using instant method." +msgstr "" + +#: watcher.module:1170 +msgid "Watcher Notification Queue has been emptied." +msgstr "" + +#: watcher.module:1200 +msgid "!username's Watched Posts" +msgstr "" + +#: watcher.module:1205 +msgid "Click to Disable" +msgstr "" + +#: watcher.module:1206 +msgid "Click to Enable" +msgstr "" + +#: watcher.module:1207 +msgid "Email notifications for this post are ENABLED, click to disable" +msgstr "" + +#: watcher.module:1208 +msgid "Email notifications for this post are DISABLED, click to enable" +msgstr "" + +#: watcher.module:1224 +msgid "Type" +msgstr "" + +#: watcher.module:1229 +msgid "Post" +msgstr "" + +#: watcher.module:1236 +msgid "Author" +msgstr "" + +#: watcher.module:1243 +msgid "Post Added" +msgstr "" + +#: watcher.module:1251 +msgid "Last updated" +msgstr "" + +#: watcher.module:1257 +msgid "Comments" +msgstr "" + +#: watcher.module:1261 +msgid "Notifications" +msgstr "" + +#: watcher.module:1266 +msgid "Remove" +msgstr "" + +#: watcher.module:1301;1305 +msgid "!time ago" +msgstr "" + +#: watcher.module:1331 +msgid "No posts in the list - you should add some!" +msgstr "" + +#: watcher.module:1331 +msgid "!username's watched posts list is empty" +msgstr "" + +#: watcher.module:1366 +msgid "Settings for Watching Posts" +msgstr "" + +#: watcher.module:1375 +msgid "Your settings are currently defaults, as set by the site owner. Save these settings to customize them." +msgstr "" + +#: watcher.module:1387 +msgid "Email Notification Settings" +msgstr "" + +#: watcher.module:1418 +msgid "Watch Automatically" +msgstr "" + +#: watcher.module:1437 +msgid "Sharing" +msgstr "" + +#: watcher.module:1438 +msgid "By sharing your list of watched posts, other users can see it but they cannot remove or add posts or change it in any way." +msgstr "" + +#: watcher.module:1456 +msgid "Save my settings" +msgstr "" + +#: watcher.module:1471 +msgid "Help on Watching Posts" +msgstr "" + +#: watcher.module:1539 +msgid "%ntitle previously watched by %email is no longer being watched." +msgstr "" + +#: watcher.module:1556 +msgid "Are you sure you want to STOP watching all posts %email currently watches on this site? This action cannot be undone." +msgstr "" + +#: watcher.module:1575 +msgid "All posts on this site previously watched by %email are no longer being watched." +msgstr "" + +#: watcher.module:1604 +msgid "You are no longer watching !ntitle. Undo" +msgstr "" + +#: watcher.module:1608;1617 +msgid "We're sorry but you may not watch this type of post." +msgstr "" + +#: watcher.module:1613 +msgid "You are now watching !ntitle. Undo" +msgstr "" + +#: watcher.module:1729 +msgid "Post!nodetitlehas been updated!sitename" +msgstr "" + +#: watcher.module:1802 +msgid " about \"!nodetitle\"" +msgstr "" + +#: watcher.module:1804 +msgid "New comment posted!aboutnodetitle!sitename" +msgstr "" + +#: watcher.module:1875 +msgid "for updates and new comments" +msgstr "" + +#: watcher.module:1876 +msgid "for new comments" +msgstr "" + +#: watcher.module:1877 +msgid "for updates" +msgstr "" + +#: watcher.module:1880 +msgid " \"!nodetitle\"" +msgstr "" + +#: watcher.module:1882 +msgid "You are now watching!aboutnodetitle!forwhat!sitename" +msgstr "" + +#: watcher.module:2064 +msgid "You are watching this post, click to stop watching" +msgstr "" + +#: watcher.module:2065 +msgid "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)" +msgstr "" + +#: watcher.module:2066 +msgid "You are not watching this post, click to start watching" +msgstr "" + +#: watcher.module:2067 +msgid "Watch posts to be notified when other users comment on them or the posts are changed" +msgstr "" + +#: watcher.module:2070 +msgid "Go to your list of watched posts" +msgstr "" + +#: watcher.module:2114 +msgid "Settings saved." +msgstr "" + +#: watcher.module:2843 +msgid "The confirmation message contains your IP address so that in case of abuse the owner of the email account can identify who submitted the form." +msgstr "" + +#: watcher.module:2851 +msgid "Stop watching %title" +msgstr "" + +#: watcher.module:2853 +msgid "Enter your email address below to stop watching %title. The form will remember the email you enter until next time." +msgstr "" + +#: watcher.module:2858 +msgid "Watch %title" +msgstr "" + +#: watcher.module:2860 +msgid "Enter your email address below to start watching %title. The form will remember the email you enter until next time. Once you submit the form, a confirmation message will be sent to the email address entered. %ipinfo" +msgstr "" + +#: watcher.module:2870 +msgid "Your email address" +msgstr "" + +#: watcher.module:2882 +msgid "What to watch for" +msgstr "" + +#: watcher.module:2884 +msgid "Updates and new comments" +msgstr "" + +#: watcher.module:2885 +msgid "Only new comments" +msgstr "" + +#: watcher.module:2886 +msgid "Only updates" +msgstr "" + +#: watcher.module:2889 +msgid "Choose to be informed about new comments, updates (this post being changed) or both." +msgstr "" + +#: watcher.module:2897 +msgid "Watch" +msgstr "" + +#: watcher.module:2897 +msgid "Unwatch" +msgstr "" + +#: watcher.module:3025 +msgid "You are no longer watching %ntitle. Undo" +msgstr "" + +#: watcher.module:3036 +msgid "That email address is not associated with any user watching %ntitle" +msgstr "" + +#: watcher.module:3044 +msgid "updates and new comments" +msgstr "" + +#: watcher.module:3045 +msgid "new comments" +msgstr "" + +#: watcher.module:3046 +msgid "updates" +msgstr "" + +#: watcher.module:3048 +msgid "You are now watching %ntitle for !what. A message will be sent to the email address you entered (%email) to confirm this action." +msgstr "" + +#: watcher.module:3081 +msgid "You must enter a valid e-mail address." +msgstr "" + +#: watcher.module:587;2715;2718;368 watcher.info:0 +msgid "Watcher" +msgstr "" + +#: watcher.module:587 +msgid "Notifications were sent on cron." +msgstr "" + +#: watcher.module:2715 +msgid "Watcher has successfully sent !notifications using the !method method." +msgstr "" + +#: watcher.module:2718 +msgid "Watcher failed to send notifications using the !method method." +msgstr "" + +#: watcher.module:1082 +msgid "notification" +msgid_plural "notifications" +msgstr[0] "" +msgstr[1] "" + +#: watcher.module:2430 +msgid "1 new" +msgid_plural "@count new" +msgstr[0] "" +msgstr[1] "" + +#: watcher.module:2715 +msgid "1 notification" +msgid_plural "@count notifications" +msgstr[0] "" +msgstr[1] "" + +#: watcher.module:253 +msgid "administer watcher" +msgstr "" + +#: watcher.module:253 +msgid "use watcher" +msgstr "" + +#: watcher.module:253 +msgid "access others' lists of watched posts" +msgstr "" + +#: watcher.module:287;402 +msgid "My Watched Posts" +msgstr "" + +#: watcher.module:296 +msgid "Watched Posts" +msgstr "" + +#: watcher.module:306;377 +msgid "Settings" +msgstr "" + +#: watcher.module:316 +msgid "Help" +msgstr "" + +#: watcher.module:327 +msgid "Watcher Toggle Watching Post" +msgstr "" + +#: watcher.module:336 +msgid "Watcher Toggle Email Notifications" +msgstr "" + +#: watcher.module:369 +msgid "Modify the settings for Watcher module." +msgstr "" + +#: watcher.module:385 +msgid "Statistics" +msgstr "" + +#: watcher.module:393 +msgid "Testing" +msgstr "" + +#: watcher.module:0 +msgid "watcher" +msgstr "" + +#: watcher.info:0 +msgid "Watcher enables your site's users to watch nodes for changes and new comments and be notified about them." +msgstr "" + +#: watcher.info:0 +msgid "Other" +msgstr "" + diff --git a/sites/all/modules/watcher/watcher.db.inc b/sites/all/modules/watcher/watcher.db.inc new file mode 100644 index 0000000..661c0c0 --- /dev/null +++ b/sites/all/modules/watcher/watcher.db.inc @@ -0,0 +1,659 @@ + + * With ideas and feedback from Hans Dekker of Wordsy.com + * + * are updated or commented on. + * + * Sponsored by + * Wordsy - www.wordsy.com + * NodeOne - www.nodeone.se + */ + +/*************************************************************************************** + * DECLARATION OF CONSTANTS + ***************************************************************************************/ + +// Values for "watch_for" column in database +define('WATCHER_WATCH_FOR_ALL', 1); +define('WATCHER_WATCH_FOR_COMMENTS', 2); +define('WATCHER_WATCH_FOR_UPDATES', 3); + +/*************************************************************************************** + * DATABASE FUNCTIONS + ***************************************************************************************/ + +/** + * Returns a wealth of information on the nodes a user is watching + * Results are pageable + * + * @param $user + * User object of the user whose binder we want posts for + * @param $header + * The table header array, used for table sorting + * @return + * A paged database result resource + */ +function _watcher_db_get_watched_nodes_full($user = false, $header = null) { +// Taken from tracker.module +// TODO: These queries are very expensive, see http://drupal.org/node/105639 + if ($user->uid) { + $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, wn.send_email, wn.added, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {watcher_nodes} wn ON n.nid = wn.nid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND wn.uid = %d'; + $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) INNER JOIN {watcher_nodes} wn ON n.nid = wn.nid WHERE n.status = 1 AND wn.uid = %d AND wn.uid = %d'; + if ($header) { + $sql .= tablesort_sql($header); + } + $sql = db_rewrite_sql($sql); + $sql_count = db_rewrite_sql($sql_count); + $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $user->uid, $user->uid, $user->uid); + return $result; + } +} + +/** + * Returns minimal information on the nodes a user is watching + * + * @param $user + * User object of the user whose watched posts we want + * + * @return + * A database result resource + */ +function _watcher_db_get_watched_nodes_mini($user) { + if ($user->uid) { + $sql = 'SELECT DISTINCT(nid) FROM {watcher_nodes} WHERE uid = %d'; + } + else { + $sql = "SELECT DISTINCT(nid) FROM {watcher_nodes} WHERE mail = '%s'"; + } + $result = db_query($sql, ( $user->uid ? $user->uid : $user->mail )); + return $result; +} + +/** + * Get NIDs by UID + * see what posts a user is watching + * + * @param $uid + * UID - a user id. + * @return + * A database result set of matching table rows. + */ +function _watcher_db_get_nids_by_uid($uid) { + $sql = 'SELECT nid FROM {watcher_nodes} WHERE uid = %d'; + $result = db_query($sql, $uid); + while($row = db_fetch_object($result)) { + return $result; + } + return false; +} + +/** + * Get UIDs by NID + * see what users are watching a post + * + * @param $nid + * NID - a node id. + * @return + * A database result set of matching table rows. + */ +function _watcher_db_get_uids_by_nid($nid) { + $sql = 'SELECT uid FROM {watcher_nodes} WHERE nid = %d'; + $result = db_query($sql, $nid); + while ($row = db_fetch_object($result)) { + return $result; + } + return false; +} + +/** + * Get NIDs by user + * see what posts a user is watching + * + * @param $user + * A user object + * @return + * An array of NIDs with NIDs as keys and values + */ +function _watcher_db_get_nids_by_user($user) { + if ($user->uid) { + $sql = 'SELECT nid FROM {watcher_nodes} WHERE uid = %d'; + $result = db_query($sql, $user->uid); + } + else { + $sql = "SELECT nid FROM {watcher_nodes} WHERE mail = '%s'"; + $result = db_query($sql, $user->mail); + } + + while ($row = db_fetch_object($result)) { + $nids[$row->nid] = $row->nid; + } + + return $nids; +} + +/** + * Is user watching NID + * check if a specific user is watching the given node + * + * @param $user + * A user object. + * @param $nid + * A node NID + * + * @return + * A database result set of matching table rows. + */ +function _watcher_db_get_user_nid($user, $nid) { + if (!$user->uid) { + $sql = "SELECT mail FROM {watcher_nodes} WHERE mail = '%s' AND nid = %d"; + $result = db_query($sql, $user->mail, $nid); + } + else { + $sql = 'SELECT uid FROM {watcher_nodes} WHERE uid = %d AND nid = %d'; + $result = db_query($sql, $user->uid, $nid); + } + + while($row = db_fetch_object($result)) { + return $result; + } + return false; +} + +/** + * Add NID to UID's watch list, enable email notifications if desired + * + * @param $nid + * The nid of the node the users is going to watch + * @param $user + * A user object + * @param $what + * A string indicating what an anonymous user watches for: all, comments, updates + * + * @return + * Boolean true on success + */ +function _watcher_db_set_nid_user($nid, $user, $what = null) { + + if (!$user->uid) { + // If the user is anonymous, we first remove any already existing rows and replace + // them to allow the user to alter previously set watches + $sql = "DELETE FROM {watcher_nodes} WHERE nid = %d AND uid = %d AND mail = '%s'"; + db_query($sql, $nid, $user->uid, $user->mail); + } + + if ($what) { + // Mapping integers to strings + $for['all'] = WATCHER_WATCH_FOR_ALL; + $for['comments'] = WATCHER_WATCH_FOR_COMMENTS; + $for['updates'] = WATCHER_WATCH_FOR_UPDATES; + + $sql = "INSERT INTO {watcher_nodes} (uid, mail, nid, added, watch_for) VALUES(%d, '%s', %d, %d, %d)"; + $res = db_query($sql, $user->uid, $user->mail, $nid, time(), $for[$what]); + } + else { + $sql = "INSERT INTO {watcher_nodes} (uid, nid, added) VALUES(%d, %d, %d)"; + $res = db_query($sql, $user->uid, $nid, time()); + } + + return $res; +} + +/** + * Remove NIDs from the UID's watch list + * @param $nids + * Array of node NIDs + * @param $user + * A user object. + * + * @return + * A boolean indicating success/failure + */ +function _watcher_db_delete_nids_user($nids, $user) { + if (!count($nids)) { + return; + } + $sql_in = implode(',', $nids); + if (!$user->uid) { + $sql = "DELETE FROM {watcher_nodes} WHERE mail = '%s' AND nid IN(%s)"; + $res = db_query($sql, $user->mail, $sql_in); + } + else { + $sql = 'DELETE FROM {watcher_nodes} WHERE uid = %d AND nid IN(%s)'; + $res = db_query($sql, $user->uid, $sql_in); + } + return (bool) db_affected_rows(); +} + +/** + * Delete a node from the watch list + * @param $nid + * NID of node to delete + * @return + * Boolean of success or failure + */ +function _watcher_db_delete_nid($nid) { + $sql = 'DELETE FROM {watcher_nodes} WHERE nid = %d'; + $res = db_query($sql, $nid); + return (bool) $res; +} + +/** + * Remove all NIDs on UID's watch list + * @param $uid + * UID - a user id. + * @return + * A boolean indicating success/failur + */ +function _watcher_db_delete_uid($uid) { + $sql = 'DELETE FROM {watcher_nodes} WHERE uid = %d'; + $res = db_query($sql, $uid); + return (bool) $res; +} + +/** + * Get email notification status given UID and NID + * + * @param $uid + * UID - a user id. + * @param $nid + * NID - a node id. + * @return + * Boolean True if email notifications are enabled for this user and node + */ +function _watcher_db_get_send_email_status($nid, $uid) { + $sql = 'SELECT send_email FROM {watcher_nodes} WHERE uid = %d AND nid = %d'; + $result = db_query($sql, $uid, $nid); + $row = db_fetch_object($result); + if ($row->send_email) return true; + return false; +} + +/** + * Set email notification status given NID and UID + * + * @param $nid + * NID - a node id + * @param $user + * A user object + * @param $send_email + * A boolean integer, 1 or 0 + * @return + * Boolean denoting success/failure. + */ +function _watcher_db_set_send_email_status($nid, $user, $send_email = 0) { + if ($user->uid) { + $sql = 'UPDATE {watcher_nodes} SET send_email = %d WHERE uid = %d AND nid = %d'; + $res = db_query($sql, $send_email, $user->uid, $nid); + } + else { + $sql = "UPDATE {watcher_nodes} SET send_email = %d WHERE mail = '%s' AND nid = %d"; + $res = db_query($sql, $send_email, $user->mail, $nid); + } + return ((bool) $res); +} + +/** + * Save user settings to database + * + * @param $uid + * A user UID + * @param $settings + * An associative array of user settings + * @return + * Boolean true on success + */ +function _watcher_db_set_user_settings($uid, $settings) { + + //Add custom field to mark these user settings as custom + $settings['custom'] = 1; + + //Serialize settings + $fields = implode(', ', array_keys($settings)); + $values = implode(', ', array_values($settings)); + + // First delete existing settings + $sql = 'DELETE FROM {watcher_user_settings} WHERE uid = %d'; + db_query($sql, $uid); + + // Insert new settings + $sql = 'INSERT INTO {watcher_user_settings} (uid, %s) VALUES (%d, %s)'; + $res = db_query($sql, $fields, $uid, $values); + return (bool) $res; +} + +/** + * Delete user settings for given UID + * + * @param $uid + * A user UID + * @return + * Boolean True on success + */ +function _watcher_db_delete_user_settings($uid) { + $sql = 'DELETE FROM {watcher_user_settings} WHERE uid = %d'; + $res = db_query($sql, $uid); + return (bool) $res; +} + +/** + * Load user settings from database + * + * @param $uid + * A user UID + * @return + * An assoc array of user settings + */ +function _watcher_db_get_user_settings($uid) { + // Cache settings + static $settings; + if (!isset($settings)) { + $sql = 'SELECT * FROM {watcher_user_settings} WHERE uid = %d'; + $result = db_query($sql, $uid); + while($row = db_fetch_array($result)) { + unset($row['uid']); + $settings = $row; + return $settings; + } + $settings = false; + } + return $settings; +} + +/** + * Updates the default settings for all users who haven't customized their settings + * + * @param $settings + * An associative array of settings + * @return + * A boolean true on success + */ +function _watcher_db_user_settings_update_defaults($settings) { + // Users may have registered and not had settings set yet so add rows for any users that are "missing" + $sql = 'INSERT INTO {watcher_user_settings} (uid) SELECT u.uid FROM {users} u LEFT JOIN {watcher_user_settings} wus ON u.uid = wus.uid WHERE ISNULL(custom)'; + $res = db_query($sql); + + // If defaults are set, apply them, otherwise return + if (is_array($settings)) { + // Format settings array as string + foreach ($settings as $setting => $value) { + $insert_array[] = $setting .'='. $value; + } + $insert_string = implode(', ', $insert_array); + + // Update all users who haven't customized their settings yet + $sql = 'UPDATE {watcher_user_settings} SET %s WHERE custom <> 1'; + $res = db_query($sql, $insert_string); + } + return (bool) $res; +} + +/** + * Has UID customized his/her user settings? + * + * @param $uid + * A user UID + * @return + * A boolean true if given UID has customized his/her user settings + */ +function _watcher_db_user_settings_uid_custom($uid) { + $sql = 'SELECT custom FROM {watcher_user_settings} WHERE uid = %d AND custom = 1'; + $res = db_query($sql, $uid); + while($row = db_fetch_object($res)) { + return true; + } + return false; +} + +/** + * Return a list of users that want to get notified about node updates for given NID + * + * @param $nid + * The NID of the node that has been updated + * @param $uid_exclude + * A UID we want to exclude from our set of users, normally the user that updated the node. + * @return + * An array of objects with uid as key representing users, with attributes uid, mail and name + */ +function _watcher_db_get_users_notify_node_update($nid, $uid_exclude) { + $sql = "SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND notifications_updates = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 3)))"; + $res = db_query($sql, $nid, $uid_exclude); + $users = array(); + while ($row = db_fetch_object($res)) { + $users[$row->uid] = $row; + } + return $users; +} + +/** + * Return a list of users that want to get notified about new comments for given NID + * + * @param $nid + * The nid of the node the comment belongs to + * @param $uid_exclude + * A uid we want to exclude from our set of users, normally the user that wrote the comment, + * what's the point in being notified about your own comments, eh? + * + * @return + * An array of objects with uid as key representing users, with attributes uid, mail and name + */ +function _watcher_db_get_users_notify_comment_insert($nid, $uid_exclude) { + $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND notifications_new_comments = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 2)))'; + $res = db_query($sql, $nid, $uid_exclude); + $users = array(); + while ($row = db_fetch_object($res)) { + $users[] = $row; + } + return $users; +} + +/** + * Return a list of users that want to get notified about node updates or new comments + * for a given NID + * + * @param $nid + * The nid of the node that has been updated + * @param $uid_exclude + * A uid we want to exclude from our set of users, normally the user that updated the node. + * + * @return + * An array of objects with uid as key representing users, with attributes uid, mail and name + */ +function _watcher_db_get_users_notify_about_node($nid, $uid_exclude) { + $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {users} u ON u.uid = wn.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND send_email = 1) OR (NOT ISNULL(watch_for)))'; + $res = db_query($sql, $nid, $uid_exclude); + $users = array(); + while ($row = db_fetch_object($res)) { + $users[$row->uid] = $row; + } + return $users; +} + +/** + * Add a message to the notification queue table + * + * @param $qid + * A qid (table pk) generated by db_next_id() + * @param $r_uid + * Recipient uid + * @param $r_email + * Recipient email address + * @param $subject + * The message subject + * @param $message + * Message to be sent + * @return + * A database result resource + */ +function _watcher_db_insert_users_notification_queue($r_uid, $r_email, $subject, $message) { + $sql = "INSERT INTO {watcher_notify_queue} (uid, mail, subject, message) VALUES (%d, '%s', '%s', '%s')"; + $res = db_query($sql, $r_uid, $r_email, $subject, $message); + return (bool) $res; +} + +/** + * Delete all rows in notification queue table + * + * @return + * A boolean denoting whether any rows were deleted, false if none, true if one or more + */ +function _watcher_db_delete_users_notification_queue_all() { + $sql = "DELETE FROM {watcher_notify_queue}"; + $res = db_query($sql); + return (bool) $res; +} + +/** + * Get messages from the notification queue table + */ +function _watcher_db_get_users_notification_queue() { + $sql = "SELECT * FROM {watcher_notify_queue}"; + $res = db_query($sql); + while ($qmsg = db_fetch_object($res)) { + $qmsgs[] = $qmsg; + } + return $qmsgs; +} + +/** + * Delete a set of rows from the notification queue table + * + * @param $rows + * An array of qids (queue id) + */ +function _watcher_db_delete_users_notification_queue($qids) { + + // Database managers can only handle *finite* (gulp!) SQL queries + // so we gotta limit the fun + $limit = 4096; //2^12 elements + + $offset = 0; + for ($i = 1; $offset < count($qids); $i++) { + $batch = array_slice($qids, $offset, $limit); + $in = implode(',', $batch); + $sql = "DELETE FROM {watcher_notify_queue} WHERE qid IN (%s)"; + db_query($sql, $in); + $offset = (($i * $limit) - 1); + } +} + +/** + * Statistics for Notification Queue Table + * + * @return + * An assoc array with keys num_rows and num_sent + */ +function _watcher_db_stats_notification_queue() { + $sql = 'SELECT * FROM {watcher_notify_queue}'; + $sql2 = 'SELECT MAX(qid) FROM {watcher_notify_queue}'; + $sql3 = 'SELECT COUNT(*) FROM {watcher_notify_queue}'; + + // Obtain number of rows + $res = db_query($sql3); + $stat['num_rows'] = db_result($res); + + // Obtain the contents of the queue table + $res = db_query($sql); + while ($row = db_fetch_object($res)) { + + // Load fields + $data['qid'] = $row->qid; + $data['uid'] = $row->uid; + $data['mail'] = $row->mail; + $data['subject'] = $row->subject; + $data['message'] = '
'. $row->message .'
'; + + // Add to data array + $stat['data']['content'][] = $data; + } + + // Add header + $stat['data']['header'] = array('qid', 'uid', 'mail', 'subject', 'message'); + + // Obtain the number of notifications sent - this is not 100% accurate since we cannot + // entirely trust the increment counter + $res2 = db_query($sql2); + $num_sent = db_result($res2); + $stat['num_sent'] = ( $num_sent = db_result($res2) ? $num_sent : 0 ); + + if ($res) { + return $stat; + } + return false; +} + +/** + * Statistics for Watched Nodes Table + * Numbers of users that watch nodes + * + * @return + * An assoc array with key num_users + */ +function _watcher_db_stats_watched_nodes_users() { + $sql = 'SELECT COUNT(DISTINCT(uid)) FROM {watcher_nodes} WHERE uid <> 0'; + $sql2 = 'SELECT COUNT(DISTINCT(mail)) FROM {watcher_nodes} WHERE uid = 0'; + + // Obtain number of rows + $res = db_query($sql); + $stat['num_users_reg'] = db_result($res); + + $res2 = db_query($sql2); + $stat['num_users_anon'] = db_result($res2); + + + if ($res && $res2) return $stat; + return false; +} + +/** + * Statistics for User Settings Table + * + * @return + * An assoc array with key num_users_with_settings, num_users and num_users_no_settings + */ +function _watcher_db_stats_user_settings() { + + // Users with custom settings + $sql = 'SELECT COUNT(uid) FROM {watcher_user_settings} WHERE custom = 1'; + + // Total number of users on the site + $sql2 = 'SELECT COUNT(uid) FROM {users} WHERE uid <> 0'; + + // Obtain number of users with settings + $res = db_query($sql); + $stat['num_users_with_settings'] = db_result($res); + + // Obtain number of users without setting + $res2 = db_query($sql2); + $stat['num_users'] = db_result($res2); + $stat['num_users_no_settings'] = $stat['num_users'] - $stat['num_users_with_settings']; + + if ($res) return $stat; + return false; +} + +/** + * Return the newest node + */ +function _watcher_db_get_newest_node() { + $sql = 'SELECT nid FROM {node} ORDER BY created DESC LIMIT 0,1'; + $res = db_query($sql); + if ($nid = db_result($res)) { + return $nid; + } + return false; +} + +/** + * Return the newest comment + */ +function _watcher_db_get_newest_comment() { + $sql = 'SELECT cid FROM {comments} ORDER BY timestamp DESC LIMIT 0,1'; + $res = db_query($sql); + if ($cid = db_result($res)) { + return $cid; + } + return false; +} diff --git a/sites/all/modules/watcher/watcher.info b/sites/all/modules/watcher/watcher.info new file mode 100644 index 0000000..b5d03ce --- /dev/null +++ b/sites/all/modules/watcher/watcher.info @@ -0,0 +1,14 @@ +; $Id: watcher.info,v 1.2.4.2 2009/02/26 17:03:48 solipsist Exp $ +name = "Watcher" +description = "Watcher enables your site's users to watch nodes for changes and new comments and be notified about them." +package = Other +core = 6.x +dependencies[] = node +dependencies[] = token +dependencies[] = comment +; Information added by drupal.org packaging script on 2010-10-26 +version = "6.x-1.4" +core = "6.x" +project = "watcher" +datestamp = "1288126235" + diff --git a/sites/all/modules/watcher/watcher.install b/sites/all/modules/watcher/watcher.install new file mode 100644 index 0000000..bb8d773 --- /dev/null +++ b/sites/all/modules/watcher/watcher.install @@ -0,0 +1,250 @@ + + * With ideas and feedback from Hans Dekker of Wordsy.com + * + * Module allows users to watch nodes and receive notifications when nodes + * are updated or commented on. + * + * Sponsored by + * Wordsy - www.wordsy.com + * NodeOne - www.nodeone.se + */ + +/** + * Implementation of hook_install() + */ +function watcher_install() { + if (db_table_exists('watcher_nodes') && db_table_exists('watcher_notify_queue') && db_table_exists('watcher_user_settings')) { + drupal_set_message("Watcher's tables already exist in the database, this indicates Watcher has been installed previously. You can probably go ahead and use Watcher without any further actions."); + return; + } + + if (drupal_install_schema('watcher')) { + drupal_set_message('Watcher was successfully installed.'); + } +} + +/** + * Implementation of hook_uninstall() + */ +function watcher_uninstall() { + + // Uninstall schemas + drupal_uninstall_schema('watcher'); + + // Empty site cache + cache_clear_all('*', 'cache', true); + cache_clear_all('*', 'cache_filter', true); + cache_clear_all('*', 'cache_menu', true); + cache_clear_all('*', 'cache_page', true); + + // Clear variables + db_query("DELETE FROM {variable} WHERE name LIKE('%s%%') ", 'watcher_'); + cache_clear_all('variables', 'cache'); + +} + +/** + * Updates 5.x -> 6.x-1.0 + */ +function watcher_update_6000() { + $ret = array(); + db_add_field($ret, 'watcher_nodes', 'mail', array('type' => 'varchar', 'length' => 128, 'default' => null)); + db_drop_primary_key($ret, 'watcher_nodes'); + db_add_primary_key($ret, 'watcher_nodes', array('uid', 'nid', 'mail')); + return $ret; +} + +function watcher_update_6001() { + $ret = array(); + db_add_field($ret, 'watcher_nodes', 'watch_for', array('type' => 'int', 'size' => 'tiny', 'default' => null)); + return $ret; +} + +function watcher_update_6002() { + $ret = array(); + $schema = watcher_schema(); + foreach ($schema as $table => $table_definition) { + if ($table == 'watcher_user_settings') { + foreach ($table_definition as $property => $property_definition) { + if ($property == 'fields') { + foreach ($property_definition as $field => $field_definition) { + if ($field != 'uid') { + // We cannot set default value to integer 0 for these fields using + // db_field_set_default() due to a bug + // See: http://drupal.org/node/517642 + // db_field_set_default($ret, $table, $field, 0); + $ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' SET DEFAULT '. 0); + } + } + } + } + } + } + + return $ret; +} + + +/** + * Implementation of hook_schema() + */ +function watcher_schema() { + $schema['watcher_nodes'] = array( + 'description' => 'Holds what users are watching what nodes', + 'fields' => array( + 'uid' => array( + 'description' => 'Holds UID of user', + 'type' => 'int', + 'not null' => true, + 'disp-width' => '10' + ), + 'nid' => array( + 'description' => 'Holds NID of node', + 'type' => 'int', + 'not null' => true, + 'disp-width' => '10' + ), + 'mail' => array( + 'description' => 'Holds email address of user (if user is anonymous)', + 'type' => 'varchar', + 'length' => 128, + 'default' => null + ), + 'send_email' => array( + 'description' => 'Whether the user wants to be notified by email or not', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'default' => 0, + 'disp-width' => '1' + ), + 'added' => array( + 'description' => 'Timestamp of when row was added', + 'type' => 'int', + 'not null' => true, + 'disp-width' => '11' + ), + 'watch_for' => array( + 'description' => 'What the user is watching for (anonymous users): 1 = all, 2 = comments, 3 = updates', + 'type' => 'int', + 'size' => 'tiny', + 'default' => null + ), + ), + 'primary key' => array('uid', 'nid', 'mail'), + ); + + $schema['watcher_notify_queue'] = array( + 'description' => 'Holds the queue of notifications', + 'fields' => array( + 'qid' => array( + 'description' => 'Queue item ID', + 'type' => 'serial', + 'not null' => true, + 'disp-width' => '32' + ), + 'uid' => array( + 'description' => 'Recipient UID', + 'type' => 'int', + 'not null' => true, + 'disp-width' => '10' + ), + 'mail' => array( + 'description' => 'Recipient email address', + 'type' => 'varchar', + 'length' => '64', + 'not null' => true + ), + 'subject' => array( + 'description' => 'Message subject', + 'type' => 'varchar', + 'length' => '192', + 'not null' => true + ), + 'message' => array( + 'description' => 'Notification message', + 'type' => 'text', + 'not null' => true + ) + ), + 'primary key' => array('qid'), + ); + + $schema['watcher_user_settings'] = array( + 'description' => 'Holds personal user settings', + 'fields' => array( + 'uid' => array( + 'description' => 'User UID', + 'type' => 'int', + 'not null' => true, + 'disp-width' => '10', + ), + 'automatic_enable_notifications' => array( + 'description' => 'Automatically enable notifications for the post when a user starts watching a post', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'disp-width' => '1', + 'default' => 0 + ), + 'notifications_updates' => array( + 'description' => 'User will be notified about updates of posts the user watches', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'disp-width' => '1', + 'default' => 0 + ), + 'notifications_new_comments' => array( + 'description' => 'User will be notified about new comments on posts the user watches', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'disp-width' => '1', + 'default' => 0 + ), + 'autowatch_commented_on' => array( + 'description' => 'User will automatically watch nodes the user comments on', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'disp-width' => '1', + 'default' => 0 + ), + 'autowatch_posted' => array( + 'description' => 'User will automatically watch nodes the user creates', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'disp-width' => '1', + 'default' => 0 + ), + 'share_binder' => array( + 'description' => 'Whether the user\'s list of watched posts should be viewable by others', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'disp-width' => '1', + 'default' => 0 + ), + 'custom' => array( + 'description' => 'Whether the user has customized the settings or whether they were derived from the defaults', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => true, + 'disp-width' => '1', + 'default' => 0 + ) + ), + 'primary key' => array('uid'), + ); + + return $schema; +} diff --git a/sites/all/modules/watcher/watcher.module b/sites/all/modules/watcher/watcher.module new file mode 100644 index 0000000..f5a402b --- /dev/null +++ b/sites/all/modules/watcher/watcher.module @@ -0,0 +1,3240 @@ + + * With ideas and feedback from Hans Dekker of Wordsy.com + * + * Module allows users to watch nodes and receive notifications when nodes + * are updated or commented on. + * + * Sponsored by + * Wordsy - www.wordsy.com + * NodeOne - www.nodeone.se + */ + +/*************************************************************************************** + * THEME FUNCTIONS + ***************************************************************************************/ + +/** + * Return a themed personal binder page + * + * @param $intro_text + * The introduction text displayed at the top of the binder page + * @param $posts_table_header + * Header array for the posts table + * @param $posts_table_body + * Rows array for the posts table + * + * @return + * A themed personal binder page + */ +function theme_watcher_binder($intro_text = null, $posts_table_header, $posts_table_body) { + $output = '
'; + + // Intro text + if ($intro_text) { + $output .= '
'; + $output .= theme('box', null, $intro_text); + $output .= '
'; + } + + // Table + $output .= theme('table', $posts_table_header, $posts_table_body); + + // Pager + $output .= theme('pager', NULL, 25, 0); + + $output .= '
'; + + return $output; +} + +/** + * Return a disabled/enabled notification status icon with link for binder used to + * toggle email notifications + * + * 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 $t + * An associative array of localized strings + * @param $type + * A string denoting whether the icon should be of type enabled or disabled + * @param $url + * The URL for the link, usually the URL for toggling email notification status + * @param $query + * Query portion of the link + * + * @return + * A themed icon for toggling email notifications + */ +function theme_watcher_binder_email_icon($t, $type, $url, $query = null) { + $output = l( + ( $type == 'enabled' ? $t['binder_notif_text_enabled'] : $t['binder_notif_text_disabled'] ), + $url, + array( + 'query' => $query, + 'attributes' => array( + 'class' => "watcher_binder_send_email_status_icon watcher_binder_send_email_status_icon_$type", + 'title' => ( $type == 'enabled' ? $t['binder_notif_title_enabled'] : $t['binder_notif_title_disabled'] ), + 'email_status' => $type, + )) + ); + return $output; +} + +/** + * Return a stop watching post icon with link for binder + * + * @param $url + * A URL for toggling watching of given nid + * @param $query + * Query portion of the link + * + * @return + * A themed link for stopping watching a node + */ +function theme_watcher_binder_stop_watching_icon($url, $query = null) { + $output = l( + t('Stop watching'), + $url, + array( + 'query' => $query, + 'attributes' => array( + 'class' => "watcher_binder_stop_watching_icon", + 'title' => t('Stop watching this post.'), + )) + ); + return $output; +} + +/** + * Return a stop watching post icon with link to be displayed in nodes + * + * 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 $query + * Query portion of the link + * @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_toggle_watching_link($uid, $nid, $query, $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' : ''); + + $output = '
'; + + // Output a link + $output .= l( + ( $user_is_watching ? $t['watch_toggle_enabled'] : $t['watch_toggle_disabled'] ), + "user/$uid/watcher/toggle/$nid", + array( + 'query' => $query, + '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'] ), + )) + ); + + $output .= '
'; + + return $output; +} + +/** + * Return the help page + * + * @param $content + * The content for the help page as configured on the module's settings page + * + * @return + * A themed help page + * + */ +function theme_watcher_help_page($content) { + $output = '
'; + $output .= $content; + $output .= '
'; + return $output; +} + +/** + * Return system help page + * + * @param $content + * The content for the help page as configured on the module's settings page + * + * @return + * A themed help page + * + */ +function theme_watcher_help($content) { + $output = '
';
+  $output .= $content;
+  $output .= '
'; + return $output; +} + +/** + * Return a themed message telling the user the user settings are defaults + * + * @param $defaults_text + * Localized message + */ +function theme_watcher_settings_defaults_notice($defaults_text) { + return '
'. $defaults_text .'
'; +} + +/** + * Implementation of hook_theme() + */ +function watcher_theme($existing, $type, $theme, $path) { + return array( + 'watcher_binder' => array( + 'arguments' => array('intro_text' => null, 'posts_table_header' => null, 'posts_table_body' => null), + ), + 'watcher_binder_email_icon' => array( + 'arguments' => array('t' => null, 'type' => null, 'url' => null, 'query' => null), + ), + 'watcher_binder_stop_watching_icon' => array( + 'arguments' => array('url' => null, 'query' => null), + ), + 'watcher_node_toggle_watching_link' => array( + 'arguments' => array('uid' => null, 'nid' => null, 'query' => null, 'user_is_watching' => null, 't' => array()), + ), + 'watcher_help_page' => array( + 'arguments' => array('content' => null), + ), + 'watcher_help' => array( + 'arguments' => array('content' => null), + ), + 'watcher_settings_defaults_notice' => array( + 'arguments' => array('defaults_text' => null), + ), + ); +} + +/*************************************************************************************** + * HOOK IMPLEMENTATIONS + ***************************************************************************************/ + +/** + * Implementation of hook_perm() + */ +function watcher_perm() { + return array('administer watcher', 'use watcher', 'change own user settings', 'access help page', 'access others lists of watched posts'); +} + +/** + * Implementation of hook_help() + */ +function watcher_help($path, $arg) { + switch ($path) { + case 'admin/help#watcher': + // Load the help text. + $help = file_get_contents('README.txt', FILE_USE_INCLUDE_PATH); + + // Abort if we can't find the file. + if (!$help) return; + + $help = htmlentities($help); + + return theme('watcher_help', $help); + } +} + +/** + * Implementation of hook_menu(). + */ +function watcher_menu() { + global $user; + $items = array(); + + // Include file + $base_include = array( + 'file' => 'watcher.db.inc' + ); + + $items['user/%user/watcher'] = array( + 'title' => 'My Watched Posts', + 'page callback' => '_watcher_binder', + 'page arguments' => array(1), + 'access callback' => '_watcher_menu_access_binder', + 'access arguments' => array(1), + 'type' => MENU_LOCAL_TASK, + ) + $base_include; + + $items['user/%user/watcher/binder'] = array( + 'title' => 'Watched Posts', + 'page callback' => '_watcher_binder', + 'page arguments' => array(1), + 'access callback' => '_watcher_menu_access_binder', + 'access arguments' => array(1), + 'weight' => 0, + 'type' => MENU_DEFAULT_LOCAL_TASK, + ) + $base_include; + + $items['user/%user/watcher/settings'] = array( + 'title' => 'Settings', + 'weight' => 5, + 'page callback' => 'drupal_get_form', + 'page arguments' => array('_watcher_user_settings', 1), + 'access arguments' => array('change own user settings'), + 'type' => MENU_IS_LOCAL_TASK + ) + $base_include; + + $items['user/%/watcher/help'] = array( + 'title' => 'Help', + 'weight' => 10, + 'page callback' => '_watcher_help_page', + 'access arguments' => array('access help page'), + 'type' => MENU_IS_LOCAL_TASK + ) + $base_include; + + + // Callbacks for toggling + + $items['user/%user/watcher/toggle/%node'] = array( + 'title' => 'Watcher Toggle Watching Post', + 'page callback' => '_watcher_watch_toggle', + 'page arguments' => array(4), + 'access callback' => '_watcher_menu_access_toggle_watching_post', + 'access arguments' => array(1), + 'type' => MENU_CALLBACK + ) + $base_include; + + $items['user/%user/watcher/email_notifications_toggle'] = array( + 'title' => 'Watcher Toggle Email Notifications', + 'page callback' => '_watcher_email_notifications_toggle', + 'access callback' => '_watcher_menu_access_toggle_email_notifications', + 'access arguments' => array(1), + 'type' => MENU_CALLBACK + ) + $base_include; + + // Unwatching for anonymous users + // + // NOTE: Path must not end with /%/%, else callback arguments will be garbled! + // Even if we pass additional path args, such as arg(6) and arg(7), + // we do not need to wildcard these. + + $items['user/%user/watcher/toggle/%node/unwatch'] = array( + 'page callback' => '_watcher_watch_toggle', + 'page arguments' => array(4, 6, 'node', 7), + 'access callback' => '_watcher_menu_access_toggle_watching_post', + 'access arguments' => array(1), + 'type' => MENU_CALLBACK + ) + $base_include; + + $items['user/%user/watcher/toggle/%node/unwatch-all'] = array( + 'page callback' => '_watcher_watch_toggle', + 'page arguments' => array(4, 6, 'all', 7), + 'access callback' => '_watcher_menu_access_toggle_watching_post', + 'access arguments' => array(1), + 'type' => MENU_CALLBACK + ) + $base_include; + + // Administration Panel Settings + + $items['admin/settings/watcher'] = array( + 'title' => 'Watcher', + 'description' => 'Modify the settings for Watcher module.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('_watcher_admin_settings'), + 'access arguments' => array('administer watcher'), + 'type' => MENU_NORMAL_ITEM, + ) + $base_include; + + $items['admin/settings/watcher/settings'] = array( + 'title' => 'Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('_watcher_admin_settings'), + 'access arguments' => array('administer watcher'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + ) + $base_include; + + $items['admin/settings/watcher/stats'] = array( + 'title' => 'Statistics', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('_watcher_admin_stats'), + 'access arguments' => array('administer watcher'), + 'type' => MENU_LOCAL_TASK, + ) + $base_include; + + $items['admin/settings/watcher/test'] = array( + 'title' => 'Testing', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('_watcher_admin_test'), + 'access arguments' => array('administer watcher'), + 'type' => MENU_LOCAL_TASK, + ) + $base_include; + + // Binder shortcut, redirect to user's My Watched Posts page + $items['user/watcher'] = array( + 'title' => 'My Watched Posts', + 'page callback' => '_watcher_binder_shortcut', + 'access callback' => '_watcher_menu_access_binder_shortcut', + 'type' => MENU_NORMAL_ITEM, + ) + $base_include; + + return $items; +} + +/** + * Access callback to check access to binder (own or others') + */ +function _watcher_menu_access_binder($account) { + global $user; + return ( + $user->uid == 1 || + ($user->uid == $account->uid && user_access('use watcher')) || + (user_access('access others lists of watched posts') && _watcher_user_settings_load('watcher_share_binder', $account->uid)) + ); +} + +/** + * Access callback to check access to toggle watching a post + */ +function _watcher_menu_access_toggle_watching_post($account) { + global $user; + return ( + $user->uid == 1 || + ($user->uid == $account->uid && user_access('use watcher')) + ); +} + +/** + * Access callback to check access to toggle watching a post + */ +function _watcher_menu_access_toggle_email_notifications($account) { + global $user; + return ( + $user->uid == 1 || + ($user->uid == $account->uid && user_access('use watcher')) + ); +} + +/** + * Access callback to check access to binder shortcut + * We check to see if current user has a non-zero UID (authenticated) + */ +function _watcher_menu_access_binder_shortcut() { + global $user; + return ((bool) $user->uid); +} + +/** + * Implementation of hook_nodeapi() + */ +function watcher_nodeapi(&$node, $op, $a3, $a4) { + + // Check whether this is one of the node types for which Watcher is enabled + if (!_watcher_node_type_enabled($node)) { + return false; + } + + // Include DB dependent functions + module_load_include('inc', 'watcher', 'watcher.db'); + + // Dispatch the operator. + $function = '_watcher_hook_nodeapi_'. $op; + if (function_exists($function)) { + return $function($node, $a3, $a4); + } +} + +/** + * Implementation of hook_nodeapi(), op: view + */ +function _watcher_hook_nodeapi_view(&$node, $a3, $a4) { + global $user; + if (user_access('use watcher')) { + _watcher_node_watch_link($node, $a3, $a4); + } +} + +/** + * Implementation of hook_nodeapi(), op: insert + */ +function _watcher_hook_nodeapi_insert(&$node, $a3, $a4) { + global $user; + if ($user->uid) { + _watcher_user_autowatch_node_insert($node->nid); + } +} + +/** + * Implementation of hook_nodeapi(), op: update + */ +function _watcher_hook_nodeapi_update(&$node, $a3, $a4) { + _watcher_email_notify_node_update($node); +} + +/** + * Implementation of hook_nodeapi(), op: delete + */ +function _watcher_hook_nodeapi_delete(&$node, $a3, $a4) { + _watcher_db_delete_nid($node->nid); +} + +/** + * Implementation of hook_comment() + */ +function watcher_comment($comment, $op) { + + // Include DB dependent functions + module_load_include('inc', 'watcher', 'watcher.db'); + + // Dispatch the operator. + $function = '_watcher_hook_comment_'. $op; + if (function_exists($function)) { + return $function($comment); + } +} + +/** + * Implementation of hook_comment(), op: insert + */ +function _watcher_hook_comment_insert($comment) { + global $user; + + // Check whether this is one of the node types for which Watcher is enabled + if (!_watcher_node_type_enabled($comment['nid'])) { + return false; + } + + // Only add the node to user's watch list if this is a non-anonymous user + if ($user->uid) { + _watcher_user_autowatch_comment_insert($comment); + } + + // Only send notifications if the comment does not need approval first + if (user_access('post comments without approval')) { + //Notify those that watch this node + _watcher_email_notify_comment_insert($comment); + } +} + +/** + * Implementation of hook_comment(), op: publish + * + * @param $comment A comment object. + */ +function _watcher_hook_comment_publish($comment) { + + // comment_publish is passed a comment as an object so we have to cast + // it as an array first + $comment = (array) $comment; + + // Check whether this is one of the node types for which Watcher is enabled + if (!_watcher_node_type_enabled($comment['nid'])) { + return false; + } + + $comment_author = user_load(array('uid' => $comment['uid'])); + + // If this comment was unpublished as a result of it requiring approval + // notify the users watching the node now that it's deemed worthy to publish + if (!user_access('post comments without approval', $comment_author)) { + //Notify those that watch this node + _watcher_email_notify_comment_insert($comment); + } +} + +/** + * Implementation of hook_comment(), op: update + * + * @param $comment An array of comment edit form values. + */ +function _watcher_hook_comment_update($comment) { + + // Check whether this is one of the node types for which Watcher is enabled + if (!_watcher_node_type_enabled($comment['nid'])) { + return false; + } + + // Make sure the comment is published + if ($comment['status'] == COMMENT_PUBLISHED) { + + // If the comment author is anonymous, the uid field is null + $comment_author = user_load(array('uid' => (is_null($commment['uid']) ? 0 : $commment['uid']))); + + // If this comment was unpublished as a result of it requiring approval + // notify the users watching the node now that it's deemed worthy to publish + if (!user_access('post comments without approval', $comment_author)) { + //Notify those that watch this node + _watcher_email_notify_comment_insert($comment); + } + + } +} + + +/** + * Implementation of hook_user() + */ +function watcher_user($type, &$edit, &$account) { + + // Include DB dependent functions + module_load_include('inc', 'watcher', 'watcher.db'); + + // Dispatch the operator. + $function = '_watcher_hook_user_'. $type; + if (function_exists($function)) { + $function($edit, $account); + } +} + +/** + * Implementation of hook_user(), op: insert + */ +function _watcher_hook_user_insert($edit, $account, $category = NULL) { + _watcher_user_settings_update_defaults(); +} + +/** + * Implementation of hook_user(), op: delete + */ +function _watcher_hook_user_delete($edit, $account, $category = NULL) { + _watcher_db_delete_user_settings($account->uid); +} + +/** + * Implementation of hook_cron() + */ +function watcher_cron() { + + // Include DB dependent functions + module_load_include('inc', 'watcher', 'watcher.db'); + + // Send emails in queue + if (_watcher_email_notifications_send_cron()) { + watchdog('Watcher', 'Notifications were sent on cron.'); + } +} + +/** + * Implementation of hook_mail() + */ +function watcher_mail($key, &$message, $params) { + $message['subject'] = $params['subject']; + $message['body'] = $params['body']; +} + +/** + * Implementation of hook_exit() + */ +function watcher_exit() { + _watcher_email_notifications_send_instant(); +} + +/*************************************************************************************** + * ADMINISTRATION + ***************************************************************************************/ + +/** + * This is our admin settings page + */ +function _watcher_admin_settings(&$form_state) { + + global $user; + + // Update user settings defaults + _watcher_user_settings_update_defaults(); + + $form = array(); + + // Content Type Settings + _watcher_admin_settings_content_types($form); + + // Watch Toggle Link Settings + _watcher_admin_settings_watch_toggle_link($form); + + // Personal Binder Settings + _watcher_admin_settings_personal_binder($form); + + // Email Notification Settings + _watcher_admin_settings_email_notifications($form); + + // Settings for Default Settings + _watcher_admin_settings_default_user_settings($form); + + // Help Page Text + _watcher_admin_settings_help($form); + + + return system_settings_form($form); + +} + +/** + * Settings concerning content types + * @param $form + */ +function _watcher_admin_settings_content_types(&$form) { + $form['contenttypes'] = array( + '#type' => 'fieldset', + '#title' => t('Watchable Content Types'), + '#description' => t('Select the content types that may be watched.'), + '#collapsible' => true, + '#collapsed' => true, + ); + + // Display error message if no node types have been selected + $watchable_node_types = variable_get('watcher_content_types', false); + if (!$watchable_node_types) { + drupal_set_message(t("You haven't selected any watchable content types. This module will not work until you do so."), 'error'); + } + + $form['contenttypes']['watcher_content_types'] = array( + '#type' => 'checkboxes', + '#default_value' => $watchable_node_types, + '#options' => node_get_types('names'), + '#default_value' => variable_get('watcher_content_types', array()), + ); +} + +/** + * Settings concerning the watch toggle link + * @param $form + */ +function _watcher_admin_settings_watch_toggle_link(&$form) { + $form['togglelink'] = array( + '#type' => 'fieldset', + '#title' => t('Watch Toggle Link'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['togglelink']['watcher_toggle_link_in_teaser'] = array( + '#type' => 'checkbox', + '#title' => t('Display "watch this post" toggle link in teasers.'), + '#description' => t('Determines whether or not to show the "watch this post" toggle link in node teasers (used on front page and content listings). Teasers are the shortened down version of a node, often shown on a site\'s frontpage or on pages that summarize content. If disabled, link will only be shown when nodes are shown as pages (full view).'), + '#default_value' => variable_get('watcher_toggle_link_in_teaser', false), + ); +} + +/** + * Settings concerning the personal binder + * @param $form + */ +function _watcher_admin_settings_personal_binder(&$form) { + global $user; + + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + $form['display'] = array( + '#type' => 'fieldset', + '#title' => t('Display Settings for Personal Binder'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['display'][] = array( + '#value' => '

'. l(t('Click here to view your personal binder'), "user/$user->uid/watcher") .'

', + ); + + $form['display']['watcher_display_intro_text'] = array( + '#type' => 'textarea', + '#title' => t('Text at the top of the Personal Binder page'), + '#description' => t('You are recommended to use this space to display brief information about what this page does and how it works to the user.'), + '#default_value' => variable_get('watcher_display_intro_text', $templates['watcher_display_intro_text']), + '#rows' => 5, + ); + + $form['display']['posts_table'] = array( + '#type' => 'fieldset', + '#title' => t('Settings for the table of posts'), + ); + + $form['display']['posts_table']['watcher_display_node_type'] = array( + '#type' => 'checkbox', + '#title' => t('Display Node Type Column'), + '#default_value' => variable_get('watcher_display_node_type', 0), + ); + + $form['display']['posts_table']['watcher_display_last_updated'] = array( + '#type' => 'checkbox', + '#title' => t('Display Last Updated Column'), + '#default_value' => variable_get('watcher_display_last_updated', 0), + ); + + $form['display']['posts_table']['watcher_display_post_author'] = array( + '#type' => 'checkbox', + '#title' => t('Display Post Author Column'), + '#default_value' => variable_get('watcher_display_post_author', 1), + ); +} + +/** + * Settings concerning email notifications + * @param $form + */ +function _watcher_admin_settings_email_notifications(&$form) { + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + $form['notifications'] = array( + '#type' => 'fieldset', + '#title' => t('Settings for Email Notifications'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['notifications'][] = array( + '#value' => '
', + ); + + $form['notifications']['watcher_email_notifications_enabled'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Email Notifications'), + '#default_value' => variable_get('watcher_email_notifications_enabled', 1), + ); + + $form['notifications'][] = array( + '#value' => '
', + ); + + $form['notifications']['watcher_email_notifications_method'] = array( + '#type' => 'radios', + '#title' => t('Messages are sent'), + '#description' => t('You can select when messages are sent. Using "on cron", messages are sent when cron is being run, usually every hour depending on how you have configured crontab, this is preferred for large sites with hundreds of users or more. Using the second method, messages are sent right away for the time limit set (see below). Any messages that remain unsent will be sent next time messages are sent. The second method won\'t affect loading times since messages are sent after the page has been delivered to the user\'s browser.'), + '#default_value' => variable_get('watcher_email_notifications_method', 'cron'), + '#options' => array( + 'cron' => t('on cron (recommended for large sites)'), + 'instant' => t('instantaneously and for limited number of seconds (recommended for small to medium sites)') + ), + ); + + // Snippet taken from simplenews.module + $max_time = array(1, 2, 3, 4); + $max_time = drupal_map_assoc($max_time); + $ini_max = ini_get('max_execution_time'); + if ($ini_max) { + for ($i = 5; $i < $ini_max; $i=$i+5) { + $max_time[$i] = $i; + } + $max_time['unlimited'] = t('unlimited'); + } + + $form['notifications']['watcher_email_notifications_send_time_limit'] = array( + '#type' => 'select', + '#title' => t('Time limit for sending messages in seconds'), + '#description' => t('This setting lets you specify for how many seconds messages should be sent and it applies to both methods. Any messages that remain unsent after this interval will be sent next time messages are sent. This setting will not make your site seem slower to visitors. The maximum value is the max execution time in your PHP configuration.'), + '#default_value' => variable_get('watcher_email_notifications_send_time_limit', 5), + '#options' => $max_time, + '#attributes' => (array('id' => 'watcher_send_time_limit')), + ); + + $form['notifications']['watcher_email_notifications_comment_excerpt_len'] = array( + '#type' => 'select', + '#title' => t('Limit length of comment excerpt in notification email to'), + '#description' => t('It may be wise not to send the entire comment as doing so will tease the user to go to your site to view it which results in traffic. Here you can select how much of the comment you want to include in the email. Percentages refer to the length of the comment. "Nothing" means no excerpt will be included in the message.'), + '#default_value' => variable_get('watcher_email_notifications_comment_excerpt_len', '200chars'), + '#options' => array( + 'nothing' => t('nothing'), + '25percent' => t('25% of comment'), + '50percent' => t('50% of comment'), + '75percent' => t('75% of comment'), + '100chars' => t('100 characters of comment'), + '200chars' => t('200 characters of comment'), + '300chars' => t('300 characters of comment'), + '400chars' => t('400 characters of comment'), + 'entire' => t('entire comment'), + ) + ); + + $form['notifications']['templates'] = array( + '#type' => 'fieldset', + '#title' => t('Notification Message Templates'), + '#description' => t('These message templates are used for notifications and confirmation messages. You may edit them if you like. Tokens are in [brackets] and act as placeholders for variables, such as URLs, usernames and email addresses, and will be replaced when the email is sent. You cannot use HTML code in your message templates.'), + '#collapsible' => true, + '#collapsed' => true, + ); + + // Header + + $form['notifications']['templates']['watcher_notifications_templates_header'] = array( + '#type' => 'textarea', + '#title' => t('Message Header'), + '#default_value' => variable_get('watcher_notifications_templates_header', $templates['header']), + '#description' => t('

The text above will be prepended to every message sent. The following tokens are available:

  • [recipient-username]
  • [recipient-user-settings-url]
  • [stop-watching-url]
') + ); + + $form['notifications']['templates']['tokens_header'] = array( + '#type' => 'fieldset', + '#title' => t('Additional Tokens for Header'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['notifications']['templates']['tokens_header'][] = array( + '#value' => theme('token_help', 'global'), + ); + + // Footer + + $form['notifications']['templates']['watcher_notifications_templates_footer'] = array( + '#type' => 'textarea', + '#title' => t('Message Footer'), + '#default_value' => variable_get('watcher_notifications_templates_footer', $templates['footer']), + '#description' => t('

The text above will be appended to every message sent. The following tokens are available:

  • [recipient-username]
  • [recipient-user-settings-url]
  • [stop-watching-url]
') + ); + + $form['notifications']['templates']['watcher_notifications_templates_footer_anonymous_notify'] = array( + '#type' => 'textarea', + '#title' => t('Message Footer for Anonymous Users'), + '#default_value' => variable_get('watcher_notifications_templates_footer_anonymous_notify', $templates['footer_anonymous_notify']), + '#description' => t("

The text above will be appended to notification messages messages sent to anonymous users. The following tokens are available:

  • [stop-watching-url]
  • [stop-watching-url]
  • [stop-watching-all-url]
") + ); + + $form['notifications']['templates']['watcher_notifications_templates_footer_confirm'] = array( + '#type' => 'textarea', + '#title' => t('Message Footer in Confirmation Messages'), + '#default_value' => variable_get('watcher_notifications_templates_footer_confirm', $templates['footer_confirm']), + '#description' => t("

The text above will be appended to confirmation messages sent to anonymous users when they start watching a node. Links for stopping watching this or every node the user watches and user's IP address are automatically prepended to this text.

  • [user-ip]
  • [stop-watching-url]
  • [stop-watching-all-url]
") + ); + + $form['notifications']['templates']['tokens_footer'] = array( + '#type' => 'fieldset', + '#title' => t('Additional Tokens for Footers'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['notifications']['templates']['tokens_footer'][] = array( + '#value' => theme('token_help', 'global'), + ); + + // Template for Messages about Node Updates + + $form['notifications']['templates']['watcher_notifications_templates_body_node'] = array( + '#type' => 'textarea', + '#title' => t('Message Body for Node Updates'), + '#default_value' => variable_get('watcher_notifications_templates_body_node', $templates['body_node_update']), + '#description' => t('

The following tokens are available:

  • [node-url]
') + ); + + $form['notifications']['templates']['tokens_nodes'] = array( + '#type' => 'fieldset', + '#title' => t('Additional Tokens for Nodes'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['notifications']['templates']['tokens_nodes'][] = array( + '#value' => theme('token_help', 'node'), + ); + + // Template for Messages about New Comments + + $form['notifications']['templates']['watcher_notifications_templates_body_cmt'] = array( + '#type' => 'textarea', + '#title' => t('Message Body for New Comments'), + '#default_value' => variable_get('watcher_notifications_templates_body_cmt', $templates['body_comment_insert']), + '#description' => t('

The following tokens are available:

  • [comment-excerpt]
  • [node-url]
  • [comment-url]
  • [comment-reply-url]
') + ); + + $form['notifications']['templates']['tokens_comments'] = array( + '#type' => 'fieldset', + '#title' => t('Additional Tokens for Comments'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['notifications']['templates']['tokens_comments'][] = array( + '#value' => theme('token_help', 'comment') . theme('token_help', 'node'), + ); + + // Template for Confirmation Messages to anonymous users + + $form['notifications']['templates']['watcher_notifications_templates_body_confirm'] = array( + '#type' => 'textarea', + '#title' => t('Message Body for Confirmation Messages'), + '#default_value' => variable_get('watcher_notifications_templates_body_confirm', $templates['body_confirm']), + '#description' => t('

The text above will be included in confirmation messages sent to anonymous users when they start watching a node.:

The following tokens are available:

  • [node-url]
') + ); +} + +/** + * Settings concerning default user settings + * @param $form + */ +function _watcher_admin_settings_default_user_settings(&$form) { + // Get the number of users that have not customized their settings + $stats = _watcher_db_stats_user_settings(); + + $form['default'] = array( + '#type' => 'fieldset', + '#title' => t('Default User Settings'), + '#description' => t('These will set the defaults in every user\'s personal settings. Settings you make here will affect the settings of every user that hasn\'t customized his or her settings. This setting will currently affect !numusers users who have not customized their settings.', array('!numusers' => $stats['num_users_no_settings'])), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['default']['watcher_default_settings'] = array( + '#type' => 'checkboxes', + '#default_value' => variable_get('watcher_default_settings', array()), + '#options' => array( + 'watcher_automatic_enable_notifications' => t('Automatically enable email notifications for posts that I start watching'), + 'watcher_notifications_updates' => t('Send email notification when a post is updated or edited'), + 'watcher_notifications_new_comments' => t('Send email notification when a post receives a new comment'), + 'watcher_autowatch_commented_on' => t('Automatically watch posts that I comment on'), + 'watcher_autowatch_posted' => t('Automatically watch posts that I make'), + 'watcher_share_binder' => t('Share my list of watched posts'), + ), + ); +} + +/** + * Settings concerning the help page + * @param $form + */ +function _watcher_admin_settings_help(&$form) { + global $user; + + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + $form['help'] = array( + '#type' => 'fieldset', + '#title' => t('Help Page'), + '#description' => t('This help text is displayed if the user clicks the Help link in the list of watched posts. You can customize it below. To apply your own CSS rules to this page you can use the #watcher_help_page selector.'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['help']['watcher_help_text'] = array( + '#type' => 'textarea', + '#title' => t('Text on Help Page'), + '#default_value' => variable_get('watcher_help_text', $templates['watcher_help_text']), + '#rows' => 20, + ); + + $form['help'][] = array( + '#value' => l(t('Preview help page'), "user/$user->uid/watcher/help"), + ); +} + +/** + * Returns statistics for the module + */ +function _watcher_admin_stats() { + $form = array(); + + //////////////// Notification Queue Table Statistics //////////////// + + $stats = _watcher_db_stats_notification_queue(); + + $form['notification_queue_table'] = array( + '#type' => 'fieldset', + '#title' => t('Notification Queue Table'), + ); + + if ($stats['num_rows'] > 0) { + $table_body = array( + array(t('Number of notifications in queue'), $stats['num_rows']), + array(t('Notification counter (some kind of indication of how many notifications that have been sent)'), $stats['num_sent']), + ); + + $form['notification_queue_table'][] = array( + '#value' => theme('table', array(), $table_body), + ); + + + $form['notification_queue_table']['content'] = array( + '#type' => 'fieldset', + '#title' => t('Table Content'), + '#description' => t('This is the content of the notification queue table.'), + '#collapsed' => true, + '#collapsible' => true, + ); + $form['notification_queue_table']['content'][] = array( + '#value' => theme('table', $stats['data']['header'], $stats['data']['content']), + ); + } + else { + $form['notification_queue_table'][] = array( + '#value' => t('There are no notifications in the queue.'), + ); + } + //////////////// Watched Nodes Table Statistics //////////////// + + $stats = _watcher_db_stats_watched_nodes_users(); + + $form['watched_nodes_users_table'] = array( + '#type' => 'fieldset', + '#title' => t('Watched Nodes Table'), + ); + + $table_body = array( + array(t('Number of registered users that watch nodes'), $stats['num_users_reg']), + array(t('Number of anonymous users that watch nodes'), $stats['num_users_anon']), + ); + + $form['watched_nodes_users_table'][] = array( + '#value' => theme('table', array(), $table_body), + ); + + + //////////////// User Settings Table Statistics //////////////// + + $stats = _watcher_db_stats_user_settings(); + + $form['user_settings_table'] = array( + '#type' => 'fieldset', + '#title' => t('User Settings Table'), + ); + + $table_body = array( + array(t('Number of users that have changed their user settings'), $stats['num_users_with_settings']), + array(t('Number of users that use default user settings'), $stats['num_users_no_settings']), + ); + + $form['user_settings_table'][] = array( + '#value' => theme('table', array(), $table_body), + ); + + + return $form; + +} + +/** + * Functions for testing the module's functionality + */ +function _watcher_admin_test() { + + global $user; + + $form = array(); + + if (!variable_get('watcher_email_notifications_enabled', 1)) { + $form[] = array( + '#value' => '

'. t('Email notifications are NOT enabled. You can use the diagnostics tools anyway but regular notifications will not be sent.') .'

', + ); + } + + $form[] = array( + '#value' => t("If you're experiencing problems with the module such as messages not being delivered et c, you can use the diagnostic tools on this page to send test notifications. The statistics page also contains valuable information for troubleshooting.", array('!statpage' => url('admin/settings/watcher/stats'))) + ); + + $form['create_test_notification'] = array( + '#type' => 'fieldset', + '#title' => t('Create a Test Notification'), + '#description' => t('Click the buttons below to add a notification to the queue. A notification for a new comment will use content from the newest comment on the site. A notification for a node update will contain a link to the newest node on the site. Notifications will be sent to your email account (!usermail).', array('!usermail' => $user->mail)) + ); + + $form['create_test_notification']['create_notification_node_update'] = array( + '#type' => 'submit', + '#value' => t('Create test notification for node update'), + '#submit' => array('_watcher_admin_test_create_node_update_notification'), + ); + + $form['create_test_notification']['create_notification_new_comment'] = array( + '#type' => 'submit', + '#value' => t('Create test notification for new comment'), + '#submit' => array('_watcher_admin_test_create_new_comment_notification'), + ); + + $form['send_notifications_in_queue'] = array( + '#type' => 'fieldset', + '#title' => t('Send Notifications in Queue'), + '#description' => t('Notifications are stored in a queue. Depending on what method you have chosen in the settings, notifications are either delivered instantaneously (when a comment is posted or a node updated) or when cron is run.', array('!settings' => url('admin/settings/watcher/settings'))) + ); + + $method = variable_get('watcher_email_notifications_method', 'cron'); + + $form['send_notifications_in_queue'][] = array( + '#value' => '

'. t('Your currently selected method for sending notifications in queue is !method.', array('!method' => $method)) .'

', + ); + + $stats = _watcher_db_stats_notification_queue(); + + $form['send_notifications_in_queue']['stats'] = array( + '#value' => '

'. t('There are currently !num !notification_plural in the queue.', array('!num' => $stats['num_rows'], '!notification_plural' => format_plural($stats['num_rows'], 'notification', 'notifications'))) .'

', + ); + + if ($stats['num_rows']) { + if ($method == 'cron' ) { + $form['send_notifications_in_queue']['cron'] = array( + '#value' => '

'. l(t('Click here to run cron manually and SEND messages in queue'), 'admin/reports/status/run-cron', array('query' => 'destination=admin/settings/watcher/test')) .'

', + ); + } + else { + $form['send_notifications_in_queue']['instant'] = array( + '#type' => 'submit', + '#value' => t('Click here to SEND messages in queue'), + '#submit' => array('_watcher_admin_test_send_notifications_in_queue_instant'), + ); + } + + $form['send_notifications_in_queue'][] = array( + '#value' => '

- or -

', + ); + + $form['send_notifications_in_queue']['empty_queue'] = array( + '#type' => 'submit', + '#value' => t('Click here to EMPTY queue'), + '#submit' => array('_watcher_admin_test_empty_queue') + ); + } + + return $form; +} + +/** + * Submit handler for test form: Create node update notification + */ +function _watcher_admin_test_create_node_update_notification($form, &$form_state) { + global $user; + + // Prepare an array of recipients + $recipients = array($user->uid => $user); + + if ($newest_nid = _watcher_db_get_newest_node()) { + $node = node_load($newest_nid); + $subject = t('TEST: Post has been updated'); + if (_watcher_email_notify_node_update_add_to_queue($recipients, $subject, $node)) { + drupal_set_message(t('A test notification (node update) has been created.')); + } + } + else { + drupal_set_message(t('No nodes exist. You need to create at least one.'), 'error'); + } +} + +/** + * Submit handler for test form: Create new comment notification + */ +function _watcher_admin_test_create_new_comment_notification($form, &$form_state) { + + global $user; + + // Prepare an array of recipients + $recipients = array($user->uid => $user); + + if ($newest_cid = _watcher_db_get_newest_comment()) { + $comment = (array) _comment_load($newest_cid); + $subject = t('TEST: New comment posted'); + if (_watcher_email_notify_comment_insert_add_to_queue($recipients, $subject, $comment)) { + drupal_set_message(t('A test notification (new comment) has been created.')); + } + } + else { + drupal_set_message(t('No comments exist. You need to make at least one.'), 'error'); + } +} + +/** + * Submit handler for test form: Send notifications in queue instantly + */ +function _watcher_admin_test_send_notifications_in_queue_instant($form, &$form_state) { + _watcher_static('messages to send', true); + drupal_set_message(t('Notifications have been sent using instant method.')); +} + +/** + * Submit handler for test form: Empty notification queue + */ +function _watcher_admin_test_empty_queue($form, &$form_state) { + if (_watcher_db_delete_users_notification_queue_all()) { + drupal_set_message(t('Watcher Notification Queue has been emptied.')); + } +} + + +/*************************************************************************************** + * PAGES + ***************************************************************************************/ + +/** + * Displays the user's binder + * + * @param $account + * User object for the user whose list we want to display + */ +function _watcher_binder($account) { + + global $user; + + // Is the current user the owner of this binder? + $user_is_owner = ($user->uid == $account->uid); + + // Are email notifications enabled? + $emails_enabled = variable_get('watcher_email_notifications_enabled', 1); + + // Load account of binder owner + $owner = $account; + $uid = $owner->uid; + + // Set title + drupal_set_title(t('!username\'s Watched Posts', array('!username' => $owner->name))); + + + // Make localized strings for JavaScript + $tstrings = array(); + $tstrings['binder_notif_text_enabled'] = t('Click to Disable'); + $tstrings['binder_notif_text_disabled'] = t('Click to Enable'); + $tstrings['binder_notif_title_enabled'] = t('Email notifications for this post are ENABLED, click to disable'); + $tstrings['binder_notif_title_disabled'] = t('Email notifications for this post are DISABLED, click to enable'); + $tstrings['module_path'] = base_path() . drupal_get_path('module', 'watcher'); + + // Add CSS + drupal_add_css(drupal_get_path('module', 'watcher') .'/css/watcher.css'); + + // Add JS for AJAX + drupal_add_js(drupal_get_path('module', 'watcher') .'/js/watcher.js'); + drupal_add_js(array('watcher' => $tstrings), 'setting'); + + //////////// Set up table header //////////////// + $header = array(); + + // type + if (variable_get('watcher_display_node_type', 0)) { + $header[] = t('Type'); + } + + // post title + $header[] = array( + 'data' => t('Post'), + 'field' => 'n.title', + ); + + // post author + if (variable_get('watcher_display_post_author', true)) { + $header[] = array( + 'data' => t('Author'), + 'field' => 'u.name', + ); + } + + // time post was added to watched list + $header[] = array( + 'data' => t('Post Added'), + 'field' => 'wn.added', + 'sort' => 'desc', + ); + + // last post updated time + if (variable_get('watcher_display_last_updated', 0)) { + $header[] = array( + 'data' => t('Last updated'), + 'field' => 'last_updated', + ); + } + + // Comment and new comments count + $header[] = t('Comments'); + + // Email notification toggle icon + if ($user_is_owner && $emails_enabled) { + $header[] = t('Notifications'); + } + + // Watch post toggle icon + if ($user_is_owner) { + $header[] = t('Remove'); + } + + + //////////// Obtain nodes the user is watching ////////// + $result = _watcher_db_get_watched_nodes_full($owner, $header); + + + ///////////// Process the result set ////////////// + $rows = array(); + while ($node = db_fetch_object($result)) { + + // Determine the number of comments: + $comments = _watcher_binder_comment_count($node); + + // Generate destination and token query + $link_query = drupal_get_destination() ."&token=". _watcher_get_token($node->nid); + + // Populate table + $row = array(); + + // Get name of node type + if (variable_get('watcher_display_node_type', 0)) { + $row[] = check_plain(node_get_types('name', $node->type)); + } + + // Node title + $row[] = l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)); + + // Author user name + if (variable_get('watcher_display_post_author', 0)) { + $row[] = theme('username', $node); + } + + // Post added + $row[] = ($node->added ? t('!time ago', array('!time' => format_interval(time() - $node->added))) : null ); + + // Post last updated + if (variable_get('watcher_display_last_updated', 0)) { + $row[] = t('!time ago', array('!time' => format_interval(time() - $node->last_updated))); + } + + // Number of comments + $row[] = array( + 'class' => 'replies', + 'data' => $comments + ); + + // Email notification status icon + if ($user_is_owner && $emails_enabled) { + $row[] = theme('watcher_binder_email_icon', $tstrings, ($node->send_email ? 'enabled' : 'disabled'), "user/$uid/watcher/email_notifications_toggle/$node->nid", $link_query); + } + + // Stop watching icon + if ($user_is_owner) { + $row[] = theme('watcher_binder_stop_watching_icon', "user/$uid/watcher/toggle/$node->nid", $link_query); + } + + $rows[] = $row; + } + + // If there are no posts + if (!$rows) { + $rows[] = array( + array( + 'data' => ( $user_is_owner ? t('No posts in the list - you should add some!') : t('!username\'s watched posts list is empty', array('!username' => $owner->name))), + 'colspan' => count($header), + ) + ); + } + + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + //////////////// Generate page content ///////////// + $intro_text = filter_xss_admin(variable_get('watcher_display_intro_text', $templates['watcher_display_intro_text'])); + $output = theme('watcher_binder', $intro_text, $header, $rows); + + return $output; +} + +/** + * Redirection to user/nid/watcher + */ +function _watcher_binder_shortcut() { + $uid = $GLOBALS['user']->uid; + drupal_goto("user/$uid/watcher/binder"); +} + +/** + * Provide a user settings page for the module + */ +function _watcher_user_settings(&$form_state, $account) { + + global $user; + + // Add CSS + drupal_add_css(drupal_get_path('module', 'watcher') .'/css/watcher.css'); + + // Set page title + drupal_set_title(t('Settings for Watching Posts')); + + // Load account of binder owner + $owner = $account; + $uid = $owner->uid; + + $form = array(); + + $defaults = !((bool) _watcher_user_settings_load('watcher_custom', $uid)); + $defaults_text = t('Your settings are currently defaults, as set by the site owner. Save these settings to customize them.'); + + if ($defaults) { + $form[] = array( + '#value' => theme('watcher_settings_defaults_notice', $defaults_text), + ); + } + + if (variable_get('watcher_email_notifications_enabled', 1)) { + + $form['email'] = array( + '#type' => 'fieldset', + '#title' => t('Email Notification Settings'), + '#collapsible' => false, + '#collapsed' => false, + ); + + $form['email']['watcher_automatic_enable_notifications'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically enable email notifications for posts that I start watching'), + '#default_value' => _watcher_user_settings_load('watcher_automatic_enable_notifications', $uid), + ); + + $form['email'][] = array( + '#value' => '
' + ); + + $form['email']['watcher_notifications_updates'] = array( + '#type' => 'checkbox', + '#title' => t('Send email notification when a post is updated or edited'), + '#default_value' => _watcher_user_settings_load('watcher_notifications_updates', $uid), + ); + + $form['email']['watcher_notifications_new_comments'] = array( + '#type' => 'checkbox', + '#title' => t('Send email notification when a post receives a new comment'), + '#default_value' => _watcher_user_settings_load('watcher_notifications_new_comments', $uid), + ); + + } + + $form['autowatch'] = array( + '#type' => 'fieldset', + '#title' => t('Watch Automatically'), + '#collapsible' => false, + '#collapsed' => false, + ); + + $form['autowatch']['watcher_autowatch_commented_on'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically watch posts that I comment on'), + '#default_value' => _watcher_user_settings_load('watcher_autowatch_commented_on', $uid), + ); + + $form['autowatch']['watcher_autowatch_posted'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically watch posts that I make'), + '#default_value' => _watcher_user_settings_load('watcher_autowatch_posted', $uid), + ); + + $form['sharing'] = array( + '#type' => 'fieldset', + '#title' => t('Sharing'), + '#description' => t('By sharing your list of watched posts, other users can see it but they cannot remove or add posts or change it in any way.'), + '#collapsible' => false, + '#collapsed' => false, + ); + + $form['sharing']['watcher_share_binder'] = array( + '#type' => 'checkbox', + '#title' => t('Share my list of watched posts'), + '#default_value' => _watcher_user_settings_load('watcher_share_binder', $uid), + ); + + $form['uid'] = array( + '#type' => 'hidden', + '#value' => $uid, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save my settings') + ); + + return $form; + +} + +/** + * Display the help text of the module + */ +function _watcher_help_page() { + // Add CSS + drupal_add_css(drupal_get_path('module', 'watcher') .'/css/watcher.css'); + + // Set page title + drupal_set_title(t('Help on Watching Posts')); + + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + // Check text for XSS + $text = filter_xss_admin(variable_get('watcher_help_text', $templates['watcher_help_text'])); + + // Return a themed help page + return theme('watcher_help_page', $text); +} + + +/*************************************************************************************** + * MENU CALLBACKS + ***************************************************************************************/ + +/** + * Toggle watching/unwatching a post + * + * @param $node + * Node object of the node we want to toggle watching for + * @param $mail + * String passed for anonymous users unwatching, the email address of the users + * @param $unwatch + * String passed for anonymous users unwatching, 'node' to unwatch given node, + * 'all' to unwatch all nodes associated with given $mail + * @param $confirm + * String, passed if the user is confirming an action such as unwatching all posts on the site + * + * TODO: Refactor into several functions + */ +function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm = null) { + $nid = $node->nid; + $token = $_REQUEST['token']; + + // Validate token + if (_watcher_get_token($node->nid) != $token) { + drupal_set_message(t("You've followed an invalid link.")); + drupal_access_denied(); + return; + } + + global $user; + + // Are email notifications enabled? + $email_notifications = variable_get('watcher_email_notifications_enabled', true); + + // Is this an anonymous user? + $anonymous = !((bool) $user->uid); + + // If this is an anonymous user, we check to see if the user is already watching this node in current session + if ($anonymous) { + if (is_array($watches = _watcher_session('watching'))) { + $watching = in_array($nid, $watches); + } + // Load user's email address from session + $user->mail = _watcher_session('mail'); + } + + // Is this an asynchronous request? + $async = $_GET['async']; + + // Get destination for redirection later on + $dest = drupal_get_destination(); + + // Handle an unwatch request for an anonymous user + // The user doesn't have to be the current user, it can be someone else so we load the default + // anonymous user object and add a mail property + + if ($mail && $unwatch) { + $recipient_user = user_load(0); + $recipient_user->mail = $mail; + + // Unwatching a single node + if ($unwatch == 'node') { + $nids = array($nid); + if (_watcher_user_unset_watching_nodes(array($nid), $recipient_user)) { + $message = t('%ntitle previously watched by %email is no longer being watched.', array('%ntitle' => check_plain($node->title), '%email' => check_plain($recipient_user->mail))); + + // Remove NID from session to mark it as no longer being watched + $nids = _watcher_session('watching'); + if (is_array($nids)) { + unset($nids[$nid]); + _watcher_session('watching', $nids); + } + } + } + + // Unwatching all nodes being watched + + if ($unwatch == 'all') { + if ($confirm != 'confirm') { + + $link_query = "token=$token"; + + // Confirm the action + $out = array(); + $out[] = array( + '#value' => '

' . t('Are you sure you want to STOP watching all posts %email currently watches on this site? This action cannot be undone.', array('%email' => check_plain($recipient_user->mail))) . '

' . '

'. l('Yes, I am sure.', 'user/'. $user->uid .'/watcher/toggle/'. $nid .'/unwatch-all/'. $mail .'/confirm', array('query' => $link_query)) .'

', + ); + return drupal_render($out); + } + else { + if ($db_result = _watcher_db_get_watched_nodes_mini($recipient_user)) { + + // Remove NID from session to mark it as no longer being watched + $nids = _watcher_session('watching'); + while ($row = db_fetch_object($db_result)) { + $watched_nids[] = $row->nid; + if (is_array($nids)) { + unset($nids[$row->nid]); + } + } + _watcher_session('watching', $nids); + + // Unwatch nodes + _watcher_user_unset_watching_nodes($watched_nids, $recipient_user); + $message = t('All posts on this site previously watched by %email are no longer being watched.', array('%email' => check_plain($recipient_user->mail))); + } + } + } + } + + + // Handle watching for anonymous users + + elseif ($anonymous) { + // Check if email notifications are enabled before displaying email address form + if ($email_notifications) { + // If this is the result of a form submission or regular request, render form in HTML + // otherwise return JSON + $watch_action = ($watching ? 'unwatch' : 'watch'); + if ($_POST || !$async) { + return drupal_get_form('_watcher_watch_toggle_anonymous_form', $nid, $watch_action); + } + $nstatus['status'] = 'form'; + $nstatus['data'] = drupal_get_form('_watcher_watch_toggle_anonymous_form', $nid, $watch_action); + } + } + + + // Handle watching and unwatching for logged-in users + else { + + $link_query = $dest ."&token=$token"; + + if (_watcher_user_is_watching_node($user, $nid)) { + if (_watcher_user_unset_watching_nodes(array($nid), $user)) { + $message = t('You are no longer watching !ntitle. Undo', array('!ntitle' => check_plain($node->title), '!undo' => url("user/$user->uid/watcher/toggle/$node->nid", array('query' => $link_query)))); + $nstatus['status'] = 'disabled'; + } + else { + $message = t('We\'re sorry but you may not watch this type of post.'); + } + } + else { + if (_watcher_user_set_watching_node($nid, $user)) { + $message = t('You are now watching !ntitle. Undo', array('!ntitle' => check_plain($node->title), '!undo' => url("user/$user->uid/watcher/toggle/$node->nid", array('query' => $link_query)))); + $nstatus['status'] = 'enabled'; + } + else { + $message = t('We\'re sorry but you may not watch this type of post.'); + } + } + } + + // If this was an asynchronous request, see if a form was generated then output it + // otherwise output of status of request + if ($async) { + print drupal_to_js($nstatus); + } + else { + drupal_set_message($message); + drupal_goto(); + } +} + +/** + * Toggle email notifications for a post + * + * @param $nid Node ID of the node we want to toggle notifications forr + */ +function _watcher_email_notifications_toggle($nid) { + global $user; + $uid = $user->uid; + + $token = $_REQUEST['token']; + + // Validate token + if (_watcher_get_token($nid) != $token) { + drupal_set_message(t("You've followed an invalid link.")); + drupal_access_denied(); + return; + } + + // Toggle + if (_watcher_user_is_watching_node($user, $nid)) { + if (_watcher_email_notifications_status_for_user_node($nid, $uid)) { + _watcher_email_notifications_disable($nid, $uid); + $nstatus['status'] = 'disabled'; + } + else { + _watcher_email_notifications_enable($nid, $user); + $nstatus['status'] = 'enabled'; + } + } + + // Is this an asynchronous request? + $async = $_GET['async']; + + // If this was an asynchronous request - output JSON, otherwise redirect + if ($async) { + print drupal_to_js($nstatus); + } + else { + drupal_goto(); + } + +} + + +/*************************************************************************************** + * SUPPORT FUNCTIONS + ***************************************************************************************/ + +/** + * Enable Email Notifications for a User for a Node + * + * @param $nid + * Node NID + * + * @param $user + * A user object + */ +function _watcher_email_notifications_enable($nid, $user) { + return _watcher_db_set_send_email_status($nid, $user, 1); +} + +/** + * Disable Email Notifications for a Node + * + * @param $nid + * Node NID + * + * @param $uid + * User UID + */ +function _watcher_email_notifications_disable($nid, $uid) { + return _watcher_db_set_send_email_status($nid, $uid, 0); +} + +/** + * Does the user receive email notifications for this node? + * + * @param $nid + * Node NID + * + * @param $uid + * User UID + */ +function _watcher_email_notifications_status_for_user_node($nid, $uid) { + return _watcher_db_get_send_email_status($nid, $uid); +} + +/** + * Send notification when a node has been updated + * + * @param $node + * A node object. + */ +function _watcher_email_notify_node_update(&$node) { + global $user; + + // Are email notifications enabled? + $email_notifications = variable_get('watcher_email_notifications_enabled', true); + if (!$email_notifications) { + return false; + } + + // Since a node may be edited by many, we want to exclude the user who just + // edited it (who may not necessarily be its author), so we exclude current + // user's UID. + + // TODO: Exclusion by email address, allows exclusion of anonymous users who + // still have their email address in session and who we therefore can + // identify. + + // Who are the users that want to be notified of this event? + $recipients = _watcher_db_get_users_notify_node_update($node->nid, $user->uid); + + // Set up subject + $node_title = check_plain($node->title ? ' "'. substr($node->title, 0, 128) .'" ' : false); + $site_name = variable_get('site_name', false ? ' ('. check_plain(variable_get('site_name', '')) .')' : ''); + $subject = t('Post!nodetitlehas been updated!sitename', array('!nodetitle' => $node_title, '!sitename' => $site_name)); + + // Add to queue + _watcher_email_notify_node_update_add_to_queue($recipients, $subject, $node); + + // Flag that there are messages in queue + _watcher_static('messages to send', true); +} + +/** + * Add node update notification to the notification queue + * + * @param $recipients + * An array with UID as key of recipient user objects with attributes name, mail and uid + * @param $subject + * The subject of the notification + * @param $node + * A node object of the node that has been updated + */ +function _watcher_email_notify_node_update_add_to_queue($recipients, $subject, $node) { + foreach ($recipients as $recipient) { + + $message = ''; + + // Get message header with tokens replaced + // Do not include headers for anonymous recipients (they have no user name) + if ($recipient->uid) { + $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $node->nid, 'header'); + } + + // Get message body with tokens replaced + $message .= _watcher_email_notifications_replace_tokens_node_update($node, $recipient); + + // Get message footer with tokens replaced + // Use different templates depending on whether this is a regular or anonymous recipient + if ($recipient->uid) { + $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $node->nid, 'footer'); + } + else { + $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $node->nid, 'footer_anonymous_notify'); + } + + // Add to message queue + $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : true ); + } + return $res; +} + +/** + * Send notification when a comment has been posted + * + * @param $comment + * A comment object as provided by hook_comment + */ +function _watcher_email_notify_comment_insert(&$comment) { + + // Are email notifications enabled? + $email_notifications = variable_get('watcher_email_notifications_enabled', true); + if (!$email_notifications) { + return false; + } + + // Since a comment is by necessity authored by the current user, we can safely assume + // that the current user authored it and use the comment's UID for exclusion. + + // Who are the users that want to be notified of this event? + $recipients = _watcher_db_get_users_notify_comment_insert($comment['nid'], $comment['uid']); + // No need to go any further unless we have to + if (!count($recipients)) { + return; + } + + // Load node to get its title + $node = node_load($comment['nid']); + + // Set up subject + $node_title = ( $node->title ? t(' about "!nodetitle"', array('!nodetitle' => substr($node->title, 0, 128))) : false ); + $site_name = ( variable_get('site_name', false ) ? ' ('. variable_get('site_name', '') .')' : '' ); + $subject = t('New comment posted!aboutnodetitle!sitename', array('!aboutnodetitle' => $node_title, '!sitename' => $site_name)); + + // Add to queue + _watcher_email_notify_comment_insert_add_to_queue($recipients, $subject, $comment); + + // Flag that there are messages in queue + _watcher_static('messages to send', true); +} + +/** + * Add comment insert notification to the notification queue + * + * @param $recipients + * An array with UID as key of recipient user objects with attributes name, mail and uid + * @param $subject + * The subject of the notification + * @param $node + * The object of the node the anonymous user is now watching + */ +function _watcher_email_notify_comment_insert_add_to_queue($recipients, $subject, $comment) { + foreach ($recipients as $recipient) { + + $message = ''; + + // Get message header with tokens replaced + // Do not include headers for anonymous recipients (they have no user name) + if ($recipient->uid) { + $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $comment['nid'], 'header'); + } + + // Get message body with tokens replaced + $message .= _watcher_email_notifications_replace_tokens_comment_insert($comment, $recipient); + + // Get message footer with tokens replaced + // Use different templates depending on whether this is a regular or anonymous recipient + if ($recipient->uid) { + $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $comment['nid'], 'footer'); + } + else { + $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $comment['nid'], 'footer_anonymous_notify'); + } + + // Add to message queue + $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : true ); + } + return $res; +} + +/** + * Send a confirmation message upon anonymous user starting to watch a node + * + * @param $user + * A user object + * @param $nid + * NID of node being watched + */ +function _watcher_email_notify_anonymous_watch_confirm($user, $nid, $what = null) { + + // Are email notifications enabled? + $email_notifications = variable_get('watcher_email_notifications_enabled', true); + if (!$email_notifications) { + return false; + } + + // Add user to recipients + $recipients[] = $user; + + // Load node + $node = node_load($nid); + + // Adapt subject depending on what the user is watching for + $subj_for_what['all'] = ' '. t('for updates and new comments'); + $subj_for_what['comments'] = ' '. t('for new comments'); + $subj_for_what['updates'] = ' '. t('for updates'); + + // Set up subject + $node_title = check_plain($node->title ? t(' "!nodetitle"', array('!nodetitle' => substr($node->title, 0, 128))) : false); + $site_name = ( variable_get('site_name', false ) ? ' ('. variable_get('site_name', '') .')' : '' ); + $subject = t('You are now watching!aboutnodetitle!forwhat!sitename', array('!aboutnodetitle' => $node_title, '!forwhat' => $subj_for_what[$what], '!sitename' => $site_name)); + + // Add to queue + _watcher_email_notify_anonymous_watch_confirm_add_to_queue($recipients, $subject, $node); + + // Flag that there are messages in queue + _watcher_static('messages to send', true); + +} + +/** + * Add confirm anonymous watching notification to the notification queue + * + * @param $recipients + * An array with UID as key of recipient user objects with attributes name, mail and uid + * @param $subject + * The subject of the notification + * @param $node + * Node object of the node that is now being watched + */ +function _watcher_email_notify_anonymous_watch_confirm_add_to_queue($recipients, $subject, $node) { + foreach ($recipients as $recipient) { + // Get message body with tokens replaced + $message .= _watcher_email_notifications_replace_tokens_anonymous_watch_confirm($node, $recipient); + + // Get message footer with tokens replaced + $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $node->nid, 'footer_confirm'); + + // Add to message queue + $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : true ); + } + return $res; +} + + +/** + * Is the user watching the node? + * + * @param $user + * A user object + * @param $nid + * Node NID + */ +function _watcher_user_is_watching_node($user, $nid) { + + $uid = $user->uid; + $mail = $user->mail; + + // Cache result for a given uid or email address, + // this saves us a lot of unnecessary queries! + static $result; + + // We have to look up anonymous users by email + if (!$uid) { + if (!isset($result[$mail])) { + $result[$mail] = _watcher_db_get_nids_by_user($user); + } + return $result[$mail][$nid]; + } + else { + if (!isset($result[$uid])) { + $result[$uid] = _watcher_db_get_nids_by_user($user); + } + return $result[$uid][$nid]; + } + +} + +/** + * Set user watching post + * + * @param $nid + * Node NID + * @param $user + * A user object + * @param $what + * A string representing what the user wishes to watch for: all, comments, updates + * + * @return + * Boolean true on success, false on failure + */ +function _watcher_user_set_watching_node($nid, $user, $what = null) { + + // Check whether this is one of the node types for which Watcher is enabled + if (!_watcher_node_type_enabled($nid)) { + return false; + } + + // For logged-in users, we check if the user is watching the node + // For anonymous, we start watching regardless of whether the user was watching before or not + if (($user->uid && !_watcher_user_is_watching_node($user, $nid)) || !$user->uid) { + if (_watcher_db_set_nid_user($nid, $user, $what)) { + // Automatically enable notifications for this node if the user has + // set this option, it's in the defaults or the user is anonymous as + // anonymous users must be notified as they do not have a binder + if (_watcher_user_settings_load('watcher_automatic_enable_notifications') || !$user->uid) { + _watcher_email_notifications_enable($nid, $user); + } + return true; + } + } + return false; +} + +/** + * Unset user watching posts + * + * @param $nids + * Array of node NIDs + * @param $user + * A user object + * + * @return + * A boolean indicating success + */ +function _watcher_user_unset_watching_nodes($nids, $user) { + return (_watcher_db_delete_nids_user($nids, $user)); +} + +/** + * Autowatch a node the user has posted + * + * @param $nid + * Node NID + */ +function _watcher_user_autowatch_node_insert($nid) { + global $user; + if (_watcher_user_settings_load('watcher_autowatch_posted')) { + _watcher_user_set_watching_node($nid, $user); + } +} + +/** + * Autowatch a node the user has commented on + * + * @param $comment + * A comment object as provided by hook_comment + */ +function _watcher_user_autowatch_comment_insert($comment) { + global $user; + + if (_watcher_user_settings_load('watcher_autowatch_commented_on')) { + _watcher_user_set_watching_node($comment['nid'], $user); + } +} + +/** + * Return a link for watching/unwatching a post + */ +function _watcher_node_watch_link(&$node, $a3, $a4) { + + global $user; + $anonymous = !((bool) $user->uid); + + // If email notifications are disabled, no link will be shown to anonymous users + // as email notifications must be enabled for anonymous users to be notified + // since they do not have their own binder + $email_notifications = variable_get('watcher_email_notifications_enabled', true); + if ($anonymous && !$email_notifications) { + return; + } + + // Do not display toggle watch link in teaser if admin has disabled link for teaser + $link_in_teaser = variable_get('watcher_toggle_link_in_teaser', false); + if ($a3 && !$link_in_teaser) { + return false; + } + + // Keep track of whether the module has been run multiple times + static $called; + + // Is current user watching this node? + if ($anonymous) { + if (is_array($watches = _watcher_session('watching'))) { + $watching = in_array($node->nid, $watches); + } + } + else { + $watching = _watcher_user_is_watching_node($user, $node->nid); + } + + $link_query = drupal_get_destination() ."&token=". _watcher_get_token($node->nid, $user->uid); + + // Make localized strings + $tstrings = array(); + $tstrings['watch_toggle_enabled'] = 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_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 + $tstrings['watch_watched_posts_link'] = l(t('Go to your list of watched posts'), 'user/'. $user->uid .'/watcher', array('attributes' => array('class' => 'watcher_node_help_link_to_binder'))); + + // Add JS setting boolean variable indicating whether the current user is anonymous or not + $settings['watcher'] = array('user_is_anonymous' => (bool) $user->uid); + + // Add JS for AJAX + drupal_add_js(drupal_get_path('module', 'watcher') .'/js/watcher.js'); + + // Load language strings into JS + $settings['watcher'] += $tstrings; + // We should only call drupal_add_js once or we'll end up with arrays instead of + // strings in our JS settings + if (!$called) { + drupal_add_js($settings, 'setting'); + $called = true; + } + + // 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, $link_query, $watching, $tstrings), + '#weight' => 30, + ); +} + +/** + * Save user settings for Watcher + * + * @param $settings + * An associative array of user settings, usually a subset of a form array + * @param $uid + * UID of user who these settings apply to + * @param $form + * A boolean denoting whether the function was called as a result from + * the user using the user settings form in their user profile + */ +function _watcher_user_settings_save($settings, $uid = null) { + global $user; + + // Save to database + $uid = ( $uid ? $uid : $user->uid ); + if (_watcher_db_set_user_settings($uid, $settings)) { + drupal_set_message(t('Settings saved.')); + return true; + } + +} + +/** + * Load user settings for Watcher + * + * @param $setting + * The setting to be loaded + * @param $acct_uid + * The UID of the user account the setting applies to. + * + * @return + * The setting's value as a string or null. + */ +function _watcher_user_settings_load($setting, $acct_uid = null) { + // Include DB dependent functions + module_load_include('inc', 'watcher', 'watcher.db'); + + global $user; + $uid = ( is_numeric($acct_uid) ? $acct_uid : $user->uid ); + + // Anonymous users cannot have settings + if (!$uid) { + return false; + } + + // Strip watcher_ + if (preg_match('/^watcher_(.*)/', $setting, $matches)) { + $setting = $matches[1]; + } + + // Cache settings + static $settings; + + // Load from db if setting isn't cached + if (!isset($settings[$setting])) { + $settings = _watcher_db_get_user_settings($uid); + } + + // Return the requested setting + return $settings[$setting]; +} + +/** + * Set passed default settings for user who have not customized their settings + * + * @param $default_settings + * An assoc array of user settings + * + */ +function _watcher_user_settings_update_defaults($default_settings = null) { + // Load defaults if not passed as argument + if (!$default_settings) { + $default_settings = _watcher_user_settings_load_defaults(); + } + + // DB query + _watcher_db_user_settings_update_defaults($default_settings); +} + +/** + * Returns the default user settings either as passed as an argument or loaded from variables as an associative array + * + * @param $default_settings + * An associative array of default user settings, keys with watcher_ prefix + * + * @return + * An associate array of user settings + */ +function _watcher_user_settings_load_defaults($default_settings = null) { + static $settings; + + if (!$settings) { + // Load defaults + $dsettings = ( $default_settings ? $default_settings : variable_get('watcher_default_settings', 0) ); + + // If defaults have been set, generate an associative array + if (is_array($dsettings)) { + + // Build query string elements + foreach ($dsettings as $dsetting => $value) { + + // Strip watcher_ + preg_match('/^watcher_(.*)/', $dsetting, $matches); + $setting = $matches[1]; + + // Add new element + $settings[$setting] = (int) (bool) $value; + } + } + } + + // If all defaults are "off", the settings array contains an element with + // an empty key which we need to delete + unset($settings['']); + + // Return the finished array + return $settings; +} + +/** + * Returns templates for some settings fields that are textareas + */ +function _watcher_admin_settings_field_value_templates() { + + // Heredoc syntax used for convenience. + + // Intro text on binder ////////////////////////////////////// + + $templates['watcher_display_intro_text'] = <<watching posts that you want to keep an eye on you can see (and be notified) when they're updated or changed or when new comments are posted. This page lists all posts that you are currently watching. Click Help to learn more. + +EOT; + //' + // Header ////////////////////////////////////// + + $templates['header'] = <<It's sometimes difficult to keep track of posts that are interesting or which you have been posting comments on. By watching posts that you want to keep an eye on you can see (and be notified) when they're updated or changed or when new comments are posted.

+ +

Basic use

+
    +
  • To start watching a post, click the link you see by the post on the site. The post is now added to your list of watched posts. Click again to stop watching the post.
  • +
  • In your watched posts list you can see all posts that you are watching. You can also see the number of comments and how many of those are new (not yet read by you).
  • +
  • If the site owner has enabled email notifications, next to each post is an icon that tells you whether changes to this post results in notifications by email. Click the icon to enable/disable email notifications. Emails are sent to the email address you have entered in your site account details.
  • +
  • To stop watching posts, either click the trash can icon next to the post in your watched posts list or click the link by the post.
  • +
+ + +

Settings

+

The settings page allows you to customize how and when posts are watched and notifications are sent. The site owner may have set default settings that will apply to all users who have not modified their settings. The default settings will apply until you have modified your settings.

+
+
Email Notification Settings
+
The email notification settings allow you to change your preferences regarding how and when email notifications are sent. +
+
Automatically enable email notifications for posts that I start watching
+
When you start watching a post, email notifications are automatically enabled for it as well. You can disable email notifications by clicking the email icon in your watched posts list.
+
Send email notification when a post is updated or edited
+
An email notification is sent when the post is changed, either by its original author or someone else. This is useful for being notified about changes to posts that many users may edit. You will not be notified if you edited the post yourself.
+
Send email notification when a post receives a new comment
+
An email notification will be sent when a new comment is posted to the post you're watching. You will not be notified about comments you have made yourself.
+
+
+
Watch Automatically
+
These settings control when posts are watched automatically without you having to manually click "watch this post". +
+
Automatically watch posts that I comment on
+
When you post a comment on a post, the post will be added to your watched posts list without you having to manually add it. This is handy if you always want to watch all posts you have commented on and discuss with other users.
+
Automatically watch posts that I make
+
Posts that you have made will automatically be added to your watched posts list. This helps you keep track of what changes are made to your posts and the comments that are posted about your posts.
+
+
+
Sharing
+
Your list of watched posts can be shared with other users. +
+
Share my list of watched posts
+
If you want other users to be able see what posts you watch, enable this setting. When you're sharing your list, a link will appear in your profile allowing other users to browse your list of watched posts.
+
+
+
+EOT; + + //'//fix for phpeclipse syntax highlighter bug + $templates['watcher_help_text'] .= ''; + + ///////////////////////////////////////////////////////////// + + return $templates; + +} + +/** + * Return the number of comments and new comments for a node + * + * @param $node A node object + */ +function _watcher_binder_comment_count($node) { + $comments = 0; + if ($node->comment_count) { + $comments = $node->comment_count; + + if ($new = comment_num_new($node->nid)) { + $comments .= '
'; + $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('fragment' => 'new')); + } + } + return $comments; +} + + +/** + * Return a message for an updated node with tokens replaced + * + * @param $object + * A node object + */ +function _watcher_email_notifications_replace_tokens_node_update($node) { + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + // Get message template from settings + $message = variable_get('watcher_notifications_templates_body_node', $templates['body_node_update']) ."\r\n"; + + // Start by replacing our own tokens + $node_url = url('node/'. $node->nid, array('absolute' => true)); + + $tokens = array('[node-url]'); + $replaces = array($node_url); + + $message = str_replace($tokens, $replaces, $message); + + // Replace tokens supplied by Token Module + $message = token_replace($message, 'node', $node); + + return $message; +} + +/** + * Return a message for a new comment with tokens replaced + */ +function _watcher_email_notifications_replace_tokens_comment_insert($comment) { + // Cache excerpt since it doesn't vary and requires regular expressions + // to produce - thus may be expensive if there are many recipients + static $comment_excerpt; + + // Cache node object, node_load() caches too under certain conditions, + // but we cache regardless of circumstances + static $node; + + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + // Get message template from settings + $message = variable_get('watcher_notifications_templates_body_cmt', $templates['body_comment_insert']) ."\r\n"; + + // Load the node the comment is about, cache it to save queries + if (!isset($node)) { + $node = node_load($comment['nid']); + } + + // Start by replacing our own tokens + + // Load excerpt from cached static + if (!isset($comment_excerpt)) { + $comment_excerpt = _watcher_email_notifications_create_excerpt($comment['comment']); + } + $comment_url = url('node/'. $comment['nid'], array('fragment' => 'comment-'. $comment['cid'], 'absolute' => true)); + $comment_reply_url = url('comment/reply/'. $comment['nid'] .'/'. $comment['cid'], array('absolute' => true)); + $node_url = url('node/'. $comment['nid'], array('absolute' => true)); + + $tokens = array('[comment-excerpt]', '[comment-url]', '[comment-reply-url]', '[node-url]'); + $replaces = array($comment_excerpt, $comment_url, $comment_reply_url, $node_url); + + $message = str_replace($tokens, $replaces, $message); + + // Replace tokens supplied by Token Module + $message = token_replace($message, 'comment', $comment); + $message = token_replace($message, 'node', $node); + + return $message; +} + +/** + * Return a message for a confirmation email to an anonymous user + */ +function _watcher_email_notifications_replace_tokens_anonymous_watch_confirm($node, $recipient) { + + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + // Get message template from settings + $message = variable_get('watcher_notifications_templates_body_confirm', $templates['body_confirm']) ."\r\n"; + + // Start by replacing our own tokens + $node_url = url('node/'. $node->nid, array('absolute' => true)); + $tokens = array('[node-url]'); + $replaces = array($node_url); + $message = str_replace($tokens, $replaces, $message); + + // Replace tokens supplied by Token Module + $message = token_replace($message); + + return $message; +} + +/** + * Return a message header or footer + */ +function _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $nid, $type = 'header') { + // Load notification message templates + $templates = _watcher_admin_settings_field_value_templates(); + + // Get header/footer template from settings + $message = variable_get("watcher_notifications_templates_$type", $templates[$type]); + + // Set recipient email address + $r_email = ( $recipient->mail ? $recipient->mail : ( $recipient->umail ? $recipient->umail : $recipient->wnmail )); + + $link_query = "token=". _watcher_get_token($nid, $recipient->uid); + + // Start by replacing our own tokens + $recipient_username = $recipient->name; + $recipient_user_settings_url = url('user/'. $recipient->uid .'/watcher/settings', array('absolute' => true)); + $stop_watching_url = url('user/'. $recipient->uid .'/watcher/toggle/'. $nid . ( $recipient->uid ? '' : '/unwatch/'. $r_email ), array('absolute' => true, 'query' => $link_query)); + $stop_watching_all_url = url('user/'. $recipient->uid .'/watcher/toggle/'. $nid .'/unwatch-all/'. $r_email, array('absolute' => true, 'query' => $link_query)); + + $tokens = array('[recipient-username]', '[recipient-user-settings-url]', '[stop-watching-url]', '[stop-watching-all-url]', '[user-ip]'); + $replaces = array($recipient_username, $recipient_user_settings_url, $stop_watching_url, $stop_watching_all_url, $recipient->ip); + + $message = str_replace($tokens, $replaces, $message); + + // Replace tokens supplied by Token Module + $message = token_replace($message); + + return $message; +} + +/** + * Create an excerpt from a string disregarding words, just plain truncation + * + * @param $text + * The text we want to create an excerpt from + */ +function _watcher_email_notifications_create_excerpt($text) { + + // Load current excerpt length setting + $set = variable_get('watcher_email_notification_comment_excerpt_len', '200chars'); + + // Strip tags since we don't want HTML emails + $text = strip_tags($text); + + // Filter XSS, filter out potentially dangerous stuff + $text = filter_xss($text); + + // Get text's length + $textlen = strlen($text); + + // Determine the type of setting (percent or absolute) and calculate excerpt length + $matches = array(); + if (preg_match('/^(.*)chars$/', $set, $matches)) { + $len = $matches[1]; + } + elseif (preg_match('/^(.*)percent$/', $set, $matches)) { + $len = $textlen * ( $matches[1] / 100 ); + $len = round($len); + } + elseif ($set == 'nothing') { + $len = 0; + } + elseif ($set == 'entire') { + $len = $textlen; + } + + // Create an excerpt + if ($len > 0) { + return (substr($text, 0, $len)); + } + + return null; + +} + +/** + * Determine whether this node is of one of the node types for which Watcher is enabled + * + * @param $n A node identifier, eiher a NID (int) or a node object + */ +function _watcher_node_type_enabled($n) { + // Cache node type status + static $nodes; + if (is_numeric($n)) { + if (!isset($nodes[$n])) { + $nodes[$n] = node_load($n); + } + $node = $nodes[$n]; + } + elseif (isset($n->nid) && isset($n->type)) { + if (!isset($nodes[$n->nid])) { + $nodes[$n->nid] = $n; + } + $node = $nodes[$n->nid]; + } + + if ($node) { + // Load enabled node types for Watcher + $enabled_node_types = variable_get('watcher_content_types', array()); + + // Return match + return (bool) $enabled_node_types[$node->type]; + } + return false; +} + +/** + * Add a message to the notification message queue + * + * @param $recipient + * An object with properties uid, name and mail + * @param $subject + * Message subject + * @param $message + * The contents of the email message + */ +function _watcher_email_notifications_add_to_queue($recipient, $subject, $message) { + // $recipient is an object, obtain variable values + $r_uid = $recipient->uid; + // Set mail. Anonymous users have their emails stored in wnmail, registered in umail + $r_email = ( $recipient->mail ? $recipient->mail : ( $recipient->umail ? $recipient->umail : $recipient->wnmail )); + + // Add to database + return (_watcher_db_insert_users_notification_queue($r_uid, $r_email, $subject, $message)); +} + +/** + * Send all messages in queue using the instantaneous method + */ +function _watcher_email_notifications_send_instant() { + + // If there are messages to send, proceed to sending them + if (_watcher_static('messages to send')) { + $method = variable_get('watcher_email_notifications_method', 'cron'); + if ($method == 'instant') { + return _watcher_email_notifications_send_queue(); + } + } + +} + +/** + * Send all messages in queue using the cron method + */ +function _watcher_email_notifications_send_cron() { + $method = variable_get('watcher_email_notifications_method', 'cron'); + if ($method == 'cron') { + return _watcher_email_notifications_send_queue(); + } +} + +/** + * Send all messages in queue + */ +function _watcher_email_notifications_send_queue() { + + // Obtain current queue + $qmsgs = _watcher_db_get_users_notification_queue(); + + // Normally, we should have an array of notifications but let's check + // just to be sure + if (is_array($qmsgs)) { + + // Start the timer + _watcher_email_notifications_send_queue_timer(true); + + // Process queue until timer says stop (returns false) or we run out of notifications + while ((list($k, $qmsg) = each($qmsgs)) && _watcher_email_notifications_send_queue_timer()) { + + // Send message and add it to the sent messages array + if (_watcher_email_notifications_send_message($qmsg)) { + $sent_qmsgs[$qmsg->qid] = $qmsg->qid; + } + + } + + // Purge sent messages from queue + if (count($sent_qmsgs)) { + _watcher_db_delete_users_notification_queue($sent_qmsgs); + } + + // Make Watchdog entry + $method = variable_get('watcher_email_notifications_method', 'cron'); + if ($sent_qmsgs) { + watchdog('Watcher', 'Watcher has successfully sent !notifications using the !method method.', array('!notifications' => format_plural(count($sent_qmsgs), '1 notification', '@count notifications'), '!method' => $method)); + } + else { + watchdog('Watcher', 'Watcher failed to send notifications using the !method method.', array('!method' => $method), WATCHDOG_ERROR); + } + + } + + return (bool) $sent_qmsgs; + +} + +/** + * Start the timer we use when sending messages + * + * @param $start boolean + * A boolean denoting that the timer should start + * + * @return + * A boolean true if the time limit hasn't expired, a false if it has + */ +function _watcher_email_notifications_send_queue_timer($start = false) { + // Store current time in a static var + static $start_time; + static $time_limit; + + // Get time limit from settings + if (!$time_limit) { + $time_limit = variable_get('watcher_email_notifications_send_time_limit', 5); + + // Time limit may be a string, if so it's "unlimited" so set it high + if (!is_numeric($time_limit)) { + $time_limit = 99999999999999; + } + $time_limit = (float) $time_limit; + } + + // Get current time in seconds and microseconds + list($msec, $sec) = explode(" ", microtime(true)); + $cur_time = ((float)$msec + (float)$sec); + + // We're starting, set starting time + if ($start) { + $start_time = $cur_time; + } + // Checked whether the timer has expired + else { + $elapsed_time = $cur_time - $start_time; + return ($elapsed_time < $time_limit); + } +} + +/** + * Send a message + * + * @param $qmsg + * An object containing a queue item with properties qid, uid, mail, subject and message + */ +function _watcher_email_notifications_send_message($qmsg) { + + // Cache 'from' header + static $from; + + // Set up addresses + $site_name = check_plain(variable_get('site_name', '')); + $site_mail = variable_get('site_mail', ini_get('sendmail_from')); + + // No need to generate the from header more than once + if (!isset($from)) { + $from = sprintf('"%s" <%s>', mime_header_encode(_watcher_filter_rfc2047_especials($site_name)), $site_mail); + } + + // Subject + // Decode html entities, quotes in particular so we don't get HTML character + // entity tags in our emails, finally strip RFC 2047 especials + $subject = html_entity_decode(strip_tags(filter_xss($qmsg->subject)), ENT_QUOTES); + + // To + $to = $qmsg->mail; + + // Body + $body = html_entity_decode(strip_tags(filter_xss($qmsg->message)), ENT_QUOTES); + + // Key + $key = 'watcher#'. $qmsg->qid; + + // Set up params + $params['subject'] = $subject; + $params['body'] = $body; + + // Language + $language = language_default(); + + // Send email + $message = drupal_mail('watcher', 'notification', $to, $language, $params, $from, true); + + return $message['result']; + +} + +/** + * Displays a form with an email address field + * + * @param $nid + * A node id NID + * @param $watch_action + * The watch action to be carried out: watch or unwatch + * + * @return + * A FAPI form array + */ +function _watcher_watch_toggle_anonymous_form(&$form_state, $nid, $watch_action){ + + // Load previous entered form details from current session + $mail = _watcher_session('mail'); + $what = _watcher_session('what'); + + $node = node_load($nid); + + // Load the mail footer template + $templates = _watcher_admin_settings_field_value_templates(); + $message = variable_get("watcher_notifications_templates_$type", $templates['footer_confirm']); + + // Determine if user's IP address token is included in template + $ip_reported = (strpos($message, '[user-ip]') !== false); + + // Messages + $ip_info = ' '. t("The confirmation message contains your IP address so that in case of abuse the owner of the email account can identify who submitted the form."); + + $form = array(); + + // Help text depending on watch action + if ($watch_action == 'unwatch') { + $form['watcher'] = array ( + '#type' => 'fieldset', + '#title' => ''. t("Stop watching %title", array('%title' => check_plain($node->title))) .'', + ); + $info = t("Enter your email address below to stop watching %title. The form will remember the email you enter until next time.", array('%title' => check_plain($node->title), '%ipinfo' => ( $ip_reported ? $ip_info : null ))); + } + else { + $form['watcher'] = array ( + '#type' => 'fieldset', + '#title' => ''. t("Watch %title", array('%title' => check_plain($node->title))) .'', + ); + $info = t("Enter your email address below to start watching %title. The form will remember the email you enter until next time. Once you submit the form, a confirmation message will be sent to the email address entered. %ipinfo", array('%title' => $node->title, '%ipinfo' => ( $ip_reported ? $ip_info : null ))); + } + + $form['watcher'][] = array( + '#value' => $info, + '#weight' => 0, + ); + + $form['watcher']['mail'] = array( + '#type' => 'textfield', + '#title' => t('Your email address'), + '#default_value' => $mail, + '#size' => 32, + '#maxlength' => 128, + '#required' => true, + '#weight' => 5, + ); + + // If the user wants to start watching, present what to watch for + if ($watch_action == 'watch') { + $form['watcher']['what'] = array( + '#type' => 'select', + '#title' => t('What to watch for'), + '#options' => array( + 'all' => t('Updates and new comments'), + 'comments' => t('Only new comments'), + 'updates' => t('Only updates'), + ), + '#default_value' => $what, + '#description' => t('Choose to be informed about new comments, updates (this post being changed) or both.'), + '#required' => true, + '#weight' => 10, + ); + } + + $form['watcher']['submit'] = array( + '#type' => 'submit', + '#value' => ( $watch_action == 'watch' ? t('Watch') : t('Unwatch') ), + '#weight' => 15, + ); + + $form['watcher']['nid'] = array( + '#type' => 'hidden', + '#value' => $nid + ); + + $form['watcher']['watch_action'] = array( + '#type' => 'hidden', + '#value' => $watch_action + ); + + return $form; +} + +/** + * Stores a value in a static variable + * + * @param $name + * The name of the value to store + * @param $value + * The value to store, if omitted stored value for $name is returned + * @return + * If $value is not passed, the value stored for $name is returned + */ +function _watcher_static($name, $value = null) { + static $static; + if (is_null($value)) { + return $static[$name]; + } + $static[$name] = $value; +} + +/** + * Removes especials in RFC2047 from string + * + * @param $string + * String to be processed + * @return + * A string without RFC2047 especials + */ +function _watcher_filter_rfc2047_especials($string) { + $especials = array('(', ')', '<', '>', '@', ',', ';', ':', '/', '[', ']', '?', '.', '='); + return str_replace($especials, '', $string); +} + +/** + * Store and retrieve variables from session + * + * @param $key + * Key to be set or got + * @param $value + * Value to set for $key + * @return + * If only $key is given, sought-after value for key + */ +function _watcher_session($key, $value = null) { + if (isset($value)) { + unset($_SESSION[$key]); + $_SESSION[$key] = $value; + } + + if (isset($_SESSION[$key])) { + return $_SESSION[$key]; + } +} + + +/*************************************************************************************** + * SUBMIT HANDLERS + ***************************************************************************************/ + +/** + * Handle user settings form submit + * + * @param $form + * A form array + * @param $form_state + * A form state array + */ +function _watcher_user_settings_submit($form, &$form_state) { + + // Extract settings + foreach ($form_state['values'] as $key => $item) { + if (preg_match('/^watcher_(.*)/', $key, $matches)) { + $setting_key = $matches[1]; + $tosave[$setting_key] = $item; + } + } + + _watcher_user_settings_save($tosave, $form_state['values']['uid']); +} + +/** + * Handle anonymous watch toggle form submit + * + * @param $form + * A form array + * @param $form_state + * A form state array + */ +function _watcher_watch_toggle_anonymous_form_submit($form, &$form_state) { + global $user; + $nid = $form_state['values']['nid']; + $what = $form_state['values']['what']; + $watch_action = $form_state['values']['watch_action']; + $node = node_load($nid); + + // Get user's IP, even when behind proxy/cache server + if (!($user->ip = $_SERVER['HTTP_X_FORWARDED_FOR'])) { + $user->ip = $_SERVER['REMOTE_ADDR']; + } + + // Store form details in session for use later + _watcher_session('mail', $form_state['values']['mail']); + _watcher_session('what', $form_state['values']['what']); + + // Add user's email to $user object + $user->mail = $form_state['values']['mail']; + + // Get destination for redirection later on + $dest = drupal_get_destination(); + + // Handle watching/unwatching + if ($watch_action == 'unwatch') { + if ($user->mail && _watcher_user_unset_watching_nodes(array($nid), $user)) { + $message = t('You are no longer watching %ntitle. Undo', array('%ntitle' => check_plain($node->title), '!undo' => url("user/$user->uid/watcher/toggle/$node->nid", array('query' => $dest)))); + drupal_set_message($message); + + // Remove NID from session to mark it as no longer being watched + $nids = _watcher_session('watching'); + if (is_array($nids)) { + unset($nids[$nid]); + _watcher_session('watching', $nids); + } + } + else { + $message = t('That email address is not associated with any user watching %ntitle', array('%ntitle' => check_plain($node->title))); + drupal_set_message($message); + } + } + else { + if (_watcher_user_set_watching_node($nid, $user, $what)) { + + // Adapt message depending on what the user is watching for + $message_what['all'] = t('updates and new comments'); + $message_what['comments'] = t('new comments'); + $message_what['updates'] = t('updates'); + + $message = t('You are now watching %ntitle for !what. A message will be sent to the email address you entered (%email) to confirm this action.', array('%ntitle' => $node->title, '%email' => $user->mail, '!what' => $message_what[$what])); + drupal_set_message($message); + + // Store node's NID in session to mark it as being watched + if (!is_array($nids = _watcher_session('watching'))) { + $nids = array(); + } + $nids[$nid] = $nid; + _watcher_session('watching', $nids); + + // Send confirmation message + _watcher_email_notify_anonymous_watch_confirm($user, $nid, $what); + } + } + + // Redirect user back to originating page + drupal_goto(); +} + +/** + * Get a private token used to protect links from spoofing - CSRF. + */ +function _watcher_get_token($seed, $uid = false) { + if ($uid === false) { + $uid = $GLOBALS['user']->uid; + } + return drupal_get_token($seed . $uid); +} + +/** + * Check to see if a token value matches the specified node. + */ +function _watcher_check_token($token, $seed, $uid = false) { + if ($uid === false) { + $uid = $GLOBALS['user']->uid; + } + return drupal_get_token($seed . $uid) == $token; +} + +/** + * FORM VALIDATORS + */ + +/** + * Validate an anonymous user watch toggle form + * + * @param $form + * Structured FAPI form + * @param $form_state + * Populated form with values + */ +function _watcher_watch_toggle_anonymous_form_validate($form, &$form_state) { + if (!valid_email_address(trim($form_state['values']['mail']))) { + form_set_error('mail', t('You must enter a valid e-mail address.')); + } +} + +// EOF