Subversion Repositories oidinfo_api

Rev

Rev 21 | Rev 26 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 24
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OID-Info.com API for PHP
4
 * OID-Info.com API for PHP
5
 * Copyright 2019-2021 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019-2021 Daniel Marschall, ViaThinkSoft
6
 * Version 2021-06-19
6
 * Version 2021-11-24
7
 *
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
10
 * You may obtain a copy of the License at
11
 *
11
 *
Line 177... Line 177...
177
 
177
 
178
                return true;
178
                return true;
179
        }
179
        }
180
 
180
 
181
        public function softCorrectEMail($email, $params) {
181
        public function softCorrectEMail($email, $params) {
-
 
182
                $params = $this->init_params($params);
-
 
183
 
182
                $email = str_replace(' ', '', $email);
184
                $email = str_replace(' ', '', $email);
183
                $email = str_replace('&', '@', $email);
185
                $email = str_replace('&', '@', $email);
184
                $email = str_replace('(at)', '@', $email);
186
                $email = str_replace('(at)', '@', $email);
185
                $email = str_replace('[at]', '@', $email);
187
                $email = str_replace('[at]', '@', $email);
186
                $email = str_replace('(dot)', '.', $email);
188
                $email = str_replace('(dot)', '.', $email);
Line 193... Line 195...
193
 
195
 
194
                return $email;
196
                return $email;
195
        }
197
        }
196
 
198
 
197
        public function softCorrectPhone($phone, $params) {
199
        public function softCorrectPhone($phone, $params) {
-
 
200
                $params = $this->init_params($params);
-
 
201
 
198
                // TODO: if no "+", add "+1" , but only if address is in USA
202
                // TODO: if no "+", add "+1" , but only if address is in USA
199
                // TODO: or use param to fixate country if it is not known
203
                // TODO: or use param to fixate country if it is not known
200
                /*
204
                /*
201
                NOTE: with german phone numbers, this will cause trouble, even if we assume "+49"
205
                NOTE: with german phone numbers, this will cause trouble, even if we assume "+49"
202
                        06223 / 1234
206
                        06223 / 1234
Line 256... Line 260...
256
        const OIDINFO_CORRECT_DESC_OPTIONAL_ENDING_DOT = 0;
260
        const OIDINFO_CORRECT_DESC_OPTIONAL_ENDING_DOT = 0;
257
        const OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT = 1;
261
        const OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT = 1;
258
        const OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT = 2;
262
        const OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT = 2;
259
 
263
 
260
        public function correctDesc($desc, $params, $ending_dot_policy=self::OIDINFO_CORRECT_DESC_OPTIONAL_ENDING_DOT, $enforce_xhtml_light=false) {
264
        public function correctDesc($desc, $params, $ending_dot_policy=self::OIDINFO_CORRECT_DESC_OPTIONAL_ENDING_DOT, $enforce_xhtml_light=false) {
-
 
265
                $params = $this->init_params($params);
-
 
266
 
261
                $desc = trim($desc);
267
                $desc = trim($desc);
262
 
268
 
263
                $desc = preg_replace('@<!\\[CDATA\\[(.+)\\]\\]>@ismU', '\\1', $desc);
269
                $desc = preg_replace('@<!\\[CDATA\\[(.+)\\]\\]>@ismU', '\\1', $desc);
264
 
270
 
265
                if (substr_count($desc, '>') != substr_count($desc, '<')) {
271
                if (substr_count($desc, '>') != substr_count($desc, '<')) {
Line 483... Line 489...
483
 
489
 
484
                $comment = 'test';
490
                $comment = 'test';
485
 
491
 
486
                echo $oa->createXMLEntry($oid, $elements, $params, $comment);
492
                echo $oa->createXMLEntry($oid, $elements, $params, $comment);
487
        */
493
        */
488
        public function createXMLEntry($oid, $elements, $params, $comment='') {
494
        private function init_params($params) {
489
                // Backward compatibility
495
                // Backward compatibility
490
                if (!isset($params['do_csv_check']))           $params['do_simpleping_check'] = true;
496
                if (!isset($params['do_csv_check']))           $params['do_simpleping_check'] = true;
491
 
497
 
492
                // Set default behavior
498
                // Set default behavior
493
                if (!isset($params['allow_html']))             $params['allow_html'] = false; // Allow HTML in <description> and <information>
499
                if (!isset($params['allow_html']))             $params['allow_html'] = false; // Allow HTML in <description> and <information>
Line 501... Line 507...
501
                if (!isset($params['always_output_comment']))  $params['always_output_comment'] = false; // Also output comment if there was an error (e.g. OID already existing)
507
                if (!isset($params['always_output_comment']))  $params['always_output_comment'] = false; // Also output comment if there was an error (e.g. OID already existing)
502
                if (!isset($params['creation_allowed_check'])) $params['creation_allowed_check'] = true;
508
                if (!isset($params['creation_allowed_check'])) $params['creation_allowed_check'] = true;
503
                if (!isset($params['tolerant_htmlentities']))  $params['tolerant_htmlentities'] = true;
509
                if (!isset($params['tolerant_htmlentities']))  $params['tolerant_htmlentities'] = true;
504
                if (!isset($params['ignore_xhtml_light']))     $params['ignore_xhtml_light'] = false;
510
                if (!isset($params['ignore_xhtml_light']))     $params['ignore_xhtml_light'] = false;
505
 
511
 
-
 
512
                return $params;
-
 
513
        }
-
 
514
        public function createXMLEntry($oid, $elements, $params, $comment='') {
-
 
515
                $params = $this->init_params($params);
-
 
516
 
506
                $out = '';
517
                $out = '';
507
                if (!empty($comment)) $out .= "\t\t<!-- $comment -->\n";
518
                if (!empty($comment)) $out .= "\t\t<!-- $comment -->\n";
508
 
519
 
509
                if ($params['always_output_comment']) {
520
                if ($params['always_output_comment']) {
510
                        $err = $out;
521
                        $err = $out;