Rev 1086 | Rev 1125 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1086 | Rev 1116 | ||
---|---|---|---|
Line 26... | Line 26... | ||
26 | class OIDplusPageAdminOIDInfoExport extends OIDplusPagePluginAdmin { |
26 | class OIDplusPageAdminOIDInfoExport extends OIDplusPagePluginAdmin { |
27 | 27 | ||
28 | /*private*/ const QUERY_LIST_OIDINFO_OIDS_V1 = '1.3.6.1.4.1.37476.2.5.2.1.5.1'; |
28 | /*private*/ const QUERY_LIST_OIDINFO_OIDS_V1 = '1.3.6.1.4.1.37476.2.5.2.1.5.1'; |
29 | /*private*/ const QUERY_GET_OIDINFO_DATA_V1 = '1.3.6.1.4.1.37476.2.5.2.1.6.1'; |
29 | /*private*/ const QUERY_GET_OIDINFO_DATA_V1 = '1.3.6.1.4.1.37476.2.5.2.1.6.1'; |
30 | 30 | ||
- | 31 | /** |
|
- | 32 | * @param string $actionID |
|
- | 33 | * @param array $params |
|
- | 34 | * @return array|int[] |
|
- | 35 | * @throws OIDplusException |
|
- | 36 | */ |
|
31 | public function action($actionID, $params) { |
37 | public function action(string $actionID, array $params): array { |
32 | 38 | ||
33 | if ($actionID == 'import_xml_file') { |
39 | if ($actionID == 'import_xml_file') { |
34 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
40 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
35 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
41 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
36 | } |
42 | } |
Line 148... | Line 154... | ||
148 | return array("status" => -1, "error" => _L('Imported %1, but expected to import 1',$count_imported_oids)); |
154 | return array("status" => -1, "error" => _L('Imported %1, but expected to import 1',$count_imported_oids)); |
149 | } else { |
155 | } else { |
150 | return array("status" => 0); |
156 | return array("status" => 0); |
151 | } |
157 | } |
152 | } else { |
158 | } else { |
153 | throw new OIDplusException(_L('Unknown action ID')); |
159 | return parent::action($actionID, $params); |
154 | } |
160 | } |
155 | } |
161 | } |
156 | 162 | ||
- | 163 | /** |
|
- | 164 | * @param bool $html |
|
- | 165 | * @return void |
|
- | 166 | */ |
|
157 | public function init($html=true) { |
167 | public function init(bool $html=true) { |
158 | // Nothing |
168 | // Nothing |
159 | } |
169 | } |
160 | 170 | ||
- | 171 | /** |
|
- | 172 | * @param string $id |
|
- | 173 | * @param array $out |
|
- | 174 | * @param bool $handled |
|
- | 175 | * @return void |
|
- | 176 | * @throws OIDplusException |
|
- | 177 | */ |
|
161 | public function gui($id, &$out, &$handled) { |
178 | public function gui(string $id, array &$out, bool &$handled) { |
162 | $ary = explode('$', $id); |
179 | $ary = explode('$', $id); |
163 | if (isset($ary[1])) { |
180 | if (isset($ary[1])) { |
164 | $id = $ary[0]; |
181 | $id = $ary[0]; |
165 | $tab = $ary[1]; |
182 | $tab = $ary[1]; |
166 | } else { |
183 | } else { |
Line 638... | Line 655... | ||
638 | 655 | ||
639 | $out['text'] .= '</div></div><script>$("#dataTransferArea")[0].style.visibility = "visible";</script>'; |
656 | $out['text'] .= '</div></div><script>$("#dataTransferArea")[0].style.visibility = "visible";</script>'; |
640 | } |
657 | } |
641 | } |
658 | } |
642 | 659 | ||
- | 660 | /** |
|
- | 661 | * @param array $json |
|
- | 662 | * @param string|null $ra_email |
|
- | 663 | * @param bool $nonjs |
|
- | 664 | * @param string $req_goto |
|
- | 665 | * @return bool |
|
- | 666 | * @throws OIDplusException |
|
- | 667 | */ |
|
643 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
668 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
644 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
669 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
645 | 670 | ||
646 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
671 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
647 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
672 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
648 | } else { |
673 | } else { |
Line 656... | Line 681... | ||
656 | ); |
681 | ); |
657 | 682 | ||
658 | return true; |
683 | return true; |
659 | } |
684 | } |
660 | 685 | ||
- | 686 | /** |
|
- | 687 | * @param string $request |
|
- | 688 | * @return array|false |
|
- | 689 | */ |
|
661 | public function tree_search($request) { |
690 | public function tree_search(string $request) { |
662 | return false; |
691 | return false; |
663 | } |
692 | } |
664 | 693 | ||
- | 694 | /** |
|
- | 695 | * @param $only_non_existing |
|
- | 696 | * @return string[] |
|
- | 697 | * @throws OIDplusException |
|
- | 698 | * @throws \OIDInfoException |
|
- | 699 | */ |
|
665 | public static function outputXML($only_non_existing) { |
700 | public static function outputXML($only_non_existing) { |
666 | $out_type = null; |
701 | $out_type = null; |
667 | $out_content = ''; |
702 | $out_content = ''; |
668 | 703 | ||
669 | // This file contains class \OIDInfoAPI. |
704 | // This file contains class \OIDInfoAPI. |
Line 860... | Line 895... | ||
860 | 895 | ||
861 | $out_type = 'text/xml'; |
896 | $out_type = 'text/xml'; |
862 | return array($out_content, $out_type); |
897 | return array($out_content, $out_type); |
863 | } |
898 | } |
864 | 899 | ||
- | 900 | /** |
|
- | 901 | * @param $str |
|
- | 902 | * @return mixed|string |
|
- | 903 | */ |
|
865 | private static function _formatdate($str) { |
904 | private static function _formatdate($str) { |
866 | $str = explode(' ',$str)[0]; |
905 | $str = explode(' ',$str)[0]; |
867 | if ($str == '0000-00-00') $str = ''; |
906 | if ($str == '0000-00-00') $str = ''; |
868 | return $str; |
907 | return $str; |
869 | } |
908 | } |
870 | 909 | ||
- | 910 | /** |
|
- | 911 | * @param $str |
|
- | 912 | * @return array|string|string[]|null |
|
- | 913 | * @throws OIDplusException |
|
- | 914 | */ |
|
871 | private static function repair_relative_links($str) { |
915 | private static function repair_relative_links($str) { |
872 | $str = preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) { |
916 | $str = preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) { |
873 | $url = $treffer[3]; |
917 | $url = $treffer[3]; |
874 | if ((stripos($url,'http:') !== 0) && (stripos($url,'https:') !== 0) && (stripos($url,'ftp:') !== 0)) { |
918 | if ((stripos($url,'http:') !== 0) && (stripos($url,'https:') !== 0) && (stripos($url,'ftp:') !== 0)) { |
875 | if (stripos($url,'www.') === 0) { |
919 | if (stripos($url,'www.') === 0) { |
Line 881... | Line 925... | ||
881 | return $treffer[1].$url.$treffer[4]; |
925 | return $treffer[1].$url.$treffer[4]; |
882 | }, $str); |
926 | }, $str); |
883 | return $str; |
927 | return $str; |
884 | } |
928 | } |
885 | 929 | ||
- | 930 | /** |
|
- | 931 | * @param $address |
|
- | 932 | * @return array|string[] |
|
- | 933 | */ |
|
886 | private static function split_address_country($address) { |
934 | private static function split_address_country($address) { |
887 | global $oidinfo_countries; |
935 | global $oidinfo_countries; |
888 | $ary = explode("\n", $address); |
936 | $ary = explode("\n", $address); |
889 | $last_line = array_pop($ary); |
937 | $last_line = array_pop($ary); |
890 | $rest = implode("\n", $ary); |
938 | $rest = implode("\n", $ary); |
Line 893... | Line 941... | ||
893 | } else { |
941 | } else { |
894 | return array($rest."\n".$last_line, ''); |
942 | return array($rest."\n".$last_line, ''); |
895 | } |
943 | } |
896 | } |
944 | } |
897 | 945 | ||
- | 946 | /** |
|
- | 947 | * @param $name |
|
- | 948 | * @return array |
|
- | 949 | */ |
|
898 | private static function split_name($name) { |
950 | private static function split_name($name) { |
899 | // uses regex that accepts any word character or hyphen in last name |
951 | // uses regex that accepts any word character or hyphen in last name |
900 | // https://stackoverflow.com/questions/13637145/split-text-string-into-first-and-last-name-in-php |
952 | // https://stackoverflow.com/questions/13637145/split-text-string-into-first-and-last-name-in-php |
901 | $name = trim($name); |
953 | $name = trim($name); |
902 | $last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name); |
954 | $last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name); |
Line 906... | Line 958... | ||
906 | 958 | ||
907 | /*protected*/ const ORPHAN_IGNORE = 0; |
959 | /*protected*/ const ORPHAN_IGNORE = 0; |
908 | /*protected*/ const ORPHAN_AUTO_DEORPHAN = 1; |
960 | /*protected*/ const ORPHAN_AUTO_DEORPHAN = 1; |
909 | /*protected*/ const ORPHAN_DISALLOW_ORPHANS = 2; |
961 | /*protected*/ const ORPHAN_DISALLOW_ORPHANS = 2; |
910 | 962 | ||
- | 963 | /** |
|
- | 964 | * @param $xml_contents |
|
- | 965 | * @param $errors |
|
- | 966 | * @param $replaceExistingOIDs |
|
- | 967 | * @param $orphan_mode |
|
- | 968 | * @return array|int[] |
|
- | 969 | * @throws OIDplusException |
|
- | 970 | */ |
|
911 | protected function oidinfoImportXML($xml_contents, &$errors, $replaceExistingOIDs=false, $orphan_mode=self::ORPHAN_AUTO_DEORPHAN) { |
971 | protected function oidinfoImportXML($xml_contents, &$errors, $replaceExistingOIDs=false, $orphan_mode=self::ORPHAN_AUTO_DEORPHAN) { |
912 | // TODO: Implement RA import (let the user decide) |
972 | // TODO: Implement RA import (let the user decide) |
913 | // TODO: Let the user decide about $replaceExistingOIDs |
973 | // TODO: Let the user decide about $replaceExistingOIDs |
914 | // TODO: Let the user decide if "created=now" should be set (this is good when the XML files is created by the user itself to do bulk-inserts) |
974 | // TODO: Let the user decide if "created=now" should be set (this is good when the XML files is created by the user itself to do bulk-inserts) |
915 | 975 | ||
Line 1079... | Line 1139... | ||
1079 | 1139 | ||
1080 | return array($count_imported_oids, $count_already_existing, $count_errors, $count_warnings); |
1140 | return array($count_imported_oids, $count_already_existing, $count_errors, $count_warnings); |
1081 | 1141 | ||
1082 | } |
1142 | } |
1083 | 1143 | ||
- | 1144 | /** |
|
- | 1145 | * @param string $id |
|
- | 1146 | * @return bool |
|
- | 1147 | */ |
|
1084 | public function implementsFeature($id) { |
1148 | public function implementsFeature(string $id): bool { |
1085 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications() |
1149 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications() |
1086 | return false; |
1150 | return false; |
1087 | } |
1151 | } |
1088 | 1152 | ||
- | 1153 | /** |
|
- | 1154 | * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8 |
|
- | 1155 | * @param $user |
|
- | 1156 | * @return array |
|
- | 1157 | * @throws OIDplusException |
|
- | 1158 | */ |
|
1089 | public function getNotifications($user=null): array { |
1159 | public function getNotifications($user=null): array { |
1090 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.8 |
- | |
1091 | $notifications = array(); |
1160 | $notifications = array(); |
1092 | if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) { |
1161 | if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) { |
1093 | if (!function_exists('curl_init')) { |
1162 | if (!function_exists('curl_init')) { |
1094 | $title = _L('OID-Info.com import/export'); |
1163 | $title = _L('OID-Info.com import/export'); |
1095 | $notifications[] = array('ERR', _L('OIDplus plugin "%1" is enabled, but the required PHP extension "%2" is not installed.', '<a '.OIDplus::gui()->link('oidplus:datatransfer').'>'.htmlentities($title).'</a>', 'php_curl')); |
1164 | $notifications[] = array('ERR', _L('OIDplus plugin "%1" is enabled, but the required PHP extension "%2" is not installed.', '<a '.OIDplus::gui()->link('oidplus:datatransfer').'>'.htmlentities($title).'</a>', 'php_curl')); |