if ($run_environment == 'dev') {
    error_reporting(E_ALL);
    require 'scraperwiki.php';
}
require 'scraperwiki/simple_html_dom.php';
$url = "http://www.floridaleagueofcities.com/directory.aspx";
$city_list = get_city_list($url);
// $alldata = $city_list;
$count = 1;
foreach ($city_list as $link) {
    $url = $link['source'];
    $city = $link['name'];
    if ($run_environment == 'prod') {
        get_city_data($city, $url);
    } else {
        $alldata[] = get_city_data($city, $url);
    }
    $count++;
    if ($run_environment == 'dev' && $count > $max_records) {
        break;
    }
}
// if testing
if ($run_environment == 'dev') {
    header('Content-type: application/json');
    print json_encode($alldata);
}
function get_city_list($url)
{
    global $run_environment;
    global $max_records;
$sql = "SELECT id_city, total_user, cambio\n                FROM record_city_grow_temp\n                WHERE period = 90\n                ORDER BY 3 DESC, 2 ASC;\n                ";
$que = mysql_query($sql) or die(mysql_error());
if ($fila = mysql_fetch_assoc($que)) {
    if ($fila['cambio'] > 0) {
        $_name_city = get_city_data($fila['id_city'], 'name');
        $hh_city_mayor_crec_3_meses = array('id_city' => $fila['id_city'], 'ciudad' => substr($_name_city, 0, strpos($_name_city, ',')), 'country' => get_country_data(get_city_data($fila['id_city'], 'id_country'), 'name'), 'pais' => get_country_data(get_city_data($fila['id_city'], 'id_country'), 'nombre'), 'cambio' => $fila['cambio'], 'cambio_number' => $fila['cambio'], 'total_user' => $fila['total_user']);
    }
}
//Imprimimos la ciudad con el mayor decremento en los últimos 90 días
//La consulta anterior se ordena en forma descendente por su cantidad de crecimiento de usuario, por tanto, el último registro contiene al país que sufrió el mayor DECREMENTO (en caso de que sea negativo).
//Nos posicionamos al último registro
mysql_data_seek($que, mysql_num_rows($que) - 1);
if ($fila = mysql_fetch_assoc($que)) {
    if ($fila['cambio'] < 0) {
        $_name_city = get_city_data($fila['id_city'], 'name');
        $hh_city_mayor_decrec_3_meses = array('id_city' => $fila['id_city'], 'ciudad' => substr($_name_city, 0, strpos($_name_city, ',')), 'country' => get_country_data(get_city_data($fila['id_city'], 'id_country'), 'name'), 'pais' => get_country_data(get_city_data($fila['id_city'], 'id_country'), 'nombre'), 'cambio' => $fila['cambio'] * -1, 'cambio_number' => $fila['cambio'] * -1, 'total_user' => $fila['total_user']);
    }
}
/************************************************ FIN ULTIMOS 30 DIAS *********************************************************/
//Estadísticas de Habla Hispana
//Por mes
if ($hh_city_mayor_crec_mes['ciudad'] != '') {
    $hh_city_mayor_crec_mes['ciudad'] = '<a href="' . URL_ROOT . 'facebook-stats/cities/' . convert_to_url_string($hh_city_mayor_crec_mes['country']) . '/" title="Estadísticas de Facebook en ' . $hh_city_mayor_crec_mes['pais'] . '">' . $hh_city_mayor_crec_mes['ciudad'] . '</a>';
    $hh_city_mayor_crec_mes['cambio'] = owloo_number_format($hh_city_mayor_crec_mes['cambio']);
} else {
    $hh_city_mayor_crec_mes['ciudad'] = '<span>sin cambio</span>';
    $hh_city_mayor_crec_mes['cambio'] = '<span>0</span>';
}
if ($hh_city_mayor_decrec_mes['ciudad'] != '') {
    $hh_city_mayor_decrec_mes['ciudad'] = '<a href="' . URL_ROOT . 'facebook-stats/cities/' . convert_to_url_string($hh_city_mayor_decrec_mes['country']) . '/" title="Estadísticas de Facebook en ' . $hh_city_mayor_decrec_mes['pais'] . '">' . $hh_city_mayor_decrec_mes['ciudad'] . '</a>';
    $hh_city_mayor_decrec_mes['cambio'] = owloo_number_format($hh_city_mayor_decrec_mes['cambio']);
Example #3
0
 /**
  * 显示编辑页面
  * @author liuxiaolin <*****@*****.**>
  * @param int $dataID 信息的ID编号
  * @param int $bool 1表示复制
  * @return void
  */
 public function edit($dataID, $bool = 0)
 {
     $dataID = (int) $dataID;
     if (empty($dataID)) {
         $errorTpl = '信息ID不正确';
         $this->error($errorTpl);
     }
     //检测新注册用户
     $checkUserInfo = $this->checkNewUserPost();
     if ($checkUserInfo['status'] == false) {
         $this->error($checkUserInfo['msg'], '', 10);
     }
     //检测发贴是否超过限制
     $check = $this->checkPostTimes();
     if ($check['status'] == false) {
         $this->error($check['msg'], '', 10);
     }
     //检测发帖间隔
     $message = $this->checkTimesInterval();
     if ($message['status'] == false) {
         $this->error($message['msg'], '', 10);
     }
     //实例化ctg_data表,获得主表数据,同时得到模型ID
     $model = M('ctgData');
     $data = $model->where(array('dataID' => $dataID))->find();
     //是否有编辑权限
     //if ($_SESSION['userName'] !== $data['userName'] && $_SESSION['adminUserName'] !== 'admin') {
     //    $errorTpl = '你没有权限编辑';
     //    $this->error($errorTpl, U('Home/Class/index'));
     //}
     //$groupID = M('user')->where(array('userID' => session('userID')))->getField('groupID');
     //if ($groupID == 4) {
     //    $this->error('你已被加入黑名单,不允许编辑');
     //}
     //如果有图片,处理图片
     if (!empty($data['picUrl'])) {
         $picData = explode('|', $data['picUrl']);
     } else {
         $picData = [];
     }
     //获得副表数据
     $fmodel = M('ctgData' . $data['modID']);
     $fdata = $fmodel->where(array('dataID' => $dataID))->find();
     //处理副表数据, 如果是数组,则转换成字符串
     foreach ($fdata as $key => $value) {
         if ($key != 'content_txt') {
             if (strpos($value, ',')) {
                 $fdata[$key] = explode(',', $value);
             }
         }
     }
     //合并主表和副表数据
     $rsdb = array_merge($data, $fdata);
     //模型-栏目数据
     $modData = get_mod_data();
     //模型ID
     $modID = $data['modID'];
     //取得模板地址
     $file = T('Ucenter@default/Post/postTpl/postTpl' . $modID);
     //如果用户模板不存在,就使用系统模板
     if (!file_exists($file)) {
         $errorTpl = '模板文件不存在,无法显示,请联系管理员';
         $this->error($errorTpl, U('Ucenter/Post/showPost'));
     }
     //取得基本模板文件
     $content = file_get_contents(T('Ucenter@default/Post/postBase'));
     //取得副表模板
     $form = file_get_contents($file);
     //如果模型允许上传图片,取得图片上传基本模板
     if ($modData[$data['ctgClassID']]['isPic'] == 1) {
         $picTpl = file_get_contents(T('Ucenter@default/Post/picTpl'));
     } else {
         $picTpl = '';
     }
     //替换上传图片模板
     $content = str_replace('{$picTpl}', $picTpl, $content);
     //替换副表模板文件
     $content = str_replace('{$postTpl}', $form, $content);
     //城市数据
     $cityData = get_city_data();
     //加密数据,其中type=1表示编辑
     if ($bool == 1) {
         $tokenArr = ['mid' => $modID, 'ctgClassID' => $data['ctgClassID'], 'type' => 0];
     } else {
         $tokenArr = ['mid' => $modID, 'dataID' => $dataID, 'type' => 1];
     }
     $token = authcode(serialize($tokenArr), 'ENCODE', C('AUTH_TOKEN'));
     //生成令牌防止重复提交
     session('token', $token);
     //一级栏目名字
     $fclassName = $modData[$modData[$data['ctgClassID']]['fctgClassID']]['ctgClassName'];
     //二级栏目名字
     $className = $modData[$data['ctgClassID']]['ctgClassName'];
     //变量赋值
     $this->assign('token', $token);
     $this->assign('cityList', $cityData[$data['gid']]);
     $this->assign('fclassName', $fclassName);
     $this->assign('className', $className);
     $this->assign('cityID', $data['cityID']);
     $this->assign('countryName', $cityData[$data['gid']][$data['cityID']]['countryName']);
     $this->assign('rsdb', $rsdb);
     $this->assign('picArr', $picData);
     $this->assign('picNum', count($picData));
     $this->show($content);
 }
// only used for testing
if ($run_environment == 'dev') {
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');
    require 'scraperwiki.php';
}
require 'scraperwiki/simple_html_dom.php';
$city_directory = "http://www.mrsc.org/cityprofiles/citylist.aspx";
$cities = get_cities($city_directory);
$count = 1;
foreach ($cities as $city) {
    if ($run_environment == 'prod') {
        scraperwiki::save_sqlite(array('data_url'), $city, $table_name = 'city');
        get_city_data($city['name'], $city['officials_url']);
    } else {
        $reps = get_city_data($city['name'], $city['officials_url']);
        $alldata[] = array('city' => $city, 'reps' => $reps);
    }
    $count++;
    if ($run_environment == 'dev' && $count > $max_records) {
        break;
    }
}
if ($run_environment == 'prod') {
    sleep(3);
    // this is required on scraperwiki.com
}
// if testing
if ($run_environment == 'dev') {
    header('Content-type: application/json');
    print json_encode($alldata);
function get_city_data($html = null, $url = null, $reps = null)
{
    global $run_environment;
    global $post_url;
    if (!empty($url)) {
        $html = scraperWiki::scrape($url);
    }
    $dom = new simple_html_dom();
    $dom->load($html);
    $count = 1;
    // for debugging
    if (!$dom->find("table", 0)) {
        echo $url;
        exit;
    }
    $table = $dom->find("table", 0);
    foreach ($table->find("tr") as $data) {
        $tds = $data->find("td");
        if (trim($tds[0]->plaintext) == 'Full Name') {
            continue;
        }
        $rep = null;
        $rep['name_full'] = trim($tds[0]->plaintext);
        $rep['city'] = trim($tds[1]->plaintext);
        $rep['title'] = trim($tds[2]->plaintext);
        $rep['source'] = 'http://events.cacities.org' . $tds[0]->find('a', 0)->href;
        $rep_details = get_rep_details($rep['source']);
        if ($run_environment == 'prod') {
            sleep(1);
            // this may be needed on scraperwiki.com
        }
        //$rep = array_merge($rep, $rep_details);
        $rep = $rep_details;
        if ($run_environment == 'dev') {
            $reps[] = $rep;
        } else {
            $reps = null;
            scraperwiki::save_sqlite(array('title', 'name_full', 'city'), $rep, $table_name = 'rep');
        }
    }
    if ($dom->find("div[class=prevNext]", 0) && ($next = $dom->find("div[class=prevNext]", 0)->find("a[class=last]", 0))) {
        $page = str_replace(' ', '%20', $next->href);
        $url = 'http://events.cacities.org' . $page;
        get_city_data(null, $url, $reps);
    }
    if ($run_environment == 'dev') {
        return $reps;
    } else {
        return true;
    }
}