@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 24 | 24 | |
@@ -31,161 +31,161 @@ discard block |
||
| 31 | 31 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 32 | 32 | */ |
| 33 | 33 | function couleur_html_to_hex($couleur) { |
| 34 | - $couleurs_html = [ |
|
| 35 | - 'aliceblue' => 'F0F8FF', |
|
| 36 | - 'antiquewhite' => 'FAEBD7', |
|
| 37 | - 'aqua' => '00FFFF', |
|
| 38 | - 'aquamarine' => '7FFFD4', |
|
| 39 | - 'azure' => 'F0FFFF', |
|
| 40 | - 'beige' => 'F5F5DC', |
|
| 41 | - 'bisque' => 'FFE4C4', |
|
| 42 | - 'black' => '000000', |
|
| 43 | - 'blanchedalmond' => 'FFEBCD', |
|
| 44 | - 'blue' => '0000FF', |
|
| 45 | - 'blueviolet' => '8A2BE2', |
|
| 46 | - 'brown' => 'A52A2A', |
|
| 47 | - 'burlywood' => 'DEB887', |
|
| 48 | - 'cadetblue' => '5F9EA0', |
|
| 49 | - 'chartreuse' => '7FFF00', |
|
| 50 | - 'chocolate' => 'D2691E', |
|
| 51 | - 'coral' => 'FF7F50', |
|
| 52 | - 'cornflowerblue' => '6495ED', |
|
| 53 | - 'cornsilk' => 'FFF8DC', |
|
| 54 | - 'crimson' => 'DC143C', |
|
| 55 | - 'cyan' => '00FFFF', |
|
| 56 | - 'darkblue' => '00008B', |
|
| 57 | - 'darkcyan' => '008B8B', |
|
| 58 | - 'darkgoldenrod' => 'B8860B', |
|
| 59 | - 'darkgray' => 'A9A9A9', |
|
| 60 | - 'darkgreen' => '006400', |
|
| 61 | - 'darkgrey' => 'A9A9A9', |
|
| 62 | - 'darkkhaki' => 'BDB76B', |
|
| 63 | - 'darkmagenta' => '8B008B', |
|
| 64 | - 'darkolivegreen' => '556B2F', |
|
| 65 | - 'darkorange' => 'FF8C00', |
|
| 66 | - 'darkorchid' => '9932CC', |
|
| 67 | - 'darkred' => '8B0000', |
|
| 68 | - 'darksalmon' => 'E9967A', |
|
| 69 | - 'darkseagreen' => '8FBC8F', |
|
| 70 | - 'darkslateblue' => '483D8B', |
|
| 71 | - 'darkslategray' => '2F4F4F', |
|
| 72 | - 'darkslategrey' => '2F4F4F', |
|
| 73 | - 'darkturquoise' => '00CED1', |
|
| 74 | - 'darkviolet' => '9400D3', |
|
| 75 | - 'deeppink' => 'FF1493', |
|
| 76 | - 'deepskyblue' => '00BFFF', |
|
| 77 | - 'dimgray' => '696969', |
|
| 78 | - 'dimgrey' => '696969', |
|
| 79 | - 'dodgerblue' => '1E90FF', |
|
| 80 | - 'firebrick' => 'B22222', |
|
| 81 | - 'floralwhite' => 'FFFAF0', |
|
| 82 | - 'forestgreen' => '228B22', |
|
| 83 | - 'fuchsia' => 'FF00FF', |
|
| 84 | - 'gainsboro' => 'DCDCDC', |
|
| 85 | - 'ghostwhite' => 'F8F8FF', |
|
| 86 | - 'gold' => 'FFD700', |
|
| 87 | - 'goldenrod' => 'DAA520', |
|
| 88 | - 'gray' => '808080', |
|
| 89 | - 'green' => '008000', |
|
| 90 | - 'greenyellow' => 'ADFF2F', |
|
| 91 | - 'grey' => '808080', |
|
| 92 | - 'honeydew' => 'F0FFF0', |
|
| 93 | - 'hotpink' => 'FF69B4', |
|
| 94 | - 'indianred' => 'CD5C5C', |
|
| 95 | - 'indigo' => '4B0082', |
|
| 96 | - 'ivory' => 'FFFFF0', |
|
| 97 | - 'khaki' => 'F0E68C', |
|
| 98 | - 'lavender' => 'E6E6FA', |
|
| 99 | - 'lavenderblush' => 'FFF0F5', |
|
| 100 | - 'lawngreen' => '7CFC00', |
|
| 101 | - 'lemonchiffon' => 'FFFACD', |
|
| 102 | - 'lightblue' => 'ADD8E6', |
|
| 103 | - 'lightcoral' => 'F08080', |
|
| 104 | - 'lightcyan' => 'E0FFFF', |
|
| 105 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | - 'lightgray' => 'D3D3D3', |
|
| 107 | - 'lightgreen' => '90EE90', |
|
| 108 | - 'lightgrey' => 'D3D3D3', |
|
| 109 | - 'lightpink' => 'FFB6C1', |
|
| 110 | - 'lightsalmon' => 'FFA07A', |
|
| 111 | - 'lightseagreen' => '20B2AA', |
|
| 112 | - 'lightskyblue' => '87CEFA', |
|
| 113 | - 'lightslategray' => '778899', |
|
| 114 | - 'lightslategrey' => '778899', |
|
| 115 | - 'lightsteelblue' => 'B0C4DE', |
|
| 116 | - 'lightyellow' => 'FFFFE0', |
|
| 117 | - 'lime' => '00FF00', |
|
| 118 | - 'limegreen' => '32CD32', |
|
| 119 | - 'linen' => 'FAF0E6', |
|
| 120 | - 'magenta' => 'FF00FF', |
|
| 121 | - 'maroon' => '800000', |
|
| 122 | - 'mediumaquamarine' => '66CDAA', |
|
| 123 | - 'mediumblue' => '0000CD', |
|
| 124 | - 'mediumorchid' => 'BA55D3', |
|
| 125 | - 'mediumpurple' => '9370DB', |
|
| 126 | - 'mediumseagreen' => '3CB371', |
|
| 127 | - 'mediumslateblue' => '7B68EE', |
|
| 128 | - 'mediumspringgreen' => '00FA9A', |
|
| 129 | - 'mediumturquoise' => '48D1CC', |
|
| 130 | - 'mediumvioletred' => 'C71585', |
|
| 131 | - 'midnightblue' => '191970', |
|
| 132 | - 'mintcream' => 'F5FFFA', |
|
| 133 | - 'mistyrose' => 'FFE4E1', |
|
| 134 | - 'moccasin' => 'FFE4B5', |
|
| 135 | - 'navajowhite' => 'FFDEAD', |
|
| 136 | - 'navy' => '000080', |
|
| 137 | - 'oldlace' => 'FDF5E6', |
|
| 138 | - 'olive' => '808000', |
|
| 139 | - 'olivedrab' => '6B8E23', |
|
| 140 | - 'orange' => 'FFA500', |
|
| 141 | - 'orangered' => 'FF4500', |
|
| 142 | - 'orchid' => 'DA70D6', |
|
| 143 | - 'palegoldenrod' => 'EEE8AA', |
|
| 144 | - 'palegreen' => '98FB98', |
|
| 145 | - 'paleturquoise' => 'AFEEEE', |
|
| 146 | - 'palevioletred' => 'DB7093', |
|
| 147 | - 'papayawhip' => 'FFEFD5', |
|
| 148 | - 'peachpuff' => 'FFDAB9', |
|
| 149 | - 'peru' => 'CD853F', |
|
| 150 | - 'pink' => 'FFC0CB', |
|
| 151 | - 'plum' => 'DDA0DD', |
|
| 152 | - 'powderblue' => 'B0E0E6', |
|
| 153 | - 'purple' => '800080', |
|
| 154 | - 'rebeccapurple' => '663399', |
|
| 155 | - 'red' => 'FF0000', |
|
| 156 | - 'rosybrown' => 'BC8F8F', |
|
| 157 | - 'royalblue' => '4169E1', |
|
| 158 | - 'saddlebrown' => '8B4513', |
|
| 159 | - 'salmon' => 'FA8072', |
|
| 160 | - 'sandybrown' => 'F4A460', |
|
| 161 | - 'seagreen' => '2E8B57', |
|
| 162 | - 'seashell' => 'FFF5EE', |
|
| 163 | - 'sienna' => 'A0522D', |
|
| 164 | - 'silver' => 'C0C0C0', |
|
| 165 | - 'skyblue' => '87CEEB', |
|
| 166 | - 'slateblue' => '6A5ACD', |
|
| 167 | - 'slategray' => '708090', |
|
| 168 | - 'slategrey' => '708090', |
|
| 169 | - 'snow' => 'FFFAFA', |
|
| 170 | - 'springgreen' => '00FF7F', |
|
| 171 | - 'steelblue' => '4682B4', |
|
| 172 | - 'tan' => 'D2B48C', |
|
| 173 | - 'teal' => '008080', |
|
| 174 | - 'thistle' => 'D8BFD8', |
|
| 175 | - 'tomato' => 'FF6347', |
|
| 176 | - 'turquoise' => '40E0D0', |
|
| 177 | - 'violet' => 'EE82EE', |
|
| 178 | - 'wheat' => 'F5DEB3', |
|
| 179 | - 'white' => 'FFFFFF', |
|
| 180 | - 'whitesmoke' => 'F5F5F5', |
|
| 181 | - 'yellow' => 'FFFF00', |
|
| 182 | - 'yellowgreen' => '9ACD32', |
|
| 183 | - ]; |
|
| 184 | - if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | - return $couleurs_html[$lc]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $couleur; |
|
| 34 | + $couleurs_html = [ |
|
| 35 | + 'aliceblue' => 'F0F8FF', |
|
| 36 | + 'antiquewhite' => 'FAEBD7', |
|
| 37 | + 'aqua' => '00FFFF', |
|
| 38 | + 'aquamarine' => '7FFFD4', |
|
| 39 | + 'azure' => 'F0FFFF', |
|
| 40 | + 'beige' => 'F5F5DC', |
|
| 41 | + 'bisque' => 'FFE4C4', |
|
| 42 | + 'black' => '000000', |
|
| 43 | + 'blanchedalmond' => 'FFEBCD', |
|
| 44 | + 'blue' => '0000FF', |
|
| 45 | + 'blueviolet' => '8A2BE2', |
|
| 46 | + 'brown' => 'A52A2A', |
|
| 47 | + 'burlywood' => 'DEB887', |
|
| 48 | + 'cadetblue' => '5F9EA0', |
|
| 49 | + 'chartreuse' => '7FFF00', |
|
| 50 | + 'chocolate' => 'D2691E', |
|
| 51 | + 'coral' => 'FF7F50', |
|
| 52 | + 'cornflowerblue' => '6495ED', |
|
| 53 | + 'cornsilk' => 'FFF8DC', |
|
| 54 | + 'crimson' => 'DC143C', |
|
| 55 | + 'cyan' => '00FFFF', |
|
| 56 | + 'darkblue' => '00008B', |
|
| 57 | + 'darkcyan' => '008B8B', |
|
| 58 | + 'darkgoldenrod' => 'B8860B', |
|
| 59 | + 'darkgray' => 'A9A9A9', |
|
| 60 | + 'darkgreen' => '006400', |
|
| 61 | + 'darkgrey' => 'A9A9A9', |
|
| 62 | + 'darkkhaki' => 'BDB76B', |
|
| 63 | + 'darkmagenta' => '8B008B', |
|
| 64 | + 'darkolivegreen' => '556B2F', |
|
| 65 | + 'darkorange' => 'FF8C00', |
|
| 66 | + 'darkorchid' => '9932CC', |
|
| 67 | + 'darkred' => '8B0000', |
|
| 68 | + 'darksalmon' => 'E9967A', |
|
| 69 | + 'darkseagreen' => '8FBC8F', |
|
| 70 | + 'darkslateblue' => '483D8B', |
|
| 71 | + 'darkslategray' => '2F4F4F', |
|
| 72 | + 'darkslategrey' => '2F4F4F', |
|
| 73 | + 'darkturquoise' => '00CED1', |
|
| 74 | + 'darkviolet' => '9400D3', |
|
| 75 | + 'deeppink' => 'FF1493', |
|
| 76 | + 'deepskyblue' => '00BFFF', |
|
| 77 | + 'dimgray' => '696969', |
|
| 78 | + 'dimgrey' => '696969', |
|
| 79 | + 'dodgerblue' => '1E90FF', |
|
| 80 | + 'firebrick' => 'B22222', |
|
| 81 | + 'floralwhite' => 'FFFAF0', |
|
| 82 | + 'forestgreen' => '228B22', |
|
| 83 | + 'fuchsia' => 'FF00FF', |
|
| 84 | + 'gainsboro' => 'DCDCDC', |
|
| 85 | + 'ghostwhite' => 'F8F8FF', |
|
| 86 | + 'gold' => 'FFD700', |
|
| 87 | + 'goldenrod' => 'DAA520', |
|
| 88 | + 'gray' => '808080', |
|
| 89 | + 'green' => '008000', |
|
| 90 | + 'greenyellow' => 'ADFF2F', |
|
| 91 | + 'grey' => '808080', |
|
| 92 | + 'honeydew' => 'F0FFF0', |
|
| 93 | + 'hotpink' => 'FF69B4', |
|
| 94 | + 'indianred' => 'CD5C5C', |
|
| 95 | + 'indigo' => '4B0082', |
|
| 96 | + 'ivory' => 'FFFFF0', |
|
| 97 | + 'khaki' => 'F0E68C', |
|
| 98 | + 'lavender' => 'E6E6FA', |
|
| 99 | + 'lavenderblush' => 'FFF0F5', |
|
| 100 | + 'lawngreen' => '7CFC00', |
|
| 101 | + 'lemonchiffon' => 'FFFACD', |
|
| 102 | + 'lightblue' => 'ADD8E6', |
|
| 103 | + 'lightcoral' => 'F08080', |
|
| 104 | + 'lightcyan' => 'E0FFFF', |
|
| 105 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | + 'lightgray' => 'D3D3D3', |
|
| 107 | + 'lightgreen' => '90EE90', |
|
| 108 | + 'lightgrey' => 'D3D3D3', |
|
| 109 | + 'lightpink' => 'FFB6C1', |
|
| 110 | + 'lightsalmon' => 'FFA07A', |
|
| 111 | + 'lightseagreen' => '20B2AA', |
|
| 112 | + 'lightskyblue' => '87CEFA', |
|
| 113 | + 'lightslategray' => '778899', |
|
| 114 | + 'lightslategrey' => '778899', |
|
| 115 | + 'lightsteelblue' => 'B0C4DE', |
|
| 116 | + 'lightyellow' => 'FFFFE0', |
|
| 117 | + 'lime' => '00FF00', |
|
| 118 | + 'limegreen' => '32CD32', |
|
| 119 | + 'linen' => 'FAF0E6', |
|
| 120 | + 'magenta' => 'FF00FF', |
|
| 121 | + 'maroon' => '800000', |
|
| 122 | + 'mediumaquamarine' => '66CDAA', |
|
| 123 | + 'mediumblue' => '0000CD', |
|
| 124 | + 'mediumorchid' => 'BA55D3', |
|
| 125 | + 'mediumpurple' => '9370DB', |
|
| 126 | + 'mediumseagreen' => '3CB371', |
|
| 127 | + 'mediumslateblue' => '7B68EE', |
|
| 128 | + 'mediumspringgreen' => '00FA9A', |
|
| 129 | + 'mediumturquoise' => '48D1CC', |
|
| 130 | + 'mediumvioletred' => 'C71585', |
|
| 131 | + 'midnightblue' => '191970', |
|
| 132 | + 'mintcream' => 'F5FFFA', |
|
| 133 | + 'mistyrose' => 'FFE4E1', |
|
| 134 | + 'moccasin' => 'FFE4B5', |
|
| 135 | + 'navajowhite' => 'FFDEAD', |
|
| 136 | + 'navy' => '000080', |
|
| 137 | + 'oldlace' => 'FDF5E6', |
|
| 138 | + 'olive' => '808000', |
|
| 139 | + 'olivedrab' => '6B8E23', |
|
| 140 | + 'orange' => 'FFA500', |
|
| 141 | + 'orangered' => 'FF4500', |
|
| 142 | + 'orchid' => 'DA70D6', |
|
| 143 | + 'palegoldenrod' => 'EEE8AA', |
|
| 144 | + 'palegreen' => '98FB98', |
|
| 145 | + 'paleturquoise' => 'AFEEEE', |
|
| 146 | + 'palevioletred' => 'DB7093', |
|
| 147 | + 'papayawhip' => 'FFEFD5', |
|
| 148 | + 'peachpuff' => 'FFDAB9', |
|
| 149 | + 'peru' => 'CD853F', |
|
| 150 | + 'pink' => 'FFC0CB', |
|
| 151 | + 'plum' => 'DDA0DD', |
|
| 152 | + 'powderblue' => 'B0E0E6', |
|
| 153 | + 'purple' => '800080', |
|
| 154 | + 'rebeccapurple' => '663399', |
|
| 155 | + 'red' => 'FF0000', |
|
| 156 | + 'rosybrown' => 'BC8F8F', |
|
| 157 | + 'royalblue' => '4169E1', |
|
| 158 | + 'saddlebrown' => '8B4513', |
|
| 159 | + 'salmon' => 'FA8072', |
|
| 160 | + 'sandybrown' => 'F4A460', |
|
| 161 | + 'seagreen' => '2E8B57', |
|
| 162 | + 'seashell' => 'FFF5EE', |
|
| 163 | + 'sienna' => 'A0522D', |
|
| 164 | + 'silver' => 'C0C0C0', |
|
| 165 | + 'skyblue' => '87CEEB', |
|
| 166 | + 'slateblue' => '6A5ACD', |
|
| 167 | + 'slategray' => '708090', |
|
| 168 | + 'slategrey' => '708090', |
|
| 169 | + 'snow' => 'FFFAFA', |
|
| 170 | + 'springgreen' => '00FF7F', |
|
| 171 | + 'steelblue' => '4682B4', |
|
| 172 | + 'tan' => 'D2B48C', |
|
| 173 | + 'teal' => '008080', |
|
| 174 | + 'thistle' => 'D8BFD8', |
|
| 175 | + 'tomato' => 'FF6347', |
|
| 176 | + 'turquoise' => '40E0D0', |
|
| 177 | + 'violet' => 'EE82EE', |
|
| 178 | + 'wheat' => 'F5DEB3', |
|
| 179 | + 'white' => 'FFFFFF', |
|
| 180 | + 'whitesmoke' => 'F5F5F5', |
|
| 181 | + 'yellow' => 'FFFF00', |
|
| 182 | + 'yellowgreen' => '9ACD32', |
|
| 183 | + ]; |
|
| 184 | + if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | + return $couleurs_html[$lc]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $couleur; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -201,16 +201,16 @@ discard block |
||
| 201 | 201 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 202 | 202 | */ |
| 203 | 203 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 204 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | - $hsl = [ |
|
| 206 | - 'h' => round($hsl['h'] * 360), |
|
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | - ]; |
|
| 210 | - if ($format === null) { |
|
| 211 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | - } |
|
| 213 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 204 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | + $hsl = [ |
|
| 206 | + 'h' => round($hsl['h'] * 360), |
|
| 207 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | + ]; |
|
| 210 | + if ($format === null) { |
|
| 211 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | + } |
|
| 213 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 228 | 228 | */ |
| 229 | 229 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 230 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | - $rgb = [ |
|
| 232 | - 'r' => $rgb['red'], |
|
| 233 | - 'g' => $rgb['green'], |
|
| 234 | - 'b' => $rgb['blue'], |
|
| 235 | - ]; |
|
| 236 | - if ($format === null) { |
|
| 237 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | - } |
|
| 239 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 230 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | + $rgb = [ |
|
| 232 | + 'r' => $rgb['red'], |
|
| 233 | + 'g' => $rgb['green'], |
|
| 234 | + 'b' => $rgb['blue'], |
|
| 235 | + ]; |
|
| 236 | + if ($format === null) { |
|
| 237 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | + } |
|
| 239 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -252,15 +252,15 @@ discard block |
||
| 252 | 252 | * Code hexadécimal de la couleur plus foncée |
| 253 | 253 | */ |
| 254 | 254 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 255 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 256 | 256 | |
| 257 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 257 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 260 | 260 | |
| 261 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 262 | 262 | |
| 263 | - return $couleur; |
|
| 263 | + return $couleur; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | * Code hexadécimal de la couleur éclaircie |
| 277 | 277 | */ |
| 278 | 278 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 279 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 279 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 280 | 280 | |
| 281 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 284 | 284 | |
| 285 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 285 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 286 | 286 | |
| 287 | - return $couleur; |
|
| 287 | + return $couleur; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -307,28 +307,28 @@ discard block |
||
| 307 | 307 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 308 | 308 | */ |
| 309 | 309 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 310 | - if (!$img) { |
|
| 311 | - return $img; |
|
| 312 | - } |
|
| 313 | - list($h, $l) = taille_image($img); |
|
| 314 | - $select = true; |
|
| 315 | - if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | - $select = false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $class = extraire_attribut($img, 'class'); |
|
| 320 | - $p = strpos($class, 'filtre_inactif'); |
|
| 321 | - if (($select == false) and ($p === false)) { |
|
| 322 | - $class .= ' filtre_inactif'; |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - if (($select == true) and ($p !== false)) { |
|
| 326 | - // no_image_filtrer : historique, a virer |
|
| 327 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | - $img = inserer_attribut($img, 'class', $class); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - return $img; |
|
| 310 | + if (!$img) { |
|
| 311 | + return $img; |
|
| 312 | + } |
|
| 313 | + list($h, $l) = taille_image($img); |
|
| 314 | + $select = true; |
|
| 315 | + if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | + $select = false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $class = extraire_attribut($img, 'class'); |
|
| 320 | + $p = strpos($class, 'filtre_inactif'); |
|
| 321 | + if (($select == false) and ($p === false)) { |
|
| 322 | + $class .= ' filtre_inactif'; |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + if (($select == true) and ($p !== false)) { |
|
| 326 | + // no_image_filtrer : historique, a virer |
|
| 327 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | + $img = inserer_attribut($img, 'class', $class); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + return $img; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -376,45 +376,45 @@ discard block |
||
| 376 | 376 | * Code HTML de l'image ou du texte. |
| 377 | 377 | **/ |
| 378 | 378 | function image_passe_partout( |
| 379 | - $img, |
|
| 380 | - $taille_x = -1, |
|
| 381 | - $taille_y = -1, |
|
| 382 | - $force = false, |
|
| 383 | - $cherche_image = false, |
|
| 384 | - $process = 'AUTO' |
|
| 379 | + $img, |
|
| 380 | + $taille_x = -1, |
|
| 381 | + $taille_y = -1, |
|
| 382 | + $force = false, |
|
| 383 | + $cherche_image = false, |
|
| 384 | + $process = 'AUTO' |
|
| 385 | 385 | ) { |
| 386 | - // PHP 7+ type hint |
|
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 392 | - |
|
| 393 | - if (!$img) { |
|
| 394 | - return ''; |
|
| 395 | - } |
|
| 396 | - list($hauteur, $largeur) = taille_image($img); |
|
| 397 | - if ($taille_x === -1) { |
|
| 398 | - $taille_x = isset($GLOBALS['meta']['taille_preview']) ? $GLOBALS['meta']['taille_preview'] : 150; |
|
| 399 | - } |
|
| 400 | - if ($taille_y === -1) { |
|
| 401 | - $taille_y = $taille_x; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | - $taille_x = 1; |
|
| 406 | - } # {0,300} -> c'est 300 qui compte |
|
| 407 | - elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | - $taille_y = 1; |
|
| 409 | - } # {300,0} -> c'est 300 qui compte |
|
| 410 | - elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | - return ''; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur, $hauteur, $taille_x, $taille_y); |
|
| 415 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | - |
|
| 417 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 386 | + // PHP 7+ type hint |
|
| 387 | + $img = (string)$img; |
|
| 388 | + $taille_x = (int)$taille_x; |
|
| 389 | + $taille_y = (int)$taille_y; |
|
| 390 | + $force = (bool)$force; |
|
| 391 | + $process = (string)$process; |
|
| 392 | + |
|
| 393 | + if (!$img) { |
|
| 394 | + return ''; |
|
| 395 | + } |
|
| 396 | + list($hauteur, $largeur) = taille_image($img); |
|
| 397 | + if ($taille_x === -1) { |
|
| 398 | + $taille_x = isset($GLOBALS['meta']['taille_preview']) ? $GLOBALS['meta']['taille_preview'] : 150; |
|
| 399 | + } |
|
| 400 | + if ($taille_y === -1) { |
|
| 401 | + $taille_y = $taille_x; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | + $taille_x = 1; |
|
| 406 | + } # {0,300} -> c'est 300 qui compte |
|
| 407 | + elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | + $taille_y = 1; |
|
| 409 | + } # {300,0} -> c'est 300 qui compte |
|
| 410 | + elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | + return ''; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur, $hauteur, $taille_x, $taille_y); |
|
| 415 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | + |
|
| 417 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -457,44 +457,44 @@ discard block |
||
| 457 | 457 | * Code HTML de l'image ou du texte. |
| 458 | 458 | **/ |
| 459 | 459 | function image_reduire( |
| 460 | - $img, |
|
| 461 | - $taille = -1, |
|
| 462 | - $taille_y = -1, |
|
| 463 | - $force = false, |
|
| 464 | - $cherche_image = false, |
|
| 465 | - $process = 'AUTO' |
|
| 460 | + $img, |
|
| 461 | + $taille = -1, |
|
| 462 | + $taille_y = -1, |
|
| 463 | + $force = false, |
|
| 464 | + $cherche_image = false, |
|
| 465 | + $process = 'AUTO' |
|
| 466 | 466 | ) { |
| 467 | - // PHP 7+ type hint |
|
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 473 | - |
|
| 474 | - // Determiner la taille x,y maxi |
|
| 475 | - // prendre le reglage de previsu par defaut |
|
| 476 | - if ($taille === -1) { |
|
| 477 | - $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | - ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | - : 150; |
|
| 480 | - } |
|
| 481 | - if ($taille_y === -1) { |
|
| 482 | - $taille_y = $taille; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if ($taille === 0 and $taille_y > 0) { |
|
| 486 | - $taille = 10000; |
|
| 487 | - } # {0,300} -> c'est 300 qui compte |
|
| 488 | - elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | - $taille_y = 10000; |
|
| 490 | - } # {300,0} -> c'est 300 qui compte |
|
| 491 | - elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | - return ''; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | - |
|
| 497 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 467 | + // PHP 7+ type hint |
|
| 468 | + $img = (string)$img; |
|
| 469 | + $taille = (int)$taille; |
|
| 470 | + $taille_y = (int)$taille_y; |
|
| 471 | + $force = (bool)$force; |
|
| 472 | + $process = (string)$process; |
|
| 473 | + |
|
| 474 | + // Determiner la taille x,y maxi |
|
| 475 | + // prendre le reglage de previsu par defaut |
|
| 476 | + if ($taille === -1) { |
|
| 477 | + $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | + ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | + : 150; |
|
| 480 | + } |
|
| 481 | + if ($taille_y === -1) { |
|
| 482 | + $taille_y = $taille; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if ($taille === 0 and $taille_y > 0) { |
|
| 486 | + $taille = 10000; |
|
| 487 | + } # {0,300} -> c'est 300 qui compte |
|
| 488 | + elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | + $taille_y = 10000; |
|
| 490 | + } # {300,0} -> c'est 300 qui compte |
|
| 491 | + elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | + return ''; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | + |
|
| 497 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -505,16 +505,16 @@ discard block |
||
| 505 | 505 | * |
| 506 | 506 | **/ |
| 507 | 507 | function image_recadre_avec_fallback( |
| 508 | - $im, |
|
| 509 | - $width, |
|
| 510 | - $height = '-', |
|
| 511 | - $position = 'focus', |
|
| 512 | - $background_color = 'white' |
|
| 508 | + $im, |
|
| 509 | + $width, |
|
| 510 | + $height = '-', |
|
| 511 | + $position = 'focus', |
|
| 512 | + $background_color = 'white' |
|
| 513 | 513 | ) { |
| 514 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | - } else { return image_passe_partout($im, $width, $height); |
|
| 517 | - } |
|
| 514 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | + } else { return image_passe_partout($im, $width, $height); |
|
| 517 | + } |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -532,25 +532,25 @@ discard block |
||
| 532 | 532 | * Code HTML de l'image ou du texte. |
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | - // PHP 7+ type hint |
|
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 535 | + // PHP 7+ type hint |
|
| 536 | + $img = (string)$img; |
|
| 537 | + $val = (int)$val; |
|
| 538 | + $force = (bool)$force; |
|
| 539 | 539 | |
| 540 | - list($hauteur, $largeur) = taille_image($img); |
|
| 540 | + list($hauteur, $largeur) = taille_image($img); |
|
| 541 | 541 | |
| 542 | - $l = round($largeur / $val); |
|
| 543 | - $h = round($hauteur / $val); |
|
| 542 | + $l = round($largeur / $val); |
|
| 543 | + $h = round($hauteur / $val); |
|
| 544 | 544 | |
| 545 | - if ($l > $h) { |
|
| 546 | - $h = 0; |
|
| 547 | - } else { |
|
| 548 | - $l = 0; |
|
| 549 | - } |
|
| 545 | + if ($l > $h) { |
|
| 546 | + $h = 0; |
|
| 547 | + } else { |
|
| 548 | + $l = 0; |
|
| 549 | + } |
|
| 550 | 550 | |
| 551 | - $img = image_reduire($img, $l, $h, $force); |
|
| 551 | + $img = image_reduire($img, $l, $h, $force); |
|
| 552 | 552 | |
| 553 | - return $img; |
|
| 553 | + return $img; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * Couleur en écriture hexadécimale. |
| 574 | 574 | **/ |
| 575 | 575 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 576 | - if (function_exists('couleur_saturation')) { |
|
| 577 | - return couleur_saturation($couleur, $val, $strict); |
|
| 578 | - } |
|
| 579 | - return $couleur; |
|
| 576 | + if (function_exists('couleur_saturation')) { |
|
| 577 | + return couleur_saturation($couleur, $val, $strict); |
|
| 578 | + } |
|
| 579 | + return $couleur; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -597,8 +597,8 @@ discard block |
||
| 597 | 597 | * Couleur en écriture hexadécimale. |
| 598 | 598 | **/ |
| 599 | 599 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 600 | - if (function_exists('couleur_luminance')) { |
|
| 601 | - return couleur_luminance($couleur, $val); |
|
| 602 | - } |
|
| 603 | - return $couleur; |
|
| 600 | + if (function_exists('couleur_luminance')) { |
|
| 601 | + return couleur_luminance($couleur, $val); |
|
| 602 | + } |
|
| 603 | + return $couleur; |
|
| 604 | 604 | } |
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | $hsl = _couleur_hex_to_hsl($couleur); |
| 205 | 205 | $hsl = [ |
| 206 | 206 | 'h' => round($hsl['h'] * 360), |
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 207 | + 's' => round($hsl['s'] * 100).'%', |
|
| 208 | + 'l' => round($hsl['l'] * 100).'%' |
|
| 209 | 209 | ]; |
| 210 | 210 | if ($format === null) { |
| 211 | 211 | return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | $process = 'AUTO' |
| 385 | 385 | ) { |
| 386 | 386 | // PHP 7+ type hint |
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 387 | + $img = (string) $img; |
|
| 388 | + $taille_x = (int) $taille_x; |
|
| 389 | + $taille_y = (int) $taille_y; |
|
| 390 | + $force = (bool) $force; |
|
| 391 | + $process = (string) $process; |
|
| 392 | 392 | |
| 393 | 393 | if (!$img) { |
| 394 | 394 | return ''; |
@@ -465,11 +465,11 @@ discard block |
||
| 465 | 465 | $process = 'AUTO' |
| 466 | 466 | ) { |
| 467 | 467 | // PHP 7+ type hint |
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 468 | + $img = (string) $img; |
|
| 469 | + $taille = (int) $taille; |
|
| 470 | + $taille_y = (int) $taille_y; |
|
| 471 | + $force = (bool) $force; |
|
| 472 | + $process = (string) $process; |
|
| 473 | 473 | |
| 474 | 474 | // Determiner la taille x,y maxi |
| 475 | 475 | // prendre le reglage de previsu par defaut |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $background_color = 'white' |
| 513 | 513 | ) { |
| 514 | 514 | if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 515 | + return image_reduire(image_recadre($im, $width.':'.$height, '-', $position, $background_color), $width, $height); |
|
| 516 | 516 | } else { return image_passe_partout($im, $width, $height); |
| 517 | 517 | } |
| 518 | 518 | } |
@@ -533,9 +533,9 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | 535 | // PHP 7+ type hint |
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 536 | + $img = (string) $img; |
|
| 537 | + $val = (int) $val; |
|
| 538 | + $force = (bool) $force; |
|
| 539 | 539 | |
| 540 | 540 | list($hauteur, $largeur) = taille_image($img); |
| 541 | 541 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/charsets'); |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * @return array |
| 43 | 43 | */ |
| 44 | 44 | function importer_csv_importcharset($texte, $definir_charset_source = false) { |
| 45 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | - static $charset_source = 'iso-8859-1'; |
|
| 47 | - if ($definir_charset_source) { |
|
| 48 | - if ($definir_charset_source === true) { |
|
| 49 | - $charset_source = 'iso-8859-1'; |
|
| 50 | - } else { |
|
| 51 | - $charset_source = $definir_charset_source; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | - if (is_utf8($texte)) { |
|
| 56 | - $charset = 'utf-8'; |
|
| 57 | - } else { |
|
| 58 | - $charset = $charset_source; |
|
| 59 | - } |
|
| 60 | - return importer_charset($texte, $charset); |
|
| 45 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | + static $charset_source = 'iso-8859-1'; |
|
| 47 | + if ($definir_charset_source) { |
|
| 48 | + if ($definir_charset_source === true) { |
|
| 49 | + $charset_source = 'iso-8859-1'; |
|
| 50 | + } else { |
|
| 51 | + $charset_source = $definir_charset_source; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | + if (is_utf8($texte)) { |
|
| 56 | + $charset = 'utf-8'; |
|
| 57 | + } else { |
|
| 58 | + $charset = $charset_source; |
|
| 59 | + } |
|
| 60 | + return importer_charset($texte, $charset); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | 70 | function importer_csv_nettoie_key($key) { |
| 71 | - return translitteration($key); |
|
| 71 | + return translitteration($key); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -87,77 +87,77 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | function inc_importer_csv_dist($file, $options = []) { |
| 89 | 89 | |
| 90 | - // support ancienne syntaxe |
|
| 91 | - // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | - if (!is_array($options)) { |
|
| 93 | - $args = func_get_args(); |
|
| 94 | - $options = []; |
|
| 95 | - foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | - if (!empty($args[$k])) { |
|
| 97 | - $options[$option] = $args[$k]; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 90 | + // support ancienne syntaxe |
|
| 91 | + // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | + if (!is_array($options)) { |
|
| 93 | + $args = func_get_args(); |
|
| 94 | + $options = []; |
|
| 95 | + foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | + if (!empty($args[$k])) { |
|
| 97 | + $options[$option] = $args[$k]; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $default_options = [ |
|
| 103 | - 'head' => false, |
|
| 104 | - 'delim' => ',', |
|
| 105 | - 'enclos' => '"', |
|
| 106 | - 'len' => 10000, |
|
| 107 | - 'charset_source' => '', |
|
| 108 | - ]; |
|
| 109 | - $options = array_merge($default_options, $options); |
|
| 102 | + $default_options = [ |
|
| 103 | + 'head' => false, |
|
| 104 | + 'delim' => ',', |
|
| 105 | + 'enclos' => '"', |
|
| 106 | + 'len' => 10000, |
|
| 107 | + 'charset_source' => '', |
|
| 108 | + ]; |
|
| 109 | + $options = array_merge($default_options, $options); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - $return = false; |
|
| 113 | - if ( |
|
| 114 | - @file_exists($file) |
|
| 115 | - and $handle = fopen($file, 'r') |
|
| 116 | - ) { |
|
| 117 | - if ($options['charset_source']) { |
|
| 118 | - importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | - } |
|
| 120 | - if ($options['head']) { |
|
| 121 | - $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | - if ($header) { |
|
| 123 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | - $header_type = []; |
|
| 126 | - foreach ($header as $heading) { |
|
| 127 | - if (!isset($header_type[$heading])) { |
|
| 128 | - $header_type[$heading] = 'scalar'; |
|
| 129 | - } else { |
|
| 130 | - $header_type[$heading] = 'array'; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } |
|
| 112 | + $return = false; |
|
| 113 | + if ( |
|
| 114 | + @file_exists($file) |
|
| 115 | + and $handle = fopen($file, 'r') |
|
| 116 | + ) { |
|
| 117 | + if ($options['charset_source']) { |
|
| 118 | + importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | + } |
|
| 120 | + if ($options['head']) { |
|
| 121 | + $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | + if ($header) { |
|
| 123 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | + $header_type = []; |
|
| 126 | + foreach ($header as $heading) { |
|
| 127 | + if (!isset($header_type[$heading])) { |
|
| 128 | + $header_type[$heading] = 'scalar'; |
|
| 129 | + } else { |
|
| 130 | + $header_type[$heading] = 'array'; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | - if ($options['head'] and isset($header)) { |
|
| 139 | - $row = []; |
|
| 140 | - foreach ($header as $key => $heading) { |
|
| 141 | - if ($header_type[$heading] == 'array') { |
|
| 142 | - if (!isset($row[$heading])) { |
|
| 143 | - $row[$heading] = []; |
|
| 144 | - } |
|
| 145 | - if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | - $row[$heading][] = $data[$key]; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - $row[$heading] = (isset($data[$key])) ? $data[$key] : ''; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - $return[] = $row; |
|
| 153 | - } else { |
|
| 154 | - $return[] = $data; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - if ($options['charset_source']) { |
|
| 158 | - importer_csv_importcharset('', true); |
|
| 159 | - } |
|
| 160 | - } |
|
| 136 | + while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | + if ($options['head'] and isset($header)) { |
|
| 139 | + $row = []; |
|
| 140 | + foreach ($header as $key => $heading) { |
|
| 141 | + if ($header_type[$heading] == 'array') { |
|
| 142 | + if (!isset($row[$heading])) { |
|
| 143 | + $row[$heading] = []; |
|
| 144 | + } |
|
| 145 | + if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | + $row[$heading][] = $data[$key]; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + $row[$heading] = (isset($data[$key])) ? $data[$key] : ''; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + $return[] = $row; |
|
| 153 | + } else { |
|
| 154 | + $return[] = $data; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + if ($options['charset_source']) { |
|
| 158 | + importer_csv_importcharset('', true); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $return; |
|
| 162 | + return $return; |
|
| 163 | 163 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | include_spip('inc/filtres'); |
| 28 | 28 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @return string Rien. |
| 40 | 40 | **/ |
| 41 | 41 | function filtre_image_dist($t) { |
| 42 | - return ''; |
|
| 42 | + return ''; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string Rien. |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_audio_dist($t) { |
| 55 | - return ''; |
|
| 55 | + return ''; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @return string Rien. |
| 66 | 66 | **/ |
| 67 | 67 | function filtre_video_dist($t) { |
| 68 | - return ''; |
|
| 68 | + return ''; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return string Rien. |
| 79 | 79 | **/ |
| 80 | 80 | function filtre_application_dist($t) { |
| 81 | - return ''; |
|
| 81 | + return ''; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return string Rien. |
| 92 | 92 | **/ |
| 93 | 93 | function filtre_message_dist($t) { |
| 94 | - return ''; |
|
| 94 | + return ''; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return string Rien. |
| 105 | 105 | **/ |
| 106 | 106 | function filtre_multipart_dist($t) { |
| 107 | - return ''; |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * @return string Contenu échappé. |
| 118 | 118 | **/ |
| 119 | 119 | function filtre_text_dist($t) { |
| 120 | - static $t1 = ['&', '<', '>']; |
|
| 121 | - static $t2 = ['&', '<', '>']; |
|
| 120 | + static $t1 = ['&', '<', '>']; |
|
| 121 | + static $t2 = ['&', '<', '>']; |
|
| 122 | 122 | |
| 123 | - return '<pre>' . str_replace($t1, $t2, $t) . '</pre>'; |
|
| 123 | + return '<pre>' . str_replace($t1, $t2, $t) . '</pre>'; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -135,21 +135,21 @@ discard block |
||
| 135 | 135 | * Tableau (formaté en SPIP) |
| 136 | 136 | **/ |
| 137 | 137 | function filtre_text_csv_dist($t) { |
| 138 | - include_spip('inc/csv'); |
|
| 139 | - list($entete, $lignes, $caption) = analyse_csv($t); |
|
| 140 | - foreach ($lignes as &$l) { |
|
| 141 | - $l = join('|', $l); |
|
| 142 | - } |
|
| 143 | - $corps = join("\n", $lignes) . "\n"; |
|
| 144 | - $corps = $caption . |
|
| 145 | - "\n|{{" . |
|
| 146 | - join('}}|{{', $entete) . |
|
| 147 | - '}}|' . |
|
| 148 | - "\n|" . |
|
| 149 | - str_replace("\n", "|\n|", $corps); |
|
| 150 | - include_spip('inc/texte'); |
|
| 151 | - |
|
| 152 | - return propre($corps); |
|
| 138 | + include_spip('inc/csv'); |
|
| 139 | + list($entete, $lignes, $caption) = analyse_csv($t); |
|
| 140 | + foreach ($lignes as &$l) { |
|
| 141 | + $l = join('|', $l); |
|
| 142 | + } |
|
| 143 | + $corps = join("\n", $lignes) . "\n"; |
|
| 144 | + $corps = $caption . |
|
| 145 | + "\n|{{" . |
|
| 146 | + join('}}|{{', $entete) . |
|
| 147 | + '}}|' . |
|
| 148 | + "\n|" . |
|
| 149 | + str_replace("\n", "|\n|", $corps); |
|
| 150 | + include_spip('inc/texte'); |
|
| 151 | + |
|
| 152 | + return propre($corps); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -163,33 +163,33 @@ discard block |
||
| 163 | 163 | * @return string Code html sécurisé ou texte échappé |
| 164 | 164 | **/ |
| 165 | 165 | function filtre_text_html_dist($t) { |
| 166 | - if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 167 | - return appliquer_filtre($t, 'text/plain'); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - list(, $h, $t) = $r; |
|
| 171 | - |
|
| 172 | - $style = ''; |
|
| 173 | - // recuperer les styles internes |
|
| 174 | - if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 175 | - $style = join("\n", $r[1]); |
|
| 176 | - } |
|
| 177 | - // ... et externes |
|
| 178 | - |
|
| 179 | - include_spip('inc/distant'); |
|
| 180 | - if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 181 | - foreach ($r[0] as $l) { |
|
| 182 | - preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 183 | - $page = recuperer_url($m[1]); |
|
| 184 | - $page = $page['page'] ?? ''; |
|
| 185 | - $style .= "\n/* $l */\n" |
|
| 186 | - . str_replace('<', '', $page); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 190 | - $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t)); |
|
| 191 | - |
|
| 192 | - return (!$style ? '' : "\n<style>" . $style . '</style>') . $t; |
|
| 166 | + if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 167 | + return appliquer_filtre($t, 'text/plain'); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + list(, $h, $t) = $r; |
|
| 171 | + |
|
| 172 | + $style = ''; |
|
| 173 | + // recuperer les styles internes |
|
| 174 | + if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 175 | + $style = join("\n", $r[1]); |
|
| 176 | + } |
|
| 177 | + // ... et externes |
|
| 178 | + |
|
| 179 | + include_spip('inc/distant'); |
|
| 180 | + if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 181 | + foreach ($r[0] as $l) { |
|
| 182 | + preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 183 | + $page = recuperer_url($m[1]); |
|
| 184 | + $page = $page['page'] ?? ''; |
|
| 185 | + $style .= "\n/* $l */\n" |
|
| 186 | + . str_replace('<', '', $page); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 190 | + $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t)); |
|
| 191 | + |
|
| 192 | + return (!$style ? '' : "\n<style>" . $style . '</style>') . $t; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return string Code HTML des balises `<param>` |
| 203 | 203 | **/ |
| 204 | 204 | function filtre_audio_x_pn_realaudio($id) { |
| 205 | - return " |
|
| 205 | + return " |
|
| 206 | 206 | <param name='controls' value='PositionSlider' /> |
| 207 | 207 | <param name='controls' value='ImageWindow' /> |
| 208 | 208 | <param name='controls' value='PlayButton' /> |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | static $t1 = ['&', '<', '>']; |
| 121 | 121 | static $t2 = ['&', '<', '>']; |
| 122 | 122 | |
| 123 | - return '<pre>' . str_replace($t1, $t2, $t) . '</pre>'; |
|
| 123 | + return '<pre>'.str_replace($t1, $t2, $t).'</pre>'; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | foreach ($lignes as &$l) { |
| 141 | 141 | $l = join('|', $l); |
| 142 | 142 | } |
| 143 | - $corps = join("\n", $lignes) . "\n"; |
|
| 144 | - $corps = $caption . |
|
| 145 | - "\n|{{" . |
|
| 146 | - join('}}|{{', $entete) . |
|
| 147 | - '}}|' . |
|
| 148 | - "\n|" . |
|
| 143 | + $corps = join("\n", $lignes)."\n"; |
|
| 144 | + $corps = $caption. |
|
| 145 | + "\n|{{". |
|
| 146 | + join('}}|{{', $entete). |
|
| 147 | + '}}|'. |
|
| 148 | + "\n|". |
|
| 149 | 149 | str_replace("\n", "|\n|", $corps); |
| 150 | 150 | include_spip('inc/texte'); |
| 151 | 151 | |
@@ -187,9 +187,9 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
| 190 | - $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t)); |
|
| 190 | + $t = safehtml(preg_replace(',<script'.'.*?</script>,is', '', $t)); |
|
| 191 | 191 | |
| 192 | - return (!$style ? '' : "\n<style>" . $style . '</style>') . $t; |
|
| 192 | + return (!$style ? '' : "\n<style>".$style.'</style>').$t; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -20,21 +20,21 @@ |
||
| 20 | 20 | * Retourne la liste des menus favoris par défaut ainsi que leur rang |
| 21 | 21 | */ |
| 22 | 22 | function inc_definir_menus_favoris_dist() { |
| 23 | - $liste = [ |
|
| 23 | + $liste = [ |
|
| 24 | 24 | |
| 25 | - // Menu Édition, |
|
| 26 | - 'auteurs' => 1, |
|
| 27 | - 'rubriques' => 2, |
|
| 28 | - 'articles' => 3, |
|
| 25 | + // Menu Édition, |
|
| 26 | + 'auteurs' => 1, |
|
| 27 | + 'rubriques' => 2, |
|
| 28 | + 'articles' => 3, |
|
| 29 | 29 | |
| 30 | - // Menu Maintenance |
|
| 31 | - 'admin_vider' => 1, |
|
| 30 | + // Menu Maintenance |
|
| 31 | + 'admin_vider' => 1, |
|
| 32 | 32 | |
| 33 | - // Menu Configurations |
|
| 34 | - 'configurer_identite' => 1, |
|
| 35 | - 'admin_plugin' => 2, |
|
| 33 | + // Menu Configurations |
|
| 34 | + 'configurer_identite' => 1, |
|
| 35 | + 'admin_plugin' => 2, |
|
| 36 | 36 | |
| 37 | - ]; |
|
| 37 | + ]; |
|
| 38 | 38 | |
| 39 | - return $liste; |
|
| 39 | + return $liste; |
|
| 40 | 40 | } |
@@ -16,32 +16,32 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 23 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | 24 | } |
| 25 | 25 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 26 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | - define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 33 | 33 | } |
| 34 | 34 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 35 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 39 | - preg_replace( |
|
| 40 | - '@^https?:@', |
|
| 41 | - 'https?:', |
|
| 42 | - (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | - ) |
|
| 44 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 39 | + preg_replace( |
|
| 40 | + '@^https?:@', |
|
| 41 | + 'https?:', |
|
| 42 | + (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | + ) |
|
| 44 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 45 | 45 | |
| 46 | 46 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 47 | 47 | |
@@ -68,77 +68,77 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
| 70 | 70 | |
| 71 | - // si c'est la protection de soi-meme, retourner le path |
|
| 72 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | - |
|
| 75 | - return @file_exists($source) ? $source : false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (is_null($local)) { |
|
| 79 | - $local = fichier_copie_locale($source); |
|
| 80 | - } else { |
|
| 81 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | - if (!$local) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 94 | - $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | - |
|
| 96 | - // test d'existence du fichier |
|
| 97 | - if ($mode == 'test') { |
|
| 98 | - return $t ? $local : ''; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // sinon voir si on doit/peut le telecharger |
|
| 102 | - if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | - return $local; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($mode == 'modif' or !$t) { |
|
| 107 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | - // et des eventuelles recuperations concurantes |
|
| 109 | - include_spip('inc/acces'); |
|
| 110 | - if (!$taille_max) { |
|
| 111 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | - } |
|
| 113 | - $res = recuperer_url( |
|
| 114 | - $source, |
|
| 115 | - ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 116 | - ); |
|
| 117 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | - } |
|
| 120 | - if (!$res['length']) { |
|
| 121 | - // si $t c'est sans doute juste un not-modified-since |
|
| 122 | - return $t ? $local : false; |
|
| 123 | - } |
|
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | - |
|
| 126 | - // pour une eventuelle indexation |
|
| 127 | - pipeline( |
|
| 128 | - 'post_edition', |
|
| 129 | - [ |
|
| 130 | - 'args' => [ |
|
| 131 | - 'operation' => 'copie_locale', |
|
| 132 | - 'source' => $source, |
|
| 133 | - 'fichier' => $local, |
|
| 134 | - 'http_res' => $res['length'], |
|
| 135 | - ], |
|
| 136 | - 'data' => null |
|
| 137 | - ] |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $local; |
|
| 71 | + // si c'est la protection de soi-meme, retourner le path |
|
| 72 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | + |
|
| 75 | + return @file_exists($source) ? $source : false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (is_null($local)) { |
|
| 79 | + $local = fichier_copie_locale($source); |
|
| 80 | + } else { |
|
| 81 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | + if (!$local) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $localrac = _DIR_RACINE . $local; |
|
| 94 | + $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | + |
|
| 96 | + // test d'existence du fichier |
|
| 97 | + if ($mode == 'test') { |
|
| 98 | + return $t ? $local : ''; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // sinon voir si on doit/peut le telecharger |
|
| 102 | + if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | + return $local; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($mode == 'modif' or !$t) { |
|
| 107 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | + // et des eventuelles recuperations concurantes |
|
| 109 | + include_spip('inc/acces'); |
|
| 110 | + if (!$taille_max) { |
|
| 111 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | + } |
|
| 113 | + $res = recuperer_url( |
|
| 114 | + $source, |
|
| 115 | + ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 116 | + ); |
|
| 117 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | + } |
|
| 120 | + if (!$res['length']) { |
|
| 121 | + // si $t c'est sans doute juste un not-modified-since |
|
| 122 | + return $t ? $local : false; |
|
| 123 | + } |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | + |
|
| 126 | + // pour une eventuelle indexation |
|
| 127 | + pipeline( |
|
| 128 | + 'post_edition', |
|
| 129 | + [ |
|
| 130 | + 'args' => [ |
|
| 131 | + 'operation' => 'copie_locale', |
|
| 132 | + 'source' => $source, |
|
| 133 | + 'fichier' => $local, |
|
| 134 | + 'http_res' => $res['length'], |
|
| 135 | + ], |
|
| 136 | + 'data' => null |
|
| 137 | + ] |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $local; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -153,93 +153,93 @@ discard block |
||
| 153 | 153 | * url ou false en cas d'echec |
| 154 | 154 | */ |
| 155 | 155 | function valider_url_distante($url, $known_hosts = []) { |
| 156 | - if (!function_exists('protocole_verifier')) { |
|
| 157 | - include_spip('inc/filtres_mini'); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $parsed_url = parse_url($url); |
|
| 165 | - if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if (!is_array($known_hosts)) { |
|
| 178 | - $known_hosts = [$known_hosts]; |
|
| 179 | - } |
|
| 180 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 181 | - $known_hosts[] = url_de_base(); |
|
| 182 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 183 | - |
|
| 184 | - $is_known_host = false; |
|
| 185 | - foreach ($known_hosts as $known_host) { |
|
| 186 | - $parse_known = parse_url($known_host); |
|
| 187 | - if ( |
|
| 188 | - $parse_known |
|
| 189 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 190 | - ) { |
|
| 191 | - $is_known_host = true; |
|
| 192 | - break; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!$is_known_host) { |
|
| 197 | - $host = trim($parsed_url['host'], '.'); |
|
| 198 | - if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 199 | - $ip = $host; |
|
| 200 | - } else { |
|
| 201 | - $ip = gethostbyname($host); |
|
| 202 | - if ($ip === $host) { |
|
| 203 | - // Error condition for gethostbyname() |
|
| 204 | - $ip = false; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - if ($ip) { |
|
| 208 | - $parts = array_map('intval', explode('.', $ip)); |
|
| 209 | - if ( |
|
| 210 | - 127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 211 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 212 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 213 | - ) { |
|
| 214 | - return false; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if (empty($parsed_url['port'])) { |
|
| 220 | - return $url; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $port = $parsed_url['port']; |
|
| 224 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 225 | - return $url; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if ($is_known_host) { |
|
| 229 | - foreach ($known_hosts as $known_host) { |
|
| 230 | - $parse_known = parse_url($known_host); |
|
| 231 | - if ( |
|
| 232 | - $parse_known |
|
| 233 | - and !empty($parse_known['port']) |
|
| 234 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 235 | - and $parse_known['port'] == $port |
|
| 236 | - ) { |
|
| 237 | - return $url; |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return false; |
|
| 156 | + if (!function_exists('protocole_verifier')) { |
|
| 157 | + include_spip('inc/filtres_mini'); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $parsed_url = parse_url($url); |
|
| 165 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if (!is_array($known_hosts)) { |
|
| 178 | + $known_hosts = [$known_hosts]; |
|
| 179 | + } |
|
| 180 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 181 | + $known_hosts[] = url_de_base(); |
|
| 182 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 183 | + |
|
| 184 | + $is_known_host = false; |
|
| 185 | + foreach ($known_hosts as $known_host) { |
|
| 186 | + $parse_known = parse_url($known_host); |
|
| 187 | + if ( |
|
| 188 | + $parse_known |
|
| 189 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 190 | + ) { |
|
| 191 | + $is_known_host = true; |
|
| 192 | + break; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!$is_known_host) { |
|
| 197 | + $host = trim($parsed_url['host'], '.'); |
|
| 198 | + if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 199 | + $ip = $host; |
|
| 200 | + } else { |
|
| 201 | + $ip = gethostbyname($host); |
|
| 202 | + if ($ip === $host) { |
|
| 203 | + // Error condition for gethostbyname() |
|
| 204 | + $ip = false; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + if ($ip) { |
|
| 208 | + $parts = array_map('intval', explode('.', $ip)); |
|
| 209 | + if ( |
|
| 210 | + 127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 211 | + or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 212 | + or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 213 | + ) { |
|
| 214 | + return false; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if (empty($parsed_url['port'])) { |
|
| 220 | + return $url; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $port = $parsed_url['port']; |
|
| 224 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 225 | + return $url; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if ($is_known_host) { |
|
| 229 | + foreach ($known_hosts as $known_host) { |
|
| 230 | + $parse_known = parse_url($known_host); |
|
| 231 | + if ( |
|
| 232 | + $parse_known |
|
| 233 | + and !empty($parse_known['port']) |
|
| 234 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 235 | + and $parse_known['port'] == $port |
|
| 236 | + ) { |
|
| 237 | + return $url; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return false; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -259,86 +259,86 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | function prepare_donnees_post($donnees, $boundary = '') { |
| 261 | 261 | |
| 262 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 263 | - // pour un appel soap par exemple |
|
| 264 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 265 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 266 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 267 | - $entete = ''; |
|
| 268 | - // on repasse tous les \r\n et \r en simples \n |
|
| 269 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 270 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 271 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 272 | - $p = strpos($donnees, "\n\n"); |
|
| 273 | - if ($p !== false) { |
|
| 274 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 275 | - $donnees = substr($donnees, $p + 2); |
|
| 276 | - } |
|
| 277 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 278 | - } else { |
|
| 279 | - /* boundary automatique */ |
|
| 280 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 281 | - if ($boundary === '') { |
|
| 282 | - $taille = 0; |
|
| 283 | - foreach ($donnees as $cle => $valeur) { |
|
| 284 | - if (is_array($valeur)) { |
|
| 285 | - foreach ($valeur as $val2) { |
|
| 286 | - $taille += strlen($val2); |
|
| 287 | - } |
|
| 288 | - } else { |
|
| 289 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 290 | - $taille += strlen($valeur); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - if ($taille > 500) { |
|
| 294 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 299 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 300 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 301 | - $chaine = ''; |
|
| 302 | - if (is_array($donnees)) { |
|
| 303 | - foreach ($donnees as $cle => $valeur) { |
|
| 304 | - if (is_array($valeur)) { |
|
| 305 | - foreach ($valeur as $val2) { |
|
| 306 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 307 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 308 | - $chaine .= "\r\n"; |
|
| 309 | - $chaine .= $val2; |
|
| 310 | - } |
|
| 311 | - } else { |
|
| 312 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 313 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 314 | - $chaine .= "\r\n"; |
|
| 315 | - $chaine .= $valeur; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 319 | - } |
|
| 320 | - } else { |
|
| 321 | - // fabrique une chaine HTTP simple pour un POST |
|
| 322 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 323 | - $chaine = []; |
|
| 324 | - if (is_array($donnees)) { |
|
| 325 | - foreach ($donnees as $cle => $valeur) { |
|
| 326 | - if (is_array($valeur)) { |
|
| 327 | - foreach ($valeur as $val2) { |
|
| 328 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 329 | - } |
|
| 330 | - } else { |
|
| 331 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - $chaine = implode('&', $chaine); |
|
| 335 | - } else { |
|
| 336 | - $chaine = $donnees; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - return [$entete, $chaine]; |
|
| 262 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 263 | + // pour un appel soap par exemple |
|
| 264 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 265 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 266 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 267 | + $entete = ''; |
|
| 268 | + // on repasse tous les \r\n et \r en simples \n |
|
| 269 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 270 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 271 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 272 | + $p = strpos($donnees, "\n\n"); |
|
| 273 | + if ($p !== false) { |
|
| 274 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 275 | + $donnees = substr($donnees, $p + 2); |
|
| 276 | + } |
|
| 277 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 278 | + } else { |
|
| 279 | + /* boundary automatique */ |
|
| 280 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 281 | + if ($boundary === '') { |
|
| 282 | + $taille = 0; |
|
| 283 | + foreach ($donnees as $cle => $valeur) { |
|
| 284 | + if (is_array($valeur)) { |
|
| 285 | + foreach ($valeur as $val2) { |
|
| 286 | + $taille += strlen($val2); |
|
| 287 | + } |
|
| 288 | + } else { |
|
| 289 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 290 | + $taille += strlen($valeur); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + if ($taille > 500) { |
|
| 294 | + $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 299 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 300 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 301 | + $chaine = ''; |
|
| 302 | + if (is_array($donnees)) { |
|
| 303 | + foreach ($donnees as $cle => $valeur) { |
|
| 304 | + if (is_array($valeur)) { |
|
| 305 | + foreach ($valeur as $val2) { |
|
| 306 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 307 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 308 | + $chaine .= "\r\n"; |
|
| 309 | + $chaine .= $val2; |
|
| 310 | + } |
|
| 311 | + } else { |
|
| 312 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 313 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 314 | + $chaine .= "\r\n"; |
|
| 315 | + $chaine .= $valeur; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 319 | + } |
|
| 320 | + } else { |
|
| 321 | + // fabrique une chaine HTTP simple pour un POST |
|
| 322 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 323 | + $chaine = []; |
|
| 324 | + if (is_array($donnees)) { |
|
| 325 | + foreach ($donnees as $cle => $valeur) { |
|
| 326 | + if (is_array($valeur)) { |
|
| 327 | + foreach ($valeur as $val2) { |
|
| 328 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 329 | + } |
|
| 330 | + } else { |
|
| 331 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + $chaine = implode('&', $chaine); |
|
| 335 | + } else { |
|
| 336 | + $chaine = $donnees; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + return [$entete, $chaine]; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -352,22 +352,22 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | function url_to_ascii($url_idn) { |
| 354 | 354 | |
| 355 | - if ($parts = parse_url($url_idn)) { |
|
| 356 | - $host = $parts['host']; |
|
| 357 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 358 | - include_spip('inc/idna_convert.class'); |
|
| 359 | - $IDN = new idna_convert(); |
|
| 360 | - $host_ascii = $IDN->encode($host); |
|
| 361 | - $url_idn = explode($host, $url_idn, 2); |
|
| 362 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 363 | - } |
|
| 364 | - // et on urlencode les char utf si besoin dans le path |
|
| 365 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 366 | - return urlencode($match[0]); |
|
| 367 | - }, $url_idn); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return $url_idn; |
|
| 355 | + if ($parts = parse_url($url_idn)) { |
|
| 356 | + $host = $parts['host']; |
|
| 357 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 358 | + include_spip('inc/idna_convert.class'); |
|
| 359 | + $IDN = new idna_convert(); |
|
| 360 | + $host_ascii = $IDN->encode($host); |
|
| 361 | + $url_idn = explode($host, $url_idn, 2); |
|
| 362 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 363 | + } |
|
| 364 | + // et on urlencode les char utf si besoin dans le path |
|
| 365 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 366 | + return urlencode($match[0]); |
|
| 367 | + }, $url_idn); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return $url_idn; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -408,197 +408,197 @@ discard block |
||
| 408 | 408 | * string file : nom du fichier si enregistre dans un fichier |
| 409 | 409 | */ |
| 410 | 410 | function recuperer_url($url, $options = []) { |
| 411 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 412 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 413 | - $default = [ |
|
| 414 | - 'transcoder' => false, |
|
| 415 | - 'methode' => 'GET', |
|
| 416 | - 'taille_max' => null, |
|
| 417 | - 'headers' => [], |
|
| 418 | - 'datas' => '', |
|
| 419 | - 'boundary' => '', |
|
| 420 | - 'refuser_gz' => false, |
|
| 421 | - 'if_modified_since' => '', |
|
| 422 | - 'uri_referer' => '', |
|
| 423 | - 'file' => '', |
|
| 424 | - 'follow_location' => 10, |
|
| 425 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 426 | - ]; |
|
| 427 | - $options = array_merge($default, $options); |
|
| 428 | - // copier directement dans un fichier ? |
|
| 429 | - $copy = $options['file']; |
|
| 430 | - |
|
| 431 | - if ($options['methode'] == 'HEAD') { |
|
| 432 | - $options['taille_max'] = 0; |
|
| 433 | - } |
|
| 434 | - if (is_null($options['taille_max'])) { |
|
| 435 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - // Ajout des en-têtes spécifiques si besoin |
|
| 440 | - $head_add = ''; |
|
| 441 | - if (!empty($options['headers'])) { |
|
| 442 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 443 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 444 | - } |
|
| 445 | - // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 446 | - unset($options['entetes']); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - if (!empty($options['datas'])) { |
|
| 450 | - list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 451 | - $head .= $head_add; |
|
| 452 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 453 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 454 | - } |
|
| 455 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 456 | - if ( |
|
| 457 | - strlen($postdata) |
|
| 458 | - and !$methode_demandee |
|
| 459 | - ) { |
|
| 460 | - $options['methode'] = 'POST'; |
|
| 461 | - } |
|
| 462 | - } elseif ($head_add) { |
|
| 463 | - $options['datas'] = $head_add . "\r\n"; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 467 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 468 | - if (!tester_url_absolue($url)) { |
|
| 469 | - $url = 'http://' . $url; |
|
| 470 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 471 | - $url = 'http:' . $url; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $url = url_to_ascii($url); |
|
| 475 | - |
|
| 476 | - $result = [ |
|
| 477 | - 'status' => 0, |
|
| 478 | - 'headers' => '', |
|
| 479 | - 'page' => '', |
|
| 480 | - 'length' => 0, |
|
| 481 | - 'last_modified' => '', |
|
| 482 | - 'location' => '', |
|
| 483 | - 'url' => $url |
|
| 484 | - ]; |
|
| 485 | - |
|
| 486 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 487 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 488 | - |
|
| 489 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 490 | - list($handle, $fopen) = init_http( |
|
| 491 | - $options['methode'], |
|
| 492 | - $url, |
|
| 493 | - $refuser_gz, |
|
| 494 | - $options['uri_referer'], |
|
| 495 | - $options['datas'], |
|
| 496 | - $options['version_http'], |
|
| 497 | - $options['if_modified_since'] |
|
| 498 | - ); |
|
| 499 | - if (!$handle) { |
|
| 500 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 501 | - |
|
| 502 | - return false; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 506 | - // et recuperer les en-tetes de reponses |
|
| 507 | - if (!$fopen) { |
|
| 508 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 509 | - if (!$res) { |
|
| 510 | - fclose($handle); |
|
| 511 | - $t = @parse_url($url); |
|
| 512 | - $host = $t['host']; |
|
| 513 | - // Chinoisierie inexplicable pour contrer |
|
| 514 | - // les actions liberticides de l'empire du milieu |
|
| 515 | - if ( |
|
| 516 | - !need_proxy($host) |
|
| 517 | - and $res = @file_get_contents($url) |
|
| 518 | - ) { |
|
| 519 | - $result['length'] = strlen($res); |
|
| 520 | - if ($copy) { |
|
| 521 | - ecrire_fichier($copy, $res); |
|
| 522 | - $result['file'] = $copy; |
|
| 523 | - } else { |
|
| 524 | - $result['page'] = $res; |
|
| 525 | - } |
|
| 526 | - $res = [ |
|
| 527 | - 'status' => 200, |
|
| 528 | - ]; |
|
| 529 | - } else { |
|
| 530 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 531 | - return false; |
|
| 532 | - } |
|
| 533 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 534 | - $options['follow_location']--; |
|
| 535 | - fclose($handle); |
|
| 536 | - include_spip('inc/filtres'); |
|
| 537 | - $url = suivre_lien($url, $res['location']); |
|
| 538 | - spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 539 | - |
|
| 540 | - return recuperer_url($url, $options); |
|
| 541 | - } elseif ($res['status'] !== 200) { |
|
| 542 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 543 | - } |
|
| 544 | - $result['status'] = $res['status']; |
|
| 545 | - if (isset($res['headers'])) { |
|
| 546 | - $result['headers'] = $res['headers']; |
|
| 547 | - } |
|
| 548 | - if (isset($res['last_modified'])) { |
|
| 549 | - $result['last_modified'] = $res['last_modified']; |
|
| 550 | - } |
|
| 551 | - if (isset($res['location'])) { |
|
| 552 | - $result['location'] = $res['location']; |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - // on ne veut que les entetes |
|
| 557 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 558 | - return $result; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 563 | - // sinon la memoire explose pour les gros flux |
|
| 564 | - |
|
| 565 | - $gz = false; |
|
| 566 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 567 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 571 | - if (!$result['length']) { |
|
| 572 | - $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 573 | - fclose($handle); |
|
| 574 | - if ($copy) { |
|
| 575 | - $result['length'] = $res; |
|
| 576 | - $result['file'] = $copy; |
|
| 577 | - } elseif ($res) { |
|
| 578 | - $result['page'] = &$res; |
|
| 579 | - $result['length'] = strlen($result['page']); |
|
| 580 | - } |
|
| 581 | - if (!$result['status']) { |
|
| 582 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - if (!$result['page']) { |
|
| 586 | - return $result; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - // Decompresser au besoin |
|
| 590 | - if ($gz) { |
|
| 591 | - $result['page'] = implode('', gzfile($gz)); |
|
| 592 | - supprimer_fichier($gz); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - // Faut-il l'importer dans notre charset local ? |
|
| 596 | - if ($options['transcoder']) { |
|
| 597 | - include_spip('inc/charsets'); |
|
| 598 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - return $result; |
|
| 411 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 412 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 413 | + $default = [ |
|
| 414 | + 'transcoder' => false, |
|
| 415 | + 'methode' => 'GET', |
|
| 416 | + 'taille_max' => null, |
|
| 417 | + 'headers' => [], |
|
| 418 | + 'datas' => '', |
|
| 419 | + 'boundary' => '', |
|
| 420 | + 'refuser_gz' => false, |
|
| 421 | + 'if_modified_since' => '', |
|
| 422 | + 'uri_referer' => '', |
|
| 423 | + 'file' => '', |
|
| 424 | + 'follow_location' => 10, |
|
| 425 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 426 | + ]; |
|
| 427 | + $options = array_merge($default, $options); |
|
| 428 | + // copier directement dans un fichier ? |
|
| 429 | + $copy = $options['file']; |
|
| 430 | + |
|
| 431 | + if ($options['methode'] == 'HEAD') { |
|
| 432 | + $options['taille_max'] = 0; |
|
| 433 | + } |
|
| 434 | + if (is_null($options['taille_max'])) { |
|
| 435 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + // Ajout des en-têtes spécifiques si besoin |
|
| 440 | + $head_add = ''; |
|
| 441 | + if (!empty($options['headers'])) { |
|
| 442 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 443 | + $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 444 | + } |
|
| 445 | + // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 446 | + unset($options['entetes']); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + if (!empty($options['datas'])) { |
|
| 450 | + list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 451 | + $head .= $head_add; |
|
| 452 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 453 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 454 | + } |
|
| 455 | + $options['datas'] = $head . "\r\n" . $postdata; |
|
| 456 | + if ( |
|
| 457 | + strlen($postdata) |
|
| 458 | + and !$methode_demandee |
|
| 459 | + ) { |
|
| 460 | + $options['methode'] = 'POST'; |
|
| 461 | + } |
|
| 462 | + } elseif ($head_add) { |
|
| 463 | + $options['datas'] = $head_add . "\r\n"; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 467 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 468 | + if (!tester_url_absolue($url)) { |
|
| 469 | + $url = 'http://' . $url; |
|
| 470 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 471 | + $url = 'http:' . $url; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $url = url_to_ascii($url); |
|
| 475 | + |
|
| 476 | + $result = [ |
|
| 477 | + 'status' => 0, |
|
| 478 | + 'headers' => '', |
|
| 479 | + 'page' => '', |
|
| 480 | + 'length' => 0, |
|
| 481 | + 'last_modified' => '', |
|
| 482 | + 'location' => '', |
|
| 483 | + 'url' => $url |
|
| 484 | + ]; |
|
| 485 | + |
|
| 486 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 487 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 488 | + |
|
| 489 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 490 | + list($handle, $fopen) = init_http( |
|
| 491 | + $options['methode'], |
|
| 492 | + $url, |
|
| 493 | + $refuser_gz, |
|
| 494 | + $options['uri_referer'], |
|
| 495 | + $options['datas'], |
|
| 496 | + $options['version_http'], |
|
| 497 | + $options['if_modified_since'] |
|
| 498 | + ); |
|
| 499 | + if (!$handle) { |
|
| 500 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 501 | + |
|
| 502 | + return false; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 506 | + // et recuperer les en-tetes de reponses |
|
| 507 | + if (!$fopen) { |
|
| 508 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 509 | + if (!$res) { |
|
| 510 | + fclose($handle); |
|
| 511 | + $t = @parse_url($url); |
|
| 512 | + $host = $t['host']; |
|
| 513 | + // Chinoisierie inexplicable pour contrer |
|
| 514 | + // les actions liberticides de l'empire du milieu |
|
| 515 | + if ( |
|
| 516 | + !need_proxy($host) |
|
| 517 | + and $res = @file_get_contents($url) |
|
| 518 | + ) { |
|
| 519 | + $result['length'] = strlen($res); |
|
| 520 | + if ($copy) { |
|
| 521 | + ecrire_fichier($copy, $res); |
|
| 522 | + $result['file'] = $copy; |
|
| 523 | + } else { |
|
| 524 | + $result['page'] = $res; |
|
| 525 | + } |
|
| 526 | + $res = [ |
|
| 527 | + 'status' => 200, |
|
| 528 | + ]; |
|
| 529 | + } else { |
|
| 530 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 531 | + return false; |
|
| 532 | + } |
|
| 533 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 534 | + $options['follow_location']--; |
|
| 535 | + fclose($handle); |
|
| 536 | + include_spip('inc/filtres'); |
|
| 537 | + $url = suivre_lien($url, $res['location']); |
|
| 538 | + spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 539 | + |
|
| 540 | + return recuperer_url($url, $options); |
|
| 541 | + } elseif ($res['status'] !== 200) { |
|
| 542 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 543 | + } |
|
| 544 | + $result['status'] = $res['status']; |
|
| 545 | + if (isset($res['headers'])) { |
|
| 546 | + $result['headers'] = $res['headers']; |
|
| 547 | + } |
|
| 548 | + if (isset($res['last_modified'])) { |
|
| 549 | + $result['last_modified'] = $res['last_modified']; |
|
| 550 | + } |
|
| 551 | + if (isset($res['location'])) { |
|
| 552 | + $result['location'] = $res['location']; |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + // on ne veut que les entetes |
|
| 557 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 558 | + return $result; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 563 | + // sinon la memoire explose pour les gros flux |
|
| 564 | + |
|
| 565 | + $gz = false; |
|
| 566 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 567 | + $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 571 | + if (!$result['length']) { |
|
| 572 | + $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 573 | + fclose($handle); |
|
| 574 | + if ($copy) { |
|
| 575 | + $result['length'] = $res; |
|
| 576 | + $result['file'] = $copy; |
|
| 577 | + } elseif ($res) { |
|
| 578 | + $result['page'] = &$res; |
|
| 579 | + $result['length'] = strlen($result['page']); |
|
| 580 | + } |
|
| 581 | + if (!$result['status']) { |
|
| 582 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + if (!$result['page']) { |
|
| 586 | + return $result; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + // Decompresser au besoin |
|
| 590 | + if ($gz) { |
|
| 591 | + $result['page'] = implode('', gzfile($gz)); |
|
| 592 | + supprimer_fichier($gz); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + // Faut-il l'importer dans notre charset local ? |
|
| 596 | + if ($options['transcoder']) { |
|
| 597 | + include_spip('inc/charsets'); |
|
| 598 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + return $result; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -614,73 +614,73 @@ discard block |
||
| 614 | 614 | * @return array|bool|mixed |
| 615 | 615 | */ |
| 616 | 616 | function recuperer_url_cache($url, $options = []) { |
| 617 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 618 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 619 | - } |
|
| 620 | - $default = [ |
|
| 621 | - 'transcoder' => false, |
|
| 622 | - 'methode' => 'GET', |
|
| 623 | - 'taille_max' => null, |
|
| 624 | - 'datas' => '', |
|
| 625 | - 'boundary' => '', |
|
| 626 | - 'refuser_gz' => false, |
|
| 627 | - 'if_modified_since' => '', |
|
| 628 | - 'uri_referer' => '', |
|
| 629 | - 'file' => '', |
|
| 630 | - 'follow_location' => 10, |
|
| 631 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 632 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 633 | - ]; |
|
| 634 | - $options = array_merge($default, $options); |
|
| 635 | - |
|
| 636 | - // cas ou il n'est pas possible de cacher |
|
| 637 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 638 | - return recuperer_url($url, $options); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 642 | - static $errors = []; |
|
| 643 | - if (isset($errors[$url])) { |
|
| 644 | - return $errors[$url]; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - $sig = $options; |
|
| 648 | - unset($sig['if_modified_since']); |
|
| 649 | - unset($sig['delai_cache']); |
|
| 650 | - $sig['url'] = $url; |
|
| 651 | - |
|
| 652 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 653 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 654 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 655 | - $cache = "$sub$cache"; |
|
| 656 | - |
|
| 657 | - $res = false; |
|
| 658 | - $is_cached = file_exists($cache); |
|
| 659 | - if ( |
|
| 660 | - $is_cached |
|
| 661 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 662 | - ) { |
|
| 663 | - lire_fichier($cache, $res); |
|
| 664 | - if ($res = unserialize($res)) { |
|
| 665 | - // mettre le last_modified et le status=304 ? |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - if (!$res) { |
|
| 669 | - $res = recuperer_url($url, $options); |
|
| 670 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 671 | - if (!$res) { |
|
| 672 | - if ($is_cached) { |
|
| 673 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 674 | - lire_fichier($cache, $res); |
|
| 675 | - $res = unserialize($res); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - return $errors[$url] = $res; |
|
| 679 | - } |
|
| 680 | - ecrire_fichier($cache, serialize($res)); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - return $res; |
|
| 617 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 618 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 619 | + } |
|
| 620 | + $default = [ |
|
| 621 | + 'transcoder' => false, |
|
| 622 | + 'methode' => 'GET', |
|
| 623 | + 'taille_max' => null, |
|
| 624 | + 'datas' => '', |
|
| 625 | + 'boundary' => '', |
|
| 626 | + 'refuser_gz' => false, |
|
| 627 | + 'if_modified_since' => '', |
|
| 628 | + 'uri_referer' => '', |
|
| 629 | + 'file' => '', |
|
| 630 | + 'follow_location' => 10, |
|
| 631 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 632 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 633 | + ]; |
|
| 634 | + $options = array_merge($default, $options); |
|
| 635 | + |
|
| 636 | + // cas ou il n'est pas possible de cacher |
|
| 637 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 638 | + return recuperer_url($url, $options); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 642 | + static $errors = []; |
|
| 643 | + if (isset($errors[$url])) { |
|
| 644 | + return $errors[$url]; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + $sig = $options; |
|
| 648 | + unset($sig['if_modified_since']); |
|
| 649 | + unset($sig['delai_cache']); |
|
| 650 | + $sig['url'] = $url; |
|
| 651 | + |
|
| 652 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 653 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 654 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 655 | + $cache = "$sub$cache"; |
|
| 656 | + |
|
| 657 | + $res = false; |
|
| 658 | + $is_cached = file_exists($cache); |
|
| 659 | + if ( |
|
| 660 | + $is_cached |
|
| 661 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 662 | + ) { |
|
| 663 | + lire_fichier($cache, $res); |
|
| 664 | + if ($res = unserialize($res)) { |
|
| 665 | + // mettre le last_modified et le status=304 ? |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + if (!$res) { |
|
| 669 | + $res = recuperer_url($url, $options); |
|
| 670 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 671 | + if (!$res) { |
|
| 672 | + if ($is_cached) { |
|
| 673 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 674 | + lire_fichier($cache, $res); |
|
| 675 | + $res = unserialize($res); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + return $errors[$url] = $res; |
|
| 679 | + } |
|
| 680 | + ecrire_fichier($cache, serialize($res)); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + return $res; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
@@ -698,41 +698,41 @@ discard block |
||
| 698 | 698 | * string contenu de la resource |
| 699 | 699 | */ |
| 700 | 700 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 701 | - $taille = 0; |
|
| 702 | - $result = ''; |
|
| 703 | - $fp = false; |
|
| 704 | - if ($fichier) { |
|
| 705 | - include_spip('inc/acces'); |
|
| 706 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 707 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 708 | - if (!$fp and file_exists($fichier)) { |
|
| 709 | - return filesize($fichier); |
|
| 710 | - } |
|
| 711 | - if (!$fp) { |
|
| 712 | - return false; |
|
| 713 | - } |
|
| 714 | - $result = 0; // on renvoie la taille du fichier |
|
| 715 | - } |
|
| 716 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 717 | - $res = fread($handle, 16384); |
|
| 718 | - $taille += strlen($res); |
|
| 719 | - if ($fp) { |
|
| 720 | - fwrite($fp, $res); |
|
| 721 | - $result = $taille; |
|
| 722 | - } else { |
|
| 723 | - $result .= $res; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - if ($fp) { |
|
| 727 | - spip_fclose_unlock($fp); |
|
| 728 | - spip_unlink($fichier); |
|
| 729 | - @rename($tmpfile, $fichier); |
|
| 730 | - if (!file_exists($fichier)) { |
|
| 731 | - return false; |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - return $result; |
|
| 701 | + $taille = 0; |
|
| 702 | + $result = ''; |
|
| 703 | + $fp = false; |
|
| 704 | + if ($fichier) { |
|
| 705 | + include_spip('inc/acces'); |
|
| 706 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 707 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 708 | + if (!$fp and file_exists($fichier)) { |
|
| 709 | + return filesize($fichier); |
|
| 710 | + } |
|
| 711 | + if (!$fp) { |
|
| 712 | + return false; |
|
| 713 | + } |
|
| 714 | + $result = 0; // on renvoie la taille du fichier |
|
| 715 | + } |
|
| 716 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 717 | + $res = fread($handle, 16384); |
|
| 718 | + $taille += strlen($res); |
|
| 719 | + if ($fp) { |
|
| 720 | + fwrite($fp, $res); |
|
| 721 | + $result = $taille; |
|
| 722 | + } else { |
|
| 723 | + $result .= $res; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + if ($fp) { |
|
| 727 | + spip_fclose_unlock($fp); |
|
| 728 | + spip_unlink($fichier); |
|
| 729 | + @rename($tmpfile, $fichier); |
|
| 730 | + if (!file_exists($fichier)) { |
|
| 731 | + return false; |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + return $result; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -754,35 +754,35 @@ discard block |
||
| 754 | 754 | * string location |
| 755 | 755 | */ |
| 756 | 756 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 757 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 758 | - |
|
| 759 | - $s = @trim(fgets($handle, 16384)); |
|
| 760 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 761 | - return false; |
|
| 762 | - } |
|
| 763 | - $result['status'] = intval($r[1]); |
|
| 764 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 765 | - $result['headers'][] = $s . "\n"; |
|
| 766 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 767 | - list(, $d, $v) = $r; |
|
| 768 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 769 | - $result['location'] = $v; |
|
| 770 | - } elseif ($d == 'Last-Modified') { |
|
| 771 | - $result['last_modified'] = strtotime($v); |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - if ( |
|
| 775 | - $if_modified_since |
|
| 776 | - and $result['last_modified'] |
|
| 777 | - and $if_modified_since > $result['last_modified'] |
|
| 778 | - and $result['status'] == 200 |
|
| 779 | - ) { |
|
| 780 | - $result['status'] = 304; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - $result['headers'] = implode('', $result['headers']); |
|
| 784 | - |
|
| 785 | - return $result; |
|
| 757 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 758 | + |
|
| 759 | + $s = @trim(fgets($handle, 16384)); |
|
| 760 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 761 | + return false; |
|
| 762 | + } |
|
| 763 | + $result['status'] = intval($r[1]); |
|
| 764 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 765 | + $result['headers'][] = $s . "\n"; |
|
| 766 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 767 | + list(, $d, $v) = $r; |
|
| 768 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 769 | + $result['location'] = $v; |
|
| 770 | + } elseif ($d == 'Last-Modified') { |
|
| 771 | + $result['last_modified'] = strtotime($v); |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + if ( |
|
| 775 | + $if_modified_since |
|
| 776 | + and $result['last_modified'] |
|
| 777 | + and $if_modified_since > $result['last_modified'] |
|
| 778 | + and $result['status'] == 200 |
|
| 779 | + ) { |
|
| 780 | + $result['status'] = 304; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + $result['headers'] = implode('', $result['headers']); |
|
| 784 | + |
|
| 785 | + return $result; |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | /** |
@@ -804,22 +804,22 @@ discard block |
||
| 804 | 804 | * Nom du fichier pour copie locale |
| 805 | 805 | **/ |
| 806 | 806 | function nom_fichier_copie_locale($source, $extension) { |
| 807 | - include_spip('inc/documents'); |
|
| 807 | + include_spip('inc/documents'); |
|
| 808 | 808 | |
| 809 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 810 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 809 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 810 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 811 | 811 | |
| 812 | - // on se place tout le temps comme si on etait a la racine |
|
| 813 | - if (_DIR_RACINE) { |
|
| 814 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 815 | - } |
|
| 812 | + // on se place tout le temps comme si on etait a la racine |
|
| 813 | + if (_DIR_RACINE) { |
|
| 814 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 815 | + } |
|
| 816 | 816 | |
| 817 | - $m = md5($source); |
|
| 817 | + $m = md5($source); |
|
| 818 | 818 | |
| 819 | - return $d |
|
| 820 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 821 | - . substr($m, 0, 4) |
|
| 822 | - . ".$extension"; |
|
| 819 | + return $d |
|
| 820 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 821 | + . substr($m, 0, 4) |
|
| 822 | + . ".$extension"; |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | /** |
@@ -837,70 +837,70 @@ discard block |
||
| 837 | 837 | * Nom du fichier calculé |
| 838 | 838 | **/ |
| 839 | 839 | function fichier_copie_locale($source) { |
| 840 | - // Si c'est deja local pas de souci |
|
| 841 | - if (!tester_url_absolue($source)) { |
|
| 842 | - if (_DIR_RACINE) { |
|
| 843 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - return $source; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 850 | - // a deja ete copie en local avec cette extension |
|
| 851 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 852 | - $path_parts = pathinfo($source); |
|
| 853 | - if (!isset($path_parts['extension'])) { |
|
| 854 | - $path_parts['extension'] = ''; |
|
| 855 | - } |
|
| 856 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 857 | - if ( |
|
| 858 | - $ext |
|
| 859 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 860 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 861 | - and file_exists(_DIR_RACINE . $f) |
|
| 862 | - ) { |
|
| 863 | - return $f; |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - // Si c'est deja dans la table des documents, |
|
| 868 | - // ramener le nom de sa copie potentielle |
|
| 869 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 870 | - |
|
| 871 | - if ($ext) { |
|
| 872 | - return nom_fichier_copie_locale($source, $ext); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 876 | - // et si il n'aurait pas deja ete rapatrie |
|
| 877 | - |
|
| 878 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 879 | - |
|
| 880 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 881 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 882 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 883 | - return $f; |
|
| 884 | - } |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - // Ping pour voir si son extension est connue et autorisee |
|
| 888 | - // avec mise en cache du resultat du ping |
|
| 889 | - |
|
| 890 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 891 | - if ( |
|
| 892 | - !@file_exists($cache) |
|
| 893 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 894 | - or _request('var_mode') == 'recalcul' |
|
| 895 | - ) { |
|
| 896 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 897 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 898 | - } |
|
| 899 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 900 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 901 | - return nom_fichier_copie_locale($source, $ext); |
|
| 902 | - } |
|
| 903 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 840 | + // Si c'est deja local pas de souci |
|
| 841 | + if (!tester_url_absolue($source)) { |
|
| 842 | + if (_DIR_RACINE) { |
|
| 843 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + return $source; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 850 | + // a deja ete copie en local avec cette extension |
|
| 851 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 852 | + $path_parts = pathinfo($source); |
|
| 853 | + if (!isset($path_parts['extension'])) { |
|
| 854 | + $path_parts['extension'] = ''; |
|
| 855 | + } |
|
| 856 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 857 | + if ( |
|
| 858 | + $ext |
|
| 859 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 860 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 861 | + and file_exists(_DIR_RACINE . $f) |
|
| 862 | + ) { |
|
| 863 | + return $f; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + // Si c'est deja dans la table des documents, |
|
| 868 | + // ramener le nom de sa copie potentielle |
|
| 869 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 870 | + |
|
| 871 | + if ($ext) { |
|
| 872 | + return nom_fichier_copie_locale($source, $ext); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 876 | + // et si il n'aurait pas deja ete rapatrie |
|
| 877 | + |
|
| 878 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 879 | + |
|
| 880 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 881 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 882 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 883 | + return $f; |
|
| 884 | + } |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + // Ping pour voir si son extension est connue et autorisee |
|
| 888 | + // avec mise en cache du resultat du ping |
|
| 889 | + |
|
| 890 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 891 | + if ( |
|
| 892 | + !@file_exists($cache) |
|
| 893 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 894 | + or _request('var_mode') == 'recalcul' |
|
| 895 | + ) { |
|
| 896 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 897 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 898 | + } |
|
| 899 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 900 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 901 | + return nom_fichier_copie_locale($source, $ext); |
|
| 902 | + } |
|
| 903 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | |
@@ -928,153 +928,153 @@ discard block |
||
| 928 | 928 | **/ |
| 929 | 929 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
| 930 | 930 | |
| 931 | - // pas la peine de perdre son temps |
|
| 932 | - if (!tester_url_absolue($source)) { |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - # charger les alias des types mime |
|
| 937 | - include_spip('base/typedoc'); |
|
| 938 | - |
|
| 939 | - $a = []; |
|
| 940 | - $mime_type = ''; |
|
| 941 | - // On va directement charger le debut des images et des fichiers html, |
|
| 942 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 943 | - // ca echoue l'utilisateur devra les entrer... |
|
| 944 | - $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 945 | - $headers = $reponse['headers'] ?? ''; |
|
| 946 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 947 | - if ($headers) { |
|
| 948 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 949 | - $mime_type = (trim($regs[1])); |
|
| 950 | - } else { |
|
| 951 | - $mime_type = ''; |
|
| 952 | - } // inconnu |
|
| 953 | - |
|
| 954 | - // Appliquer les alias |
|
| 955 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 956 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - // Si on a un mime-type insignifiant |
|
| 960 | - // text/plain,application/octet-stream ou vide |
|
| 961 | - // c'est peut-etre que le serveur ne sait pas |
|
| 962 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 963 | - // ou le Content-Disposition: attachment; filename=... |
|
| 964 | - $t = null; |
|
| 965 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 966 | - if ( |
|
| 967 | - !$t |
|
| 968 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 969 | - ) { |
|
| 970 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 971 | - } |
|
| 972 | - if ( |
|
| 973 | - !$t |
|
| 974 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 975 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 976 | - ) { |
|
| 977 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 982 | - if (!$t) { |
|
| 983 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 987 | - // On essaie de nouveau avec l'extension |
|
| 988 | - if ( |
|
| 989 | - !$t |
|
| 990 | - and $mime_type != 'text/plain' |
|
| 991 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 992 | - ) { |
|
| 993 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 994 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - if ($t) { |
|
| 998 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 999 | - $a['extension'] = $t['extension']; |
|
| 1000 | - } else { |
|
| 1001 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1002 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1003 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1004 | - if (!$t) { |
|
| 1005 | - return false; |
|
| 1006 | - } |
|
| 1007 | - $a['extension'] = $t['extension']; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1011 | - $a['taille'] = intval($regs[1]); |
|
| 1012 | - } |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - // Echec avec HEAD, on tente avec GET |
|
| 1016 | - if (!$a and !$max) { |
|
| 1017 | - spip_log("tenter GET $source", 'distant'); |
|
| 1018 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // si on a rien trouve pas la peine d'insister |
|
| 1022 | - if (!$a) { |
|
| 1023 | - return false; |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1027 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1028 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 1029 | - if ( |
|
| 1030 | - strpos($mime_type, 'image/') === 0 |
|
| 1031 | - and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1032 | - ) { |
|
| 1033 | - if ( |
|
| 1034 | - $max == 0 |
|
| 1035 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1036 | - and in_array($extension, formats_image_acceptables()) |
|
| 1037 | - and $charger_si_petite_image |
|
| 1038 | - ) { |
|
| 1039 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1040 | - } else { |
|
| 1041 | - if ($a['body']) { |
|
| 1042 | - $a['extension'] = $extension; |
|
| 1043 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1044 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1045 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1046 | - $a['largeur'] = intval($size_image[0]); |
|
| 1047 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1048 | - $a['type_image'] = true; |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1054 | - // ce sera mieux que 0x0 |
|
| 1055 | - // Flash is dead! |
|
| 1056 | - if ( |
|
| 1057 | - $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1058 | - and empty($a['largeur']) |
|
| 1059 | - ) { |
|
| 1060 | - $a['largeur'] = 425; |
|
| 1061 | - $a['hauteur'] = 350; |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - if ($mime_type == 'text/html') { |
|
| 1065 | - include_spip('inc/filtres'); |
|
| 1066 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1067 | - $page = $page['page'] ?? ''; |
|
| 1068 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1069 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1070 | - } |
|
| 1071 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1072 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1075 | - $a['mime_type'] = $mime_type; |
|
| 1076 | - |
|
| 1077 | - return $a; |
|
| 931 | + // pas la peine de perdre son temps |
|
| 932 | + if (!tester_url_absolue($source)) { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + # charger les alias des types mime |
|
| 937 | + include_spip('base/typedoc'); |
|
| 938 | + |
|
| 939 | + $a = []; |
|
| 940 | + $mime_type = ''; |
|
| 941 | + // On va directement charger le debut des images et des fichiers html, |
|
| 942 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 943 | + // ca echoue l'utilisateur devra les entrer... |
|
| 944 | + $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 945 | + $headers = $reponse['headers'] ?? ''; |
|
| 946 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 947 | + if ($headers) { |
|
| 948 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 949 | + $mime_type = (trim($regs[1])); |
|
| 950 | + } else { |
|
| 951 | + $mime_type = ''; |
|
| 952 | + } // inconnu |
|
| 953 | + |
|
| 954 | + // Appliquer les alias |
|
| 955 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 956 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + // Si on a un mime-type insignifiant |
|
| 960 | + // text/plain,application/octet-stream ou vide |
|
| 961 | + // c'est peut-etre que le serveur ne sait pas |
|
| 962 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 963 | + // ou le Content-Disposition: attachment; filename=... |
|
| 964 | + $t = null; |
|
| 965 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 966 | + if ( |
|
| 967 | + !$t |
|
| 968 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 969 | + ) { |
|
| 970 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 971 | + } |
|
| 972 | + if ( |
|
| 973 | + !$t |
|
| 974 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 975 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 976 | + ) { |
|
| 977 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 982 | + if (!$t) { |
|
| 983 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 987 | + // On essaie de nouveau avec l'extension |
|
| 988 | + if ( |
|
| 989 | + !$t |
|
| 990 | + and $mime_type != 'text/plain' |
|
| 991 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 992 | + ) { |
|
| 993 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 994 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + if ($t) { |
|
| 998 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 999 | + $a['extension'] = $t['extension']; |
|
| 1000 | + } else { |
|
| 1001 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1002 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1003 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1004 | + if (!$t) { |
|
| 1005 | + return false; |
|
| 1006 | + } |
|
| 1007 | + $a['extension'] = $t['extension']; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1011 | + $a['taille'] = intval($regs[1]); |
|
| 1012 | + } |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + // Echec avec HEAD, on tente avec GET |
|
| 1016 | + if (!$a and !$max) { |
|
| 1017 | + spip_log("tenter GET $source", 'distant'); |
|
| 1018 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // si on a rien trouve pas la peine d'insister |
|
| 1022 | + if (!$a) { |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1027 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1028 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 1029 | + if ( |
|
| 1030 | + strpos($mime_type, 'image/') === 0 |
|
| 1031 | + and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1032 | + ) { |
|
| 1033 | + if ( |
|
| 1034 | + $max == 0 |
|
| 1035 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1036 | + and in_array($extension, formats_image_acceptables()) |
|
| 1037 | + and $charger_si_petite_image |
|
| 1038 | + ) { |
|
| 1039 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1040 | + } else { |
|
| 1041 | + if ($a['body']) { |
|
| 1042 | + $a['extension'] = $extension; |
|
| 1043 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1044 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1045 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1046 | + $a['largeur'] = intval($size_image[0]); |
|
| 1047 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1048 | + $a['type_image'] = true; |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1054 | + // ce sera mieux que 0x0 |
|
| 1055 | + // Flash is dead! |
|
| 1056 | + if ( |
|
| 1057 | + $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1058 | + and empty($a['largeur']) |
|
| 1059 | + ) { |
|
| 1060 | + $a['largeur'] = 425; |
|
| 1061 | + $a['hauteur'] = 350; |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + if ($mime_type == 'text/html') { |
|
| 1065 | + include_spip('inc/filtres'); |
|
| 1066 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1067 | + $page = $page['page'] ?? ''; |
|
| 1068 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1069 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1070 | + } |
|
| 1071 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1072 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + $a['mime_type'] = $mime_type; |
|
| 1076 | + |
|
| 1077 | + return $a; |
|
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | |
@@ -1090,46 +1090,46 @@ discard block |
||
| 1090 | 1090 | * @return string |
| 1091 | 1091 | */ |
| 1092 | 1092 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1093 | - if (is_null($http_proxy)) { |
|
| 1094 | - $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1095 | - } |
|
| 1096 | - // rien a faire si pas de proxy :) |
|
| 1097 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1098 | - return ''; |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - if (is_null($http_noproxy)) { |
|
| 1102 | - $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1103 | - } |
|
| 1104 | - // si pas d'exception, on retourne le proxy |
|
| 1105 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1106 | - return $http_proxy; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1110 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1111 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1112 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1113 | - $http_noproxy = " $http_noproxy "; |
|
| 1114 | - $domain = $host; |
|
| 1115 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1116 | - if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1117 | - return ''; |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - while (strpos($domain, '.') !== false) { |
|
| 1121 | - $domain = explode('.', $domain); |
|
| 1122 | - array_shift($domain); |
|
| 1123 | - $domain = implode('.', $domain); |
|
| 1124 | - |
|
| 1125 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1126 | - if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1127 | - return ''; |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - // ok c'est pas une exception |
|
| 1132 | - return $http_proxy; |
|
| 1093 | + if (is_null($http_proxy)) { |
|
| 1094 | + $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1095 | + } |
|
| 1096 | + // rien a faire si pas de proxy :) |
|
| 1097 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1098 | + return ''; |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + if (is_null($http_noproxy)) { |
|
| 1102 | + $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1103 | + } |
|
| 1104 | + // si pas d'exception, on retourne le proxy |
|
| 1105 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1106 | + return $http_proxy; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1110 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1111 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1112 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1113 | + $http_noproxy = " $http_noproxy "; |
|
| 1114 | + $domain = $host; |
|
| 1115 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1116 | + if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1117 | + return ''; |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + while (strpos($domain, '.') !== false) { |
|
| 1121 | + $domain = explode('.', $domain); |
|
| 1122 | + array_shift($domain); |
|
| 1123 | + $domain = implode('.', $domain); |
|
| 1124 | + |
|
| 1125 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1126 | + if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1127 | + return ''; |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + // ok c'est pas une exception |
|
| 1132 | + return $http_proxy; |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | |
@@ -1152,59 +1152,59 @@ discard block |
||
| 1152 | 1152 | * @return array |
| 1153 | 1153 | */ |
| 1154 | 1154 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1155 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1156 | - $fopen = false; |
|
| 1157 | - |
|
| 1158 | - $t = @parse_url($url); |
|
| 1159 | - $host = $t['host']; |
|
| 1160 | - if ($t['scheme'] == 'http') { |
|
| 1161 | - $scheme = 'http'; |
|
| 1162 | - $noproxy = ''; |
|
| 1163 | - } elseif ($t['scheme'] == 'https') { |
|
| 1164 | - $scheme = 'ssl'; |
|
| 1165 | - $noproxy = 'ssl://'; |
|
| 1166 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1167 | - $t['port'] = 443; |
|
| 1168 | - } |
|
| 1169 | - } else { |
|
| 1170 | - $scheme = $t['scheme']; |
|
| 1171 | - $noproxy = $scheme . '://'; |
|
| 1172 | - } |
|
| 1173 | - if (isset($t['user'])) { |
|
| 1174 | - $user = [$t['user'], $t['pass']]; |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1178 | - $port = 80; |
|
| 1179 | - } |
|
| 1180 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1181 | - $path = '/'; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - if (!empty($t['query'])) { |
|
| 1185 | - $path .= '?' . $t['query']; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1189 | - if (!$f or !is_resource($f)) { |
|
| 1190 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1191 | - // ce qui correspond a $f===110 |
|
| 1192 | - if ( |
|
| 1193 | - $f !== 110 |
|
| 1194 | - and !need_proxy($host) |
|
| 1195 | - and !_request('tester_proxy') |
|
| 1196 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1197 | - ) { |
|
| 1198 | - $f = @fopen($url, 'rb'); |
|
| 1199 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1200 | - $fopen = true; |
|
| 1201 | - } else { |
|
| 1202 | - // echec total |
|
| 1203 | - $f = false; |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - return [$f, $fopen]; |
|
| 1155 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1156 | + $fopen = false; |
|
| 1157 | + |
|
| 1158 | + $t = @parse_url($url); |
|
| 1159 | + $host = $t['host']; |
|
| 1160 | + if ($t['scheme'] == 'http') { |
|
| 1161 | + $scheme = 'http'; |
|
| 1162 | + $noproxy = ''; |
|
| 1163 | + } elseif ($t['scheme'] == 'https') { |
|
| 1164 | + $scheme = 'ssl'; |
|
| 1165 | + $noproxy = 'ssl://'; |
|
| 1166 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1167 | + $t['port'] = 443; |
|
| 1168 | + } |
|
| 1169 | + } else { |
|
| 1170 | + $scheme = $t['scheme']; |
|
| 1171 | + $noproxy = $scheme . '://'; |
|
| 1172 | + } |
|
| 1173 | + if (isset($t['user'])) { |
|
| 1174 | + $user = [$t['user'], $t['pass']]; |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1178 | + $port = 80; |
|
| 1179 | + } |
|
| 1180 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1181 | + $path = '/'; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + if (!empty($t['query'])) { |
|
| 1185 | + $path .= '?' . $t['query']; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1189 | + if (!$f or !is_resource($f)) { |
|
| 1190 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1191 | + // ce qui correspond a $f===110 |
|
| 1192 | + if ( |
|
| 1193 | + $f !== 110 |
|
| 1194 | + and !need_proxy($host) |
|
| 1195 | + and !_request('tester_proxy') |
|
| 1196 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1197 | + ) { |
|
| 1198 | + $f = @fopen($url, 'rb'); |
|
| 1199 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1200 | + $fopen = true; |
|
| 1201 | + } else { |
|
| 1202 | + // echec total |
|
| 1203 | + $f = false; |
|
| 1204 | + } |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + return [$f, $fopen]; |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | /** |
@@ -1239,125 +1239,125 @@ discard block |
||
| 1239 | 1239 | * resource socket vers l'url demandee |
| 1240 | 1240 | */ |
| 1241 | 1241 | function lance_requete( |
| 1242 | - $method, |
|
| 1243 | - $scheme, |
|
| 1244 | - $user, |
|
| 1245 | - $host, |
|
| 1246 | - $path, |
|
| 1247 | - $port, |
|
| 1248 | - $noproxy, |
|
| 1249 | - $refuse_gz = false, |
|
| 1250 | - $referer = '', |
|
| 1251 | - $datas = '', |
|
| 1252 | - $vers = 'HTTP/1.0', |
|
| 1253 | - $date = '' |
|
| 1242 | + $method, |
|
| 1243 | + $scheme, |
|
| 1244 | + $user, |
|
| 1245 | + $host, |
|
| 1246 | + $path, |
|
| 1247 | + $port, |
|
| 1248 | + $noproxy, |
|
| 1249 | + $refuse_gz = false, |
|
| 1250 | + $referer = '', |
|
| 1251 | + $datas = '', |
|
| 1252 | + $vers = 'HTTP/1.0', |
|
| 1253 | + $date = '' |
|
| 1254 | 1254 | ) { |
| 1255 | 1255 | |
| 1256 | - $proxy_user = ''; |
|
| 1257 | - $http_proxy = need_proxy($host); |
|
| 1258 | - if ($user) { |
|
| 1259 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - $connect = ''; |
|
| 1263 | - if ($http_proxy) { |
|
| 1264 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1265 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1266 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1267 | - . "Host: $path_host\r\n" |
|
| 1268 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1269 | - } else { |
|
| 1270 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1271 | - . (!$user ? '' : "$user@") |
|
| 1272 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1273 | - } |
|
| 1274 | - $t2 = @parse_url($http_proxy); |
|
| 1275 | - $first_host = $t2['host']; |
|
| 1276 | - if (!($port = $t2['port'])) { |
|
| 1277 | - $port = 80; |
|
| 1278 | - } |
|
| 1279 | - if ($t2['user']) { |
|
| 1280 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1281 | - } |
|
| 1282 | - } else { |
|
| 1283 | - $first_host = $noproxy . $host; |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - if ($connect) { |
|
| 1287 | - $streamContext = stream_context_create([ |
|
| 1288 | - 'ssl' => [ |
|
| 1289 | - 'verify_peer' => false, |
|
| 1290 | - 'allow_self_signed' => true, |
|
| 1291 | - 'SNI_enabled' => true, |
|
| 1292 | - 'peer_name' => $host, |
|
| 1293 | - ] |
|
| 1294 | - ]); |
|
| 1295 | - $f = @stream_socket_client( |
|
| 1296 | - "tcp://$first_host:$port", |
|
| 1297 | - $errno, |
|
| 1298 | - $errstr, |
|
| 1299 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1300 | - STREAM_CLIENT_CONNECT, |
|
| 1301 | - $streamContext |
|
| 1302 | - ); |
|
| 1303 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1304 | - if (!$f) { |
|
| 1305 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1306 | - return $errno; |
|
| 1307 | - } |
|
| 1308 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1309 | - |
|
| 1310 | - fputs($f, $connect); |
|
| 1311 | - fputs($f, "\r\n"); |
|
| 1312 | - $res = fread($f, 1024); |
|
| 1313 | - if ( |
|
| 1314 | - !$res |
|
| 1315 | - or !count($res = explode(' ', $res)) |
|
| 1316 | - or $res[1] !== '200' |
|
| 1317 | - ) { |
|
| 1318 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1319 | - fclose($f); |
|
| 1320 | - |
|
| 1321 | - return false; |
|
| 1322 | - } |
|
| 1323 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1324 | - stream_set_blocking($f, true); |
|
| 1325 | - // envoyer le handshake |
|
| 1326 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1327 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1328 | - } else { |
|
| 1329 | - $ntry = 3; |
|
| 1330 | - do { |
|
| 1331 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1332 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1333 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1334 | - if (!$f) { |
|
| 1335 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1336 | - |
|
| 1337 | - return $errno; |
|
| 1338 | - } |
|
| 1339 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1343 | - |
|
| 1344 | - $host_port = $host; |
|
| 1345 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1346 | - $host_port .= ":$port"; |
|
| 1347 | - } |
|
| 1348 | - $req = "$method $path $vers\r\n" |
|
| 1349 | - . "Host: $host_port\r\n" |
|
| 1350 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1351 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1352 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1353 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1354 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1355 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1356 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1256 | + $proxy_user = ''; |
|
| 1257 | + $http_proxy = need_proxy($host); |
|
| 1258 | + if ($user) { |
|
| 1259 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + $connect = ''; |
|
| 1263 | + if ($http_proxy) { |
|
| 1264 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1265 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1266 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1267 | + . "Host: $path_host\r\n" |
|
| 1268 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1269 | + } else { |
|
| 1270 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1271 | + . (!$user ? '' : "$user@") |
|
| 1272 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1273 | + } |
|
| 1274 | + $t2 = @parse_url($http_proxy); |
|
| 1275 | + $first_host = $t2['host']; |
|
| 1276 | + if (!($port = $t2['port'])) { |
|
| 1277 | + $port = 80; |
|
| 1278 | + } |
|
| 1279 | + if ($t2['user']) { |
|
| 1280 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1281 | + } |
|
| 1282 | + } else { |
|
| 1283 | + $first_host = $noproxy . $host; |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + if ($connect) { |
|
| 1287 | + $streamContext = stream_context_create([ |
|
| 1288 | + 'ssl' => [ |
|
| 1289 | + 'verify_peer' => false, |
|
| 1290 | + 'allow_self_signed' => true, |
|
| 1291 | + 'SNI_enabled' => true, |
|
| 1292 | + 'peer_name' => $host, |
|
| 1293 | + ] |
|
| 1294 | + ]); |
|
| 1295 | + $f = @stream_socket_client( |
|
| 1296 | + "tcp://$first_host:$port", |
|
| 1297 | + $errno, |
|
| 1298 | + $errstr, |
|
| 1299 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1300 | + STREAM_CLIENT_CONNECT, |
|
| 1301 | + $streamContext |
|
| 1302 | + ); |
|
| 1303 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1304 | + if (!$f) { |
|
| 1305 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1306 | + return $errno; |
|
| 1307 | + } |
|
| 1308 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1309 | + |
|
| 1310 | + fputs($f, $connect); |
|
| 1311 | + fputs($f, "\r\n"); |
|
| 1312 | + $res = fread($f, 1024); |
|
| 1313 | + if ( |
|
| 1314 | + !$res |
|
| 1315 | + or !count($res = explode(' ', $res)) |
|
| 1316 | + or $res[1] !== '200' |
|
| 1317 | + ) { |
|
| 1318 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1319 | + fclose($f); |
|
| 1320 | + |
|
| 1321 | + return false; |
|
| 1322 | + } |
|
| 1323 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1324 | + stream_set_blocking($f, true); |
|
| 1325 | + // envoyer le handshake |
|
| 1326 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1327 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1328 | + } else { |
|
| 1329 | + $ntry = 3; |
|
| 1330 | + do { |
|
| 1331 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1332 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1333 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1334 | + if (!$f) { |
|
| 1335 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1336 | + |
|
| 1337 | + return $errno; |
|
| 1338 | + } |
|
| 1339 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1343 | + |
|
| 1344 | + $host_port = $host; |
|
| 1345 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1346 | + $host_port .= ":$port"; |
|
| 1347 | + } |
|
| 1348 | + $req = "$method $path $vers\r\n" |
|
| 1349 | + . "Host: $host_port\r\n" |
|
| 1350 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1351 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1352 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1353 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1354 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1355 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1356 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1357 | 1357 | |
| 1358 | 1358 | # spip_log("Requete\n$req", 'distant'); |
| 1359 | - fputs($f, $req); |
|
| 1360 | - fputs($f, $datas ? $datas : "\r\n"); |
|
| 1359 | + fputs($f, $req); |
|
| 1360 | + fputs($f, $datas ? $datas : "\r\n"); |
|
| 1361 | 1361 | |
| 1362 | - return $f; |
|
| 1362 | + return $f; |
|
| 1363 | 1363 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | 32 | define('_INC_DISTANT_MAX_SIZE', 2097152); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 38 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 39 | 39 | preg_replace( |
| 40 | 40 | '@^https?:@', |
| 41 | 41 | 'https?:', |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | // si c'est la protection de soi-meme, retourner le path |
| 72 | 72 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 74 | 74 | |
| 75 | 75 | return @file_exists($source) ? $source : false; |
| 76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 93 | + $localrac = _DIR_RACINE.$local; |
|
| 94 | 94 | $t = ($mode == 'force') ? false : @file_exists($localrac); |
| 95 | 95 | |
| 96 | 96 | // test d'existence du fichier |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
| 116 | 116 | ); |
| 117 | 117 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], 'distant'._LOG_INFO_IMPORTANTE); |
|
| 119 | 119 | } |
| 120 | 120 | if (!$res['length']) { |
| 121 | 121 | // si $t c'est sans doute juste un not-modified-since |
| 122 | 122 | return $t ? $local : false; |
| 123 | 123 | } |
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK', 'distant'); |
|
| 125 | 125 | |
| 126 | 126 | // pour une eventuelle indexation |
| 127 | 127 | pipeline( |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | $parts = array_map('intval', explode('.', $ip)); |
| 209 | 209 | if ( |
| 210 | 210 | 127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
| 211 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 212 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 211 | + or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1]) |
|
| 212 | + or (192 === $parts[0] && 168 === $parts[1]) |
|
| 213 | 213 | ) { |
| 214 | 214 | return false; |
| 215 | 215 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | $port = $parsed_url['port']; |
| 224 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 224 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 225 | 225 | return $url; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | if ($taille > 500) { |
| 294 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 294 | + $boundary = substr(md5(rand().'spip'), 0, 8); |
|
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
@@ -319,16 +319,16 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | } else { |
| 321 | 321 | // fabrique une chaine HTTP simple pour un POST |
| 322 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 322 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 323 | 323 | $chaine = []; |
| 324 | 324 | if (is_array($donnees)) { |
| 325 | 325 | foreach ($donnees as $cle => $valeur) { |
| 326 | 326 | if (is_array($valeur)) { |
| 327 | 327 | foreach ($valeur as $val2) { |
| 328 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 328 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 329 | 329 | } |
| 330 | 330 | } else { |
| 331 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 331 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | $chaine = implode('&', $chaine); |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $url_idn = implode($host_ascii, $url_idn); |
| 363 | 363 | } |
| 364 | 364 | // et on urlencode les char utf si besoin dans le path |
| 365 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 365 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { |
|
| 366 | 366 | return urlencode($match[0]); |
| 367 | 367 | }, $url_idn); |
| 368 | 368 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $head_add = ''; |
| 441 | 441 | if (!empty($options['headers'])) { |
| 442 | 442 | foreach ($options['headers'] as $champ => $valeur) { |
| 443 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 443 | + $head_add .= $champ.': '.$valeur."\r\n"; |
|
| 444 | 444 | } |
| 445 | 445 | // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
| 446 | 446 | unset($options['entetes']); |
@@ -450,9 +450,9 @@ discard block |
||
| 450 | 450 | list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
| 451 | 451 | $head .= $head_add; |
| 452 | 452 | if (stripos($head, 'Content-Length:') === false) { |
| 453 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 453 | + $head .= 'Content-Length: '.strlen($postdata)."\r\n"; |
|
| 454 | 454 | } |
| 455 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 455 | + $options['datas'] = $head."\r\n".$postdata; |
|
| 456 | 456 | if ( |
| 457 | 457 | strlen($postdata) |
| 458 | 458 | and !$methode_demandee |
@@ -460,15 +460,15 @@ discard block |
||
| 460 | 460 | $options['methode'] = 'POST'; |
| 461 | 461 | } |
| 462 | 462 | } elseif ($head_add) { |
| 463 | - $options['datas'] = $head_add . "\r\n"; |
|
| 463 | + $options['datas'] = $head_add."\r\n"; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 467 | 467 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 468 | 468 | if (!tester_url_absolue($url)) { |
| 469 | - $url = 'http://' . $url; |
|
| 469 | + $url = 'http://'.$url; |
|
| 470 | 470 | } elseif (strncmp($url, '//', 2) == 0) { |
| 471 | - $url = 'http:' . $url; |
|
| 471 | + $url = 'http:'.$url; |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | $url = url_to_ascii($url); |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | $options['if_modified_since'] |
| 498 | 498 | ); |
| 499 | 499 | if (!$handle) { |
| 500 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 500 | + spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR); |
|
| 501 | 501 | |
| 502 | 502 | return false; |
| 503 | 503 | } |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | 'status' => 200, |
| 528 | 528 | ]; |
| 529 | 529 | } else { |
| 530 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 530 | + spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR); |
|
| 531 | 531 | return false; |
| 532 | 532 | } |
| 533 | 533 | } elseif ($res['location'] and $options['follow_location']) { |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | |
| 540 | 540 | return recuperer_url($url, $options); |
| 541 | 541 | } elseif ($res['status'] !== 200) { |
| 542 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 542 | + spip_log('HTTP status '.$res['status']." pour $url", 'distant'); |
|
| 543 | 543 | } |
| 544 | 544 | $result['status'] = $res['status']; |
| 545 | 545 | if (isset($res['headers'])) { |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | |
| 565 | 565 | $gz = false; |
| 566 | 566 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 567 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 567 | + $gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz'); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | $sig['url'] = $url; |
| 651 | 651 | |
| 652 | 652 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 653 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 653 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 654 | 654 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 655 | 655 | $cache = "$sub$cache"; |
| 656 | 656 | |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | $fp = false; |
| 704 | 704 | if ($fichier) { |
| 705 | 705 | include_spip('inc/acces'); |
| 706 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 706 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 707 | 707 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 708 | 708 | if (!$fp and file_exists($fichier)) { |
| 709 | 709 | return filesize($fichier); |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | } |
| 763 | 763 | $result['status'] = intval($r[1]); |
| 764 | 764 | while ($s = trim(fgets($handle, 16384))) { |
| 765 | - $result['headers'][] = $s . "\n"; |
|
| 765 | + $result['headers'][] = $s."\n"; |
|
| 766 | 766 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 767 | 767 | list(, $d, $v) = $r; |
| 768 | 768 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -811,13 +811,13 @@ discard block |
||
| 811 | 811 | |
| 812 | 812 | // on se place tout le temps comme si on etait a la racine |
| 813 | 813 | if (_DIR_RACINE) { |
| 814 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 814 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | $m = md5($source); |
| 818 | 818 | |
| 819 | 819 | return $d |
| 820 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 820 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 821 | 821 | . substr($m, 0, 4) |
| 822 | 822 | . ".$extension"; |
| 823 | 823 | } |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | // Si c'est deja local pas de souci |
| 841 | 841 | if (!tester_url_absolue($source)) { |
| 842 | 842 | if (_DIR_RACINE) { |
| 843 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 843 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | return $source; |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | $ext |
| 859 | 859 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 860 | 860 | and $f = nom_fichier_copie_locale($source, $ext) |
| 861 | - and file_exists(_DIR_RACINE . $f) |
|
| 861 | + and file_exists(_DIR_RACINE.$f) |
|
| 862 | 862 | ) { |
| 863 | 863 | return $f; |
| 864 | 864 | } |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | |
| 867 | 867 | // Si c'est deja dans la table des documents, |
| 868 | 868 | // ramener le nom de sa copie potentielle |
| 869 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 869 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 870 | 870 | |
| 871 | 871 | if ($ext) { |
| 872 | 872 | return nom_fichier_copie_locale($source, $ext); |
@@ -877,9 +877,9 @@ discard block |
||
| 877 | 877 | |
| 878 | 878 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 879 | 879 | |
| 880 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 880 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 881 | 881 | $f = nom_fichier_copie_locale($source, $ext); |
| 882 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 882 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 883 | 883 | return $f; |
| 884 | 884 | } |
| 885 | 885 | } |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | // Ping pour voir si son extension est connue et autorisee |
| 888 | 888 | // avec mise en cache du resultat du ping |
| 889 | 889 | |
| 890 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 890 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 891 | 891 | if ( |
| 892 | 892 | !@file_exists($cache) |
| 893 | 893 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
@@ -897,10 +897,10 @@ discard block |
||
| 897 | 897 | ecrire_fichier($cache, serialize($path_parts)); |
| 898 | 898 | } |
| 899 | 899 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 900 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 900 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 901 | 901 | return nom_fichier_copie_locale($source, $ext); |
| 902 | 902 | } |
| 903 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 903 | + spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | |
@@ -967,20 +967,20 @@ discard block |
||
| 967 | 967 | !$t |
| 968 | 968 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 969 | 969 | ) { |
| 970 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 970 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 971 | 971 | } |
| 972 | 972 | if ( |
| 973 | 973 | !$t |
| 974 | 974 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 975 | 975 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 976 | 976 | ) { |
| 977 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 977 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 982 | 982 | if (!$t) { |
| 983 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 983 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -991,11 +991,11 @@ discard block |
||
| 991 | 991 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 992 | 992 | ) { |
| 993 | 993 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 994 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 994 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | if ($t) { |
| 998 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 998 | + spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant'); |
|
| 999 | 999 | $a['extension'] = $t['extension']; |
| 1000 | 1000 | } else { |
| 1001 | 1001 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | } else { |
| 1041 | 1041 | if ($a['body']) { |
| 1042 | 1042 | $a['extension'] = $extension; |
| 1043 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1043 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension); |
|
| 1044 | 1044 | ecrire_fichier($a['fichier'], $a['body']); |
| 1045 | 1045 | $size_image = @spip_getimagesize($a['fichier']); |
| 1046 | 1046 | $a['largeur'] = intval($size_image[0]); |
@@ -1168,7 +1168,7 @@ discard block |
||
| 1168 | 1168 | } |
| 1169 | 1169 | } else { |
| 1170 | 1170 | $scheme = $t['scheme']; |
| 1171 | - $noproxy = $scheme . '://'; |
|
| 1171 | + $noproxy = $scheme.'://'; |
|
| 1172 | 1172 | } |
| 1173 | 1173 | if (isset($t['user'])) { |
| 1174 | 1174 | $user = [$t['user'], $t['pass']]; |
@@ -1182,7 +1182,7 @@ discard block |
||
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | if (!empty($t['query'])) { |
| 1185 | - $path .= '?' . $t['query']; |
|
| 1185 | + $path .= '?'.$t['query']; |
|
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1256,20 +1256,20 @@ discard block |
||
| 1256 | 1256 | $proxy_user = ''; |
| 1257 | 1257 | $http_proxy = need_proxy($host); |
| 1258 | 1258 | if ($user) { |
| 1259 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1259 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | $connect = ''; |
| 1263 | 1263 | if ($http_proxy) { |
| 1264 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1265 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1266 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1264 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) { |
|
| 1265 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1266 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1267 | 1267 | . "Host: $path_host\r\n" |
| 1268 | 1268 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1269 | 1269 | } else { |
| 1270 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1270 | + $path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://") |
|
| 1271 | 1271 | . (!$user ? '' : "$user@") |
| 1272 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1272 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1273 | 1273 | } |
| 1274 | 1274 | $t2 = @parse_url($http_proxy); |
| 1275 | 1275 | $first_host = $t2['host']; |
@@ -1277,10 +1277,10 @@ discard block |
||
| 1277 | 1277 | $port = 80; |
| 1278 | 1278 | } |
| 1279 | 1279 | if ($t2['user']) { |
| 1280 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1280 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1281 | 1281 | } |
| 1282 | 1282 | } else { |
| 1283 | - $first_host = $noproxy . $host; |
|
| 1283 | + $first_host = $noproxy.$host; |
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | if ($connect) { |
@@ -1302,7 +1302,7 @@ discard block |
||
| 1302 | 1302 | ); |
| 1303 | 1303 | spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
| 1304 | 1304 | if (!$f) { |
| 1305 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1305 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1306 | 1306 | return $errno; |
| 1307 | 1307 | } |
| 1308 | 1308 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | or !count($res = explode(' ', $res)) |
| 1316 | 1316 | or $res[1] !== '200' |
| 1317 | 1317 | ) { |
| 1318 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1318 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1319 | 1319 | fclose($f); |
| 1320 | 1320 | |
| 1321 | 1321 | return false; |
@@ -1332,7 +1332,7 @@ discard block |
||
| 1332 | 1332 | } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
| 1333 | 1333 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 1334 | 1334 | if (!$f) { |
| 1335 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1335 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1336 | 1336 | |
| 1337 | 1337 | return $errno; |
| 1338 | 1338 | } |
@@ -1342,16 +1342,16 @@ discard block |
||
| 1342 | 1342 | $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
| 1343 | 1343 | |
| 1344 | 1344 | $host_port = $host; |
| 1345 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1345 | + if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) { |
|
| 1346 | 1346 | $host_port .= ":$port"; |
| 1347 | 1347 | } |
| 1348 | 1348 | $req = "$method $path $vers\r\n" |
| 1349 | 1349 | . "Host: $host_port\r\n" |
| 1350 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1351 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1350 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1351 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1352 | 1352 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1353 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1354 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1353 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1354 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1355 | 1355 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1356 | 1356 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1357 | 1357 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/texte'); |
@@ -19,105 +19,105 @@ discard block |
||
| 19 | 19 | // https://code.spip.net/@inc_plonger_dist |
| 20 | 20 | function inc_plonger_dist($id_rubrique, $idom = '', $list = [], $col = 1, $exclu = 0, $do = 'aff') { |
| 21 | 21 | |
| 22 | - if ($list) { |
|
| 23 | - $id_rubrique = $list[$col - 1]; |
|
| 24 | - } |
|
| 22 | + if ($list) { |
|
| 23 | + $id_rubrique = $list[$col - 1]; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - $ret = ''; |
|
| 26 | + $ret = ''; |
|
| 27 | 27 | |
| 28 | - # recherche les filles et petites-filles de la rubrique donnee |
|
| 29 | - # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 30 | - # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 31 | - # racine... sauf vers elle-meme ou sa propre branche) |
|
| 32 | - $ordre = []; |
|
| 33 | - $rub = []; |
|
| 28 | + # recherche les filles et petites-filles de la rubrique donnee |
|
| 29 | + # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on |
|
| 30 | + # deplace une rubrique, on peut la deplacer partout a partir de la |
|
| 31 | + # racine... sauf vers elle-meme ou sa propre branche) |
|
| 32 | + $ordre = []; |
|
| 33 | + $rub = []; |
|
| 34 | 34 | |
| 35 | - $res = sql_select( |
|
| 36 | - 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 37 | - 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 38 | - 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 35 | + $res = sql_select( |
|
| 36 | + 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
|
| 37 | + 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
|
| 38 | + 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 39 | 39 | AND rub1.id_rubrique!=' . sql_quote($exclu) . ' |
| 40 | 40 | AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')', |
| 41 | - '', |
|
| 42 | - '0+rub1.titre,rub1.titre' |
|
| 43 | - ); |
|
| 41 | + '', |
|
| 42 | + '0+rub1.titre,rub1.titre' |
|
| 43 | + ); |
|
| 44 | 44 | |
| 45 | - while ($row = sql_fetch($res)) { |
|
| 46 | - if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 47 | - $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 48 | - if ($row['id_parent'] == $id_rubrique) { |
|
| 49 | - $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 50 | - if ($row['langue_choisie'] != 'oui') { |
|
| 51 | - $t .= ' <small title="' |
|
| 52 | - . traduire_nom_langue($row['lang']) |
|
| 53 | - . '">[' . $row['lang'] . ']</small>'; |
|
| 54 | - } |
|
| 55 | - $ordre[$row['id_rubrique']] = $t; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $next = isset($list[$col]) ? $list[$col] : 0; |
|
| 60 | - if ($ordre) { |
|
| 61 | - $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 62 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 63 | - $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 45 | + while ($row = sql_fetch($res)) { |
|
| 46 | + if (autoriser('voir', 'rubrique', $row['id_rubrique'])) { |
|
| 47 | + $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant']; |
|
| 48 | + if ($row['id_parent'] == $id_rubrique) { |
|
| 49 | + $t = trim(typo(supprimer_numero($row['titre']))); |
|
| 50 | + if ($row['langue_choisie'] != 'oui') { |
|
| 51 | + $t .= ' <small title="' |
|
| 52 | + . traduire_nom_langue($row['lang']) |
|
| 53 | + . '">[' . $row['lang'] . ']</small>'; |
|
| 54 | + } |
|
| 55 | + $ordre[$row['id_rubrique']] = $t; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $next = isset($list[$col]) ? $list[$col] : 0; |
|
| 60 | + if ($ordre) { |
|
| 61 | + $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 62 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
|
| 63 | + $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 64 | 64 | |
| 65 | - foreach ($ordre as $id => $titrebrut) { |
|
| 66 | - $titre = supprimer_numero($titrebrut); |
|
| 65 | + foreach ($ordre as $id => $titrebrut) { |
|
| 66 | + $titre = supprimer_numero($titrebrut); |
|
| 67 | 67 | |
| 68 | - $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 69 | - if (isset($rub[$id]['enfants'])) { |
|
| 70 | - $classe2 = " class='rub-ouverte'"; |
|
| 71 | - $url = "\nhref='$rec&id=$id'"; |
|
| 72 | - } else { |
|
| 73 | - $classe2 = $url = ''; |
|
| 74 | - $url = "\nhref='javascript:void(0)'"; |
|
| 75 | - } |
|
| 68 | + $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 69 | + if (isset($rub[$id]['enfants'])) { |
|
| 70 | + $classe2 = " class='rub-ouverte'"; |
|
| 71 | + $url = "\nhref='$rec&id=$id'"; |
|
| 72 | + } else { |
|
| 73 | + $classe2 = $url = ''; |
|
| 74 | + $url = "\nhref='javascript:void(0)'"; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $js_func = $do . '_selection_titre'; |
|
| 78 | - $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 79 | - . (!is_array($list) ? ' false' |
|
| 80 | - : "aff_selection_provisoire($id,$args)") |
|
| 77 | + $js_func = $do . '_selection_titre'; |
|
| 78 | + $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
|
| 79 | + . (!is_array($list) ? ' false' |
|
| 80 | + : "aff_selection_provisoire($id,$args)") |
|
| 81 | 81 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 82 | 82 | # et l'affichage de son titre dans le bandeau |
| 83 | - . "\"\nondblclick=\"" |
|
| 84 | - . "$js_func(this." |
|
| 85 | - . 'firstChild.nodeValue,' |
|
| 86 | - . $id |
|
| 87 | - . ",'selection_rubrique','id_parent');" |
|
| 88 | - . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 89 | - . '"'; |
|
| 83 | + . "\"\nondblclick=\"" |
|
| 84 | + . "$js_func(this." |
|
| 85 | + . 'firstChild.nodeValue,' |
|
| 86 | + . $id |
|
| 87 | + . ",'selection_rubrique','id_parent');" |
|
| 88 | + . "\nreturn aff_selection_provisoire($id,$args);" |
|
| 89 | + . '"'; |
|
| 90 | 90 | |
| 91 | - $ret .= "<div class='" |
|
| 92 | - . (($id == $next) ? 'item on' : 'item') |
|
| 93 | - . "'><div class='" |
|
| 94 | - . $classe1 |
|
| 95 | - . "'><div$classe2><a" |
|
| 96 | - . $url |
|
| 97 | - . $click |
|
| 98 | - . '>' |
|
| 99 | - . $titre |
|
| 100 | - . '</a></div></div></div>'; |
|
| 101 | - } |
|
| 102 | - } |
|
| 91 | + $ret .= "<div class='" |
|
| 92 | + . (($id == $next) ? 'item on' : 'item') |
|
| 93 | + . "'><div class='" |
|
| 94 | + . $classe1 |
|
| 95 | + . "'><div$classe2><a" |
|
| 96 | + . $url |
|
| 97 | + . $click |
|
| 98 | + . '>' |
|
| 99 | + . $titre |
|
| 100 | + . '</a></div></div></div>'; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $idom2 = $idom . '_col_' . ($col + 1); |
|
| 105 | - $left = ($col * 250); |
|
| 104 | + $idom2 = $idom . '_col_' . ($col + 1); |
|
| 105 | + $left = ($col * 250); |
|
| 106 | 106 | |
| 107 | - return http_img_pack( |
|
| 108 | - 'loader.svg', |
|
| 109 | - '', |
|
| 110 | - "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 111 | - . ($left - 30) |
|
| 112 | - . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 113 | - ) |
|
| 114 | - . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 115 | - . ($left - 250) |
|
| 116 | - . "px;'>" |
|
| 117 | - . $ret |
|
| 118 | - . "\n</div>\n<div id='$idom2'>" |
|
| 119 | - . ($next |
|
| 120 | - ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 121 | - : '') |
|
| 122 | - . "\n</div>"; |
|
| 107 | + return http_img_pack( |
|
| 108 | + 'loader.svg', |
|
| 109 | + '', |
|
| 110 | + "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 111 | + . ($left - 30) |
|
| 112 | + . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
|
| 113 | + ) |
|
| 114 | + . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 115 | + . ($left - 250) |
|
| 116 | + . "px;'>" |
|
| 117 | + . $ret |
|
| 118 | + . "\n</div>\n<div id='$idom2'>" |
|
| 119 | + . ($next |
|
| 120 | + ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu) |
|
| 121 | + : '') |
|
| 122 | + . "\n</div>"; |
|
| 123 | 123 | } |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | $res = sql_select( |
| 36 | 36 | 'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant', |
| 37 | 37 | 'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)', |
| 38 | - 'rub1.id_parent = ' . sql_quote($id_rubrique) . ' |
|
| 39 | - AND rub1.id_rubrique!=' . sql_quote($exclu) . ' |
|
| 40 | - AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')', |
|
| 38 | + 'rub1.id_parent = '.sql_quote($id_rubrique).' |
|
| 39 | + AND rub1.id_rubrique!=' . sql_quote($exclu).' |
|
| 40 | + AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu).')', |
|
| 41 | 41 | '', |
| 42 | 42 | '0+rub1.titre,rub1.titre' |
| 43 | 43 | ); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | if ($row['langue_choisie'] != 'oui') { |
| 51 | 51 | $t .= ' <small title="' |
| 52 | 52 | . traduire_nom_langue($row['lang']) |
| 53 | - . '">[' . $row['lang'] . ']</small>'; |
|
| 53 | + . '">['.$row['lang'].']</small>'; |
|
| 54 | 54 | } |
| 55 | 55 | $ordre[$row['id_rubrique']] = $t; |
| 56 | 56 | } |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | $next = isset($list[$col]) ? $list[$col] : 0; |
| 60 | 60 | if ($ordre) { |
| 61 | - $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); |
|
| 61 | + $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=".($col + 1)); |
|
| 62 | 62 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); |
| 63 | - $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; |
|
| 63 | + $args = "'$idom',this,$col,'".$GLOBALS['spip_lang_left']."','$info',event"; |
|
| 64 | 64 | |
| 65 | 65 | foreach ($ordre as $id => $titrebrut) { |
| 66 | 66 | $titre = supprimer_numero($titrebrut); |
| 67 | 67 | |
| 68 | - $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 68 | + $classe1 = 'petit-item '.($id_rubrique ? 'petite-rubrique' : 'petit-secteur'); |
|
| 69 | 69 | if (isset($rub[$id]['enfants'])) { |
| 70 | 70 | $classe2 = " class='rub-ouverte'"; |
| 71 | 71 | $url = "\nhref='$rec&id=$id'"; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $url = "\nhref='javascript:void(0)'"; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $js_func = $do . '_selection_titre'; |
|
| 77 | + $js_func = $do.'_selection_titre'; |
|
| 78 | 78 | $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn " |
| 79 | 79 | . (!is_array($list) ? ' false' |
| 80 | 80 | : "aff_selection_provisoire($id,$args)") |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $idom2 = $idom . '_col_' . ($col + 1); |
|
| 104 | + $idom2 = $idom.'_col_'.($col + 1); |
|
| 105 | 105 | $left = ($col * 250); |
| 106 | 106 | |
| 107 | 107 | return http_img_pack( |
| 108 | 108 | 'loader.svg', |
| 109 | 109 | '', |
| 110 | - "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 110 | + "class='loader' style='visibility: hidden; position: absolute; ".$GLOBALS['spip_lang_left'].': ' |
|
| 111 | 111 | . ($left - 30) |
| 112 | 112 | . "px; top: 2px; z-index: 2;' id='img_$idom2'" |
| 113 | 113 | ) |
| 114 | - . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': ' |
|
| 114 | + . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; ".$GLOBALS['spip_lang_left'].': ' |
|
| 115 | 115 | . ($left - 250) |
| 116 | 116 | . "px;'>" |
| 117 | 117 | . $ret |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/boutons'); |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * Contexte |
| 38 | 38 | **/ |
| 39 | 39 | function definir_barre_contexte($contexte = null) { |
| 40 | - if (is_null($contexte)) { |
|
| 41 | - $contexte = $_GET; |
|
| 42 | - } elseif (is_string($contexte)) { |
|
| 43 | - $contexte = unserialize($contexte); |
|
| 44 | - } |
|
| 45 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | - if (!function_exists('trouver_objet_exec')) { |
|
| 47 | - include_spip('inc/pipelines_ecrire'); |
|
| 48 | - } |
|
| 49 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | - $_id = $e['id_table_objet']; |
|
| 51 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | - $table = $e['table_objet_sql']; |
|
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | - if (isset($row['id_rubrique'])) { |
|
| 55 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | - if (isset($row['id_secteur'])) { |
|
| 57 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | - } |
|
| 59 | - } elseif (isset($row['id_groupe'])) { |
|
| 60 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $contexte; |
|
| 40 | + if (is_null($contexte)) { |
|
| 41 | + $contexte = $_GET; |
|
| 42 | + } elseif (is_string($contexte)) { |
|
| 43 | + $contexte = unserialize($contexte); |
|
| 44 | + } |
|
| 45 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | + if (!function_exists('trouver_objet_exec')) { |
|
| 47 | + include_spip('inc/pipelines_ecrire'); |
|
| 48 | + } |
|
| 49 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | + $_id = $e['id_table_objet']; |
|
| 51 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | + $table = $e['table_objet_sql']; |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | + if (isset($row['id_rubrique'])) { |
|
| 55 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | + if (isset($row['id_secteur'])) { |
|
| 57 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | + } |
|
| 59 | + } elseif (isset($row['id_groupe'])) { |
|
| 60 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $contexte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -79,92 +79,92 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 82 | - include_spip('inc/autoriser'); |
|
| 83 | - $boutons_admin = []; |
|
| 82 | + include_spip('inc/autoriser'); |
|
| 83 | + $boutons_admin = []; |
|
| 84 | 84 | |
| 85 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | - $liste_boutons = []; |
|
| 85 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | + $liste_boutons = []; |
|
| 87 | 87 | |
| 88 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | - if ( |
|
| 90 | - function_exists('boutons_plugins') |
|
| 91 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | - ) { |
|
| 93 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | - } |
|
| 88 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | + if ( |
|
| 90 | + function_exists('boutons_plugins') |
|
| 91 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | + ) { |
|
| 93 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($liste_boutons as $id => $infos) { |
|
| 97 | - $parent = ''; |
|
| 98 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | - if ( |
|
| 100 | - !isset($infos['parent']) |
|
| 101 | - or !($parent = $infos['parent']) |
|
| 102 | - or !$autorise |
|
| 103 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | - ) { |
|
| 105 | - if ( |
|
| 106 | - $parent |
|
| 107 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | - and isset($boutons_admin[$parent]) |
|
| 109 | - ) { |
|
| 110 | - if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 111 | - $boutons_admin[$parent]->sousmenu = []; |
|
| 112 | - } |
|
| 113 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 114 | - if ($position < 0) { |
|
| 115 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 116 | - } |
|
| 117 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 118 | - + [ |
|
| 119 | - $id => new Bouton( |
|
| 120 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | - $infos['titre'], // titre |
|
| 122 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 123 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 124 | - ) |
|
| 125 | - ] |
|
| 126 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 127 | - } |
|
| 128 | - if ( |
|
| 129 | - !$parent |
|
| 130 | - // provisoire, eviter les vieux boutons |
|
| 131 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 132 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 133 | - ) { |
|
| 134 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 135 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 136 | - + [ |
|
| 137 | - $id => new Bouton( |
|
| 138 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | - $infos['titre'], // titre |
|
| 140 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 141 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 142 | - ) |
|
| 143 | - ] |
|
| 144 | - + array_slice($boutons_admin, $position, 100); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 96 | + foreach ($liste_boutons as $id => $infos) { |
|
| 97 | + $parent = ''; |
|
| 98 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | + if ( |
|
| 100 | + !isset($infos['parent']) |
|
| 101 | + or !($parent = $infos['parent']) |
|
| 102 | + or !$autorise |
|
| 103 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | + ) { |
|
| 105 | + if ( |
|
| 106 | + $parent |
|
| 107 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | + and isset($boutons_admin[$parent]) |
|
| 109 | + ) { |
|
| 110 | + if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 111 | + $boutons_admin[$parent]->sousmenu = []; |
|
| 112 | + } |
|
| 113 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 114 | + if ($position < 0) { |
|
| 115 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 116 | + } |
|
| 117 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 118 | + + [ |
|
| 119 | + $id => new Bouton( |
|
| 120 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | + $infos['titre'], // titre |
|
| 122 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 123 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 124 | + ) |
|
| 125 | + ] |
|
| 126 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 127 | + } |
|
| 128 | + if ( |
|
| 129 | + !$parent |
|
| 130 | + // provisoire, eviter les vieux boutons |
|
| 131 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 132 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 133 | + ) { |
|
| 134 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 135 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 136 | + + [ |
|
| 137 | + $id => new Bouton( |
|
| 138 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | + $infos['titre'], // titre |
|
| 140 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 141 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 142 | + ) |
|
| 143 | + ] |
|
| 144 | + + array_slice($boutons_admin, $position, 100); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 149 | 149 | |
| 150 | - // définir les favoris et positions d’origine |
|
| 151 | - if ($boutons_admin) { |
|
| 152 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 153 | - $i = 1; |
|
| 154 | - foreach ($boutons_admin as $key => $menu) { |
|
| 155 | - $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 156 | - $menu->position = $i++; |
|
| 157 | - if ($menu->sousmenu) { |
|
| 158 | - $j = 1; |
|
| 159 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 160 | - $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 161 | - $bouton->position = $j++; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 150 | + // définir les favoris et positions d’origine |
|
| 151 | + if ($boutons_admin) { |
|
| 152 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 153 | + $i = 1; |
|
| 154 | + foreach ($boutons_admin as $key => $menu) { |
|
| 155 | + $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 156 | + $menu->position = $i++; |
|
| 157 | + if ($menu->sousmenu) { |
|
| 158 | + $j = 1; |
|
| 159 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 160 | + $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 161 | + $bouton->position = $j++; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - return $boutons_admin; |
|
| 167 | + return $boutons_admin; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -176,22 +176,22 @@ discard block |
||
| 176 | 176 | * @return Bouton[] |
| 177 | 177 | */ |
| 178 | 178 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 179 | - foreach ($menus as $menu) { |
|
| 180 | - if ($menu->sousmenu) { |
|
| 181 | - $libelles = $isfavoris = $favoris = []; |
|
| 182 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 183 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 184 | - $isfavoris[$key] = (bool)$item->favori; |
|
| 185 | - $favoris[$key] = $item->favori; |
|
| 186 | - } |
|
| 187 | - if ($avec_favoris) { |
|
| 188 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | - } else { |
|
| 190 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - return $menus; |
|
| 179 | + foreach ($menus as $menu) { |
|
| 180 | + if ($menu->sousmenu) { |
|
| 181 | + $libelles = $isfavoris = $favoris = []; |
|
| 182 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 183 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 184 | + $isfavoris[$key] = (bool)$item->favori; |
|
| 185 | + $favoris[$key] = $item->favori; |
|
| 186 | + } |
|
| 187 | + if ($avec_favoris) { |
|
| 188 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | + } else { |
|
| 190 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + return $menus; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return Bouton[] |
| 203 | 203 | */ |
| 204 | 204 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 205 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 205 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -215,23 +215,23 @@ discard block |
||
| 215 | 215 | * @return string |
| 216 | 216 | */ |
| 217 | 217 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 218 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 219 | - $url = generer_url_ecrire($url, $args, true); |
|
| 220 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 221 | - // &truc=@machin@ |
|
| 222 | - // @machin@ etant remplace par _request('machin') |
|
| 223 | - $url = str_replace('&', '&', $url); |
|
| 224 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 225 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 226 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 227 | - } |
|
| 228 | - $val = _request($matches[2], $contexte); |
|
| 229 | - $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
|
| 230 | - } |
|
| 231 | - $url = str_replace('&', '&', $url); |
|
| 232 | - } |
|
| 218 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 219 | + $url = generer_url_ecrire($url, $args, true); |
|
| 220 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 221 | + // &truc=@machin@ |
|
| 222 | + // @machin@ etant remplace par _request('machin') |
|
| 223 | + $url = str_replace('&', '&', $url); |
|
| 224 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 225 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 226 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 227 | + } |
|
| 228 | + $val = _request($matches[2], $contexte); |
|
| 229 | + $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
|
| 230 | + } |
|
| 231 | + $url = str_replace('&', '&', $url); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - return $url; |
|
| 234 | + return $url; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * Code HTML du bandeau |
| 242 | 242 | */ |
| 243 | 243 | function inc_bandeau_dist() { |
| 244 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 244 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function obtenir_menus_favoris() { |
| 253 | - if ( |
|
| 254 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 256 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 257 | - ) { |
|
| 258 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 259 | - } |
|
| 260 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 261 | - return $definir_menus_favoris(); |
|
| 253 | + if ( |
|
| 254 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 256 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 257 | + ) { |
|
| 258 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 259 | + } |
|
| 260 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 261 | + return $definir_menus_favoris(); |
|
| 262 | 262 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $_id = $e['id_table_objet']; |
| 51 | 51 | if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
| 52 | 52 | $table = $e['table_objet_sql']; |
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=".intval($id)); |
|
| 54 | 54 | if (isset($row['id_rubrique'])) { |
| 55 | 55 | $contexte['id_rubrique'] = $row['id_rubrique']; |
| 56 | 56 | if (isset($row['id_secteur'])) { |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
| 118 | 118 | + [ |
| 119 | 119 | $id => new Bouton( |
| 120 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | - $infos['titre'], // titre |
|
| 120 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | + $infos['titre'], // titre |
|
| 122 | 122 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 123 | 123 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 124 | 124 | ) |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | $boutons_admin = array_slice($boutons_admin, 0, $position) |
| 136 | 136 | + [ |
| 137 | 137 | $id => new Bouton( |
| 138 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | - $infos['titre'], // titre |
|
| 138 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | + $infos['titre'], // titre |
|
| 140 | 140 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 141 | 141 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 142 | 142 | ) |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $libelles = $isfavoris = $favoris = []; |
| 182 | 182 | foreach ($menu->sousmenu as $key => $item) { |
| 183 | 183 | $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
| 184 | - $isfavoris[$key] = (bool)$item->favori; |
|
| 184 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 185 | 185 | $favoris[$key] = $item->favori; |
| 186 | 186 | } |
| 187 | 187 | if ($avec_favoris) { |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | $url = str_replace('&', '&', $url); |
| 224 | 224 | while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
| 225 | 225 | if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
| 226 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 226 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 227 | 227 | } |
| 228 | 228 | $val = _request($matches[2], $contexte); |
| 229 | 229 | $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('base/objets'); |
| 23 | 23 | |
@@ -57,115 +57,115 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | */ |
| 59 | 59 | function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) { |
| 60 | - static $current_base = null; |
|
| 60 | + static $current_base = null; |
|
| 61 | 61 | |
| 62 | - // les anciennes fonctions modifient directement les globales |
|
| 63 | - // on les sauve avant l'appel, et on les retablit apres ! |
|
| 64 | - $save = [ |
|
| 65 | - isset($GLOBALS['fond']) ? $GLOBALS['fond'] : null, |
|
| 66 | - isset($GLOBALS['contexte']) ? $GLOBALS['contexte'] : null, |
|
| 67 | - isset($_SERVER['REDIRECT_url_propre']) ? $_SERVER['REDIRECT_url_propre'] : null, |
|
| 68 | - isset($_ENV['url_propre']) ? $_ENV['url_propre'] : null, |
|
| 69 | - $GLOBALS['profondeur_url'] |
|
| 70 | - ]; |
|
| 62 | + // les anciennes fonctions modifient directement les globales |
|
| 63 | + // on les sauve avant l'appel, et on les retablit apres ! |
|
| 64 | + $save = [ |
|
| 65 | + isset($GLOBALS['fond']) ? $GLOBALS['fond'] : null, |
|
| 66 | + isset($GLOBALS['contexte']) ? $GLOBALS['contexte'] : null, |
|
| 67 | + isset($_SERVER['REDIRECT_url_propre']) ? $_SERVER['REDIRECT_url_propre'] : null, |
|
| 68 | + isset($_ENV['url_propre']) ? $_ENV['url_propre'] : null, |
|
| 69 | + $GLOBALS['profondeur_url'] |
|
| 70 | + ]; |
|
| 71 | 71 | |
| 72 | - if (is_null($current_base)) { |
|
| 73 | - include_spip('inc/filtres_mini'); |
|
| 74 | - // le decodage des urls se fait toujours par rapport au site public |
|
| 75 | - $current_base = url_absolue(_DIR_RACINE ? _DIR_RACINE : './'); |
|
| 76 | - } |
|
| 77 | - if (strncmp($url, $current_base, strlen($current_base)) == 0) { |
|
| 78 | - $url = substr($url, strlen($current_base)); |
|
| 79 | - } |
|
| 72 | + if (is_null($current_base)) { |
|
| 73 | + include_spip('inc/filtres_mini'); |
|
| 74 | + // le decodage des urls se fait toujours par rapport au site public |
|
| 75 | + $current_base = url_absolue(_DIR_RACINE ? _DIR_RACINE : './'); |
|
| 76 | + } |
|
| 77 | + if (strncmp($url, $current_base, strlen($current_base)) == 0) { |
|
| 78 | + $url = substr($url, strlen($current_base)); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // si on est en train d'assembler la page principale, |
|
| 82 | - // recuperer l'url depuis les globales url propres si fournies |
|
| 83 | - // sinon extraire la bonne portion d'url |
|
| 84 | - if ($assembler) { |
|
| 85 | - if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 86 | - $url = $_SERVER['REDIRECT_url_propre']; |
|
| 87 | - } elseif (isset($_ENV['url_propre'])) { |
|
| 88 | - $url = $_ENV['url_propre']; |
|
| 89 | - } else { |
|
| 90 | - $qs = explode('?', $url); |
|
| 91 | - // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 92 | - $url = ltrim($qs[0], '/'); |
|
| 93 | - $url = explode('/', $url); |
|
| 94 | - while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 95 | - array_shift($url); |
|
| 96 | - } |
|
| 97 | - $qs[0] = implode('/', $url); |
|
| 98 | - $url = implode('?', $qs); |
|
| 99 | - } |
|
| 100 | - } |
|
| 81 | + // si on est en train d'assembler la page principale, |
|
| 82 | + // recuperer l'url depuis les globales url propres si fournies |
|
| 83 | + // sinon extraire la bonne portion d'url |
|
| 84 | + if ($assembler) { |
|
| 85 | + if (isset($_SERVER['REDIRECT_url_propre'])) { |
|
| 86 | + $url = $_SERVER['REDIRECT_url_propre']; |
|
| 87 | + } elseif (isset($_ENV['url_propre'])) { |
|
| 88 | + $url = $_ENV['url_propre']; |
|
| 89 | + } else { |
|
| 90 | + $qs = explode('?', $url); |
|
| 91 | + // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee |
|
| 92 | + $url = ltrim($qs[0], '/'); |
|
| 93 | + $url = explode('/', $url); |
|
| 94 | + while (count($url) > $GLOBALS['profondeur_url'] + 1) { |
|
| 95 | + array_shift($url); |
|
| 96 | + } |
|
| 97 | + $qs[0] = implode('/', $url); |
|
| 98 | + $url = implode('?', $qs); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - unset($_SERVER['REDIRECT_url_propre']); |
|
| 103 | - unset($_ENV['url_propre']); |
|
| 104 | - include_spip('inc/filtres_mini'); |
|
| 105 | - if (strpos($url, '://') === false) { |
|
| 106 | - $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 107 | - } else { |
|
| 108 | - $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 109 | - } |
|
| 102 | + unset($_SERVER['REDIRECT_url_propre']); |
|
| 103 | + unset($_ENV['url_propre']); |
|
| 104 | + include_spip('inc/filtres_mini'); |
|
| 105 | + if (strpos($url, '://') === false) { |
|
| 106 | + $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/'); |
|
| 107 | + } else { |
|
| 108 | + $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/')); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - $url_redirect = ''; |
|
| 112 | - $renommer = generer_url_entite('', '', '', '', true); |
|
| 113 | - if (!$renommer and !function_exists('recuperer_parametres_url')) { |
|
| 114 | - $renommer = charger_fonction('page', 'urls'); |
|
| 115 | - } // fallback pour decoder l'url |
|
| 116 | - if ($renommer) { |
|
| 117 | - $a = $renommer($url, $fond, $contexte); |
|
| 118 | - if (is_array($a)) { |
|
| 119 | - list($ncontexte, $type, $url_redirect, $nfond) = array_pad($a, 4, null); |
|
| 120 | - if ($url_redirect == $url) { |
|
| 121 | - $url_redirect = ''; |
|
| 122 | - } // securite pour eviter une redirection infinie |
|
| 123 | - if ($assembler and strlen($url_redirect)) { |
|
| 124 | - spip_log("Redirige $url vers $url_redirect"); |
|
| 125 | - include_spip('inc/headers'); |
|
| 126 | - redirige_par_entete($url_redirect, '', 301); |
|
| 127 | - } |
|
| 128 | - if (isset($nfond)) { |
|
| 129 | - $fond = $nfond; |
|
| 130 | - } else { |
|
| 131 | - if ( |
|
| 132 | - $fond == '' |
|
| 133 | - or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 134 | - ) { |
|
| 135 | - $fond = $type; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - if (isset($ncontexte)) { |
|
| 139 | - $contexte = $ncontexte; |
|
| 140 | - } |
|
| 141 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 142 | - $contexte['type'] = $type; |
|
| 143 | - } |
|
| 144 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 145 | - $contexte['type-page'] = $type; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - } // compatibilite <= 1.9.2 |
|
| 149 | - elseif (function_exists('recuperer_parametres_url')) { |
|
| 150 | - $GLOBALS['fond'] = $fond; |
|
| 151 | - $GLOBALS['contexte'] = $contexte; |
|
| 152 | - recuperer_parametres_url($fond, nettoyer_uri()); |
|
| 153 | - // fond est en principe modifiee directement |
|
| 154 | - $contexte = $GLOBALS['contexte']; |
|
| 155 | - } |
|
| 111 | + $url_redirect = ''; |
|
| 112 | + $renommer = generer_url_entite('', '', '', '', true); |
|
| 113 | + if (!$renommer and !function_exists('recuperer_parametres_url')) { |
|
| 114 | + $renommer = charger_fonction('page', 'urls'); |
|
| 115 | + } // fallback pour decoder l'url |
|
| 116 | + if ($renommer) { |
|
| 117 | + $a = $renommer($url, $fond, $contexte); |
|
| 118 | + if (is_array($a)) { |
|
| 119 | + list($ncontexte, $type, $url_redirect, $nfond) = array_pad($a, 4, null); |
|
| 120 | + if ($url_redirect == $url) { |
|
| 121 | + $url_redirect = ''; |
|
| 122 | + } // securite pour eviter une redirection infinie |
|
| 123 | + if ($assembler and strlen($url_redirect)) { |
|
| 124 | + spip_log("Redirige $url vers $url_redirect"); |
|
| 125 | + include_spip('inc/headers'); |
|
| 126 | + redirige_par_entete($url_redirect, '', 301); |
|
| 127 | + } |
|
| 128 | + if (isset($nfond)) { |
|
| 129 | + $fond = $nfond; |
|
| 130 | + } else { |
|
| 131 | + if ( |
|
| 132 | + $fond == '' |
|
| 133 | + or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */ |
|
| 134 | + ) { |
|
| 135 | + $fond = $type; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + if (isset($ncontexte)) { |
|
| 139 | + $contexte = $ncontexte; |
|
| 140 | + } |
|
| 141 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 142 | + $contexte['type'] = $type; |
|
| 143 | + } |
|
| 144 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 145 | + $contexte['type-page'] = $type; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + } // compatibilite <= 1.9.2 |
|
| 149 | + elseif (function_exists('recuperer_parametres_url')) { |
|
| 150 | + $GLOBALS['fond'] = $fond; |
|
| 151 | + $GLOBALS['contexte'] = $contexte; |
|
| 152 | + recuperer_parametres_url($fond, nettoyer_uri()); |
|
| 153 | + // fond est en principe modifiee directement |
|
| 154 | + $contexte = $GLOBALS['contexte']; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - // retablir les globales |
|
| 158 | - list($GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']) = $save; |
|
| 157 | + // retablir les globales |
|
| 158 | + list($GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']) = $save; |
|
| 159 | 159 | |
| 160 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 161 | - // d'inversion url => objet |
|
| 162 | - // maintenir pour compat ? |
|
| 163 | - #if ($assembler) { |
|
| 164 | - # unset($_SERVER['REDIRECT_url_propre']); |
|
| 165 | - # unset($_ENV['url_propre']); |
|
| 166 | - #} |
|
| 160 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 161 | + // d'inversion url => objet |
|
| 162 | + // maintenir pour compat ? |
|
| 163 | + #if ($assembler) { |
|
| 164 | + # unset($_SERVER['REDIRECT_url_propre']); |
|
| 165 | + # unset($_ENV['url_propre']); |
|
| 166 | + #} |
|
| 167 | 167 | |
| 168 | - return [$fond, $contexte, $url_redirect]; |
|
| 168 | + return [$fond, $contexte, $url_redirect]; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | |
@@ -179,24 +179,24 @@ discard block |
||
| 179 | 179 | * @return string|array |
| 180 | 180 | */ |
| 181 | 181 | function urls_liste_objets($preg = true) { |
| 182 | - static $url_objets = null; |
|
| 183 | - if (is_null($url_objets)) { |
|
| 184 | - $url_objets = []; |
|
| 185 | - // recuperer les tables_objets_sql declarees |
|
| 186 | - $tables_objets = lister_tables_objets_sql(); |
|
| 187 | - foreach ($tables_objets as $t => $infos) { |
|
| 188 | - if ($infos['page']) { |
|
| 189 | - $url_objets[] = $infos['type']; |
|
| 190 | - $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 194 | - } |
|
| 195 | - if (!$preg) { |
|
| 196 | - return $url_objets; |
|
| 197 | - } |
|
| 182 | + static $url_objets = null; |
|
| 183 | + if (is_null($url_objets)) { |
|
| 184 | + $url_objets = []; |
|
| 185 | + // recuperer les tables_objets_sql declarees |
|
| 186 | + $tables_objets = lister_tables_objets_sql(); |
|
| 187 | + foreach ($tables_objets as $t => $infos) { |
|
| 188 | + if ($infos['page']) { |
|
| 189 | + $url_objets[] = $infos['type']; |
|
| 190 | + $url_objets = array_merge($url_objets, $infos['type_surnoms']); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + $url_objets = pipeline('declarer_url_objets', $url_objets); |
|
| 194 | + } |
|
| 195 | + if (!$preg) { |
|
| 196 | + return $url_objets; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return implode('|', array_map('preg_quote', $url_objets)); |
|
| 199 | + return implode('|', array_map('preg_quote', $url_objets)); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -210,26 +210,26 @@ discard block |
||
| 210 | 210 | * @return array |
| 211 | 211 | */ |
| 212 | 212 | function nettoyer_url_page($url, $contexte = []) { |
| 213 | - $url_objets = urls_liste_objets(); |
|
| 214 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 215 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 216 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 213 | + $url_objets = urls_liste_objets(); |
|
| 214 | + $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 215 | + $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 216 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 217 | 217 | |
| 218 | - if ( |
|
| 219 | - preg_match($raccourci_url_page_html, $url, $regs) |
|
| 220 | - or preg_match($raccourci_url_page_id, $url, $regs) |
|
| 221 | - or preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 222 | - ) { |
|
| 223 | - $regs = array_pad($regs, 4, null); |
|
| 224 | - $type = objet_type($regs[1]); |
|
| 225 | - $_id = id_table_objet($type); |
|
| 226 | - $contexte[$_id] = $regs[2]; |
|
| 227 | - $suite = $regs[3]; |
|
| 218 | + if ( |
|
| 219 | + preg_match($raccourci_url_page_html, $url, $regs) |
|
| 220 | + or preg_match($raccourci_url_page_id, $url, $regs) |
|
| 221 | + or preg_match($raccourci_url_page_spip, $url, $regs) |
|
| 222 | + ) { |
|
| 223 | + $regs = array_pad($regs, 4, null); |
|
| 224 | + $type = objet_type($regs[1]); |
|
| 225 | + $_id = id_table_objet($type); |
|
| 226 | + $contexte[$_id] = $regs[2]; |
|
| 227 | + $suite = $regs[3]; |
|
| 228 | 228 | |
| 229 | - return [$contexte, $type, null, $type, $suite]; |
|
| 230 | - } |
|
| 229 | + return [$contexte, $type, null, $type, $suite]; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - return []; |
|
| 232 | + return []; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -248,33 +248,33 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | */ |
| 250 | 250 | function generer_url_ecrire_objet($objet, $id, $args = '', $ancre = '', $public = null, $connect = '') { |
| 251 | - static $furls = []; |
|
| 252 | - if (!isset($furls[$objet])) { |
|
| 253 | - if ( |
|
| 254 | - function_exists($f = 'generer_url_ecrire_' . $objet) |
|
| 255 | - // ou definie par un plugin |
|
| 256 | - or $f = charger_fonction($f, 'urls', true) |
|
| 257 | - ) { |
|
| 258 | - $furls[$objet] = $f; |
|
| 259 | - } else { |
|
| 260 | - $furls[$objet] = ''; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - if ($furls[$objet]) { |
|
| 264 | - return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 265 | - } |
|
| 266 | - // si pas de flag public fourni |
|
| 267 | - // le calculer en fonction de la declaration de statut |
|
| 268 | - if (is_null($public) and !$connect) { |
|
| 269 | - $public = objet_test_si_publie($objet, $id, $connect); |
|
| 270 | - } |
|
| 271 | - if ($public or $connect) { |
|
| 272 | - return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect); |
|
| 273 | - } |
|
| 274 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 275 | - if (!function_exists('objet_info')) { |
|
| 276 | - include_spip('inc/filtres'); |
|
| 277 | - } |
|
| 251 | + static $furls = []; |
|
| 252 | + if (!isset($furls[$objet])) { |
|
| 253 | + if ( |
|
| 254 | + function_exists($f = 'generer_url_ecrire_' . $objet) |
|
| 255 | + // ou definie par un plugin |
|
| 256 | + or $f = charger_fonction($f, 'urls', true) |
|
| 257 | + ) { |
|
| 258 | + $furls[$objet] = $f; |
|
| 259 | + } else { |
|
| 260 | + $furls[$objet] = ''; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + if ($furls[$objet]) { |
|
| 264 | + return $furls[$objet]($id, $args, $ancre, $public, $connect); |
|
| 265 | + } |
|
| 266 | + // si pas de flag public fourni |
|
| 267 | + // le calculer en fonction de la declaration de statut |
|
| 268 | + if (is_null($public) and !$connect) { |
|
| 269 | + $public = objet_test_si_publie($objet, $id, $connect); |
|
| 270 | + } |
|
| 271 | + if ($public or $connect) { |
|
| 272 | + return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect); |
|
| 273 | + } |
|
| 274 | + $a = id_table_objet($objet) . '=' . intval($id); |
|
| 275 | + if (!function_exists('objet_info')) { |
|
| 276 | + include_spip('inc/filtres'); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 279 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 280 | 280 | } |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | function nettoyer_url_page($url, $contexte = []) { |
| 213 | 213 | $url_objets = urls_liste_objets(); |
| 214 | - $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 215 | - $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 216 | - $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,'; |
|
| 214 | + $raccourci_url_page_html = ',^(?:[^?]*/)?('.$url_objets.')([0-9]+)(?:\.html)?([?&].*)?$,'; |
|
| 215 | + $raccourci_url_page_id = ',^(?:[^?]*/)?('.$url_objets.')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,'; |
|
| 216 | + $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('.$url_objets.')([0-9]+)=?(&.*)?$,'; |
|
| 217 | 217 | |
| 218 | 218 | if ( |
| 219 | 219 | preg_match($raccourci_url_page_html, $url, $regs) |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | static $furls = []; |
| 252 | 252 | if (!isset($furls[$objet])) { |
| 253 | 253 | if ( |
| 254 | - function_exists($f = 'generer_url_ecrire_' . $objet) |
|
| 254 | + function_exists($f = 'generer_url_ecrire_'.$objet) |
|
| 255 | 255 | // ou definie par un plugin |
| 256 | 256 | or $f = charger_fonction($f, 'urls', true) |
| 257 | 257 | ) { |
@@ -271,10 +271,10 @@ discard block |
||
| 271 | 271 | if ($public or $connect) { |
| 272 | 272 | return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect); |
| 273 | 273 | } |
| 274 | - $a = id_table_objet($objet) . '=' . intval($id); |
|
| 274 | + $a = id_table_objet($objet).'='.intval($id); |
|
| 275 | 275 | if (!function_exists('objet_info')) { |
| 276 | 276 | include_spip('inc/filtres'); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : ''); |
|
| 279 | + return generer_url_ecrire(objet_info($objet, 'url_voir'), $a.($args ? "&$args" : '')).($ancre ? "#$ancre" : ''); |
|
| 280 | 280 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | // |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // |
@@ -22,54 +22,54 @@ discard block |
||
| 22 | 22 | // https://code.spip.net/@image_math |
| 23 | 23 | function produire_image_math($tex) { |
| 24 | 24 | |
| 25 | - switch ($GLOBALS['traiter_math']) { |
|
| 26 | - // Attention: mathml desactiv'e pour l'instant |
|
| 27 | - case 'mathml': |
|
| 28 | - $ext = '.xhtml'; |
|
| 29 | - $server = $GLOBALS['mathml_server']; |
|
| 30 | - break; |
|
| 31 | - case 'tex': |
|
| 32 | - $ext = '.png'; |
|
| 33 | - $server = $GLOBALS['tex_server']; |
|
| 34 | - break; |
|
| 35 | - default: |
|
| 36 | - return $tex; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | - } |
|
| 43 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - if (!@file_exists($fichier)) { |
|
| 47 | - // Aller chercher l'image sur le serveur |
|
| 48 | - if ($server) { |
|
| 49 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 50 | - include_spip('inc/distant'); |
|
| 51 | - recuperer_url($url, ['file' => $fichier]); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - // Composer la reponse selon presence ou non de l'image |
|
| 57 | - $tex = entites_html($tex); |
|
| 58 | - if (@file_exists($fichier)) { |
|
| 59 | - // MathML |
|
| 60 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 61 | - return implode('', file($fichier)); |
|
| 62 | - } // TeX |
|
| 63 | - else { |
|
| 64 | - list(, , , $size) = @spip_getimagesize($fichier); |
|
| 65 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 66 | - |
|
| 67 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 68 | - } |
|
| 69 | - } else // pas de fichier |
|
| 70 | - { |
|
| 71 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 72 | - } |
|
| 25 | + switch ($GLOBALS['traiter_math']) { |
|
| 26 | + // Attention: mathml desactiv'e pour l'instant |
|
| 27 | + case 'mathml': |
|
| 28 | + $ext = '.xhtml'; |
|
| 29 | + $server = $GLOBALS['mathml_server']; |
|
| 30 | + break; |
|
| 31 | + case 'tex': |
|
| 32 | + $ext = '.png'; |
|
| 33 | + $server = $GLOBALS['tex_server']; |
|
| 34 | + break; |
|
| 35 | + default: |
|
| 36 | + return $tex; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | + } |
|
| 43 | + $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + if (!@file_exists($fichier)) { |
|
| 47 | + // Aller chercher l'image sur le serveur |
|
| 48 | + if ($server) { |
|
| 49 | + spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 50 | + include_spip('inc/distant'); |
|
| 51 | + recuperer_url($url, ['file' => $fichier]); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + // Composer la reponse selon presence ou non de l'image |
|
| 57 | + $tex = entites_html($tex); |
|
| 58 | + if (@file_exists($fichier)) { |
|
| 59 | + // MathML |
|
| 60 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 61 | + return implode('', file($fichier)); |
|
| 62 | + } // TeX |
|
| 63 | + else { |
|
| 64 | + list(, , , $size) = @spip_getimagesize($fichier); |
|
| 65 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 66 | + |
|
| 67 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 68 | + } |
|
| 69 | + } else // pas de fichier |
|
| 70 | + { |
|
| 71 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -104,52 +104,52 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 106 | 106 | |
| 107 | - $texte_a_voir = $letexte; |
|
| 108 | - while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 109 | - if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 110 | - $fin = strlen($texte_a_voir); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 114 | - $texte_milieu = substr( |
|
| 115 | - $texte_a_voir, |
|
| 116 | - $debut + strlen('<math>'), |
|
| 117 | - $fin - $debut - strlen('<math>') |
|
| 118 | - ); |
|
| 119 | - $texte_fin = substr( |
|
| 120 | - $texte_a_voir, |
|
| 121 | - $fin + strlen('</math>'), |
|
| 122 | - strlen($texte_a_voir) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 126 | - while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 127 | - $expression = $regs[1]; |
|
| 128 | - if ($defaire_amp) { |
|
| 129 | - $expression = str_replace('&', '&', $expression); |
|
| 130 | - } |
|
| 131 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 132 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 133 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 134 | - . code_echappement($echap, $source) |
|
| 135 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Les simples $x^2$ en mode 'span' |
|
| 139 | - while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 140 | - $expression = $regs[1]; |
|
| 141 | - if ($defaire_amp) { |
|
| 142 | - $expression = str_replace('&', '&', $expression); |
|
| 143 | - } |
|
| 144 | - $echap = produire_image_math($expression); |
|
| 145 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 146 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 147 | - . code_echappement($echap, $source) |
|
| 148 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $texte_a_voir; |
|
| 107 | + $texte_a_voir = $letexte; |
|
| 108 | + while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 109 | + if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 110 | + $fin = strlen($texte_a_voir); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 114 | + $texte_milieu = substr( |
|
| 115 | + $texte_a_voir, |
|
| 116 | + $debut + strlen('<math>'), |
|
| 117 | + $fin - $debut - strlen('<math>') |
|
| 118 | + ); |
|
| 119 | + $texte_fin = substr( |
|
| 120 | + $texte_a_voir, |
|
| 121 | + $fin + strlen('</math>'), |
|
| 122 | + strlen($texte_a_voir) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 126 | + while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 127 | + $expression = $regs[1]; |
|
| 128 | + if ($defaire_amp) { |
|
| 129 | + $expression = str_replace('&', '&', $expression); |
|
| 130 | + } |
|
| 131 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 132 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 133 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 134 | + . code_echappement($echap, $source) |
|
| 135 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Les simples $x^2$ en mode 'span' |
|
| 139 | + while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 140 | + $expression = $regs[1]; |
|
| 141 | + if ($defaire_amp) { |
|
| 142 | + $expression = str_replace('&', '&', $expression); |
|
| 143 | + } |
|
| 144 | + $echap = produire_image_math($expression); |
|
| 145 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 146 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 147 | + . code_echappement($echap, $source) |
|
| 148 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $texte_a_voir; |
|
| 155 | 155 | } |
@@ -37,16 +37,16 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 40 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 40 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 41 | 41 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 42 | 42 | } |
| 43 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 43 | + $fichier = $dir_tex.md5(trim($tex)).$ext; |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | if (!@file_exists($fichier)) { |
| 47 | 47 | // Aller chercher l'image sur le serveur |
| 48 | 48 | if ($server) { |
| 49 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 49 | + spip_log($url = $server.'?'.rawurlencode($tex)); |
|
| 50 | 50 | include_spip('inc/distant'); |
| 51 | 51 | recuperer_url($url, ['file' => $fichier]); |
| 52 | 52 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | return implode('', file($fichier)); |
| 62 | 62 | } // TeX |
| 63 | 63 | else { |
| 64 | - list(, , , $size) = @spip_getimagesize($fichier); |
|
| 64 | + list(,,, $size) = @spip_getimagesize($fichier); |
|
| 65 | 65 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 66 | 66 | |
| 67 | 67 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | if ($defaire_amp) { |
| 129 | 129 | $expression = str_replace('&', '&', $expression); |
| 130 | 130 | } |
| 131 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 131 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n"; |
|
| 132 | 132 | $pos = strpos($texte_milieu, $regs[0]); |
| 133 | 133 | $texte_milieu = substr($texte_milieu, 0, $pos) |
| 134 | 134 | . code_echappement($echap, $source) |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | . substr($texte_milieu, $pos + strlen($regs[0])); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 151 | + $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return $texte_a_voir; |