diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-05-11 00:05:22 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-05-13 08:48:23 +0200 |
commit | 141a86c503af8e314381b3ee39ba4287fdfac63e (patch) | |
tree | 86cb3f8d8998bb924216cdee1101fb8ea5bd96e4 | |
parent | 03eb19ac60d54442332077fa35a9b0d4e33df365 (diff) | |
download | Shaarli-141a86c503af8e314381b3ee39ba4287fdfac63e.tar.gz Shaarli-141a86c503af8e314381b3ee39ba4287fdfac63e.tar.zst Shaarli-141a86c503af8e314381b3ee39ba4287fdfac63e.zip |
Add private link counter
-rw-r--r-- | application/LinkUtils.php | 16 | ||||
-rw-r--r-- | index.php | 17 | ||||
-rw-r--r-- | tests/LinkUtilsTest.php | 9 | ||||
-rw-r--r-- | tpl/page.header.html | 3 |
4 files changed, 30 insertions, 15 deletions
diff --git a/application/LinkUtils.php b/application/LinkUtils.php index 2df76ba8..da04ca97 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php | |||
@@ -77,3 +77,19 @@ function html_extract_charset($html) | |||
77 | 77 | ||
78 | return false; | 78 | return false; |
79 | } | 79 | } |
80 | |||
81 | /** | ||
82 | * Count private links in given linklist. | ||
83 | * | ||
84 | * @param array $links Linklist. | ||
85 | * | ||
86 | * @return int Number of private links. | ||
87 | */ | ||
88 | function count_private($links) | ||
89 | { | ||
90 | $cpt = 0; | ||
91 | foreach ($links as $link) { | ||
92 | $cpt = $link['private'] == true ? $cpt + 1 : $cpt; | ||
93 | } | ||
94 | return $cpt; | ||
95 | } | ||
@@ -736,7 +736,6 @@ function showDaily($pageBuilder, $LINKSDB) | |||
736 | $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); | 736 | $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); |
737 | $data = array( | 737 | $data = array( |
738 | 'linksToDisplay' => $linksToDisplay, | 738 | 'linksToDisplay' => $linksToDisplay, |
739 | 'linkcount' => count($LINKSDB), | ||
740 | 'cols' => $columns, | 739 | 'cols' => $columns, |
741 | 'day' => $dayDate->getTimestamp(), | 740 | 'day' => $dayDate->getTimestamp(), |
742 | 'previousday' => $previousday, | 741 | 'previousday' => $previousday, |
@@ -792,6 +791,8 @@ function renderPage() | |||
792 | } | 791 | } |
793 | 792 | ||
794 | $PAGE = new PageBuilder(); | 793 | $PAGE = new PageBuilder(); |
794 | $PAGE->assign('linkcount', count($LINKSDB)); | ||
795 | $PAGE->assign('privateLinkcount', count_private($LINKSDB)); | ||
795 | 796 | ||
796 | // Determine which page will be rendered. | 797 | // Determine which page will be rendered. |
797 | $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : ''; | 798 | $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : ''; |
@@ -855,7 +856,6 @@ function renderPage() | |||
855 | } | 856 | } |
856 | 857 | ||
857 | $data = array( | 858 | $data = array( |
858 | 'linkcount' => count($LINKSDB), | ||
859 | 'linksToDisplay' => $linksToDisplay, | 859 | 'linksToDisplay' => $linksToDisplay, |
860 | ); | 860 | ); |
861 | $pluginManager->executeHooks('render_picwall', $data, array('loggedin' => isLoggedIn())); | 861 | $pluginManager->executeHooks('render_picwall', $data, array('loggedin' => isLoggedIn())); |
@@ -905,7 +905,6 @@ function renderPage() | |||
905 | } | 905 | } |
906 | 906 | ||
907 | $data = array( | 907 | $data = array( |
908 | 'linkcount' => count($LINKSDB), | ||
909 | 'tags' => $tagList, | 908 | 'tags' => $tagList, |
910 | ); | 909 | ); |
911 | $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); | 910 | $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); |
@@ -1099,7 +1098,6 @@ function renderPage() | |||
1099 | if ($targetPage == Router::$PAGE_TOOLS) | 1098 | if ($targetPage == Router::$PAGE_TOOLS) |
1100 | { | 1099 | { |
1101 | $data = array( | 1100 | $data = array( |
1102 | 'linkcount' => count($LINKSDB), | ||
1103 | 'pageabsaddr' => index_url($_SERVER), | 1101 | 'pageabsaddr' => index_url($_SERVER), |
1104 | ); | 1102 | ); |
1105 | $pluginManager->executeHooks('render_tools', $data); | 1103 | $pluginManager->executeHooks('render_tools', $data); |
@@ -1144,7 +1142,6 @@ function renderPage() | |||
1144 | } | 1142 | } |
1145 | else // show the change password form. | 1143 | else // show the change password form. |
1146 | { | 1144 | { |
1147 | $PAGE->assign('linkcount',count($LINKSDB)); | ||
1148 | $PAGE->assign('token',getToken()); | 1145 | $PAGE->assign('token',getToken()); |
1149 | $PAGE->renderPage('changepassword'); | 1146 | $PAGE->renderPage('changepassword'); |
1150 | exit; | 1147 | exit; |
@@ -1192,7 +1189,6 @@ function renderPage() | |||
1192 | } | 1189 | } |
1193 | else // Show the configuration form. | 1190 | else // Show the configuration form. |
1194 | { | 1191 | { |
1195 | $PAGE->assign('linkcount',count($LINKSDB)); | ||
1196 | $PAGE->assign('token',getToken()); | 1192 | $PAGE->assign('token',getToken()); |
1197 | $PAGE->assign('title', empty($GLOBALS['title']) ? '' : $GLOBALS['title'] ); | 1193 | $PAGE->assign('title', empty($GLOBALS['title']) ? '' : $GLOBALS['title'] ); |
1198 | $PAGE->assign('redirector', empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'] ); | 1194 | $PAGE->assign('redirector', empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'] ); |
@@ -1208,7 +1204,6 @@ function renderPage() | |||
1208 | if ($targetPage == Router::$PAGE_CHANGETAG) | 1204 | if ($targetPage == Router::$PAGE_CHANGETAG) |
1209 | { | 1205 | { |
1210 | if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { | 1206 | if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { |
1211 | $PAGE->assign('linkcount', count($LINKSDB)); | ||
1212 | $PAGE->assign('token', getToken()); | 1207 | $PAGE->assign('token', getToken()); |
1213 | $PAGE->assign('tags', $LINKSDB->allTags()); | 1208 | $PAGE->assign('tags', $LINKSDB->allTags()); |
1214 | $PAGE->renderPage('changetag'); | 1209 | $PAGE->renderPage('changetag'); |
@@ -1257,7 +1252,6 @@ function renderPage() | |||
1257 | // -------- User wants to add a link without using the bookmarklet: Show form. | 1252 | // -------- User wants to add a link without using the bookmarklet: Show form. |
1258 | if ($targetPage == Router::$PAGE_ADDLINK) | 1253 | if ($targetPage == Router::$PAGE_ADDLINK) |
1259 | { | 1254 | { |
1260 | $PAGE->assign('linkcount',count($LINKSDB)); | ||
1261 | $PAGE->renderPage('addlink'); | 1255 | $PAGE->renderPage('addlink'); |
1262 | exit; | 1256 | exit; |
1263 | } | 1257 | } |
@@ -1383,7 +1377,6 @@ function renderPage() | |||
1383 | $link = $LINKSDB[$_GET['edit_link']]; // Read database | 1377 | $link = $LINKSDB[$_GET['edit_link']]; // Read database |
1384 | if (!$link) { header('Location: ?'); exit; } // Link not found in database. | 1378 | if (!$link) { header('Location: ?'); exit; } // Link not found in database. |
1385 | $data = array( | 1379 | $data = array( |
1386 | 'linkcount' => count($LINKSDB), | ||
1387 | 'link' => $link, | 1380 | 'link' => $link, |
1388 | 'link_is_new' => false, | 1381 | 'link_is_new' => false, |
1389 | 'token' => getToken(), | 1382 | 'token' => getToken(), |
@@ -1451,7 +1444,6 @@ function renderPage() | |||
1451 | } | 1444 | } |
1452 | 1445 | ||
1453 | $data = array( | 1446 | $data = array( |
1454 | 'linkcount' => count($LINKSDB), | ||
1455 | 'link' => $link, | 1447 | 'link' => $link, |
1456 | 'link_is_new' => $link_is_new, | 1448 | 'link_is_new' => $link_is_new, |
1457 | 'token' => getToken(), // XSRF protection. | 1449 | 'token' => getToken(), // XSRF protection. |
@@ -1473,7 +1465,6 @@ function renderPage() | |||
1473 | // Export links as a Netscape Bookmarks file | 1465 | // Export links as a Netscape Bookmarks file |
1474 | 1466 | ||
1475 | if (empty($_GET['selection'])) { | 1467 | if (empty($_GET['selection'])) { |
1476 | $PAGE->assign('linkcount',count($LINKSDB)); | ||
1477 | $PAGE->renderPage('export'); | 1468 | $PAGE->renderPage('export'); |
1478 | exit; | 1469 | exit; |
1479 | } | 1470 | } |
@@ -1532,7 +1523,6 @@ function renderPage() | |||
1532 | // -------- Show upload/import dialog: | 1523 | // -------- Show upload/import dialog: |
1533 | if ($targetPage == Router::$PAGE_IMPORT) | 1524 | if ($targetPage == Router::$PAGE_IMPORT) |
1534 | { | 1525 | { |
1535 | $PAGE->assign('linkcount',count($LINKSDB)); | ||
1536 | $PAGE->assign('token',getToken()); | 1526 | $PAGE->assign('token',getToken()); |
1537 | $PAGE->assign('maxfilesize',getMaxFileSize()); | 1527 | $PAGE->assign('maxfilesize',getMaxFileSize()); |
1538 | $PAGE->renderPage('import'); | 1528 | $PAGE->renderPage('import'); |
@@ -1764,7 +1754,6 @@ function buildLinkList($PAGE,$LINKSDB) | |||
1764 | 1754 | ||
1765 | // Fill all template fields. | 1755 | // Fill all template fields. |
1766 | $data = array( | 1756 | $data = array( |
1767 | 'linkcount' => count($LINKSDB), | ||
1768 | 'previous_page_url' => $previous_page_url, | 1757 | 'previous_page_url' => $previous_page_url, |
1769 | 'next_page_url' => $next_page_url, | 1758 | 'next_page_url' => $next_page_url, |
1770 | 'page_current' => $page, | 1759 | 'page_current' => $page, |
@@ -2039,7 +2028,7 @@ function install() | |||
2039 | $timezone_html = '<tr><td><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; | 2028 | $timezone_html = '<tr><td><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; |
2040 | } | 2029 | } |
2041 | 2030 | ||
2042 | $PAGE = new pageBuilder; | 2031 | $PAGE = new PageBuilder(); |
2043 | $PAGE->assign('timezone_html',$timezone_html); | 2032 | $PAGE->assign('timezone_html',$timezone_html); |
2044 | $PAGE->assign('timezone_js',$timezone_js); | 2033 | $PAGE->assign('timezone_js',$timezone_js); |
2045 | $PAGE->renderPage('install'); | 2034 | $PAGE->renderPage('install'); |
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php index 609a80cb..d1b022fd 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/LinkUtilsTest.php | |||
@@ -84,4 +84,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
84 | $html = '<html><meta>stuff</meta><meta charset=""/></html>'; | 84 | $html = '<html><meta>stuff</meta><meta charset=""/></html>'; |
85 | $this->assertFalse(html_extract_charset($html)); | 85 | $this->assertFalse(html_extract_charset($html)); |
86 | } | 86 | } |
87 | |||
88 | /** | ||
89 | * Test count_private. | ||
90 | */ | ||
91 | public function testCountPrivateLinks() | ||
92 | { | ||
93 | $refDB = new ReferenceLinkDB(); | ||
94 | $this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks())); | ||
95 | } | ||
87 | } | 96 | } |
diff --git a/tpl/page.header.html b/tpl/page.header.html index 52429f23..3a09ecd9 100644 --- a/tpl/page.header.html +++ b/tpl/page.header.html | |||
@@ -2,7 +2,8 @@ | |||
2 | <div id="logo" title="Share your links !" onclick="document.location='?';"></div> | 2 | <div id="logo" title="Share your links !" onclick="document.location='?';"></div> |
3 | 3 | ||
4 | <div id="linkcount" class="nomobile"> | 4 | <div id="linkcount" class="nomobile"> |
5 | {if="!empty($linkcount)"}{$linkcount} links{/if} | 5 | {if="!empty($linkcount)"}{$linkcount} links{/if}<br> |
6 | {if="!empty($privateLinkcount)"}{$privateLinkcount} private links{/if} | ||
6 | </div> | 7 | </div> |
7 | 8 | ||
8 | <div id="menu"> | 9 | <div id="menu"> |