ID,'website',true)); return get_speaker_website($ret); } function get_speaker_website($website){ $ret = trim($website ?? ''); $ret_upper = strtoupper($ret); if (strpos($ret_upper,'https://N/A')!==false || strpos($ret_upper,'HTTPS://N/A')!==false ||strpos($ret_upper,'N/A')!==false) { $ret = ''; } return $ret; /*$ret = trim($website); if (stripos($ret,'https://N/A')===0 or stripos($ret,'N/A')===0) { $ret = ''; } return $ret;*/ } function get_agenda_room($is_at_speaker_page=false){ $a = array( array('room'=>'R0', 'building'=>'International Conference Hall'), array('room'=>'R1', 'building'=>'1st Conference Room'), array('room'=>'R2', 'building'=>'2nd Conference Room'), array('room'=>'R3', 'building'=>'1st Conference Room
(學術活動中心 2 樓)'), array('room'=>'R4', 'building'=>'Flat Presentation Room
(學術活動中心 2 樓)'), ); if ($is_at_speaker_page) { $ret = []; foreach ($a as $v) { $ret[] = $v['building']; } return $ret; } return $a; } function display_speaker_box($v, $conf='', $imgsrc='', $name='', $talk_title=''){ // $v is $post $speaker_id = get_speaker_id_by_post_name($v); if($conf===''){ $conf = strtoupper($speaker->conf); } if($imgsrc===''){ $imgsrc = get_speaker_photo_imgsrc( $speaker_id+0 ); } if($name===''){ $name = substr($v->post_title, 0, strpos($v->post_title, ' -')); } if(0 && $talk_title===''){ $name = substr($v->post_title, 0, strpos($v->post_title, ' -')); if($name){ $talk_title = trim(str_replace($name.' -' , '', $v->post_title)); } } $box='
'; $box.='
'.$name.'
'; $box.='
'; $box.='

'.$name.' '.pangu($talk_title).'

'; $box.=display_post_tags($v); $post_content = $v->post_content; if (strpos($post_content,'N/A')===0) { $post_content=''; } $post_content = pangu($post_content); $box.='
'.$post_content.'
'; $box.='more '; $box.='
'; $box.='
';//.box return$box; } function get_speaker_id_by_post_name($v){ global$wpdb; $speaker_id = strpos($v->post_name, 'speaker-')===0 ? str_replace('speaker-', '', $v->post_name) : ''; if($speaker_id===''){ $tmp = $wpdb->get_row('SELECT * FROM '.TBL_SPEAKERS.' WHERE anchor="'.$v->post_name.'"'); $speaker_id = $tmp->id; } return $speaker_id; } function get_post_by_anchor($anchor){ global$wpdb; $post = $wpdb->get_row('SELECT * FROM '.$wpdb->prefix . 'posts WHERE post_name="'.$anchor.'"'); return $post; } function display_talk_title($talk_title, $speaker=NULL){ $ret = str_replace('’', "'",trim($talk_title)); if($speaker and $speaker->talk_lang){ $lang = $speaker->talk_lang; $ret = ('mandarin'===strtolower($lang) ? '🀄' : '🌐') . ' ' . $ret; $can_playback = strtolower($speaker->can_playback); $ret = ($can_playback==='yes' ? '▶️ ' : ($can_playback ? '🛑 ' : '')) . $ret; // If the speaker has not been decided, then do not show the title. if(strpos($ret,"題目")!==false){ $ret = ""; } } return $ret; } function _get_topic_speaker_title($title){ // $title=$title??[]; $title_origin = $title; $title_attrtitle = ' title="'.$title_origin.'"'; $title_style = array(); $title_split = mbStringToArray($title)??[]; $title_wordcount = 0; $need_truncate_title = count($title_split)>=23; $title=implode('',array_slice($title_split,0,23)); $title_style = $title_style ? ' style="'.implode(';',$title_style).'"' : ''; if($title!=$title_origin){$title.='...';} return array('title_attrtitle'=>$title_attrtitle, 'title'=>$title, 'title_style'=>$title_style, 'title_origin'=>$title_origin); } function get_speaker_img_filename_from_upload($speaker_id, $upload_file_name){ $ext = explode('.', $upload_file_name); $ext = $ext[count($ext)-1]; $s = $speaker_id.'~datasci!CONF'; // echo"\n\ns=";echo$s; $ret = md5($s); $ret = substr($ret,0,8).'.'.$ext; // echo"\n\nret=";echo$ret; return$ret; } function get_speaker_photo_imgsrc($speaker_id, $ary_allow_photo_ext=array('png','jpg','jpeg','PNG','JPG','JPEG')){ $imgsrc = 'speaker.png'; //default foreach($ary_allow_photo_ext as$ext){ $img_fn = get_speaker_img_filename_from_upload($speaker_id, '__.'.$ext); if(file_exists(IMG_SPEAKER_DIR.$img_fn)){ $imgsrc = $img_fn;break; } } $imgsrc = IMG_SPEAKER_URL . $imgsrc . (IS_DEV ? '?'.time() : '?'.date('md').'13'); return$imgsrc; } function setup_speaker_data($wpdb, $type='TOPIC'){ if($type=='TOPIC'){ $sql_exclude_special = ' AND id NOT IN ('.SPECIAL_SPEAKER_ID1.','.SPECIAL_SPEAKER_ID2.','.SPECIAL_SPEAKER_ID3.','.SPECIAL_SPEAKER_ID4.') '; $sql = 'SELECT * FROM '.TBL_SPEAKERS.' WHERE `hide`=0 AND `conf` IN ("AI") '.$sql_exclude_special.' ORDER BY `sort`, `name2` ASC'; # need exclude keynote-speakers ids }elseif($type=='KEYNOTE'){ $sql = 'SELECT * FROM '.TBL_SPEAKERS.' WHERE `hide`=0 AND `conf` IN ("DSK","AIK") ORDER BY CASE WHEN id=3 THEN 1 WHEN id=67 THEN 2 WHEN id=4 THEN 3 WHEN id=14 THEN 4 WHEN id=37 THEN 5 WHEN id=69 THEN 6 END;'; }else{ // SPECIAL $sql = 'SELECT * FROM '.TBL_SPEAKERS.' WHERE `hide`=0 AND id IN ('.SPECIAL_SPEAKER_ID1.','.SPECIAL_SPEAKER_ID2.','.SPECIAL_SPEAKER_ID3.','.SPECIAL_SPEAKER_ID4.') ORDER BY CASE WHEN id='.SPECIAL_SPEAKER_ID1.' THEN 1 WHEN id='.SPECIAL_SPEAKER_ID2.' THEN 2 WHEN id='.SPECIAL_SPEAKER_ID3.' THEN 3 WHEN id='.SPECIAL_SPEAKER_ID4.' THEN 5 END;'; } $a = $wpdb->get_results($sql); $ary_allow_photo_ext = array('png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG'); return array('ary_allow_photo_ext'=>$ary_allow_photo_ext, 'a'=>$a); } function mbStringToArray($string) { // http://php.net/manual/en/function.mb-split.php $strlen = mb_strlen($string); $array = array(); while ($strlen) { $array[] = mb_substr($string,0,1,"UTF-8"); $string = mb_substr($string,1,$strlen,"UTF-8"); $strlen = mb_strlen($string); } return $array; } function is_valid_link($link, $is_auto_add_http_to_check){ if(strpos($link,'://N/A')!==false){return false;} $b = filter_var($link, FILTER_VALIDATE_URL);/* || filter_var($link, FILTER_FLAG_SCHEME_REQUIRED) || filter_var($link, FILTER_FLAG_HOST_REQUIRED) || filter_var($link, FILTER_FLAG_PATH_REQUIRED) || filter_var($link, FILTER_FLAG_QUERY_REQUIRED);*/ if(isset($_GET['testwebsite'])){ var_dump($link); var_dump($b); } if(!$b && $is_auto_add_http_to_check){ $b = $b || filter_var('http://'.$link, FILTER_VALIDATE_URL); } return$b; } function get_browser_type(){ // https://stackoverflow.com/questions/5302302/php-if-internet-explorer-6-7-8-or-9 $browser = ''; $ua = strtolower($_SERVER['HTTP_USER_AGENT']); if (preg_match('~(?:msie ?|trident.+?; ?rv: ?)(\d+)~', $ua, $matches)) $browser = 'ie'.$matches[1]; elseif (preg_match('~(safari|chrome|firefox)~', $ua, $matches)) $browser = $matches[1]; return $browser; } function isDomainAvailible($domain){ // https://css-tricks.com/snippets/php/check-if-website-is-available/ //check, if a valid url is provided if(!filter_var($domain, FILTER_VALIDATE_URL)){ return false; } //initialize curl $curlInit = curl_init($domain); curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($curlInit,CURLOPT_HEADER,true); curl_setopt($curlInit,CURLOPT_NOBODY,true); curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true); //get answer $response = curl_exec($curlInit); curl_close($curlInit); if ($response) return true; return false; } function pangu($text) { // copy from https://github.com/Rakume/pangu.php/blob/master/pangu.php $cjk = '' . '\x{2e80}-\x{2eff}' . '\x{2f00}-\x{2fdf}' . '\x{3040}-\x{309f}' . '\x{30a0}-\x{30ff}' . '\x{3100}-\x{312f}' . '\x{3200}-\x{32ff}' . '\x{3400}-\x{4dbf}' . '\x{4e00}-\x{9fff}' . '\x{f900}-\x{faff}'; $patterns = array( 'cjk_quote' => array( '([' . $cjk . '])(["\'])', '$1 $2' ), 'quote_cjk' => array( '(["\'])([' . $cjk . '])', '$1 $2' ), 'fix_quote' => array( '(["\']+)(\s*)(.+?)(\s*)(["\']+)', '$1$3$5' ), 'cjk_hash' => array( '([' . $cjk . '])(#(\S+))', '$1 $2' ), 'hash_cjk' => array( '((\S+)#)([' . $cjk . '])', '$1 $3' ), 'cjk_operator_ans' => array( '([' . $cjk . '])([A-Za-z0-9])([\+\-\*\/=&\\|<>])', '$1 $2 $3' ), 'ans_operator_cjk' => array( '([\+\-\*\/=&\\|<>])([A-Za-z0-9])([' . $cjk . '])', '$1 $2 $3' ), 'bracket' => array( array( '([' . $cjk . '])([<\[\{\(]+(.*?)[>\]\}\)]+)([' . $cjk . '])', '$1 $2 $4' ), array( 'cjk_bracket' => array( '([' . $cjk . '])([<>\[\]\{\}\(\)])', '$1 $2' ), 'bracket_cjk' => array( '([<>\[\]\{\}\(\)])([' . $cjk . '])', '$1 $2' ) ) ), 'fix_bracket' => array( '([<\[\{\(]+)(\s*)(.+?)(\s*)([>\]\}\)]+)', '$1$3$5' ), 'cjk_ans' => array( '([' . $cjk . '])([A-Za-z0-9`@&%\=\$\^\*\-\+\\/|\\\])', '$1 $2' ), 'ans_cjk' => array( '([A-Za-z0-9`~!%&=;\|\,\.\:\?\$\^\*\-\+\/\\\])([' . $cjk . '])', '$1 $2' ) ); foreach ($patterns as $key => $value) { if ($key === 'bracket') { $old = $text; $new = preg_replace('/' . $value[0][0] . '/iu', $value[0][1], $text); $text = $new; if ($old === $new) { foreach ($value[1] as $value) { $text = preg_replace('/' . $value[0] . '/iu', $value[1], $text); } } continue; } $text = preg_replace('/' . $value[0] . '/iu', $value[1], $text); } $text = str_replace("\\",'',$text); preg_match_all('/http[.\/\-\:a-zA-Z0-9]+/', $text, $m); if($m and is_array($m)){ foreach($m as$mm){ if($mm and is_array($mm)){ foreach($mm as$v){ $domain = explode('//',$v)[1]; if(strpos($domain, '/')!==false){ $domain = explode('/',$domain)[0]; } $text = str_replace($v, '['.$domain.' 連結]', $text); } } } } return $text; } function get_manual_agenda_from_googlesheet(){ require_once 'google_apiclient/vendor/autoload.php'; $client = new Google_Client(); $client->setAuthConfig("/data/www/google_service_account_key__+-?e1/aia-courses-d87ec0f4cbdf.json"); $client->addScope(Google_Service_Sheets::SPREADSHEETS); $service = new Google_Service_Sheets($client); $spreadsheetId = '1lEcwlj1uIuxWLtfKY1xqcY3OTVMmbZZ864gNuwcP7Tk'; $range = '臨時_agenda!L2'; $response = $service->spreadsheets_values->get($spreadsheetId, $range); $values = $response->getValues(); return $values; }