This repository was archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext.last_segment.php
More file actions
131 lines (109 loc) · 2.62 KB
/
ext.last_segment.php
File metadata and controls
131 lines (109 loc) · 2.62 KB
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
<?php if ( ! defined('EXT')) exit('Invalid file request');
/**
* Create some new segment based variables
*
* @package ExpressionEngine
* @subpackage Last_segment Extension
* @category Extension
* @author Tom Kiss
* @link http://www.tomkiss.net/ee
*/
class Last_segment {
var $settings = array();
var $name = 'Last_segment';
var $version = '1.0.2';
var $description = 'Creates a global variable for the last segment in a URL.';
var $settings_exist = 'n';
var $docs_url = 'http://www.tomkiss.net/ee';
/**
* Constructor
*
*/
function Last_segment($settings='')
{
$this->settings = $settings;
}
function set_last_segment($SESS)
{
global $IN, $FNS;
$IN->global_vars['last_segment'] = end($IN->SEGS);
$IN->global_vars['current_url'] = $FNS->fetch_current_uri();
// Ignore Pagination
$start = substr(end($IN->SEGS), 0, 1);
$end = substr(end($IN->SEGS), 1, strlen(end($IN->SEGS)));
if ($start == "P" && (preg_match( '/^\d*$/', $end) == 1))
{
$index = sizeof($IN->SEGS)-1;
$ls_np = $IN->SEGS[$index];
}
else
{
$ls_np = end($IN->SEGS);
}
$IN->global_vars['last_segment_np'] = $ls_np;
}
// --------------------------------------------------------------------
/**
* Activate Extension
*
* Installs the extension
*
* @access public
* @return void
*/
function activate_extension($from_module = FALSE)
{
global $DB, $LANG, $OUT;
$DB->query($DB->insert_string('exp_extensions',
array(
'extension_id' => '',
'class' => "Last_segment",
'method' => "set_last_segment",
'hook' => "sessions_start",
'settings' => "a:0:{}",
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
}
// --------------------------------------------------------------------
/**
* Update Extension
*
* Updates the extension
*
* @access public
* @param type
* @return type
*/
function update_extension($current = '')
{
global $DB;
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
$DB->query("UPDATE exp_extensions
SET version = '".$DB->escape_str($this->version)."'
WHERE class = 'Last_segment'");
}
// --------------------------------------------------------------------
/**
* Disable Extension
*
* Uninstalls the extension
*
* @access public
* @return void
*/
function disable_extension($from_module = FALSE)
{
global $DB, $LANG, $OUT;
$DB->query("DELETE FROM exp_extensions WHERE class = 'Last_segment'");
}
// --------------------------------------------------------------------
}
// END Fresh Variables Class
?>