Ejemplo n.º 1
0
function get_state_data($url)
{
    $html = scraperWiki::scrape($url);
    $dom = new simple_html_dom();
    $dom->load($html);
    $count = 1;
    foreach ($dom->find("div[id=dashboard_main_content] tr") as $data) {
        $ths = $data->find("th");
        $tds = $data->find("td");
        $heading = $ths[0]->plaintext;
        $object = $tds[0];
        $value = $object->plaintext;
        if (!$heading) {
            $heading = "Extra Field {$count}:";
            $count++;
        }
        $heading = substr($heading, 0, strpos($heading, ":"));
        $clean_heading = str_replace(' ', '_', strtolower($heading));
        $record[$clean_heading] = $value;
        if ($clean_heading == 'official_name' || $clean_heading == 'information' || $clean_heading == 'governor') {
            foreach ($object->find("a") as $link) {
                $link = $link->href;
                $new_heading = $clean_heading . "_url";
                if (substr($link, 0, 7) == 'mailto:') {
                    $record['email'] = substr($link, 7, strlen($link) - 7);
                } else {
                    $heading = "{$heading} URL";
                    $record[$new_heading] = $link;
                }
            }
        }
        if ($clean_heading == 'information') {
            $phone_numbers = get_phone_numbers($value);
            $record['phone_primary'] = $phone_numbers[0] ? $phone_numbers[0] : '';
            $record['phone_secondary'] = $phone_numbers[1] ? $phone_numbers[1] : '';
        }
    }
    if (!isset($record['email'])) {
        $record['email'] = null;
    }
    if (isset($record)) {
        return $record;
    } else {
        return 'hello';
    }
}
function get_state_data($url)
{
    $html = scraperWiki::scrape($url);
    $dom = new simple_html_dom();
    $dom->load($html);
    $count = 1;
    $content = $dom->find("div[id=contentwrapper]", 0);
    $title = $content->find("div[class=article-title]", 0)->plaintext;
    // clean up weird spacing
    $title = trim(preg_replace('!\\s+!', ' ', $title));
    $title = substr($title, strpos($title, 'Governor') + 9);
    $record['name'] = $title;
    $table = $content->find("table tr", 0);
    $column = $table->find('td', 0);
    $record['url_photo'] = 'http://www.nga.org' . $column->find('img', 0)->src;
    if ($column->find('li', 0)) {
        $link_href = $column->find('li', 0)->find('a', 0)->href;
        $link_text = $column->find('li', 0)->find('a', 0)->plaintext;
        if ($link_text == "Governor's Website") {
            $record['url_governor'] = $link_href;
        }
        if ($link_text == 'State Website') {
            $record['url_state'] = $link_href;
        }
    }
    if ($column->find('li', 1)) {
        $record['url_state'] = $column->find('li', 1)->find('a', 0)->href;
    }
    $column = $table->find('td', 2);
    $address = $column->find("div", 0);
    $address_name = $address->innertext;
    $address_name = trim(substr($address_name, strpos($address_name, '</span>') + 7));
    $record['address_1'] = substr($address_name, 0, strpos($address_name, '<br>'));
    $record_1 = trim($address->find("div", 0)->plaintext);
    $record_2 = $address->find("div", 1)->plaintext;
    if (empty($record_2)) {
        $record['address_2'] = null;
        $address_full = $record_1;
    } else {
        $record['address_2'] = $record_1;
        $address_full = $record_2;
    }
    $address_full = str_replace('&nbsp;', ' ', $address_full);
    $address_full = trim(preg_replace('!\\s+!', ' ', $address_full));
    $record['address_city'] = substr($address_full, 0, strrpos($address_full, ', '));
    $record['address_state'] = substr($address_full, strrpos($address_full, ', ') + 2, 2);
    $record['address_zip'] = substr($address_full, strrpos($address_full, ' ') + 1);
    // Phone number
    foreach ($column->find("span[class=bio-stats-title]") as $data) {
        $field = trim($data->plaintext);
        if ($field == 'Phone:') {
            $phone = $data->parent();
            $phone = $phone->innertext;
            $phone = trim(substr($phone, strpos($phone, '</span>') + 7));
            $phone_clean = get_phone_numbers($phone);
            if (!empty($phone_clean)) {
                $record['phone'] = $phone_clean[0];
            } else {
                $record['phone'] = null;
            }
        }
    }
    if (isset($record)) {
        return $record;
    } else {
        return 'hello';
    }
}
Ejemplo n.º 3
0
function reader_phone_shortcode($atts)
{
    $a = shortcode_atts(array('reader' => ''), $atts);
    $reader = $a['reader'];
    $reader_keys = get_reader_keys();
    $output = '';
    if (in_array($reader, $reader_keys)) {
        $phone_numbers = get_phone_numbers();
        $today = strtolower(day_of_week());
        $now = strtotime(now());
        $in = strtotime(reader_in($reader, $today));
        $out = strtotime(reader_out($reader, $today));
        manage_buttons($reader);
        $available = '<h2 style="text-align: center; color: #17de9b; font-weight: bold;">' . $phone_numbers[$reader] . '</h2>';
        $not_available = '<div class="margin-top-0 ' . $reader . '-not-available ' . '"><a class=" ' . '" href="#">Not Available</a></div>';
        $busy = '<div class="' . $reader . '-busy>' . '<a class="white  ' . '" href="#">Busy with Client</a></div>';
        if ($in <= $now && $now <= $out) {
            if (is_reader_busy($reader) == '0') {
                // Reader Available
                $output = $available;
            } else {
                // Reader Busy
                $output = $busy;
            }
        } else {
            // Reader Not Available
            $output = $not_available;
        }
    }
    return $output;
}