1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @deprecated since version 2.0 |
5
|
|
|
* |
6
|
|
|
* @property int $ParentID |
7
|
|
|
* @property string $Date |
8
|
|
|
* @property string $PublishDate |
9
|
|
|
* @property string $Tags |
10
|
|
|
*/ |
11
|
|
|
class BlogEntry extends BlogPost implements MigratableObject |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private static $hide_ancestor = 'BlogEntry'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
private static $db = array( |
|
|
|
|
22
|
|
|
'Date' => 'SS_Datetime', |
23
|
|
|
'Author' => 'Text', |
24
|
|
|
'Tags' => 'Text', |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function canCreate($member = null) |
31
|
|
|
{ |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function up() |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
//Migrate comma separated tags into BlogTag objects. |
42
|
|
|
foreach ($this->TagNames() as $tag) { |
|
|
|
|
43
|
|
|
$existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID)); |
44
|
|
|
if ($existingTag->count()) { |
45
|
|
|
//if tag already exists we will simply add it to this post. |
46
|
|
|
$tagObject = $existingTag->First(); |
47
|
|
|
} else { |
48
|
|
|
|
49
|
|
|
//if the tag is now we create it and add it to this post. |
50
|
|
|
$tagObject = new BlogTag(); |
51
|
|
|
$tagObject->Title = $tag; |
52
|
|
|
$tagObject->BlogID = $this->ParentID; |
53
|
|
|
$tagObject->write(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if ($tagObject) { |
57
|
|
|
$this->Tags()->add($tagObject); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
//Store if the original entity was published or not (draft) |
62
|
|
|
$published = $this->IsPublished(); |
63
|
|
|
// If a user has subclassed BlogEntry, it should not be turned into a BlogPost. |
64
|
|
|
if ($this->ClassName === 'BlogEntry') { |
65
|
|
|
$this->ClassName = 'BlogPost'; |
66
|
|
|
$this->RecordClassName = 'BlogPost'; |
67
|
|
|
} |
68
|
|
|
//Migrate these key data attributes |
69
|
|
|
$this->PublishDate = $this->Date; |
70
|
|
|
$this->AuthorNames = $this->Author; |
71
|
|
|
$this->InheritSideBar = true; |
72
|
|
|
|
73
|
|
|
//Write and additionally publish the item if it was published before. |
74
|
|
|
$this->write(); |
75
|
|
|
if ($published) { |
76
|
|
|
$this->publish('Stage', 'Live'); |
77
|
|
|
$message = "PUBLISHED: "; |
78
|
|
|
} else { |
79
|
|
|
$message = "DRAFT: "; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $message . $this->Title; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Safely split and parse all distinct tags assigned to this BlogEntry. |
87
|
|
|
* |
88
|
|
|
* @deprecated since version 2.0 |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function TagNames() |
93
|
|
|
{ |
94
|
|
|
$tags = preg_split('/\s*,\s*/', trim($this->Tags)); |
95
|
|
|
|
96
|
|
|
$results = array(); |
97
|
|
|
|
98
|
|
|
foreach ($tags as $tag) { |
99
|
|
|
if ($tag) { |
100
|
|
|
$results[mb_strtolower($tag)] = $tag; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $results; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @deprecated since version 2.0 |
110
|
|
|
*/ |
111
|
|
|
class BlogEntry_Controller extends BlogPost_Controller |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
} |
114
|
|
|
|
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.