This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
/
events.plugin.php
150 lines (130 loc) · 3.83 KB
/
events.plugin.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
143
144
145
146
147
148
149
150
<?php
// let only monstra allow to use this script
defined('MONSTRA_ACCESS') or die('No direct script access.');
/**
* Events plugin
*
* Provides CRUD for events and different output possibilities for event lists
*
* @package Monstra
* @subpackage Plugins
* @author Andreas Müller | devmount <mail@devmount.de>
* @license MIT
* @version 0.1.2016-01-02
* @link https://github.com/devmount-monstra/events
*
*/
// Register plugin
Plugin::register(
__FILE__,
__('Events'),
__('Event management for Monstra.'),
'0.1.2016-01-02',
'devmount',
'http://devmount.de'
);
// Include plugin admin
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) {
Plugin::Admin('events');
}
// Add shortcode
Shortcode::add('events', 'Events::_shortcode');
// Add CSS and JavaScript
Action::add('theme_footer', 'Events::_insertJS');
Action::add('theme_header', 'Events::_insertCSS');
// register repository classes
require_once 'repositories/repository.events.php';
require_once 'repositories/repository.categories.php';
require_once 'repositories/repository.locations.php';
/**
* Events class
*
* <code>
* <?php Events::listEvents('list', 'minimal', 'future', 5, 'ASC'); ?>
* </code>
*
*/
class Events
{
/**
* Creates shortcodes for content pages
*
* <code>
* {events type="list" style="minimal" time="future" count="5" order="ASC"}
* </code>
*
* @param array $attributes given
* @return void generated content
*
*/
public static function _shortcode($attributes)
{
switch ($attributes['type']) {
case 'list':
return Events::listEvents($attributes['style'], $attributes['time'], $attributes['count'], $attributes['order']);
break;
default:
return Events::error();
break;
}
return Events::error();
}
/**
* _insertJS function
*
* @return JavaScript to insert
*
*/
public static function _insertJS()
{
echo '';
}
/**
* _insertCSS function
*
* @return JavaScript to insert
*
*/
public static function _insertCSS()
{
echo '<link rel="stylesheet" type="text/css" href="' . Option::get('siteurl') . '/plugins/events/css/events.plugin.css" />';
echo '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">';
}
/**
* list events
*
* @param string $style ['extended', 'minimal', 'archive']
* @param string $time ['future', 'past', 'all']
* @param string $count number of records to show [number or 'all']
* @param string $order ['ASC', 'DESC']
*
* @return array
*
*/
public function listEvents($style, $time = 'all', $count = 'all', $order = 'ASC')
{
// load template according to given style
$template = '';
$style = trim($style);
if (in_array($style, array('extended', 'minimal', 'archive'))) {
$template = 'list-' . $style;
$groupby = $style == 'archive' ? 'year' : '';
$is_archive = $style == 'archive';
} else {
$template = 'list-minimal';
}
return View::factory('events/views/frontend/' . $template)
->assign('eventlist', EventsRepository::getList($time, $count, $order, $groupby, $is_archive))
->assign('categories', CategoriesRepository::getAll())
->assign('locations', LocationsRepository::getAll())
->assign('imagepath', 'public/uploads/' . Option::get('events_image_directory') . '/')
->render();
}
/**
* error occurance
*/
public function error()
{
return 'error occured';
}
}