/
Navigation.php
82 lines (73 loc) · 2.23 KB
/
Navigation.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
<?php
namespace Concrete\Core\Html\Service;
use Concrete\Core\Support\Facade\Application;
use Database;
use Page;
use URL;
use Concrete\Core\User\User;
use Concrete\Core\Validation\CSRF\Token;
class Navigation
{
/**
* Returns a link to a page. Note: this always returns a string.
* if you really need the URL object, use \URL::to($page) instead. Not returning a string was killing a json
* encode in the sitemap (and could probably screw up other stuff down the line.).
*
* @param Page $cObj
*
* @return string
*/
public function getLinkToCollection($cObj)
{
return (string) URL::to($cObj);
}
/**
* Returns an array of collections as a breadcrumb to the current page.
*
* @param Page $c
*
* @return Page[]
*/
public function getTrailToCollection($c)
{
$db = Database::connection();
$cArray = array();
$currentcParentID = $c->getCollectionParentID();
if ($currentcParentID > 0) {
while (is_numeric($currentcParentID) && $currentcParentID > 0 && $currentcParentID) {
$q = "select cID, cParentID from Pages where cID = '{$currentcParentID}'";
$r = $db->query($q);
$row = $r->fetch();
if ($row['cID']) {
$cArray[] = Page::getByID($row['cID'], 'ACTIVE');
}
$currentcParentID = $row['cParentID']; // moving up the tree until we hit 1
}
}
return $cArray;
}
/**
* Returns the URL of a collection so that it can be clicked on.
*
* @param Page $cObj
*
* @return string
*/
public function getCollectionURL($cObj)
{
return $this->getLinkToCollection($cObj);
}
public function getLogInOutLink()
{
$app = Application::getFacadeApplication();
$u = $app->make(User::class);
if (!$u->isRegistered()) {
$url = URL::to('/login');
$label = t('Log in');
} else {
$url = URL::to('/login', 'do_logout', $app->make(Token::class)->generate('do_logout'));
$label = t('Log out');
}
return sprintf('<a href="%s">%s</a>', $url, $label);
}
}