PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/likeboxfree/likeboxfree.php

https://gitlab.com/sutrix.hoa.tran/Research-Prestashop
PHP | 416 lines | 391 code | 23 blank | 2 comment | 72 complexity | 073b263e2391e371498015b567c7dca4 MD5 | raw file
  1. <?php
  2. class likeboxfree extends Module {
  3. function __construct(){
  4. $this->name = 'likeboxfree';
  5. $this->tab = 'social_networks';
  6. $this->version = '2.3';
  7. $this->author = 'Xuan hoa';
  8. $this->dir = '/modules/likeboxfree/';
  9. parent::__construct();
  10. $this->trusted();
  11. $this->displayName = $this->l('Fanpage Likebox Free');
  12. $this->description = $this->l('This module add special likebox block with your fanpage on Facebook. Now anybody can like your facebook fanpage!');
  13. $this->mkey="freelicense";
  14. if (@file_exists('../modules/'.$this->name.'/key.php'))
  15. @require_once ('../modules/'.$this->name.'/key.php');
  16. else if (@file_exists(dirname(__FILE__) . $this->name.'/key.php'))
  17. @require_once (dirname(__FILE__) . $this->name.'/key.php');
  18. else if (@file_exists('modules/'.$this->name.'/key.php'))
  19. @require_once ('modules/'.$this->name.'/key.php');
  20. $this->checkforupdates();
  21. }
  22. function checkforupdates(){
  23. if (isset($_GET['controller']) OR isset($_GET['tab'])){
  24. if (Configuration::get('update_'.$this->name) < (date("U")>86400)){
  25. $actual_version = likeboxfreeUpdate::verify($this->name,$this->mkey,$this->version);
  26. }
  27. if (likeboxfreeUpdate::version($this->version)<likeboxfreeUpdate::version(Configuration::get('updatev_'.$this->name))){
  28. $this->warning=$this->l('New version available, check www.MyPresta.eu for more informations');
  29. }
  30. }
  31. }
  32. function trusted() {
  33. if(_PS_VERSION_ >= "1.6.0.8") {
  34. if(isset($_GET['controller'])) {
  35. if($_GET['controller'] == "AdminModules") {
  36. if(_PS_VERSION_ >= "1.6.0.8") {
  37. if(isset($_GET['controller'])) {
  38. if($_GET['controller'] == "AdminModules") {
  39. $this->context->controller->addJS(($this->_path).'trusted.js', 'all');
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. if(defined('_PS_HOST_MODE_')) {
  47. if(isset($_GET['controller'])) {
  48. if($_GET['controller'] == "AdminModules") {
  49. if(defined('self::CACHE_FILE_TRUSTED_MODULES_LIST') == true) {
  50. $context = Context::getContext();
  51. $theme = new Theme($context->shop->id_theme);
  52. $xml = simplexml_load_string(file_get_contents(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST));
  53. if($xml) {
  54. $css = $xml->modules->addChild('module');
  55. $css->addAttribute('name', $this->name);
  56. $xmlcode = $xml->asXML();
  57. if(!strpos(file_get_contents(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST), $this->name))
  58. if(file_exists(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST))
  59. file_put_contents(_PS_ROOT_DIR_.self::CACHE_FILE_TRUSTED_MODULES_LIST, $xmlcode);
  60. }
  61. }
  62. if(defined('self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST') == true) {
  63. $xml = simplexml_load_string(file_get_contents(_PS_ROOT_DIR_.self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST));
  64. //$xml=new SimpleXMLElement('<modules/>');
  65. //$cs=$xml->addChild('modules');
  66. if($xml) {
  67. $css = $xml->addChild('module');
  68. $css->addChild('id', 0);
  69. $css->addChild('name', "<![CDATA[".$this->name."]]>");
  70. $xmlcode = $xml->asXML();
  71. $xmlcode = str_replace('&lt;', "<", $xmlcode);
  72. $xmlcode = str_replace('&gt;', ">", $xmlcode);
  73. if(!strpos(file_get_contents(_PS_ROOT_DIR_.self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST), $this->name))
  74. if(file_exists(_PS_ROOT_DIR_.self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST))
  75. file_put_contents(_PS_ROOT_DIR_.self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, $xmlcode);
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. function install(){
  83. if (parent::install() == false
  84. OR !Configuration::updateValue('update_'.$this->name,'0')
  85. OR $this->registerHook('rightColumn') == false
  86. OR $this->registerHook('leftColumn') == false
  87. OR $this->registerHook('home') == false
  88. OR $this->registerHook('footer') == false
  89. OR Configuration::updateValue('likeboxfree_position', '2') == false
  90. OR Configuration::updateValue('lbf_width', '191') == false
  91. OR Configuration::updateValue('lbf_height', '300') == false
  92. OR Configuration::updateValue('lbf_hide_cover', '0') == false
  93. OR Configuration::updateValue('lbf_show_facepile', '1') == false
  94. OR Configuration::updateValue('lbf_show_posts', '0') == false
  95. OR Configuration::updateValue('lbf_hide_cta', '0') == false
  96. OR Configuration::updateValue('lbf_small_header', '0') == false
  97. OR Configuration::updateValue('lbf_url', 'https://www.facebook.com/mypresta') == false
  98. ){
  99. return false;
  100. }
  101. return true;
  102. }
  103. public function getContent(){
  104. $output="";
  105. $this->msg="";
  106. if (Tools::isSubmit('submit_settings')){
  107. Configuration::updateValue('likeboxfree_position', Tools::getValue('new_likebox_position'), true);
  108. Configuration::updateValue('lbf_width', Tools::getValue('lbf_width'), true);
  109. Configuration::updateValue('lbf_height', Tools::getValue('lbf_height'), true);
  110. Configuration::updateValue('lbf_hide_cover', Tools::getValue('lbf_hide_cover'), true);
  111. Configuration::updateValue('lbf_show_facepile', Tools::getValue('lbf_show_facepile'), true);
  112. Configuration::updateValue('lbf_show_posts', Tools::getValue('lbf_show_posts'), true);
  113. Configuration::updateValue('lbf_hide_cta', Tools::getValue('lbf_hide_cta'), true);
  114. Configuration::updateValue('lbf_small_header', Tools::getValue('lbf_small_header'), true);
  115. Configuration::updateValue('lbf_url', Tools::getValue('lbf_url'), true);
  116. Configuration::updateValue('likeboxfree_fanpageurl', Tools::getValue('new_likebox_fanpageurl'), true);
  117. Configuration::updateValue('lbf_includeapp', Tools::getValue('lbf_includeapp',0));
  118. $this->msg.= '<div class="bootstrap" style="margin-top:20px;"><div class="alert alert-success"><div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div></div></div>';
  119. }
  120. return $output.$this->displayForm();
  121. }
  122. public function displayForm(){
  123. $likebox_showstream_checked="0";
  124. $likebox_showheader_checked="0";
  125. $likebox_showfaces_checked="0";
  126. $likebox_position = Configuration::get('likeboxfree_position');
  127. $new_likebox1=""; $new_likebox2=""; $new_likebox3=""; $new_likebox4="";
  128. if ($likebox_position=="4"){$new_likebox4="checked=\"yes\"";}
  129. if ($likebox_position=="3"){$new_likebox3="checked=\"yes\"";}
  130. if ($likebox_position=="2"){$new_likebox2="checked=\"yes\"";}
  131. if ($likebox_position=="1"){$new_likebox1="checked=\"yes\"";}
  132. $likebox_fanpageurl = Configuration::get('likeboxfree_fanpageurl');
  133. $likebox_width = Configuration::get('likeboxfree_width');
  134. $likebox_height = Configuration::get('likeboxfree_height');
  135. $likebox_colorscheme = Configuration::get('likeboxfree_colorscheme');
  136. if ($likebox_colorscheme=="light"){$selected_light="SELECTED"; $selected_dark=""; $likebox_colorscheme_bg="white";}
  137. if ($likebox_colorscheme=="dark"){$selected_dark="SELECTED"; $selected_light=""; $likebox_colorscheme_bg="black";}
  138. $likebox_showfaces = Configuration::get('likeboxfree_showfaces');
  139. if ($likebox_showfaces=="1"){$likebox_showfaces_checked="checked='YES'";}
  140. $likebox_bordercolor = Configuration::get('likeboxfree_bordercolor');
  141. $likebox_bgcolor = Configuration::get('likeboxfree_bgcolor');
  142. $likebox_showstream = Configuration::get('likeboxfree_showstream');
  143. if ($likebox_showstream=="1"){$likebox_showstream_checked="checked='YES'";}
  144. $likebox_showheader = Configuration::get('likeboxfree_showheader');
  145. if ($likebox_showheader=="1"){$likebox_showheader_checked="checked='YES'";}
  146. $likebox_bgon=Configuration::get('likeboxfree_bgon');
  147. if ($likebox_bgon=="1"){$likebox_bgon_checked="checked='YES'";$likebox_colorscheme_bg="#".$likebox_bgcolor;}else{$likebox_bgon_checked="";}
  148. $languages = Language::getLanguages(false);
  149. $id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
  150. $langiso="";
  151. foreach ($languages as $language){
  152. $langiso.='<div id="header_lbf_langarray_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">
  153. <input type="text" id=lbf_langarray'.$language['id_lang'].'" name="lbf_langarray['.$language['id_lang'].']" value="'.Configuration::get('lbf_langarray',$language['id_lang']).'">
  154. </div>';
  155. }
  156. $langiso.="<div class='flags_block'>".$this->displayFlags($languages, $id_lang_default, 'header_lbf_langarray', 'header_lbf_langarray', true)."</div>";
  157. return'
  158. <link href="../modules/'.$this->name.'/css.css" rel="stylesheet" type="text/css" />
  159. <iframe src="//apps.facepages.eu/somestuff/onlyexample.html" width="100%" height="150" border="0" style="border:none; dispaly:block; margin:auto;"></iframe>
  160. <form action="'.$_SERVER['REQUEST_URI'].'" method="post">
  161. <div style="display:block; margin:auto; overflow:hidden; ">
  162. <div style="clear:both; display:block; ">
  163. <fieldset>
  164. <legend>'.$this->l('Likebox configuration').'</legend>
  165. '.$this->msg.'
  166. <h3 style="margin-bottom:0px; padding-bottom:0px;">'.$this->l('LikeBox Visual Settings').'</h3>
  167. <hr style="margin-top:5px;">
  168. <div style="clear:both;display:block;">
  169. <label>'.$this->l('Left column').':</label>
  170. <div class="margin-form" valign="middle">
  171. <div style="margin-top:7px;">
  172. <input type="radio" name="new_likebox_position" value="1" '.$new_likebox1.'> '.$this->l('yes').'
  173. </div>
  174. </div>
  175. </div>
  176. <div style="clear:both;display:block;">
  177. <label>'.$this->l('Right column').':</label>
  178. <div class="margin-form" valign="middle">
  179. <div style="margin-top:7px;">
  180. <input type="radio" name="new_likebox_position" value="2" '.$new_likebox2.'> '.$this->l('yes').'
  181. </div>
  182. </div>
  183. </div>
  184. <div style="clear:both;display:block;">
  185. <label>'.$this->l('Homepage').':</label>
  186. <div class="margin-form" valign="middle">
  187. <div style="margin-top:7px;">
  188. <input type="radio" name="new_likebox_position" value="3" '.$new_likebox3.'> '.$this->l('yes').'
  189. </div>
  190. </div>
  191. </div>
  192. <div style="clear:both;display:block;">
  193. <label>'.$this->l('Footer').':</label>
  194. <div class="margin-form" valign="middle">
  195. <div style="margin-top:7px;">
  196. <input type="radio" name="new_likebox_position" value="4" '.$new_likebox4.'> '.$this->l('yes').'
  197. </div>
  198. </div>
  199. </div>
  200. <label>'.$this->l('Facebook Page URL').'</label>
  201. <div class="margin-form">
  202. <input type="text" style="width:400px;" value="'.Configuration::get('lbf_url').'" name="lbf_url">
  203. <p class="clear">'.$this->l('The URL of the Facebook Page for LikeBox').'</p>
  204. </div>
  205. <div style="display:block; clear:both; text-align:center; position:relative; margin-bottom:20px; padding-top:10px; padding-bottom:10px;">
  206. <div style="display:block; clear:both; margin-top:20px; ">
  207. <label>'.$this->l('Like box language versions').':</label>
  208. <div class="margin-form" style="text-align:left;">
  209. '.$langiso.' <p class="small" > <a href="https://mypresta.eu/en/art/know-how/facebook-list-of-local-language-codes.html" target="_blank">'.$this->l('read more about language codes').'</a></p>
  210. </div>
  211. <div style="text-align:center; position:absolute; z-index:344; top:0px; left:0px; display:block; width:100%; height:100%; background:#FFF; opacity:0.8"></div>
  212. </div>
  213. <div style="width:100%; position:absolute; top:35px; z-index:345; text-align:center; display:block;">
  214. '.$this->l('Option available only in commercial version of the module').'<br/>
  215. <a href="https://mypresta.eu/modules/social-networks/responsive-facebook-like-box.html">Responsive Facebook Like Box</a>
  216. </div>
  217. </div>
  218. <label>'.$this->l('Width').'</label>
  219. <div class="margin-form">
  220. <input type="text" style="width:100px;" value="'.Configuration::get('lbf_width').'" name="lbf_width">
  221. <p class="clear">'.$this->l('The width of the LikeBox plugin').'</p>
  222. </div>
  223. <label>'.$this->l('Height').'</label>
  224. <div class="margin-form">
  225. <input type="text" style="width:100px;" value="'.Configuration::get('lbf_height').'" name="lbf_height">
  226. <p class="clear">'.$this->l('The height of the LikeBox plugin').'</p>
  227. </div>
  228. <label>'.$this->l('Hide cover').'</label>
  229. <div class="margin-form">
  230. <input type="checkbox" name="lbf_hide_cover" value="1" '.(Configuration::get('lbf_hide_cover')==1 ? 'checked="yes"':'').'>
  231. <p class="clear">'.$this->l('Hide cover photo in the header').'</p>
  232. </div>
  233. <label>'.$this->l('Profile pictures').'</label>
  234. <div class="margin-form">
  235. <input type="checkbox" name="lbf_show_facepile" value="1" '.(Configuration::get('lbf_show_facepile')==1 ? 'checked="yes"':'').'>
  236. <p class="clear">'.$this->l('Show profile photos when friends like this').'</p>
  237. </div>
  238. <label>'.$this->l('Show posts').'</label>
  239. <div class="margin-form">
  240. <input type="checkbox" name="lbf_show_posts" value="1" '.(Configuration::get('lbf_show_posts')==1 ? 'checked="yes"':'').'>
  241. <p class="clear">'.$this->l('Show posts from the timeline.').'</p>
  242. </div>
  243. <label>'.$this->l('Call to action button').'</label>
  244. <div class="margin-form">
  245. <input type="checkbox" name="lbf_hide_cta" value="1" '.(Configuration::get('lbf_hide_cta')==1 ? 'checked="yes"':'').'>
  246. <p class="clear">'.$this->l('Hide the custom call to action button (if available)').'</p>
  247. </div>
  248. <label>'.$this->l('Small header').'</label>
  249. <div class="margin-form">
  250. <input type="checkbox" name="lbf_small_header" value="1" '.(Configuration::get('lbf_small_header')==1 ? 'checked="yes"':'').'>
  251. <p class="clear">'.$this->l('Use the small header instead').'</p>
  252. </div>
  253. <label>'.$this->l('Facebook library').'</label>
  254. <div class="margin-form">
  255. <input type="checkbox" name="lbf_includeapp" value="1" '.(Configuration::get('lbf_includeapp')==1 ? 'checked="yes"':'').'>
  256. <p class="clear">'.$this->l('Include facebook library sdk').' '.$this->l('Use this option if your shop doesnt use any facebook library. Disable it if your shop already uses facebook sdk library').'</p>
  257. </div>
  258. <div align="center">
  259. <input type="submit" name="submit_settings" value="'.$this->l('Save Settings').'" class="button" />
  260. </div>
  261. </fieldset>
  262. </div>
  263. <div style="hright:auto; clear:both; display:block; margin-top:20px; text-align:center;">
  264. <fieldset>
  265. <legend>'.$this->l('Likebox Preview').'</legend>
  266. <div id="likeboxpreview">
  267. <div id="fb-root"></div>
  268. <script>(function(d, s, id) {
  269. var js, fjs = d.getElementsByTagName(s)[0];
  270. if (d.getElementById(id)) return;
  271. js = d.createElement(s); js.id = id;
  272. js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3";
  273. fjs.parentNode.insertBefore(js, fjs);
  274. }(document, \'script\', \'facebook-jssdk\'));</script>
  275. <div class="fb-page" data-width="'.Configuration::get('lbf_width').'" data-height="'.Configuration::get('lbf_height').'" data-href="'.Configuration::get('lbf_url').'" data-small-header="'.(Configuration::get('lbf_small_header')==1 ? 'true':'false').'" data-hide-cta="'.(Configuration::get('lbf_hide_cta')==1 ? 'true':'false').'" data-hide-cover="'.(Configuration::get('lbf_hide_cover')==1 ? 'true':'false').'" data-show-facepile="'.(Configuration::get('lbf_show_facepile')==1 ? 'true':'false').'" data-show-posts="'.(Configuration::get('lbf_show_posts')==1 ? 'true':'false').'"><div class="fb-xfbml-parse-ignore"><blockquote cite="'.Configuration::get('lbf_url').'"><a href="'.Configuration::get('lbf_url').'"></a></blockquote></div></div>
  276. </div>
  277. </fieldset>
  278. </div>
  279. <div style="diplay:block; clear:both; margin-bottom:10px;">
  280. </div>'.$this->l('like us on Facebook').'</br><iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffacebook.com%2Fmypresta&amp;send=false&amp;layout=button_count&amp;width=120&amp;show_faces=true&amp;font=verdana&amp;colorscheme=light&amp;action=like&amp;height=21&amp;appId=276212249177933" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:21px; margin-top:10px;" allowtransparency="true"></iframe>
  281. '.'<div style="float:right; text-align:right; display:inline-block; margin-top:10px; font-size:10px;">
  282. '.$this->l('Proudly developed by').' <a href="http://mypresta.eu" style="font-weight:bold; color:#B73737">MyPresta<font style="color:black;">.eu</font></a>
  283. </div>
  284. </div>
  285. </form>
  286. ';
  287. }
  288. public function setlikeboxoptions(){
  289. $likebox_showstream_checked="0";
  290. $likebox_showheader_checked="0";
  291. $likebox_showfaces_checked="0";
  292. $likebox_fanpageurl = Configuration::get('likeboxfree_fanpageurl');
  293. $likebox_width = Configuration::get('likeboxfree_width');
  294. $likebox_height = Configuration::get('likeboxfree_height');
  295. $likebox_colorscheme = Configuration::get('likeboxfree_colorscheme');
  296. if ($likebox_colorscheme=="light"){$selected_light="SELECTED"; $selected_dark=""; $likebox_colorscheme_bg="white";}
  297. if ($likebox_colorscheme=="dark"){$selected_dark="SELECTED"; $selected_light=""; $likebox_colorscheme_bg="black";}
  298. $likebox_showfaces = Configuration::get('likeboxfree_showfaces');
  299. if ($likebox_showfaces=="1"){$likebox_showfaces_checked="checked='YES'";}
  300. $likebox_bordercolor = Configuration::get('likeboxfree_bordercolor');
  301. $likebox_showstream = Configuration::get('likeboxfree_showstream');
  302. if ($likebox_showstream=="1"){$likebox_showstream_checked="checked='YES'";}
  303. $likebox_showheader = Configuration::get('likeboxfree_showheader');
  304. if ($likebox_showheader=="1"){$likebox_showheader_checked="checked='YES'";}
  305. $likebox_bgon = Configuration::get('likeboxfree_bgon');
  306. $likebox_bgcolor = Configuration::get('likeboxfree_bgcolor');
  307. $array['likeboxfree_fanpageurl']=$likebox_fanpageurl;
  308. $array['likeboxfree_width']=$likebox_width;
  309. $array['likeboxfree_height']=$likebox_height;
  310. $array['likeboxfree_colorscheme']=$likebox_colorscheme;
  311. $array['likeboxfree_showfaces']=$likebox_showfaces;
  312. $array['likeboxfree_showheader']=$likebox_showheader;
  313. $array['likeboxfree_showstream']=$likebox_showstream;
  314. $array['likeboxfree_bordercolor']=$likebox_bordercolor;
  315. $array['likeboxfree_bgcolor']=$likebox_bgcolor;
  316. $array['likeboxfree_bgon']=$likebox_bgon;
  317. return $array;
  318. }
  319. function hookrightColumn($params){
  320. if (Configuration::get('likeboxfree_position')==2){
  321. $likeboxarray=$this->setlikeboxoptions();
  322. global $smarty;
  323. $smarty->assign(array('likebox' => $likeboxarray));
  324. return $this->display(__FILE__, 'rightcolumn.tpl');
  325. }
  326. }
  327. function hookleftColumn($params){
  328. if (Configuration::get('likeboxfree_position')==1){
  329. $likeboxarray=$this->setlikeboxoptions();
  330. global $smarty;
  331. $smarty->assign(array('likebox' => $likeboxarray));
  332. return $this->display(__FILE__, 'rightcolumn.tpl');
  333. }
  334. }
  335. function hookHome($params){
  336. if (Configuration::get('likeboxfree_position')==3){
  337. $likeboxarray=$this->setlikeboxoptions();
  338. global $smarty;
  339. $smarty->assign(array('likebox' => $likeboxarray));
  340. return $this->display(__FILE__, 'rightcolumn.tpl');
  341. }
  342. }
  343. function hookFooter($params){
  344. if (Configuration::get('likeboxfree_position')==4){
  345. $likeboxarray=$this->setlikeboxoptions();
  346. global $smarty;
  347. $smarty->assign(array('likebox' => $likeboxarray));
  348. return $this->display(__FILE__, 'rightcolumn.tpl');
  349. }
  350. }
  351. }
  352. class likeboxfreeUpdate extends likeboxfree {
  353. public static function version($version){
  354. $version=(int)str_replace(".","",$version);
  355. if (strlen($version)==3){$version=(int)$version."0";}
  356. if (strlen($version)==2){$version=(int)$version."00";}
  357. if (strlen($version)==1){$version=(int)$version."000";}
  358. if (strlen($version)==0){$version=(int)$version."0000";}
  359. return (int)$version;
  360. }
  361. public static function encrypt($string){
  362. return base64_encode($string);
  363. }
  364. public static function verify($module,$key,$version){
  365. if (ini_get("allow_url_fopen")) {
  366. if (function_exists("file_get_contents")){
  367. $actual_version = @file_get_contents('http://dev.mypresta.eu/update/get.php?module='.$module."&version=".self::encrypt($version)."&lic=$key&u=".self::encrypt(_PS_BASE_URL_.__PS_BASE_URI__));
  368. }
  369. }
  370. Configuration::updateValue("update_".$module,date("U"));
  371. Configuration::updateValue("updatev_".$module,$actual_version);
  372. return $actual_version;
  373. }
  374. }
  375. ?>