IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

EDI, CMS, Outils, Scripts et API PHP Discussion :

Adapter rowiki à php 7.0 ou 5.6 !


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Janvier 2016
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Janvier 2016
    Messages : 10
    Points : 4
    Points
    4
    Par défaut Adapter rowiki à php 7.0 ou 5.6 !
    J'ai modifié un peu le code. Mais il reste des optimisations à faire et toujours l'erreur :
    ''Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    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
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    <?php
    /*
    		roWiki
    		Author: Marc Rohlfing <rowiki@rowlff.de>
    		Version: 1.05 (2005-06-04)
    		Home/Docs/Licensing: www.rowlff.de/rowiki/
    */
     
    // Configuration and language variables. Set these to your values:
        $WIKI_TITLE			=	"roWiki";
        $START_PAGE			=	"Accueil";
        $HOME_BUTTON		=	"Accueil";
        $HELP_BUTTON		=	"Aide";
        $EDIT_BUTTON		=	"Edit Page";
        $DEFAULT_CONTENT	=	"This is an empty page";
        $DONE_BUTTON		=	"Done";
        $PROTECTED_BUTTON 	=	"Locked Page";
        $SEARCH_BUTTON		=	"Search";
        $SEARCH_RESULTS		=	"Search results for";
        $NEW_PAGE			=	"New Page";
        $RECENT_CHANGES		=	"Recent Changes";
        $LAST_CHANGE		=	"Last change:";
        $TIME_FORMAT		=	"%m/%d/%y %R";
    	$PAGES_DIR			= 	"pages/";
    	$BACKUP_DIR			=	"history/";
        $CONTENT            =   "";
     
        $PAGE_ISSET = isset($_GET['page']) ? $_GET['page'] : '';
        $ACTION_ISSET = isset($_GET['action']) ? $_GET['action'] : '';
        $QUERY_ISSET = isset($_GET['query']) ? $_GET['query'] : '';
     
    // Determine page to display
        if (! $PAGE_TITLE = $PAGE_ISSET) {
            if ($ACTION_ISSET == "search")
                $PAGE_TITLE = "$SEARCH_RESULTS \"$_GET[query]\"";
            elseif ($ACTION_ISSET == "recent")
                $PAGE_TITLE = "$RECENT_CHANGES";
            else
                $PAGE_TITLE = "$START_PAGE";
        }
    // Catch malicious paths
        if (preg_match("/\//", $PAGE_TITLE))
    		$PAGE_TITLE = $START_PAGE;	
    // Write changes to page, if there are any
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (! $file = @fopen($PAGES_DIR . stripslashes($_POST["page"]) . ".txt", "w"))
                die("Could not write page!");
            if (get_magic_quotes_gpc())
    	        fputs($file, trim(stripslashes($_POST["content"])));
    	    else
    	        fputs($file, trim($_POST["content"]));	    
            fclose($file);        
            if ($BACKUP_DIR <> '') {
    	         if (! $file = @fopen($BACKUP_DIR . $_POST["page"] . ".bak", "a"))
        	        die("Could not write backup of page!");
            	fputs($file, "\n\n\n--------------------\n" . strftime("$TIME_FORMAT", time()) . " / " . $_SERVER['REMOTE_ADDR'] . "\n--------------------\n");
    	        if (get_magic_quotes_gpc())
        	    	fputs($file, trim(stripslashes($_POST["content"])));
        	    else
        	    	fputs($file, trim($_POST["content"]));    	    
            	fclose($file);
            }
            header("location: index.php?page=" . urlencode(stripslashes($_POST[page])));
        }
    // Read and parse template
        if (! $file = @fopen("Template.html", "r"))
            die("'Template.html' is missing!");
        $template = fread($file, filesize("Template.html"));
        fclose($file);
    // Read page contents and time of last change
        if (($file = @fopen($PAGES_DIR . $PAGE_TITLE . ".txt", "r")) || $ACTION_ISSET <> "") {
            $TIME = strftime("$TIME_FORMAT", @filemtime($PAGES_DIR . $PAGE_TITLE . ".txt"));
            $CONTENT = "\n" . @fread($file, @filesize($PAGES_DIR . $PAGE_TITLE . ".txt")) . "\n";
            @fclose($file);
    		$CONTENT = preg_replace("/\\$/Umsi", "$", $CONTENT);
    		$CONTENT = preg_replace("/\\\/Umsi", "\", $CONTENT);
        }
        else {
            $ACTION_ISSET = "edit";
            $TIME = "$NEW_PAGE";
        }
    // Determine access mode
        if ($ACTION_ISSET == "edit" || $ACTION_ISSET <> "")
            $html = preg_replace('/{EDIT}/', "$EDIT_BUTTON", $template);
        elseif (is_writable($PAGES_DIR . $PAGE_TITLE . ".txt"))
            $html = preg_replace('/{EDIT}/', "<a href=\"index.php?page=$PAGE_TITLE&action=edit\">$EDIT_BUTTON</a>", $template);
        else
            $html = preg_replace('/{EDIT}/', "$PROTECTED_BUTTON", $template);
        if ($ACTION_ISSET == "recent")
            $html = preg_replace('/{RECENT_CHANGES}/', "$RECENT_CHANGES", $html);
        else
            $html = preg_replace('/{RECENT_CHANGES}/', "<a href=\"index.php?action=recent\">$RECENT_CHANGES</a>", $html);
    // Put values into template
        $html = preg_replace('/{PAGE_TITLE}/', "$PAGE_TITLE", $html);
        if ($PAGE_TITLE == $START_PAGE && $ACTION_ISSET <> "search")
            $html = preg_replace('/{HOME}/', "$HOME_BUTTON", $html);
        else
            $html = preg_replace('/{HOME}/', "<a href=\"index.php\">$HOME_BUTTON</a>", $html);
        $html = preg_replace('/{WIKI_TITLE}/', $WIKI_TITLE, $html);
        $html = preg_replace('/{LAST_CHANGE}/', $LAST_CHANGE, $html);
        if ($PAGE_TITLE == $HELP_BUTTON)
    	    $html = preg_replace('/{HELP}/', "$HELP_BUTTON", $html);    
        else
    	    $html = preg_replace('/{HELP}/', "<a href=\"index.php?page=$HELP_BUTTON\">$HELP_BUTTON</a>", $html);
        $html = preg_replace('/{SEARCH}/', "<form method=\"get\" action=\"index.php\"><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$QUERY_ISSET\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" /></form>", $html);
        if ($ACTION_ISSET == "edit") {
        	if ($CONTENT == '')
        		$CONTENT = $DEFAULT_CONTENT;
            $CONTENT = "<form method=\"post\" action=\"index.php\"><textarea name=\"content\" cols=\"90\" rows=\"30\">$CONTENT</textarea><input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br /><input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></form>";
    	}
    // Search pages
        if ($ACTION_ISSET == "search") {
            $dir = opendir(getcwd() . "/$PAGES_DIR");
            while ($file = readdir($dir)) {
                if (preg_match("/.txt/", $file)) {
                    $handle = fopen($PAGES_DIR . $file, "r");
                    $content = fread($handle, filesize($PAGES_DIR . $file));
                    fclose($handle);
                    if (preg_match("/$_GET[query]/i", $content) || preg_match("/$_GET[query]/i", "$PAGES_DIR/$file")) {
                        $file = substr($file, 0, strlen($file) - 4);
                        $CONTENT .= "<p><a href=\"index.php?page=$file\">$file</a></p>";
                    }
                }
            }
            $TIME = "-";
        }
    // Recent changes
        elseif ($ACTION_ISSET == "recent") {
            $dir = opendir(getcwd() . "/$PAGES_DIR");
            while ($file = readdir($dir))
                if (preg_match("/.txt/", $file))
                    $filetime[$file] = filemtime($PAGES_DIR . $file);
            arsort($filetime);
            $filetime = array_slice($filetime, 0, 10);
            foreach ($filetime as $filename => $timestamp) {
                $filename = substr($filename, 0, strlen($filename) - 4);
                $CONTENT .= "<p><a href=\"index.php?page=$filename\">$filename</a> (" . strftime("$TIME_FORMAT", $timestamp) . ")</p>";
            }
            $TIME = "-";
        }
    // Prepare page formatting
        elseif ($ACTION_ISSET <> "edit") {
            $CONTENT = htmlentities($CONTENT);
    		$CONTENT = preg_replace("/&amp;#036;/Umsi", "$", $CONTENT);
    		$CONTENT = preg_replace("/&amp;#092;/Umsi", "\", $CONTENT);
    		$CONTENT = preg_replace("/\^(.)/Umsie", "'&#'.ord('\\1').';'", $CONTENT);
    		$CONTENT = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&amp;,\+]*)\]#U', '<a href="xx$2" class="url">$1</a>', $CONTENT);
    		$CONTENT = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $CONTENT);
    		$CONTENT = preg_replace('#(https?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*)#i', '<a href="$0" class="url">$1</a>', $CONTENT);
    		$CONTENT = preg_replace('#xxttp#', 'http', $CONTENT);
    //		preg_match_all("/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER);
    		preg_match_all("/\[([^\/]+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER);
    		foreach ($matches[1] as $match)
    			if (file_exists("$PAGES_DIR/$match.txt"))
    				$CONTENT = str_replace("[$match]", "<a href=\"index.php?page=$match\">$match</a>", $CONTENT);
    			else
    				$CONTENT = str_replace("[$match]", "<a class=\"pending\" href=\"index.php?page=$match\">$match</a>", $CONTENT);
    		$CONTENT = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '<a href="mailto:$0">$0</a>', $CONTENT);
            $CONTENT = preg_replace('/^\*\*\*(.*)(\n)/Um', "<ul><ul><ul><li>$1</li></ul></ul></ul>$2", $CONTENT);
            $CONTENT = preg_replace('/^\*\*(.*)(\n)/Um', "<ul><ul><li>$1</li></ul></ul>$2", $CONTENT);
            $CONTENT = preg_replace('/^\*(.*)(\n)/Um', "<ul><li>$1</li></ul>$2", $CONTENT);
            $CONTENT = preg_replace('/^\#\#\#(.*)(\n)/Um', "<ol><ol><ol><li>$1</li></ol></ol></ol>$2", $CONTENT);
            $CONTENT = preg_replace('/^\#\#(.*)(\n)/Um', "<ol><ol><li>$1</li></ol></ol>$2", $CONTENT);
            $CONTENT = preg_replace('/^\#(.*)(\n)/Um', "<ol><li>$1</li></ol>$2", $CONTENT);
            $CONTENT = preg_replace('/(<\/ol>\n*<ol>|<\/ul>\n*<ul>)/', "", $CONTENT);
            $CONTENT = preg_replace('/^!!!(.*)(\n)/Um', '<h1>$1</h1>$2', $CONTENT);
            $CONTENT = preg_replace('/^!!(.*)(\n)/Um', '<h2>$1</h2>$2', $CONTENT);
            $CONTENT = preg_replace('/^!(.*)(\n)/Um', '<h3>$1</h3>$2', $CONTENT);
            while (preg_match('/^  /Um', $CONTENT))
    			$CONTENT = preg_replace('/^( +) ([^ ])/Um', '$1&nbsp;&nbsp;&nbsp;&nbsp;$2', $CONTENT);
    		$CONTENT = preg_replace('/^ /Um', '&nbsp;&nbsp;&nbsp;&nbsp;', $CONTENT);
            $CONTENT = preg_replace('/----(\r\n|\r|\n)/m', '<hr />', $CONTENT);
            $CONTENT = preg_replace('/\n/', '<br />', $CONTENT);
    		$CONTENT = preg_replace('#</ul>(<br />)*#', "</ul>", $CONTENT);
    		$CONTENT = preg_replace('#</ol>(<br />)*#', "</ol>", $CONTENT);
            $CONTENT = preg_replace('#(</h[123]>)<br />#', "$1", $CONTENT);
            $CONTENT = preg_replace("/{(.+)}/Ue", "'<code><pre>' . preg_replace('#<br />#', '', '\\1') . '</pre></code>'", $CONTENT);
            $CONTENT = preg_replace("/'''(.*)'''/Um", '<b>$1</b>', $CONTENT);
            $CONTENT = preg_replace("/''(.*)''/Um", '<i>$1</i>', $CONTENT); 
            $CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6);
        }
    // Print page        
        $html = preg_replace("/{CONTENT}/", "$CONTENT", $html);
        $html = preg_replace('/{TIME}/', $TIME, $html);
        echo $html;
    ?>

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    preg_replace n'a pas été retiré de PHP 7.

    Pour les "notice" tu peux cacher ce type d'erreur ou faire un contournement rapide :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    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
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    <?php
    /*
    		roWiki
    		Author: Marc Rohlfing <rowiki@rowlff.de>
    		Version: 1.02 (2005-01-04)
    		Home/Docs/Licensing: www.rowlff.de/rowiki/
    */
     
    // Configuration and language variables. Set these to your values:
        $WIKI_TITLE			=	"roWiki";
        $START_PAGE			=	"Accueil";
        $HOME_BUTTON		=	"Accueil";
        $HELP_BUTTON		=	"Aide";
        $EDIT_BUTTON		=	"Edit Page";
        $DONE_BUTTON		=	"Done";
        $PROTECTED_BUTTON 	=	"Locked Page";
        $SEARCH_BUTTON		=	"Search";
        $SEARCH_RESULTS		=	"Search results for";
        $NEW_PAGE			=	"New Page";
        $RECENT_CHANGES		=	"Recent Changes";
        $TIME_FORMAT		=	"%m/%d/%y %R";
    	$PAGES_DIR			= 	"pages/";
    	$BACKUP_DIR			=	"history/";
     
    	$page = isset($_GET['page']) ? $_GET['page'] : '';
    	$action = isset($_GET['action']) ? $_GET['action'] : '';
    	$query = isset($_GET['query']) ? $_GET['query'] : '';
     
    // Determine page to display
        if (! $PAGE_TITLE = $page) {
            if ($action == "search")
                $PAGE_TITLE = "$SEARCH_RESULTS \"$_GET[query]\"";
            elseif ($action == "recent")
                $PAGE_TITLE = "$RECENT_CHANGES";
            else
                $PAGE_TITLE = "$START_PAGE";
        }
    // Catch malicious paths
        if (preg_match("/\//", $PAGE_TITLE))
    		$PAGE_TITLE = $START_PAGE;	
    // Write changes to page, if there are any
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (! $file = @fopen($PAGES_DIR . stripslashes($_POST["page"]) . ".txt", "w"))
                die ("Could not write page!");
            fputs($file, trim(stripslashes($_POST["content"])));
            fclose($file);
            if ($BACKUP_DIR <> '') {
    	         if (! $file = @fopen($BACKUP_DIR . $_POST["page"] . ".bak", "a"))
        	        die ("Could not write backup of page!");
            	fputs($file, "\n\n\n--------------------\n" . strftime("$TIME_FORMAT", time()) . " / " . $_SERVER['REMOTE_ADDR'] . "\n--------------------\n");
            	fputs($file, trim(stripslashes($_POST["content"])));
            	fclose($file);
            }
            header("location: index.php?page=" . urlencode(stripslashes($_POST[page])));
        }
    // Read and parse template
        if (! $file = @fopen("template.html", "r"))
            die ("'template.html' is missing!");
        $template = fread($file, filesize("template.html"));
        fclose($file);
    // Read page contents and time of last change
        if (($file = @fopen($PAGES_DIR . $PAGE_TITLE . ".txt", "r")) || $action <> "") {
            $TIME = strftime("$TIME_FORMAT", @filemtime($PAGES_DIR . $PAGE_TITLE . ".txt"));
            $CONTENT = "\n" . @fread($file, @filesize($PAGES_DIR . $PAGE_TITLE . ".txt")) . "\n";
            @fclose($file);
    		$CONTENT = preg_replace("/\\$/Umsi", "$", $CONTENT);
        }
        else {
            $action = "edit";
            $TIME = "$NEW_PAGE";
        }
    // Determine access mode
        if ($action == "edit" || $action <> "")
            $html = preg_replace('/{EDIT}/', "$EDIT_BUTTON", $template);
        elseif (is_writable($PAGES_DIR . $PAGE_TITLE . ".txt"))
            $html = preg_replace('/{EDIT}/', "<a href=\"index.php?page=$PAGE_TITLE&action=edit\">$EDIT_BUTTON</a>", $template);
        else
            $html = preg_replace('/{EDIT}/', "$PROTECTED_BUTTON", $template);
        if ($action == "recent")
            $html = preg_replace('/{RECENT_CHANGES}/', "$RECENT_CHANGES", $html);
        else
            $html = preg_replace('/{RECENT_CHANGES}/', "<a href=\"index.php?action=recent\">$RECENT_CHANGES</a>", $html);
    // Put values into template
        $html = preg_replace('/{PAGE_TITLE}/', "$PAGE_TITLE", $html);
        if ($PAGE_TITLE == $START_PAGE && $action <> "search")
            $html = preg_replace('/{HOME}/', "$HOME_BUTTON", $html);
        else
            $html = preg_replace('/{HOME}/', "<a href=\"index.php\">$HOME_BUTTON</a>", $html);
        $html = preg_replace('/{WIKI_TITLE}/', $WIKI_TITLE, $html);
        if ($PAGE_TITLE == $HELP_BUTTON)
    	    $html = preg_replace('/{HELP}/', "$HELP_BUTTON", $html);    
        else
    	    $html = preg_replace('/{HELP}/', "<a href=\"index.php?page=$HELP_BUTTON\">$HELP_BUTTON</a>", $html);
        $html = preg_replace('/{SEARCH}/', "<form method=\"get\" action=\"index.php\"><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$query\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" /></form>", $html);
        if ($action == "edit")
            $CONTENT = "<form method=\"post\" action=\"index.php\"><textarea name=\"content\" cols=\"90\" rows=\"30\">$CONTENT</textarea><input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br /><input type=\"submit\" value=\"$DONE_BUTTON\" /></form>";
    // Search pages
        if ($action == "search") {
            $dir = opendir(getcwd() . "/$PAGES_DIR");
            while ($file = readdir($dir)) {
                if (preg_match("/.txt/", $file)) {
                    $handle = fopen($PAGES_DIR . $file, "r");
                    $content = fread($handle, filesize($PAGES_DIR . $file));
                    fclose($handle);
                    if (preg_match("/$query/i", $content) || preg_match("/$query/i", "pages/$file")) {
                        $file = substr($file, 0, strlen($file) - 4);
                        $CONTENT .= "<p><a href=\"index.php?page=$file\">$file</a></p>";
                    }
                }
            }
            $TIME = "-";
        }
    // Recent changes
        elseif ($action == "recent") {
            $dir = opendir(getcwd() . "/$PAGES_DIR");
            while ($file = readdir($dir))
                if (preg_match("/.txt/", $file))
                    $filetime[$file] = filemtime($PAGES_DIR . $file);
            arsort($filetime);
            $filetime = array_slice($filetime, 0, 10);
            foreach ($filetime as $filename => $timestamp) {
                $filename = substr($filename, 0, strlen($filename) - 4);
                $CONTENT .= "<p><a href=\"index.php?page=$filename\">$filename</a> (" . strftime("$TIME_FORMAT", $timestamp) . ")</p>";
            }
            $TIME = "-";
        }
    // Prepare page formatting
        elseif ($action <> "edit") {
            $CONTENT = htmlentities($CONTENT);
    		$CONTENT = preg_replace("/&amp;#036;/Umsi", "$", $CONTENT);
    		$CONTENT = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&amp;,\+]*)\]#U', '<a href="xx$2">$1</a>', $CONTENT);
    		$CONTENT = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $CONTENT);
    		$CONTENT = preg_replace('#(https?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*)#i', '<a href="$0">$1</a>', $CONTENT);
    		$CONTENT = preg_replace('#xxttp#', 'http', $CONTENT);
            $CONTENT = preg_replace("/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U", '<a href="index.php?page=$1">$1</a>', $CONTENT);
            $CONTENT = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '<a href="mailto:$0">$0</a>', $CONTENT);
            $CONTENT = preg_replace('/^\*(.*)\n/Um', "<ul><li>$1</li></ul>", $CONTENT);
            $CONTENT = preg_replace('/^\#(.*)\n/Um', "<ol><li>$1</li></ol>", $CONTENT);
            $CONTENT = preg_replace('/(<\/ol><ol>|<\/ul><ul>)/', "", $CONTENT);
            $CONTENT = preg_replace('/^!!!(.*)(\n)/Um', '<h1>$1</h1>$2', $CONTENT);
            $CONTENT = preg_replace('/^!!(.*)(\n)/Um', '<h2>$1</h2>$2', $CONTENT);
            $CONTENT = preg_replace('/^!(.*)(\n)/Um', '<h3>$1</h3>$2', $CONTENT);
            $CONTENT = preg_replace('/----(\r\n|\r|\n)/m', '<hr>', $CONTENT);
            $CONTENT = preg_replace('/\n/', '<br />', $CONTENT);
            $CONTENT = preg_replace('#(</h[123]>)<br />#', "$1", $CONTENT);
            $CONTENT = preg_replace("/{(.+)}/Ue", "'<code><pre>' . preg_replace('#<br />#', '', '\\1') . '</pre></code>'", $CONTENT);
            $CONTENT = preg_replace("/'''(.*)'''/Um", '<b>$1</b>', $CONTENT);
            $CONTENT = preg_replace("/''(.*)''/Um", '<i>$1</i>', $CONTENT); 
            $CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6);
        }
    // Print page            
        $html = preg_replace("/{CONTENT}/", "$CONTENT", $html);
        $html = preg_replace('/{TIME}/', $TIME, $html);
        echo $html;
    ?>
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Janvier 2016
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Janvier 2016
    Messages : 10
    Points : 4
    Points
    4
    Par défaut
    Merci
    Je veux aussi enlever l'erreur "Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in C:\Wamp\www\RoWiki\index.php on line 140".

    PS : Corrigez aussi si il y a des optimisations à faire.

  4. #4
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Janvier 2016
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Janvier 2016
    Messages : 10
    Points : 4
    Points
    4
    Par défaut
    J'ai modifié un peu le code. Mais il reste des optimisations à faire et toujours l'erreur :
    ''Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    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
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    <?php
    /*
    		roWiki
    		Author: Marc Rohlfing <rowiki@rowlff.de>
    		Version: 1.05 (2005-06-04)
    		Home/Docs/Licensing: www.rowlff.de/rowiki/
    */
     
    // Configuration and language variables. Set these to your values:
        $WIKI_TITLE			=	"roWiki";
        $START_PAGE			=	"Accueil";
        $HOME_BUTTON		=	"Accueil";
        $HELP_BUTTON		=	"Aide";
        $EDIT_BUTTON		=	"Edit Page";
        $DEFAULT_CONTENT	=	"This is an empty page";
        $DONE_BUTTON		=	"Done";
        $PROTECTED_BUTTON 	=	"Locked Page";
        $SEARCH_BUTTON		=	"Search";
        $SEARCH_RESULTS		=	"Search results for";
        $NEW_PAGE			=	"New Page";
        $RECENT_CHANGES		=	"Recent Changes";
        $LAST_CHANGE		=	"Last change:";
        $TIME_FORMAT		=	"%m/%d/%y %R";
    	$PAGES_DIR			= 	"pages/";
    	$BACKUP_DIR			=	"history/";
        $CONTENT            =   "";
     
        $PAGE_ISSET = isset($_GET['page']) ? $_GET['page'] : '';
        $ACTION_ISSET = isset($_GET['action']) ? $_GET['action'] : '';
        $QUERY_ISSET = isset($_GET['query']) ? $_GET['query'] : '';
     
    // Determine page to display
        if (! $PAGE_TITLE = $PAGE_ISSET) {
            if ($ACTION_ISSET == "search")
                $PAGE_TITLE = "$SEARCH_RESULTS \"$_GET[query]\"";
            elseif ($ACTION_ISSET == "recent")
                $PAGE_TITLE = "$RECENT_CHANGES";
            else
                $PAGE_TITLE = "$START_PAGE";
        }
    // Catch malicious paths
        if (preg_match("/\//", $PAGE_TITLE))
    		$PAGE_TITLE = $START_PAGE;	
    // Write changes to page, if there are any
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (! $file = @fopen($PAGES_DIR . stripslashes($_POST["page"]) . ".txt", "w"))
                die("Could not write page!");
            if (get_magic_quotes_gpc())
    	        fputs($file, trim(stripslashes($_POST["content"])));
    	    else
    	        fputs($file, trim($_POST["content"]));	    
            fclose($file);        
            if ($BACKUP_DIR <> '') {
    	         if (! $file = @fopen($BACKUP_DIR . $_POST["page"] . ".bak", "a"))
        	        die("Could not write backup of page!");
            	fputs($file, "\n\n\n--------------------\n" . strftime("$TIME_FORMAT", time()) . " / " . $_SERVER['REMOTE_ADDR'] . "\n--------------------\n");
    	        if (get_magic_quotes_gpc())
        	    	fputs($file, trim(stripslashes($_POST["content"])));
        	    else
        	    	fputs($file, trim($_POST["content"]));    	    
            	fclose($file);
            }
            header("location: index.php?page=" . urlencode(stripslashes($_POST[page])));
        }
    // Read and parse template
        if (! $file = @fopen("Template.html", "r"))
            die("'Template.html' is missing!");
        $template = fread($file, filesize("Template.html"));
        fclose($file);
    // Read page contents and time of last change
        if (($file = @fopen($PAGES_DIR . $PAGE_TITLE . ".txt", "r")) || $ACTION_ISSET <> "") {
            $TIME = strftime("$TIME_FORMAT", @filemtime($PAGES_DIR . $PAGE_TITLE . ".txt"));
            $CONTENT = "\n" . @fread($file, @filesize($PAGES_DIR . $PAGE_TITLE . ".txt")) . "\n";
            @fclose($file);
    		$CONTENT = preg_replace("/\\$/Umsi", "$", $CONTENT);
    		$CONTENT = preg_replace("/\\\/Umsi", "\", $CONTENT);
        }
        else {
            $ACTION_ISSET = "edit";
            $TIME = "$NEW_PAGE";
        }
    // Determine access mode
        if ($ACTION_ISSET == "edit" || $ACTION_ISSET <> "")
            $html = preg_replace('/{EDIT}/', "$EDIT_BUTTON", $template);
        elseif (is_writable($PAGES_DIR . $PAGE_TITLE . ".txt"))
            $html = preg_replace('/{EDIT}/', "<a href=\"index.php?page=$PAGE_TITLE&action=edit\">$EDIT_BUTTON</a>", $template);
        else
            $html = preg_replace('/{EDIT}/', "$PROTECTED_BUTTON", $template);
        if ($ACTION_ISSET == "recent")
            $html = preg_replace('/{RECENT_CHANGES}/', "$RECENT_CHANGES", $html);
        else
            $html = preg_replace('/{RECENT_CHANGES}/', "<a href=\"index.php?action=recent\">$RECENT_CHANGES</a>", $html);
    // Put values into template
        $html = preg_replace('/{PAGE_TITLE}/', "$PAGE_TITLE", $html);
        if ($PAGE_TITLE == $START_PAGE && $ACTION_ISSET <> "search")
            $html = preg_replace('/{HOME}/', "$HOME_BUTTON", $html);
        else
            $html = preg_replace('/{HOME}/', "<a href=\"index.php\">$HOME_BUTTON</a>", $html);
        $html = preg_replace('/{WIKI_TITLE}/', $WIKI_TITLE, $html);
        $html = preg_replace('/{LAST_CHANGE}/', $LAST_CHANGE, $html);
        if ($PAGE_TITLE == $HELP_BUTTON)
    	    $html = preg_replace('/{HELP}/', "$HELP_BUTTON", $html);    
        else
    	    $html = preg_replace('/{HELP}/', "<a href=\"index.php?page=$HELP_BUTTON\">$HELP_BUTTON</a>", $html);
        $html = preg_replace('/{SEARCH}/', "<form method=\"get\" action=\"index.php\"><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$QUERY_ISSET\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" /></form>", $html);
        if ($ACTION_ISSET == "edit") {
        	if ($CONTENT == '')
        		$CONTENT = $DEFAULT_CONTENT;
            $CONTENT = "<form method=\"post\" action=\"index.php\"><textarea name=\"content\" cols=\"90\" rows=\"30\">$CONTENT</textarea><input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br /><input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></form>";
    	}
    // Search pages
        if ($ACTION_ISSET == "search") {
            $dir = opendir(getcwd() . "/$PAGES_DIR");
            while ($file = readdir($dir)) {
                if (preg_match("/.txt/", $file)) {
                    $handle = fopen($PAGES_DIR . $file, "r");
                    $content = fread($handle, filesize($PAGES_DIR . $file));
                    fclose($handle);
                    if (preg_match("/$_GET[query]/i", $content) || preg_match("/$_GET[query]/i", "$PAGES_DIR/$file")) {
                        $file = substr($file, 0, strlen($file) - 4);
                        $CONTENT .= "<p><a href=\"index.php?page=$file\">$file</a></p>";
                    }
                }
            }
            $TIME = "-";
        }
    // Recent changes
        elseif ($ACTION_ISSET == "recent") {
            $dir = opendir(getcwd() . "/$PAGES_DIR");
            while ($file = readdir($dir))
                if (preg_match("/.txt/", $file))
                    $filetime[$file] = filemtime($PAGES_DIR . $file);
            arsort($filetime);
            $filetime = array_slice($filetime, 0, 10);
            foreach ($filetime as $filename => $timestamp) {
                $filename = substr($filename, 0, strlen($filename) - 4);
                $CONTENT .= "<p><a href=\"index.php?page=$filename\">$filename</a> (" . strftime("$TIME_FORMAT", $timestamp) . ")</p>";
            }
            $TIME = "-";
        }
    // Prepare page formatting
        elseif ($ACTION_ISSET <> "edit") {
            $CONTENT = htmlentities($CONTENT);
    		$CONTENT = preg_replace("/&amp;#036;/Umsi", "$", $CONTENT);
    		$CONTENT = preg_replace("/&amp;#092;/Umsi", "\", $CONTENT);
    		$CONTENT = preg_replace("/\^(.)/Umsie", "'&#'.ord('\\1').';'", $CONTENT);
    		$CONTENT = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&amp;,\+]*)\]#U', '<a href="xx$2" class="url">$1</a>', $CONTENT);
    		$CONTENT = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $CONTENT);
    		$CONTENT = preg_replace('#(https?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*)#i', '<a href="$0" class="url">$1</a>', $CONTENT);
    		$CONTENT = preg_replace('#xxttp#', 'http', $CONTENT);
    //		preg_match_all("/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER);
    		preg_match_all("/\[([^\/]+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER);
    		foreach ($matches[1] as $match)
    			if (file_exists("$PAGES_DIR/$match.txt"))
    				$CONTENT = str_replace("[$match]", "<a href=\"index.php?page=$match\">$match</a>", $CONTENT);
    			else
    				$CONTENT = str_replace("[$match]", "<a class=\"pending\" href=\"index.php?page=$match\">$match</a>", $CONTENT);
    		$CONTENT = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '<a href="mailto:$0">$0</a>', $CONTENT);
            $CONTENT = preg_replace('/^\*\*\*(.*)(\n)/Um', "<ul><ul><ul><li>$1</li></ul></ul></ul>$2", $CONTENT);
            $CONTENT = preg_replace('/^\*\*(.*)(\n)/Um', "<ul><ul><li>$1</li></ul></ul>$2", $CONTENT);
            $CONTENT = preg_replace('/^\*(.*)(\n)/Um', "<ul><li>$1</li></ul>$2", $CONTENT);
            $CONTENT = preg_replace('/^\#\#\#(.*)(\n)/Um', "<ol><ol><ol><li>$1</li></ol></ol></ol>$2", $CONTENT);
            $CONTENT = preg_replace('/^\#\#(.*)(\n)/Um', "<ol><ol><li>$1</li></ol></ol>$2", $CONTENT);
            $CONTENT = preg_replace('/^\#(.*)(\n)/Um', "<ol><li>$1</li></ol>$2", $CONTENT);
            $CONTENT = preg_replace('/(<\/ol>\n*<ol>|<\/ul>\n*<ul>)/', "", $CONTENT);
            $CONTENT = preg_replace('/^!!!(.*)(\n)/Um', '<h1>$1</h1>$2', $CONTENT);
            $CONTENT = preg_replace('/^!!(.*)(\n)/Um', '<h2>$1</h2>$2', $CONTENT);
            $CONTENT = preg_replace('/^!(.*)(\n)/Um', '<h3>$1</h3>$2', $CONTENT);
            while (preg_match('/^  /Um', $CONTENT))
    			$CONTENT = preg_replace('/^( +) ([^ ])/Um', '$1&nbsp;&nbsp;&nbsp;&nbsp;$2', $CONTENT);
    		$CONTENT = preg_replace('/^ /Um', '&nbsp;&nbsp;&nbsp;&nbsp;', $CONTENT);
            $CONTENT = preg_replace('/----(\r\n|\r|\n)/m', '<hr />', $CONTENT);
            $CONTENT = preg_replace('/\n/', '<br />', $CONTENT);
    		$CONTENT = preg_replace('#</ul>(<br />)*#', "</ul>", $CONTENT);
    		$CONTENT = preg_replace('#</ol>(<br />)*#', "</ol>", $CONTENT);
            $CONTENT = preg_replace('#(</h[123]>)<br />#', "$1", $CONTENT);
            $CONTENT = preg_replace("/{(.+)}/Ue", "'<code><pre>' . preg_replace('#<br />#', '', '\\1') . '</pre></code>'", $CONTENT);
            $CONTENT = preg_replace("/'''(.*)'''/Um", '<b>$1</b>', $CONTENT);
            $CONTENT = preg_replace("/''(.*)''/Um", '<i>$1</i>', $CONTENT); 
            $CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6);
        }
    // Print page        
        $html = preg_replace("/{CONTENT}/", "$CONTENT", $html);
        $html = preg_replace('/{TIME}/', $TIME, $html);
        echo $html;
    ?>
    Le Template.html
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    <?xml version="1.0" encoding="iso-8859-1"?>
     
    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
     
          <style type="text/css"> @import "style.css"; </style>
     
          <title> {WIKI_TITLE} - {PAGE_TITLE} </title>
     
    </head>
     
    <body>
     
    <p align="right">
       <a href="http://www.rowlff.de/rowiki/"><img src="http://www.rowlff.de/rowiki/rowikibutton.png" border="0" alt="roWiki button" /></a>
    </p>
     
    <h2>{WIKI_TITLE} - {PAGE_TITLE}</h2>
     
    <div align="center">
       <div class="content" align="left">
          {CONTENT}
       </div>
    </div>
     
    {LAST_CHANGE} {TIME} | {EDIT} | {HELP} | {HOME} | {RECENT_CHANGES} | {SEARCH}
     
    </body>
     
    </html>

  5. #5
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Essaie :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $CONTENT = preg_replace_callback('/{(.+)}/U', create_function ('$matches', 'return "<code><pre>" . preg_replace("#<br />#", "", $matches[1]) . "</pre></code>"'), $CONTENT);
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  6. #6
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Janvier 2016
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Janvier 2016
    Messages : 10
    Points : 4
    Points
    4
    Par défaut
    Parse error: syntax error, unexpected '}' in C:\Wamp\www\WikWok\index.php(178) : runtime-created function on line 1
    Warning: preg_replace_callback(): Requires argument 2, '', to be a valid callback in C:\Wamp\www\WikWok\index.php on line 178

    PS : Si c'est possible je voudrais que quand quelqu'un modifie un fichier d'une page : un fichier LENOMDELAPAGE.lock soit créée temporairement et que l'édition de fichier soit bloqué jusqu'à la fin de l'édition pour éviter les pertes.

Discussions similaires

  1. adapter site php mysql pour pda
    Par Marsupilami36 dans le forum Webdesign & Ergonomie
    Réponses: 3
    Dernier message: 13/07/2009, 15h59
  2. adapter un sha1 php en delphi
    Par aphyl dans le forum Langage
    Réponses: 3
    Dernier message: 12/04/2009, 11h35
  3. [XSLT][PHP]adaptation à php5
    Par casafree dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 14/06/2007, 12h02
  4. [PHP-JS] XML/PHP adapté à mon application ?
    Par bblampain dans le forum Langage
    Réponses: 2
    Dernier message: 22/02/2007, 13h07
  5. [PHP] XML adapté au LDVH interactif ?
    Par doustij dans le forum XML/XSL et SOAP
    Réponses: 9
    Dernier message: 27/01/2007, 14h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo