This repository has been archived by the owner on Dec 7, 2018. It is now read-only.
/
internal_links_scan.php
218 lines (189 loc) · 7.89 KB
/
internal_links_scan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Jojo CMS - Internal links plugin
* ================
*
* Copyright 2007-2008 Robbie MacKay <rjmackay@gmail.com>
*
* See the enclosed file license.txt for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Robbie MacKay <rjmackay@gmail.com>
* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
* @link http://rjmackay.wordpress.org/code/
* @package internal_links
*/
class JOJO_Plugin_internal_links_scan extends JOJO_Plugin
{
function _getContent()
{
global $smarty, $_USERGROUPS;
/*
The $sitemap array holds all the various different sitemap trees.
'title' - the title of the sitemap section eg Pages, Articles, Forums etc.
'tree' - the tree array generated by the plugin.
'header' - any HTML to go above the tree.
'footer' - any HTML to go below the tree.
'order' - the importance or order of the sitemap section. 0 appears first, 10 last.
*/
$sitemap = array();
/* Apply filter to allow other plugins to alter the sitemap */
//$sitemap = Jojo::applyFilter('jojo_sitemap', $sitemap);
$sitemap = _page_sitemap($sitemap);
$sitemap = _article_sitemap($sitemap);
/* Sort the sitemap */
usort($sitemap, array("JOJO_Plugin_internal_links_scan", "_sortSitemap"));
/* Convert array tree into html */
foreach($sitemap as $k => $v) {
$sitemap[$k]['htmlTree'] = JOJO_Plugin_internal_links_scan::_htmlSitemap($v['tree']);
}
/* Assign the sitemap to smarty */
$smarty->assign('sitemap', $sitemap);
/* Return the content */
$content = array();
$content['content'] = $smarty->display('internal_links_scan.tpl');
exit();
//return $content;
}
/**
* Recursively convert the sitemay array to html
*/
function _htmlSitemap($tree)
{
if (!is_array($tree) || !count($tree)) {
return '';
}
//$html = '<ul style="list-style-type: circle;">';
foreach ($tree as $t) {
$html .= sprintf("{url:\"%s\",title:\"%s\", children:[%s]},\n", addslashes($t['url']), addslashes($t['name']), JOJO_Plugin_internal_links_scan::_htmlSitemap($t['children']));
}
//$html .= '</ul>';
return $html;
}
/**
* Sort the sitemap based on the order field
*/
function _sortSitemap($a, $b) {
if ($a['order'] == $b['order']) {
return 0;
}
return ($a['order'] < $b['order']) ? -1 : 1;
}
}
/**
* Sitemap filter
*
* Receives existing sitemap and adds pages section
*/
function _page_sitemap($sitemap)
{
global $_USERGROUPS;
$perms = new JOJO_Permissions();
$pagetree = new hktree();
$sitemappages = JOJO::selectQuery("SELECT * FROM page WHERE pg_livedate<".strtotime('now')." AND (pg_expirydate=0 OR pg_expirydate>".strtotime('now').") ORDER BY pg_order");
$n = count($sitemappages);
for ($i=0;$i<$n;$i++) {
$link = JOJO::urlPrefix( JOJO::yes2true($sitemappages[$i]['pg_ssl']));
if ($sitemappages[$i]['pageid'] == 1) { //homepage
$link = _SITEURL;
} elseif (substr(strtolower($sitemappages[$i]['pg_link']), 0, 7) == 'http://') { //external
$link .= $sitemappages[$i]['pg_link'];
} elseif ($sitemappages[$i]['pg_url']) { //discovery level
if (_MULTILANGUAGE) {
$link .= $sitemappages[$i]['pg_language'] .'/'. $sitemappages[$i]['pg_url'] . '/';
} else {
$link .= $sitemappages[$i]['pg_url'] . '/';
}
} else { //rewritten
$link .= JOJO::rewrite('page',$sitemappages[$i]['pageid'],$sitemappages[$i]['pg_title']);
}
$perms->getPermissions('page', $sitemappages[$i]['pageid']);
if ($perms->hasPerm($_USERGROUPS, 'show')) {
$pagetree->addNode($sitemappages[$i]['pageid'],$sitemappages[$i]['pg_parent'],$sitemappages[$i]['pg_title'],$link);
}
}
/* Add to the sitemap array */
$sitemap['pages'] = array(
'title' => 'Pages',
'tree' => $pagetree->asArray(0,0,5),
'order' => 0,
'header' => '',
'footer' => ''
);
return $sitemap;
}
/**
* Sitemap filter
*
* Receives existing sitemap and adds articles section
*/
function _article_sitemap($sitemap)
{
$limit = 15;
$articlesperpage = 40;
/* Create tree and add index and feed links at the top */
$articletree = new hktree();
$articletree->addNode('index', 0, 'Article Index', JOJO_Plugin_Jojo_article::_getPrefix() . '/');
$articletree->addNode('index-rss', 'index', 'Articles RSS Feed', JOJO_Plugin_Jojo_article::_getPrefix('rss'));
/* Get the article content from the database */
$articles = JOJO_Plugin_Jojo_article::getArticles($limit);
$n = count($articles);
foreach ($articles as $a) {
$articletree->addNode($a['articleid'], 0, $a['ar_title'], $a['url']);
}
/* Get number of articles for pagination */
$now = strtotime('now');
$articlescount = JOJO::selectQuery("SELECT COUNT(*) AS numarticles FROM article WHERE ar_livedate<$now AND (ar_expirydate<=0 OR ar_expirydate>$now)");
$numarticles = $articlescount[0]['numarticles'];
$numpages = ceil($numarticles / $articlesperpage);
/* calculate pagination */
if ($numpages == 1) {
if ($limit < $numarticles) {
$articletree->addNode('p1', 0, 'More Articles', 'articles/');
}
} else {
for ($p=1; $p <= $numpages; $p++) {
$url = ($p == 1) ? 'articles/' : 'articles/p' . $p .'/';
$articletree->addNode('p' . $p, 0, 'Page '. $p ,$url);
}
}
/* Remove any other links to the articles section form the sitemap */
foreach($sitemap as $k => $section) {
$sitemap[$k]['tree'] = JOJO_Plugin_Jojo_article::_sitemapRemoveSelf($section['tree']);
}
/* Add to the sitemap array */
$sitemap['articles'] = array(
'title' => 'Articles',
'tree' => $articletree->asArray(),
'order' => 2,
'header' => '',
'footer' => '',
);
/* Tags are broken at the moment.
//tags
if (tableexists('tag')) {
$tagtree = new hktree();
//$articletree->liststyle = 'disc';
$tagtree->addNode('index',0,'Tag Index','tags/');
$limit = 20;
//Article listing
$tags = JOJO::selectQuery("SELECT * FROM tag WHERE 1 ORDER BY tag LIMIT " . $limit);
$n = count($tags);
for ($i=0;$i<$n;$i++) {
$tags[$i]['url'] = 'tags/'.JOJO::cleanURL($tags[$i]['tag']).'/';
$tagtree->addNode($tags[$i]['tag'],0,$tags[$i]['tag'],$tags[$i]['url']);
}
if ($n) {
// Add to the sitemap array
$sitemapsection = array();
$sitemapsection['title'] = 'Tags';
$sitemapsection['tree'] = $tagtree->asArray();
$sitemapsection['order'] = 5;
$sitemapsection['header'] = '';
$sitemapsection['footer'] = '';
$sitemap[] = $sitemapsection;
}
}
*/
return $sitemap;
}