diff options
Diffstat (limited to 'index.php')
-rwxr-xr-x | index.php | 278 |
1 files changed, 193 insertions, 85 deletions
@@ -45,9 +45,17 @@ $GLOBALS['config']['RAINTPL_TPL'] = 'tpl/' ; // Raintpl template directory (keep | |||
45 | $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; // For updates check of Shaarli. | 45 | $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; // For updates check of Shaarli. |
46 | $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400 ; // Updates check frequency for Shaarli. 86400 seconds=24 hours | 46 | $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400 ; // Updates check frequency for Shaarli. 86400 seconds=24 hours |
47 | // Note: You must have publisher.php in the same directory as Shaarli index.php | 47 | // Note: You must have publisher.php in the same directory as Shaarli index.php |
48 | $GLOBALS['config']['ARCHIVE_ORG'] = false; // For each link, add a link to an archived version on archive.org | ||
49 | $GLOBALS['config']['ENABLE_RSS_PERMALINKS'] = true; // Enable RSS permalinks by default. This corresponds to the default behavior of shaarli before this was added as an option. | 48 | $GLOBALS['config']['ENABLE_RSS_PERMALINKS'] = true; // Enable RSS permalinks by default. This corresponds to the default behavior of shaarli before this was added as an option. |
50 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] = false; | 49 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] = false; |
50 | //$GLOBALS['config']['ENABLED_PLUGINS'] = array( | ||
51 | // 'qrcode', 'archiveorg', 'readityourself', 'demo_plugin', 'playvideos', | ||
52 | // 'wallabag', 'markdown', 'addlink_toolbar', | ||
53 | //); | ||
54 | // Warning: order matters. | ||
55 | $GLOBALS['config']['ENABLED_PLUGINS'] = array('qrcode'); | ||
56 | |||
57 | // Default plugins, default config - will be overriden by config.php and then plugin's config.php file. | ||
58 | //$GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org/'; | ||
51 | // ----------------------------------------------------------------------------------------------- | 59 | // ----------------------------------------------------------------------------------------------- |
52 | define('shaarli_version', '0.5.4'); | 60 | define('shaarli_version', '0.5.4'); |
53 | // http://server.com/x/shaarli --> /shaarli/ | 61 | // http://server.com/x/shaarli --> /shaarli/ |
@@ -75,6 +83,8 @@ require_once 'application/TimeZone.php'; | |||
75 | require_once 'application/Url.php'; | 83 | require_once 'application/Url.php'; |
76 | require_once 'application/Utils.php'; | 84 | require_once 'application/Utils.php'; |
77 | require_once 'application/Config.php'; | 85 | require_once 'application/Config.php'; |
86 | require_once 'application/PluginManager.php'; | ||
87 | require_once 'application/Router.php'; | ||
78 | 88 | ||
79 | // Ensure the PHP version is supported | 89 | // Ensure the PHP version is supported |
80 | try { | 90 | try { |
@@ -119,6 +129,9 @@ include "inc/rain.tpl.class.php"; //include Rain TPL | |||
119 | raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory | 129 | raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory |
120 | raintpl::$cache_dir = $GLOBALS['config']['RAINTPL_TMP']; // cache directory | 130 | raintpl::$cache_dir = $GLOBALS['config']['RAINTPL_TMP']; // cache directory |
121 | 131 | ||
132 | $pluginManager = PluginManager::getInstance(); | ||
133 | $pluginManager->load($GLOBALS['config']['ENABLED_PLUGINS']); | ||
134 | |||
122 | ob_start(); // Output buffering for the page cache. | 135 | ob_start(); // Output buffering for the page cache. |
123 | 136 | ||
124 | 137 | ||
@@ -566,28 +579,43 @@ class pageBuilder | |||
566 | 579 | ||
567 | function __construct() | 580 | function __construct() |
568 | { | 581 | { |
569 | $this->tpl=false; | 582 | $this->tpl = false; |
570 | } | 583 | } |
571 | 584 | ||
585 | /** | ||
586 | * Initialize all default tpl tags. | ||
587 | */ | ||
572 | private function initialize() | 588 | private function initialize() |
573 | { | 589 | { |
574 | $this->tpl = new RainTPL; | 590 | $this->tpl = new RainTPL; |
575 | $this->tpl->assign('newversion',escape(checkUpdate())); | 591 | $this->tpl->assign('newversion', escape(checkUpdate())); |
576 | $this->tpl->assign('feedurl',escape(index_url($_SERVER))); | 592 | $this->tpl->assign('feedurl', escape(index_url($_SERVER))); |
577 | $searchcrits=''; // Search criteria | 593 | $searchcrits = ''; // Search criteria |
578 | if (!empty($_GET['searchtags'])) $searchcrits.='&searchtags='.urlencode($_GET['searchtags']); | 594 | if (!empty($_GET['searchtags'])) { |
579 | elseif (!empty($_GET['searchterm'])) $searchcrits.='&searchterm='.urlencode($_GET['searchterm']); | 595 | $searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']); |
580 | $this->tpl->assign('searchcrits',$searchcrits); | 596 | } |
581 | $this->tpl->assign('source',index_url($_SERVER)); | 597 | elseif (!empty($_GET['searchterm'])) { |
582 | $this->tpl->assign('version',shaarli_version); | 598 | $searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']); |
583 | $this->tpl->assign('scripturl',index_url($_SERVER)); | 599 | } |
584 | $this->tpl->assign('pagetitle','Shaarli'); | 600 | $this->tpl->assign('searchcrits', $searchcrits); |
585 | $this->tpl->assign('privateonly',!empty($_SESSION['privateonly'])); // Show only private links? | 601 | $this->tpl->assign('source', index_url($_SERVER)); |
586 | if (!empty($GLOBALS['title'])) $this->tpl->assign('pagetitle',$GLOBALS['title']); | 602 | $this->tpl->assign('version', shaarli_version); |
587 | if (!empty($GLOBALS['titleLink'])) $this->tpl->assign('titleLink',$GLOBALS['titleLink']); | 603 | $this->tpl->assign('scripturl', index_url($_SERVER)); |
588 | if (!empty($GLOBALS['pagetitle'])) $this->tpl->assign('pagetitle',$GLOBALS['pagetitle']); | 604 | $this->tpl->assign('pagetitle', 'Shaarli'); |
589 | $this->tpl->assign('shaarlititle',empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title'] ); | 605 | $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? |
590 | return; | 606 | if (!empty($GLOBALS['title'])) { |
607 | $this->tpl->assign('pagetitle', $GLOBALS['title']); | ||
608 | } | ||
609 | if (!empty($GLOBALS['titleLink'])) { | ||
610 | $this->tpl->assign('titleLink', $GLOBALS['titleLink']); | ||
611 | } | ||
612 | if (!empty($GLOBALS['pagetitle'])) { | ||
613 | $this->tpl->assign('pagetitle', $GLOBALS['pagetitle']); | ||
614 | } | ||
615 | $this->tpl->assign('shaarlititle', empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title']); | ||
616 | if (!empty($GLOBALS['plugins']['errors'])) { | ||
617 | $this->tpl->assign('plugin_errors', $GLOBALS['plugins']['errors']); | ||
618 | } | ||
591 | } | 619 | } |
592 | 620 | ||
593 | // The following assign() method is basically the same as RainTPL (except that it's lazy) | 621 | // The following assign() method is basically the same as RainTPL (except that it's lazy) |
@@ -962,16 +990,31 @@ function showDaily() | |||
962 | $fill[$index]+=$length; | 990 | $fill[$index]+=$length; |
963 | } | 991 | } |
964 | $PAGE = new pageBuilder; | 992 | $PAGE = new pageBuilder; |
965 | $PAGE->assign('linksToDisplay',$linksToDisplay); | 993 | $data = array( |
966 | $PAGE->assign('linkcount',count($LINKSDB)); | 994 | 'linksToDisplay' => $linksToDisplay, |
967 | $PAGE->assign('cols', $columns); | 995 | 'linkcount' => count($LINKSDB), |
968 | $PAGE->assign('day',linkdate2timestamp($day.'_000000')); | 996 | 'cols' => $columns, |
969 | $PAGE->assign('previousday',$previousday); | 997 | 'day' => linkdate2timestamp($day.'_000000'), |
970 | $PAGE->assign('nextday',$nextday); | 998 | 'previousday' => $previousday, |
999 | 'nextday' => $nextday, | ||
1000 | ); | ||
1001 | $pluginManager = PluginManager::getInstance(); | ||
1002 | $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn())); | ||
1003 | |||
1004 | foreach ($data as $key => $value) { | ||
1005 | $PAGE->assign($key, $value); | ||
1006 | } | ||
1007 | |||
971 | $PAGE->renderPage('daily'); | 1008 | $PAGE->renderPage('daily'); |
972 | exit; | 1009 | exit; |
973 | } | 1010 | } |
974 | 1011 | ||
1012 | // Renders the linklist | ||
1013 | function showLinkList($PAGE, $LINKSDB) { | ||
1014 | buildLinkList($PAGE,$LINKSDB); // Compute list of links to display | ||
1015 | $PAGE->renderPage('linklist'); | ||
1016 | } | ||
1017 | |||
975 | 1018 | ||
976 | // ------------------------------------------------------------------------------------------ | 1019 | // ------------------------------------------------------------------------------------------ |
977 | // Render HTML page (according to URL parameters and user rights) | 1020 | // Render HTML page (according to URL parameters and user rights) |
@@ -983,12 +1026,36 @@ function renderPage() | |||
983 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] | 1026 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'] |
984 | ); | 1027 | ); |
985 | 1028 | ||
1029 | $PAGE = new pageBuilder; | ||
1030 | |||
1031 | // Determine which page will be rendered. | ||
1032 | $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : ''; | ||
1033 | $targetPage = Router::findPage($query, $_GET, isLoggedIn()); | ||
1034 | |||
1035 | // Call plugin hooks for header, footer and includes, specifying which page will be rendered. | ||
1036 | // Then assign generated data to RainTPL. | ||
1037 | $common_hooks = array( | ||
1038 | 'header', | ||
1039 | 'footer', | ||
1040 | 'includes', | ||
1041 | ); | ||
1042 | $pluginManager = PluginManager::getInstance(); | ||
1043 | foreach($common_hooks as $name) { | ||
1044 | $plugin_data = array(); | ||
1045 | $pluginManager->executeHooks('render_' . $name, $plugin_data, | ||
1046 | array( | ||
1047 | 'target' => $targetPage, | ||
1048 | 'loggedin' => isLoggedIn() | ||
1049 | ) | ||
1050 | ); | ||
1051 | $PAGE->assign('plugins_' . $name, $plugin_data); | ||
1052 | } | ||
1053 | |||
986 | // -------- Display login form. | 1054 | // -------- Display login form. |
987 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=login')) | 1055 | if ($targetPage == Router::$PAGE_LOGIN) |
988 | { | 1056 | { |
989 | if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli | 1057 | if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli |
990 | $token=''; if (ban_canLogin()) $token=getToken(); // Do not waste token generation if not useful. | 1058 | $token=''; if (ban_canLogin()) $token=getToken(); // Do not waste token generation if not useful. |
991 | $PAGE = new pageBuilder; | ||
992 | $PAGE->assign('token',$token); | 1059 | $PAGE->assign('token',$token); |
993 | $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):'')); | 1060 | $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):'')); |
994 | $PAGE->renderPage('loginform'); | 1061 | $PAGE->renderPage('loginform'); |
@@ -1004,7 +1071,7 @@ function renderPage() | |||
1004 | } | 1071 | } |
1005 | 1072 | ||
1006 | // -------- Picture wall | 1073 | // -------- Picture wall |
1007 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=picwall')) | 1074 | if ($targetPage == Router::$PAGE_PICWALL) |
1008 | { | 1075 | { |
1009 | // Optionally filter the results: | 1076 | // Optionally filter the results: |
1010 | $links=array(); | 1077 | $links=array(); |
@@ -1027,15 +1094,22 @@ function renderPage() | |||
1027 | } | 1094 | } |
1028 | } | 1095 | } |
1029 | 1096 | ||
1030 | $PAGE = new pageBuilder; | 1097 | $data = array( |
1031 | $PAGE->assign('linkcount',count($LINKSDB)); | 1098 | 'linkcount' => count($LINKSDB), |
1032 | $PAGE->assign('linksToDisplay',$linksToDisplay); | 1099 | 'linksToDisplay' => $linksToDisplay, |
1100 | ); | ||
1101 | $pluginManager->executeHooks('render_picwall', $data, array('loggedin' => isLoggedIn())); | ||
1102 | |||
1103 | foreach ($data as $key => $value) { | ||
1104 | $PAGE->assign($key, $value); | ||
1105 | } | ||
1106 | |||
1033 | $PAGE->renderPage('picwall'); | 1107 | $PAGE->renderPage('picwall'); |
1034 | exit; | 1108 | exit; |
1035 | } | 1109 | } |
1036 | 1110 | ||
1037 | // -------- Tag cloud | 1111 | // -------- Tag cloud |
1038 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=tagcloud')) | 1112 | if ($targetPage == Router::$PAGE_TAGCLOUD) |
1039 | { | 1113 | { |
1040 | $tags= $LINKSDB->allTags(); | 1114 | $tags= $LINKSDB->allTags(); |
1041 | 1115 | ||
@@ -1049,9 +1123,17 @@ function renderPage() | |||
1049 | { | 1123 | { |
1050 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); | 1124 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); |
1051 | } | 1125 | } |
1052 | $PAGE = new pageBuilder; | 1126 | |
1053 | $PAGE->assign('linkcount',count($LINKSDB)); | 1127 | $data = array( |
1054 | $PAGE->assign('tags',$tagList); | 1128 | 'linkcount' => count($LINKSDB), |
1129 | 'tags' => $tagList, | ||
1130 | ); | ||
1131 | $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); | ||
1132 | |||
1133 | foreach ($data as $key => $value) { | ||
1134 | $PAGE->assign($key, $value); | ||
1135 | } | ||
1136 | |||
1055 | $PAGE->renderPage('tagcloud'); | 1137 | $PAGE->renderPage('tagcloud'); |
1056 | exit; | 1138 | exit; |
1057 | } | 1139 | } |
@@ -1164,32 +1246,36 @@ function renderPage() | |||
1164 | header('Location: ?do=login&post='); | 1246 | header('Location: ?do=login&post='); |
1165 | exit; | 1247 | exit; |
1166 | } | 1248 | } |
1167 | 1249 | showLinkList($PAGE, $LINKSDB); | |
1168 | if (isset($_GET['edit_link'])) { | 1250 | if (isset($_GET['edit_link'])) { |
1169 | header('Location: ?do=login&edit_link='. escape($_GET['edit_link'])); | 1251 | header('Location: ?do=login&edit_link='. escape($_GET['edit_link'])); |
1170 | exit; | 1252 | exit; |
1171 | } | 1253 | } |
1172 | 1254 | ||
1173 | $PAGE = new pageBuilder; | ||
1174 | buildLinkList($PAGE,$LINKSDB); // Compute list of links to display | ||
1175 | $PAGE->renderPage('linklist'); | ||
1176 | exit; // Never remove this one! All operations below are reserved for logged in user. | 1255 | exit; // Never remove this one! All operations below are reserved for logged in user. |
1177 | } | 1256 | } |
1178 | 1257 | ||
1179 | // -------- All other functions are reserved for the registered user: | 1258 | // -------- All other functions are reserved for the registered user: |
1180 | 1259 | ||
1181 | // -------- Display the Tools menu if requested (import/export/bookmarklet...) | 1260 | // -------- Display the Tools menu if requested (import/export/bookmarklet...) |
1182 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=tools')) | 1261 | if ($targetPage == Router::$PAGE_TOOLS) |
1183 | { | 1262 | { |
1184 | $PAGE = new pageBuilder; | 1263 | $data = array( |
1185 | $PAGE->assign('linkcount',count($LINKSDB)); | 1264 | 'linkcount' => count($LINKSDB), |
1186 | $PAGE->assign('pageabsaddr',index_url($_SERVER)); | 1265 | 'pageabsaddr' => index_url($_SERVER), |
1266 | ); | ||
1267 | $pluginManager->executeHooks('render_tools', $data); | ||
1268 | |||
1269 | foreach ($data as $key => $value) { | ||
1270 | $PAGE->assign($key, $value); | ||
1271 | } | ||
1272 | |||
1187 | $PAGE->renderPage('tools'); | 1273 | $PAGE->renderPage('tools'); |
1188 | exit; | 1274 | exit; |
1189 | } | 1275 | } |
1190 | 1276 | ||
1191 | // -------- User wants to change his/her password. | 1277 | // -------- User wants to change his/her password. |
1192 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=changepasswd')) | 1278 | if ($targetPage == Router::$PAGE_CHANGEPASSWORD) |
1193 | { | 1279 | { |
1194 | if ($GLOBALS['config']['OPEN_SHAARLI']) die('You are not supposed to change a password on an Open Shaarli.'); | 1280 | if ($GLOBALS['config']['OPEN_SHAARLI']) die('You are not supposed to change a password on an Open Shaarli.'); |
1195 | if (!empty($_POST['setpassword']) && !empty($_POST['oldpassword'])) | 1281 | if (!empty($_POST['setpassword']) && !empty($_POST['oldpassword'])) |
@@ -1220,7 +1306,6 @@ function renderPage() | |||
1220 | } | 1306 | } |
1221 | else // show the change password form. | 1307 | else // show the change password form. |
1222 | { | 1308 | { |
1223 | $PAGE = new pageBuilder; | ||
1224 | $PAGE->assign('linkcount',count($LINKSDB)); | 1309 | $PAGE->assign('linkcount',count($LINKSDB)); |
1225 | $PAGE->assign('token',getToken()); | 1310 | $PAGE->assign('token',getToken()); |
1226 | $PAGE->renderPage('changepassword'); | 1311 | $PAGE->renderPage('changepassword'); |
@@ -1229,7 +1314,7 @@ function renderPage() | |||
1229 | } | 1314 | } |
1230 | 1315 | ||
1231 | // -------- User wants to change configuration | 1316 | // -------- User wants to change configuration |
1232 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=configure')) | 1317 | if ($targetPage == Router::$PAGE_CONFIGURE) |
1233 | { | 1318 | { |
1234 | if (!empty($_POST['title']) ) | 1319 | if (!empty($_POST['title']) ) |
1235 | { | 1320 | { |
@@ -1265,7 +1350,6 @@ function renderPage() | |||
1265 | } | 1350 | } |
1266 | else // Show the configuration form. | 1351 | else // Show the configuration form. |
1267 | { | 1352 | { |
1268 | $PAGE = new pageBuilder; | ||
1269 | $PAGE->assign('linkcount',count($LINKSDB)); | 1353 | $PAGE->assign('linkcount',count($LINKSDB)); |
1270 | $PAGE->assign('token',getToken()); | 1354 | $PAGE->assign('token',getToken()); |
1271 | $PAGE->assign('title', empty($GLOBALS['title']) ? '' : $GLOBALS['title'] ); | 1355 | $PAGE->assign('title', empty($GLOBALS['title']) ? '' : $GLOBALS['title'] ); |
@@ -1279,11 +1363,10 @@ function renderPage() | |||
1279 | } | 1363 | } |
1280 | 1364 | ||
1281 | // -------- User wants to rename a tag or delete it | 1365 | // -------- User wants to rename a tag or delete it |
1282 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=changetag')) | 1366 | if ($targetPage == Router::$PAGE_CHANGETAG) |
1283 | { | 1367 | { |
1284 | if (empty($_POST['fromtag'])) | 1368 | if (empty($_POST['fromtag'])) |
1285 | { | 1369 | { |
1286 | $PAGE = new pageBuilder; | ||
1287 | $PAGE->assign('linkcount',count($LINKSDB)); | 1370 | $PAGE->assign('linkcount',count($LINKSDB)); |
1288 | $PAGE->assign('token',getToken()); | 1371 | $PAGE->assign('token',getToken()); |
1289 | $PAGE->assign('tags', $LINKSDB->allTags()); | 1372 | $PAGE->assign('tags', $LINKSDB->allTags()); |
@@ -1328,9 +1411,8 @@ function renderPage() | |||
1328 | } | 1411 | } |
1329 | 1412 | ||
1330 | // -------- User wants to add a link without using the bookmarklet: Show form. | 1413 | // -------- User wants to add a link without using the bookmarklet: Show form. |
1331 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=addlink')) | 1414 | if ($targetPage == Router::$PAGE_ADDLINK) |
1332 | { | 1415 | { |
1333 | $PAGE = new pageBuilder; | ||
1334 | $PAGE->assign('linkcount',count($LINKSDB)); | 1416 | $PAGE->assign('linkcount',count($LINKSDB)); |
1335 | $PAGE->renderPage('addlink'); | 1417 | $PAGE->renderPage('addlink'); |
1336 | exit; | 1418 | exit; |
@@ -1349,6 +1431,9 @@ function renderPage() | |||
1349 | $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), | 1431 | $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), |
1350 | 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); | 1432 | 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); |
1351 | if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. | 1433 | if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. |
1434 | |||
1435 | $pluginManager->executeHooks('save_link', $link); | ||
1436 | |||
1352 | $LINKSDB[$linkdate] = $link; | 1437 | $LINKSDB[$linkdate] = $link; |
1353 | $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // Save to disk. | 1438 | $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // Save to disk. |
1354 | pubsubhub(); | 1439 | pubsubhub(); |
@@ -1386,6 +1471,9 @@ function renderPage() | |||
1386 | // - confirmation is handled by JavaScript | 1471 | // - confirmation is handled by JavaScript |
1387 | // - we are protected from XSRF by the token. | 1472 | // - we are protected from XSRF by the token. |
1388 | $linkdate=$_POST['lf_linkdate']; | 1473 | $linkdate=$_POST['lf_linkdate']; |
1474 | |||
1475 | $pluginManager->executeHooks('delete_link', $LINKSDB[$linkdate]); | ||
1476 | |||
1389 | unset($LINKSDB[$linkdate]); | 1477 | unset($LINKSDB[$linkdate]); |
1390 | $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // save to disk | 1478 | $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // save to disk |
1391 | 1479 | ||
@@ -1427,13 +1515,20 @@ function renderPage() | |||
1427 | { | 1515 | { |
1428 | $link = $LINKSDB[$_GET['edit_link']]; // Read database | 1516 | $link = $LINKSDB[$_GET['edit_link']]; // Read database |
1429 | if (!$link) { header('Location: ?'); exit; } // Link not found in database. | 1517 | if (!$link) { header('Location: ?'); exit; } // Link not found in database. |
1430 | $PAGE = new pageBuilder; | 1518 | $data = array( |
1431 | $PAGE->assign('linkcount',count($LINKSDB)); | 1519 | 'linkcount' => count($LINKSDB), |
1432 | $PAGE->assign('link',$link); | 1520 | 'link' => $link, |
1433 | $PAGE->assign('link_is_new',false); | 1521 | 'link_is_new' => false, |
1434 | $PAGE->assign('token',getToken()); // XSRF protection. | 1522 | 'token' => getToken(), |
1435 | $PAGE->assign('http_referer',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : '')); | 1523 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1436 | $PAGE->assign('tags', $LINKSDB->allTags()); | 1524 | 'tags' => $LINKSDB->allTags(), |
1525 | ); | ||
1526 | $pluginManager->executeHooks('render_editlink', $data); | ||
1527 | |||
1528 | foreach ($data as $key => $value) { | ||
1529 | $PAGE->assign($key, $value); | ||
1530 | } | ||
1531 | |||
1437 | $PAGE->renderPage('editlink'); | 1532 | $PAGE->renderPage('editlink'); |
1438 | exit; | 1533 | exit; |
1439 | } | 1534 | } |
@@ -1497,24 +1592,30 @@ function renderPage() | |||
1497 | ); | 1592 | ); |
1498 | } | 1593 | } |
1499 | 1594 | ||
1500 | $PAGE = new pageBuilder; | 1595 | $data = array( |
1501 | $PAGE->assign('linkcount',count($LINKSDB)); | 1596 | 'linkcount' => count($LINKSDB), |
1502 | $PAGE->assign('link',$link); | 1597 | 'link' => $link, |
1503 | $PAGE->assign('link_is_new',$link_is_new); | 1598 | 'link_is_new' => $link_is_new, |
1504 | $PAGE->assign('token',getToken()); // XSRF protection. | 1599 | 'token' => getToken(), // XSRF protection. |
1505 | $PAGE->assign('http_referer',(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')); | 1600 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1506 | $PAGE->assign('source',(isset($_GET['source']) ? $_GET['source'] : '')); | 1601 | 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), |
1507 | $PAGE->assign('tags', $LINKSDB->allTags()); | 1602 | 'tags' => $LINKSDB->allTags(), |
1603 | ); | ||
1604 | $pluginManager->executeHooks('render_editlink', $data); | ||
1605 | |||
1606 | foreach ($data as $key => $value) { | ||
1607 | $PAGE->assign($key, $value); | ||
1608 | } | ||
1609 | |||
1508 | $PAGE->renderPage('editlink'); | 1610 | $PAGE->renderPage('editlink'); |
1509 | exit; | 1611 | exit; |
1510 | } | 1612 | } |
1511 | 1613 | ||
1512 | // -------- Export as Netscape Bookmarks HTML file. | 1614 | // -------- Export as Netscape Bookmarks HTML file. |
1513 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=export')) | 1615 | if ($targetPage == Router::$PAGE_EXPORT) |
1514 | { | 1616 | { |
1515 | if (empty($_GET['what'])) | 1617 | if (empty($_GET['what'])) |
1516 | { | 1618 | { |
1517 | $PAGE = new pageBuilder; | ||
1518 | $PAGE->assign('linkcount',count($LINKSDB)); | 1619 | $PAGE->assign('linkcount',count($LINKSDB)); |
1519 | $PAGE->renderPage('export'); | 1620 | $PAGE->renderPage('export'); |
1520 | exit; | 1621 | exit; |
@@ -1566,9 +1667,8 @@ HTML; | |||
1566 | } | 1667 | } |
1567 | 1668 | ||
1568 | // -------- Show upload/import dialog: | 1669 | // -------- Show upload/import dialog: |
1569 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=import')) | 1670 | if ($targetPage == Router::$PAGE_IMPORT) |
1570 | { | 1671 | { |
1571 | $PAGE = new pageBuilder; | ||
1572 | $PAGE->assign('linkcount',count($LINKSDB)); | 1672 | $PAGE->assign('linkcount',count($LINKSDB)); |
1573 | $PAGE->assign('token',getToken()); | 1673 | $PAGE->assign('token',getToken()); |
1574 | $PAGE->assign('maxfilesize',getMaxFileSize()); | 1674 | $PAGE->assign('maxfilesize',getMaxFileSize()); |
@@ -1577,9 +1677,7 @@ HTML; | |||
1577 | } | 1677 | } |
1578 | 1678 | ||
1579 | // -------- Otherwise, simply display search form and links: | 1679 | // -------- Otherwise, simply display search form and links: |
1580 | $PAGE = new pageBuilder; | 1680 | showLinkList($PAGE, $LINKSDB); |
1581 | buildLinkList($PAGE,$LINKSDB); // Compute list of links to display | ||
1582 | $PAGE->renderPage('linklist'); | ||
1583 | exit; | 1681 | exit; |
1584 | } | 1682 | } |
1585 | 1683 | ||
@@ -1750,7 +1848,7 @@ function buildLinkList($PAGE,$LINKSDB) | |||
1750 | $taglist = explode(' ',$link['tags']); | 1848 | $taglist = explode(' ',$link['tags']); |
1751 | uasort($taglist, 'strcasecmp'); | 1849 | uasort($taglist, 'strcasecmp'); |
1752 | $link['taglist']=$taglist; | 1850 | $link['taglist']=$taglist; |
1753 | 1851 | $link['shorturl'] = smallHash($link['linkdate']); | |
1754 | if ($link["url"][0] === '?' && // Check for both signs of a note: starting with ? and 7 chars long. I doubt that you'll post any links that look like this. | 1852 | if ($link["url"][0] === '?' && // Check for both signs of a note: starting with ? and 7 chars long. I doubt that you'll post any links that look like this. |
1755 | strlen($link["url"]) === 7) { | 1853 | strlen($link["url"]) === 7) { |
1756 | $link["url"] = index_url($_SERVER) . $link["url"]; | 1854 | $link["url"] = index_url($_SERVER) . $link["url"]; |
@@ -1770,18 +1868,28 @@ function buildLinkList($PAGE,$LINKSDB) | |||
1770 | $token = ''; if (isLoggedIn()) $token=getToken(); | 1868 | $token = ''; if (isLoggedIn()) $token=getToken(); |
1771 | 1869 | ||
1772 | // Fill all template fields. | 1870 | // Fill all template fields. |
1773 | $PAGE->assign('linkcount',count($LINKSDB)); | 1871 | $data = array( |
1774 | $PAGE->assign('previous_page_url',$previous_page_url); | 1872 | 'linkcount' => count($LINKSDB), |
1775 | $PAGE->assign('next_page_url',$next_page_url); | 1873 | 'previous_page_url' => $previous_page_url, |
1776 | $PAGE->assign('page_current',$page); | 1874 | 'next_page_url' => $next_page_url, |
1777 | $PAGE->assign('page_max',$pagecount); | 1875 | 'page_current' => $page, |
1778 | $PAGE->assign('result_count',count($linksToDisplay)); | 1876 | 'page_max' => $pagecount, |
1779 | $PAGE->assign('search_type',$search_type); | 1877 | 'result_count' => count($linksToDisplay), |
1780 | $PAGE->assign('search_crits',$search_crits); | 1878 | 'search_type' => $search_type, |
1781 | $PAGE->assign('redirector',empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']); // Optional redirector URL. | 1879 | 'search_crits' => $search_crits, |
1782 | $PAGE->assign('token',$token); | 1880 | 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], // Optional redirector URL. |
1783 | $PAGE->assign('links',$linkDisp); | 1881 | 'token' => $token, |
1784 | $PAGE->assign('tags', $LINKSDB->allTags()); | 1882 | 'links' => $linkDisp, |
1883 | 'tags' => $LINKSDB->allTags(), | ||
1884 | ); | ||
1885 | |||
1886 | $pluginManager = PluginManager::getInstance(); | ||
1887 | $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn())); | ||
1888 | |||
1889 | foreach ($data as $key => $value) { | ||
1890 | $PAGE->assign($key, $value); | ||
1891 | } | ||
1892 | |||
1785 | return; | 1893 | return; |
1786 | } | 1894 | } |
1787 | 1895 | ||