Guest User

Untitled

a guest
Jan 7th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.33 KB | None | 0 0
  1. <?php
  2. /*
  3. =====================================================
  4.  DataLife Engine - by SoftNews Media Group
  5. -----------------------------------------------------
  6.  http://dle-news.ru/
  7. -----------------------------------------------------
  8.  Copyright (c) 2004,2012 SoftNews Media Group
  9. =====================================================
  10.  Данный код защищен авторскими правами
  11. =====================================================
  12.  Файл: xfields.php
  13. -----------------------------------------------------
  14.  Назначение: управление дополнительными полями
  15. =====================================================
  16. */
  17. if(!defined('DATALIFEENGINE'))
  18. {
  19.   die("Hacking attempt!");
  20. }
  21.  
  22. if (!isset($xfieldsaction)) $xfieldsaction = $_REQUEST['xfieldsaction'];
  23. if (isset ( $_REQUEST['xfieldssubactionadd'] )) $xfieldssubactionadd = $_REQUEST['xfieldssubactionadd'];
  24. if (isset ( $_REQUEST['xfieldssubaction'] )) $xfieldssubaction = $_REQUEST['xfieldssubaction'];
  25. if (isset ( $_REQUEST['xfieldsindex'] )) $xfieldsindex = intval($_REQUEST['xfieldsindex']);
  26. if (isset ( $_REQUEST['editedxfield'] )) $editedxfield = $_REQUEST['editedxfield'];
  27.  
  28. if (isset ($xfieldssubactionadd))
  29. if ($xfieldssubactionadd == "add") {
  30.   $xfieldssubaction = $xfieldssubactionadd;
  31. }
  32.  
  33. if (!isset($xf_inited)) $xf_inited = "";
  34.  
  35. if ($xf_inited !== true) { // Prevent "Cannot redeclare" error
  36.  
  37. function xfieldssave($data) {
  38.     global $lang, $dle_login_hash;
  39.  
  40.     if ($_REQUEST['user_hash'] == "" OR $_REQUEST['user_hash'] != $dle_login_hash) {
  41.  
  42.           die("Hacking attempt! User not found");
  43.  
  44.     }
  45.  
  46.     $data = array_values($data);
  47.     $filecontents = "";
  48.  
  49.     foreach ($data as $index => $value) {
  50.       $value = array_values($value);
  51.       foreach ($value as $index2 => $value2) {
  52.         $value2 = stripslashes($value2);
  53.         $value2 = str_replace("|", "&#124;", $value2);
  54.         $value2 = str_replace("\r\n", "__NEWL__", $value2);
  55.         $filecontents .= $value2 . ($index2 < count($value) - 1 ? "|" : "");
  56.       }
  57.       $filecontents .= ($index < count($data) - 1 ? "\r\n" : "");
  58.     }
  59.  
  60.     $filehandle = fopen(ENGINE_DIR.'/data/xfields.txt', "w+");
  61.     if (!$filehandle)
  62.     msg("error", $lang['xfield_error'], "$lang[xfield_err_1] \"".ENGINE_DIR."/data/xfields.txt\", $lang[xfield_err_1]");
  63.  
  64.     $find = array ('/data:/i', '/about:/i', '/vbscript:/i', '/onclick/i', '/onload/i', '/onunload/i', '/onabort/i', '/onerror/i', '/onblur/i', '/onchange/i', '/onfocus/i', '/onreset/i', '/onsubmit/i', '/ondblclick/i', '/onkeydown/i', '/onkeypress/i', '/onkeyup/i', '/onmousedown/i', '/onmouseup/i', '/onmouseover/i', '/onmouseout/i', '/onselect/i', '/javascript/i', '/javascript/i' );
  65.     $replace = array ("d&#097;ta:", "&#097;bout:", "vbscript<b></b>:", "&#111;nclick", "&#111;nload", "&#111;nunload", "&#111;nabort", "&#111;nerror", "&#111;nblur", "&#111;nchange", "&#111;nfocus", "&#111;nreset", "&#111;nsubmit", "&#111;ndblclick", "&#111;nkeydown", "&#111;nkeypress", "&#111;nkeyup", "&#111;nmousedown", "&#111;nmouseup", "&#111;nmouseover", "&#111;nmouseout", "&#111;nselect", "j&#097;vascript" );
  66.    
  67.     $filecontents = preg_replace( $find, $replace, $filecontents );
  68.     $filecontents = preg_replace( "#<iframe#i", "&lt;iframe", $filecontents );
  69.     $filecontents = preg_replace( "#<script#i", "&lt;script", $filecontents );
  70.     $filecontents = str_replace( "<?", "&lt;?", $filecontents );
  71.     $filecontents = str_replace( "?>", "?&gt;", $filecontents );
  72.     $filecontents = str_replace( "$", "&#036;", $filecontents );
  73.  
  74.     fwrite($filehandle, $filecontents);
  75.     fclose($filehandle);
  76.     header("Location: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] .
  77.         "?mod=xfields&xfieldsaction=configure");
  78.     exit;
  79. }
  80.  
  81. ////////////
  82. // Move an array item
  83. function array_move(&$array, $index1, $dist) {
  84.     $index2 = $index1 + $dist;
  85.     if ($index1 < 0 or
  86.         $index1 > count($array) - 1 or
  87.         $index2 < 0 or
  88.         $index2 > count($array) - 1) {
  89.       return false;
  90.     }
  91.     $value1 = $array[$index1];
  92.  
  93.     $array[$index1] = $array[$index2];
  94.     $array[$index2] = $value1;
  95.  
  96.     return true;
  97.   }
  98.  
  99.   $xf_inited = true;
  100. }
  101.  
  102. $xfields = xfieldsload();
  103. switch ($xfieldsaction) {
  104.   case "configure":
  105.  
  106.     if( ! $user_group[$member_id['user_group']]['admin_xfields'] ) {
  107.         msg( "error", $lang['index_denied'], $lang['index_denied'] );
  108.     }
  109.  
  110.     switch ($xfieldssubaction) {
  111.       case "delete":
  112.         if (!isset($xfieldsindex)) {
  113.           msg("error", $lang['xfield_error'], $lang['xfield_err_5'],"javascript:history.go(-1)");
  114.         }
  115.         msg("options", "info", "$lang[xfield_err_6]<br /><br /><a href=\"$PHP_SELF?mod=xfields&amp;xfieldsaction=configure&amp;xfieldsindex=$xfieldsindex&amp;xfieldssubaction=delete2&user_hash={$dle_login_hash}\">[$lang[opt_sys_yes]]</a>&nbsp;&nbsp;<a href=\"$PHP_SELF?mod=xfields&amp;xfieldsaction=configure\">[$lang[opt_sys_no]]</a>");
  116.         break;
  117.       case "delete2":
  118.         if (!isset($xfieldsindex)) {
  119.           msg("error", $lang['xfield_error'], $lang['xfield_err_5'],"javascript:history.go(-1)");
  120.         }
  121.         $db->query( "INSERT INTO " . USERPREFIX . "_admin_logs (name, date, ip, action, extras) values ('".$db->safesql($member_id['name'])."', '{$_TIME}', '{$_IP}', '73', '{$xfields[$xfieldsindex][0]}')" );
  122.  
  123.         unset($xfields[$xfieldsindex]);
  124.         @xfieldssave($xfields);
  125.         break;
  126.       case "moveup":
  127.         if (!isset($xfieldsindex)) {
  128.           msg("error", $lang['xfield_error'], $lang['xfield_err_7'],"javascript:history.go(-1)");
  129.         }
  130.         array_move($xfields, $xfieldsindex, -1);
  131.         @xfieldssave($xfields);
  132.         break;
  133.       case "movedown":
  134.         if (!isset($xfieldsindex)) {
  135.           msg("error", $lang['xfield_error'], $lang['xfield_err_7'],"javascript:history.go(-1)");
  136.         }
  137.         array_move($xfields, $xfieldsindex, +1);
  138.         @xfieldssave($xfields);
  139.         break;
  140.       case "add":
  141.         $xfieldsindex = count($xfields);
  142.         // Fall trough to edit
  143.       case "edit":
  144.         if (!isset($xfieldsindex)) {
  145.           msg("error", $lang['xfield_error'], $lang['xfield_err_8'],"javascript:history.go(-1)");
  146.         }
  147.    
  148.         if (!$editedxfield) {
  149.           $editedxfield = $xfields[$xfieldsindex];
  150.         } elseif (strlen(trim($editedxfield[0])) > 0 and
  151.             strlen(trim($editedxfield[1])) > 0) {
  152.           foreach ($xfields as $name => $value) {
  153.             if ($name != $xfieldsindex and
  154.                 $value[0] == $editedxfield[0]) {
  155.               msg("error", $lang['xfield_error'], $lang['xfield_err_9'],"javascript:history.go(-1)");
  156.             }
  157.           }
  158.           $editedxfield[0] = totranslit(trim($editedxfield[0]));
  159.  
  160.             $db->query( "INSERT INTO " . USERPREFIX . "_admin_logs (name, date, ip, action, extras) values ('".$db->safesql($member_id['name'])."', '{$_TIME}', '{$_IP}', '74', '{$editedxfield[0]}')" );
  161.  
  162.           if (!count($editedxfield[2])) $editedxfield[2][0] ="";
  163.           elseif (count($editedxfield[2]) > 1 AND $editedxfield[2][0] == "") unset($editedxfield[2][0]);
  164.  
  165.             $category_list = array();
  166.        
  167.             foreach ( $editedxfield[2] as $catval ) {
  168.                 if($catval) $category_list[] = intval($catval);
  169.             }
  170.  
  171.           $editedxfield[2]  = implode(',', $category_list);
  172.  
  173.           $editedxfield[3] = totranslit(trim($editedxfield[3]));
  174.  
  175.           if ($editedxfield[3] == "select") {
  176.             $options = array();
  177.             foreach (explode("\r\n", $editedxfield["4_select"]) as $name => $value) {
  178.               $value = trim($value);
  179.               if (!in_array($value, $options)) {
  180.                 $options[] = $value;
  181.               }
  182.             }
  183.             if (count($options) < 2) {
  184.             msg("error", $lang['xfield_error'], $lang['xfield_err_10'],"javascript:history.go(-1)");
  185.             }
  186.             $editedxfield[4] = implode("\r\n", $options);
  187.           } else {
  188.             $editedxfield[4] = $editedxfield["4_{$editedxfield[3]}"];
  189.           }
  190.           unset($editedxfield["2_custom"], $editedxfield["4_text"], $editedxfield["4_textarea"], $editedxfield["4_select"]);
  191.           if ($editedxfield[3] == "select") {
  192.             $editedxfield[5] = 0;
  193.           } else {
  194.             $editedxfield[5] = ($editedxfield[5] == "on" ? 1 : 0);
  195.           }
  196.  
  197.           if ($editedxfield[3] == "text") {
  198.             $editedxfield[6] = ($editedxfield[6] == "on" ? 1 : 0);
  199.           } else $editedxfield[6] = 0;
  200.  
  201.           ksort($editedxfield);
  202.          
  203.           $xfields[$xfieldsindex] = $editedxfield;
  204.           ksort($xfields);
  205.           @xfieldssave($xfields);
  206.           break;
  207.         } else {
  208.           msg("error", $lang['xfield_error'], $lang['xfield_err_11'],"javascript:history.go(-1)");
  209.         }
  210.         echoheader("options", (($xfieldssubaction == "add") ? $lang['xfield_addh'] : $lang['xfield_edith']) . " " . $lang['xfield_fih']);
  211.         $checked = ($editedxfield[5] ? " checked" : "");
  212.         $checked2 = ($editedxfield[6] ? " checked" : "");
  213. ?>
  214.     <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="xfieldsform">
  215.       <script language="javascript">
  216.       function ShowOrHideEx(id, show) {
  217.         var item = null;
  218.         if (document.getElementById) {
  219.           item = document.getElementById(id);
  220.         } else if (document.all) {
  221.           item = document.all[id];
  222.         } else if (document.layers){
  223.           item = document.layers[id];
  224.         }
  225.         if (item && item.style) {
  226.           item.style.display = show ? "" : "none";
  227.         }
  228.       }
  229.       function onTypeChange(value) {
  230.         ShowOrHideEx("default_text", value == "text");
  231.         ShowOrHideEx("optional2", value == "text");
  232.         ShowOrHideEx("default_textarea", value == "textarea");
  233.         ShowOrHideEx("select_options", value == "select");
  234.         ShowOrHideEx("optional", value != "select");
  235.       }
  236.       function onCategoryChange(value) {
  237.         ShowOrHideEx("category_custom", value == "custom");
  238.       }
  239.       </script>
  240.       <input type="hidden" name="mod" value="xfields">
  241.       <input type="hidden" name="user_hash" value="<?php echo $dle_login_hash; ?>">
  242.       <input type="hidden" name="xfieldsaction" value="configure">
  243.       <input type="hidden" name="xfieldssubaction" value="edit">
  244.       <input type="hidden" name="xfieldsindex" value="<?php echo $xfieldsindex; ?>">
  245.  
  246. <div style="padding-top:5px;padding-bottom:2px;">
  247. <table width="100%">
  248.     <tr>
  249.         <td width="4"><img src="engine/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
  250.         <td background="engine/skins/images/tl_oo.gif"><img src="engine/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
  251.         <td width="6"><img src="engine/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
  252.     </tr>
  253.     <tr>
  254.         <td background="engine/skins/images/tl_lb.gif"><img src="engine/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
  255.         <td style="padding:5px;" bgcolor="#FFFFFF">
  256. <table width="100%">
  257.     <tr>
  258.         <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation"><?php echo $lang['xfield_title']; ?></div></td>
  259.     </tr>
  260. </table>
  261. <div class="unterline"></div>
  262. <table width="100%">
  263.     <tr>
  264.         <td width="200" style="padding:4px;"><?php echo $lang['xfield_xname']; ?></td>
  265.         <td><input class=edit style="width: 312px;" type="text" name="editedxfield[0]" value="<?php echo $editedxfield[0];?>" />&nbsp;&nbsp;&nbsp;(<?php echo $lang['xf_lat']; ?>)</td>
  266.     </tr>
  267.     <tr>
  268.         <td style="padding:4px;"><?php echo $lang['xfield_xdescr']; ?></td>
  269.         <td><input  class=edit style="width: 312px;" type="text" name="editedxfield[1]" value="<?php echo $editedxfield[1];?>" /></td>
  270.     </tr>
  271. <?php
  272.         $cat_options = CategoryNewsSelection(explode (',', $editedxfield[2]), 0, FALSE);
  273.         if ($editedxfield[2] == "") $cats_value = "selected"; else $cats_value = "";
  274.  
  275. echo <<<HTML
  276.     <tr>
  277.         <td style="padding:4px;">{$lang['xfield_xcat']}</td>
  278.         <td><select name="editedxfield[2][]" id="category" class="cat_select" multiple><option value="" {$cats_value}>{$lang['xfield_xall']}</option>{$cat_options}</select></td>
  279.         </tr>
  280. HTML;
  281.  
  282. ?>
  283.     <tr>
  284.         <td style="padding:4px;"><?php echo $lang['xfield_xtype']; ?></td>
  285.         <td><select name="editedxfield[3]" id="type" onchange="onTypeChange(this.value)" />
  286.           <option value="text"<?php if($editedxfield[3] != "textarea") echo " selected"; else echo "";?>><?php echo $lang['xfield_xstr']; ?></option>
  287.           <option value="textarea"<?php echo ($editedxfield[3] == "textarea") ? " selected" : "";?>><?php echo $lang['xfield_xarea']; ?></option>
  288.           <option value="select"<?php echo ($editedxfield[3] == "select") ? " selected" : "";?>><?php echo $lang['xfield_xsel']; ?></option>
  289.         </select></td>
  290.     </tr>
  291.     <tr id="default_text">
  292.         <td style="padding:4px;"><?php echo $lang['xfield_xfaul']; ?></td>
  293.         <td><input class=edit style="width: 320px;" type="text" name="editedxfield[4_text]" value="<?php if ($editedxfield[3] == "text") echo htmlspecialchars($editedxfield[4]); else echo ""; ?>" /></td>
  294.     </tr>
  295.     <tr id="default_textarea">
  296.         <td style="padding:4px;"><?php echo $lang['xfield_xfaul']; ?></td>
  297.         <td><textarea style="width: 320px; height: 100px;" name="editedxfield[4_textarea]"><?php echo ($editedxfield[3] == "textarea") ? $editedxfield[4] : "";?></textarea></td>
  298.     </tr>
  299.     <tr id="select_options">
  300.         <td style="padding:4px;"><?php echo $lang['xfield_xfaul']; ?></td>
  301.         <td><textarea style="width: 320px; height: 100px;" name="editedxfield[4_select]"><?php echo ($editedxfield[3] == "select") ? $editedxfield[4] : "";?></textarea><br><?php echo $lang['xfield_xfsel']; ?></td>
  302.     </tr>
  303.     <tr>
  304.         <td colspan=2><div class="hr_line"></div></td>
  305.     </tr>
  306.     <tr>
  307.         <td colspan=2><div id="optional">
  308.       <span><input type="checkbox" name="editedxfield[5]"<?php echo $checked; ?> id="editxfive" />
  309.     <label for="editxfive"> <?php echo $lang['xfield_xw']; ?></label></span></div>
  310.     <div id="optional2">
  311.       <span><input type="checkbox" name="editedxfield[6]"<?php echo $checked2; ?> id="editxsixt" />
  312.     <label for="editxsixt"> <?php echo $lang['xfield_xw2']; ?><a href="#" class="hintanchor" onMouseover="showhint('<?php echo $lang['xfield_xw3']; ?>', this, event, '420px')">[?]</a></label></span></div></td>
  313.     </tr>
  314.     <tr>
  315.         <td colspan=2 style="padding:4px;"><input type="submit" class="buttons" value="&nbsp;&nbsp;<?php echo $lang['user_save']; ?>&nbsp;&nbsp;"></td>
  316.     </tr>
  317. </table>
  318. </td>
  319.         <td background="engine/skins/images/tl_rb.gif"><img src="engine/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
  320.     </tr>
  321.     <tr>
  322.         <td><img src="engine/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
  323.         <td background="engine/skins/images/tl_ub.gif"><img src="engine/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
  324.         <td><img src="engine/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
  325.     </tr>
  326. </table>
  327. </div>
  328.     </form>
  329.     <script type="text/javascript">
  330.     <!--
  331.       var item_type = null;
  332.       var item_category = null;
  333.       if (document.getElementById) {
  334.         item_type = document.getElementById("type");
  335.         item_category = document.getElementById("category");
  336.       } else if (document.all) {
  337.         item_type = document.all["type"];
  338.         item_category = document.all["category"];
  339.       } else if (document.layers) {
  340.         item_type = document.layers["type"];
  341.         item_category = document.layers["category"];
  342.       }
  343.       if (item_type) {
  344.         onTypeChange(item_type.value);
  345.         onCategoryChange(item_category.value);
  346.       }
  347.     // -->
  348.     </script>
  349. <?php
  350.         echofooter();
  351.         break;
  352.  
  353.       default:
  354.         echoheader("options", "");
  355. ?>
  356. <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="get" name="xfieldsform">
  357. <input type="hidden" name="mod" value="xfields">
  358. <input type="hidden" name="xfieldsaction" value="configure">
  359. <input type="hidden" name="xfieldssubactionadd" value="">
  360. <input type="hidden" name="user_hash" value="<?php echo $dle_login_hash; ?>">
  361. <div style="padding-top:5px;padding-bottom:2px;">
  362. <table width="100%">
  363.     <tr>
  364.         <td width="4"><img src="engine/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
  365.         <td background="engine/skins/images/tl_oo.gif"><img src="engine/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
  366.         <td width="6"><img src="engine/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
  367.     </tr>
  368.     <tr>
  369.         <td background="engine/skins/images/tl_lb.gif"><img src="engine/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
  370.         <td style="padding:5px;" bgcolor="#FFFFFF">
  371. <table width="100%">
  372.     <tr>
  373.         <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation"><?php echo $lang['xfield_xlist']; ?></div></td>
  374.     </tr>
  375. </table>
  376. <div class="unterline"></div>
  377. <table width="100%">
  378.   <tr>
  379.     <td style="padding:5px;">
  380.       <B><?php echo $lang['xfield_xname']; ?></B>
  381.     </td>
  382.     <td>
  383.       <B><?php echo $lang['xfield_xcat']; ?></B>
  384.     </td>
  385.     <td>
  386.       <B><?php echo $lang['xfield_xtype']; ?></B>
  387.     </td>
  388.     <td>
  389.       <B><?php echo $lang['xfield_xwt']; ?></B>
  390.     </td>
  391.     <td width=10>&nbsp;
  392.     </td>
  393.   </tr>
  394.     <tr>
  395.         <td colspan=5><div class="hr_line"></div></td>
  396.     </tr>
  397. <?php
  398.         if (count($xfields) == 0) {
  399.           echo "<tr><td colspan=\"5\" align=\"center\"><br /><br />$lang[xfield_xnof]</td></tr>";
  400.         } else {
  401.           foreach ($xfields as $name => $value) {
  402. ?>
  403.         <tr>
  404.           <td style="padding:2px;">
  405.             <?php echo $value[0]; ?>
  406.           </td>
  407.           <td>
  408.             <?php echo (trim($value[2]) ? $value[2] : $lang['xfield_xall']); ?>
  409.           </td>
  410.           <td>
  411.             <?php echo (($value[3] == "text") ? $lang['xfield_xstr'] : ""); ?>
  412.             <?php echo (($value[3] == "textarea") ? $lang['xfield_xarea'] : ""); ?>
  413.             <?php echo (($value[3] == "select") ? $lang['xfield_xsel'] : ""); ?>
  414.           </td>
  415.           <td>
  416.             <?php echo ($value[5] != 0 ? $lang['opt_sys_yes'] : $lang['opt_sys_no']); ?>
  417.           </td>
  418.           <td>
  419.             <input type="radio" name="xfieldsindex" value="<?php echo $name; ?>">
  420.           </td>
  421.         </tr><tr><td background="engine/skins/images/mline.gif" height=1 colspan=5></td></tr>
  422. <?php
  423.           }
  424.         }
  425. ?>
  426.     <tr>
  427.         <td colspan=5><div class="hr_line"></div></td>
  428.     </tr>
  429.       <tr>
  430.         <td ><a class=main onClick="javascript:Help('xfields')" href="#"><?php echo $lang['xfield_xhelp']; ?></a></td>
  431.         <td colspan="4" class="main" style="text-align: right; padding-top: 10px;">
  432.           <?php if (count($xfields) > 0) { ?>
  433.           <?php echo $lang['xfield_xact']; ?>:
  434.           <select name="xfieldssubaction">
  435.             <option value="edit"><?php echo $lang['xfield_xedit']; ?></option>
  436.             <option value="delete"><?php echo $lang['xfield_xdel']; ?></option>
  437.             <option value="moveup"><?php echo $lang['xfield_xo']; ?></option>
  438.             <option value="movedown"><?php echo $lang['xfield_xu']; ?></option>
  439.           </select>
  440.           <input type="submit" class="buttons" value="&nbsp;&nbsp;<?php echo $lang['b_start']; ?>&nbsp;&nbsp;" onclick="document.forms['xfieldsform'].xfieldssubactionadd.value = '';">
  441.           <?php } ?>
  442.           <input type="submit" class="buttons" value="&nbsp;&nbsp;<?php echo $lang['b_create']; ?>&nbsp;&nbsp;" onclick="document.forms['xfieldsform'].xfieldssubactionadd.value = 'add';">
  443.         </td>
  444.       </tr>
  445. </table>
  446. </td>
  447.         <td background="engine/skins/images/tl_rb.gif"><img src="engine/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
  448.     </tr>
  449.     <tr>
  450.         <td><img src="engine/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
  451.         <td background="engine/skins/images/tl_ub.gif"><img src="engine/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
  452.         <td><img src="engine/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
  453.     </tr>
  454. </table>
  455. </div>
  456.   </form>
  457.  
  458. <?php
  459.       echofooter();
  460.     }
  461.     break;
  462. case "list":
  463.     $output = "";
  464.     if (!isset($xfieldsid)) $xfieldsid = "";
  465.     $xfieldsdata = xfieldsdataload ($xfieldsid);
  466.     foreach ($xfields as $name => $value) {
  467.       $fieldname = $value[0];
  468.       if (!$xfieldsadd) {
  469.         $fieldvalue = $xfieldsdata[$value[0]];
  470.  
  471.         if ($row['allow_br'])
  472.             $fieldvalue = $parse->decodeBBCodes($fieldvalue, false);
  473.         else
  474.             $fieldvalue = $parse->decodeBBCodes($fieldvalue, true, "yes");
  475.  
  476.       } elseif ($value[3] != "select") {
  477.         $fieldvalue = $value[4];
  478.       }
  479.  
  480.       $holderid = "xfield_holder_$fieldname";
  481.  
  482.       if ($value[3] == "textarea") {      
  483.         if ($bb_editor) $params = "onclick=\"setFieldName(this.id)\" "; else $params = "class=\"mceEditor\" ";
  484.  
  485.         if (!$value[5]) {
  486.             $uid = "uid=\"essential\" ";
  487.             $params .= "rel=\"essential\" ";
  488.         } else {
  489.             $uid = "";
  490.         }
  491.  
  492.         $output .= <<<HTML
  493. <tr id="$holderid" {$uid}>
  494. $value[1]:<br />[if-optional]({$lang['xf_not_notig']})[/if-optional][not-optional]({$lang['xf_notig']})[/not-optional]
  495. <td class=xfields colspan="2"><!--panel--><textarea name="xfield[$fieldname]" id="xf_$fieldname" {$params}>$fieldvalue</textarea></td></tr>
  496. HTML;
  497.       } elseif ($value[3] == "text") {
  498.  
  499.         $fieldvalue = str_replace('"', '&quot;', $fieldvalue);
  500.         $fieldvalue = str_replace('&amp;', '&', $fieldvalue);
  501.  
  502.         if (!$value[5]) {
  503.             $params = "rel=\"essential\" ";
  504.             $uid = "uid=\"essential\" ";
  505.  
  506.         } else {
  507.  
  508.             $params = "";
  509.             $uid = "";
  510.  
  511.         }
  512.  
  513.         $is_xfields_upload = false;
  514.         $xfields_upload_action = 'view';
  515.         $xfields_upload_field = $value;
  516.         $xfields_upload_value = $fieldvalue;
  517.         include ENGINE_DIR . '/inc/xfields.upload1.php';
  518.         if (!$is_xfields_upload)
  519.  
  520.         $output .= <<<HTML
  521. $fieldvalue
  522. HTML;
  523.       } elseif ($value[3] == "select") {
  524.         $output .= <<<HTML
  525.  
  526. <select name="xfield[$fieldname]">
  527. HTML;
  528.         if ( !isset($fieldvalue) ) $fieldvalue = "";
  529.  
  530.         $fieldvalue = str_replace('&amp;', '&', $fieldvalue);
  531.         $fieldvalue = str_replace('&quot;', '"', $fieldvalue);
  532.  
  533.         foreach (explode("\r\n", $value[4]) as $index => $value) {
  534.           $value = str_replace("'", "&#039;", $value);
  535.           $output .= "<option value=\"$index\"" . ($fieldvalue == $value ? " selected" : "") . ">$value</option>\r\n";
  536.         }
  537.  
  538. $output .= <<<HTML
  539. </select>
  540. HTML;
  541.       }
  542.       $output = preg_replace("'\\[if-optional\\](.*?)\\[/if-optional\\]'s", $value[5] ? "\\1" : "", $output);
  543.       $output = preg_replace("'\\[not-optional\\](.*?)\\[/not-optional\\]'s", $value[5] ? "" : "\\1", $output);
  544.       $output = preg_replace("'\\[if-add\\](.*?)\\[/if-add\\]'s", ($xfieldsadd) ? "\\1" : "", $output);
  545.       $output = preg_replace("'\\[if-edit\\](.*?)\\[/if-edit\\]'s", (!$xfieldsadd) ? "\\1" : "", $output);
  546.       $outputList["{xfieldvalue_{$fieldname}}"] = $output; $output='';
  547.     }
  548.     $output = implode('',$outputList);
  549.     $output .= <<<HTML
  550.  
  551. <script type="text/javascript">
  552. <!--
  553.     onCategoryChange($('#category'));
  554. // -->
  555. </script>
  556. HTML;
  557.     break;
  558.   case "init":
  559.  
  560.     $postedxfields = $_POST['xfield'];
  561.     $newpostedxfields = array();
  562.     $filecontents = array ();
  563.    
  564.     foreach ($category as $cats_explode) {
  565.         foreach ($xfields as $name => $value) {
  566.             if ($value[2] != "" and !in_array($cats_explode, explode(",", $value[2]))) {
  567.                 continue;
  568.             }
  569.  
  570.             if ($value[5] == 0 and $postedxfields[$value[0]] == "") {
  571.    
  572.                 if ($add_module == "yes")
  573.                     $stop .= $lang['xfield_xerr1'];
  574.                 else
  575.                     msg("error", "error", "$lang[xfield_xerr1]<br /><a href=\"javascript:history.go(-1)\">$lang[func_msg]</a>");
  576.        
  577.             }
  578.  
  579.             if ($ajax_edit == "yes") $postedxfields[$value[0]] = convert_unicode( $postedxfields[$value[0]], $config['charset'] );
  580.  
  581.             if ($value[3] == "select") {
  582.                 $options = explode("\r\n", $value[4]);
  583.                 $postedxfields[$value[0]] = $options[$_POST['xfield'][$value[0]]];
  584.  
  585. if (stripos($value[4],'audio')===0 or stripos($value[4],'video')===0 or stripos($value[4],'image')===0 or stripos($value[4],'file')===0) $value[3] = 'textarea';
  586.             }
  587.  
  588.             if (($value[3] == "text" OR $value[3] == "select") AND $postedxfields[$value[0]] != "" ) {
  589.  
  590.                 $newpostedxfields[$value[0]] = trim( htmlspecialchars(strip_tags( stripslashes($postedxfields[$value[0]]) ), ENT_QUOTES ));
  591.  
  592.             } elseif ( $postedxfields[$value[0]] != "" ) {
  593.  
  594.                 if ($add_module == "yes") {
  595.  
  596.                     if( $config['allow_site_wysiwyg'] == "yes" OR $allow_br != '1' ) {
  597.                        
  598.                         $newpostedxfields[$value[0]] = $parse->BB_Parse($parse->process($postedxfields[$value[0]]));
  599.                    
  600.                     } else {
  601.                        
  602.                         $newpostedxfields[$value[0]] = $parse->BB_Parse($parse->process($postedxfields[$value[0]]), false);
  603.                    
  604.                     }
  605.  
  606.                 } else {
  607.  
  608.                     if( $config['allow_admin_wysiwyg'] == "yes" OR $allow_br != '1' ) {
  609.                        
  610.                         $newpostedxfields[$value[0]] = $parse->BB_Parse($parse->process($postedxfields[$value[0]]));
  611.                    
  612.                     } else {
  613.                        
  614.                         $newpostedxfields[$value[0]] = $parse->BB_Parse($parse->process($postedxfields[$value[0]]), false);
  615.                    
  616.                     }
  617.  
  618.                 }
  619.  
  620.             }
  621.  
  622.         }
  623.     }
  624.  
  625.     $postedxfields = $newpostedxfields;
  626.  
  627.     if( !empty( $postedxfields ) ) {
  628.         foreach ( $postedxfields as $xfielddataname => $xfielddatavalue ) {
  629.  
  630.             if( $xfielddatavalue == "" ) {
  631.                 continue;
  632.             }
  633.                
  634.             $xfielddataname = str_replace( "|", "&#124;", $xfielddataname );
  635.             $xfielddataname = str_replace( "\r\n", "__NEWL__", $xfielddataname );
  636.             $xfielddatavalue = str_replace( "|", "&#124;", $xfielddatavalue );
  637.             $xfielddatavalue = str_replace( "\r\n", "__NEWL__", $xfielddatavalue );
  638.             $filecontents[] = "$xfielddataname|$xfielddatavalue";
  639.         }
  640.        
  641.         if ( count($filecontents) ) $filecontents = $db->safesql(implode( "||", $filecontents )); else $filecontents = '';
  642.    
  643.     } else $filecontents = '';
  644.  
  645.     break;
  646.   case "delete":
  647.     break;
  648.   case "templatereplace":
  649.     $xfieldsdata = xfieldsdataload ($xfieldsid);
  650.     $xfieldsoutput = $xfieldsinput;
  651.  
  652.     foreach ($xfields as $value) {
  653.       $preg_safe_name = preg_quote($value[0], "'");
  654.  
  655.       if ($value[5] != 0) {
  656.         if (empty($xfieldsdata[$value[0]])) {
  657.           $xfieldsoutput = preg_replace("'\\[xfgiven_{$preg_safe_name}\\].*?\\[/xfgiven_{$preg_safe_name}\\]'is", "", $xfieldsoutput);
  658.         } else {
  659.           $xfieldsoutput = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $xfieldsoutput);
  660.         }
  661.       }
  662.       $xfieldsoutput = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", stripslashes($xfieldsdata[$value[0]]), $xfieldsoutput);
  663.     }
  664.     break;
  665.   case "templatereplacepreview":
  666.     if (isset ($_POST["xfield"])) $xfield = $_POST["xfield"];
  667.     $xfieldsoutput = $xfieldsinput;
  668.  
  669.     foreach ($xfields as $value) {
  670.       $preg_safe_name = preg_quote($value[0], "'");
  671.  
  672.       if ($value[3] == "select") {
  673.         $options = explode("\r\n", $value[4]);
  674.         $xfield[$value[0]] = $options[$xfield[$value[0]]];
  675.       }
  676.  
  677.       if ($config['safe_xfield']) {
  678.         $parse->ParseFilter();
  679.         $parse->safe_mode = true;
  680.       }
  681.  
  682.       $parse->allow_code = true;
  683.  
  684.         if (($value[3] == "text" OR $value[3] == "select") AND $xfield[$value[0]] != "" ) {
  685.  
  686.             $xfield[$value[0]] = trim( htmlspecialchars(strip_tags( stripslashes($xfield[$value[0]]) ), ENT_QUOTES ));
  687.  
  688.         } elseif ( $xfield[$value[0]] != "" ) {
  689.  
  690.             if ($add_module == "yes") {
  691.                 if( $config['allow_site_wysiwyg'] == "yes" OR $allow_br != '1' ) {
  692.                        
  693.                     $xfield[$value[0]] = $parse->BB_Parse($parse->process($xfield[$value[0]]));
  694.                    
  695.                 } else {
  696.                        
  697.                     $xfield[$value[0]] = $parse->BB_Parse($parse->process($xfield[$value[0]]), false);
  698.                    
  699.                 }
  700.             } else {
  701.                 if( $config['allow_admin_wysiwyg'] == "yes" OR $allow_br != '1' ) {
  702.                        
  703.                     $xfield[$value[0]] = $parse->BB_Parse($parse->process($xfield[$value[0]]));
  704.                    
  705.                 } else {
  706.                        
  707.                     $xfield[$value[0]] = $parse->BB_Parse($parse->process($xfield[$value[0]]), false);
  708.                    
  709.                 }
  710.             }
  711.  
  712.         }
  713.  
  714.       $xfield[$value[0]] = stripslashes($xfield[$value[0]]);
  715.  
  716.        if (empty($xfield[$value[0]])) {
  717.           $xfieldsoutput = preg_replace("'\\[xfgiven_{$preg_safe_name}\\].*?\\[/xfgiven_{$preg_safe_name}\\]'is", "", $xfieldsoutput);
  718.           $xfieldsoutput = str_replace( "[xfnotgiven_{$preg_safe_name}]", "", $xfieldsoutput );
  719.           $xfieldsoutput = str_replace( "[/xfnotgiven_{$preg_safe_name}]", "", $xfieldsoutput );
  720.        } else {
  721.           $xfieldsoutput = preg_replace( "'\\[xfnotgiven_{$preg_safe_name}\\](.*?)\\[/xfnotgiven_{$preg_safe_name}\\]'is", "", $xfieldsoutput );
  722.           $xfieldsoutput = str_replace( "[xfgiven_{$preg_safe_name}]", "", $xfieldsoutput );
  723.           $xfieldsoutput = str_replace( "[/xfgiven_{$preg_safe_name}]", "", $xfieldsoutput );
  724.        }
  725.  
  726.       $xfieldsoutput = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", $xfield[$value[0]], $xfieldsoutput);
  727.     }
  728.     break;
  729.   case "categoryfilter":
  730.     $categoryfilter = <<<HTML
  731.   <script type="text/javascript">
  732.   function ShowOrHideEx(id, show) {
  733.     var item = null;
  734.  
  735.     if (document.getElementById) {
  736.       item = document.getElementById(id);
  737.     } else if (document.all) {
  738.       item = document.all[id];
  739.     } else if (document.layers){
  740.       item = document.layers[id];
  741.     }
  742.     if (item && item.style) {
  743.       item.style.display = show ? "" : "none";
  744.     }
  745.   }
  746.  
  747.   function onCategoryChange(obj) {
  748.  
  749.     var value = $(obj).val();
  750.  
  751.     if ($.isArray(value)) {
  752.  
  753. HTML;
  754.  
  755.  
  756.     foreach ($xfields as $value) {
  757.  
  758.       if ( $value[2] ) {
  759.  
  760.         $categories = explode(",", $value[2]);
  761.         $temp_array = array();
  762.  
  763.         foreach ($categories as $temp_value) {
  764.  
  765.             $temp_array[] = "jQuery.inArray('{$temp_value}', value) != -1";
  766.  
  767.         }
  768.  
  769.         $categories = implode(" || ", $temp_array);
  770.  
  771.         $categoryfilter .= "ShowOrHideEx(\"xfield_holder_{$value[0]}\", {$categories} );\r\n";
  772.       }
  773.     }
  774.  
  775. $categoryfilter .= <<<HTML
  776.     } else {
  777.  
  778. HTML;
  779.  
  780.     foreach ($xfields as $value) {
  781.       $categories = str_replace(",", "||value==", $value[2]);
  782.       if ($categories) {
  783.         $categoryfilter .= "ShowOrHideEx(\"xfield_holder_{$value[0]}\", value == $categories);\r\n";
  784.       }
  785.     }
  786.  
  787.     $categoryfilter .= "}  }\r\n</script>";
  788.     break;
  789.   default:
  790.   if (function_exists('msg'))
  791.     msg("error", $lang['xfield_error'], $lang['xfield_xerr2']);
  792. }
  793. ?>
Advertisement
Add Comment
Please, Sign In to add comment