-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
123 lines (103 loc) · 1.94 KB
/
helper.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
<?php
/**
* @package Joomla
* @subpackage
*
* @copyright Katalyst Solutions, LLC
* @license GPL2
* @since 1.0
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
class ModKSTitleTagReplacerHelper
{
protected $app;
protected $defaultTitle;
protected $doc;
protected $menu;
protected $option;
/**
* ModKSTitleTagReplacerHelper constructor.
* @param string $defaultTitle
* @since 1.0
*/
public function __construct($defaultTitle = null)
{
$this->app = JFactory::getApplication();
$this->doc = JFactory::getDocument();
$this->option = $this->app->input->getCmd('option', '');
$this->defaultTitle = $defaultTitle;
}
/**
* Get the title string
*
* @return string
*
* @since 1.0
*/
public function getTitle()
{
if ($this->option == 'com_content') {
return $this->getArticleTitle();
}
return $this->getDefaultTitle();
}
/**
* Get the title of the article if com_content
*
* @return string
*
* @since 1.0
*/
protected function getArticleTitle()
{
$id = $this->app->input->getInt('id', 0);
if (empty($id)) {
return $this->getDefaultTitle();
}
$article = JTable::getInstance('content');
$article->load($id);
return $article->get('title');
}
/**
* Return the defaultTitle from the module parameter
*
* @return null|string
*
* @since version
*/
protected function getDefaultTitle()
{
if (!empty($this->defaultTitle)) {
return $this->defaultTitle;
}
return $this->getMenuTitle();
}
/**
* Get the menu item title
*
* @return string
*
* @since 1.0
*/
protected function getMenuTitle()
{
$menu = $this->app->getMenu();
$activeMenu = $menu->getActive();
if (empty($activeMenu)) {
return $this->getSiteTitle();
}
return $activeMenu->title;
}
/**
* Get the site title from global configuration
*
* @return string
*
* @since 1.0
*/
protected function getSiteTitle()
{
return $this->doc->title;
}
}