Просмотр файла admin/admin_smilies.php

Размер файла: 15.61Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', 1);
  7.  
  8. if( !empty($setmodules) )
  9. {
  10. $filename = basename(__FILE__);
  11. $module['General']['Smilies'] = $filename;
  12.  
  13. return;
  14. }
  15.  
  16. $phpbb_root_path = "./../";
  17. require($phpbb_root_path . 'extension.inc');
  18.  
  19. $cancel = ( isset($HTTP_POST_VARS['cancel']) || isset($_POST['cancel']) ) ? true : false;
  20. $no_page_header = $cancel;
  21.  
  22. if ((!empty($HTTP_GET_VARS['export_pack']) && $HTTP_GET_VARS['export_pack'] == 'send') || (!empty($_GET['export_pack']) && $_GET['export_pack'] == 'send'))
  23. {
  24. $no_page_header = true;
  25. }
  26.  
  27. require('./pagestart.' . $phpEx);
  28.  
  29. if ($cancel)
  30. {
  31. redirect('admin/' . append_sid("admin_smilies.$phpEx", true));
  32. }
  33.  
  34. if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
  35. {
  36. $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  37. $mode = htmlspecialchars($mode);
  38. }
  39. else
  40. {
  41. $mode = "";
  42. }
  43.  
  44. $delimeter = '=+:';
  45.  
  46. $dir = @opendir($phpbb_root_path . $board_config['smilies_path']);
  47.  
  48. while($file = @readdir($dir))
  49. {
  50. if( !@is_dir(phpbb_realpath($phpbb_root_path . $board_config['smilies_path'] . '/' . $file)) )
  51. {
  52. $img_size = @getimagesize($phpbb_root_path . $board_config['smilies_path'] . '/' . $file);
  53.  
  54. if( $img_size[0] && $img_size[1] )
  55. {
  56. $smiley_images[] = $file;
  57. }
  58. else if( eregi('.pak$', $file) )
  59. {
  60. $smiley_paks[] = $file;
  61. }
  62. }
  63. }
  64.  
  65. @closedir($dir);
  66.  
  67. if( isset($HTTP_GET_VARS['import_pack']) || isset($HTTP_POST_VARS['import_pack']) )
  68. {
  69.  
  70. $smile_pak = ( isset($HTTP_POST_VARS['smile_pak']) ) ? $HTTP_POST_VARS['smile_pak'] : $HTTP_GET_VARS['smile_pak'];
  71. $clear_current = ( isset($HTTP_POST_VARS['clear_current']) ) ? $HTTP_POST_VARS['clear_current'] : $HTTP_GET_VARS['clear_current'];
  72. $replace_existing = ( isset($HTTP_POST_VARS['replace']) ) ? $HTTP_POST_VARS['replace'] : $HTTP_GET_VARS['replace'];
  73.  
  74. if ( !empty($smile_pak) )
  75. {
  76.  
  77. if( !empty($clear_current) )
  78. {
  79. $sql = "DELETE
  80. FROM " . SMILIES_TABLE;
  81. if( !$result = $db->sql_query($sql) )
  82. {
  83. message_die(GENERAL_ERROR, "Couldn't delete current smilies", "", __LINE__, __FILE__, $sql);
  84. }
  85. }
  86. else
  87. {
  88. $sql = "SELECT code
  89. FROM ". SMILIES_TABLE;
  90. if( !$result = $db->sql_query($sql) )
  91. {
  92. message_die(GENERAL_ERROR, "Couldn't get current smilies", "", __LINE__, __FILE__, $sql);
  93. }
  94.  
  95. $cur_smilies = $db->sql_fetchrowset($result);
  96.  
  97. for( $i = 0; $i < count($cur_smilies); $i++ )
  98. {
  99. $k = $cur_smilies[$i]['code'];
  100. $smiles[$k] = 1;
  101. }
  102. }
  103.  
  104. $fcontents = @file($phpbb_root_path . $board_config['smilies_path'] . '/'. $smile_pak);
  105.  
  106. if( empty($fcontents) )
  107. {
  108. message_die(GENERAL_ERROR, "Couldn't read smiley pak file", "", __LINE__, __FILE__, $sql);
  109. }
  110.  
  111. for( $i = 0; $i < count($fcontents); $i++ )
  112. {
  113. $smile_data = explode($delimeter, trim(addslashes($fcontents[$i])));
  114.  
  115. for( $j = 2; $j < count($smile_data); $j++)
  116. {
  117.  
  118. $smile_data[$j] = str_replace("<", "&lt;", $smile_data[$j]);
  119. $smile_data[$j] = str_replace(">", "&gt;", $smile_data[$j]);
  120. $k = $smile_data[$j];
  121.  
  122. if( $smiles[$k] == 1 )
  123. {
  124. if( !empty($replace_existing) )
  125. {
  126. $sql = "UPDATE " . SMILIES_TABLE . "
  127. SET smile_url = '" . str_replace("\'", "''", $smile_data[0]) . "', emoticon = '" . str_replace("\'", "''", $smile_data[1]) . "'
  128. WHERE code = '" . str_replace("\'", "''", $smile_data[$j]) . "'";
  129. }
  130. else
  131. {
  132. $sql = '';
  133. }
  134. }
  135. else
  136. {
  137. $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
  138. VALUES('" . str_replace("\'", "''", $smile_data[$j]) . "', '" . str_replace("\'", "''", $smile_data[0]) . "', '" . str_replace("\'", "''", $smile_data[1]) . "')";
  139. }
  140.  
  141. if( $sql != '' )
  142. {
  143. $result = $db->sql_query($sql);
  144. if( !$result )
  145. {
  146. message_die(GENERAL_ERROR, "Couldn't update smilies!", "", __LINE__, __FILE__, $sql);
  147. }
  148. }
  149. }
  150. }
  151.  
  152. $message = $lang['smiley_import_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
  153.  
  154. message_die(GENERAL_MESSAGE, $message);
  155. }
  156. else
  157. {
  158.  
  159. $smile_paks_select = "<select name='smile_pak'><option value=''>" . $lang['Select_pak'] . "</option>";
  160. while( list($key, $value) = @each($smiley_paks) )
  161. {
  162. if ( !empty($value) )
  163. {
  164. $smile_paks_select .= "<option>" . $value . "</option>";
  165. }
  166. }
  167. $smile_paks_select .= "</select>";
  168.  
  169. $hidden_vars = "<input type='hidden' name='mode' value='import'>";
  170.  
  171. $template->set_filenames(array(
  172. "body" => "admin/smile_import_body.tpl")
  173. );
  174.  
  175. $template->assign_vars(array(
  176. "L_SMILEY_TITLE" => $lang['smiley_title'],
  177. "L_SMILEY_EXPLAIN" => $lang['smiley_import_inst'],
  178. "L_SMILEY_IMPORT" => $lang['smiley_import'],
  179. "L_SELECT_LBL" => $lang['choose_smile_pak'],
  180. "L_IMPORT" => $lang['import'],
  181. "L_CONFLICTS" => $lang['smile_conflicts'],
  182. "L_DEL_EXISTING" => $lang['del_existing_smileys'],
  183. "L_REPLACE_EXISTING" => $lang['replace_existing'],
  184. "L_KEEP_EXISTING" => $lang['keep_existing'],
  185.  
  186. "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
  187. "S_SMILE_SELECT" => $smile_paks_select,
  188. "S_HIDDEN_FIELDS" => $hidden_vars)
  189. );
  190.  
  191. $template->pparse("body");
  192. }
  193. }
  194. else if( isset($HTTP_POST_VARS['export_pack']) || isset($HTTP_GET_VARS['export_pack']) )
  195. {
  196.  
  197. if ( $HTTP_GET_VARS['export_pack'] == "send" )
  198. {
  199. $sql = "SELECT *
  200. FROM " . SMILIES_TABLE;
  201. if( !$result = $db->sql_query($sql) )
  202. {
  203. message_die(GENERAL_ERROR, "Could not get smiley list", "", __LINE__, __FILE__, $sql);
  204. }
  205.  
  206. $resultset = $db->sql_fetchrowset($result);
  207.  
  208. $smile_pak = "";
  209. for($i = 0; $i < count($resultset); $i++ )
  210. {
  211. $smile_pak .= $resultset[$i]['smile_url'] . $delimeter;
  212. $smile_pak .= $resultset[$i]['emoticon'] . $delimeter;
  213. $smile_pak .= $resultset[$i]['code'] . "\n";
  214. }
  215.  
  216. header("Content-Type: text/x-delimtext; name=\"smiles.pak\"");
  217. header("Content-disposition: attachment; filename=smiles.pak");
  218.  
  219. echo $smile_pak;
  220.  
  221. exit;
  222. }
  223.  
  224. $message = sprintf($lang['export_smiles'], "<a href=\"" . append_sid("admin_smilies.$phpEx?export_pack=send", true) . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
  225.  
  226. message_die(GENERAL_MESSAGE, $message);
  227.  
  228. }
  229. else if( isset($HTTP_POST_VARS['add']) || isset($HTTP_GET_VARS['add']) )
  230. {
  231.  
  232. $template->set_filenames(array(
  233. "body" => "admin/smile_edit_body.tpl")
  234. );
  235.  
  236. $filename_list = "";
  237. for( $i = 0; $i < count($smiley_images); $i++ )
  238. {
  239. $filename_list .= '<option value="' . $smiley_images[$i] . '">' . $smiley_images[$i] . '</option>';
  240. }
  241.  
  242. $s_hidden_fields = '<input type="hidden" name="mode" value="savenew" />';
  243.  
  244. $template->assign_vars(array(
  245. "L_SMILEY_TITLE" => $lang['smiley_title'],
  246. "L_SMILEY_CONFIG" => $lang['smiley_config'],
  247. "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
  248. "L_SMILEY_CODE" => $lang['smiley_code'],
  249. "L_SMILEY_URL" => $lang['smiley_url'],
  250. "L_SMILEY_EMOTION" => $lang['smiley_emot'],
  251. "L_SUBMIT" => $lang['Submit'],
  252. "L_RESET" => $lang['Reset'],
  253.  
  254. "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_images[0],
  255.  
  256. "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
  257. "S_HIDDEN_FIELDS" => $s_hidden_fields,
  258. "S_FILENAME_OPTIONS" => $filename_list,
  259. "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
  260. );
  261.  
  262. $template->pparse("body");
  263. }
  264. else if ( $mode != "" )
  265. {
  266. switch( $mode )
  267. {
  268. case 'delete':
  269.  
  270. $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
  271. $smiley_id = intval($smiley_id);
  272.  
  273. $confirm = isset($HTTP_POST_VARS['confirm']);
  274.  
  275. if( $confirm )
  276. {
  277. $sql = "DELETE FROM " . SMILIES_TABLE . "
  278. WHERE smilies_id = " . $smiley_id;
  279. $result = $db->sql_query($sql);
  280. if( !$result )
  281. {
  282. message_die(GENERAL_ERROR, "Couldn't delete smiley", "", __LINE__, __FILE__, $sql);
  283. }
  284.  
  285. $message = $lang['smiley_del_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
  286.  
  287. message_die(GENERAL_MESSAGE, $message);
  288. }
  289. else
  290. {
  291. $template->set_filenames(array(
  292. 'body' => 'admin/confirm_body.tpl')
  293. );
  294.  
  295. $hidden_fields = '<input type="hidden" name="mode" value="delete" /><input type="hidden" name="id" value="' . $smiley_id . '" />';
  296.  
  297. $template->assign_vars(array(
  298. 'MESSAGE_TITLE' => $lang['Confirm'],
  299. 'MESSAGE_TEXT' => $lang['Confirm_delete_smiley'],
  300.  
  301. 'L_YES' => $lang['Yes'],
  302. 'L_NO' => $lang['No'],
  303.  
  304. 'S_CONFIRM_ACTION' => append_sid("admin_smilies.$phpEx"),
  305. 'S_HIDDEN_FIELDS' => $hidden_fields)
  306. );
  307. $template->pparse('body');
  308. }
  309. break;
  310.  
  311. case 'edit':
  312.  
  313. $smiley_id = ( !empty($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
  314. $smiley_id = intval($smiley_id);
  315.  
  316. $sql = "SELECT *
  317. FROM " . SMILIES_TABLE . "
  318. WHERE smilies_id = " . $smiley_id;
  319. $result = $db->sql_query($sql);
  320. if( !$result )
  321. {
  322. message_die(GENERAL_ERROR, 'Could not obtain emoticon information', "", __LINE__, __FILE__, $sql);
  323. }
  324. $smile_data = $db->sql_fetchrow($result);
  325.  
  326. $filename_list = "";
  327. for( $i = 0; $i < count($smiley_images); $i++ )
  328. {
  329. if( $smiley_images[$i] == $smile_data['smile_url'] )
  330. {
  331. $smiley_selected = "selected=\"selected\"";
  332. $smiley_edit_img = $smiley_images[$i];
  333. }
  334. else
  335. {
  336. $smiley_selected = "";
  337. }
  338.  
  339. $filename_list .= '<option value="' . $smiley_images[$i] . '"' . $smiley_selected . '>' . $smiley_images[$i] . '</option>';
  340. }
  341.  
  342. $template->set_filenames(array(
  343. "body" => "admin/smile_edit_body.tpl")
  344. );
  345.  
  346. $s_hidden_fields = '<input type="hidden" name="mode" value="save" /><input type="hidden" name="smile_id" value="' . $smile_data['smilies_id'] . '" />';
  347.  
  348. $template->assign_vars(array(
  349. "SMILEY_CODE" => $smile_data['code'],
  350. "SMILEY_EMOTICON" => $smile_data['emoticon'],
  351.  
  352. "L_SMILEY_TITLE" => $lang['smiley_title'],
  353. "L_SMILEY_CONFIG" => $lang['smiley_config'],
  354. "L_SMILEY_EXPLAIN" => $lang['smile_desc'],
  355. "L_SMILEY_CODE" => $lang['smiley_code'],
  356. "L_SMILEY_URL" => $lang['smiley_url'],
  357. "L_SMILEY_EMOTION" => $lang['smiley_emot'],
  358. "L_SUBMIT" => $lang['Submit'],
  359. "L_RESET" => $lang['Reset'],
  360.  
  361. "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smiley_edit_img,
  362.  
  363. "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"),
  364. "S_HIDDEN_FIELDS" => $s_hidden_fields,
  365. "S_FILENAME_OPTIONS" => $filename_list,
  366. "S_SMILEY_BASEDIR" => $phpbb_root_path . $board_config['smilies_path'])
  367. );
  368.  
  369. $template->pparse("body");
  370. break;
  371.  
  372. case "save":
  373.  
  374. $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? trim($HTTP_POST_VARS['smile_code']) : '';
  375. $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? trim($HTTP_POST_VARS['smile_url']) : '';
  376. $smile_url = phpbb_ltrim(basename($smile_url), "'");
  377. $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? htmlspecialchars(trim($HTTP_POST_VARS['smile_emotion'])) : '';
  378. $smile_id = ( isset($HTTP_POST_VARS['smile_id']) ) ? intval($HTTP_POST_VARS['smile_id']) : 0;
  379. $smile_code = trim($smile_code);
  380. $smile_url = trim($smile_url);
  381.  
  382. if ($smile_code == '' || $smile_url == '')
  383. {
  384. message_die(GENERAL_MESSAGE, $lang['Fields_empty']);
  385. }
  386.  
  387. $smile_code = str_replace('<', '&lt;', $smile_code);
  388. $smile_code = str_replace('>', '&gt;', $smile_code);
  389.  
  390. $sql = "UPDATE " . SMILIES_TABLE . "
  391. SET code = '" . str_replace("\'", "''", $smile_code) . "', smile_url = '" . str_replace("\'", "''", $smile_url) . "', emoticon = '" . str_replace("\'", "''", $smile_emotion) . "'
  392. WHERE smilies_id = $smile_id";
  393. if( !($result = $db->sql_query($sql)) )
  394. {
  395. message_die(GENERAL_ERROR, "Couldn't update smilies info", "", __LINE__, __FILE__, $sql);
  396. }
  397.  
  398. $message = $lang['smiley_edit_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
  399.  
  400. message_die(GENERAL_MESSAGE, $message);
  401. break;
  402.  
  403. case "savenew":
  404.  
  405. $smile_code = ( isset($HTTP_POST_VARS['smile_code']) ) ? $HTTP_POST_VARS['smile_code'] : '';
  406. $smile_url = ( isset($HTTP_POST_VARS['smile_url']) ) ? $HTTP_POST_VARS['smile_url'] : '';
  407. $smile_url = phpbb_ltrim(basename($smile_url), "'");
  408. $smile_emotion = ( isset($HTTP_POST_VARS['smile_emotion']) ) ? htmlspecialchars(trim($HTTP_POST_VARS['smile_emotion'])) : '';
  409. $smile_code = trim($smile_code);
  410. $smile_url = trim($smile_url);
  411.  
  412. if ($smile_code == '' || $smile_url == '')
  413. {
  414. message_die(GENERAL_MESSAGE, $lang['Fields_empty']);
  415. }
  416.  
  417. $sql = "INSERT INTO " . SMILIES_TABLE . " (code, smile_url, emoticon)
  418. VALUES ('" . str_replace("\'", "''", $smile_code) . "', '" . str_replace("\'", "''", $smile_url) . "', '" . str_replace("\'", "''", $smile_emotion) . "')";
  419. $result = $db->sql_query($sql);
  420. if( !$result )
  421. {
  422. message_die(GENERAL_ERROR, "Couldn't insert new smiley", "", __LINE__, __FILE__, $sql);
  423. }
  424.  
  425. $message = $lang['smiley_add_success'] . "<br /><br />" . sprintf($lang['Click_return_smileadmin'], "<a href=\"" . append_sid("admin_smilies.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
  426.  
  427. message_die(GENERAL_MESSAGE, $message);
  428. break;
  429. }
  430. }
  431. else
  432. {
  433.  
  434. $sql = "SELECT *
  435. FROM " . SMILIES_TABLE;
  436. $result = $db->sql_query($sql);
  437. if( !$result )
  438. {
  439. message_die(GENERAL_ERROR, "Couldn't obtain smileys from database", "", __LINE__, __FILE__, $sql);
  440. }
  441.  
  442. $smilies = $db->sql_fetchrowset($result);
  443.  
  444. $template->set_filenames(array(
  445. "body" => "admin/smile_list_body.tpl")
  446. );
  447.  
  448. $template->assign_vars(array(
  449. "L_ACTION" => $lang['Action'],
  450. "L_SMILEY_TITLE" => $lang['smiley_title'],
  451. "L_SMILEY_TEXT" => $lang['smile_desc'],
  452. "L_DELETE" => $lang['Delete'],
  453. "L_EDIT" => $lang['Edit'],
  454. "L_SMILEY_ADD" => $lang['smile_add'],
  455. "L_CODE" => $lang['Code'],
  456. "L_EMOT" => $lang['Emotion'],
  457. "L_SMILE" => $lang['Smile'],
  458. "L_IMPORT_PACK" => $lang['import_smile_pack'],
  459. "L_EXPORT_PACK" => $lang['export_smile_pack'],
  460. "S_HIDDEN_FIELDS" => $s_hidden_fields,
  461. "S_SMILEY_ACTION" => append_sid("admin_smilies.$phpEx"))
  462. );
  463.  
  464. for($i = 0; $i < count($smilies); $i++)
  465. {
  466.  
  467. $smilies[$i]['code'] = str_replace('&lt;', '<', $smilies[$i]['code']);
  468. $smilies[$i]['code'] = str_replace('&gt;', '>', $smilies[$i]['code']);
  469. $row_color = '';
  470. $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';
  471.  
  472. $template->assign_block_vars("smiles", array(
  473. "ROW_COLOR" => "#" . $row_color,
  474. "ROW_CLASS" => $row_class,
  475. "SMILEY_IMG" => $phpbb_root_path . $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'],
  476. "CODE" => $smilies[$i]['code'],
  477. "EMOT" => $smilies[$i]['emoticon'],
  478. "U_SMILEY_EDIT" => append_sid("admin_smilies.$phpEx?mode=edit&amp;id=" . $smilies[$i]['smilies_id']),
  479. "U_SMILEY_DELETE" => append_sid("admin_smilies.$phpEx?mode=delete&amp;id=" . $smilies[$i]['smilies_id']))
  480. );
  481. }
  482.  
  483. $template->pparse("body");
  484. }
  485.  
  486. include('./page_footer_admin.'.$phpEx);
  487.  
  488. ?>