$content = fread($handle, filesize($file)); /** Split string by a regular expression */ $fields = preg_split('!\\n----\\s*\\n*!', $content); /** Loop through all fields */ foreach ($fields as $field) { $pos = strpos($field, ':'); $key = trim(substr($field, 0, $pos)); /** Don't add fields with empty keys */ if (empty($key)) { continue; } $post[$key] = trim(substr($field, $pos + 1)); } //$post['size'] = ceil(filesize($file)/1024); fclose($handle); if (file_exists(ABSPATH . 'includes' . DS . 'themes' . DS . $theme_directory . DS . 'author-' . basename($_SERVER['REQUEST_URI']) . '.php')) { require_once ABSPATH . 'includes' . DS . 'themes' . DS . $theme_directory . DS . 'author-' . basename($_SERVER['REQUEST_URI']) . '.php'; } else { require_once ABSPATH . 'includes' . DS . 'themes' . DS . $theme_directory . DS . 'author.php'; } } else { $is_404 = true; get_404(); } if ($cache) { $cache_content = html_trim(ob_get_clean()); $handle = fopen($cache_file, 'w'); fwrite($handle, $cache_content); fclose($handle); echo $cache_content; }
function get_bill_details($r = array()) { if (empty($r['bill'])) { return; } $html = scraperwiki::scrape('https://www.revisor.mn.gov/revisor/pages/search_status/status_detail.php?b=House&ssn=0&y=2012&f=' . $r['bill']); // Parse Dom $dom = new simple_html_dom(); $dom->load($html); $count = 0; // Table based layout without real identifiers. Get Senate votes if avialable. $senate = $dom->find('table[summary=Actions]', 1); if (!empty($senate)) { foreach ($senate->find('tr') as $rows) { $count++; // First row is header if ($count > 1) { $data = $rows->find('td'); $roll_call = html_trim($data[5]->plaintext); if (!empty($roll_call)) { $votes = explode('-', $roll_call); // Update record $r['senate_vote_yes'] = $votes[0]; $r['senate_vote_no'] = $votes[1]; $r['senate_last_vote'] = html_trim($data[0]->plaintext); $r['timestamp'] = time(); // Save. scraperwiki::save_sqlite(array('id'), $r); } } } } }