forked from AKSW/files.ontowiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttachmentModule.php
106 lines (90 loc) · 2.79 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
96
97
98
99
100
101
102
103
104
<?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
{
/*
* The module has two options:
* 1. Enable the module according to the type of the selected resource or
* 2. Enable the module without checking types (default)
*/
private $_types = array();
private $_useWithoutTypeCheck = true;
/**
* Constructor
*/
public function init()
{
$config = $this->_privateConfig;
if (isset($config->useModuleWithoutTypeCheck)) {
$this->_useWithoutTypeCheck = (boolean)$config->useModuleWithoutTypeCheck;
}
if ($this->_useWithoutTypeCheck === false && isset($config->enableForTypes)) {
$this->_types = $config->enableForTypes->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();
if ($this->_useWithoutTypeCheck === true) {
return true;
}
// search with each expression using the preg matchtype
foreach ($this->_types as $type) {
if (isset($type['classUri'])) {
$classUri = $type['classUri'];
} else {
continue;
}
if (
$rModel->hasSPvalue(
(string) $resource,
EF_RDF_TYPE,
$classUri
)
) {
return true;
}
}
// type does not match to one of the expressions
return false;
}
}