コード例 #1
0
function item_city_box($city_txt, $city_select_txt)
{
    $aCities = osc_get_cities();
    $item = osc_item() != null ? osc_item() : array();
    switch (count($aCities)) {
        case 0:
            // 0 regions
            ?>
                        <div class="clearfix">
                            <label><?php 
            echo $city_txt;
            ?>
</label>
                            <div class="input">
                                <input class="city_name" id="city_name" type="text" name="city" value="<?php 
            echo get_city_name($item);
            ?>
" />
                            </div>
                        </div>
            <?php 
            break;
        case 1:
            // only one region
            ?>
                        <input class="city_id" id="city_id" type="hidden" name="cityId" value="<?php 
            echo get_city_id($item);
            ?>
" />
            <?php 
            break;
        default:
            // more than one region
            ?>
                        <div class="clearfix">
                            <label><?php 
            echo $city_txt;
            ?>
</label>
                            <div class="input">
                                <select class="city_id" id="city_id" name="cityId">
                                    <option value=""><?php 
            echo $city_select_txt;
            ?>
</option>
                                    <?php 
            foreach ($aCities as $city) {
                ?>
                                        <option value="<?php 
                echo $city['pk_i_id'];
                ?>
"><?php 
                echo $city['s_name'];
                ?>
</option>
                                    <?php 
            }
            ?>
                                </select>
                            </div>
                        </div>
            <?php 
            break;
    }
}
function get_cb_data($name, $url)
{
    global $run_environment;
    global $max_records;
    $html = scraperWiki::scrape($url);
    $dom = new simple_html_dom();
    $dom->load($html);
    $count = 1;
    foreach ($dom->find("table[class=cb_table]") as $board) {
        $cb = null;
        $cb['source'] = $url;
        $cb['borough'] = $name;
        $cb['community_board'] = trim($board->find("td[class=cb_title]", 0)->plaintext);
        $cb['community_board_number'] = trim(substr($cb['community_board'], strlen('Community Board ')));
        $cb['city_id'] = get_city_id($cb['borough'], $cb['community_board_number']);
        $cb['neighborhoods'] = trim($board->find("tr", 1)->find("td", 2)->plaintext);
        $cb['precincts'] = trim($board->find("tr", 4)->find("td", 1)->plaintext);
        $cb['precinct_phones'] = trim($board->find("tr", 5)->find("td", 1)->plaintext);
        // Try to parse the unstructured contact info text
        $cb_info = trim($board->find("tr", 3)->find("td", 1)->innertext);
        $cb_info = str_replace('<strong>', '<b>', $cb_info);
        $cb_info = str_replace('</strong>', '</b>', $cb_info);
        $contacts = explode("<b>", $cb_info);
        foreach ($contacts as $val) {
            $val = str_replace("<br />", ",", $val);
            $val = trim($val);
            $val = explode("</b>", $val);
            array_walk($val, create_function('&$val', '$val = trim($val);'));
            if (!empty($val[1])) {
                $heading = trim($val[0], ",");
                $heading = trim($heading, ":");
                $heading = strtolower(str_replace(' ', '_', $heading));
                // Clean up stray html tags
                if (stripos($val[1], '<span>')) {
                    $val[1] = get_between($val[1], '<span>', '</span>');
                }
                $val[1] = trim($val[1], '</p>');
                $val[1] = trim($val[1], ',');
                $val[1] = trim($val[1], ',');
                $cb[$heading] = $val[1];
            }
        }
        // check if we have data in the email field that needs to be parsed like the website url
        if (!empty($cb['address'])) {
            $cb['address'] = trim($cb['address']);
            $cb['address'] = trim($cb['address'], ',');
            $cb['address'] = str_replace(",,", ",", $cb['address']);
            $cb['address'] = trim($cb['address']);
            $lines = explode(',', $cb['address']);
            $line_num = count($lines) - 1;
            if ($line_num >= 4) {
                $cb['address_title'] = $lines[$line_num - 4];
            } else {
                $cb['address_title'] = $cb['borough'] . ' ' . $cb['community_board'];
            }
            if ($cb['address_title'] == $lines[$line_num - 3]) {
                $cb['address_1'] = $lines[$line_num - 2];
                $cb['address_2'] = null;
            } else {
                $cb['address_1'] = $lines[$line_num - 3];
                $cb['address_2'] = $lines[$line_num - 2];
            }
            $zip = trim($lines[$line_num], ', NY ');
            $cb['address_zip'] = $zip;
            $cb['address_city'] = $lines[$line_num - 1];
            $cb['address_state'] = 'NY';
        }
        // check if we have data in the email field that needs to be parsed like the website url
        if (!empty($cb['email'])) {
            $snippet = new simple_html_dom();
            $snippet->load($cb['email']);
            if ($snippet->find('a', 0)) {
                // Isolate the email address from the other html
                if (stripos($cb['email'], '<a') > 0) {
                    $cb['email'] = trim(substr($cb['email'], 0, stripos($cb['email'], '<a')));
                    if (count($emails = explode(',', $cb['email'])) > 1) {
                        $cb['all_email'] = $cb['email'];
                        $cb['email'] = trim($emails[0]);
                        $cb['email'] = trim($cb['email'], '&#160;');
                    }
                } else {
                    $cb['email'] = null;
                    $cb['website'] = null;
                }
                $cb['website'] = $snippet->find('a', 0)->href;
                // External URLs have a proxy URL on nyc.gov, let's parse that off
                if (stripos($cb['website'], 'exit.pl')) {
                    $cb['website'] = substr($cb['website'], stripos($cb['website'], 'exit.pl?') + 12);
                }
            } else {
                $cb['website'] = null;
            }
        } else {
            $cb['email'] = null;
        }
        // Make this field universal, even if we don't have any data
        if (empty($cb['all_email'])) {
            $cb['all_email'] = null;
        }
        // verify we didn't mix up website and email
        if (!empty($cb['website']) && stripos($cb['website'], 'mailto') !== FALSE) {
            $cb['email'] = substr($cb['website'], stripos($cb['website'], 'mailto:') + 7);
            $cb['website'] = null;
        }
        // Be sure to clear any stray commas
        if (!empty($cb['email'])) {
            $cb['email'] = trim($cb['email'], ',');
        }
        // normalize field names
        if (!empty($cb['chairperson'])) {
            $cb['chair'] = $cb['chairperson'];
            unset($cb['chairperson']);
        }
        if ($run_environment == 'dev') {
            $cbs[] = $cb;
        } else {
            scraperwiki::save_sqlite(array('source', 'borough', 'community_board_number'), $cb, $table_name = 'community_board');
        }
        $count++;
        //if ($run_environment == 'dev' && $count > $max_records) break;
        // Clear memory
        $board->__destruct();
    }
    // Clear memory
    $dom->__destruct();
    if ($run_environment == 'dev') {
        return $cbs;
    } else {
        return true;
    }
}
コード例 #3
0
ファイル: item-post.php プロジェクト: nsswaga/OSClass
?>
" ;
            twitter_theme.max_images_fields_txt   = "<?php 
_e('Sorry, you have reached the maximum number of images per ad', 'twitter_bootstrap');
?>
" ;
            twitter_theme.country_select_id       = "<?php 
echo get_country_id(osc_item() != null ? osc_item() : array());
?>
" ;
            twitter_theme.region_select_id        = "<?php 
echo get_region_id(osc_item() != null ? osc_item() : array());
?>
" ;
            twitter_theme.city_select_id          = "<?php 
echo get_city_id(osc_item() != null ? osc_item() : array());
?>
" ;
            twitter_theme.ajax_url                = "<?php 
echo osc_base_url(true) . '?page=ajax';
?>
" ;
            twitter_theme.text_select_country     = "<?php 
_e('Select a country...', 'twitter_bootstrap');
?>
" ;
            twitter_theme.text_select_region      = "<?php 
_e('Select a region...', 'twitter_bootstrap');
?>
" ;
            twitter_theme.text_select_city        = "<?php 
コード例 #4
0
ファイル: news_list.inc.php プロジェクト: kong-qi/lexiu
    $cityid = $_GET['city'];
}
if ($show) {
    if ($show == 1) {
        $wherestr .= "and kq_checked='0'";
    }
    if ($show == 2) {
        $wherestr .= "and kq_checked='1'";
    }
    $pageurl .= "&show=" . $show;
}
if ($isok) {
    $wherestr .= "and kq_isok='" . $isok . "'";
}
if ($cityid) {
    $strcityid = "'" . implode("','", get_city_id($cityid)) . "'";
    $wherestr .= "and kq_city in (" . $strcityid . ")";
}
if ($keywrod) {
    $wherestr .= "and kq_title like '%" . $keywrod . "%' or id like '%" . $keywrod . "%'";
    $pageurl .= "&keyword=" . $keywrod;
}
$list_sql = $conn->selectone("" . DB_EXT . "news", "*", "where kq_lmid='" . $lanmuid . "' " . $wherestr . " order by kq_sort desc,id desc limit " . ($page - 1) * $pagesize . "," . $pagesize . "");
$list_total = $conn->rows($conn->selectall("" . DB_EXT . "news", "where kq_lmid='" . $lanmuid . "' " . $wherestr . ""));
//获取当前栏目信息
$lanmumsg = get_first_date('lanmu', "where id='" . $lanmuid . "'");
//活动
$huodong = $lanmumsg['kq_type'];
$pagename = $lanmumsg['kq_name'] . '';
//是否有权限
//编辑权限