forked from dojoVader-dev/Diary
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Helper.php
executable file
·142 lines (131 loc) · 4.14 KB
/
Helper.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace Plugin\Diary;
use Plugin\Diary\Forms\CategoryForm as CategoryForm;
use Plugin\Diary\Forms\NoteForm;
use Plugin\Diary\Forms\CommentForm;
use Plugin\Diary\Forms\UploadForm;
class Helper {
/**
* Retrieves the name of the Admin currently logged in
*
* @author dojoVader
* @param
* none
* @return String name of author or null
*/
static public function getAuthor() {
// Get the Admin ID currently logged in
$id = ipAdminId ();
$username = ipDb ()->selectRow ( 'administrator', 'username', array (
'id' => $id
) );
if ($username) {
return $username ['username'];
} else {
return null;
}
}
static public function getList($limit) {
$sql = sprintf ( "select * from %s LIMIT %d", ipTable ( "diary_blog" ), $limit );
return ipDb ()->fetchAll ( $sql );
}
static public function getArticleById($id) {
try{
$sqlFormat="select ip_diary_blog.author,ip_diary_blog.date,ip_diary_blog.content,
ip_diary_blog.id,title,ip_diary_blog.status,ip_diary_blog.modified,ip_diary_blog.category_id,dc.id as dcid ,dc.name
from ip_diary_blog INNER JOIN ip_diary_category dc ON ip_diary_blog.category_id=dc.id WHERE ip_diary_blog.id=:blog_id";
if (! is_int ( $id )) {
throw new \Ip\Exception\Plugin ( "Wrong Format passed in Diary Plugin in " . __CLASS__ );
}
//Bind the Value to the Statement
$query=ipDb()->getConnection()->prepare($sqlFormat);
$query->bindValue(":blog_id",$id,\PDO::PARAM_INT);
$query->execute();
$result = $query->fetch(\PDO::FETCH_ASSOC);
return $result ? $result : array();
}
catch (\PDOException $e) {
throw new \Ip\Exception\Db($e->getMessage(), $e->getCode(), $e);
}
}
static public function getArticleByAlias($string) {
try{
$sqlFormat="select ip_diary_blog.author,ip_diary_blog.id,ip_diary_blog.date,ip_diary_blog.content,
ip_diary_blog.id,title,ip_diary_blog.status,ip_diary_blog.modified,ip_diary_blog.category_id,dc.id as dcid ,dc.name
from ip_diary_blog INNER JOIN ip_diary_category dc ON ip_diary_blog.category_id=dc.id WHERE ip_diary_blog.alias=:alias";
if (is_int ( $string )) {
throw new \Ip\Exception\Plugin ( "Wrong Format passed in Diary Plugin in " . __CLASS__ );
}
//Bind the Value to the Statement
$query=ipDb()->getConnection()->prepare($sqlFormat);
$query->bindValue(":alias",$string,\PDO::PARAM_STR);
$query->execute();
$result = $query->fetch(\PDO::FETCH_ASSOC);
return $result ? $result : array();
}
catch (\PDOException $e) {
throw new \Ip\Exception\Db($e->getMessage(), $e->getCode(), $e);
}
}
static public function getCategoryForm() {
$category = new CategoryForm ();
return $category->getForm ();
}
static public function getCommentForm(){
$commentForm=new CommentForm();
return $commentForm->getForm();
}
static public function getUploadForm(){
$uploadForm=new UploadForm();
return $uploadForm->getForm();
}
static public function getNoteForm() {
$note = new NoteForm ();
return $note->getForm ();
}
static public function getEditMenu() {
$page1 = new \Ip\Menu\Item ();
$page1->setTitle ( 'Create Category' );
$page1->setUrl ( ipActionUrl ( array (
"aa" => "Diary.createCategory"
) ) );
$page2 = new \Ip\Menu\Item ();
$page2->setTitle ( 'Manage Category' );
$page2->setUrl ( ipActionUrl ( array (
"aa" => "Diary.manageCategory"
) ) );
$options = array (
'items' => array (
$page1,
$page2
), // menu to be displayed
'attributes' => array (
'id' => 'ipsTest'
)
);
return ipSlot ( 'menu', $options );
}
static public function DeleteNote($id) {
return ipDb ()->delete ( "diary_blog", array (
"id" => $id
) );
}
/**
* Sets the Url for the Diary Page
* @param Array $query
* @return string
*/
static function setDiaryUrl($query){
return ipConfig()->baseUrl().ipContent()->getCurrentPage()->getUrlPath().'?'.http_build_query($query);
}
static function getContent($content,$data){
$string=explode("<!--more-->",$content);
if($string === FALSE){
return $content;
}
else{
return sprintf("%s<br/><a href='%s'>Read More</a>",$string[0],ipRouteUrl("article",array("articleName"=>$data['alias'])));
}
}
}
?>