/
album.php
167 lines (140 loc) · 4.76 KB
/
album.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
<?php if (!defined('VB_ENTRY')) die('Access denied.');
/*========================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.1.9 - Licence Number LD18132D6F
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2015 vBulletin Solutions Inc. All Rights Reserved. # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| ###################################################################### ||
\*========================================================================*/
class vB5_Route_Album extends vB5_Route
{
protected $nodeid;
protected $title;
protected $controller = 'page';
public function __construct($routeInfo, $matches, $queryString = '', $anchor = '')
{
parent::__construct($routeInfo, $matches, $queryString, $anchor);
if (empty($matches['nodeid']))
{
throw new vB_Exception_Router('invalid_request');
}
else
{
$routeInfo['nodeid'] = $matches['nodeid'];
$this->nodeid = $matches['nodeid'];
$this->arguments['nodeid'] = $matches['nodeid'];
$this->arguments['contentid'] = $matches['nodeid'];
}
if (!empty($matches['title']))
{
//It should start with a dash, which we can ignore
$routeInfo['title'] = substr($matches['title'],1);
$this->arguments['title'] = substr($matches['title'],1);
}
if (!empty($routeInfo['title']))
{
$this->title = $routeInfo['title'];
}
$this->setPageKey('nodeid');
$this->setUserAction('viewing_album');
}
protected static function validInput(array &$data)
{
if (!parent::validInput($data) OR !isset($data['nodeid']) OR !is_numeric($data['nodeid']))
{
return FALSE;
}
$node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']);
if (empty($node) OR !empty($node['errors']))
{
return FALSE;
}
$this->title = $node['title'];
}
public function getUrl()
{
$cache = vB_Cache::instance(vB_Cache::CACHE_FAST);
$hashKey = 'vbRouteURLIndent_'. $this->arguments['nodeid'];
$urlident = $cache->read($hashKey);
if (empty($urlident))
{
$node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']);
$urlident = $node['urlident'];
$cache->write($hashKey, $urlident);
}
elseif (is_array($urlident) AND !empty($urlident['urlident']))
{
$urlident = $urlident['urlident'];
}
$url = '/album/' . $this->arguments['nodeid'] . '-' . $urlident;
if (strtolower(vB_String::getCharset()) != 'utf-8')
{
$url = vB_String::encodeUtf8Url($url);
}
return $url;
}
public function getCanonicalRoute($node = false)
{
if (!isset($this->canonicalRoute))
{
if (empty($this->title))
{
if (empty($node))
{
$node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']);
}
if (empty($node) OR !empty($node['errors']))
{
return FALSE;
}
$this->title = self::prepareTitle($node['title']);
}
$routeInfo = array('routeid' => $this->routeId, 'prefix' => $this->prefix, 'regex' => $this->regex,
'nodeid' => $this->nodeid, 'title' => $this->title, 'controller' => $this->controller, 'pageid' => $this->arguments['contentid']);
$this->canonicalRoute = new vB5_Route_Album($routeInfo, array('nodeid' => $this->nodeid), http_build_query($this->queryParameters));
}
return $this->canonicalRoute;
}
/**
* Returns arguments to be exported
* @param string $arguments
* @return array
*/
public static function exportArguments($arguments)
{
$data = unserialize($arguments);
$page = vB::getDbAssertor()->getRow('page', array('pageid' => $data['pageid']));
if (empty($page))
{
throw new Exception('Couldn\'t find page');
}
$data['pageGuid'] = $page['guid'];
unset($data['pageid']);
return serialize($data); }
/**
* Returns an array with imported values for the route
* @param string $arguments
* @return string
*/
public static function importArguments($arguments)
{
$data = unserialize($arguments);
$page = vB::getDbAssertor()->getRow('page', array('guid' => $data['pageGuid']));
if (empty($page))
{
throw new Exception('Couldn\'t find page');
}
$data['pageid'] = $page['pageid'];
unset($data['pageGuid']);
return serialize($data);
}
}
/*=========================================================================*\
|| #######################################################################
|| # Downloaded: 15:45, Tue Sep 8th 2015
|| # CVS: $RCSfile$ - $Revision: 83435 $
|| #######################################################################
\*=========================================================================*/