Server IP : 180.180.241.3 / Your IP : 216.73.216.127 Web Server : Microsoft-IIS/7.5 System : Windows NT NETWORK-NHRC 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 User : IUSR ( 0) PHP Version : 5.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/AppServ/www/app/Console/Command/ |
Upload File : |
<?php App::uses( 'ClassRegistry', 'Utility' ); class AreasShell extends AppShell { public function main() { $provincesRawContent = @file_get_contents( APP . DS . WEBROOT_DIR . DS . 'files' . DS . 'provinces-areas.txt' ); $matches = array(); $pattern = '/<area.*coords="([0-9,\.]*)".*href="([^"].*?)".*title="([^"].*?)".*>/'; preg_match_all( $pattern, $provincesRawContent, $matches ); $Province = ClassRegistry::init( 'Province' ); $District = ClassRegistry::init( 'District' ); $Province->query('TRUNCATE TABLE provinces;'); $District->query('TRUNCATE TABLE districts;'); for( $i = 0; $i < 77; $i++ ) { $Province->create(); $Province->save( array( 'name' => $matches[3][$i], 'region_id' => 0, 'coords' => $matches[1][$i], ) ); $idProvince = $Province->getLastInsertId(); // and now let's go with the districts... This one will be a real pain in the ass! $buffer = @file_get_contents( $matches[2][$i] ); echo $matches[2][$i] . ' ' . ( ( $buffer === false) ? ' ERROR' : 'OK' ) . "\n"; if( $buffer === false ) { continue; } $matches2 = array(); $pattern2 = '/<iframe.*src="([^"].*?")/'; preg_match_all( $pattern2, $buffer, $matches2 ); // find the link of the correct iframe $link = ''; foreach( $matches2[1] as $match ) { if (false !== strpos( $match, 'callcenter.thaiflood.com') ) { $link = $match; // echo $link . "\n"; break; } } // get the content of the district page if( !empty( $link ) ) { $buffer = @file_get_contents( $link ); $districts = array(); $matches3 = array(); preg_match_all( $pattern, $buffer, $matches3 ); // debug( $link ); // debug( $matches3[1] ); // debug( $matches3[2] ); // debug( $matches3[3] ); $nMatches3 = count( $matches3[1] ); for( $j = 0; $j < $nMatches3; $j++ ) { // echo $matches3[3][$j] . ' - ' . $matches3[2][$j] . ' - ' . $matches3[1][$j] . "\n"; if( !isset( $districts[$matches3[3][$j]] ) ) { $districts[$matches3[3][$j]] = array( 'url' => $matches3[2][$j], 'coords1' => $matches3[1][$j], 'coords2' => '', ); } else { $districts[$matches3[3][$j]]['coords2'] = $matches3[1][$j]; } } unset( $matches3 ); // save the districts now foreach( $districts as $kDistrict => $vDistrict ) { $District->create(); $District->save( array( 'name' => $kDistrict, 'province_id' => $idProvince, 'coords1' => $vDistrict['coords1'], 'coords2' => ( !empty( $vDistrict['coords2'] ) ? $vDistrict['coords2'] : '' ), ) ); } // get the image $patternImg = '/<img.*src="(.*?)" .*usemap.*>/'; $matchesImg = array(); $img = ''; preg_match_all( $patternImg, $buffer, $matchesImg ); $nMatchesImg = count( $matchesImg[1] ); // debug($matchesImg[1]); for( $j = 0; $j < $nMatchesImg; $j++ ) { if( strpos( $matchesImg[0][$j], '-->' ) === false ) { $img = dirname( $link ) . '/' . $matchesImg[1][$j]; $img = str_replace( '"', '', $img ); // debug($matchesImg[1][$j]); break; } } unset( $matchesImg ); if( !empty( $img ) ) { $imgPath = IMAGES . 'provinces' . DS . $idProvince . '.jpg'; copy( $img, $imgPath ); echo sprintf( '%s -> %s', $img, $imgPath ); } // exit(); } echo "-------------------------\n"; } // $this->out('Hello world.'); } // main() } ?>