1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: namespace MOC\Module\Network\ParcelTracker\Carrier;
39: use MOC\Api;
40: use MOC\Generic\Device\Module;
41: use MOC\Module\Network\ParcelTracker\Carrier;
42: use MOC\Module\Network\ParcelTracker\Parcel;
43:
44: 45: 46:
47: class TOFGermany extends Carrier implements Module {
48: 49: 50: 51: 52: 53:
54: public static function InterfaceInstance() {
55: return new TOFGermany();
56: }
57:
58: 59: 60: 61: 62: 63:
64: public static function InterfaceDepending() {
65: return Api::Core()->Depending();
66: }
67:
68: 69: 70: 71: 72: 73:
74: public static function InterfaceChangelog() {
75: return Api::Core()->Changelog()->Create( __CLASS__ );
76: }
77:
78: 79: 80: 81: 82:
83: function GetStatus( $TrackingNumber ) {
84:
85: $this->SetTarget( 'http://track.tof.de/trace/tracking.cgi?barcode='.$TrackingNumber );
86: $DOM = $this->GetData();
87:
88:
89: if( false !== strpos( $DOM->getElementsByTagName('title')->item(0)->nodeValue, 'Nutzungsbedingungen' ) ) {
90:
91: $SubmitForm = $DOM->getElementsByTagName('form')->item(0);
92:
93: $Target = '';
94:
95: $FormElementList = $SubmitForm->getElementsByTagName('input');
96: $FormElementListLength = $FormElementList->length;
97: for( $Run = 0; $Run < $FormElementListLength; $Run++ ) {
98: $FormElementAttributeList = $FormElementList->item( $Run )->attributes;
99: $FieldName = $FormElementAttributeList->getNamedItem('name')->nodeValue;
100: $FieldValue = $FormElementAttributeList->getNamedItem('value')->nodeValue;
101:
102: if( $FieldName == 'zustimmungNEIN' ) {
103: continue;
104: }
105:
106: if( !empty( $Target ) ) {
107: $Target .= '&';
108: }
109:
110: $Target .= $FieldName.'='.urlencode( $FieldValue );
111: }
112:
113: $this->SetTarget( 'http://track.tof.de/trace/tracking.cgi?'.$Target );
114: $DOM = $this->GetData();
115:
116:
117: $this->SetTarget( 'http://track.tof.de/trace/tracking.cgi?barcode='.$TrackingNumber );
118: }
119:
120:
121: $TrackingMessage = '';
122: $TrackingTimestamp = 0;
123: $StatusTableObject = null;
124: $StatusTable = $DOM->getElementsByTagName('table');
125: $StatusTableLength = $StatusTable->length;
126: for( $Run = 0; $Run < $StatusTableLength; $Run++ ) {
127:
128: $TableItem = $StatusTable->item( $Run );
129: $CellList = $TableItem->getElementsByTagName('td');
130: $CellListLength = $CellList->length;
131:
132: for( $RunCell = 0; $RunCell < $CellListLength; $RunCell++ ) {
133: $CheckStatus = preg_replace( '![^\w]!is', '', $this->NodeValue( $CellList->item( $RunCell )->nodeValue ) );
134: if( $CheckStatus == 'Status' ) {
135: $TrackingMessage = $this->NodeValue( $CellList->item( $RunCell +1 )->nodeValue );
136:
137: $Date = current( preg_grep( '![0-9]{2}\.[0-9]{2}\.[0-9]{4}!', explode( ' ', $TrackingMessage ) ) );
138: $Time = current( preg_grep( '![0-9]{2}\:[0-9]{2}!', explode( ' ', $TrackingMessage ) ) );
139:
140: $TrackingTimestamp = strtotime( $Date.' '.$Time );
141: break 2;
142: }
143: }
144: }
145:
146: $Parcel = new Parcel( $TrackingNumber, $this->GetTarget() );
147:
148: $Parcel->AddStatus( $TrackingTimestamp, $TrackingMessage, '' );
149:
150: return $Parcel;
151: }
152: }
153: