function conditions(&$cond){ if($cond['type'] == 'catalogrule/rule_condition_combine'){ foreach( $cond['conditions'] as &$c ){ if(is_array($c)){ conditions($c); } } unset($c); // need for accurate delete link! }else{ //mage::D($cond); switch( $cond['attribute'] ) { case 'attribute_set_id' : $model = Mage::getModel('eav/entity_attribute_set')->load($cond['value']); $cond['value'] = $model->getAttributeSetName(); break; case 'category_ids' : $categ_arr = explode(", ", $cond['value']); foreach($categ_arr as &$c){ $c = Mage::getModel('catalog/category')->load($c)->getName(); }unset($c); $cond['value'] = implode(", ", $categ_arr); break; default : $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $cond['attribute']); if(!$attribute) { return; } $allOpts = $attribute->getSource()->getAllOptions(true, true); foreach ($allOpts as $option){ if( $option['value'] == $cond['value']){ $cond['value'] = $option['label']; } } } } }
public function index($tag_id, $offset = 0) { $columns = array(); $configs = array('article-tag', $this->tag->id, 'articles', '%s'); $conditions = conditions($columns, $configs); ArticleTagMapping::addConditions($conditions, 'article_tag_id = ?', $this->tag->id); $limit = 7; $total = ArticleTagMapping::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 3, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li class="f">', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li class="p">', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li class="n">', 'next_tag_close' => '</li>', 'last_tag_open' => '<li class="l">', 'last_tag_close' => '</li>'), $configs))->create_links(); $article_ids = column_array(ArticleTagMapping::find('all', array('select' => 'article_id', 'offset' => $offset, 'limit' => $limit, 'order' => 'article_id DESC', 'conditions' => $conditions)), 'article_id'); $articles = $article_ids ? Article::find('all', array('order' => 'FIELD(id,' . implode(',', $article_ids) . ')', 'conditions' => array('is_visibled = ? AND id IN (?) AND destroy_user_id IS NULL', Article::IS_VISIBLED, $article_ids))) : array(); if ($articles) { $this->add_meta(array('name' => 'keywords', 'content' => implode(',', column_array($articles, 'title')) . ',' . implode(',', Cfg::setting('site', 'site', 'keywords'))))->add_meta(array('name' => 'description', 'content' => $articles[0]->mini_content(150)))->add_meta(array('property' => 'og:title', 'content' => $this->tag->name . '文章' . ' - ' . Cfg::setting('site', 'site', 'title')))->add_meta(array('property' => 'og:description', 'content' => $articles[0]->mini_content(300)))->add_meta(array('property' => 'og:image', 'tag' => 'larger', 'content' => $img = $articles[0]->cover->url('1200x630c'), 'alt' => $this->tag->name . '文章' . ' - ' . Cfg::setting('site', 'site', 'title')))->add_meta(array('property' => 'og:image:type', 'tag' => 'larger', 'content' => 'image/' . pathinfo($img, PATHINFO_EXTENSION)))->add_meta(array('property' => 'og:image:width', 'tag' => 'larger', 'content' => '1200'))->add_meta(array('property' => 'og:image:height', 'tag' => 'larger', 'content' => '630'))->add_meta(array('property' => 'article:modified_time', 'content' => $articles[0]->updated_at->format('c')))->add_meta(array('property' => 'article:published_time', 'content' => $articles[0]->created_at->format('c'))); if (($tags = column_array($articles[0]->tags, 'name')) || ($tags = Cfg::setting('site', 'site', 'keywords'))) { foreach ($tags as $i => $tag) { if (!$i) { $this->add_meta(array('property' => 'article:section', 'content' => $tag))->add_meta(array('property' => 'article:tag', 'content' => $tag)); } else { $this->add_meta(array('property' => 'article:tag', 'content' => $tag)); } } } } return $this->set_title($this->tag->name . '文章' . ' - ' . Cfg::setting('site', 'site', 'title'))->set_class('articles')->set_method('index')->load_view(array('tag' => $this->tag, 'articles' => $articles, 'pagination' => $pagination, 'columns' => $columns)); }
public function index($offset = 0) { $columns = array(array('key' => 'name', 'title' => '名稱', 'sql' => 'name LIKE ?')); $configs = array('admin', $this->get_class(), '%s'); $conditions = conditions($columns, $configs); $limit = 25; $total = ArticleTag::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links(); $tags = ArticleTag::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'conditions' => $conditions)); return $this->set_tab_index(1)->set_subtitle('文章類別列表')->load_view(array('tags' => $tags, 'pagination' => $pagination, 'columns' => $columns)); }
private function _conditions($offset, $is_visibled) { $columns = array(array('key' => 'name', 'title' => '稱呼', 'sql' => 'name LIKE ?'), array('key' => 'email', 'title' => 'E-Mail', 'sql' => 'email LIKE ?'), array('key' => 'message', 'title' => '留言', 'sql' => 'message LIKE ?'), array('key' => 'ip', 'title' => 'IP', 'sql' => 'ip LIKE ?')); $configs = array('admin', $this->get_class(), '%s'); $conditions = conditions($columns, $configs); Contact::addConditions($conditions, 'is_visibled = ?', $is_visibled); $limit = 25; $total = Contact::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links(); $contacts = Contact::find('all', array('offset' => $offset, 'limit' => $limit, 'conditions' => $conditions)); return array('contacts' => $contacts, 'pagination' => $pagination, 'columns' => $columns); }
public function index($offset = 0) { $columns = array('weather_id' => 'int'); $configs = array('admin', 'call_logs', '%s'); $conditions = conditions($columns, $configs, 'CallLog', $this->input_gets()); $conditions = array(implode(' AND ', $conditions)); $limit = 25; $total = CallLog::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $configs = array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs); $this->pagination->initialize($configs); $pagination = $this->pagination->create_links(); $call_logs = CallLog::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('weather'), 'conditions' => $conditions)); $message = identity()->get_session('_flash_message', true); $this->add_js(base_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'jquery.timeago.js'))->add_js(base_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'locales', 'jquery.timeago.zh-TW.js'))->load_view(array('message' => $message, 'pagination' => $pagination, 'call_logs' => $call_logs, 'columns' => $columns)); }
public function index($offset = 0) { $columns = array('latitude' => 'string', 'longitude' => 'string'); $configs = array('admin', 'proposes', '%s'); $conditions = conditions($columns, $configs, 'Propose', $this->input_gets()); $conditions = array(implode(' AND ', array_merge($conditions, array('id_enabled = 1')))); $limit = 25; $total = Propose::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $configs = array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs); $this->pagination->initialize($configs); $pagination = $this->pagination->create_links(); $proposes = Propose::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'conditions' => $conditions)); $message = identity()->get_session('_flash_message', true); $this->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'jquery.fancybox.css'))->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'jquery.fancybox-buttons.css'))->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'jquery.fancybox-thumbs.css'))->add_css(base_url('resource', 'css', 'fancyBox_v2.1.5', 'my.css'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox.js'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox-buttons.js'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox-thumbs.js'))->add_js(base_url('resource', 'javascript', 'fancyBox_v2.1.5', 'jquery.fancybox-media.js'))->load_view(array('message' => $message, 'pagination' => $pagination, 'proposes' => $proposes, 'columns' => $columns)); }
public function index($offset = 0) { $columns = array(array('key' => 'user_id', 'title' => '作者', 'sql' => 'user_id = ?', 'select' => array_map(function ($user) { return array('value' => $user->id, 'text' => $user->name); }, User::all(array('select' => 'id, name')))), array('key' => 'is_visibled', 'title' => '是否公開', 'sql' => 'is_visibled = ?', 'select' => array_map(function ($key) { return array('value' => $key, 'text' => Article::$visibleNames[$key]); }, array_keys(Article::$visibleNames))), array('key' => 'title', 'title' => '標題', 'sql' => 'title LIKE ?'), array('key' => 'content', 'title' => '內容', 'sql' => 'content LIKE ?')); $configs = array('admin', $this->get_class(), '%s'); $conditions = conditions($columns, $configs); Article::addConditions($conditions, 'destroy_user_id IS NULL'); $limit = 25; $total = Article::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links(); $articles = Article::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('user'), 'conditions' => $conditions)); Session::setData('admin_articles_index_url', current_url()); return $this->set_tab_index(1)->set_subtitle('文章列表')->add_hidden(array('id' => 'is_visibled_url', 'value' => base_url('admin', $this->get_class(), 'is_visibled')))->load_view(array('articles' => $articles, 'pagination' => $pagination, 'columns' => $columns)); }
public function index($tag_id, $offset = 0) { $columns = array(array('key' => 'title', 'title' => '標題', 'sql' => 'title LIKE ?'), array('key' => 'content', 'title' => '內容', 'sql' => 'content LIKE ?')); $configs = array('admin', $this->get_class(), $this->tag->id, 'works', '%s'); $conditions = conditions($columns, $configs); Work::addConditions($conditions, 'destroy_user_id IS NULL'); if ($work_id = column_array(WorkTagMapping::find('all', array('select' => 'work_id', 'conditions' => array('work_tag_id = ?', $this->tag->id))), 'work_id')) { Work::addConditions($conditions, 'id IN (?)', $work_id); } else { Work::addConditions($conditions, 'id = ?', -1); } $limit = 25; $total = Work::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links(); $works = Work::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('pictures'), 'conditions' => $conditions)); return $this->set_tab_index(2)->set_subtitle($this->tag->name . '內的作品列表')->load_view(array('tag' => $this->tag, 'works' => $works, 'pagination' => $pagination, 'columns' => $columns)); }
public function index($offset = 0) { $columns = array(array('key' => 'user_id', 'title' => '作者', 'sql' => 'user_id = ?', 'select' => array_map(function ($user) { return array('value' => $user->id, 'text' => $user->name); }, User::all(array('select' => 'id, name')))), array('key' => 'title', 'title' => '標題', 'sql' => 'title LIKE ?'), array('key' => 'tag_id', 'title' => '分類', 'sql' => '(id != 0 OR id = ?)', 'select' => array_map(function ($tag) { return array('value' => $tag->id, 'text' => $tag->name); }, WorkTag::all(array('select' => 'id, name'))))); $configs = array('admin', $this->get_class(), '%s'); $conditions = conditions($columns, $configs); Work::addConditions($conditions, 'destroy_user_id IS NULL'); if (($tag_id = OAInput::get('tag_id')) && ($ids = column_array(WorkTagMapping::find('all', array('select' => 'work_id', 'conditions' => array('work_tag_id = ?', $tag_id))), 'work_id'))) { Work::addConditions($conditions, 'id IN (?)', $ids); } $limit = 25; $total = Work::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links(); $works = Work::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('user', 'pictures'), 'conditions' => $conditions)); Session::setData('admin_works_index_url', current_url()); return $this->set_tab_index(1)->set_subtitle('作品列表')->add_hidden(array('id' => 'is_enabled_url', 'value' => base_url('admin', $this->get_class(), 'is_enabled')))->load_view(array('works' => $works, 'pagination' => $pagination, 'columns' => $columns)); }
function take() { $_SESSION["obj"] = (int) $_GET["obj"]; if ($_SESSION["world"][$_SESSION["room"]]["stuff"][$_SESSION["obj"]] >= 1) { $_SESSION["world"][$_SESSION["room"]]["stuff"][$_SESSION["obj"]] -= 1; $_SESSION["stuff"][$_SESSION["obj"]] += 1; } $code = conditions(); if ($code === 0) { play(); } else { liveordie($code); } }
public function index($offset = 0) { $columns = $this->_search_columns(); $configs = array('admin', $this->get_class(), '%s'); $conditions = conditions($columns, $configs); Invoice::addConditions($conditions, 'destroy_user_id IS NULL'); $limit = 25; $total = Invoice::count(array('conditions' => $conditions)); $offset = $offset < $total ? $offset : 0; $this->load->library('pagination'); $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links(); $invoices = Invoice::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('pictures', 'user', 'tag'), 'conditions' => $conditions)); return $this->set_tab_index(1)->set_subtitle('帳務列表')->add_hidden(array('id' => 'is_finished_url', 'value' => base_url('admin', $this->get_class(), 'is_finished')))->load_view(array('invoices' => $invoices, 'pagination' => $pagination, 'columns' => $columns)); }
$output_str .= $st[1888]; } elseif ($do_all == 1) { //Leaving Goods $output_str .= load_unload_planet(0, 1); } elseif ($do_all == 2) { //taking the goods $output_str .= load_unload_planet(0, 2); } } elseif (isset($all_shield)) { // Charge all shields on all ships in system. $taken = 0; //Shields taken from planet so far. $ship_counter = 0; if ($sure != "yes") { get_var($st[1661], 'planet.php', $st[1662], 'sure', 'yes'); } elseif (conditions($user, $planet)) { $output_str .= sprintf($st[1663], $GAME_VARS[min_before_transfer]) . "<p />"; } elseif ($user['turns'] < 3) { print_page($cw['error'], $st[1664]); } elseif ($planet['shield_charge'] < 1) { print_page($cw['error'], $st[1665]); } else { db2("select ship_id,shields,max_shields,ship_name from {$db_name}_ships where login_id = '{$user['login_id']}' && location = '{$planet_loc}' && max_shields > 0 && shields < max_shields"); while ($ships = dbr2()) { //planet can charge ship w/ spare shields maybe. $free = $ships['max_shields'] - $ships['shields']; if ($free <= $planet['shield_charge'] - $taken) { $ship_counter++; dbn("update {$db_name}_ships set shields = max_shields where ship_id = '{$ships['ship_id']}'"); $out .= "<br /><b class='b1'>{$ships['ship_name']}</b> " . sprintf($st[1666], $free); if ($ships['ship_id'] == $user_ship['ship_id']) {
function scrape($state_code, $state_name) { $const_post = http_build_query(array('method' => 'loadMainNcdrcQryPg', 'stateCode' => $state_code, 'login' => '', 'distCode' => '0', 'loginType' => 'C', 'stateName' => '', 'districtName' => '', 'cid' => '', 'userType' => 'C', 'ncdrc_id' => 'ncdrc', 'state_id' => $state_code, 'state_idD' => '0', 'dist_id' => '0', 'fano' => '', 'dtFrom' => date('d/m/Y', strtotime('-10 days')), 'dtTo' => date('d/m/Y'), 'andor' => 'or')); $results = array(); for ($i = 0; $i < 2; $i++) { //POST is split up into two sets of conditions. $post = $const_post . conditions($i); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_URL => 'http://164.100.72.12/ncdrcusersWeb/login.do', CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $post)); echo "Loading data ...\n"; $dom = new DOMDocument(); @$dom->loadHTML(curl_exec($ch)); $xpath = new DOMXPath($dom); if ($xpath->query('//title')->item(0)->nodeValue != 'Query Report') { return array(); } $query = $xpath->query('//tr'); $dom = null; $xpath = null; unset($dom); unset($xpath); $n = $query->length; curl_close($ch); echo "Parsing results ...\n"; for ($j = 0; $j < $n; $j++) { $row = $query->item($j); if (!@preg_match('/No record is available/i', $row->childNodes->item(2)->nodeValue)) { @($result = array('state' => $state_name, 'case_number' => trim($row->childNodes->item(2)->nodeValue), 'complainant' => trim(str_replace('&', '&', $row->childNodes->item(4)->nodeValue)), 'respondent' => trim(str_replace('&', '&', $row->childNodes->item(6)->nodeValue)), 'complainant_advocate' => trim(str_replace('&', '&', $row->childNodes->item(8)->nodeValue)), 'respondent_advocate' => trim(str_replace('&', '&', $row->childNodes->item(10)->nodeValue)), 'filing_date' => trim($row->childNodes->item(12)->nodeValue))); if ($result['complainant'] == '-') { $result['complainant'] = ''; } if ($result['respondent'] == '-') { $result['respondent'] = ''; } if ($result['complainant_advocate'] == '-') { $result['complainant_advocate'] = ''; } if ($result['respondent_advocate'] == '-') { $result['respondent_advocate'] = ''; } if ($j > 0 && $result['case_number']) { array_push($results, $result); } } $result = null; $row = null; unset($result); unset($row); if ($j % 100 === 0) { scraperwiki::save_sqlite(array('case_number'), $results); $results = array(); } } $dom = null; $xpath = null; $query = null; $ch = null; unset($dom); unset($xpath); unset($query); unset($ch); } //Last save to database scraperwiki::save_sqlite(array('case_number'), $results); $results = null; unset($results); }
function scrape() { $const_post = http_build_query(array('method' => 'loadMainNcdrcQryPg', 'stateCode' => '0', 'login' => '', 'distCode' => '0', 'loginType' => 'B', 'stateName' => '', 'districtName' => '', 'cid' => '', 'userType' => 'B', 'ncdrc_id' => 'ncdrc', 'state_id' => '0', 'state_idD' => '0', 'dist_id' => '0', 'fano' => '', 'dtFrom' => date("d/m/Y", strtotime("-30 days")), 'dtTo' => date("d/m/Y", strtotime("+5 days")), 'andor' => 'or')); $results = array(); for ($i = 0; $i < 2; $i++) { //POST is split up into two sets of conditions because of website limitations. This executive cURL twice. $post = $const_post . conditions($i); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_URL => 'http://164.100.72.12/ncdrcusersWeb/login.do', CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $post)); echo "Loading data ...\n"; $dom = new DOMDocument(); @$dom->loadHTML(curl_exec($ch)); $xpath = new DOMXPath($dom); $query = $xpath->query('*//tr'); $n = $query->length; curl_close($ch); echo "Parsing results ...\n"; for ($j = 0; $j < $n; $j++) { $row = $query->item($j); @($result = array('case_number' => trim($row->childNodes->item(2)->nodeValue), 'complainant' => trim(str_replace('&', '&', $row->childNodes->item(4)->nodeValue)), 'respondent' => trim(str_replace('&', '&', $row->childNodes->item(6)->nodeValue)), 'complainant_advocate' => trim(str_replace('&', '&', $row->childNodes->item(8)->nodeValue)), 'respondent_advocate' => trim(str_replace('&', '&', $row->childNodes->item(10)->nodeValue)), 'filing_date' => trim($row->childNodes->item(12)->nodeValue))); if ($result['complainant'] == '-') { $result['complainant'] = ''; } if ($result['respondent'] == '-') { $result['respondent'] = ''; } if ($result['complainant_advocate'] == '-') { $result['complainant_advocate'] = ''; } if ($result['respondent_advocate'] == '-') { $result['respondent_advocate'] = ''; } if ($j > 0 && $result['case_number']) { array_push($results, $result); } $result = null; $row = null; unset($result); unset($row); } $dom = null; $xpath = null; $query = null; $ch = null; unset($dom); unset($xpath); unset($query); unset($ch); } //Save results echo "Peak memory usage: " . memory_get_peak_usage() . "\n"; scraperwiki::save_sqlite(array('case_number'), $results); }