PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/mod_sp_smart_slider/helpers/spArticleSliderHelper.class.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 496 lines | 443 code | 48 blank | 5 comment | 2 complexity | 52e7cea435dbda6f8c0b6643ac3dad90 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, MIT, BSD-3-Clause
  1. <?php
  2. /**
  3. * @author JoomShaper http://www.joomshaper.com
  4. * @copyright Copyright (C) 2010 - 2012 JoomShaper
  5. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2
  6. */
  7. class spArticleSliderHelper
  8. {
  9. public $name = 'Article';
  10. public $uniqid = 'article';
  11. public $fieldname;
  12. public $params;
  13. public function setOptions()
  14. {
  15. $html = array();
  16. $html[] = array(
  17. 'title'=>'Article',
  18. 'tip'=>'Select an article',
  19. 'tipdesc'=>'Choose an article from source',
  20. 'class'=>'select-'.$this->uniqid,
  21. 'attrs'=>'',
  22. 'html'=>'
  23. <input readonly="readonly" type="text" value="'.$this->params['title'].'" ref="title" id="'.$this->uniqid.'-slider-article-item-%index%"
  24. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][title][]" class="'.$this->uniqid.'-slider-item">
  25. <input type="hidden" value="'.$this->params['id'].'" id="'.$this->uniqid.'-slider-articleid-item-%index%"
  26. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][id][]" class="'.$this->uniqid.'-slider-item">
  27. <a class="model btn" ref="{article: \\\''.$this->uniqid.'-slider-article-item-%index%\\\', id: \\\''.$this->uniqid.'-slider-articleid-item-%index%\\\'}" class="'.$this->uniqid.'-slide-item-select" title="Select" href="index.php?option=com_content&view=articles&layout=modal&tmpl=component&function=spSelectArticle" rel="{handler: \\\'iframe\\\', size: {x: 800, y: 500}}">Select</a>'
  28. );
  29. $html[] = array(
  30. 'title'=>'Pre Title',
  31. 'tip'=>'Pre Title',
  32. 'tipdesc'=>'Text to display before title',
  33. 'class'=>''.$this->uniqid.'-slider-title-li',
  34. 'attrs'=>'',
  35. 'html'=>'
  36. <input type="text" value="'.$this->params['pretitle'].'"
  37. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][pretitle][]">'
  38. );
  39. $html[] = array(
  40. 'title'=>'Title type',
  41. 'tip'=>'Title type',
  42. 'tipdesc'=>'Select type of title from list',
  43. 'class'=>$this->uniqid.'-slider-title-type-li',
  44. 'attrs'=>'',
  45. 'html'=>'
  46. <select class="'.$this->uniqid.'-slider-title-custom" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][titletype][]">
  47. <option value="default" '.(($this->params['titletype']=='default')?'selected':'').'>Default</option>
  48. <option value="custom" '.(($this->params['titletype']=='custom')?'selected':'').'>Custom</option>
  49. </select>'
  50. );
  51. $html[] = array(
  52. 'title'=>'Title',
  53. 'tip'=>'Custom title',
  54. 'tipdesc'=>'Set custom title text',
  55. 'class'=>''.$this->uniqid.'-slider-title-li',
  56. 'attrs'=>(($this->params['titletype']=='custom')?' style="display: block;"':' style="display: none;"'),
  57. 'html'=>'
  58. <input type="text" value="'.$this->params['customtitle'].'" ref="title" id="'.$this->uniqid.'-slider-title-%index%"
  59. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][customtitle][]">'
  60. );
  61. $html[] = array(
  62. 'title'=>'Post Title',
  63. 'tip'=>'Post title',
  64. 'tipdesc'=>'Text to display after title',
  65. 'class'=>''.$this->uniqid.'-slider-title-li',
  66. 'attrs'=>'',
  67. 'html'=>'
  68. <input type="text" value="'.$this->params['posttitle'].'"
  69. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][posttitle][]">'
  70. );
  71. $html[] = array(
  72. 'title'=>'Image source',
  73. 'tip'=>'Image source',
  74. 'tipdesc'=>'Set image source from the list',
  75. 'class'=>''.$this->uniqid.'-slider-image-type-li',
  76. 'attrs'=>'',
  77. 'html'=>'
  78. <select class="'.$this->uniqid.'-slider-image-type-custom" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][customimage][]">
  79. <option value="no" '.(($this->params['customimage']=='no')?'selected':'').'>Default</option>
  80. <option value="yes" '.(($this->params['customimage']=='yes')?'selected':'').'>Custom</option>
  81. </select>'
  82. );
  83. $html[] = array(
  84. 'title'=>'Image',
  85. 'tip'=>'Custom image',
  86. 'tipdesc'=>'Choose custom image',
  87. 'class'=>''.$this->uniqid.'-slider-image-li',
  88. 'attrs'=>(($this->params['customimage']=='yes')?' style="display: block;"':' style="display: none;"'),
  89. 'html'=>'
  90. <input style="width:110px" type="text" value="'.$this->params['image'].'" id="'.$this->uniqid.'-slider-image-%index%"
  91. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][image][]" class="'.$this->uniqid.'-slider-image">
  92. <a class="model btn" class="'.$this->uniqid.'-slide-image-select" title="Select" href="index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=&amp;author=&amp;fieldid='.$this->uniqid.'-slider-image-%index%&amp;folder=" rel="{handler: \\\'iframe\\\', size: {x: 800, y: 500}}">Select</a>
  93. <a title="Clear" class="btn" href="javascript:;" onclick="javascript:document.getElementById(\\\''.$this->uniqid.'-slider-image-%index%\\\').value=\\\'\\\';">Clear</a>'
  94. );
  95. $html[] = array(
  96. 'title'=>'Thumb',
  97. 'tip'=>'Custom thumb image',
  98. 'tipdesc'=>'Choose custom thumb image',
  99. 'class'=>''.$this->uniqid.'-slider-image-li',
  100. 'attrs'=>(($this->params['customimage']=='yes')?' style="display: block;"':' style="display: none;"'),
  101. 'html'=>'
  102. <input type="text" style="width:110px" value="'.$this->params['thumb'].'" id="'.$this->uniqid.'-thumbslider-image-%index%"
  103. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][thumb][]" class="'.$this->uniqid.'-slider-image">
  104. <a class="model btn" class="'.$this->uniqid.'-slide-image-select" title="Select" href="index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=&amp;author=&amp;fieldid='.$this->uniqid.'-thumbslider-image-%index%&amp;folder=" rel="{handler: \\\'iframe\\\', size: {x: 800, y: 500}}">Select</a>
  105. <a title="Clear" class="btn" href="javascript:;" onclick="javascript:document.getElementById(\\\''.$this->uniqid.'-thumbslider-image-%index%\\\').value=\\\'\\\';">Clear</a>'
  106. );
  107. $html[] = array(
  108. 'title'=>'Show link',
  109. 'tip'=>'Show article link',
  110. 'tipdesc'=>'Display article link or set custom link',
  111. 'class'=>$this->uniqid.'-slider-title-type-li',
  112. 'attrs'=>'',
  113. 'html'=>'
  114. <select class="'.$this->uniqid.'-slider-showlink" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][showlink][]">
  115. <option value="yes" '.(($this->params['showlink']=='yes')?'selected':'').'>Yes</option>
  116. <option value="no" '.(($this->params['showlink']=='no')?'selected':'').'>No</option>
  117. <option value="custom" '.(($this->params['showlink']=='custom')?'selected':'').'>Custom</option>
  118. </select>'
  119. );
  120. $html[] = array(
  121. 'title'=>'Custom link',
  122. 'tip'=>'Custom link',
  123. 'tipdesc'=>'Custom link url',
  124. 'class'=>''.$this->uniqid.'-slider-title-li',
  125. 'attrs'=>(($this->params['showlink']=='custom')?' style="display: block;"':' style="display: none;"'),
  126. 'html'=>'<input type="text" value="'.$this->params['link'].'" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][link][]">'
  127. );
  128. $html[] = array(
  129. 'title'=>'Text Limit',
  130. 'tip'=>'Text limit type',
  131. 'tipdesc'=>'Choose text limit type',
  132. 'class'=>$this->uniqid.'-slider-title-type-li',
  133. 'attrs'=>'',
  134. 'html'=>'
  135. <select class="'.$this->uniqid.'-slider-textlimit" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][textlimit][]">
  136. <option value="no" '.(($this->params['textlimit']=='no')?'selected':'').'>No limit</option>
  137. <option value="word" '.(($this->params['textlimit']=='word')?'selected':'').'>Word</option>
  138. <option value="char" '.(($this->params['textlimit']=='char')?'selected':'').'>Character</option>
  139. </select>'
  140. );
  141. $html[] = array(
  142. 'title'=>'Limit Count',
  143. 'tip'=>'Text limit count',
  144. 'tipdesc'=>'Text limit count',
  145. 'class'=>''.$this->uniqid.'-slider-title-li',
  146. 'attrs'=>(($this->params['textlimit']=='no' or !isset($this->params['textlimit']))?' style="display: none;"':' style="display: block;"'),
  147. 'html'=>'
  148. <input type="text" value="'.$this->params['limitcount'].'" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][limitcount][]">'
  149. );
  150. $html[] = array(
  151. 'title'=>'Strip HTML',
  152. 'tip'=>'Remove html',
  153. 'tipdesc'=>'Remove html tags',
  154. 'class'=>$this->uniqid.'-slider-title-type-li',
  155. 'attrs'=>'',
  156. 'html'=>'
  157. <select class="'.$this->uniqid.'-slider-striphtml" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][striphtml][]">
  158. <option value="no" '.(($this->params['striphtml']=='no')?'selected':'').'>No</option>
  159. <option value="yes" '.(($this->params['striphtml']=='yes')?'selected':'').'>Yes</option>
  160. </select>'
  161. );
  162. $html[] = array(
  163. 'title'=>'Allowable tags',
  164. 'tip'=>'Allowable html tags',
  165. 'tipdesc'=>'Allowable html tags when html removed',
  166. 'class'=>''.$this->uniqid.'-slider-title-li',
  167. 'attrs'=>(($this->params['striphtml']=='no' or !isset($this->params['striphtml']))?' style="display: none;"':' style="display: block;"'),
  168. 'html'=>'<input type="text" value="'.$this->params['allowabletag'].'" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][allowabletag][]"><small>&lt;img&gt;,&lt;a&gt; </small>'
  169. );
  170. $html[] = array(
  171. 'title'=>'Readmore Text',
  172. 'tip'=>'Readmore text',
  173. 'tipdesc'=>'Write readmore text',
  174. 'class'=>''.$this->uniqid.'-slider-title-li',
  175. 'attrs'=>'',
  176. 'html'=>'
  177. <input type="text" value="'.$this->params['readmore'].'"
  178. name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][readmore][]">'
  179. );
  180. $html[] = array(
  181. 'title'=>'State',
  182. 'tip'=>'Set State',
  183. 'tipdesc'=>'Published or unpublished slide item',
  184. 'class'=>''.$this->uniqid.'-slider-item-li',
  185. 'attrs'=>'',
  186. 'fieldname'=>'text',
  187. 'html'=>'
  188. <select class="sp-state" name="jform[params]['.$this->fieldname.']['.$this->uniqid.'][state][]">
  189. <option value="published" '.(($this->params['state']=='unpublished')?'selected':'').'>Published</option>
  190. <option value="unpublished" '.(($this->params['state']=='unpublished')?'selected':'').'>Un Published</option>
  191. </select>'
  192. );
  193. return $html;
  194. }
  195. public function styleSheet()
  196. {
  197. return '';
  198. }
  199. private function JS3()
  200. {
  201. return 'var sp_item_opened;
  202. function spSelectArticle(id, title, cid, $null, url)
  203. {
  204. var data = jQuery("body").data("article");
  205. jQuery("#"+data.id).val(id);
  206. jQuery("#"+data.article).val(title).focus();
  207. SqueezeBox.close();
  208. }
  209. jQuery(document).ready(function(){
  210. jQuery("#options-sliders").delegate("a.model", "hover", function(event)
  211. {
  212. eval( "var $callerData=(" + jQuery(this).attr("ref") + ")" );
  213. jQuery("body").data("article", $callerData );
  214. });
  215. });
  216. window.addEvent("domready",function()
  217. {
  218. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-title-custom)", function(event, element) {
  219. if( this.get("value")=="custom" )
  220. {
  221. this.getParent().getPrevious().getChildren("[ref=\'title\']").set("readonly","readonly");
  222. this.getParent().getNext().setStyle("display","block");
  223. } else {
  224. this.getParent().getPrevious().getChildren("[ref=\'title\']").set("readonly","");
  225. this.getParent().getNext().setStyle("display","none");
  226. }
  227. });
  228. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-image-type-custom)", function(event, element) {
  229. if( this.get("value")=="yes" )
  230. {
  231. this.getParent().getNext().setStyle("display","block");
  232. this.getParent().getNext().getNext().setStyle("display","block");
  233. } else {
  234. this.getParent().getNext().setStyle("display","none");
  235. this.getParent().getNext().getNext().setStyle("display","none");
  236. }
  237. });
  238. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-textlimit)", function(event, element) {
  239. if( this.get("value")=="no" )
  240. {
  241. this.getParent().getNext().setStyle("display","none");
  242. } else {
  243. this.getParent().getNext().setStyle("display","block");
  244. }
  245. });
  246. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-striphtml)", function(event, element)
  247. {
  248. if( this.get("value")=="no" )
  249. {
  250. this.getParent().getNext().setStyle("display","none");
  251. } else {
  252. this.getParent().getNext().setStyle("display","block");
  253. }
  254. });
  255. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-showlink)", function(event, element)
  256. {
  257. if( this.get("value")=="custom" )
  258. {
  259. this.getParent().getNext().setStyle("display","block");
  260. } else {
  261. this.getParent().getNext().setStyle("display","none");
  262. }
  263. });
  264. });';
  265. }
  266. private function JS2()
  267. {
  268. return 'var sp_item_opened;
  269. function spSelectArticle(id, title, cid, $null, url)
  270. {
  271. var data = jQuery("body").data("article");
  272. $(data.article).set("value", title);
  273. $(data.id).set("value", id);
  274. $(data.article).focus();
  275. SqueezeBox.close();
  276. }
  277. jQuery(function($){
  278. $("ul.adminformlist").delegate("a.model", "hover", function()
  279. {
  280. eval( "var $callerData=(" + $(this).attr("ref") + ")" );
  281. $("body").data("article", $callerData );
  282. });
  283. });
  284. window.addEvent("domready",function() {
  285. /*$(document.body).addEvent("click:relay(a.model)", function(event, element)
  286. {
  287. event.stop();
  288. this.addEvent("click", function(){
  289. if( this.get("ref") )
  290. {
  291. sp_item_opened = JSON.encode(this.get("ref"));
  292. }
  293. })
  294. });*/
  295. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-title-custom)", function(event, element) {
  296. if( this.get("value")=="custom" )
  297. {
  298. this.getParent().getPrevious().getChildren("[ref=\'title\']").set("readonly","readonly");
  299. this.getParent().getNext().setStyle("display","block");
  300. } else {
  301. this.getParent().getPrevious().getChildren("[ref=\'title\']").set("readonly","");
  302. this.getParent().getNext().setStyle("display","none");
  303. }
  304. });
  305. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-image-type-custom)", function(event, element) {
  306. if( this.get("value")=="yes" )
  307. {
  308. this.getParent().getNext().setStyle("display","block");
  309. this.getParent().getNext().getNext().setStyle("display","block");
  310. } else {
  311. this.getParent().getNext().setStyle("display","none");
  312. this.getParent().getNext().getNext().setStyle("display","none");
  313. }
  314. });
  315. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-textlimit)", function(event, element) {
  316. if( this.get("value")=="no" )
  317. {
  318. this.getParent().getNext().setStyle("display","none");
  319. } else {
  320. this.getParent().getNext().setStyle("display","block");
  321. }
  322. });
  323. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-striphtml)", function(event, element)
  324. {
  325. if( this.get("value")=="no" )
  326. {
  327. this.getParent().getNext().setStyle("display","none");
  328. } else {
  329. this.getParent().getNext().setStyle("display","block");
  330. }
  331. });
  332. $(document.body).addEvent("change:relay(.'.$this->uniqid.'-slider-showlink)", function(event, element)
  333. {
  334. if( this.get("value")=="custom" )
  335. {
  336. this.getParent().getNext().setStyle("display","block");
  337. } else {
  338. this.getParent().getNext().setStyle("display","none");
  339. }
  340. });
  341. });
  342. ';
  343. }
  344. public function JavaScript()
  345. {
  346. return ( JVERSION < 3 ) ? $this->JS2() : $this->JS3() ;
  347. }
  348. public function display($helper)
  349. {
  350. $article = $helper->getArticle($this->params['id']);
  351. $article['title'] = ($this->params['titletype']=='yes')?$this->params['customtitle']:$article['title'];
  352. if( isset($article['images']) and !empty($article['images']) )
  353. {
  354. $artimages = json_decode($article['images'],true);
  355. $image = $artimages['image_intro'];
  356. $thumb = $artimages['image_fulltext'];
  357. } else { $image=''; $thumb=''; }
  358. $this->params['image'] = ($this->params['customimage']=='yes')?$this->params['image']:$image;
  359. $this->params['thumb'] = ($this->params['customimage']=='yes')?$this->params['thumb']:$thumb;
  360. return $article+$this->params;
  361. }
  362. }