Guest User

slieders.php

a guest
Jul 9th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. <?php
  2. /** Modulo JQuerySlider Galery **/
  3. /** www.tiendasvirtuales.com.ve **/
  4.  
  5. class slideric extends Module
  6. {
  7. /** @var max image size */
  8. protected $maxImageSize = 307200;
  9.  
  10. function __construct()
  11. {
  12. $this->name = 'slideric';
  13. $this->tab = 'Home';
  14. $this->version = '2.0';
  15.  
  16. /* The parent construct is required for translations */
  17. parent::__construct();
  18.  
  19. $this->page = basename(__FILE__, '.php');
  20. $this->displayName = $this->l('Slideric - JQuery Nivo Slider');
  21. $this->description = $this->l('Slide the images with choosen languages | Prestashopic.com');
  22. }
  23.  
  24. function install()
  25. {
  26. if (!parent::install() OR !$this->registerHook('Home'))
  27. return false;
  28. return true;
  29. }
  30.  
  31. function putContent($xml_data, $key, $field)
  32. {
  33. $field = htmlspecialchars($field);
  34. if (!$field)
  35. return 0;
  36. return ("\n".' <'.$key.'>'.$field.'</'.$key.'>');
  37. }
  38.  
  39. function getContent()
  40. {
  41. global $cookie;
  42. /* Languages preliminaries */
  43. $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
  44. $languages = Language::getLanguages();
  45. $iso = Language::getIsoById($defaultLanguage);
  46. $isoUser = Language::getIsoById(intval($cookie->id_lang));
  47.  
  48.  
  49. /* display the module name */
  50. $this->_html = '<h2>'.$this->displayName.' '.$this->version.'</h2>';
  51.  
  52. /* update the editorial xml */
  53. if (isset($_POST['submitUpdate']))
  54. {
  55. // Generate new XML data
  56. $newXml = '<?xml version=\'1.0\' encoding=\'utf-8\' ?>'."\n";
  57. $newXml .= '<links>'."\n";
  58. $i = 0;
  59. foreach ($_POST['link'] as $link)
  60. {
  61. $newXml .= ' <link>';
  62. foreach ($link AS $key => $field)
  63. {
  64. if ($line = $this->putContent($newXml, $key, $field))
  65. $newXml .= $line;
  66. }
  67.  
  68. /* upload the image */
  69. if (isset($_FILES['link_'.$i.'_img']) AND isset($_FILES['link_'.$i.'_img']['tmp_name']) AND !empty($_FILES['link_'.$i.'_img']['tmp_name']))
  70. {
  71. Configuration::set('PS_IMAGE_GENERATION_METHOD', 1);
  72. if ($error = checkImage($_FILES['link_'.$i.'_img'], $this->maxImageSize))
  73. $this->_html .= $error;
  74. elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['link_'.$i.'_img']['tmp_name'], $tmpName))
  75. return false;
  76. elseif (!imageResize($tmpName, dirname(__FILE__).'/'.$isoUser.$i.'.jpg'))
  77. $this->_html .= $this->displayError($this->l('An error occurred during the image upload.'));
  78. unlink($tmpName);
  79. }
  80. if ($line = $this->putContent($newXml, 'img', $isoUser.$i.'.jpg'))
  81. $newXml .= $line;
  82. $newXml .= "\n".' </link>'."\n";
  83. $i++;
  84. }
  85. $newXml .= '</links>'."\n";
  86.  
  87. /* write it into the editorial xml file */
  88. if ($fd = @fopen(dirname(__FILE__).'/'.$isoUser.'links.xml', 'w'))
  89. {
  90. if (!@fwrite($fd, $newXml))
  91. $this->_html .= $this->displayError($this->l('Unable to write to the editor file.'));
  92. if (!@fclose($fd))
  93. $this->_html .= $this->displayError($this->l('Can\'t close the editor file.'));
  94. }
  95. else
  96. $this->_html .= $this->displayError($this->l('Unable to update the editor file.<br />Please check the editor file\'s writing permissions.'));
  97. }
  98.  
  99. /* display the editorial's form */
  100. $this->_displayForm();
  101.  
  102. return $this->_html;
  103. }
  104.  
  105. private function _displayForm()
  106. {
  107. global $cookie;
  108. /* Languages preliminaries */
  109. $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
  110. $languages = Language::getLanguages();
  111. $iso = Language::getIsoById($defaultLanguage);
  112. $isoUser = Language::getIsoById(intval($cookie->id_lang));
  113.  
  114.  
  115. /* xml loading */
  116. $xml = false;
  117. if (file_exists(dirname(__FILE__).'/'.$isoUser.'links.xml'))
  118. if (!$xml = @simplexml_load_file(dirname(__FILE__).'/'.$isoUser.'links.xml'))
  119. $this->_html .= $this->displayError($this->l('Your links file is empty.'));
  120. $this->_html .= '<br />
  121. <form method="post" action="'.$_SERVER['REQUEST_URI'].'" enctype="multipart/form-data">
  122. <fieldset style="width: 900px;">
  123. <legend><img src="'.$this->_path.'logo.gif" alt="" title="" /> '.$this->displayName.'</legend><span id="odliczanie"></span>';
  124. $i = 0;
  125. foreach ($xml->link as $link)
  126. {
  127. $divLangName = 'title'.$i.'Β€cpara'.$i;
  128. $this->_html .= '<h4>'.$this->l('Slider #').$i.'</h4>';
  129. $this->_html .= '<div class="clear"></div>';
  130. $this->_html .= '
  131.  
  132. <fieldset style="width:870px">
  133. <h5><label>'.$this->l('Image Size (50%)').'</label></h5>
  134. <div class="margin-form">
  135. <img src="'.$this->_path.$isoUser.$i.'.jpg" alt="" title="" style="width:50%; height:50%;" /><br />
  136. <input type="file" name="link_'.$i.'_img" />
  137. </div>
  138. <h5><label>'.$this->l('URL').'</label></h5>
  139. <div class="margin-form">
  140. <input type="text" name="link['.$i.'][url]" size="64" value="'.($xml ? stripslashes(htmlspecialchars($xml->link[$i]->url)) : '').'" />
  141. </div>
  142. </fieldset>';
  143.  
  144. $i++;
  145. }
  146.  
  147.  
  148. $this->_html .= '
  149.  
  150. <div class="margin-form clear">
  151. <div class="clear pspace"></div>
  152. <div class="margin-form">
  153. <input type="submit" name="submitUpdate" value="'.$this->l('Save').'" class="button" />
  154. </div>
  155. </div>
  156.  
  157. </fieldset>
  158. </form>';
  159. }
  160.  
  161. function hookHome($params)
  162. {
  163. global $cookie;
  164. /* Languages preliminaries */
  165. $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
  166. $languages = Language::getLanguages();
  167. $iso = Language::getIsoById($defaultLanguage);
  168. $isoUser = Language::getIsoById(intval($cookie->id_lang));
  169.  
  170. if (file_exists(dirname(__FILE__).'/'.$isoUser.'links.xml'))
  171. if ($xml = simplexml_load_file(dirname(__FILE__).'/'.$isoUser.'links.xml'))
  172. {
  173. global $cookie, $smarty;
  174. $smarty->assign(array(
  175. 'xml' => $xml,
  176. 'this_path' => $this->_path
  177. ));
  178. return $this->display(__FILE__, 'slideric.tpl');
  179. }
  180. return false;
  181. }
  182.  
  183. }
  184.  
  185. ?>
Advertisement
Add Comment
Please, Sign In to add comment