forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.class.php
More file actions
169 lines (156 loc) · 3.88 KB
/
View.class.php
File metadata and controls
169 lines (156 loc) · 3.88 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
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
168
169
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* URL短縮用表示クラス
*
* @package NetCommons Components
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
class Abbreviateurl_View
{
/**
* @var DBオブジェクトを保持
*
* @access private
*/
var $_db = null;
/**
* @var DIコンテナを保持
*
* @access private
*/
var $_container = null;
/**
* @var Sessionオブジェクトを保持
*
* @access private
*/
var $_session = null;
/**
* コンストラクター
*
* @access public
*/
function Abbreviateurl_View()
{
$this->_container =& DIContainerFactory::getContainer();
$this->_db =& $this->_container->getComponent("DbObject");
$this->_session =& $this->_container->getComponent("Session");
}
/**
* abbreviate_urlから取得
*
* @param string $dir_name
* @param string $unique_id
*
* @return boolean
* @access public
*/
function getAbbreviateUrl($unique_id, $dir_name=null)
{
//dir_nameが省略されている場合、実行アクションから取得
if (!isset($dir_name)) {
$dir_name = $this->getDefaultUniqueKey();
}
$params = array(
'dir_name' => $dir_name,
'unique_id' => $unique_id
);
$result = $this->_db->selectExecute('abbreviate_url', $params);
if ($result === false) {
return $result;
}
if (isset($result[0])) {
return $result[0]["short_url"];
}
return "";
}
/**
* install.iniからアクションを取得
*
* @return string
* @access public
*/
function getIniFile($module_name, $key)
{
// install.iniチェック
// [Abbreviateurl]
$file_path = MODULE_DIR."/".$module_name.'/install.ini';
if (file_exists($file_path)) {
if(version_compare(phpversion(), "5.0.0", ">=")){
$initializer =& DIContainerInitializerLocal::getInstance();
$install_ini = $initializer->read_ini_file($file_path, true);
} else {
$install_ini = parse_ini_file($file_path, true);
}
if (isset($install_ini['Abbreviateurl']) && is_array($install_ini['Abbreviateurl']) && isset($install_ini['Abbreviateurl'][$key])) {
return $install_ini['Abbreviateurl'][$key];
}
}
return "";
}
/**
* ユニークキーの初期値
*
* @return string
* @access public
*/
function getDefaultUniqueKey()
{
$actionChain =& $this->_container->getComponent("ActionChain");
$actionName = $actionChain->getCurActionName();
$pathList = explode("_", $actionName);
$dir_name = $pathList[0];
return $dir_name;
}
/**
* モジュールID取得
*
* @return string
* @access public
*/
function getDefaultModuleId($module_name)
{
$getdata = $this->_container->getComponent("GetData");
$modules = $getdata->getParameter("modules");
if (isset($modules[$module_name])) {
$module = $modules[$module_name];
} else {
$modulesView = $this->_container->getComponent("modulesView");
$module = $modulesView->getModuleByDirname($module_name);
}
$module_id = $module['module_id'];
return $module_id;
}
/**
* 英数字のランダム文字列を作成
*
* @param int $len
* @param string $prefix
*
* @return string
* @access public
*/
function randString($len=8, $prefix=null)
{
$pt = _ABBREVIATE_URL_PATTERN;
$st = '';
if (isset($prefix)) {
$st .= $prefix;
} else {
$rd = rand(0, strlen($pt)-1);
$st .= $pt[$rd];
}
$set_len = strlen($st);
for ($i=0; $i<$len-$set_len; $i++) {
$rd = rand(0, strlen($pt)-1);
$st .= $pt[$rd];
}
return $st;
}
}
?>