пятница, 1 февраля 2013 г.

DLE Замена url на leech для всех старый новостей


было дело, начал писать свой скрипт,
хотя оказалось что скрипт уже написан

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 <?php
 
   //
   //    Created by nick-on                                               
   //    icq: 834361, nick-on@mail.ru, http://nick-on.ru
   // 
 
    set_time_limit( 0 );
 
    define ( "DATALIFEENGINE", true );
 
      define ( "ROOT_DIR", dirname ( __FILE__ ));
 
      define ( "ENGINE_DIR", ROOT_DIR . "/engine/" );
 
    require_once ROOT_DIR . '/engine/classes/mysql.php';
 
      require_once ROOT_DIR . '/engine/data/config.php';
 
      require_once ROOT_DIR . '/engine/data/dbconfig.php';
 
      require_once ROOT_DIR . '/engine/classes/parse.class.php';
 
 
    $sql_result = $db->query ( "SELECT * FROM " . PREFIX . "_post" );
 
    $parse = new ParseFilter(Array(), Array(), 1, 1);
 
    while ( $row = $db->get_row ( $sql_result ))
    {
 
        $short_story = $parse->decodeBBCodes( $row['short_story'], false );
        $full_story  = $parse->decodeBBCodes( $row['full_story'],  false );
 
 
        $short_story = str_replace ( "[url=", "[leech=", $short_story );
        $full_story  = str_replace ( "[url=", "[leech=", $full_story );
 
         $short_story = str_replace ( "[/url]", "[/leech]", $short_story );
         $full_story     = str_replace ( "[/url]", "[/leech]", $full_story );
 
          $short_story = $db->safesql ( $parse->BB_Parse( $parse->process( $short_story ), false));
          $full_story     = $db->safesql ( $parse->BB_Parse( $parse->process( $full_story ), false));
 
          $db->query ( "UPDATE " . PREFIX . "_post SET short_story = '{$short_story}', full_story = '{$full_story}' WHERE id = '{$row['id']}'" );
 
 
    }
 
    $db->free();
 
?>

а вот что я хотел написать, 99% готово
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 <meta http-equiv="content-type" content="application/xhtml+xml; charset=windows-1251" />
<?php
 
 
 
@ob_start();
@ob_implicit_flush(0);
 
if( !defined( 'E_DEPRECATED' ) ) {
 
 @error_reporting ( E_ALL ^ E_WARNING ^ E_NOTICE );
 @ini_set ( 'error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE );
 
} else {
 
 @error_reporting ( E_ALL ^ E_WARNING ^ E_DEPRECATED ^ E_NOTICE );
 @ini_set ( 'error_reporting', E_ALL ^ E_WARNING ^ E_DEPRECATED ^ E_NOTICE );
 
}
 
@ini_set ( 'display_errors', true );
@ini_set ( 'html_errors', false );
 
define ( 'DATALIFEENGINE', true );
define ( 'ROOT_DIR', dirname ( __FILE__ ) );
define ( 'ENGINE_DIR', ROOT_DIR . '/engine' );
 
 
require_once (ENGINE_DIR . '/inc/include/init.php');
 
 
$db->query ( "SELECT id FROM " . PREFIX . "_post WHERE 1" );
$all_id = array ();
while ( $row = $db->get_row () ) {
 $all_id[] = $row['id'];
}
 
echo (sizeof($all_id));
$n = intval($_GET['id']);
echo "#$n#<br><br>";
$once = 5;
$_p1='';
 
foreach ($all_id as $k=>$id) {
 if ($k>=$n && $k<($n+$once) ){
  $_p1[] = (int) $id; 
 } 
}
 
if(!strlen($_p1)) exit;
 
$_p1 = implode(',', $_p1);
 
$db->query ( "SELECT * FROM " . PREFIX . "_post WHERE id in ($_p1)" );
$data = array ();
while ( $row = $db->get_row () ) {
 $data[] = $row;
}
 
 
foreach ($data as $k=>$row) {
 echo "<br>({$row['id']})";
 $row["short_story"] = addLeach($row["short_story"]);
 $row["full_story"]  = addLeach($row["full_story"]);
 
 
 $db->query ( " UPDATE " . PREFIX . "_post 
     SET 
      `full_story`  = '{$db->safesql($row["full_story"])}',
      `short_story` = '{$db->safesql($row["short_story"])}'
      WHERE 
      id = {$row['id']}" );
 
}
 
 
sleep (1);
#header ('Location: /leech_conv.php?id='. $n + $once);
$url = '/leech_conv.php?id='. ($n + $once);
 
 
echo '<META HTTP-EQUIV="Refresh"CONTENT="0; URL='.$url.'">'; 
 
 
function addLeach($html)
{ // BEGIN function addLeach
 
    $html = preg_replace( "#<a href=[\"'](http://|https://|ftp://|ed2k://|news://|magnet:)?(\S.+?)['\"].*?" . ">(.+?)</a>#ie", "\make_leech('\\1\\2', '\\3')", $html );
 
 return $html;
 
} // END function addLeach
 
 
function make_leech($url = "", $show = "") {
    GLOBAL $config;
 
 $show = stripslashes( $show );
 
 $url_html = $config['http_home_url'] . "engine/go.php?url=" . rawurlencode( base64_encode( $url ) );
 $target = 'target="_blank" ' ;
 
 $pos = strpos("$url" ,"engine/go.php?url=");
 if ($pos === false) {
  return "<!--dle_leech_begin--><a href=\"" . $url_html . "\" " . $target . ">" . $show . "</a><!--dle_leech_end-->";
 }else{
  return "<a href=\"" . $url . "\" " . $target . ">" . $show . "</a>";
 }
}
 
?>

1 комментарий: