Skip to content

Commit 15f2b7f

Browse files
committed
8.7 LTS compatibility, sticky on old
Fix to make CoolUri compatible with 8.7 LTS Sticky option added to old links, option not to delete sticky links upon delete all action
1 parent 524416d commit 15f2b7f

File tree

7 files changed

+118
-59
lines changed

7 files changed

+118
-59
lines changed

Classes/Core/Translate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ private function saveInCache($params,$path,$originalparams,$updatecacheid,$cache
832832
$db->query('UPDATE '.$tp.'cache SET url='.$db->escape($path.$p).' WHERE id='.(int)$updatecacheid);
833833

834834
// if the path has changed back, no need to store it in the oldlinks
835-
// prevets from overflooding the DB when tampering with configuration
835+
// prevents from flooding the DB when tampering with configuration
836836
$db->query('DELETE FROM '.$tp.'oldlinks WHERE url='.$db->escape($path.$p));
837837

838838
}

Classes/Integration/CoolUri.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static function cool2params($params, $ref)
127127
$params['pObj']->id = $pars['id'];
128128
unset($pars['id']);
129129
$npars = self::extractArraysFromParams($pars);
130-
\TYPO3\CMS\Core\Utility\GeneralUtility::stripSlashesOnArray($npars);
130+
self::stripSlashesOnArray($npars);
131131
$params['pObj']->mergingWithGetVars($npars);
132132

133133
// Re-create QUERY_STRING from Get vars for use with typoLink()
@@ -622,6 +622,19 @@ public static function pageNotFound()
622622
{
623623
$GLOBALS['TSFE']->pageNotFoundAndExit();
624624
}
625+
626+
private static function stripSlashesOnArray(array &$theArray)
627+
{
628+
foreach ($theArray as &$value) {
629+
if (is_array($value)) {
630+
self::stripSlashesOnArray($value);
631+
} else {
632+
$value = stripslashes($value);
633+
}
634+
}
635+
unset($value);
636+
reset($theArray);
637+
}
625638
}
626639

627640
?>

Classes/Manager/Main.php

Lines changed: 96 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function main() {
4141

4242
if (!$this->enable) return $this->noCache();
4343

44-
$content = '';
44+
$content = '<div class="container-fluid">';
4545

4646
// if (empty($_GET['mod'])) {
4747
// $content .= $this->welcome();
@@ -58,6 +58,9 @@ public function main() {
5858
default: $content .= $this->cache();
5959
}
6060
// }
61+
62+
$content .= '</div>';
63+
6164
return $content;
6265
}
6366

@@ -67,22 +70,30 @@ public function all() {
6770
if (isset($_POST['refresh'])) {
6871
$this->db->query('UPDATE '.$this->table.'cache SET tstamp=0');
6972
} elseif (isset($_POST['delete'])) {
70-
$this->db->query('TRUNCATE '.$this->table.'cache');
71-
$this->db->query('TRUNCATE '.$this->table.'oldlinks');
73+
if (isset($_POST['sticky']) && $_POST['sticky'] == 1) {
74+
$this->db->query('TRUNCATE '.$this->table.'cache');
75+
$this->db->query('TRUNCATE '.$this->table.'oldlinks');
76+
} else {
77+
$this->db->query('DELETE FROM '.$this->table.'cache WHERE sticky != 1');
78+
$this->db->query('DELETE FROM '.$this->table.'oldlinks WHERE sticky != 1');
79+
}
7280
}
7381
$c .= '<div class="succes"><p>Done.</p></div>';
7482
}
7583
$c .= '
7684
<h2>Force all links to update upon next hit</h2>
77-
<p>Upon next page hit, all links will be regenerated and if changed, old link will be moved to "oldlinks".</p>
85+
<p>Upon next page hit, all links will be regenerated and if changed, any old link will be moved to "oldlinks".</p>
7886
<form method="post" action="'.$this->file.'mod=all">
79-
<input type="submit" name="refresh" value="FORCE UPDATE OF ALL LINKS" class="btn btn-warning" />
87+
<input type="submit" name="refresh" value="FORCE UPDATE OF ALL LINKS" class="btn btn-warning">
8088
</form>
8189
82-
<h2>Start againg</h2>
90+
<h2>Start again</h2>
8391
<p>Delete everything - cache and oldlinks.</p>
84-
<form method="post" action="'.$this->file.'mod=all">
85-
<input type="submit" name="delete" value="DELETE EVERYTHING AND START AGAIN" class="btn btn-danger" />
92+
<form method="post" action="'.$this->file.'mod=all" class="form-inline">
93+
<input type="submit" name="delete" value="DELETE EVERYTHING AND START AGAIN" class="btn btn-danger">
94+
<label class="checkbox">
95+
<input type="checkbox" name="sticky" value="1"> Delete sticky too
96+
</label>
8697
</form>
8798
';
8899
return $c;
@@ -98,11 +109,19 @@ private function serializedArrayToQueryString($ar) {
98109
}
99110

100111
public function delete() {
101-
if (empty($_GET['lid'])) $id = 0;
102-
else $id = (int)$_GET['lid'];
112+
if (empty($_GET['lid'])) {
113+
$id = 0;
114+
}
115+
else {
116+
$id = (int)$_GET['lid'];
117+
}
103118

104-
if (isset($_GET['old'])) $old = true;
105-
else $old = false;
119+
if (isset($_GET['old'])) {
120+
$old = true;
121+
}
122+
else {
123+
$old = false;
124+
}
106125

107126
if (!empty($id)) {
108127
$q = $this->db->query('DELETE FROM '.$this->table.($old?'oldlinks':'cache').' WHERE id='.$id.' LIMIT 1');
@@ -120,11 +139,15 @@ public function sticky() {
120139
if (empty($_GET['lid'])) $id = 0;
121140
else $id = (int)$_GET['lid'];
122141

123-
if (isset($_GET['old'])) $old = true;
124-
else $old = false;
142+
if (isset($_GET['old'])) {
143+
$old = true;
144+
}
145+
else {
146+
$old = false;
147+
}
125148

126149
if (!empty($id)) {
127-
$q = $this->db->query('UPDATE '.$this->table.'cache SET sticky=not(sticky) WHERE id='.$id.' LIMIT 1');
150+
$q = $this->db->query('UPDATE '.$this->table.($old?'oldlinks':'cache').' SET sticky=not(sticky) WHERE id='.$id.' LIMIT 1');
128151
if (!$q || $this->db->affected_rows()==0) {
129152
$c = '<div class="error"><p>The sticky value hasn\'t been changed because the link doesn\'t exist (or maybe a DB error).</p></div>';
130153
} else {
@@ -198,13 +221,11 @@ public function cache() {
198221
';
199222
}
200223
$c .= '</p>';
201-
$c .= '<form method="post" action="'.$this->file.'">
202-
<p class="center">
203-
Link starts with: <input type="text" name="l" class="a" value="'.htmlspecialchars($let).'" />
204-
<input type="hidden" name="mod" value="cache" />
205-
<input type="submit" value="Search" class="submit" />
206-
<label>Ignore domain: <input type="checkbox" name="domain" value="1" '.(!empty($_REQUEST['domain'])?' checked="checked"':'').'/></label>
207-
</p>
224+
$c .= '<form method="post" action="'.$this->file.'" class="form-inline">
225+
<label>Link starts with: <input type="text" name="l" class="a form-control" value="'.htmlspecialchars($let).'"></label>
226+
<input type="hidden" name="mod" value="cache">
227+
<input type="submit" value="Search" class="submit btn btn-primary">
228+
<label><input type="checkbox" name="domain" value="1" '.(!empty($_REQUEST['domain'])?' checked="checked"':'').'> Ignore domain</label>
208229
</form>';
209230

210231
if (!empty($let)) {
@@ -227,10 +248,13 @@ public function cache() {
227248
<td>'.$row['crdatetime'].'</td>
228249
<td>'.$row['tstamp'].'</td>
229250
<td>'.($row['sticky']?'YES':'NO').'</td>
230-
<td class="nowrap"><a href="'.$this->file.'mod=link&amp;lid='.$row['id'].'"><img src="'.$this->resPath.'img/button_edit.gif" alt="Edit" title="Edit" /></a>
231-
<a href="'.$this->file.'mod=update&amp;lid='.$row['id'].'&amp;from=cache:'.$let.'"><img src="'.$this->resPath.'img/button_refresh.gif" alt="Update" title="Update" /></a>
232-
<a href="'.$this->file.'mod=delete&amp;lid='.$row['id'].'&amp;from=cache:'.$let.'"><img src="'.$this->resPath.'img/button_garbage.gif" alt="Delete" title="Delete" onclick="return confirm(\'Are you sure?\');" /></a>
233-
<a href="'.$this->file.'mod=sticky&amp;lid='.$row['id'].'&amp;from=cache:'.$let.'"><img src="'.$this->resPath.'img/button_sticky.gif" alt="Sticky on/off" title="Sticky on/off" /></a>
251+
<td class="nowrap">
252+
<div class="btn-group">
253+
<a href="'.$this->file.'mod=link&amp;lid='.$row['id'].'" class="btn btn-default"><img src="'.$this->resPath.'img/button_edit.gif" alt="Edit" title="Edit"></a>
254+
<a href="'.$this->file.'mod=update&amp;lid='.$row['id'].'&amp;from=cache:'.$let.'" class="btn btn-default"><img src="'.$this->resPath.'img/button_refresh.gif" alt="Update" title="Update"></a>
255+
<a href="'.$this->file.'mod=delete&amp;lid='.$row['id'].'&amp;from=cache:'.$let.'" class="btn btn-default" onclick="return confirm(\'Are you sure?\');"><img src="'.$this->resPath.'img/button_garbage.gif" alt="Delete" title="Delete"></a>
256+
<a href="'.$this->file.'mod=sticky&amp;lid='.$row['id'].'&amp;from=cache:'.$let.'" class="btn btn-default"><img src="'.$this->resPath.'img/button_sticky.gif" alt="Sticky on/off" title="Sticky on/off"></a>
257+
</div>
234258
</td>
235259
</tr>';
236260
}
@@ -258,29 +282,32 @@ public function old() {
258282
';
259283
}
260284
$c .= '</p>';
261-
$c .= '<form method="post" action="'.$this->file.'mod=old">
262-
<p class="center">
263-
Link starts with: <input type="text" name="l" class="a" value="'.htmlspecialchars($let).'" />
264-
<input type="hidden" name="mod" value="cache" />
265-
<input type="submit" value="Search" class="submit" />
266-
</p>
285+
$c .= '<form method="post" action="'.$this->file.'mod=old" class="form-inline">
286+
<label>Link starts with: <input type="text" name="l" class="a form-control" value="'.htmlspecialchars($let).'"></label>
287+
<input type="hidden" name="mod" value="cache">
288+
<input type="submit" value="Search" class="submit btn btn-primary">
267289
</form>';
268290

269291
if (!empty($let)) {
270-
$q = $this->db->query('SELECT o.id, o.url AS ourl, l.url AS lurl, o.tstamp FROM '.$this->table.'oldlinks AS o LEFT JOIN '.$this->table.'cache AS l
292+
$q = $this->db->query('SELECT o.id, o.url AS ourl, l.url AS lurl, o.tstamp, o.sticky FROM '.$this->table.'oldlinks AS o LEFT JOIN '.$this->table.'cache AS l
271293
ON l.id=o.link_id WHERE LOWER(o.url) LIKE '.$this->db->escape(strtolower($let).'%').' ORDER BY o.url');
272294

273295
$num = $this->db->num_rows($q);
274296
if ($num>0) {
275297
$c .= '<p class="center">Records found: '.$num.'</p>';
276298
$c .= '<form method="post" action="'.$this->file.'mod=cache">';
277-
$c .= '<table id="list" class="table table-striped"><tr><th class="left">Old URI</th><th class="left">Cached URI</th><th>Moved to olds</th><th>Action</th>';
299+
$c .= '<table id="list" class="table table-striped"><tr><th class="left">Old URI</th><th class="left">Cached URI</th><th>Moved to olds</th><th>Sticky</th><th>Action</th>';
278300
while ($row = $this->db->fetch($q)) {
279301
$c .= '<tr>
280302
<td class="left">'.htmlspecialchars($row['ourl']).'</td>
281303
<td class="left">'.htmlspecialchars($row['lurl']).'</td>
282304
<td>'.$row['tstamp'].'</td>
283-
<td class="nowrap"><a href="'.$this->file.'mod=delete&amp;old&amp;lid='.$row['id'].'&amp;from=old:'.$let.'"><img src="'.$this->resPath.'img/button_garbage.gif" alt="Delete" title="Delete" onclick="return confirm(\'Are you sure?\');" /></a>
305+
<td>'.($row['sticky']?'YES':'NO').'</td>
306+
<td class="nowrap">
307+
<div class="btn-group">
308+
<a href="'.$this->file.'mod=delete&amp;old&amp;lid='.$row['id'].'&amp;from=old:'.$let.'" class="btn btn-default" onclick="return confirm(\'Are you sure?\');"><img src="'.$this->resPath.'img/button_garbage.gif" alt="Delete" title="Delete" ></a>
309+
<a href="'.$this->file.'mod=sticky&amp;old&amp;lid='.$row['id'].'&amp;from=old:'.$let.'" class="btn btn-default"><img src="'.$this->resPath.'img/button_sticky.gif" alt="Sticky on/off" title="Sticky on/off"></a>
310+
</div>
284311
</td>
285312
</tr>';
286313
}
@@ -398,14 +425,22 @@ public function link() {
398425
$c .= '<form method="post" action="'.$this->file.'mod=link'.($new?'':'&amp;lid='.$id).'">
399426
<fieldset>
400427
<legend>URI details</legend>
401-
<label for="url">URI:</label><br />
402-
<input type="text" name="url" id="url" value="'.(empty($data['url'])?'':htmlspecialchars($data['url'])).'" /><br />
403-
<label for="params">Parameters (query string: id=1&amp;type=2):</label><br />
404-
<input type="text" name="params" id="params" value="'.(empty($data['params'])?'':htmlspecialchars($data['params'])).'" /><br />
405-
<label for="sticky">Sticky (won\'t be updated):</label><br />
406-
<input type="checkbox" class="check" name="sticky" id="sticky" value="1" '.(empty($data['sticky'])?'':' checked="checked"').' />
428+
<div class="form-group">
429+
<label for="url">URI:</label>
430+
<input type="text" name="url" id="url" class="form-control" value="'.(empty($data['url'])?'':htmlspecialchars($data['url'])).'">
431+
</div>
432+
<div class="form-group">
433+
<label for="params">Parameters (query string: id=1&amp;type=2):</label>
434+
<input type="text" name="params" id="params" class="form-control" value="'.(empty($data['params'])?'':htmlspecialchars($data['params'])).'">
435+
</div>
436+
<div class="form-group">
437+
<label for="sticky">
438+
<input type="checkbox" class="check" name="sticky" id="sticky" value="1" '.(empty($data['sticky'])?'':' checked="checked"').'>
439+
Sticky (won\'t be updated)
440+
</label>
441+
</div>
407442
</fieldset>
408-
<input type="submit" value=" '.($new?'Save new URI':'Update this URI').' " class="submit" />
443+
<input type="submit" value=" '.($new?'Save new URI':'Update this URI').' " class="submit btn btn-primary">
409444
</form>
410445
';
411446
return $c;
@@ -421,9 +456,10 @@ public function redirect() {
421456
if (empty($id) || empty($_POST['url'])) {
422457
$c .= '<div class="error"><p>All fields are required.</p></div>';
423458
} else {
424-
$this->db->query('INSERT INTO '.$this->table.'oldlinks(link_id,url)
459+
$this->db->query('INSERT INTO '.$this->table.'oldlinks(link_id,url,sticky)
425460
VALUES('.$id.',
426-
'.$this->db->escape($_POST['url']).')');
461+
'.$this->db->escape($_POST['url']).',
462+
'.(!empty($_POST['sticky']) && $_POST['sticky']==1?1:0).')');
427463
$c .= '<div class="succes"><p>The redirect was saved successfully.</p></div>';
428464
}
429465
}
@@ -433,18 +469,28 @@ public function redirect() {
433469
$c .= '<form method="post" action="'.$this->file.'mod=redirect">
434470
<fieldset>
435471
<legend>Redirect details</legend>
436-
<label for="url">From:</label><br />
437-
<input type="text" name="url" id="url" /><br />
438-
<label for="to">To:</label><br />
439-
<select name="to" id="to">
472+
<div class="form-group">
473+
<label for="url">From:</label>
474+
<input type="text" name="url" id="url" class="form-control">
475+
</div>
476+
<div class="form-group">
477+
<label for="to">To:</label>
478+
<select name="to" id="to" class="form-control">
440479
';
441480
while ($row = $this->db->fetch($allq)) {
442481
$c .= '<option value="'.$row['id'].'">'.$row['url'].'</option>
443482
';
444483
}
445484
$c .= '</select>
485+
</div>
486+
<div class="checkbox">
487+
<label for="sticky">
488+
<input type="checkbox" class="check" name="sticky" id="sticky" value="1" '.(empty($data['sticky'])?'':' checked="checked"').'>
489+
Sticky (won\'t be deleted upon Delete all action)
490+
</label>
491+
</div>
446492
</fieldset>
447-
<input type="submit" value="Submit this redirect" class="submit" />
493+
<input type="submit" value="Submit this redirect" class="submit btn btn-primary">
448494
</form>
449495
';
450496
return $c;
@@ -460,7 +506,7 @@ public function menu() {
460506
if (empty($cm)) {
461507
$cm = 'cache';
462508
}
463-
$c = '<nav class="navbar navbar-default"><div class="container-fluid"><ul class="nav navbar-nav">';
509+
$c = '<nav class="navbar navbar-default" style="margin-bottom: 20px"><div class="container-fluid"><ul class="nav nav-tabs">';
464510
foreach ($mods as $k=>$v) {
465511
$c .= '<li'.($cm==$k?' class="active"':'').'><a href="'.$this->file.($k?'mod='.$k:'').'">'.$v.'</a></li>';
466512
}

Resources/Private/Layouts/Default.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<f:be.container>
32
<div class="typo3-fullDoc">
43
<div id="typo3-docheader">
@@ -20,7 +19,7 @@
2019
</div>
2120
<div id="typo3-docbody">
2221
<div id="typo3-inner-docbody">
23-
<f:flashMessages renderMode="div" />
22+
<f:flashMessages />
2423
<f:render section="content" />
2524
</div>
2625
</div>

Resources/Private/Templates/LinkFix/List.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ <h2><f:translate key="LLL:EXT:cooluri/Resources/Private/Language/locallang_fix1.
99

1010
<p><f:translate key="LLL:EXT:cooluri/Resources/Private/Language/locallang_fix1.xlf:mlang_labels_form_description" /></p>
1111

12-
<f:form action="list">
13-
<f:form.textfield name="url" size="100" value="{url}"/>
12+
<f:form action="list" class="form-inline">
13+
<f:form.textfield name="url" size="100" value="{url}" class="form-control"/>
1414
<f:form.submit value="{f:translate(key:'LLL:EXT:cooluri/Resources/Private/Language/locallang_fix1.xlf:mlang_labels_form_button_find' )}" class="btn btn-primary"/>
1515
</f:form>
1616

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'author_email' => '[email protected]',
1010
'constraints' => array(
1111
'depends' => array(
12-
'typo3' => '6.2.0-7.6.99',
12+
'typo3' => '6.2.0-8.7.99',
1313
),
1414
),
1515
);

ext_tables.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CREATE TABLE link_cache (
1919
id int(10) unsigned NOT NULL auto_increment,
2020
params blob,
2121
url char(255),
22-
tstamp TIMESTAMP default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
22+
tstamp TIMESTAMP default CURRENT_TIMESTAMP,
2323
crdatetime datetime default NULL,
2424
sticky tinyint(1) unsigned default 0,
2525

@@ -32,7 +32,8 @@ CREATE TABLE link_oldlinks (
3232
id int(10) unsigned NOT NULL auto_increment,
3333
link_id int(10) unsigned NOT NULL default 0,
3434
url char(255),
35-
tstamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
35+
tstamp timestamp NOT NULL default CURRENT_TIMESTAMP,
36+
sticky tinyint(1) unsigned default 0,
3637

3738
PRIMARY KEY (id),
3839
UNIQUE KEY id (id),

0 commit comments

Comments
 (0)