public function getContentsName($detail = false, $options = array())
{
$options = array_merge(array('home' => 'Home', 'default' => 'Default', 'error' => 'Error', 'underscore' => false), $options);
$home = $options['home'];
$default = $options['default'];
$error = $options['error'];
$underscore = $options['underscore'];
$prefix = '';
$plugin = '';
$controller = '';
$action = '';
$pass = array();
$url0 = '';
$url1 = '';
$url2 = '';
$aryUrl = array();
if (!empty($this->request->params['prefix'])) {
$prefix = h($this->request->params['prefix']);
}
if (!empty($this->request->params['plugin'])) {
$plugin = h($this->request->params['plugin']);
}
$controller = h($this->request->params['controller']);
if ($prefix) {
$action = str_replace($prefix . '_', '', h($this->request->params['action']));
} else {
$action = h($this->request->params['action']);
}
if (!empty($this->request->params['pass'])) {
foreach ($this->request->params['pass'] as $key => $value) {
$pass[$key] = h($value);
}
}
$url = explode('/', h($this->request->url));
if (@$this->request->params['Site']['alias']) {
array_shift($url);
}
if (isset($url[0])) {
$url0 = $url[0];
}
if (isset($url[1])) {
$url1 = $url[1];
}
if (isset($url[2])) {
$url2 = $url[2];
}
// 固定ページの場合
if ($controller == 'pages' && $action == 'display') {
if (strpos($pass[0], 'pages/') !== false) {
$pageUrl = str_replace('pages/', '', $pass[0]);
} else {
if (empty($pass)) {
$pageUrl = h($this->request->url);
} else {
$pageUrl = implode('/', $pass);
}
}
$sitePrefix = $this->getSitePrefix();
if ($sitePrefix) {
$pageUrl = preg_replace('/^' . preg_quote($sitePrefix, '/') . '\\//', '', $pageUrl);
}
if (preg_match('/\\/$/', $pageUrl)) {
$pageUrl .= 'index';
}
$pageUrl = preg_replace('/\\.html$/', '', $pageUrl);
$pageUrl = preg_replace('/^\\//', '', $pageUrl);
$aryUrl = explode('/', $pageUrl);
} else {
// プラグインルーティングの場合
if (($url1 == '' && in_array($action, array('index', 'mobile_index', 'smartphone_index')) || $url1 == $action) && $url2 != $action && $plugin) {
$prefix = '';
$plugin = '';
$controller = $url0;
}
if ($plugin) {
$controller = $plugin . '_' . $controller;
}
if ($prefix) {
$controller = $prefix . '_' . $controller;
}
if ($controller) {
$aryUrl[] = $controller;
}
if ($action) {
$aryUrl[] = $action;
}
if ($pass) {
$aryUrl = array_merge($aryUrl, $pass);
}
}
if ($this->_View->name == 'CakeError') {
$contentsName = $error;
} elseif (count($aryUrl) >= 2) {
if (!$detail) {
$contentsName = $aryUrl[0];
} else {
$contentsName = implode('_', $aryUrl);
}
} elseif (count($aryUrl) == 1 && $aryUrl[0] == 'index') {
$contentsName = $home;
} else {
if (!$detail) {
$contentsName = $default;
} else {
$contentsName = $aryUrl[0];
}
}
if ($underscore) {
$contentsName = Inflector::underscore($contentsName);
} else {
$contentsName = Inflector::camelize($contentsName);
}
return $contentsName;
}