-
Notifications
You must be signed in to change notification settings - Fork 1
/
AttachmentModule.php
97 lines (82 loc) · 2.47 KB
/
AttachmentModule.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
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2011, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* Attachment module for the OntoWiki files extension
*
* @category OntoWiki
* @package OntoWiki_extensions_files
* @author {@link http://sebastian.tramp.name Sebastian Tramp}
*/
class AttachmentModule extends OntoWiki_Module
{
/*
* An array of positive regexps to check the class URI of the resource
* (an empty array means, show always)
*/
private $_typeExpressions = array();
/**
* Constructor
*/
public function init()
{
$config = $this->_privateConfig;
if (isset($config->typeExpression)) {
$this->_typeExpressions = $config->typeExpression->toArray();
}
}
public function getTitle()
{
return "File Attachment";
}
public function shouldShow()
{
// show only if type matches
return $this->_checkClass();
}
public function getContents()
{
$selectedResource = $this->_owApp->selectedResource;
$data = array();
$data['file_uri'] = $selectedResource;
require_once('FilesController.php');
$pathHashed = FilesController::getFullPath($selectedResource);
if (is_readable($pathHashed)) {
$data['mimeType'] = FilesController::getMimeType($selectedResource);
return $this->render('files/moduleFile', $data);
} else {
return $this->render('files/moduleUpload', $data);
}
}
/*
* checks the resource types agains the configured patterns
*/
private function _checkClass()
{
$resource = $this->_owApp->selectedResource;
$rModel = $resource->getMemoryModel();
// no configured value means, show always
if (count($this->_typeExpressions) == 0) {
return true;
}
// search with each expression using the preg matchtype
foreach ($this->_typeExpressions as $typeExpression) {
if (
$rModel->hasSPvalue(
(string) $resource,
EF_RDF_TYPE,
$typeExpression,
'preg'
)
) {
return true;
}
}
// type does not match to one of the expressions
return false;
}
}