-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.php
executable file
·158 lines (139 loc) · 4.03 KB
/
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
151
152
153
154
155
156
157
158
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Videos Plugin
*
* Create lists of posts
*
* @package PyroCMS
* @author PyroCMS Dev Team
* @copyright Copyright (c) 2008 - 2011, PyroCMS
*
*/
class Plugin_Videos extends Plugin
{
/**
* Blog List
*
* Creates a list of blog posts
*
* Usage:
* {pyro:videos:videos order-by="title" limit="5"}
* <h2>{pyro:title}</h2>
* {pyro:embed_code}
* {/pyro:videos:videos}
*
* @param array
* @return array
*/
public function videos()
{
$limit = $this->attribute('limit', 10);
$channel = $this->attribute('channel');
$order_by = $this->attribute('order-by', 'created_on');
$order_dir = $this->attribute('order-dir', 'ASC');
if ($channel)
{
$this->db->where('video_channels.' . (is_numeric($channel) ? 'id' : 'slug'), $channel);
}
return $foo = $this->db
->select('videos.*, video_channels.title as channel_title, video_channels.slug as channel_slug')
->where('schedule_on <=', now())
->join('video_channels', 'videos.channel_id = video_channels.id', 'LEFT')
->order_by('videos.' . $order_by, $order_dir)
->limit($limit)
->get('videos')
->result();
var_dump($foo);
}
/**
* Featured List
*
* Creates a list of blog posts
*
* Usage:
* {pyro:videos:featured limit="2"}
* <h2>{pyro:title}</h2>
* {pyro:embed_code}
* {/pyro:videos:featured}
*
* @param array
* @return array
*/
public function featured()
{
$width = $this->attribute('width');
$limit = $this->attribute('limit', 1);
$order_by = $this->attribute('order-by', 'featured_on');
$order_dir = $this->attribute('order-dir', 'DESC');
$videos = $this->db
->select('videos.*, video_channels.title as channel_title, video_channels.slug as channel_slug')
->where('schedule_on <=', now())
->where('featured_on > 0')
->join('video_channels', 'videos.channel_id = video_channels.id', 'LEFT')
->order_by('videos.' . $order_by, $order_dir)
->limit($limit)
->get('videos')
->result();
$html = '';
foreach ($videos as &$video)
{
// Custom width detected, lets do some awkward shit
if ($width)
{
$ratio = $width / $video->width;
$new_width = round($width);
$new_height = round($video->height * $ratio);
$video->embed_code = str_replace(array(
'width="'.$video->width.'"',
'height="'.$video->height.'"',
'width:'.$video->width.'px',
'height:'.$video->height.'px',
), array(
'width="'.$new_width.'"',
'height="'.$new_height.'"',
'width:'.$new_width.'px',
'height:"'.$new_height.'px',
), $video->embed_code);
}
// Single tag? Build up HTML
$this->content() or $html .= $video->embed_code;
}
return $this->content() ? $videos : $html;
}
/**
* Channel List
*
* Creates a list of channels
*
* Usage:
* {pyro:videos:channels order-by="title" limit="5" include-count="yes"}
* <h2>{pyro:title}</h2>
* There are {pyro:video_count} video(s) in this channel
* {/pyro:videos:channels}
*
* @param array
* @return array
*/
public function channels()
{
$limit = $this->attribute('limit');
$order_by = $this->attribute('order-by', 'created_on');
$order_dir = $this->attribute('order-dir', 'ASC');
$include_count = (bool) in_array(strtolower($this->attribute('include-count')), array('y', 'yes', 'true'));
$this->db
->select('video_channels.id, video_channels.title, video_channels.slug, video_channels.description, video_channels.thumbnail')
->select('pvc.id as parent_id, pvc.title as parent_title, pvc.slug as parent_slug');
if ($include_count)
{
$this->db->select('(SELECT count(id) FROM '.$this->db->dbprefix('videos').' v WHERE '.$this->db->dbprefix('video_channels').'.id = v.channel_id) as video_count ', FALSE);
$this->db->having('video_count > 0');
}
$limit && $this->db->limit($limit);
return $this->db
->order_by($order_by, $order_dir)
->join('video_channels pvc', 'pvc.id = video_channels.parent_id', 'left')
->get('video_channels')
->result_array();
}
}
/* End of file plugin.php */