2010-08-01 06:46:32 +02:00
|
|
|
<?php
|
2010-10-21 22:27:23 +02:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
/**
|
2010-12-21 10:42:44 +01:00
|
|
|
* A specific page within a {@link DocumentationEntity}. Maps 1 to 1 to a file on the
|
|
|
|
* filesystem.
|
2010-08-01 06:46:32 +02:00
|
|
|
*
|
|
|
|
* @package sapphiredocs
|
|
|
|
*/
|
|
|
|
class DocumentationPage extends ViewableData {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var DocumentationEntity
|
|
|
|
*/
|
|
|
|
protected $entity;
|
|
|
|
|
|
|
|
/**
|
2010-12-22 09:21:49 +01:00
|
|
|
* Stores the relative path (from the {@link DocumentationEntity} to
|
|
|
|
* this page. The actual file name can be accessed via {@link $this->getFilename()}
|
|
|
|
*
|
2010-08-01 06:46:32 +02:00
|
|
|
* @var String
|
|
|
|
*/
|
|
|
|
protected $relativePath;
|
|
|
|
|
2010-10-21 22:27:23 +02:00
|
|
|
/**
|
|
|
|
* @var String
|
|
|
|
*/
|
2010-08-01 06:46:32 +02:00
|
|
|
protected $lang = 'en';
|
|
|
|
|
2010-12-21 10:42:44 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $title;
|
|
|
|
|
2010-10-21 22:27:23 +02:00
|
|
|
/**
|
|
|
|
* @var String
|
|
|
|
*/
|
2010-08-01 06:46:32 +02:00
|
|
|
protected $version;
|
|
|
|
|
2010-12-21 10:42:44 +01:00
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
/**
|
|
|
|
* @return DocumentationEntity
|
|
|
|
*/
|
|
|
|
function getEntity() {
|
|
|
|
return $this->entity;
|
|
|
|
}
|
2010-10-21 22:27:23 +02:00
|
|
|
|
2010-12-21 10:42:44 +01:00
|
|
|
/**
|
|
|
|
* @param DocumentationEntity
|
|
|
|
*/
|
2010-10-21 22:27:23 +02:00
|
|
|
function setEntity($entity) {
|
|
|
|
$this->entity = $entity;
|
|
|
|
}
|
2010-08-01 06:46:32 +02:00
|
|
|
|
|
|
|
/**
|
2010-12-21 10:42:44 +01:00
|
|
|
* @return string
|
2010-08-01 06:46:32 +02:00
|
|
|
*/
|
|
|
|
function getRelativePath() {
|
|
|
|
return $this->relativePath;
|
|
|
|
}
|
|
|
|
|
2010-12-21 10:42:44 +01:00
|
|
|
/**
|
|
|
|
* @param string
|
|
|
|
*/
|
2010-10-21 22:27:23 +02:00
|
|
|
function setRelativePath($path) {
|
|
|
|
$this->relativePath = $path;
|
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
/**
|
|
|
|
* Absolute path including version and lang folder.
|
|
|
|
*
|
2010-12-21 10:42:44 +01:00
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*
|
2010-12-21 11:54:11 +01:00
|
|
|
* @param bool $defaultFile - If this is a folder and this is set to true then getPath
|
|
|
|
* will return the path of the first file in the folder
|
2010-12-21 10:42:44 +01:00
|
|
|
* @return string
|
2010-08-01 06:46:32 +02:00
|
|
|
*/
|
2010-12-21 11:54:11 +01:00
|
|
|
function getPath($defaultFile = false) {
|
2010-12-22 09:21:49 +01:00
|
|
|
if($this->entity) {
|
|
|
|
$path = rtrim($this->entity->getPath($this->version, $this->lang), '/') . '/' . trim($this->getRelativePath(), '/');
|
|
|
|
|
|
|
|
if(!is_dir($path)) $path = realpath($path);
|
|
|
|
else if($defaultFile) {
|
|
|
|
$file = DocumentationService::find_page($this->entity, explode('/', $this->getRelativePath()));
|
2010-12-21 11:54:11 +01:00
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
if($file) $path = $file;
|
2010-12-21 10:42:44 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-22 09:21:49 +01:00
|
|
|
else {
|
|
|
|
$path = $this->getRelativePath();
|
|
|
|
}
|
2010-12-21 11:54:11 +01:00
|
|
|
|
|
|
|
if(!file_exists($path)) {
|
|
|
|
throw new InvalidArgumentException(sprintf(
|
|
|
|
'Path could not be found. Module path: %s, file path: %s',
|
|
|
|
$this->entity->getPath(),
|
2010-12-22 09:21:49 +01:00
|
|
|
$this->getRelativePath()
|
2010-12-21 11:54:11 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
|
|
|
|
return (is_dir($path)) ? rtrim($path, '/') . '/' : $path;
|
2010-12-21 11:54:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-22 09:21:49 +01:00
|
|
|
* Returns the link for the web browser
|
2010-12-21 11:54:11 +01:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2010-12-22 09:21:49 +01:00
|
|
|
function Link() {
|
|
|
|
if($entity = $this->getEntity()) {
|
2011-01-13 09:27:25 +01:00
|
|
|
$link = Controller::join_links($entity->Link($this->version, $this->lang), $this->getRelativeLink());
|
2010-12-22 09:21:49 +01:00
|
|
|
|
|
|
|
$link = rtrim(DocumentationService::trim_extension_off($link), '/');
|
|
|
|
|
|
|
|
// folders should have a / on them. Looks nicer
|
|
|
|
try {
|
|
|
|
if(is_dir($this->getPath())) $link .= '/';
|
|
|
|
}
|
|
|
|
catch (Exception $e) {}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$link = $this->getPath(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
2010-12-21 10:42:44 +01:00
|
|
|
}
|
|
|
|
|
2011-01-13 09:27:25 +01:00
|
|
|
/**
|
|
|
|
* Relative to the module base, not the webroot
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getRelativeLink() {
|
|
|
|
$link = rtrim(DocumentationService::trim_extension_off($this->getRelativePath()), '/');
|
|
|
|
|
|
|
|
// folders should have a / on them. Looks nicer
|
|
|
|
try {
|
|
|
|
if(is_dir($this->getPath())) $link .= '/';
|
|
|
|
} catch (Exception $e) {};
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2010-12-21 10:42:44 +01:00
|
|
|
function setFullPath($path) {
|
|
|
|
$this->fullPath = $path;
|
|
|
|
}
|
2010-08-01 06:46:32 +02:00
|
|
|
|
|
|
|
function getLang() {
|
|
|
|
return $this->lang;
|
|
|
|
}
|
|
|
|
|
2010-10-21 22:27:23 +02:00
|
|
|
function setLang($lang) {
|
|
|
|
$this->lang = $lang;
|
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
function getVersion() {
|
|
|
|
return $this->version;
|
|
|
|
}
|
2010-10-21 22:27:23 +02:00
|
|
|
|
|
|
|
function setVersion($version) {
|
|
|
|
$this->version = $version;
|
|
|
|
}
|
2010-12-21 10:42:44 +01:00
|
|
|
|
|
|
|
function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTitle() {
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
2010-12-21 11:54:11 +01:00
|
|
|
/**
|
2010-12-22 09:21:49 +01:00
|
|
|
* @return string
|
2010-12-21 11:54:11 +01:00
|
|
|
*/
|
2010-12-22 09:21:49 +01:00
|
|
|
function getFilename() {
|
|
|
|
$path = rtrim($this->relativePath, '/');
|
|
|
|
|
|
|
|
try {
|
|
|
|
return (is_dir($this->getPath())) ? $path . '/' : $path;
|
|
|
|
}
|
|
|
|
catch (Exception $e) {}
|
|
|
|
|
|
|
|
return $path;
|
2010-12-21 11:54:11 +01:00
|
|
|
}
|
|
|
|
|
2010-08-01 06:46:32 +02:00
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
function getMarkdown() {
|
2010-10-22 03:08:44 +02:00
|
|
|
try {
|
2010-12-21 11:54:11 +01:00
|
|
|
$path = $this->getPath(true);
|
|
|
|
|
|
|
|
if($path) {
|
|
|
|
return file_get_contents($path);
|
|
|
|
}
|
2010-10-22 03:08:44 +02:00
|
|
|
}
|
|
|
|
catch(InvalidArgumentException $e) {}
|
|
|
|
|
|
|
|
return null;
|
2010-08-01 06:46:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $baselink
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
function getHTML($baselink = null) {
|
2010-12-21 10:42:44 +01:00
|
|
|
// if this is not a directory then we can to parse the file
|
2010-12-21 11:54:11 +01:00
|
|
|
return DocumentationParser::parse($this->getPath(true), $baselink);
|
2010-08-01 06:46:32 +02:00
|
|
|
}
|
|
|
|
}
|