diff --git a/adm/style/acp_newspage_settings.html b/adm/style/acp_newspage_settings.html index c3b291e..6a411b0 100644 --- a/adm/style/acp_newspage_settings.html +++ b/adm/style/acp_newspage_settings.html @@ -1,65 +1,65 @@ - +{% include 'overall_header.html' %} -

{L_ACP_NEWSPAGE}

-

{L_ACP_NEWSPAGE_SETTINGS_EXPLAIN}

+

{{ lang('ACP_NEWSPAGE') }}

+

{{ lang('ACP_NEWSPAGE_SETTINGS_EXPLAIN') }}

-
+
- {L_ACP_NEWSPAGE_SETTINGS} + {{ lang('ACP_NEWSPAGE_SETTINGS') }}
-

{L_NEWS_ICON_EXPLAIN}
-
+

{{ lang('NEWS_ICON_EXPLAIN') }}
+
-
-
+
+
-
-
+
+
-
-
+
+
-

{L_NEWS_CHAR_LIMIT_EXPLAIN}
-
+

{{ lang('NEWS_CHAR_LIMIT_EXPLAIN') }}
+
-
-
checked="checked" />
+
+
-
-
checked="checked" />
+
+
-
-
checked="checked" />
+
+
-

{L_NEWS_USER_INFO_EXPLAIN}
-
checked="checked" />
+

{{ lang('NEWS_USER_INFO_EXPLAIN') }}
+
-

{L_NEWS_POST_BUTTONS_EXPLAIN}
-
checked="checked" />
+

{{ lang('NEWS_POST_BUTTONS_EXPLAIN') }}
+
-

{L_NEWS_LEAD_IMAGE_EXPLAIN}
-
checked="checked" />
+

{{ lang('NEWS_LEAD_IMAGE_EXPLAIN') }}
+
-

{L_NEWS_ATTACH_SHOW_EXPLAIN}
-
checked="checked" />
+

{{ lang('NEWS_ATTACH_SHOW_EXPLAIN') }}
+
- - - {S_FORM_TOKEN} + + + {{ S_FORM_TOKEN }}
- +{% include 'overall_footer.html' %} diff --git a/config/services.yml b/config/services.yml index 2a37252..e3869e9 100644 --- a/config/services.yml +++ b/config/services.yml @@ -5,7 +5,6 @@ services: - "@config" - "@dispatcher" - "@template" - - "@user" - "@controller.helper" - "@phpbbmodders.newspage" - "%core.root_path%" @@ -31,7 +30,7 @@ services: - "@cache" - "@config" - "@dbal.conn" - - "@request" + - "@profilefields.manager" - "@template" - "@user" - "@content.visibility" @@ -58,6 +57,7 @@ services: arguments: - "@phpbbmodders.newspage.helper" - "@user" + - "@auth" - "%core.php_ext%" tags: - { name: event.listener } diff --git a/controller/main.php b/controller/main.php index 15bb624..893095c 100644 --- a/controller/main.php +++ b/controller/main.php @@ -34,9 +34,6 @@ class main /* @var \phpbb\template\template */ protected $template; - /* @var \phpbb\user */ - protected $user; - /* @var \phpbb\controller\helper */ protected $helper; @@ -55,18 +52,16 @@ class main * @param \phpbb\config\config $config * @param \phpbb\event\dispatcher $dispatcher * @param \phpbb\template\template $template - * @param \phpbb\user $user * @param \phpbb\controller\helper $helper * @param \phpbbmodders\newspage\newspage $newspage * @param string $root_path * @param string $php_ext */ - public function __construct(\phpbb\config\config $config, \phpbb\event\dispatcher $dispatcher, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbbmodders\newspage\newspage $newspage, $root_path, $php_ext) + public function __construct(\phpbb\config\config $config, \phpbb\event\dispatcher $dispatcher, \phpbb\template\template $template, \phpbb\controller\helper $helper, \phpbbmodders\newspage\newspage $newspage, $root_path, $php_ext) { $this->config = $config; $this->dispatcher = $dispatcher; $this->template = $template; - $this->user = $user; $this->helper = $helper; $this->newspage = $newspage; $this->root_path = $root_path; @@ -178,7 +173,6 @@ public function base($display_pagination = true) } $this->newspage->base(); - $this->assign_images($this->config['news_user_info'], $this->config['news_post_buttons']); $this->template->assign_vars(array( 'S_ON_NEWSPAGE' => true, @@ -186,38 +180,4 @@ public function base($display_pagination = true) return $this->helper->render('newspage_body.html', $this->newspage->get_page_title()); } - - /** - * @param bool $assign_user_buttons - * @param bool $assign_post_buttons - */ - protected function assign_images($assign_user_buttons, $assign_post_buttons) - { - $this->template->assign_vars(array( - 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'POST_REPORTED'), - )); - - if ($assign_user_buttons) - { - $this->template->assign_vars(array( - 'PROFILE_IMG' => $this->user->img('icon_user_profile', 'READ_PROFILE'), - 'SEARCH_IMG' => $this->user->img('icon_user_search', 'SEARCH_USER_POSTS'), - 'PM_IMG' => $this->user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'), - 'EMAIL_IMG' => $this->user->img('icon_contact_email', 'SEND_EMAIL'), - 'JABBER_IMG' => $this->user->img('icon_contact_jabber', 'JABBER'), - )); - } - - if ($assign_post_buttons) - { - $this->template->assign_vars(array( - 'QUOTE_IMG' => $this->user->img('icon_post_quote', 'REPLY_WITH_QUOTE'), - 'EDIT_IMG' => $this->user->img('icon_post_edit', 'EDIT_POST'), - 'DELETE_IMG' => $this->user->img('icon_post_delete', 'DELETE_POST'), - 'INFO_IMG' => $this->user->img('icon_post_info', 'VIEW_INFO'), - 'REPORT_IMG' => $this->user->img('icon_post_report', 'REPORT_POST'), - 'WARN_IMG' => $this->user->img('icon_user_warn', 'WARN_USER'), - )); - } - } } diff --git a/docs/TODO.md b/docs/TODO.md index e521630..0327ebc 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -1,6 +1,4 @@ # TODO -- **German ACP and install strings**: `language/de/` only has `newspage.php`. The ACP settings page - (`info_acp_newspage.php`) and the enable messages (`install_newspage.php`) fall back to English. - **Version check**: no phpBB.com listing for this extension could be confirmed. Once it has one, add an `extra.version-check` block to `composer.json` pointing at it, so the ACP can report new releases. diff --git a/event/viewonline_listener.php b/event/viewonline_listener.php index d8f9547..662d1b9 100644 --- a/event/viewonline_listener.php +++ b/event/viewonline_listener.php @@ -40,6 +40,9 @@ public static function getSubscribedEvents() /* @var \phpbb\user */ protected $user; + /* @var \phpbb\auth\auth */ + protected $auth; + /* @var string phpEx */ protected $php_ext; @@ -48,12 +51,14 @@ public static function getSubscribedEvents() * * @param \phpbbmodders\newspage\helper $helper * @param \phpbb\user $user + * @param \phpbb\auth\auth $auth * @param string $php_ext */ - public function __construct(\phpbbmodders\newspage\helper $helper, \phpbb\user $user, $php_ext) + public function __construct(\phpbbmodders\newspage\helper $helper, \phpbb\user $user, \phpbb\auth\auth $auth, $php_ext) { $this->helper = $helper; $this->user = $user; + $this->auth = $auth; $this->php_ext = $php_ext; } @@ -75,7 +80,14 @@ public function add_newspage_viewonline($event) $forum_id = $this->get_category_from_route($parts); $archive = $this->get_archive_from_route($parts); - if (count($parts) === 1) + // Name a forum only when it exists and the viewer may see it, as viewonline.php does + $hidden_forum = $forum_id && (!isset($event['forum_data'][$forum_id]) || !$this->auth->acl_get('f_list', $forum_id)); + if ($hidden_forum) + { + $forum_id = false; + } + + if (count($parts) === 1 || ($hidden_forum && !$archive)) { $event['location_url'] = $route->get_url(); $event['location'] = $this->user->lang('VIEWONLINE_NEWS'); diff --git a/language/de/newspage.php b/language/de/newspage.php deleted file mode 100644 index d8d66b0..0000000 --- a/language/de/newspage.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @copyright (c) 2026, phpBB Modders, https://www.phpbbmodders.com/ - * @license GNU General Public License, version 2 (GPL-2.0) - * - */ - -if (!defined('IN_PHPBB')) -{ - exit; -} -if (empty($lang) || !is_array($lang)) -{ - $lang = array(); -} - -$lang = array_merge($lang, array( - 'NEWS' => 'News', - 'NEWS_ADD_NEW' => 'Neu', - 'NEWS_ADD_NEW_TITLE' => 'Neuen News-Eintrag erstellen', - 'NEWS_ARCHIVE_SHOW' => 'Erlaube das Datum einzuschränken', - 'NEWS_ARCHIVE' => 'Archiv', - 'NEWS_ARCHIVE_OF' => 'Archiv vom %s', - 'NEWS_ATTACH_SHOW' => 'Anhänge anzeigen', - 'NEWS_ATTACH_SHOW_EXPLAIN' => 'Anhänge die in Beiträge eingefügt wurden, werden immer angezeigt.', - 'NEWS_CAT' => 'Foren', - 'NEWS_CAT_SHOW' => 'Erlaube die Foren einzuschränken', - 'NEWS_CHAR_LIMIT' => 'News-Einträge kürzen', - 'NEWS_CHAR_LIMIT_EXPLAIN' => 'Textlänge, „0“ um Kürzen zu unterbinden', - 'NEWS_COMMENTS' => 'Kommentare', - 'NEWS_COMMENTS_COUNT' => array( - 0 => 'Noch keine Kommentare', - 1 => '%d Kommentar', - 2 => '%d Kommentare', - ), - 'NEWS_ALL' => 'Alle News', - 'NEWS_REPLY' => 'Antworten', - 'NEWS_IN_FORUM' => 'in %s', - 'NEWS_READ_MORE' => 'Weiterlesen', - 'NEWS_VIEW_TOPIC' => 'Thema ansehen', - 'NEWS_FILTER_ARCHIVE' => 'Alle Monate', - 'NEWS_FILTER_BY_ARCHIVE' => 'Filter News-Einträge nach Jahr und Monat', - 'NEWS_FILTER_BY_CATEGORY' => 'Filter News-Einträge nach Forum', - 'NEWS_FILTER_CATEGORY' => 'Alle Foren', - 'NEWS_FILTER_REMOVE' => 'Filter entfernen', - 'NEWS_FILTER_CLEAR' => 'Filter zurücksetzen', - 'NEWS_FILTER_SHOWING' => 'Angezeigt', - 'NEWS_FORUMS' => 'News-Foren auswählen', - 'NEWS_GO_TO_TOPIC' => 'Link zum Thema', - 'NEWS_NUMBER' => 'News pro Seite', - 'NEWS_PAGES' => 'Anzahl der News-Seiten', - 'NEWS_POLL' => 'Umfrage', - 'NEWS_POLL_GOTO' => 'Klicke hier um abzustimmen!', - 'NEWS_POST_BUTTONS' => 'Beitrags-Buttons anzeigen', - 'NEWS_POST_BUTTONS_EXPLAIN' => 'Zitat, Ändern, etc.', - 'NEWS_READ_FULL' => 'News ganz lesen', - 'NEWS_READ_HERE' => 'Hier', - 'NEWS_SAVED' => 'Die Einstellung wurden erfolgreich gespeichert.', - 'NEWS_SHADOW_SHOW' => 'Verschobene Themen anzeigen', - 'NEWS_USER_INFO' => 'Benutzerinformation anzeigen', - 'NEWS_USER_INFO_EXPLAIN' => 'Avatar, Profilefelder, etc.', - - 'NO_NEWS' => 'Es gibt keine News-Einträge.', - 'NO_NEWS_ARCHIVE' => 'In diesem Archiv gibt es keine News-Einträge.', - 'NO_NEWS_CATEGORY' => 'In dieser Kategorien gibt es keine News-Einträge.', - - 'NEWSPAGE' => 'News', - - 'VIEW_NEWS_POSTS' => array( - 0 => 'Keine News', - 1 => '1 News', - 2 => '%d News', - ), - - 'VIEWONLINE_NEWS' => 'Liest News', - 'VIEWONLINE_NEWS_ARCHIVE' => 'Liest News von %s', - 'VIEWONLINE_NEWS_CATEGORY' => 'Liest News in %s', - 'VIEWONLINE_NEWS_CATEGORY_ARCHIVE' => 'Liest News in %s von %s', -)); diff --git a/language/en/newspage.php b/language/en/newspage.php index 8be9f58..dbc4bff 100644 --- a/language/en/newspage.php +++ b/language/en/newspage.php @@ -51,15 +51,12 @@ 'NEWS_FILTER_CLEAR' => 'Clear filters', 'NEWS_FILTER_SHOWING' => 'Showing', 'NEWS_FORUMS' => 'Select News-Forums', - 'NEWS_GO_TO_TOPIC' => 'Link to topic', 'NEWS_NUMBER' => 'News per page', 'NEWS_PAGES' => 'Number of pages', 'NEWS_POLL' => 'Poll', 'NEWS_POLL_GOTO' => 'Click here to vote!', 'NEWS_POST_BUTTONS' => 'Show post-related buttons', 'NEWS_POST_BUTTONS_EXPLAIN' => 'Quote, Edit, etc.', - 'NEWS_READ_FULL' => 'Read full news', - 'NEWS_READ_HERE' => 'Here', 'NEWS_SAVED' => 'The settings have been saved successfully.', 'NEWS_SHADOW_SHOW' => 'Show moved topics', 'NEWS_USER_INFO' => 'Show user information', diff --git a/license.txt b/license.txt index b860267..b8b347f 100644 --- a/license.txt +++ b/license.txt @@ -1,340 +1,281 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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/migrations/v14x/remove_version_config.php b/migrations/v14x/remove_version_config.php new file mode 100644 index 0000000..ae3714b --- /dev/null +++ b/migrations/v14x/remove_version_config.php @@ -0,0 +1,35 @@ +config['newspage_mod_version']); + } + + public static function depends_on() + { + return array('\\phpbbmodders\\newspage\\migrations\\v11x\\release_1_1_1'); + } + + public function update_data() + { + return array( + array('config.remove', array('newspage_mod_version')), + ); + } +} diff --git a/newspage.php b/newspage.php index 150f859..31b4490 100644 --- a/newspage.php +++ b/newspage.php @@ -27,8 +27,8 @@ class newspage protected $config; /** @var \phpbb\db\driver\driver_interface */ protected $db; - /** @var \phpbb\request\request_interface */ - protected $request; + /** @var \phpbb\profilefields\manager */ + protected $profile_fields; /** @var \phpbb\template\template */ protected $template; /** @var \phpbb\user */ @@ -62,9 +62,6 @@ class newspage /** @var int */ protected $category = 0; - const ARCHIVE_SHOW = 1; - const ARCHIVE_PER_YEAR = 2; - /** @var int[] */ protected $post_ids; /** @var int[] */ @@ -81,7 +78,7 @@ class newspage * @param \phpbb\cache\service $cache Cache object * @param \phpbb\config\config $config Config object * @param \phpbb\db\driver\driver_interface $db Database object - * @param \phpbb\request\request_interface $request Request object + * @param \phpbb\profilefields\manager $profile_fields Profile fields manager * @param \phpbb\template\template $template Template object * @param \phpbb\user $user User object * @param \phpbb\content_visibility $content_visibility Content visibility object @@ -91,13 +88,13 @@ class newspage * @param string $root_path phpBB root path * @param string $php_ext phpEx */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\request\request_interface $request, \phpbb\template\template $template, \phpbb\user $user, \phpbb\content_visibility $content_visibility, \phpbb\controller\helper $helper, \phpbbmodders\newspage\helper $news_helper, \phpbb\pagination $pagination, $root_path, $php_ext) + public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\profilefields\manager $profile_fields, \phpbb\template\template $template, \phpbb\user $user, \phpbb\content_visibility $content_visibility, \phpbb\controller\helper $helper, \phpbbmodders\newspage\helper $news_helper, \phpbb\pagination $pagination, $root_path, $php_ext) { $this->auth = $auth; $this->cache = $cache; $this->config = $config; $this->db = $db; - $this->request = $request; + $this->profile_fields = $profile_fields; $this->template = $template; $this->user = $user; $this->content_visibility = $content_visibility; @@ -329,9 +326,12 @@ public function base() return; } - // Grab ranks, icons, online-status and attachments + // The "last edited by" notice uses viewtopic's language strings + $this->user->add_lang('viewtopic'); + + // Grab icons, attachments and profile fields $icons = $this->cache->obtain_icons(); - $user_online_tracking_info = (!empty($this->poster_ids)) ? $this->get_online_posters($this->poster_ids) : array(); + $profile_fields = ($this->config['news_user_info']) ? $this->get_profile_fields($this->poster_ids) : array(); $attachments = (!empty($this->post_ids)) ? $this->get_attachments($this->post_ids) : array(); // Get topic tracking @@ -362,15 +362,18 @@ public function base() ); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); - while ($row = $this->db->sql_fetchrow($result)) + $editors = $this->get_editors($rows); + + foreach ($rows as $row) { // Set some variables $post_id = (int) $row['post_id']; $poster_id = (int) $row['poster_id']; $topic_id = (int) $row['topic_id']; $forum_id = (int) $row['forum_id']; - $post_edit_list = array(); $display_notice = false; $post_unread = (isset($topic_tracking_info[$forum_id][$topic_id]) && $row['post_time'] > $topic_tracking_info[$forum_id][$topic_id]) ? true : false; @@ -423,31 +426,16 @@ public function base() $row['post_text'] = $message; // Edit Information - if (($row['post_edit_count'] && $this->config['display_last_edited']) || $row['post_edit_reason']) + if ($this->shows_edit_notice($row)) { - // Get usernames for all following posts if not already stored - if (!sizeof($post_edit_list) && ($row['post_edit_reason'] || ($row['post_edit_user'] && !isset($user_cache[$row['post_edit_user']])))) - { - $sql2 = 'SELECT DISTINCT u.user_id, u.username, u.user_colour - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.post_edit_count <> 0 - AND p.post_edit_user <> 0 - AND p.post_edit_user = u.user_id'; - $result2 = $this->db->sql_query($sql2); - while ($user_edit_row = $this->db->sql_fetchrow($result2)) - { - $post_edit_list[$user_edit_row['user_id']] = $user_edit_row; - } - $this->db->sql_freeresult($result2); - } - - if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id) + $editor_id = (int) $row['post_edit_user']; + if (!$editor_id || $editor_id == $poster_id || !isset($editors[$editor_id])) { $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']); } else { - $display_username = get_username_string('full', $row['post_edit_user'], $post_edit_list[$row['post_edit_user']]['username'], $post_edit_list[$row['post_edit_user']]['user_colour']); + $display_username = get_username_string('full', $editor_id, $editors[$editor_id]['username'], $editors[$editor_id]['user_colour']); } $l_edited_by = $this->user->lang('EDITED_TIMES_TOTAL', (int) $row['post_edit_count'], $display_username, $this->user->format_date($row['post_edit_time'], false, true)); @@ -465,52 +453,19 @@ public function base() $row['rank_image'] = $rank_data['img']; $row['rank_image_src'] = $rank_data['img_src']; - // phpBB 4.0 has no Jabber field, so the column may be missing - $row['user_jabber'] = (!empty($row['user_jabber']) && $this->auth->acl_get('u_sendim')) ? append_sid("{$this->root_path}memberlist.{$this->php_ext}", "mode=contact&action=jabber&u=$poster_id") : ''; - - // Can this user receive a Private Message? - $can_receive_pm = ( - // They must be a "normal" user - $row['user_type'] != USER_IGNORE && - - // They must not be deactivated by the administrator - ($row['user_type'] != USER_INACTIVE || $row['user_inactive_reason'] != INACTIVE_MANUAL) && - - // They must be able to read PMs - //@todo in_array($poster_id, $can_receive_pm_list) && - - // They must not be permanently banned - //@todo !in_array($poster_id, $permanently_banned_users) && - - // They must allow users to contact via PM - (($this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) || $row['user_allow_pm']) - ); - - $u_pm = $u_email = ''; - - if ($this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $can_receive_pm) - { - $u_pm = append_sid("{$this->root_path}ucp.{$this->php_ext}", 'i=pm&mode=compose&action=quotepost&p=' . $row['post_id']); - } + $comments = $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1; - if ((!empty($row['user_allow_viewemail']) && $this->auth->acl_get('u_sendemail')) || $this->auth->acl_get('a_email')) - { - $u_email = ($this->config['board_email_form'] && $this->config['email_enable']) ? append_sid("{$this->root_path}memberlist.{$this->php_ext}", "mode=email&u=$poster_id") : (($this->config['board_hide_emails'] && !$this->auth->acl_get('a_email')) ? '' : 'mailto:' . $row['user_email']); - } + // Forum names are stored HTML-escaped + $forum_name = isset($row['forum_name']) ? $row['forum_name'] : ''; + $u_forum = append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $forum_id); $this->template->assign_block_vars('postrow', array( 'POST_ID' => $post_id, - 'S_IGNORE_POST' => false, - 'L_IGNORE_POST' => '', - 'ONLINE_IMG' => ($poster_id == ANONYMOUS || !$this->config['load_onlinetrack']) ? '' : ((in_array($poster_id, $user_online_tracking_info)) ? $this->user->img('icon_user_online', 'ONLINE') : $this->user->img('icon_user_offline', 'OFFLINE')), - 'S_ONLINE' => ($poster_id == ANONYMOUS || !$this->config['load_onlinetrack']) ? false : ((in_array($poster_id, $user_online_tracking_info)) ? true : false), - 'U_EDIT' => (!$this->user->data['is_registered']) ? '' : ((($this->user->data['user_id'] == $row['poster_id'] && $this->auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - ($this->config['edit_time'] * 60) || !$this->config['edit_time'])) || $this->auth->acl_get('m_edit', $forum_id)) ? append_sid("{$this->root_path}posting.{$this->php_ext}", "mode=edit&f=$forum_id&p={$row['post_id']}") : ''), 'U_QUOTE' => ($this->auth->acl_get('f_reply', $forum_id)) ? append_sid("{$this->root_path}posting.{$this->php_ext}", "mode=quote&f=$forum_id&p={$row['post_id']}") : '', 'U_INFO' => ($this->auth->acl_get('m_info', $forum_id)) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", "i=main&mode=post_details&f=$forum_id&p=" . $row['post_id'], true, $this->user->session_id) : '', 'U_DELETE' => (!$this->user->data['is_registered']) ? '' : ((($this->user->data['user_id'] == $row['poster_id'] && $this->auth->acl_get('f_delete', $forum_id) && $row['topic_last_post_id'] == $row['post_id'] && ($row['post_time'] > time() - ($this->config['edit_time'] * 60) || !$this->config['edit_time'])) || $this->auth->acl_get('m_delete', $forum_id)) ? append_sid("{$this->root_path}posting.{$this->php_ext}", "mode=delete&f=$forum_id&p={$row['post_id']}") : ''), 'U_REPORT' => ($this->auth->acl_get('f_report', $forum_id)) ? append_sid("{$this->root_path}report.{$this->php_ext}", 'f=' . $forum_id . '&p=' . $row['post_id']) : '', - 'U_NOTES' => ($this->auth->acl_getf_global('m_')) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=notes&mode=user_notes&u=' . $poster_id, true, $this->user->session_id) : '', 'U_WARN' => ($this->auth->acl_get('m_warn') && $poster_id != $this->user->data['user_id'] && $poster_id != ANONYMOUS) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=warn&mode=warn_post&f=' . $forum_id . '&p=' . $post_id, true, $this->user->session_id) : '', 'U_NEWS' => $this->helper->route('phpbbmodders_newspage_singlenews_controller', array('topic_id' => $topic_id)), @@ -519,16 +474,12 @@ public function base() 'POST_ICON_IMG_HEIGHT' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '', 'U_MINI_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'p=' . $row['post_id']) . (($row['topic_type'] == POST_GLOBAL) ? '&f=' . $forum_id : '') . '#p' . $row['post_id'], 'POST_SUBJECT' => htmlspecialchars(censor_text($row['post_subject']), ENT_QUOTES, 'UTF-8', false), - 'MINI_POST_IMG' => ($post_unread) ? $this->user->img('icon_post_target_unread', 'NEW_POST') : $this->user->img('icon_post_target', 'POST'), - 'MINI_POST' => ($post_unread) ? $this->user->lang['UNREAD_POST'] : $this->user->lang['POST'], 'S_UNREAD_POST' => $post_unread, 'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), 'POST_DATE' => $this->user->format_date($row['post_time']), - 'S_POST_UNAPPROVED' => $row['post_visibility'] == ITEM_UNAPPROVED, 'S_POST_REPORTED' => ($row['post_reported'] && $this->auth->acl_get('m_report', $forum_id)) ? true : false, 'U_MCP_REPORT' => ($this->auth->acl_get('m_report', $forum_id)) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=reports&mode=report_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $this->user->session_id) : '', - 'U_MCP_APPROVE' => ($this->auth->acl_get('m_approve', $forum_id)) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=queue&mode=approve_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $this->user->session_id) : '', 'MESSAGE' => $row['post_text'], @@ -539,14 +490,15 @@ public function base() 'EDITED_MESSAGE' => $l_edited_by, 'EDIT_REASON' => htmlspecialchars($row['post_edit_reason'], ENT_QUOTES, 'UTF-8', false), 'SIGNATURE' => ($row['enable_sig']) ? $row['user_sig'] : '', - 'NEWS_COMMENTS' => $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1, - 'NEWS_COMMENTS_TEXT' => $this->user->lang('NEWS_COMMENTS_COUNT', $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1), + 'NEWS_COMMENTS' => $comments, + 'NEWS_COMMENTS_TEXT' => $this->user->lang('NEWS_COMMENTS_COUNT', $comments), 'S_NEWS_SHORTENED' => $shortened, 'U_NEWS_REPLY' => ($this->auth->acl_get('f_reply', $forum_id) && ($row['topic_status'] != ITEM_LOCKED || $this->auth->acl_get('m_edit', $forum_id))) ? append_sid("{$this->root_path}posting.{$this->php_ext}", "mode=reply&t=$topic_id") : '', 'NEWS_LEAD_IMAGE_SRC' => utf8_htmlspecialchars($lead_image['src']), 'NEWS_LEAD_IMAGE_ALT' => utf8_htmlspecialchars($lead_image['alt']), - 'NEWS_FORUM_NAME' => isset($row['forum_name']) ? $row['forum_name'] : '', - 'U_NEWS_FORUM' => append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $forum_id), + 'NEWS_FORUM_NAME' => $forum_name, + 'U_NEWS_FORUM' => $u_forum, + 'NEWS_IN_FORUM' => ($forum_name !== '') ? $this->user->lang('NEWS_IN_FORUM', '' . $forum_name . '') : '', 'POSTER_AVATAR' => ($this->user->optionget('viewavatars')) ? $this->get_poster_avatar($row) : '', 'U_POST_AUTHOR' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), @@ -554,58 +506,15 @@ public function base() 'RANK_IMG' => $row['rank_image'], 'RANK_IMG_SRC' => $row['rank_image_src'], 'POSTER_POSTS' => $row['user_posts'], - 'POSTER_JOINED' => $this->user->format_date($row['user_regdate']), 'U_SEARCH' => $this->auth->acl_get('u_search') ? append_sid("{$this->root_path}search.{$this->php_ext}", 'author_id=' . $poster_id . '&sr=posts') : '', - - 'U_PM' => $u_pm, - 'U_EMAIL' => $u_email, - 'U_JABBER' => $row['user_jabber'], )); - $contact_fields = array( - array( - 'ID' => 'pm', - 'NAME' => $this->user->lang['PRIVATE_MESSAGES'], - 'U_CONTACT' => $u_pm, - ), - array( - 'ID' => 'email', - 'NAME' => $this->user->lang['SEND_EMAIL'], - 'U_CONTACT' => $u_email, - ), - ); - - if ($row['user_jabber']) - { - $contact_fields[] = array( - 'ID' => 'jabber', - 'NAME' => $this->user->lang['JABBER'], - 'U_CONTACT' => $row['user_jabber'], - ); - } - - foreach ($contact_fields as $field) - { - if ($field['U_CONTACT']) - { - $this->template->assign_block_vars('postrow.contact', $field); - } - } - - if (!empty($cp_row['blockrow'])) + if (!empty($profile_fields[$poster_id])) { + $cp_row = $this->profile_fields->generate_profile_fields_template_data($profile_fields[$poster_id], false); foreach ($cp_row['blockrow'] as $field_data) { $this->template->assign_block_vars('postrow.custom_fields', $field_data); - - if ($field_data['S_PROFILE_CONTACT']) - { - $this->template->assign_block_vars('postrow.contact', array( - 'ID' => $field_data['PROFILE_FIELD_IDENT'], - 'NAME' => $field_data['PROFILE_FIELD_NAME'], - 'U_CONTACT' => $field_data['PROFILE_FIELD_CONTACT'], - )); - } } } @@ -620,13 +529,11 @@ public function base() } } } - $this->db->sql_freeresult($result); // Specify some images $this->template->assign_vars(array( 'NEWS_USER_INFO' => (bool) $this->config['news_user_info'], 'NEWS_POST_BUTTONS' => (bool) $this->config['news_post_buttons'], - 'S_NEWS_ARCHIVE_PER_YEAR' => $this->config['news_archive_show'] == self::ARCHIVE_PER_YEAR, 'NEWS_ONLY' => $this->news, 'NEWS_TITLE' => $this->get_page_title(), @@ -636,26 +543,80 @@ public function base() } /** - * @param array $posters - * @return array + * Whether a post shows the "last edited by" notice, as viewtopic.php decides it. + * + * @param array $row Post row + * @return bool */ - public function get_online_posters(array $posters) + protected function shows_edit_notice(array $row) { - $users = array(); - $sql = 'SELECT session_user_id - FROM ' . SESSIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('session_user_id', $posters) . ' - AND session_user_id <> ' . ANONYMOUS . ' - AND session_viewonline = 1'; - $result = $this->db->sql_query($sql); + return ($row['post_edit_count'] && $this->config['display_last_edited']) || $row['post_edit_reason']; + } + + /** + * Names and colours of the users who last edited the shown posts, when that + * was not the poster, in one query. + * + * @param array $rows Post rows + * @return array User rows keyed by user ID + */ + protected function get_editors(array $rows) + { + $editor_ids = array(); + foreach ($rows as $row) + { + if ($this->shows_edit_notice($row) && $row['post_edit_user'] && $row['post_edit_user'] != $row['poster_id']) + { + $editor_ids[] = (int) $row['post_edit_user']; + } + } + + $editors = array(); + if (empty($editor_ids)) + { + return $editors; + } + $sql = 'SELECT user_id, username, user_colour + FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', array_unique($editor_ids)); + $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $users[] = $row['session_user_id']; + $editors[(int) $row['user_id']] = $row; } $this->db->sql_freeresult($result); - return $users; + return $editors; + } + + /** + * The posters' profile fields that are set to show on topic pages, as viewtopic.php + * picks them. + * + * @param int[] $poster_ids + * @return array Profile fields keyed by user ID, then by field name + */ + protected function get_profile_fields(array $poster_ids) + { + if (empty($poster_ids) || !$this->config['load_cpf_viewtopic']) + { + return array(); + } + + $profile_fields = array(); + foreach ($this->profile_fields->grab_profile_fields_data(array_unique($poster_ids)) as $user_id => $fields) + { + foreach ($fields as $ident => $field) + { + if ($field['data']['field_show_on_vt']) + { + $profile_fields[$user_id][$ident] = $field; + } + } + } + + return $profile_fields; } /** diff --git a/styles/prosilver/template/event/overall_header_head_append.html b/styles/prosilver/template/event/overall_header_head_append.html index c0fdd0f..cd3fadb 100644 --- a/styles/prosilver/template/event/overall_header_head_append.html +++ b/styles/prosilver/template/event/overall_header_head_append.html @@ -1 +1 @@ - +{% INCLUDECSS '@phpbbmodders_newspage/newspage.css' %} diff --git a/styles/prosilver/template/event/overall_header_navigation_prepend.html b/styles/prosilver/template/event/overall_header_navigation_prepend.html index 63f6126..9516f59 100644 --- a/styles/prosilver/template/event/overall_header_navigation_prepend.html +++ b/styles/prosilver/template/event/overall_header_navigation_prepend.html @@ -1 +1 @@ -
  • {L_NEWSPAGE}
  • +
  • {{ lang('NEWSPAGE') }}
  • diff --git a/styles/prosilver/template/newspage_archives_dropdown.html b/styles/prosilver/template/newspage_archives_dropdown.html index 7286130..72c89ef 100644 --- a/styles/prosilver/template/newspage_archives_dropdown.html +++ b/styles/prosilver/template/newspage_archives_dropdown.html @@ -1,32 +1,32 @@ - +{% if loops.archive_block|length %} - +{% endif %} diff --git a/styles/prosilver/template/newspage_body.html b/styles/prosilver/template/newspage_body.html index 356b84e..442e930 100644 --- a/styles/prosilver/template/newspage_body.html +++ b/styles/prosilver/template/newspage_body.html @@ -1,76 +1,76 @@ - +{% include 'overall_header.html' %} - +{% EVENT nickvergessen_newspage_before %} - - - - -

    {L_NEWS_ALL}

    - - class="newspage-single-title">{NEWS_TITLE}{L_NEWS} - +{% if NEWS_ONLY %} +{% EVENT phpbbmodders_newspage_single_before %} +{% endif %} +{% if NEWS_ONLY and U_NEWSPAGE %} +

    {{ lang('NEWS_ALL') }}

    +{% endif %} +{% if NEWS_ONLY %}{{ NEWS_TITLE }}{% else %}{{ lang('NEWS') }}{% endif %} +{% EVENT nickvergessen_newspage_title_after %} - +{% if not NEWS_ONLY and (loops.archive_block|length or loops.cat_block|length or loops.pagination|length or TOTAL_NEWS) %}
    - +{% EVENT nickvergessen_newspage_filters_before %}
    - - + {% include 'newspage_categories_dropdown.html' %} + {% include 'newspage_archives_dropdown.html' %} - + {% if (PAGE_NUMBER and PAGINATION) or TOTAL_NEWS %} - + {% endif %}
    - +{% if NEWS_FILTER_CATEGORY or NEWS_FILTER_ARCHIVE_YEAR %}

    - {L_NEWS_FILTER_SHOWING}{L_COLON} - - {NEWS_FILTER_CATEGORY} {L_NEWS_FILTER_REMOVE} - - - {NEWS_FILTER_ARCHIVE_MONTH} {NEWS_FILTER_ARCHIVE_YEAR} {L_NEWS_FILTER_REMOVE} - - - {L_NEWS_FILTER_CLEAR} - - + {{ lang('NEWS_FILTER_SHOWING') }}{{ lang('COLON') }} + {% if NEWS_FILTER_CATEGORY %} + {{ NEWS_FILTER_CATEGORY }} {{ lang('NEWS_FILTER_REMOVE') }} + {% endif %} + {% if NEWS_FILTER_ARCHIVE_YEAR %} + {{ NEWS_FILTER_ARCHIVE_MONTH }} {{ NEWS_FILTER_ARCHIVE_YEAR }} {{ lang('NEWS_FILTER_REMOVE') }} + {% endif %} + {% if NEWS_FILTER_CATEGORY and NEWS_FILTER_ARCHIVE_YEAR %} + {{ lang('NEWS_FILTER_CLEAR') }} + {% endif %} + {% EVENT phpbbmodders_newspage_active_filters_append %}

    - - - +{% endif %} +{% EVENT nickvergessen_newspage_filters_after %} +{% endif %} - - - +{% if loops.postrow|length %} + {% include 'viewtopic_postrow.html' %} +{% else %}
    - {L_NO_NEWS} + {{ L_NO_NEWS }}
    - +{% endif %} - +{% if loops.pagination|length %}

    - +{% endif %} - - - +{% if NEWS_ONLY %} +{% EVENT phpbbmodders_newspage_single_after %} +{% endif %} - +{% EVENT nickvergessen_newspage_after %} - +{% include 'overall_footer.html' %} diff --git a/styles/prosilver/template/newspage_categories_dropdown.html b/styles/prosilver/template/newspage_categories_dropdown.html index f5a1f32..1d06b16 100644 --- a/styles/prosilver/template/newspage_categories_dropdown.html +++ b/styles/prosilver/template/newspage_categories_dropdown.html @@ -1,32 +1,32 @@ - +{% if loops.cat_block|length %} - +{% endif %} diff --git a/styles/prosilver/template/viewtopic_postrow.html b/styles/prosilver/template/viewtopic_postrow.html index ed0e4e5..92bd815 100644 --- a/styles/prosilver/template/viewtopic_postrow.html +++ b/styles/prosilver/template/viewtopic_postrow.html @@ -1,181 +1,150 @@ - - -
    +{% for postrow in loops.postrow %} + {% EVENT viewtopic_body_postrow_post_before %} +
    - - - + {% EVENT viewtopic_body_post_buttons_list_before %} + {% if not S_IS_BOT and NEWS_POST_BUTTONS %} + {% if postrow.U_EDIT or postrow.U_DELETE or postrow.U_REPORT or postrow.U_WARN or postrow.U_INFO or postrow.U_QUOTE %} - - - + {% endif %} + {% endif %} + {% EVENT viewtopic_body_post_buttons_list_after %} - - -

    {postrow.POST_SUBJECT}

    - + {% if not NEWS_ONLY %} + {% EVENT viewtopic_body_post_subject_before %} +

    {% if postrow.POST_ICON_IMG %} {% endif %}{{ postrow.POST_SUBJECT }}

    + {% endif %} - + {% EVENT viewtopic_body_postrow_post_details_before %} - + {% if NEWS_USER_INFO %}

    - - {postrow.RANK_IMG} {postrow.RANK_TITLE} - - {L_POSTS}{L_COLON} {postrow.POSTER_POSTS} - {L_WARNINGS}{L_COLON} {postrow.POSTER_WARNINGS} - - - - {postrow.custom_fields.PROFILE_FIELD_NAME}{L_COLON} {postrow.custom_fields.PROFILE_FIELD_VALUE} - - - + {% EVENT viewtopic_body_postrow_rank_before %} + {% if postrow.RANK_TITLE or postrow.RANK_IMG %}{{ postrow.RANK_IMG }} {{ postrow.RANK_TITLE }}{% endif %} + {% EVENT viewtopic_body_postrow_rank_after %} + {% if postrow.POSTER_POSTS != '' %}{{ lang('POSTS') }}{{ lang('COLON') }} {% if postrow.U_SEARCH %}{% endif %}{{ postrow.POSTER_POSTS }}{% if postrow.U_SEARCH %}{% endif %}{% endif %} + {% EVENT viewtopic_body_postrow_custom_fields_before %} + {% for custom_fields in postrow.custom_fields %} + {{ custom_fields.PROFILE_FIELD_NAME }}{{ lang('COLON') }} {{ custom_fields.PROFILE_FIELD_VALUE }} + {% endfor %} + {% EVENT viewtopic_body_postrow_custom_fields_after %}

    - - + {% endif %} + {% EVENT viewtopic_body_postrow_post_details_after %}
    - -
    -

    - {L_POST_UNAPPROVED_ACTION} - - - - {S_FORM_TOKEN} -

    -
    - -
    -

    - {L_POST_DELETED_ACTION} - - - - {S_FORM_TOKEN} -

    -
    - - - + {% if postrow.S_POST_REPORTED %}

    - {L_POST_REPORTED} + {{ lang('POST_REPORTED') }}

    - + {% endif %} - - - {postrow.NEWS_LEAD_IMAGE_ALT} - - - -
    {postrow.MESSAGE}
    - + {% if postrow.NEWS_LEAD_IMAGE_SRC %} + {% EVENT phpbbmodders_newspage_lead_image_before %} + {{ postrow.NEWS_LEAD_IMAGE_ALT }} + {% EVENT phpbbmodders_newspage_lead_image_after %} + {% endif %} + {% EVENT viewtopic_body_postrow_content_before %} +
    {{ postrow.MESSAGE }}
    + {% EVENT viewtopic_body_postrow_content_after %} - + {% if postrow.S_HAS_ATTACHMENTS %}
    - {L_ATTACHMENTS} + {{ lang('ATTACHMENTS') }}
    - -
    {postrow.attachment.DISPLAY_ATTACHMENT}
    - + {% for attachment in postrow.attachment %} +
    {{ attachment.DISPLAY_ATTACHMENT }}
    + {% endfor %}
    - + {% endif %} - - -

    {L_NEWS_POLL}{L_COLON} {postrow.POLL_QUESTION} » {L_NEWS_POLL_GOTO}

    - -
    {L_DOWNLOAD_NOTICE}
    - -
    - {postrow.DELETED_MESSAGE} -
    {L_REASON}{L_COLON} {postrow.DELETE_REASON} -
    - + {% EVENT viewtopic_body_postrow_post_notices_before %} + {% if postrow.S_HAS_POLL %} +

    {{ lang('NEWS_POLL') }}{{ lang('COLON') }} {{ postrow.POLL_QUESTION }} » {{ lang('NEWS_POLL_GOTO') }}

    + {% endif %} + {% if postrow.S_DISPLAY_NOTICE %}
    {{ lang('DOWNLOAD_NOTICE') }}
    {% endif %} + {% if postrow.EDITED_MESSAGE or postrow.EDIT_REASON %}
    - {postrow.EDITED_MESSAGE} -
    {L_REASON}{L_COLON} {postrow.EDIT_REASON} + {{ postrow.EDITED_MESSAGE }} + {% if postrow.EDIT_REASON %}
    {{ lang('REASON') }}{{ lang('COLON') }} {{ postrow.EDIT_REASON }}{% endif %}
    - -
    {postrow.BUMPED_MESSAGE}
    - - -
    {postrow.SIGNATURE}
    - + {% endif %} + {% EVENT viewtopic_body_postrow_post_notices_after %} + {% EVENT viewtopic_body_postrow_signature_before %} + {% if NEWS_USER_INFO and postrow.SIGNATURE %}
    {{ postrow.SIGNATURE }}
    {% endif %} + {% EVENT viewtopic_body_postrow_signature_after %} - + {% EVENT viewtopic_body_postrow_post_content_footer %}
    - - + {% EVENT viewtopic_body_postrow_post_after %} +{% endfor %} diff --git a/tests/event/viewonline_test.php b/tests/event/viewonline_test.php index 2a085b1..413de3b 100644 --- a/tests/event/viewonline_test.php +++ b/tests/event/viewonline_test.php @@ -59,6 +59,16 @@ public function setup_listener() return $route . '#' . serialize($params); }); + // Forum 40 is one the viewer may not see + $auth = $this->getMockBuilder('\phpbb\auth\auth') + ->disableOriginalConstructor() + ->getMock(); + $auth->expects($this->any()) + ->method('acl_get') + ->willReturnCallback(function ($option, $forum_id = 0) { + return $option === 'f_list' && $forum_id != 40; + }); + /** @var \phpbb\controller\helper $controller_helper */ $this->listener = new viewonline_listener( new helper( @@ -69,6 +79,7 @@ public function setup_listener() )) ), $this->user, + $auth, 'php' ); } @@ -202,6 +213,54 @@ public function add_newspage_viewonline_data() 'phpbbmodders_newspage_category_archive_controller#' . serialize(array('forum_id' => 30, 'year' => 2014, 'month' => '04')), 'VIEWONLINE_NEWS_CATEGORY_ARCHIVE Forum30 April 2014', ), + // A forum the viewer may not see, or one that no longer exists, is not named + array( + array( + 1 => 'app', + ), + array( + 'session_page' => 'app.' . $phpEx . '/news/category/40' + ), + array( + 40 => array( + 'forum_name' => 'Forum40', + ), + ), + '$location_url', + '$location', + 'phpbbmodders_newspage_controller#a:0:{}', + 'VIEWONLINE_NEWS', + ), + array( + array( + 1 => 'app', + ), + array( + 'session_page' => 'app.' . $phpEx . '/news/category/40/archive/2014/04' + ), + array( + 40 => array( + 'forum_name' => 'Forum40', + ), + ), + '$location_url', + '$location', + 'phpbbmodders_newspage_archive_controller#' . serialize(array('year' => 2014, 'month' => '04')), + 'VIEWONLINE_NEWS_ARCHIVE April 2014', + ), + array( + array( + 1 => 'app', + ), + array( + 'session_page' => 'app.' . $phpEx . '/news/category/50' + ), + array(), + '$location_url', + '$location', + 'phpbbmodders_newspage_controller#a:0:{}', + 'VIEWONLINE_NEWS', + ), // Other pages are left alone array( array(