18c2e8227SGreg Roach<?php 28c2e8227SGreg Roachnamespace Fisharebest\Webtrees; 38c2e8227SGreg Roach 48c2e8227SGreg Roach/** 58c2e8227SGreg Roach * webtrees: online genealogy 68c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team 78c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 88c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 98c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 108c2e8227SGreg Roach * (at your option) any later version. 118c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 128c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 138c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148c2e8227SGreg Roach * GNU General Public License for more details. 158c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 168c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 178c2e8227SGreg Roach */ 188c2e8227SGreg Roach 198c2e8227SGreg Roach/** 208c2e8227SGreg Roach * Class TopPageViewsModule 218c2e8227SGreg Roach */ 22e2a378d3SGreg Roachclass TopPageViewsModule extends AbstractModule implements ModuleBlockInterface { 238c2e8227SGreg Roach /** {@inheritdoc} */ 248c2e8227SGreg Roach public function getTitle() { 258c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Most viewed pages'); 268c2e8227SGreg Roach } 278c2e8227SGreg Roach 288c2e8227SGreg Roach /** {@inheritdoc} */ 298c2e8227SGreg Roach public function getDescription() { 308c2e8227SGreg Roach return /* I18N: Description of the “Most visited pages” module */ I18N::translate('A list of the pages that have been viewed the most number of times.'); 318c2e8227SGreg Roach } 328c2e8227SGreg Roach 338c2e8227SGreg Roach /** {@inheritdoc} */ 348c2e8227SGreg Roach public function getBlock($block_id, $template = true, $cfg = null) { 354b9ff166SGreg Roach global $ctype, $WT_TREE; 368c2e8227SGreg Roach 37e2a378d3SGreg Roach $num = $this->getBlockSetting($block_id, 'num', '10'); 38e2a378d3SGreg Roach $count_placement = $this->getBlockSetting($block_id, 'count_placement', 'before'); 39e2a378d3SGreg Roach $block = $this->getBlockSetting($block_id, 'block', '0'); 408c2e8227SGreg Roach 418c2e8227SGreg Roach if ($cfg) { 428c2e8227SGreg Roach foreach (array('count_placement', 'num', 'block') as $name) { 438c2e8227SGreg Roach if (array_key_exists($name, $cfg)) { 448c2e8227SGreg Roach $$name = $cfg[$name]; 458c2e8227SGreg Roach } 468c2e8227SGreg Roach } 478c2e8227SGreg Roach } 488c2e8227SGreg Roach 498c2e8227SGreg Roach $id = $this->getName() . $block_id; 508c2e8227SGreg Roach $class = $this->getName() . '_block'; 514b9ff166SGreg Roach if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 529353052eSGreg Roach $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype . '"></a>'; 538c2e8227SGreg Roach } else { 548c2e8227SGreg Roach $title = ''; 558c2e8227SGreg Roach } 568c2e8227SGreg Roach $title .= $this->getTitle(); 578c2e8227SGreg Roach 588c2e8227SGreg Roach $content = ""; 598c2e8227SGreg Roach // load the lines from the file 608c2e8227SGreg Roach $top10 = Database::prepare( 618c2e8227SGreg Roach "SELECT page_parameter, page_count" . 628c2e8227SGreg Roach " FROM `##hit_counter`" . 638c2e8227SGreg Roach " WHERE gedcom_id = :tree_id AND page_name IN ('individual.php','family.php','source.php','repo.php','note.php','mediaviewer.php')" . 648c2e8227SGreg Roach " ORDER BY page_count DESC LIMIT :limit" 658c2e8227SGreg Roach )->execute(array( 6624ec66ceSGreg Roach 'tree_id' => $WT_TREE->getTreeId(), 678c2e8227SGreg Roach 'limit' => (int) $num, 688c2e8227SGreg Roach ))->FetchAssoc(); 698c2e8227SGreg Roach 708c2e8227SGreg Roach if ($block) { 718c2e8227SGreg Roach $content .= "<table width=\"90%\">"; 728c2e8227SGreg Roach } else { 738c2e8227SGreg Roach $content .= "<table>"; 748c2e8227SGreg Roach } 758c2e8227SGreg Roach foreach ($top10 as $id => $count) { 7624ec66ceSGreg Roach $record = GedcomRecord::getInstance($id, $WT_TREE); 778c2e8227SGreg Roach if ($record && $record->canShow()) { 788c2e8227SGreg Roach $content .= '<tr valign="top">'; 798c2e8227SGreg Roach if ($count_placement == 'before') { 808c2e8227SGreg Roach $content .= '<td dir="ltr" align="right">[' . $count . ']</td>'; 818c2e8227SGreg Roach } 828c2e8227SGreg Roach $content .= '<td class="name2" ><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>'; 838c2e8227SGreg Roach if ($count_placement == 'after') { 848c2e8227SGreg Roach $content .= '<td dir="ltr" align="right">[' . $count . ']</td>'; 858c2e8227SGreg Roach } 868c2e8227SGreg Roach $content .= '</tr>'; 878c2e8227SGreg Roach } 888c2e8227SGreg Roach } 898c2e8227SGreg Roach $content .= "</table>"; 908c2e8227SGreg Roach 918c2e8227SGreg Roach if ($template) { 928c2e8227SGreg Roach if ($block) { 938c2e8227SGreg Roach $class .= ' small_inner_block'; 948c2e8227SGreg Roach } 95*cbc1590aSGreg Roach 968c2e8227SGreg Roach return Theme::theme()->formatBlock($id, $title, $class, $content); 978c2e8227SGreg Roach } else { 988c2e8227SGreg Roach return $content; 998c2e8227SGreg Roach } 1008c2e8227SGreg Roach } 1018c2e8227SGreg Roach 1028c2e8227SGreg Roach /** {@inheritdoc} */ 1038c2e8227SGreg Roach public function loadAjax() { 1048c2e8227SGreg Roach return true; 1058c2e8227SGreg Roach } 1068c2e8227SGreg Roach 1078c2e8227SGreg Roach /** {@inheritdoc} */ 1088c2e8227SGreg Roach public function isUserBlock() { 1098c2e8227SGreg Roach return false; 1108c2e8227SGreg Roach } 1118c2e8227SGreg Roach 1128c2e8227SGreg Roach /** {@inheritdoc} */ 1138c2e8227SGreg Roach public function isGedcomBlock() { 1148c2e8227SGreg Roach return true; 1158c2e8227SGreg Roach } 1168c2e8227SGreg Roach 1178c2e8227SGreg Roach /** {@inheritdoc} */ 1188c2e8227SGreg Roach public function configureBlock($block_id) { 1198c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 120e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'num', Filter::postInteger('num', 1, 10000, 10)); 121e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'count_placement', Filter::post('count_placement', 'before|after', 'before')); 122e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'block', Filter::postBool('block')); 1238c2e8227SGreg Roach } 1248c2e8227SGreg Roach 125e2a378d3SGreg Roach $num = $this->getBlockSetting($block_id, 'num', '10'); 126e2a378d3SGreg Roach $count_placement = $this->getBlockSetting($block_id, 'count_placement', 'before'); 127e2a378d3SGreg Roach $block = $this->getBlockSetting($block_id, 'block', '0'); 1288c2e8227SGreg Roach 1298c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 1308c2e8227SGreg Roach echo I18N::translate('Number of items to show'); 1318c2e8227SGreg Roach echo '</td><td class="optionbox">'; 1328c2e8227SGreg Roach echo '<input type="text" name="num" size="2" value="', $num, '">'; 1338c2e8227SGreg Roach echo '</td></tr>'; 1348c2e8227SGreg Roach 1358c2e8227SGreg Roach echo "<tr><td class=\"descriptionbox wrap width33\">"; 1368c2e8227SGreg Roach echo I18N::translate('Place counts before or after name?'); 1378c2e8227SGreg Roach echo "</td><td class=\"optionbox\">"; 1388c2e8227SGreg Roach echo select_edit_control('count_placement', array('before' => I18N::translate('before'), 'after' => I18N::translate('after')), null, $count_placement, ''); 1398c2e8227SGreg Roach echo '</td></tr>'; 1408c2e8227SGreg Roach 1418c2e8227SGreg Roach echo '<tr><td class="descriptionbox wrap width33">'; 1428c2e8227SGreg Roach echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); 1438c2e8227SGreg Roach echo '</td><td class="optionbox">'; 1448c2e8227SGreg Roach echo edit_field_yes_no('block', $block); 1458c2e8227SGreg Roach echo '</td></tr>'; 1468c2e8227SGreg Roach } 1478c2e8227SGreg Roach} 148