This repository has been archived by the owner on Mar 30, 2019. It is now read-only.
/
feed.php
218 lines (196 loc) · 5.23 KB
/
feed.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Podcast Manager for Joomla!
*
* @package PodcastManager
* @subpackage com_podcastmanager
*
* @copyright Copyright (C) 2011-2013 Michael Babker. All rights reserved.
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
*
* Podcast Manager is based upon the ideas found in Podcast Suite created by Joe LeBlanc
* Original copyright (c) 2005 - 2008 Joseph L. LeBlanc and released under the GPLv2 license
*/
defined('_JEXEC') or die;
jimport('joomla.application.component.modeladmin');
/**
* Feed edit model class.
*
* @package PodcastManager
* @subpackage com_podcastmanager
* @since 1.7
*/
class PodcastManagerModelFeed extends JModelAdmin
{
/**
* The prefix to use with controller messages.
*
* @var string
* @since 1.7
*/
protected $text_prefix = 'COM_PODCASTMANAGER';
/**
* Model context string.
*
* @var string
* @since 1.7
*/
protected $context = 'com_podcastmanager.feed';
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to delete the record. Defaults to the permission for the component.
*
* @since 2.0
*/
protected function canDelete($record)
{
if (!empty($record->id))
{
if ($record->published == -2)
{
$user = JFactory::getUser();
return $user->authorise('core.delete', 'com_podcastmanager.feed.' . (int) $record->id);
}
}
}
/**
* Method to test whether a record's state can be modified.
*
* @param object $record A record object.
*
* @return boolean True if allowed to change the state of the record. Defaults to the permission for the component.
*
* @since 2.0
*/
protected function canEditState($record)
{
$user = JFactory::getUser();
// Check for existing feed.
if (!empty($record->id))
{
return $user->authorise('core.edit.state', 'com_podcastmanager.feed.' . (int) $record->id);
}
// Default to component settings if no feed to check.
else
{
return $user->authorise('core.edit.state', 'com_podcastmanager');
}
}
/**
* Custom clean cache method
*
* @param string $group The component name
* @param integer $client_id The client ID
*
* @return void
*
* @since 1.7
*/
protected function cleanCache($group = 'com_podcastmanager', $client_id = 1)
{
parent::cleanCache($group, $client_id);
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return JForm A JForm object on success, false on failure
*
* @since 1.7
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_podcastmanager.feed', 'feed', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
// Modify the form based on access controls.
if (!$this->canEditState((object) $data))
{
// Disable fields for display.
$form->setFieldAttribute('publish_up', 'disabled', 'true');
$form->setFieldAttribute('published', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('publish_up', 'filter', 'unset');
$form->setFieldAttribute('published', 'filter', 'unset');
}
// Add tags for CMS 3.1 and later
if (version_compare(JVERSION, '3.1', 'ge'))
{
$form->setField(
new SimpleXMLElement('<field name="tags" type="tag" label="JTAG" description="JTAG_DESC" class="inputbox" multiple="true" />')
);
}
return $form;
}
/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
*
* @since 2.1
*/
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
// Convert the metadata field to an array.
$registry = new JRegistry;
$registry->loadString($item->metadata);
$item->metadata = $registry->toArray();
// Tags support in CMS 3.1+
if (version_compare(JVERSION, '3.1', 'ge'))
{
if (!empty($item->id))
{
$item->tags = new JHelperTags;
$item->tags->getTagIds($item->id, 'com_podcastmanager.feed');
$item->metadata['tags'] = $item->tags;
}
}
}
return $item;
}
/**
* Returns a JTable object, always creating it
*
* @param string $type The table type to instantiate
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return JTable A database object
*
* @since 1.7
*/
public function getTable($type = 'Feed', $prefix = 'PodcastManagerTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
*
* @since 1.7
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_podcastmanager.edit.feed.data', array());
if (empty($data))
{
$data = $this->getItem();
}
return $data;
}
}