Guest User

functions.inc

a guest
Jul 31st, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.78 KB | None | 0 0
  1. <?php
  2. ///////////////////////////////////////////////////////
  3. // Function:    formatsize
  4. // Description: Format the size of given file
  5.  
  6.  
  7.  
  8. ///////////////////////////////////////////////////////
  9. // Class:        microTimer
  10. // Description:    calculates the micro time
  11.  
  12. class microTimer {
  13.     function start() {
  14.     global $starttime;
  15.  
  16.         $mtime       = microtime();
  17.         $mtime       = explode (' ', $mtime);
  18.         $mtime       = $mtime[1] + $mtime[0];
  19.         $starttime = $mtime;
  20.     }
  21.     function stop() {
  22.     global $starttime;
  23.  
  24.         $mtime       = microtime ();
  25.         $mtime       = explode (' ', $mtime);
  26.         $mtime       = $mtime[1] + $mtime[0];
  27.         $endtime   = $mtime;
  28.         $totaltime = round (($endtime - $starttime), 5);
  29.  
  30.     return $totaltime;
  31.     }
  32. }
  33.  
  34. ///////////////////////////////////////////////////////
  35. // Function:    check_login
  36. // Description: Check login information
  37.  
  38. function check_login($username, $md5_password){
  39. global $member, $members;
  40.  
  41.     $result = false;
  42.     foreach ($members as $row){
  43.         if ($username == $row['username'] and $md5_password == $row['password']){
  44.             $result = true;
  45.             $member = $row;
  46.         }
  47.     }
  48.  
  49. return $result;
  50. }
  51.  
  52. ///////////////////////////////////////////////////////
  53. // Function:    cute_query_string
  54. // Description: Format the Query_String for CuteNews purpuses index.php?
  55.  
  56. function cute_query_string($q_string, $strips, $type = 'get'){
  57.  
  58.     foreach ($strips as $key){
  59.         $strips[$key] = true;
  60.     }
  61.  
  62.     foreach(explode('&', $q_string) as $var_peace){
  63.         $parts = explode('=', $var_peace);
  64.  
  65.         if ($strips[$parts[0]] != true and $parts[0]){
  66.             if ($type == 'post'){
  67.                 $my_q .= '<input type="hidden" name="'.$parts[0].'" value="'.$parts[1].'" />';
  68.             } else {
  69.                 $my_q .= '&'.$var_peace;
  70.             }
  71.         }
  72.     }
  73.  
  74. return $my_q;
  75. }
  76.  
  77. ///////////////////////////////////////////////////////
  78. // Function:    showRow
  79.  
  80. function showRow($title = '', $description = '', $field = ''){
  81. global $i;
  82.  
  83.     if ($i%2 !== 0 and $title){
  84.         $bg = 'class="enabled"';
  85.     } else {
  86.         $bg = 'class="disabled"';
  87.     }
  88.  
  89.     echo '<tr '.$bg.'>
  90.            <td width="400" colspan="2" class="opt-title">&nbsp;<b>'.$title.'</b></td>
  91.            <td width="250" rowspan="2" valign="middle" align="left" class="opt-space">'.$field.'</tr>
  92.         <tr '.$bg.'>
  93.            <td width="20" class="opt-space">&nbsp;</td>
  94.            <td width="400" valign="top" class="opt-desc">'.$description.'</td>
  95.         </tr>';
  96.  
  97.     $bg = '';
  98.     $i++;
  99. }
  100.  
  101. ///////////////////////////////////////////////////////
  102. // Function:    makeDropDown
  103. // Description:    رîçنà¸ٍ âûïîنàùهه ىهي
  104.  
  105. function makeDropDown($options, $name, $selected){
  106.  
  107.     foreach ($options as $value => $description){
  108.         $output .= '<option value="'.$value.'"'.(($selected == $value) ? ' selected ' : '').'>'.$description.'</option>';
  109.     }
  110.  
  111. return '<select size="1" name="'.$name.'">'.$output.'</select>';
  112. }
  113.  
  114. ///////////////////////////////////////////////////////
  115. // Function:    Flooder
  116. // Description: Flood Protection Function
  117.  
  118. function flooder($ip, $id){
  119. global $cutepath, $config_flood_time, $sql;
  120.  
  121.     foreach ($sql->select(array('table' => 'flood')) as $row){
  122.         if (($row['date'] + $config_flood_time) > time() and $row['ip'] == $ip and $row['post_id'] == $id){
  123.            $result = true;
  124.         } else {
  125.             $result = false;
  126.             $sql->delete(array(
  127.             'table' => 'flood',
  128.             'where' => array("date = $row[date]", 'and', "ip = $row[ip]", 'and', "post_id = $row[post_id]")
  129.             ));
  130.         }
  131.     }
  132.  
  133. return $result;
  134. }
  135.  
  136. ////////////////////////////////////////////////////////
  137. // Function:    msg
  138. // Description: Displays message to user
  139.  
  140. function msg($type, $title, $text, $back = false){
  141. global $echo;
  142.  
  143.     echoheader($type, $title);
  144.     echo '<table border="0" cellpading="0" cellspacing="0" width="100%" height="100%"><tr><td>'.$text.($back ? '<br /><br /><a href="'.$back.'">'.$echo['back'].'</a>' : '').'</table>';
  145.     echofooter();
  146.     exit;
  147. }
  148.  
  149. ////////////////////////////////////////////////////////
  150. // Function:    echoheader
  151. // Description: Displays header skin
  152.  
  153. function echoheader($image, $header_text){
  154. global $PHP_SELF, $is_logged_in, $config_skin, $skin_header, $skin_menu, $skin_prefix, $config_version_name;
  155.  
  156.     if ($is_logged_in == true){
  157.         $skin_header = str_replace('{menu}', $skin_menu, $skin_header);
  158.     } else {
  159.         $skin_header = str_replace('{menu}', ' &nbsp; '.$config_version_name, $skin_header);
  160.     }
  161.  
  162.     $skin_header = str_replace('{image-name}', $skin_prefix.$image, $skin_header);
  163.     $skin_header = str_replace('{header-text}', $header_text, $skin_header);
  164.     $skin_header = str_replace('{copyrights}', '<div style="font-size: 11px; text-transform: uppercase"> Powered by <a style="font-size: 11px" href="http://php.net/" target=_blank>'.$config_version_name.' '.$config_version_id.'</a> <a style="font-size:11px" href="http://best-hostia.com/" target="_blank">Script</a>)</div>', $skin_header);
  165.  
  166.     echo $skin_header;
  167. }
  168.  
  169. ////////////////////////////////////////////////////////
  170. // Function:    echofooter
  171. // Description: Displays footer skin
  172.  
  173. function echofooter(){
  174. global $PHP_SELF, $is_logged_in, $config_skin, $skin_footer, $skin_menu, $skin_prefix, $config_version_name, $config_version_id;
  175.  
  176.     if ($is_logged_in == true){
  177.         $skin_footer = str_replace('{menu}', $skin_menu, $skin_footer);
  178.     } else {
  179.         $skin_footer = str_replace('{menu}', ' &nbsp; '.$config_version_name, $skin_footer);
  180.     }
  181.  
  182.     $skin_footer = str_replace('{image-name}', $skin_prefix.$image, $skin_footer);
  183.     $skin_footer = str_replace('{header-text}', $header_text, $skin_footer);
  184.     $skin_footer = str_replace('{copyrights}', '<div style="font-size: 12px; text-transform: uppercase">  <a style="font-size: 12px"" target=_blank>'.$config_version_name.' '.$config_version_id.'</a> <a style="font-size: 11px" href="http://best-hostia.com/" target="_blank"> Best Hostia Group </a></div>', $skin_footer);
  185.  
  186.     echo $skin_footer;
  187. }
  188.  
  189. ////////////////////////////////////////////////////////
  190. // Function:    b64dck
  191. // Description: And the duck fly away.
  192. function b64dck(){
  193.     $cr = bd_config('e2NvcHlyaWdodHN9');$shder = bd_config('c2tpbl9oZWFkZXI=');$sfter = bd_config('c2tpbl9mb290ZXI=');
  194.         global $$shder,$$sfter;
  195.     $HDpnlty = bd_config('PGNlbnRlcj48aDE+Q3V0ZU5ld3M8L2gxPjxhIGhyZWY9Imh0dHA6Ly9jdXRlcGhwLmNvbSI+Q3V0ZVBIUC5jb208L2E+PC9jZW50ZXI+PGJyPg==');
  196.     $FTpnlty = bd_config('PGNlbnRlcj48ZGl2IGRpc3BsYXk9aW5saW5lIHN0eWxlPSdmb250LXNpemU6IDExcHgnPlBvd2VyZWQgYnkgPGEgc3R5bGU9J2ZvbnQtc2l6ZTogMTFweCcgaHJlZj0iaHR0cDovL2N1dGVwaHAuY29tL2N1dGVuZXdzLyIgdGFyZ2V0PV9ibGFuaz5DdXRlTmV3czwvYT4gqSAyMDA0ICA8YSBzdHlsZT0nZm9udC1zaXplOiAxMXB4JyBocmVmPSJodHRwOi8vY3V0ZXBocC5jb20vIiB0YXJnZXQ9X2JsYW5rPkN1dGVQSFA8L2E+LjwvZGl2PjwvY2VudGVyPg==');
  197.  
  198.         if(!stristr($$shder,$cr) and !stristr($$sfter,$cr)){ $$shder = $HDpnlty.$$shder; $$sfter = $$sfter.$FTpnlty; }
  199. }
  200.  
  201. ////////////////////////////////////////////////////////
  202. // Function:    insertSmilies
  203. // Description: insert smilies for adding into news/comments
  204.  
  205. function insertSmilies($insert_location, $break_location = false){
  206. global $config_http_script_dir, $config_smilies;
  207.  
  208.     $smilies = explode(',', $config_smilies);
  209.     foreach ($smilies as $smile){
  210.         $i++;
  211.  
  212.         $output .= '<a href="javascript:insertext(\':'.trim($smile).':\', \'\', \''.$insert_location.'\')"><img style="border: none;" alt="'.trim($smile).'" src="'.$config_http_script_dir.'/data/emoticons/'.trim($smile).'.gif" /></a>';
  213.  
  214.         if ($break_location and $i%$break_location == 0){
  215.             $output .= '<br />';
  216.         } else {
  217.             $output .= '&nbsp;';
  218.         }
  219.     }
  220.  
  221. return $output;
  222. }
  223.  
  224. ////////////////////////////////////////////////////////
  225. // Function:    replace_comments
  226. // Description: Replaces comments charactars
  227. function replace_comment($way, $sourse){
  228. global $config_allow_html_in_comments, $config_http_script_dir, $config_smilies;
  229.  
  230.     if ($way == 'add'){
  231.         $find     = array("\n", "\r");
  232.         $replace = array('<br />', '');
  233.         $sourse     = htmlspecialchars($sourse);
  234.  
  235.         if (!get_magic_quotes_gpc()){
  236.             $sourse = addslashes($sourse);
  237.         }
  238.  
  239.     } elseif ($way == 'show'){
  240.         $find     = array('&amp;');
  241.         $replace = array('&');
  242.         $sourse = stripslashes($sourse);
  243.  
  244.         foreach (explode(',', $config_smilies) as $smile){
  245.             $find[]       = ':'.trim($smile).':';
  246.             $replace[] = '<img style="border: 0px; vertical-align: middle;" alt="'.trim($smile).'" src="'.$config_http_script_dir.'/data/emoticons/'.trim($smile).'.gif" />';
  247.         }
  248.     } elseif ($way == 'admin'){
  249.         $find     = array('<br />');
  250.         $replace = array("\n");
  251.         $sourse     = unhtmlentities($sourse);
  252.         $sourse     = stripslashes($sourse);
  253.     }
  254.  
  255. return str_replace($find, $replace, trim($sourse));
  256. }
  257.  
  258. ////////////////////////////////////////////////////////
  259. // Function:    replace_news
  260. // Description: Replaces news charactars
  261.  
  262. function replace_news($way, $sourse, $replce_n_to_br = true, $use_html = true){
  263. global $config_allow_html_in_news, $config_http_script_dir, $config_smilies;
  264.  
  265.     if ($way == 'show'){
  266.         $find     = array('{nl}');
  267.         $replace = array('<br />');
  268.         $sourse     = stripslashes($sourse);
  269.  
  270.         foreach (explode(',', $config_smilies) as $smile){
  271.             $find[]       = ':'.trim($smile).':';
  272.             $replace[] = '<img style="border: 0px; vertical-align: middle;" alt="'.trim($smile).'" src="'.$config_http_script_dir.'/data/emoticons/'.trim($smile).'.gif" />';
  273.         }
  274.     } elseif($way == 'add'){
  275.         $find     = array('|', "\r", "\n");
  276.         $replace = array('&#124', '', '{nl}');
  277.  
  278.         if (!get_magic_quotes_gpc()){
  279.             $sourse = addslashes($sourse);
  280.         }
  281.     } elseif ($way == 'admin'){
  282.         $find     = array('{nl}', '<br>', '<br />');
  283.         $replace = array("\n", "\n", "\n");
  284.         $sourse     = stripslashes($sourse);
  285.     }
  286.  
  287. return str_replace($find, $replace, trim($sourse));
  288. }
  289.  
  290. function bd_config($str){
  291. return base64_decode($str);
  292. }
  293.  
  294. ////////////////////////////////////////////////////////
  295. // Function:    echo_r
  296.  
  297. function echo_r($array){
  298.     ob_start();
  299.     if (is_bool($array)){
  300.         echo ($array ? 'true' : 'false');
  301.     } else {
  302.         print_r($array);
  303.     }
  304.  
  305.     $echo = ob_get_contents();
  306.     ob_clean();
  307.  
  308.     echo highlight_string($echo, true);
  309. }
  310.  
  311. ////////////////////////////////////////////////////////
  312. // Function:    inserttag
  313. // Description: آٌٍàâêà ٌïèٌêà ٍمîâ ïًè نîلàâëهيèè/ًهنàêٍèًîâàيèè يîâîٌٍهé
  314.  
  315. function inserttag($insert_location){
  316. global $config_http_script_dir;
  317.         $output = "
  318.        <div class=\"tags\"><a href=\"javascript:insertext('<br />','','$insert_location')\" title='Linebreak'><img src=".$config_http_script_dir."/skins/images/tags/br.gif border=0 align=middle></a>
  319.        <a href=\"javascript:insertext('<hr />','','$insert_location')\" title='Horizontal line'><img src=".$config_http_script_dir."/skins/images/tags/hr.gif border=0 align=middle></a>
  320.        <a href=\"javascript:insertext('<p>','</p>','$insert_location')\" title='Paragraph'><img src=".$config_http_script_dir."/skins/images/tags/p.gif border=0 align=middle></a>
  321.        <a href=\"javascript:insertext('<b>','</b>','$insert_location')\" title='Bold'><img src=".$config_http_script_dir."/skins/images/tags/b.gif border=0 align=middle></a>
  322.        <a href=\"javascript:insertext('<i>','</i>','$insert_location')\" title='Italic'><img src=".$config_http_script_dir."/skins/images/tags/i.gif border=0 align=middle></a>
  323.        <a href=\"javascript:insertext('<u>','</u>','$insert_location')\" title='Underline'><img src=".$config_http_script_dir."/skins/images/tags/u.gif border=0 align=middle></a>
  324.        <a href=\"javascript:insertext('<s>','</s>','$insert_location')\" title='Linethrough'><img src=".$config_http_script_dir."/skins/images/tags/s.gif border=0 align=middle></a>
  325.        <a href=\"javascript:insertext('<sub>','</sub>','$insert_location')\" title='Subscript'><img src=".$config_http_script_dir."/skins/images/tags/sub.gif border=0 align=middle></a>
  326.        <a href=\"javascript:insertext('<sup>','</sup>','$insert_location')\" title='Superscript'><img src=".$config_http_script_dir."/skins/images/tags/sup.gif border=0 align=middle></a>
  327.        <a href=\"javascript:insertext('<font color=&quot;&quot;>','</font>','$insert_location')\" title='Font color'><img src=".$config_http_script_dir."/skins/images/tags/color.gif border=0 align=middle></a>
  328.        <a href=\"javascript:insertext('<font size=&quot;&quot;>','</font>','$insert_location')\" title='Font size'><img src=".$config_http_script_dir."/skins/images/tags/size.gif border=0 align=middle></a>
  329.        <a href=\"javascript:insertext('<ul>','</ul>','$insert_location')\" title='List'><img src=".$config_http_script_dir."/skins/images/tags/ul.gif border=0 align=middle></a>
  330.        <a href=\"javascript:insertext('<li>','</li>','$insert_location')\" title='List element'><img src=".$config_http_script_dir."/skins/images/tags/li.gif border=0 align=middle></a>
  331.        <a href=\"javascript:insertext('<a href=&quot;http://&quot; target=&quot;_blank&quot;>','</a>','$insert_location')\" title='URL'><img src=".$config_http_script_dir."/skins/images/tags/url.gif border=0 align=middle></a>
  332.        <a href=\"javascript:insertext('<a href=&quot;mailto:&quot;>','</a>','$insert_location')\" title='Email'><img src=".$config_http_script_dir."/skins/images/tags/mailto.gif border=0 align=middle></a>
  333.        <a href=\"#\" onclick=\"window.open('$PHP_SELF?mod=images&area=$insert_location', '_Addimage', 'height=450,resizable=yes,scrollbars=yes,width=500');return false;\" target=\"_Addimage\"><img src=".$config_http_script_dir."/skins/images/tags/img.gif border=0 align=middle></a>
  334.        <a href=\"javascript:insertext('<div align=&quot;&quot;>','</div>','$insert_location')\" title='Align'><img src=".$config_http_script_dir."/skins/images/tags/align.gif border=0 align=middle></a></div>";
  335.  
  336. return $output;
  337. }
  338.  
  339. ////////////////////////////////////////////////////////
  340. // Function:    cute_mail Version: 1.0
  341. // Description: Send mail with cutenews
  342.  
  343. function cute_mail($to,$subject,$message){
  344. global $config_version_name, $config_version_id;
  345.  
  346.     if (!$config_admin_mail or !$config_admin_mail){
  347.         $mail_from = 'no-reply@'.str_replace('www.', '', $_SERVER['SERVER_NAME']);
  348.     } else {
  349.         $mail_from = $config_admin_mail;
  350.     }
  351.  
  352.     $headers .= 'From: '.$mail_from."\n";
  353.     $headers .= 'Reply-to: '.$mail_from."\n";
  354.     $headers .= 'Return-Path: '.$mail_from."\n";
  355.     $headers .= 'Message-ID: <'.md5(uniqid(time())).'@'.$_SERVER['SERVER_NAME'].">\n";
  356.     $headers .= 'MIME-Version: 1.0'."\n";
  357.     $headers .= 'Content-type: text/plain; charset=iso-8859-2'."\n";
  358.     $headers .= 'Content-transfer-encoding: 7bit'."\n";
  359.     $headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."\n";
  360.     $headers .= 'X-Priority: 3'."\n";
  361.     $headers .= 'X-MSMail-Priority: Normal'."\n";
  362.     $headers .= 'X-Mailer: '.$config_version_name.' '.$config_version_id."\n";
  363.     $headers .= 'X-MimeOLE: '.$config_version_name.' '.$config_version_id."\n";
  364.  
  365.     mail($to, $subject, $message, $headers);
  366. }
  367.  
  368. ////////////////////////////////////////////////////////
  369. // Function:    chmoddir
  370. // Description: ôَيêِèے ىهيےهٍ ïًàâà âٌهى âëîوهييûى ïàïêàى è ôàéëàى âيًٍَè ïàïêè, âîçâًàùàهٍ true â ٌëَ÷àه َنà÷è è false, هٌëè ٌىهيèٍü ïًàâà ïàïêه يه َنàëîٌü
  371. // Original:        http://forum.dklab.ru/php/advises/FaylovieFunktsii.html
  372.  
  373. function chmoddir($dir, $mod){
  374.  
  375.  
  376.     closedir($dh);
  377.  
  378.     if (chmod($dir, $mod)){
  379.         return true;
  380.     } else {
  381.         return false;
  382.     }
  383. }
  384.  
  385. ////////////////////////////////////////////////////////
  386. // Function:    ِو_ىàٌٌèâ
  387. // Description: نهٍè, ٍî êàêà
  388.  
  389. function c_array($action, $sort = ''){
  390. global $sql;
  391.  
  392.     if (is_array($sort)){
  393.         $query = array('table' => $action, 'orderby' => $sort);
  394.     } else {
  395.         $query = array('table' => $action);
  396.     }
  397.  
  398.     foreach ($sql->select($query) as $k => $v){
  399.         $result[] = implode('|', $v);
  400.     }
  401.  
  402. return ($result ? $result : array());
  403. }
  404.  
  405. ////////////////////////////////////////////////////////
  406. // Function:    chicken_dick
  407. // Description: îٍنهëهيèه ىَُ îٍ ٌَïà
  408.  
  409. function chicken_dick($chicken, $dick = '/'){
  410.  
  411.     $chicken = preg_replace('/^(['.preg_quote($dick, '/').']+)/', '', $chicken);
  412.     $chicken = preg_replace('/(['.preg_quote($dick, '/').']+)/', $dick, $chicken);
  413.     $chicken = preg_replace('/(['.preg_quote($dick, '/').']+)$/', '', $chicken);
  414.  
  415. return $chicken;
  416. }
  417.  
  418. ////////////////////////////////////////////////////////
  419. // Function:    file_write
  420. // Description: çàïèٌü â ôàèë
  421.  
  422. function file_write($fopen = '', $fwrite = '', $clear = false, $chmod = false){
  423.  
  424.     if (!$chmod){
  425.         $chmod = chmod;
  426.     }
  427.  
  428.     if ($clear){
  429.         $fwrite = str_replace('     ', '', str_replace("\r\n", '', $fwrite));
  430.     }
  431.  
  432.    
  433.  
  434.     @chmod($fopen, $chmod);
  435.  
  436. }
  437.  
  438. ////////////////////////////////////////////////////////
  439. // Function:    file_read
  440. // Description: ÷ٍهيèه èç ôàèëà
  441.  
  442. function file_read($path){
  443.  
  444.     if (!filesize($path)){
  445.         return false;
  446.     }
  447.  
  448.     $fp = fopen($path, 'r');
  449.     $fo = fread($fp, filesize($path));
  450.     fclose($fp);
  451.  
  452. return $fo;
  453. }
  454.  
  455. ////////////////////////////////////////////////////////
  456. // Function:    cute_parse_url
  457. // Description: àيàëîم parse_url(), يî âûنà¸ٍ ÷ٍَü لîëüّه è يهىيîمî èيà÷ه
  458.  
  459. function cute_parse_url($url){
  460. global $DOCUMENT_ROOT;
  461.  
  462.     $url         = parse_url($url);
  463.     $url['path'] = chicken_dick($url['path']);
  464.     $url['abs']     = $DOCUMENT_ROOT.'/'.$url['path'];
  465.  
  466.     if (is_file($url['abs'])){
  467.         $url['file'] = end($url['file'] = explode('/', $url['path']));
  468.         $url['path'] = chicken_dick(preg_replace('/'.$url['file'].'$/i', '', $url['path']));
  469.         $url['abs']     = $DOCUMENT_ROOT.'/'.$url['path'];
  470.     }
  471.  
  472. return $url;
  473. }
  474.  
  475. ////////////////////////////////////////////////////////
  476. // Function:    cute_get_link
  477. // Description: ôîًىèًîâàيèه سذثîâ
  478.  
  479. function cute_get_link($arr, $type = 'post', $format = 'home'){
  480. global $PHP_SELF, $QUERY_STRING, $allow_full_story, $xfields, $config_http_home_url, $config_http_script_dir, $config_rufus, $user_id;
  481.  
  482.     # ×èلًَàّêî منه-ٍî ًےنîى!
  483.    $for = parse_ini_file(rootpath.'/data/urls.ini', true);
  484.  
  485.     if (!is_array($arr)){
  486.         global $row;
  487.  
  488.         $string = explode('/', $arr);
  489.         $type    = end($string);
  490.         unset($string[(count($string) - 1)]);
  491.         $format = join('/', $string);
  492.         $arr    = $row;
  493.     }
  494.  
  495.     if (!is_object($xfields)){
  496.         $xfields = new XfieldsData();
  497.     }
  498.  
  499.     if ($config_rufus == 'yes'){
  500.         $rufus = true;
  501.     } else {
  502.         $rufus = false;
  503.     }
  504.  
  505.     if (!$arr['date']){
  506.         $arr['category'] = $arr['id'];
  507.     }
  508.  
  509.     if (!$arr['author']){
  510.         $arr['author']    = $arr['username'];
  511.         $arr['user_id'] = $arr['id'];
  512.     } else {
  513.         $arr['user_id'] = $user_id[$arr['author']];
  514.     }
  515.  
  516.     if (!eregi('{(.*)}', $format)){
  517.         $for[$type] = $for[$format][$type];
  518.     } else {
  519.         $for[$type] = $format;
  520.     }
  521.  
  522.     //if ($for[$type] and $xfields->fetch($arr['id'], 'url_format') == 'cat'){
  523.         //$type = 'post2';
  524.     //}
  525.  
  526.     $cat    = reset($cat = explode(',', $arr['category']));
  527.     $link    = end(run_filters('cute-get-link', array('arr' => $arr, 'link' => $for[$type])));
  528.     $link    = preg_replace('/{(.*?):(.*?)}/i', '{\\1}', $link);
  529.     $link    = strtr($link, array(
  530.               '{add}'          => '',
  531.               '{id}'          => $arr['id'],
  532.               '{year}'          => date('Y', $arr['date']),
  533.               '{month}'          => date('m', $arr['date']),
  534.               '{Month}'          => strtolower(date('M', $arr['date'])),
  535.               '{day}'          => date('d', $arr['date']),
  536.               '{time}'          => date('H:i:s', $arr['date']),
  537.               '{title}'          => ($arr['url'] ? $arr['url'] : totranslit($arr['title'])),
  538.               '{user}'          => totranslit($arr['author']),
  539.               '{user-id}'      => $arr['user_id'],
  540.               '{category-id}' => ($cat ? $cat : '0'),
  541.               '{category}'      => ($cat ? end($category = explode('/', category_get_link($cat))) : 'none'),
  542.               '{categories}'  => ($cat ? category_get_link($cat) : 'none')
  543.               ));
  544.     $url    = cute_parse_url($config_http_home_url);
  545.     $config = cute_parse_url($config_http_script_dir);
  546.     $query    = cute_query_string($QUERY_STRING, array('category', 'skip', 'subaction', 'id', 'ucat', 'year', 'month', 'day', 'user', 'page', 'search', 'brro', 'PHPSESSID', 'title', 'time'));
  547.  
  548.     if (!$rufus){
  549.         $result = ($format == 'home' ? ($_SERVER['PHP_SELF'] != $PHP_SELF ? $PHP_SELF : $url['path'].'/'.$url['file']) : ((is_dir($url['abs'].'/'.$format) or is_file($url['abs'].'/'.$format)) ? $url['path'].'/'.$format : $config['path'].'/'.$format.'.php'));
  550.     } else {
  551.         $result = $url['path'];
  552.     }
  553.  
  554.     $result = chicken_dick($result.'/'.$link).preg_replace('/^(&|&amp;)/i', '?', $query);
  555.     $result = str_replace('/?', '?', $result);
  556.  
  557. return $url['scheme'].'://'.$url['host'].($url['port'] ? ':'.$url['port'] : '').'/'.$result;
  558. }
  559.  
  560. ////////////////////////////////////////////////////////
  561. // Function:    category_get_link
  562. // Description: ïîëَ÷àهٍ ٌٌûëêè ïîَُé âهيèêè êàêîé âëîوهييîٌٍè
  563.  
  564. function category_get_link($id, $link = ''){
  565. global $cat_url, $cat_parent;
  566.  
  567.     if ($cat_url[$id]){
  568.         $link = $cat_url[$id].($link ? '/'.$link : '');
  569.     }
  570.  
  571.     if ($cat_parent[$id]){
  572.         $link = category_get_link($cat_parent[$id], $link);
  573.     }
  574.  
  575. return chicken_dick($link);
  576. }
  577.  
  578. ////////////////////////////////////////////////////////
  579. // Function:    category_get_children
  580. // Description: ïîëَ÷àهٍ "نهٍهé" êàٍهمîًèè
  581.  
  582. /*function category_get_children($id){
  583. global $cat_parent, $categoty;
  584.  
  585.     foreach ($cat_parent as $cat_id => $parent){
  586.         if ($parent == $id){
  587.             $categories .= category_get_children($cat_id).','.$id.','.$cat_id;
  588.         }
  589.     }
  590.  
  591. return ($categories ? chicken_dick($categories, ',') : $id);
  592. }*/
  593. function category_get_children($id, $withid = true, $limit = 0){
  594. global $cat_parent;
  595. static $end = 1, $result = array();
  596.  
  597.     $categories_dummy = $cat_parent;
  598.  
  599.     if ($id === ''){
  600.         return false;
  601.     }
  602.  
  603.     if ($withid){
  604.         $result[] = $id;
  605.     }
  606.  
  607.     foreach ($categories_dummy as $cat_id => $row){
  608.         if ($row == $id){
  609.             $result[] = $cat_id;
  610.  
  611.             if ($limit - $end){
  612.                 $result[] = category_get_children($cat_id, $limit);
  613.             }
  614.         }
  615.     }
  616.  
  617.     $end++;
  618.  
  619.     $return = $result;
  620.     $result = array();
  621.  
  622. return join(',', $return);
  623. }
  624.  
  625. ////////////////////////////////////////////////////////
  626. // Function:    category_get_title
  627. // Description: âîçâًàùàهٍ èىے ôَيêِèè è èىهيà ه¸ ًîنèٍهëهé
  628.  
  629. function category_get_title($id, $separator = ' &raquo; ', $title = ''){
  630. global $cat_name, $cat_parent;
  631.  
  632.     if ($cat_name[$id]){
  633.         $title = $cat_name[$id].($title ? $separator.$title : '');
  634.     }
  635.  
  636.     if ($cat_parent[$id]){
  637.         $title = category_get_title($cat_parent[$id], $separator, $title);
  638.     }
  639.  
  640. return chicken_dick($title);
  641. }
  642.  
  643. ////////////////////////////////////////////////////////
  644. // Function:    category_get_tree
  645. // Description: âîçâًàùàهٍ نهًهâî êàٍهمîًèé
  646. function category_get_tree($prefix = '', $tpl = '{name}', $no_prefix = true, $id = 0, $level = 0){
  647. global $sql, $PHP_SELF;
  648. static $johnny_left_teat;
  649.  
  650.     $level++;
  651.  
  652.     foreach ($sql->select(array('table' => 'categories', 'where' => array("parent = $id"), 'orderby' => array('id', 'ASC'))) as $row){
  653.         $find = array('/{id}/i', '/{name}/i', '/{url}/i', '/{icon}/i', '/{template}/i', '/{prefix}/i', '/\[php\](.*?)\[\/php\]/ie');
  654.         $repl = array($row['id'], $row['name'], $row['url'], ($row['icon'] ? '<img src="'.$row['icon'].'" alt="'.$row['icon'].'" border="0" align="absmiddle">' : ''), $row['template'], (($row['parent'] or !$no_prefix) ? $prefix : ''), '\\1');
  655.         $johnny_left_teat .= ($no_prefix ? preg_replace('/('.$prefix.'{1})$/i', '', str_repeat($prefix, $level)) : str_repeat($prefix, $level));
  656.         $johnny_left_teat .= preg_replace($find, $repl, $tpl);
  657.         category_get_tree($prefix, $tpl, $no_prefix, $row['id'], $level);
  658.     }
  659.  
  660. return $johnny_left_teat;
  661. }
  662.  
  663. ////////////////////////////////////////////////////////
  664. // Function:    category_get_id
  665. // Description: ïîëَ÷àهٍ ID êàٍهمîًèè èç ه¸ سذثà
  666.  
  667. function category_get_id($cat){
  668. global $sql;
  669.  
  670.     $cat      = explode('/', chicken_dick($cat));
  671.     $parent      = reset($sql->select(array(
  672.     'table' => 'categories',
  673.     'where' => array(
  674.                'name = '.$cat[0],
  675.                'or',
  676.                'url = '.$cat[(count($cat) - 2)]
  677.                )
  678.     )));
  679.     $category = reset($sql->select(array(
  680.     'table' => 'categories',
  681.     'where' => array(
  682.                'name = '.$cat[0],
  683.                'and',
  684.                'parent = '.($parent['id'] ? $parent['id'] : 0),
  685.                'or',
  686.                'url = '.$cat[(count($cat) - 1)],
  687.                'and',
  688.                'parent = '.($parent['id'] ? $parent['id'] : 0)
  689.                )
  690.     )));
  691.     $category = ($category ? $category['id'] : $parent['id']);
  692.  
  693. return $category;
  694. }
  695.  
  696. ////////////////////////////////////////////////////////
  697. // Function:    cute_that
  698. // Description: ëèٌٍàهٍ ٌٍèëè
  699.  
  700. function cute_that($return1 = 'class="enabled"', $return2 = 'class="disabled"', $every = 2){
  701. static $ggg;
  702.  
  703.     $ggg++;
  704.  
  705.     if ($ggg%$every == 0){
  706.         return $return1;
  707.     } else {
  708.         return $return2;
  709.     }
  710. }
  711.  
  712. ////////////////////////////////////////////////////////
  713. // Function:    cache_remover
  714. // Description: êàêà÷èٌٍèëüùèê
  715.  
  716. function cache_remover($alone = ''){
  717.  
  718.  
  719.  
  720.  
  721. return true;
  722. }
  723.  
  724. ////////////////////////////////////////////////////////
  725. // Function:    cute_cache
  726. // Description: êàêàىéêهً
  727.  
  728. function cute_cache($file, $uniqid = '', $ext = ''){
  729. global $cache_file, $template;
  730.  
  731.     $cache_file = rootpath.'/cache/'.$file.($template ? '-'.$template : '').($uniqid ? '('.$uniqid.')' : '').($ext ? '.'.$ext : '').'.tmp';
  732.  
  733.     if (file_exists($cache_file) and cache){
  734.         return file_read($cache_file);
  735.     }
  736.  
  737. return false;
  738. }
  739.  
  740. ////////////////////////////////////////////////////////
  741. // Function:    cache_touch_this
  742.  
  743. function cache_touch_this(){
  744. static $cache_touch_this;
  745.  
  746.     $cache_touch_this++;
  747.  
  748. return ($cache_touch_this == 1 ? '' : $cache_touch_this);
  749. }
  750.  
  751. ////////////////////////////////////////////////////////
  752. // Function:    cute_lang
  753. // Description: âûلîً ےçûêîâîمî ىîنَëے
  754.  
  755. function cute_lang($module = ''){
  756. global $mod, $config_lang;
  757.  
  758.     if (!file_exists($global = rootpath.'/inc/lang/'.$config_lang.'/global.ini')){
  759.         $global = rootpath.'/inc/lang/en/global.ini';
  760.     }
  761.  
  762.     if (!file_exists($local = rootpath.'/inc/lang/'.$config_lang.'/'.($module ? $module : $mod).'.ini')){
  763.         $local = rootpath.'/inc/lang/en/'.($module ? $module : $mod).'.ini';
  764.     }
  765.  
  766.     if (file_exists($global)){
  767.         $lang = parse_ini_file($global, true);
  768.     }
  769.  
  770.     if (file_exists($local)){
  771.         $lang = array_merge($lang, parse_ini_file($local, true));
  772.     }
  773. return $lang;
  774. }
  775.  
  776. ////////////////////////////////////////////////////////
  777. // Function:    md5x
  778. // Description: êîمنà ىû مîâîًèى "ُ" ىû ïîنًàçَىهâàهى َُé
  779.  
  780. function md5x($str){
  781.  
  782.     $str = md5(md5($str));
  783.  
  784. return $str;
  785. }
  786.  
  787. ////////////////////////////////////////////////////////
  788. // Function:    iconv
  789. // Description: هٌëè يه ٌٍَàيîâëهيà لèلëèîٍهêà ïهًهêîنèًîâîê
  790.  
  791. if (!function_exists('iconv')){
  792.     function iconv($in_charset, $out_charset, $str){
  793.     return preg_replace_callback('/([\xC0-\xFF\xA8\xB8])/', 'win2utf_char', $str);
  794.     }
  795.  
  796.     function win2utf_char($c){
  797.  
  798.         list(,$c) = $c;
  799.         if ($c == "\xA8"){return "\xD0\x81";}
  800.         if ($c == "\xB8"){return "\xD1\x91";}
  801.         if ($c >= "\xC0" and $c <= "\xEF"){return "\xD0".chr(ord($c) - 48);}
  802.         if ($c >= "\xF0"){return "\xD1".chr(ord($c) - 112);}
  803.  
  804.     return $c;
  805.     }
  806. }
  807.  
  808. ////////////////////////////////////////////////////////
  809. // Function:    unhtmlentities
  810. // Description:    âîçâًàùهيèه ïîٌëه htmlentities() è htmlspecialchars()
  811.  
  812. function unhtmlentities($string){
  813.  
  814.     $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  815.     $trans_tbl = array_flip($trans_tbl);
  816.  
  817. return strtr($string, $trans_tbl);
  818. }
  819.  
  820. ////////////////////////////////////////////////////////
  821. // Function:    namespace
  822. // Description:    نîلàâëےهٍ ïîًےنêîâûé يîىهً َ "سذثَ"
  823.  
  824. function namespace($str){
  825. global $sql, $mod;
  826.  
  827.     foreach ($sql->select(array('table' => 'news')) as $row){
  828.         if (@preg_match("/$str([0-9]+)?/i", $row['url'])){
  829.             $result[] = $row['id'];
  830.         }
  831.     }
  832.  
  833.     $count = count($result);
  834.  
  835.     if ($mod == 'addnews'){
  836.         $count++;
  837.     }
  838.  
  839. return totranslit($str.(($count and $count != 1) ? ' '.$count : ''));
  840. }
  841. ?>
Add Comment
Please, Sign In to add comment