Cheetah
ChWsbTextData.php
Go to the documentation of this file.
1 <?php
2 
8 define('CH_TD_VIEWER_TYPE_VISITOR', 0);
9 define('CH_TD_VIEWER_TYPE_MEMBER', 1);
10 define('CH_TD_VIEWER_TYPE_ADMIN', 2);
11 
12 define('CH_TD_STATUS_ACTIVE', 0);
13 define('CH_TD_STATUS_INACTIVE', 1);
14 define('CH_TD_STATUS_PENDING', 2);
15 
16 ch_import('ChWsbForm');
17 ch_import('ChWsbPrivacy');
18 ch_import('ChWsbCategories');
19 ch_import('ChTemplFormView');
20 ch_import('ChWsbCategories');
21 
23 {
24  var $_oModule;
25  var $_aForm;
28 
29  function __construct(&$oModule)
30  {
31  $this->_oModule = $oModule;
32 
33  $this->_iOwnerId = ChWsbTextData::getAuthorId();
34  $oCategories = new ChWsbCategories();
35  $oCategories->getTagObjectConfig();
36 
37  $this->_aForm = array(
38  'form_attrs' => array(
39  'id' => 'text_data',
40  'name' => 'text_data',
41  'action' => ch_html_attribute($_SERVER['PHP_SELF']),
42  'method' => 'post',
43  'enctype' => 'multipart/form-data'
44  ),
45  'params' => array (
46  'db' => array(
47  'table' => '',
48  'key' => 'id',
49  'uri' => 'uri',
50  'uri_title' => 'caption',
51  'submit_name' => 'post'
52  ),
53  ),
54  'inputs' => array (
55  'author_id' => array(
56  'type' => 'hidden',
57  'name' => 'author_id',
58  'value' => $this->_iOwnerId,
59  'db' => array (
60  'pass' => 'Int',
61  ),
62  ),
63  'caption' => array(
64  'type' => 'text',
65  'name' => 'caption',
66  'caption' => _t("_td_caption"),
67  'value' => '',
68  'required' => 1,
69  'checker' => array (
70  'func' => 'length',
71  'params' => array(3,64),
72  'error' => _t('_td_err_incorrect_length'),
73  ),
74  'db' => array (
75  'pass' => 'Xss',
76  ),
77  ),
78  'snippet' => array(
79  'type' => 'textarea',
80  'html' => 0,
81  'name' => 'snippet',
82  'caption' => _t("_td_snippet"),
83  'value' => '',
84  'required' => 1,
85  'checker' => array (
86  'func' => 'length',
87  'params' => array(3,200),
88  'error' => _t('_td_err_incorrect_length'),
89  ),
90  'db' => array (
91  'pass' => 'Xss',
92  ),
93  ),
94  'content' => array(
95  'type' => 'textarea',
96  'html' => 2,
97  'name' => 'content',
98  'caption' => _t("_td_content"),
99  'value' => '',
100  'required' => 1,
101  'checker' => array (
102  'func' => 'length',
103  'params' => array(3,65536),
104  'error' => _t('_td_err_incorrect_length'),
105  ),
106  'db' => array (
107  'pass' => 'XssHtml',
108  ),
109  ),
110  'when' => array(
111  'type' => 'datetime',
112  'name' => 'when',
113  'caption' => _t("_td_date"),
114  'value' => date('Y-m-d H:i'),
115  'required' => 1,
116  'checker' => array (
117  'func' => 'DateTime',
118  'error' => _t('_td_err_empty_value'),
119  ),
120  'db' => array (
121  'pass' => 'DateTime',
122  ),
123  ),
124  'tags' => array(
125  'type' => 'text',
126  'name' => 'tags',
127  'caption' => _t("_td_tags"),
128  'value' => '',
129  'required' => 1,
130  'checker' => array (
131  'func' => 'length',
132  'params' => array(3,64),
133  'error' => _t('_td_err_incorrect_length'),
134  ),
135  'info' => _t('_sys_tags_note'),
136  'db' => array (
137  'pass' => 'Xss',
138  ),
139  ),
140  'categories' => $oCategories->getGroupChooser($this->_oModule->_oConfig->getCategoriesSystemName(), $this->_iOwnerId, true),
141  'allow_comment_to' => array(),
142  'allow_vote_to' => array(),
143  'post' => array(
144  'type' => 'submit',
145  'name' => 'post',
146  'value' => _t("_td_post"),
147  ),
148  )
149  );
150 
151  if(!empty($this->_iOwnerId)) {
152  $oPrivacy = new ChWsbPrivacy();
153  $sModuleUri = $this->_oModule->_oConfig->getUri();
154 
155  $this->_aForm['inputs']['allow_comment_to'] = $oPrivacy->getGroupChooser($this->_iOwnerId, $sModuleUri, 'comment');
156  $this->_aForm['inputs']['allow_vote_to'] = $oPrivacy->getGroupChooser($this->_iOwnerId, $sModuleUri, 'vote');
157  }
158  }
159 
160  function getPostForm($aAddFields = array())
161  {
162  $oForm = new ChTemplFormView($this->_aForm);
163  $oForm->initChecker();
164 
165  if($oForm->isSubmittedAndValid()) {
166  $iDateNow = time();
167  $iDatePublish = $oForm->getCleanValue('when');
168  if($iDatePublish > $iDateNow)
169  $iStatus = CH_TD_STATUS_PENDING;
170  else if($iDatePublish <= $iDateNow && $this->_oModule->_oConfig->isAutoapprove())
171  $iStatus = CH_TD_STATUS_ACTIVE;
172  else
173  $iStatus = CH_TD_STATUS_INACTIVE;
174 
175  $aDefFields = array(
176  'uri' => $oForm->generateUri(),
177  'date' => $iDateNow,
178  'status' => $iStatus
179  );
180  $iId = $oForm->insert(array_merge($aDefFields, $aAddFields));
181 
182  //--- 'System' -> Post for Alerts Engine ---//
183  ch_import('ChWsbAlerts');
184  $oAlert = new ChWsbAlerts($this->_oModule->_oConfig->getAlertsSystemName(), 'post', $iId, $this->_iOwnerId);
185  $oAlert->alert();
186  //--- 'System' -> Post for Alerts Engine ---//
187 
188  //--- Reparse Global Tags ---//
189  $oTags = new ChWsbTags();
190  $oTags->reparseObjTags($this->_oModule->_oConfig->getTagsSystemName(), $iId);
191  //--- Reparse Global Tags ---//
192 
193  //--- Reparse Global Categories ---//
194  $oCategories = new ChWsbCategories();
195  $oCategories->reparseObjTags($this->_oModule->_oConfig->getCategoriesSystemName(), $iId);
196  //--- Reparse Global Categories ---//
197 
198  header('Location: ' . $oForm->aFormAttrs['action']);
199  } else
200  return $oForm->getCode();
201  }
202 
203  function getEditForm($aValues, $aAddFields = array())
204  {
205  $oCategories = new ChWsbCategories();
206  if (isset($this->_aForm['inputs']['categories'])) {
207  //--- convert post form to edit one ---//
208  $this->_aForm['inputs']['categories'] = $oCategories->getGroupChooser($this->_oModule->_oConfig->getCategoriesSystemName(), $this->_iOwnerId, true, $aValues['categories']);
209  }
210  if(!empty($aValues) && is_array($aValues)) {
211 
212  foreach($aValues as $sKey => $sValue)
213  if(array_key_exists($sKey, $this->_aForm['inputs'])) {
214  if($this->_aForm['inputs'][$sKey]['type'] == 'checkbox')
215  $this->_aForm['inputs'][$sKey]['checked'] = (int)$sValue == 1 ? true : false;
216  else if($this->_aForm['inputs'][$sKey]['type'] == 'select_box' && $this->_aForm['inputs'][$sKey]['name'] == 'Categories') {
217  $aCategories = preg_split( '/['.$oCategories->sTagsDivider.']/', $sValue, 0, PREG_SPLIT_NO_EMPTY );
218  $this->_aForm['inputs'][$sKey]['value'] = $aCategories;
219  } else
220  $this->_aForm['inputs'][$sKey]['value'] = $sValue;
221  }
222  unset( $this->_aForm['inputs']['author_id']);
223  $this->_aForm['inputs']['id'] = array(
224  'type' => 'hidden',
225  'name' => 'id',
226  'value' => $aValues['id'],
227  'db' => array (
228  'pass' => 'Int',
229  )
230  );
231  $this->_aForm['inputs']['post']['value'] = _t("_td_edit");
232  }
233  $oForm = new ChTemplFormView($this->_aForm);
234  $oForm->initChecker();
235 
236  if($oForm->isSubmittedAndValid()) {
237  $iDateNow = time();
238  $iDatePublish = $oForm->getCleanValue('when');
239  if($iDatePublish > $iDateNow)
240  $iStatus = CH_TD_STATUS_PENDING;
241  else if($iDatePublish <= $iDateNow && $this->_oModule->_oConfig->isAutoapprove())
242  $iStatus = CH_TD_STATUS_ACTIVE;
243  else
244  $iStatus = CH_TD_STATUS_INACTIVE;
245 
246  $aDefFields = array(
247  'date' => $iDateNow,
248  'status' => $iStatus
249  );
250  $oForm->update($aValues['id'], array_merge($aDefFields, $aAddFields));
251 
252  //--- 'System' -> Edit for Alerts Engine ---//
253  ch_import('ChWsbAlerts');
254  $oAlert = new ChWsbAlerts($this->_oModule->_oConfig->getAlertsSystemName(), 'edit', $aValues['id'], $this->_iOwnerId);
255  $oAlert->alert();
256  //--- 'System' -> Edit for Alerts Engine ---//
257 
258  //--- Reparse Global Tags ---//
259  $oTags = new ChWsbTags();
260  $oTags->reparseObjTags($this->_oModule->_oConfig->getTagsSystemName(), $aValues['id']);
261  //--- Reparse Global Tags ---//
262 
263  //--- Reparse Global Categories ---//
264  $oCategories->reparseObjTags($this->_oModule->_oConfig->getCategoriesSystemName(), $aValues['id']);
265  //--- Reparse Global Categories ---//
266 
267  header('Location: ' . $oForm->aFormAttrs['action']);
268  } else
269  return $oForm->getCode();
270  }
271 
272  function getViewerType()
273  {
274  $iViewerType = CH_TD_VIEWER_TYPE_VISITOR;
275  if(isAdmin())
276  $iViewerType = CH_TD_VIEWER_TYPE_ADMIN;
277  else if(isMember())
278  $iViewerType = CH_TD_VIEWER_TYPE_MEMBER;
279 
280  return $iViewerType;
281  }
282 
283  public static function getAuthorId()
284  {
285  return getLoggedId();
286  }
287 
288  function getAuthorPassword()
289  {
290  return getLoggedPassword();
291  }
292 }
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
CH_TD_VIEWER_TYPE_MEMBER
const CH_TD_VIEWER_TYPE_MEMBER
Definition: ChWsbTextData.php:9
$oModule
if(! @isAdmin()) $oModule
Definition: admin.php:25
ChTemplFormView
Definition: ChTemplFormView.php:11
getLoggedPassword
getLoggedPassword()
Definition: profiles.inc.php:36
ChWsbTextData\getAuthorId
static getAuthorId()
Definition: ChWsbTextData.php:283
ChWsbTextData\getAuthorPassword
getAuthorPassword()
Definition: ChWsbTextData.php:288
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$oAlert
$oAlert
Definition: embed.php:15
php
ChWsbTextData\$_iOwnerId
$_iOwnerId
Definition: ChWsbTextData.php:27
ChWsbTags
Definition: ChWsbTags.php:15
ChWsbTextData\getPostForm
getPostForm($aAddFields=array())
Definition: ChWsbTextData.php:160
$iId
$iId
Definition: license.php:15
CH_TD_VIEWER_TYPE_VISITOR
const CH_TD_VIEWER_TYPE_VISITOR
Definition: ChWsbTextData.php:8
ChWsbTextData\__construct
__construct(&$oModule)
Definition: ChWsbTextData.php:29
ChWsbCategories
Definition: ChWsbCategories.php:13
isAdmin
isAdmin()
Definition: index.php:649
ch_html_attribute
ch_html_attribute($mixedInput)
Definition: utils.inc.php:1324
$oForm
$oForm
Definition: host_tools.php:42
ChWsbAlerts
Definition: ChWsbAlerts.php:39
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
CH_TD_STATUS_INACTIVE
const CH_TD_STATUS_INACTIVE
Definition: ChWsbTextData.php:13
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
CH_TD_STATUS_ACTIVE
const CH_TD_STATUS_ACTIVE
Definition: ChWsbTextData.php:12
ChWsbTextData
Definition: ChWsbTextData.php:23
ChWsbTextData\$_oModule
$_oModule
Definition: ChWsbTextData.php:24
ChWsbPrivacy
Definition: ChWsbPrivacy.php:60
ChWsbTextData\$_bComments
$_bComments
Definition: ChWsbTextData.php:26
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbTextData\getEditForm
getEditForm($aValues, $aAddFields=array())
Definition: ChWsbTextData.php:203
CH_TD_VIEWER_TYPE_ADMIN
const CH_TD_VIEWER_TYPE_ADMIN
Definition: ChWsbTextData.php:10
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbTextData\getViewerType
getViewerType()
Definition: ChWsbTextData.php:272
CH_TD_STATUS_PENDING
const CH_TD_STATUS_PENDING
Definition: ChWsbTextData.php:14
ChWsbTextData\$_aForm
$_aForm
Definition: ChWsbTextData.php:25
isMember
isMember($iId=0)
Definition: profiles.inc.php:44