|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by: Jens |
|
4
|
|
|
* Date: 9-1-2018 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace CloudControl\Cms\util; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
use CloudControl\Cms\cc\Request; |
|
11
|
|
|
use CloudControl\Cms\components\cms\CmsConstants; |
|
12
|
|
|
|
|
13
|
|
|
class Cms |
|
14
|
|
|
{ |
|
15
|
|
|
public static $assetsIncluded = false; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Returns a button with a link for editing a document |
|
19
|
|
|
* @param $path |
|
20
|
|
|
* @return string |
|
21
|
|
|
* @throws \Exception |
|
22
|
|
|
*/ |
|
23
|
|
|
public static function editDocument($path) |
|
24
|
|
|
{ |
|
25
|
|
|
if (self::isLoggedIn()) { |
|
26
|
|
|
$return = self::getAssetsIfNotIncluded(); |
|
27
|
|
|
return $return . '<a title="Edit Document" data-href="' . self::editDocumentLink($path) . '" class="ccEditDocumentButton"></a>'; |
|
28
|
|
|
} else { |
|
29
|
|
|
return ''; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Returns the cms link for editing a document |
|
35
|
|
|
* @param $path |
|
36
|
|
|
* @return string |
|
37
|
|
|
* @throws \Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function editDocumentLink($path) |
|
40
|
|
|
{ |
|
41
|
|
|
if (self::isLoggedIn()) { |
|
42
|
|
|
$path = $path === '/' ? '/' : substr($path, 1); |
|
43
|
|
|
return Request::$subfolders . 'cms/documents/edit-document?slug=' . urlencode($path); |
|
44
|
|
|
} else { |
|
45
|
|
|
return ''; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns a button with a link for creating a new document |
|
51
|
|
|
* @param string $path |
|
52
|
|
|
* @param string $documentType |
|
53
|
|
|
* @return string |
|
54
|
|
|
* @throws \Exception |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function newDocument($path = '/', $documentType = '') |
|
57
|
|
|
{ |
|
58
|
|
|
if (self::isLoggedIn()) { |
|
59
|
|
|
$return = self::getAssetsIfNotIncluded(); |
|
60
|
|
|
return $return . '<a title="New Document" data-href="' . self::newDocumentLink($path, $documentType) . '" class="ccEditDocumentButton ccNewDocumentButton"></a>'; |
|
61
|
|
|
} else { |
|
62
|
|
|
return ''; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns the cms link for creating a new document |
|
68
|
|
|
* @param string $path |
|
69
|
|
|
* @param string $documentType |
|
70
|
|
|
* @return string |
|
71
|
|
|
* @throws \Exception |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function newDocumentLink($path = '/', $documentType = '') |
|
74
|
|
|
{ |
|
75
|
|
|
if (self::isLoggedIn()) { |
|
76
|
|
|
$path = $path === '/' ? '/' : substr($path, 1); |
|
77
|
|
|
$linkPostFix = ''; |
|
78
|
|
|
if ($documentType !== '') { |
|
79
|
|
|
$linkPostFix = '&documentType=' . $documentType; |
|
80
|
|
|
} |
|
81
|
|
|
return Request::$subfolders . 'cms/documents/new-document?path=' . urlencode($path) . $linkPostFix; |
|
82
|
|
|
} else { |
|
83
|
|
|
return ''; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* See if a user is logged or wants to log in and |
|
90
|
|
|
* takes appropriate actions. |
|
91
|
|
|
* |
|
92
|
|
|
* @throws \Exception |
|
93
|
|
|
*/ |
|
94
|
|
|
private |
|
95
|
|
|
static function isLoggedIn() |
|
96
|
|
|
{ |
|
97
|
|
|
return isset($_SESSION[CmsConstants::SESSION_PARAMETER_CLOUD_CONTROL]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
private |
|
101
|
|
|
static function getAssetsIfNotIncluded() |
|
102
|
|
|
{ |
|
103
|
|
|
if (!self::$assetsIncluded) { |
|
104
|
|
|
self::$assetsIncluded = true; |
|
105
|
|
|
return '<style> |
|
106
|
|
|
.ccEditDocumentButton{ |
|
107
|
|
|
opacity:0; |
|
108
|
|
|
-webkit-transition: opacity 0.5s;-moz-transition: opacity 0.5s;-ms-transition: opacity 0.5s;-o-transition: opacity 0.5s;transition: opacity 0.5s; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
.ccEditDocumentButton.active { |
|
112
|
|
|
display:block; |
|
113
|
|
|
position:absolute; |
|
114
|
|
|
line-height:50px; |
|
115
|
|
|
width:50px; |
|
116
|
|
|
height:50px; |
|
117
|
|
|
background: rgb(0, 106, 193) url("data:image/svg+xml;utf8,<svg width=\'25\' height=\'25\' viewBox=\'0 0 1792 1792\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'M491 1536l91-91-235-235-91 91v107h128v128h107zm523-928q0-22-22-22-10 0-17 7l-542 542q-7 7-7 17 0 22 22 22 10 0 17-7l542-542q7-7 7-17zm-54-192l416 416-832 832h-416v-416zm683 96q0 53-37 90l-166 166-416-416 166-165q36-38 90-38 53 0 91 38l235 234q37 39 37 91z\' fill=\'#fff\'/></svg>") no-repeat center; |
|
118
|
|
|
border-radius:50%; |
|
119
|
|
|
color:#fff; |
|
120
|
|
|
font-family:Arial, sans-serif; |
|
121
|
|
|
text-align:center; |
|
122
|
|
|
cursor:pointer; |
|
123
|
|
|
box-shadow: 5px 5px 5px rgba(128, 128, 128, 0.5); |
|
124
|
|
|
z-index:255; |
|
125
|
|
|
opacity:0.7; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) { |
|
129
|
|
|
/* IE10+ CSS styles go here */ |
|
130
|
|
|
.ccEditDocumentButton.active:before { |
|
131
|
|
|
content:\'edit\'; |
|
132
|
|
|
font-family:Arial, sans-serif; |
|
133
|
|
|
font-size:12px; |
|
134
|
|
|
line-height:50px; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
.ccEditDocumentButton.active:hover { |
|
139
|
|
|
color:rgb(0, 106, 193); |
|
140
|
|
|
background: #fff url("data:image/svg+xml;utf8,<svg width=\'25\' height=\'25\' viewBox=\'0 0 1792 1792\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'M491 1536l91-91-235-235-91 91v107h128v128h107zm523-928q0-22-22-22-10 0-17 7l-542 542q-7 7-7 17 0 22 22 22 10 0 17-7l542-542q7-7 7-17zm-54-192l416 416-832 832h-416v-416zm683 96q0 53-37 90l-166 166-416-416 166-165q36-38 90-38 53 0 91 38l235 234q37 39 37 91z\' fill=\'#006AC1\'/></svg>") no-repeat center; |
|
141
|
|
|
opacity:1; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
.ccEditDocumentButton.active.ccNewDocumentButton { |
|
145
|
|
|
background-image:none; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
.ccEditDocumentButton.active.ccNewDocumentButton:before { |
|
149
|
|
|
content:\'+\'; |
|
150
|
|
|
font-family:Arial, sans-serif; |
|
151
|
|
|
font-size:20px; |
|
152
|
|
|
line-height:50px; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
.ccDocumentEditorHidden { |
|
156
|
|
|
transform: translateX(100%); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
@keyframes slideInFromRight { |
|
160
|
|
|
0% { |
|
161
|
|
|
transform: translateX(100%); |
|
162
|
|
|
} |
|
163
|
|
|
100% { |
|
164
|
|
|
transform: translateX(0); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
@keyframes slideOutToRight { |
|
169
|
|
|
0% { |
|
170
|
|
|
transform: translateX(0); |
|
171
|
|
|
} |
|
172
|
|
|
100% { |
|
173
|
|
|
transform: translateX(100%); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
</style>' . |
|
177
|
|
|
'<script src="' . Request::$subfolders . 'js/cms.js"></script>'; |
|
178
|
|
|
} |
|
179
|
|
|
return ''; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
|