1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Donatas Navidonskis <[email protected]> |
5
|
|
|
* @since 2017 |
6
|
|
|
* @class BaseBlock |
7
|
|
|
* |
8
|
|
|
* @property string Title |
9
|
|
|
* @property string Content |
10
|
|
|
* @property string BlockArea |
11
|
|
|
* @property string CanViewType |
12
|
|
|
* @property string ExtraCSSClasses |
13
|
|
|
* @property int Weight |
14
|
|
|
* @property string Area |
15
|
|
|
* @property boolean Published |
16
|
|
|
*/ |
17
|
|
|
class BaseBlock extends \ContentBlock { |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Default directory to upload your files. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
* @config |
24
|
|
|
*/ |
25
|
|
|
protected static $upload_directory = 'Uploads/ContentBlocks'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Include default styles (css) at frontend side? |
29
|
|
|
* |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
private static $default_styles = true; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Re-add (un)publish images. |
36
|
|
|
* |
37
|
|
|
* @return HTMLText |
38
|
|
|
*/ |
39
|
|
|
public function isPublishedIcon() { |
40
|
|
|
$content = HTMLText::create(); |
41
|
|
|
$images = [ |
42
|
|
|
0 => sprintf('%s/assets/images/cancel.png', CONTENT_BLOCKS_DIR), |
43
|
|
|
1 => sprintf('%s/assets/images/success.png', CONTENT_BLOCKS_DIR), |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$content->setValue(sprintf('<img src="%s" />', $images[(int) $this->isPublished()])); |
47
|
|
|
|
48
|
|
|
return $content; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Renders this block with appropriate templates |
53
|
|
|
* looks for templates that match BlockClassName_AreaName |
54
|
|
|
* falls back to BlockClassName. |
55
|
|
|
* |
56
|
|
|
* Updates: if function will find the template at blocks/ directory, |
57
|
|
|
* this will also render it. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
**/ |
61
|
|
|
public function forTemplate() { |
62
|
|
|
if (static::config()->default_styles) { |
63
|
|
|
\Requirements::css(sprintf('%s/assets/styles/app.css', CONTENT_BLOCKS_DIR)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($this->BlockArea) { |
67
|
|
|
$template = [$this->class.'_'.$this->BlockArea]; |
68
|
|
|
|
69
|
|
|
if (\SSViewer::hasTemplate($template)) { |
70
|
|
|
return $this->renderWith($template); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (\SSViewer::hasTemplate($path = "blocks/{$this->ClassName}")) { |
75
|
|
|
return $this->renderWith($path, $this->getController()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->renderWith($this->ClassName, $this->getController()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return bool|string |
83
|
|
|
*/ |
84
|
|
|
public function Link() { |
85
|
|
|
if ($page = $this->getCurrentPage()) { |
86
|
|
|
return $page->Link(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getUploadDirectory() { |
96
|
|
|
return static::config()->upload_directory; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getBlockName() { |
103
|
|
|
return strtolower(str_replace(' ', '-', \FormField::name_to_label($this->ClassName))); |
104
|
|
|
} |
105
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.