$delim = ' - '; //just use space as sometimes not ' - ' $delimpos = stripos($refdesc, ' '); $record['council_reference'] = substr($refdesc, 0, $delimpos); $address = $cells[1]->plaintext; //can't just use length of delim as don't know how many space of hyphen to strip $description = trim(substr($refdesc, $delimpos + 1), ' -'); //remove address from end of description, if it's there $description = removeSuffix($description, $delim . $address); //sometimes address has Tasmania, Australia on the end $address = removeSuffix($address, ', Australia'); $description = removeSuffix($description, $delim . $address); //sometimes address has just Tasmania on the end $address = removeSuffix($address, ', Tasmania'); //description sometimes includes address with a space-hyphen-space before $description = removeSuffix($description, $delim . $address); $record['address'] = htmlspecialchars_decode($address . ', Tasmania'); $record['description'] = htmlspecialchars_decode($description); $record['date_received'] = date('Y-m-d', strtotime($cells[2]->plaintext)); $record['on_notice_to'] = date('Y-m-d', strtotime($cells[3]->plaintext)); $record['info_url'] = $cells[4]->find('a')[0]->href; $record['comment_url'] = 'http://www.huonvalley.tas.gov.au/services/planning-2/how-to-make-a-representation/'; $record['date_scraped'] = date('Y-m-d'); scraperwiki::save_sqlite(array('council_reference'), $record, 'data'); } $existingRecords = scraperwiki::select("* from data where `council_reference`='" . $record['council_reference'] . "'"); if (count($existingRecords) == 0) { print "Saving record " . $record['council_reference'] . "\n"; // print_r ($record); scraperwiki::save_sqlite(array('council_reference'), $record, 'data'); } else {
* @internal @events OnPageNotFound,OnLoadWebDocument,OnLoadWebPageCache * @internal @properties &docid=ID документов через запятую;text; &tablename=Имя таблицы;text;content &fieldname=Уникальное поле в таблице;text;id &prefix=Префикс плейсхолдеров документа;text;custom &pkname=PrimaryKey;text;id &sendparent=При просмотре документа перенаправлять на родителя?;list;true,false;true */ if (!function_exists(removeSuffix)) { function removeSuffix($url, $folder = '0') { global $modx; $suffix = $folder == '1' && $modx->config['make_folders'] == '1' ? '/' : $modx->config['friendly_url_suffix']; $pos = strripos($url, $suffix); return $pos === false ? rtrim($url) : substr($url, 0, $pos); } } switch ($modx->event->name) { case 'OnPageNotFound': $_alias = ''; $q = explode('/', ltrim(removeSuffix($_SERVER['REQUEST_URI']), '/')); $_alias = array_pop($q); $parent_alias = implode('/', $q); if ($modx->config['use_alias_path'] == 1) { if (isset($modx->documentListing[$parent_alias])) { $pid = $modx->documentListing[$parent_alias]; } } else { $pid = $modx->documentListing[$parent_alias]; } if (isset($pid)) { $parent_template = $modx->db->getValue($modx->db->select('template', $modx->getFullTableName('site_content'), 'id=' . $pid)); if ($parent_template && $parent_template == $parent_tpl_id) { $sql = "SELECT " . $pkname . " FROM " . $modx->getFullTableName($tablename) . " WHERE `" . $fieldname . "`='" . $_alias . "'"; $res = $modx->db->query($sql); if ($modx->db->getRecordCount($res) == 1) {