Advertisement
Guest User

Untitled

a guest
Jan 14th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 35.08 KB | None | 0 0
  1. <?php
  2.     require_once( '../../helpers/vars.php' );
  3.     require_once( '../../helpers/dom_parser.php' );
  4.     require_once( '../../helpers/formaters_text.php' );
  5.     //require_once( './auto_scrap_vars.php' );
  6.     class california_crawler {
  7.         private $url;
  8.         private $dbRow;
  9.         private $html;
  10.         private $dom;
  11.         public static $table = '__import_ca_bar';
  12.         public static $ID = 'UID';
  13.         public static $URL = 'SourceURL';
  14.         public static $updatedAt = 'UpdatedAt';
  15.         public static $barNumber = 'idNumber';
  16.         public static $name = 'Name';
  17.         public static $firstName = 'firstName';
  18.         public static $middleName = 'middleName';
  19.         public static $lastName = 'lastName';
  20.         public static $suffix = 'Suffix';
  21.         public static $memberStatus = 'member_status';
  22.         public static $hasactive = 'HasActiveLicense';
  23.         public static $address = 'Address';
  24.         public static $firm = 'Firm';
  25.         public static $school = 'lawSchool';
  26.         public static $email = 'Email';
  27.         public static $addressLine2 = 'Address2';
  28.         public static $city = 'City';
  29.         public static $state = 'State';
  30.         public static $zip = 'Zip';
  31.         public static $lat = 'Lat';
  32.         public static $long = 'Lng';
  33.         public static $phone = 'Phone';
  34.         public static $disciplinaryHistory = 'DisciplinaryHistoryB';
  35.         public static $dateadmitted = 'DateAdmitted';
  36.         public static $cDateAdmitted = 'cDateAdmitted';
  37.         public static $boardCertified = 'CertifiedLegalSpecialty';
  38.         public static $boardCodes = 'Board_Certified_Codes';
  39.         // public static $sections             = 'Sections';
  40.         public static $isJudge = 'is_a_judge';
  41.         public $data = array( );
  42.         private $isDeceased = null;
  43.         private $isEligible = null;
  44.         public function __construct( $url, $dbRow ) {
  45.             $this->url   = $url;
  46.             $this->dbRow = $dbRow;
  47.         }
  48.         public static function get_select_string( ) {
  49.             $select = array(
  50.                  self::$ID,
  51.                 self::$URL,
  52.                 self::$name,
  53.                 self::$firstName,
  54.                 self::$middleName,
  55.                 self::$lastName,
  56.                 self::$suffix,
  57.                 self::$memberStatus,
  58.                 self::$hasactive,
  59.                 self::$phone,
  60.                 self::$address,
  61.                 self::$firm,
  62.                 self::$school,
  63.                 self::$email,
  64.                 self::$addressLine2,
  65.                 self::$city,
  66.                 self::$state,
  67.                 self::$zip,
  68.                 self::$long,
  69.                 self::$lat,
  70.                 self::$dateadmitted,
  71.                 self::$boardCertified,
  72.                 self::$boardCodes,
  73.                 // self::$sections,
  74.                 self::$barNumber
  75.             );
  76.             return '`' . implode( '`,`', $select ) . '`';
  77.         }
  78.         public function get_data( ) {
  79.             if ( !empty( $this->data ) ) {
  80.                 return $this->data;
  81.             }
  82.             $this->crawl_page();
  83.             $this->data[ self::$memberStatus ] = $this->get_member_status();
  84.             if ( $this->is_deceased() || !$this->is_eligible() ) {
  85.                 return $this->data;
  86.             }
  87.             $LL                                       = $this->get_address2();
  88.             $this->data[ self::$name ]                = $this->get_full_name_string();
  89.             $this->data[ self::$firstName ]           = $this->get_first_name();
  90.             $this->data[ self::$middleName ]          = $this->get_middle_name();
  91.             $this->data[ self::$lastName ]            = $this->get_last_name();
  92.             $this->data[ self::$suffix ]              = $this->get_suffix_name();
  93.             $this->data[ self::$address ]             = $LL[ 'Address' ];
  94.             $this->data[ self::$firm ]                = $this->get_firm_name();
  95.             $this->data[ self::$school ]              = $this->get_law_school();
  96.             $this->data[ self::$email ]               = $this->get_email();
  97.             $this->data[ self::$memberStatus ]        = $this->get_member_status();
  98.             $this->data[ self::$hasactive ]           = $this->get_has_active();
  99.             $this->data[ self::$city ]                = $LL[ 'City' ];
  100.             $this->data[ self::$addressLine2 ]        = $LL[ 'Subpremise' ];
  101.             $this->data[ self::$state ]               = $LL[ 'State' ];
  102.             $this->data[ self::$zip ]                 = $LL[ 'Zip' ];
  103.             $this->data[ self::$phone ]               = $this->get_phone();
  104.             $this->data[ self::$disciplinaryHistory ] = $this->get_disciplinary_history() ? 1 : 0;
  105.             $this->data[ self::$dateadmitted ]        = $this->get_date_admitted();
  106.             $this->data[ self::$cDateAdmitted ]       = date( 'c', $this->data[ self::$dateadmitted ] );
  107.             // $this->data[self::$sections]            = $this->get_sections();
  108.             $this->data[ self::$boardCertified ]      = $this->get_board_certified();
  109.             $this->data[ self::$boardCodes ]          = $this->get_board_codes();
  110.             //Don't know for sure if address changes, so always update lat and long
  111.             $this->data[ self::$long ]                = $LL[ 'lng' ];
  112.            
  113.             $this->data[ self::$lat ] = $LL[ 'lat' ];
  114.            
  115.             // die(print_r($this->data));
  116.             return $this->data;
  117.         }
  118.         public function get_data_diff( ) {
  119.             $response = array( );
  120.             // if($this->is_deceased() && $this->dbRow[self::$memberStatus] !== 'Deceased') {
  121.             //     $response[self::$memberStatus] = $this->get_member_status();
  122.             //     return $response;
  123.             // }
  124.             // if(!$this->is_eligible() && $this->dbRow[self::$memberStatus] != 'Inactive') {
  125.             //     $response[self::$memberStatus] = $this->get_member_status();
  126.             //     return $response;
  127.             // }
  128.             // die(print_r($this->dbRow));
  129.             foreach ( $this->dbRow as $column => $value ) {
  130.                 if ( isset( $this->data[ $column ] ) && $this->data[ $column ] !== $this->dbRow[ $column ] ) {
  131.                     // echo $response[$column] . ' : ' . $this->data[$column];
  132.                     $response[ $column ] = $this->data[ $column ];
  133.                 } else if ( array_key_exists( $column, $this->data ) && $this->data[ $column ] === null && $this->dbRow[ $column ] !== null ) {
  134.                     echo $column . '<br>';
  135.                     //because isset() will pretend variables that are set to null are unset
  136.                     $response[ $column ] = null;
  137.                 }
  138.             }
  139.             return $response;
  140.         }
  141.         public function is_deceased( ) {
  142.             if ( isset( $this->isDeceased ) ) {
  143.                 return $this->isDeceased;
  144.             }
  145.             if ( $this->is_page_empty() ) {
  146.                 if ( strstr( $this->html, 'This licensee is deceased.' ) !== false ) { //They're def dead
  147.                     $this->isDeceased = true;
  148.                     return $this->isDeceased;
  149.                 } else if ( $this->confirm_status_by_search('Deceased') ) {
  150.                     $this->isDeceased = true;
  151.                     return $this->isDeceased;
  152.                 } else if ( $this->confirm_status_by_search('Judge') ) {
  153.                     echo $this->url;
  154.                     $sqlu = "UPDATE `__import_ca_bar` SET `member_status` = 'Judge', `UpdatedAt` = NOW() WHERE `UID` = " . d_iwt( $this->dbRow[ 'UID' ] );
  155.                     db_query_( $sqlu );
  156.                     meta_refresh_soft( 5 );
  157.                     die( 'Judge was found! ' . $sqlu );
  158.                 } else {
  159.                     echo $this->url;
  160.                     $sqlu = "UPDATE `__import_ca_bar` SET `member_status` = 'Unknown?', `UpdatedAt` = NOW() WHERE `UID` = " . d_iwt( $this->dbRow[ 'UID' ] );
  161.                     db_query_( $sqlu );
  162.                     meta_refresh_soft( 5 );
  163.                     die( 'Page was empty, but status not confirmed! ' . $sqlu );
  164.                 }
  165.             }
  166.             $this->isDeceased = false;
  167.             return $this->isDeceased;
  168.         }
  169.         private function confirm_judge_by_search( ) {
  170.             // $paragraphs = $this->dom->find('p');
  171.             // foreach($paragraphs as $paragraph) {
  172.             //     if(isset($paragraph->plaintext)) {
  173.             //         echo $paragraph->plaintext."<br>";
  174.             //         $text = str_replace(array("\n", "\r"), '', $paragraph->plaintext);
  175.             //         $text = preg_replace('/\s\s+/', ' ', $text);
  176.             //         if(strstr($text, 'This person is currently serving as a Judge of a court') !== false) {
  177.             //             echo strstr('hello world', 'world');
  178.             //         }
  179.             //         // echo strstr($this->dom->plaintext, 'This person is currently serving as a Judge')."<br>";
  180.             //         // $search = preg_match('/.*(Th/is person is currently serving as a Judge).*/', $this->dom->plaintext, $matches);
  181.             //         // if(isset($matches[0])) {
  182.             //             // die ($matches[0]);
  183.             //             // return true;
  184.             //         // }
  185.             //     }
  186.             // }
  187.             // die();
  188.             // return false;
  189.         }
  190.         private function is_page_empty( ) {
  191.             if ( empty( $this->get_full_name_string() ) || !$this->get_full_name_string() ) {
  192.                 return true;
  193.             }
  194.             return false;
  195.         }
  196.         private function confirm_status_by_search($searchFor) {
  197.             global $curl_cached_response_code;
  198.             $name = urlencode( $this->dbRow[ self::$name ] );
  199.             $url  = 'http://members.calbar.ca.gov/fal/LicenseeSearch/QuickSearch?ResultType=0&SearchType=0&SoundsLike=False&FreeText=' . $name;
  200.             $html = curl_cached_scrape( $url );
  201.             if ( $curl_cached_response_code != '200' ) {
  202.                 $this->crawl_failure();
  203.             }
  204.             $dom  = str_get_html( $html );
  205.             $rows = $dom->find( 'table#tblAttorney tbody', 0 )->find( 'tr' );
  206.             if ( is_array( $rows ) ) {
  207.                 foreach ( $rows as $row ) {
  208.                     if ( method_exists( $row, 'find' ) ) {
  209.                         $barNumber = $row->find( 'td', 2 );
  210.                         $status    = $row->find( 'td', 1 );
  211.                     }
  212.                     if ( isset( $barNumber->plaintext ) && isset( $status->plaintext ) ) {
  213.                         $barNumber = trim( $barNumber->plaintext );
  214.                         $status    = trim( $status->plaintext );
  215.                         if ( $barNumber == $this->dbRow[ self::$barNumber ] && $status == $searchFor ) {
  216.                             return true;
  217.                         }
  218.                     }
  219.                 }
  220.             }
  221.             return false;
  222.         }
  223.         public function is_eligible( ) {
  224.             if ( $this->isEligible !== null ) {
  225.                 return $this->isEligible;
  226.             }
  227.             $tr = $this->dom->find( 'table tr', 1 );
  228.             if ( method_exists( $tr, 'find' ) ) {
  229.                 if ( method_exists( $tr, 'find' ) ) {
  230.                     $td = $tr->find( 'td', 1 );
  231.                     if ( isset( $td->plaintext ) ) {
  232.                         $activeText       = trim( $td->plaintext );
  233.                         $this->isEligible = $activeText === 'Active';
  234.                         return $this->isEligible;
  235.                     }
  236.                 }
  237.             }
  238.             $this->isEligible = false;
  239.             return $this->isEligible;
  240.         }
  241.         private function get_member_status( ) {
  242.             if ( $this->is_deceased() ) {
  243.                 return 'Deceased';
  244.             }
  245.             return $this->is_eligible() ? 'Active' : 'Inactive';
  246.         }
  247.         private function get_has_active( ) {
  248.             $theirstatus = $this->is_eligible() ? 'Active' : 'Inactive';
  249.             if ( $theirstatus == 'Active' ) {
  250.                 return true;
  251.             } else {
  252.                 return false;
  253.             }
  254.         }
  255.         // private function get_address_old() {
  256.         //     $response = [];
  257.         //     $paragraphs = $this->dom->find('p');
  258.         //     foreach($paragraphs as $paragraph) {
  259.         //         if(isset($paragraph->plaintext)) {
  260.         //             if(strstr($paragraph->plaintext, 'Address: ') !== false) {
  261.         //                 $rawaddy =  str_replace('Address: ', '', $paragraph->plaintext);
  262.         //             }
  263.         //         }
  264.         //     }  
  265.         //     return null;
  266.         // }
  267.         private function get_firm_name( ) {
  268.             $response   = array( );
  269.             $paragraphs = $this->dom->find( 'p' );
  270.             foreach ( $paragraphs as $paragraph ) {
  271.                 if ( isset( $paragraph->plaintext ) ) {
  272.                     if ( strstr( $paragraph->plaintext, 'Address: ' ) !== false ) {
  273.                         $addy  = str_replace( 'Address: ', '', $paragraph->plaintext );
  274.                         $aa    = explode( ",", $addy );
  275.                         $firm  = array( );
  276.                         $aaaa  = array( );
  277.                         $found = false;
  278.                         foreach ( $aa as $word ) {
  279.                             $word = trim( $word );
  280.                             if ( $found === false ) {
  281.                                 if ( !is_numeric( substr( $word, 0, 1 ) ) && !find_po_box( $word ) ) {
  282.                                     $firm[ ] = $word;
  283.                                 } else {
  284.                                     $found   = true;
  285.                                     $aaaa[ ] = $word;
  286.                                 }
  287.                             } else {
  288.                                 $aaaa[ ] = $word;
  289.                             }
  290.                         }
  291.                         $firmname = implode( ", ", $firm );
  292.                         if ( isset( $firm ) ) {
  293.                             return $firmname;
  294.                         } else {
  295.                             return null;
  296.                         }
  297.                     }
  298.                 }
  299.             }
  300.             return null;
  301.         }
  302.         private function get_address2( ) {
  303.             $response   = array( );
  304.             $paragraphs = $this->dom->find( 'p' );
  305.             foreach ( $paragraphs as $paragraph ) {
  306.                 if ( isset( $paragraph->plaintext ) ) {
  307.                     if ( strstr( $paragraph->plaintext, 'Address: ' ) !== false ) {
  308.                         $addy  = str_replace( 'Address: ', '', $paragraph->plaintext );
  309.                         $aa    = explode( ",", $addy );
  310.                         $firm  = array( );
  311.                         $aaaa  = array( );
  312.                         $found = false;
  313.                         foreach ( $aa as $word ) {
  314.                             $word = trim( $word );
  315.                             if ( $found === false ) {
  316.                                 if ( !is_numeric( substr( $word, 0, 1 ) ) && !find_po_box( $word ) ) {
  317.                                     $firm[ ] = $word;
  318.                                 } else {
  319.                                     $found   = true;
  320.                                     $aaaa[ ] = $word;
  321.                                 }
  322.                             } else {
  323.                                 $aaaa[ ] = $word;
  324.                             }
  325.                         }
  326.                         $addressa = implode( " ", $aaaa );
  327.                         $LL       = geocoderA::getLocation_fullc( $addy );
  328.                         if ( find_po_box( $addy ) ) {
  329.                             $addya = explode( ",", $addy );
  330.                             if ( find_po_box( $addya[ 0 ] ) ) {
  331.                                 $addyF = trim( $addya[ 0 ] );
  332.                             }
  333.                         }
  334.                         return $LL;
  335.                     }
  336.                 }
  337.             }
  338.             return null;
  339.         }
  340.         private function get_email( ) {
  341.             $response = array( );
  342.             $em       = -1;
  343.             for ( $ii = 0; $ii <= 20; $ii++ ) {
  344.                 if ( strstr( $this->dom, '#e' . $ii . '{display:inline;}' ) ) {
  345.                     $em   = $ii;
  346.                     $emid = "e" . $em;
  347.                     //return $emid;
  348.                 }
  349.             }
  350.             $findemail = "span[id=" . $emid . "]";
  351.             $rets      = $this->dom->find( $findemail );
  352.             foreach ( $rets as $ret ) {
  353.                 $rdd[ ] = trim( $ret->plaintext );
  354.             }
  355.             if ( isset( $rdd ) ) {
  356.                 $emspaced   = trim( $rdd[ 0 ] );
  357.                 $foundemail = str_replace( ' ', '', $emspaced );
  358.                 $foundemail = str_replace( '&#46;', '.', $foundemail );
  359.                 $foundemail = str_replace( '&#64;', '@', $foundemail );
  360.                 if ( $foundemail == 'Not Available' ) {
  361.                     return null;
  362.                 }
  363.                 if ( filter_var( $foundemail, FILTER_VALIDATE_EMAIL ) ) {
  364.                     return $foundemail;
  365.                 } else {
  366.                     var_dump( filter_var( $foundemail, FILTER_VALIDATE_EMAIL ) );
  367.                 }
  368.             } else {
  369.                 return null;
  370.             }
  371.         }
  372.         private function get_law_school( ) {
  373.             $response   = array( );
  374.             $paragraphs = $this->dom->find( 'p' );
  375.             foreach ( $paragraphs as $paragraph ) {
  376.                 if ( isset( $paragraph->plaintext ) ) {
  377.                     if ( strstr( $paragraph->plaintext, 'Law School: ' ) !== false ) {
  378.                         $lawschool = str_replace( 'Law School: ', '', $paragraph->plaintext );
  379.                         return $lawschool;
  380.                     }
  381.                 }
  382.             }
  383.             return null;
  384.         }
  385.         private function get_full_name_string( ) {
  386.             $response = array( );
  387.             $name     = $this->dom->find( 'h3 b', 1 );
  388.             if ( isset( $name->plaintext ) ) {
  389.                 $name = $name->plaintext;
  390.             } else {
  391.                 return false;
  392.             }
  393.             preg_match( '/^.*(\s#.*)$/', $name, $matches );
  394.             if ( isset( $matches[ 1 ] ) ) {
  395.                 $name = str_replace( $matches[ 1 ], '', $name );
  396.             } else {
  397.                 die( 'No bar number!' );
  398.             }
  399.             $name = preg_replace( '/\s\s+/', ' ', $name );
  400.             return $name;
  401.         }
  402.         private function get_full_name_array( ) {
  403.             $response = array( );
  404.             $name     = $this->get_full_name_string();
  405.             $name     = nix_nicknames( $name );
  406.             $name     = fix_names( $name );
  407.             if ( isset( $name[ 0 ] ) && strtolower( $name[ 0 ] ) == 'judge' ) {
  408.                 die( 'Name prefix was found!' );
  409.                 unset( $name[ 0 ] );
  410.                 $name = array_values( $name );
  411.             }
  412.             // if(isset($name[0]) && strtolower($name[0]) == 'justice') {
  413.             //     unset($name[0]);
  414.             //     $name = array_values($name);
  415.             // }
  416.             if ( lmatch( $this->data[ self::$name ], 'Chief Justice' ) ) {
  417.                 die( 'Name prefix was found!' );
  418.                 // foreach($name as $index => $part) {
  419.                 //     if($part == 'Chief Justice') {
  420.                 //         unset($name[$index]);
  421.                 //     }
  422.                 //     if($part == 'Chief' && isset($name[$index+1]) && $name[$index+1] == 'Justice') {
  423.                 //         unset($name[$index]);
  424.                 //         unset($name[$index+1]);
  425.                 //     }
  426.                 // }
  427.                 // $name = array_values($name);
  428.             }
  429.             if ( isset( $name[ 'f' ] ) ) {
  430.                 //First middle and last names
  431.                 $response[ 'first' ] = ucfirst( strtolower( $name[ 'f' ] ) );
  432.                 if ( isset( $name[ 'm' ] ) ) {
  433.                     $response[ 'middle' ] = ucfirst( strtolower( $name[ 'm' ] ) );
  434.                 } else {
  435.                     $response[ 'middle' ] = null;
  436.                 }
  437.                 $response[ 'last' ] = ucfirst( strtolower( $name[ 'l' ] ) );
  438.             } else if ( !isset( $name[ 1 ] ) ) {
  439.                 //Only 1 string returned
  440.                 $nameb = explode( " ", $this->dbRow[ self::$name ] );
  441.                 if ( isset( $nameb[ 0 ] ) && isset( $nameb[ 1 ] ) ) {
  442.                     $response[ 'first' ] = ucfirst( strtolower( $nameb[ 0 ] ) );
  443.                     $response[ 'last' ]  = ucfirst( strtolower( $nameb[ 1 ] ) );
  444.                 } else {
  445.                     die( "One Name??" );
  446.                 }
  447.             } else if ( isset( $name[ 4 ] ) && ( $name[ 2 ] == "De" ) && ( $name[ 3 ] == "La" ) ) {
  448.                 //De La Name
  449.                 $response[ 'first' ]  = ucfirst( strtolower( $name[ 0 ] ) );
  450.                 $response[ 'middle' ] = ucfirst( strtolower( $name[ 1 ] ) );
  451.                 $response[ 'last' ]   = "De La " . ucfirst( strtolower( $name[ 4 ] ) );
  452.             } else if ( isset( $name[ 4 ] ) && ( $name[ 3 ] == "De" ) ) {
  453.                 //De Name
  454.                 $response[ 'first' ]  = ucfirst( strtolower( $name[ 0 ] ) );
  455.                 $response[ 'middle' ] = ucfirst( strtolower( $name[ 1 ] ) ) . " " . ucfirst( strtolower( $name[ 2 ] ) );
  456.                 $response[ 'last' ]   = "De " . ucfirst( strtolower( $name[ 4 ] ) );
  457.             } else if ( isset( $name[ 4 ] ) ) {
  458.                 //
  459.                 $response[ 'first' ]  = ucfirst( strtolower( $name[ 0 ] ) );
  460.                 $response[ 'middle' ] = ucfirst( strtolower( $name[ 1 ] ) ) . " " . ucfirst( strtolower( $name[ 2 ] ) ) . " " . ucfirst( strtolower( $name[ 2 ] ) );
  461.                 $response[ 'last' ]   = ucfirst( strtolower( $name[ 4 ] ) );
  462.             } else if ( isset( $name[ 3 ] ) ) {
  463.                 //First middle and last names and extra
  464.                 $response[ 'first' ]  = ucfirst( strtolower( $name[ 0 ] ) );
  465.                 $response[ 'middle' ] = ucfirst( strtolower( $name[ 1 ] ) ) . " " . ucfirst( strtolower( $name[ 2 ] ) );
  466.                 $response[ 'last' ]   = ucfirst( strtolower( $name[ 3 ] ) );
  467.             } else if ( isset( $name[ 2 ] ) ) {
  468.                 $response[ 'first' ]  = ucfirst( strtolower( $name[ 0 ] ) );
  469.                 $response[ 'middle' ] = ucfirst( strtolower( $name[ 1 ] ) );
  470.                 $response[ 'last' ]   = ucfirst( strtolower( $name[ 2 ] ) );
  471.             } else if ( isset( $name[ 1 ] ) ) {
  472.                 $response[ 'first' ]  = ucfirst( strtolower( $name[ 0 ] ) );
  473.                 $response[ 'middle' ] = '';
  474.                 $response[ 'last' ]   = ucfirst( strtolower( $name[ 1 ] ) );
  475.             } else if ( isset( $name[ 0 ] ) ) {
  476.                 $response[ 'first' ]  = ucfirst( strtolower( $name[ 0 ] ) );
  477.                 $response[ 'middle' ] = '';
  478.                 $response[ 'last' ]   = '';
  479.             } else {
  480.                 die( 'no name!' );
  481.                 print_r( $response );
  482.             }
  483.             return $response;
  484.         }
  485.         private function get_first_name( ) {
  486.             $name = $this->get_full_name_array();
  487.             return $name[ 'first' ];
  488.         }
  489.         private function get_middle_name( ) {
  490.             $name = $this->get_full_name_array();
  491.             return $name[ 'middle' ];
  492.         }
  493.         private function get_last_name( ) {
  494.             $name = $this->get_full_name_array();
  495.             return $name[ 'last' ];
  496.         }
  497.         private function get_suffix_name( ) {
  498.             $name   = $this->get_full_name_string();
  499.             $suffix = name_suffix( $name );
  500.             if ( !empty( $suffix ) ) {
  501.                 return $suffix;
  502.             }
  503.             return null;
  504.         }
  505.         private function get_phone( ) {
  506.             $response   = array( );
  507.             $paragraphs = $this->dom->find( 'p' );
  508.             foreach ( $paragraphs as $paragraph ) {
  509.                 if ( isset( $paragraph->plaintext ) ) {
  510.                     if ( strstr( $paragraph->plaintext, 'Phone Number:' ) !== false ) {
  511.                         $phone = str_replace( 'Phone Number:', '', $paragraph->plaintext );
  512.                         return $phone;
  513.                     }
  514.                 }
  515.             }
  516.             return null;
  517.         }
  518.         // private function get_disciplinary_history() {
  519.         //     $table = $this->dom->find('div[class=margin-bottom]', 0);
  520.         //     if(method_exists($table, 'find')) {
  521.         //         foreach ($table->find('tr') as $row) {
  522.         //             //view the discipline td, not admin action
  523.         //             $disciplinary = $row->find('td', 2);
  524.         //             if(isset($disciplinary->plaintext) && !empty(trim($disciplinary->plaintext))){
  525.         //                 if(strstr(trim($disciplinary->plaintext), 'Suspended') !== false) {
  526.         //                     return true;
  527.         //                 }
  528.         //             }
  529.         //         }
  530.         //     }
  531.         //     return false;
  532.         // }
  533.         private function get_disciplinary_history( ) {
  534.             foreach ( $this->dom->find( 'div[class=margin-bottom]' ) as $table )
  535.                 $tablehtmlraw = $table->outertext;
  536.             $tablehtml  = str_get_html( $tablehtmlraw );
  537.             $th1        = $text_description = str_replace( ' &nbsp; ', '', $tablehtml );
  538.             $th2        = $text_description = str_replace( '&nbsp;', '', $tablehtml );
  539.             $tableclean = str_get_html( $th2 );
  540.             $tds        = $tableclean->find( 'td' );
  541.             foreach ( $tds as $td ) {
  542.                 $tdata[ ] = trim( $td->plaintext );
  543.             }
  544.             //create array of just the 3rd td which would be the discipline column. also exluding 1st instance whic his the label.
  545.             $count = count( $tdata );
  546.             for ( $i = 6; $i < $count; $i += 4 ) {
  547.                 $tddh[ ] = $tdata[ $i ];
  548.             }
  549.             if ( !array_filter( $tddh ) ) {
  550.                 return false;
  551.             } else {
  552.                 return true;
  553.             }
  554.         }
  555.         private function get_date_admitted( ) {
  556.             foreach ( $this->dom->find( 'div[class=margin-bottom]' ) as $table )
  557.                 $tablehtmlraw = $table->outertext;
  558.             $tablehtml  = str_get_html( $tablehtmlraw );
  559.             $th1        = $text_description = str_replace( ' &nbsp; ', '', $tablehtml );
  560.             $th2        = $text_description = str_replace( '&nbsp;', '', $tablehtml );
  561.             $tableclean = str_get_html( $th2 );
  562.             $tds        = $tableclean->find( 'td' );
  563.             foreach ( $tds as $td ) {
  564.                 $tdata[ ] = trim( $td->plaintext );
  565.             }
  566.             //get second to last value which would be admitted date
  567.             end( $tdata );
  568.             $datea = prev( $tdata );
  569.             return strtotime( $datea );
  570.         }
  571.         private function get_board_certified( ) {
  572.             $table = $this->dom->find( 'table', 1 );
  573.             if ( method_exists( $table, 'find' ) ) {
  574.                 if ( isset( $table->plaintext ) ) {
  575.                     $text = trim( $table->plaintext );
  576.                     if ( strstr( $text, 'Certified Legal Specialty' ) !== false ) {
  577.                         $row = $table->find( 'tr', 0 );
  578.                         if ( method_exists( $row, 'find' ) ) {
  579.                             $td = $row->find( 'td', 1 );
  580.                             if ( isset( $td->innertext ) ) {
  581.                                 $certificates = explode( '<br />', $td->innertext );
  582.                                 foreach ( $certificates as $index => $certificate ) {
  583.                                     $certificates[ $index ] = trim( $certificate );
  584.                                     if ( empty( $certificates[ $index ] ) ) {
  585.                                         unset( $certificates[ $index ] );
  586.                                     }
  587.                                 }
  588.                                 $certificates = implode( '|', $certificates );
  589.                                 $certificates = str_replace( '(State Bar of California)', '', $certificates );
  590.                                 return $certificates;
  591.                             }
  592.                         }
  593.                     }
  594.                 }
  595.                 // foreach ($table->find('tr') as $row) {
  596.                 //     $disciplinary = $row->find('td', 3);
  597.                 //     if(isset($disciplinary->plaintext) && !empty(trim($disciplinary->plaintext))){
  598.                 //         if(strstr(trim($disciplinary->plaintext), 'Suspended') !== false) {
  599.                 //             return true;
  600.                 //         }
  601.                 //     }
  602.                 // }
  603.             }
  604.             return null;
  605.         }
  606.         private function get_board_codes( ) {
  607.             $rawcerts = $this->get_board_certified();
  608.             $raw      = $rawcerts;
  609.             $raw      = trim( $raw );
  610.             $rawa     = explode( "|", $raw );
  611.             $certs    = array( );
  612.             foreach ( $rawa as $cert ) {
  613.                 $cert = trim( $cert );
  614.                 $key  = sha1( $cert );
  615.                 if ( !isset( $known[ $key ] ) ) {
  616.                     $known[ $key ] = $cert;
  617.                 }
  618.                 $cert = strreplace( '  ', ' ', $cert );
  619.                 if ( 0 ) {
  620.                     //keep it alinged....
  621.                 } else if ( ( $cert == 'Admiralty and Maritime Law (State Bar of California)' ) || ( $cert == 'Admiralty and Maritime Law' ) ) {
  622.                     $certs[ ] = 'cbls-adma';
  623.                 } else if ( ( $cert == 'Appellate Law (State Bar of California)' ) || ( $cert == 'Appellate Law' ) ) {
  624.                     $certs[ ] = 'cbls-appl';
  625.                 } else if ( ( $cert == 'Bankruptcy Law (State Bar of California)' ) || ( $cert == 'Bankruptcy Law' ) ) {
  626.                     $certs[ ] = 'cbls-bank';
  627.                 } else if ( ( $cert == 'Business Bankruptcy Law (American Bd of Certification)' ) || ( $cert == 'Business Bankruptcy Law (American Bd of Certification)' ) ) {
  628.                     $certs[ ] = 'abc-bb';
  629.                 } else if ( $cert == 'Civil Trial Advocacy (Natl Board of Trial Advocacy)' ) {
  630.                     $certs[ ] = 'nbta-cpp';
  631.                 } else if ( $cert == 'Consumer Bankruptcy Law (American Bd of Certification)' ) {
  632.                     $certs[ ] = 'abc-cb';
  633.                 } else if ( $cert == "Creditor's Rights Law (American Bd of Certification)" ) {
  634.                     $certs[ ] = 'abc-cr';
  635.                 } else if ( ( $cert == 'Criminal Law (State Bar of California)' ) || ( $cert == 'Criminal Law' ) ) {
  636.                     $certs[ ] = 'cbls-crim';
  637.                 } else if ( $cert == 'Criminal Trial Advocacy (Natl Board of Trial Advocacy)' ) {
  638.                     $certs[ ] = 'nbta-crim';
  639.                 } else if ( $cert == 'Elder Law (National Elder Law Foundation)' ) {
  640.                     $certs[ ] = 'nelf-el';
  641.                 } else if ( ( $cert == 'Estate Planning, Trust & Probate Law (State Bar of California)' ) || ( $cert == 'Estate Planning, Trust & Probate Law' ) ) {
  642.                     $certs[ ] = 'cbls-wtep';
  643.                 } else if ( ( $cert == 'Family Law (State Bar of California)' ) || ( $cert == 'Family Law' ) ) {
  644.                     $certs[ ] = 'cbls-fmly';
  645.                 } else if ( $cert == 'Family Law Trial Advocacy (Natl Board of Trial Advocacy)' ) {
  646.                     $certs[ ] = 'nbta-fam';
  647.                 } else if ( ( $cert == 'Franchise & Distribution Law (State Bar of California)' ) || ( $cert == 'Franchise & Distribution Law' ) ) {
  648.                     $certs[ ] = 'cbls-fran';
  649.                 } else if ( ( $cert == 'Immigration & Nationality Law (State Bar of California)' ) || ( $cert == 'Immigration & Nationality Law' ) ) {
  650.                     $certs[ ] = 'cbls-immi';
  651.                 } else if ( $cert == 'Juvenile Law (Child Welfare) (Natl Assn/Counsel for Children)' ) {
  652.                     $certs[ ] = 'nacc-cw';
  653.                 } else if ( ( $cert == 'Legal Malpractice Law (State Bar of California)' ) || ( $cert == 'Legal Malpractice Law' ) ) {
  654.                     $certs[ ] = 'cbls-lgmp';
  655.                 } else if ( $cert == 'Legal Professional Liability (Am Brd of Prof Liability Attys)' ) {
  656.                     $certs[ ] = 'abpla-leg';
  657.                 } else if ( $cert == 'Medical Professional Liability (Am Brd of Prof Liability Attys)' ) {
  658.                     $certs[ ] = 'abpla-med';
  659.                 } else if ( $cert == 'Social Security Disability Law (Natl Board of Trial Advocacy)' ) {
  660.                     $certs[ ] = 'nbta-ssd';
  661.                 } else if ( ( $cert == 'Taxation Law (State Bar of California)' ) || ( $cert == 'Taxation Law' ) ) {
  662.                     $certs[ ] = 'cbls-taxl';
  663.                 } else if ( ( $cert == "Workers' Compensation Law (State Bar of California)" ) || ( $cert == "Workers' Compensation Law" ) ) {
  664.                     $certs[ ] = 'cbls-wcmp';
  665.                 } else {
  666.                     return null;
  667.                 }
  668.             }
  669.             if ( count( $certs ) > 0 ) {
  670.                 $certcodes = implode( "|", $certs );
  671.                 return $certcodes;
  672.             } else {
  673.                 return null;
  674.             }
  675.         }
  676.         //Sections needs to be fixed because currently breaks when both
  677.         //section and board specialty exist. easy fix but no time.
  678.         // private function get_sections() {
  679.         //     $tables = $this->dom->find('table');
  680.         //     foreach($tables as $table) {
  681.         //         $tablesa[] = $table;
  682.         //     }
  683.         //     $sect = str_get_html($tablesa[1]);
  684.         //     $tds = $sect->find('td');
  685.         //     foreach($tds as $td) {
  686.         //         $tda[] = $td;
  687.         //     }
  688.         //     $sectdraw = $tda[1];
  689.         //     if(isset($tda[1])) {
  690.         //         $sectdx = explode('<br />',$sectdraw);
  691.         //         $sectdx = array_map('strip_tags', $sectdx);
  692.         //         $sectdx = array_map('trim', $sectdx);
  693.         //         $sectdx = array_filter($sectdx);
  694.         //         $secti = implode('|', $sectdx);
  695.         //         $secti = trim($secti);
  696.         //         if($secti !==''){
  697.         //             return $secti;
  698.         //         } else {
  699.         //             return null;
  700.         //         }
  701.         //     } else {
  702.         //         return null;
  703.         //     }
  704.         // }
  705.         private function crawl_page( $url = false ) {
  706.             global $curl_cached_response_code;
  707.             $this->html = curl_cached_scrape( $url ? $url : $this->url );
  708.             if ( $curl_cached_response_code != '200' ) {
  709.                 $this->crawl_failure();
  710.             }
  711.             $this->dom = str_get_html( $this->html );
  712.         }
  713.         private function crawl_failure( ) {
  714.             global $file_get_contents_cached_as;
  715.             unlink( $file_get_contents_cached_as[ 0 ] ); //Delete cache for this crawl
  716.             echo "<strong>This page was unable to be crawled:</strong><br>" + $this->url;
  717.             exit;
  718.         }
  719.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement