getName(); echo'
'; echo $KEYCLOAK_USER->getEmail(); echo'
'; echo $KEYCLOAK_USER->getId(); echo'
'; } //*/ } function is_ajax_request() { return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); } function curl_post_request($url, $ary_data, $is_json_request = false) { $ch = curl_init(); $a = array(); foreach ($ary_data as $k => $v) { $a[] = $k . '=' . $v; } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $a)); // In real life you should use something like: // curl_setopt($ch, CURLOPT_POSTFIELDS, // http_build_query(array('postvar1' => 'value1'))); // Receive server response ... curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($is_json_request) { //Set the content type to application/json # https://thisinterestsme.com/sending-json-via-post-php/ curl_setopt($ch, CURLOPT_HEADER, false); $payload = json_encode($ary_data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($payload) )); } $server_output = curl_exec($ch); curl_close($ch); return $server_output; } function is_aia_staff_openid_email($email) { } function _convert_number2sortable($s) { foreach ( array( '二十' => 20, '十九' => 19, '十八' => 18, '十七' => 17, '十六' => 16, '十五' => 15, '十四' => 14, '十三' => 13, '十二' => 12, '十一' => 11, '十' => 10, '九' => '09', '八' => '08', '七' => '07', '六' => '06', '五' => '05', '四' => '04', '三' => '03', '二' => '02', '一' => '01', ) as $k => $v ) { if (strpos($s, $k) === false) { continue; } $s = str_replace($k, $v, $s); } return $s; } function normalize_aia_email($email, $need_care_valid_or_not = true) { if ($need_care_valid_or_not and !filter_var($email, FILTER_VALIDATE_EMAIL)) { var_dump($email); die('invalid AIAcademy email'); } return trim(strtolower($email)); } function get_datetime_weekday($date) { $dw = str_replace(array(' ', "\n", "\r"), '', shell_exec('date -d"' . $date . '" "+%w"')); return $dw; } function is_weekday_sunday($dw) { $dw = (int)$dw; return $dw === 0; } function fix_post_data($_POST_VALUE) { // tested on chrome if (is_int($_POST_VALUE) or is_float($_POST_VALUE)) { return $_POST_VALUE; } if (is_string($_POST_VALUE)) { return stripslashes($_POST_VALUE); } else { if (is_array($_POST_VALUE)) { foreach ($_POST_VALUE as $k => $v) { $_POST_VALUE[$k] = fix_post_data($v); } } } return $_POST_VALUE; } function now($format = 'Y-m-d H:i:s') { // %Y-%m-%d %H:%M:%S // 保存當前時區 //$originalTimeZone = date_default_timezone_get(); // 設定時區為台北時間 // date_default_timezone_set('Asia/Taipei'); $time = date($format); // 恢復原始時區 // date_default_timezone_set($originalTimeZone); return $time; // foreach(array('Y'=>'%Y', 'm'=>'%m', 'd'=>'%d', 'H'=>'%H', 'i'=>'%M', 's'=>'%S')as$k=>$v){ // $format = str_replace($k,$v,$format); // } // $ret = shell_exec("date '+".$format."'"); // #if($is_remove_new_line_break){ // $ret = str_replace(array("\r","\n"),'',$ret); // #} // return$ret; } function ajax_response($code, $data, $msg = '') { return array('code' => $code, 'msg' => $msg, 'data' => $data); } function is_aia_student_login() { // 20180712 So far, only for mgr-students return isset($_SESSION['aia_student_school_no']) && $_SESSION['aia_student_school_no']; } function get_aia_student_school_no() { // 20180712 return isset($_SESSION['aia_student_school_no']) ? $_SESSION['aia_student_school_no'] : ''; } function can_view_content() { if (get_aia_student_school_no()) { return true; } # 20180712 added this line global $KEYCLOAK_USER; if (!$KEYCLOAK_USER) { $KEYCLOAK_USER = get_keycloak_user_by_session_or_cache(); } $user = wp_get_current_user(); return (isset($KEYCLOAK_USER) && $KEYCLOAK_USER) || strpos($user->user_login, 'student') === 0 || $user->user_login; } function get_dates_diff($date1, $date2) { $datetime1 = date_create($date1); # or use new DateTime($date1); $datetime2 = date_create($date2); $interval = date_diff($datetime1, $datetime2); return $interval; } define('WEB_URL', '/'); define('STUDENT_MGR_URL', WEB_URL . 'mgr/'); define('HR_WEB_URL', WEB_URL . 'hr/'); define('ENTER_LOGS_URL', WEB_URL . 'enter_logs/'); define('ENTER_LOGS_JS_URL', ENTER_LOGS_URL . 'js/'); define('ENTER_LOGS_JS_VENDOR_URL', ENTER_LOGS_JS_URL . 'vendors/'); define('ENTER_LOGS_JQUERY_UI_URL', ENTER_LOGS_JS_VENDOR_URL . 'jquery-ui-1.12.1.custom/'); define('ENTER_LOGS_ADMIN_URL', ENTER_LOGS_URL . 'admin/'); define('ENTER_LOGS_ADMIN_LIB_URL', ENTER_LOGS_ADMIN_URL . 'lib/'); define('ENTER_LOGS_DASHBOARD_URL', ENTER_LOGS_URL . 'dashboard/'); define('ENTER_LOGS_DASHBOARD_LIB_URL', ENTER_LOGS_DASHBOARD_URL . 'lib/'); define('LIVE_DOMAIN', 'class.aiacademy.tw'); define('LIVE_DOMAIN_WITH_WWW', 'class.aiacademy.tw'); define('IS_HTTPS', stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true); define('LIVE_DOMAIN_WITH_PROTOCOL', 'https://' . LIVE_DOMAIN); function get_override_or_append_GET($ary_for_override_or_append) { $a = $_GET; // default if (!$a) { $a = $ary_for_override_or_append; } else { foreach ($ary_for_override_or_append as $k => $v) { $a[$k] = $v; } } return $a; } function getCourseCalendarHtmlFromGoogleSpreadsheet($url) { $gid = explode('&gid=', $url)[1]; $doc = explode('/', $url)[5]; $cache = ''; $fn = __DIR__ . '/cache4calendar/' . $doc . '```' . $gid . '.cache'; $s = 'no content...'; if (file_exists($fn)) { $s = file_get_contents($fn); } /*if(strpos($s, 'C.S')===false or strpos($s,'C.L')===false){ $s = getHtml($url); }*/ return $s; } function getHtml($url, $post = null) { if (isset($GLOBALS[$url])) { # echo'from memory--'.strlen($GLOBALS[$url]).'--'.$url.'
'; return $GLOBALS[$url]; } # start to try to use db cache value $WP_OPTION_KEY_BEFORE_MD5 = 'getHtml::' . $url; $WP_OPTION_KEY = md5($WP_OPTION_KEY_BEFORE_MD5); $DATE_FORMAT = 'Y-m-d H:i:s'; $opt_val = get_option($WP_OPTION_KEY); if ($opt_val) { $create_time = substr($opt_val, 0, strpos($opt_val, '@')); $now = date($DATE_FORMAT); $interval = get_dates_diff($create_time, $now); if ($interval->y === 0 && $interval->m === 0 && $interval->d === 0 && $interval->h === 0 && $interval->i < 1) { $val = substr($opt_val, strpos($opt_val, '@') + 1); # echo'from db--'.strlen($val).'--'.$url.'
'; $GLOBALS[$url] = $val; return $val; } } # realtime get $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); if (!empty($post)) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } $result = curl_exec($ch); curl_close($ch); # // echo'insert memory for '.$url.'--'.strlen($result).'--'.$WP_OPTION_KEY.'--'.$WP_OPTION_KEY.'_before_md5'; $GLOBALS[$url] = $result; update_option($WP_OPTION_KEY, date($DATE_FORMAT) . '@' . $result); update_option($WP_OPTION_KEY . '_before_md5', $WP_OPTION_KEY_BEFORE_MD5); return $result; } ####### define('LECTURER_NAME', 'lecturer'); define('LECTURER_URI_PREFIX', '/' . LECTURER_NAME . '/'); if (strpos($_SERVER['REQUEST_URI'], LECTURER_URI_PREFIX) === 0 and strlen($_SERVER['REQUEST_URI']) > strlen(LECTURER_URI_PREFIX)) { $a = explode('/', $_SERVER['REQUEST_URI']); $html = getHtml('https://' . LIVE_DOMAIN . WEB_URL . $a[2] . '/?nc'); die($html . '' #debug mark ); } /** * WordPress 基本設定檔。 * * 本檔案包含以下設定選項: MySQL 設定、資料表前綴、 * 私密金鑰、WordPress 語言設定以及 ABSPATH。如需更多資訊,請 * 前往 {@link http://codex.wordpress.org/Editing_wp-config.php 編輯 * wp-config.php} Codex 頁面。或者向您的空間提供商諮詢關於 MySQL 設定資訊。 * * 這個檔案用於安裝程式自動生成 wp-config.php 設定檔。 * 您不需要將它用於您的網站,可以手動複製這個檔案, * 並重新命名為 "wp-config.php",然後輸入相關訊息。 * * @package WordPress */ define('ROOT_PATH', dirname(__FILE__) . '/'); $DB_USER_PWD_FILE = ROOT_PATH . 'db_user_pwd.php'; if (!file_exists($DB_USER_PWD_FILE) or (isset($db_user) and !$db_user) or (isset($db_pwd) and !$db_pwd) or (isset($db_name) and !$db_name)) { // ** MySQL 設定 - 您可以從主機服務提供商獲取相關資訊。 ** // /** WordPress 的資料庫名稱,請更改 "database_name_here" */ define('DB_NAME', 'class_aiacademy_tw'); /** MySQL 資料庫使用者名稱,請更改 "username_here" */ define('DB_USER', 'root'); /** MySQL 資料庫密碼,請更改 "password_here" */ define('DB_PASSWORD', 'swC651121!#'); } else { require_once $DB_USER_PWD_FILE; define('DB_NAME', $db_name); /** MySQL database username */ define('DB_USER', $db_user); /** MySQL database password */ define('DB_PASSWORD', $db_pwd); } /** MySQL 主機位址 */ define('DB_HOST', 'mysql8'); /** 建立資料表時預設的文字編碼 */ define('DB_CHARSET', 'utf8mb4'); /** 資料庫對照型態。如果不確定請勿更改。 */ define('DB_COLLATE', 'utf8_unicode_ci'); /**#@+ * 認證唯一金鑰設定。 * * 將這些更改為不同的唯一字串或符號。 * 您可以使用 {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org 私密金鑰服務} 來自動產生。 * 您可於任何時候修改這些字串讓 Cookies 失效。這將會強制所有使用者必須重新登入。 * * @since 2.6.0 */ /* define('AUTH_KEY', 'A%+E/S1/]p%(#tAX!mm$Nmx?; dFq|7XZ)B@nl=80b4lx$g$5n_|{CroI*u*O+jd'); define('SECURE_AUTH_KEY', 'vFTqk2t$8@q*gyfbjP&V)^j1S}&bP,_(yiO6o^y`bDOQ4Vl)yHDMR;qn[ l.PTIH'); define('LOGGED_IN_KEY', 'O]Q ud l`^&-0)tQQvDD1]JR/V=FtUXr) y5?:a;ohBb6V^Q!4 [kk`eK(ez!Bj5'); define('NONCE_KEY', 'u.(ihOLvw!yog=}5MqQ`zk6$PqAPj|r`trIpYgyXpx_m~!1:;bQE(B1vMjb9Wez$'); define('AUTH_SALT', '$,?rk8vm1GN5SA`M&anLDw8vi=yCTr-,XSvoP+5~)&0GXk9LlMIq{r=ivWI_t/>_'); define('SECURE_AUTH_SALT', 'GpOjf|!0nnjN{8PF[bl@}-x#0QqBh2cfdhq)(j9K<*vXb[@?_.(z WDd2GJr!z0m'); define('LOGGED_IN_SALT', '(CGLK!-Q7?YggmYnGC&_0`t#TArVdg[Te7`@X56m3gg2.JRPjYi8SEO_w['); define('NONCE_SALT', '~@&qrSG;8v._YnyqScHVuHTq!DOPojPFSwnceZ?j53$f3X]h[bYCc*:>ObAF m)nn1UO`D3@*{Eq1_@!Hw>W2Tq'); define('LOGGED_IN_KEY', 'HmG&btcn;,-xCi-vYTM@ajiekgJv?,/#}.A<[kw9*b&,||>:Y{O=-7o,[Yd$Y`1Q'); define('NONCE_KEY', 'sW1parent); return $video_cat_area_code; } function get_video_cat_joinno($cat_id = 0) { $cat_id = $cat_id ? $cat_id : get_query_var('cat') + 0; $cur_cat = get_category($cat_id); $tmp = explode('-', $cur_cat->slug); return $tmp[count($tmp) - 1]; } define('HOME_PAGE_ID', 4); function d() { } function dd() { } function is_facebook_bot() { return isset($_SERVER['HTTP_USER_AGENT']) && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'facebook') !== false; } function is_twitter_bot() { return isset($_SERVER['HTTP_USER_AGENT']) && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'twitter') !== false; } function is_google_bot() { return isset($_SERVER['HTTP_USER_AGENT']) && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'google') !== false; } function is_bot() { $b = isset($_SERVER['HTTP_USER_AGENT']) && ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'bot') !== false || is_google_bot() || is_facebook_bot() || is_twitter_bot() ); return $b; } function need_og_tags() { return is_facebook_bot() || is_twitter_bot(); # https://dev.twitter.com/cards/getting-started#crawling } function need_twitter_card_tags() { return is_twitter_bot(); } function my_safe_html($s, $ary_allow = array()) { foreach ($ary_allow as $k => $v) { $s = str_replace($k, $v, $s); } $s = htmlspecialchars($s); foreach ($ary_allow as $k => $v) { $s = str_replace($v, $k, $s); } return $s; } function safe_db_value($s) { return str_replace(array('=', '--', ';', '"', "'"), '', $s); } function str_replace_first($from, $to, $content) { # https://stackoverflow.com/questions/1252693/using-str-replace-so-that-it-only-acts-on-the-first-match $from = '/' . preg_quote($from, '/') . '/'; return preg_replace($from, $to, $content, 1); } function auto_add_target_blank($content) { preg_match_all('/]+>/i', $content, $m); foreach ($m as $k => $v) { foreach ($v as $k2 => $v2) { #echo $k.'--'.$k2.'--'. htmlspecialchars($v2); if (strpos($v2, ' href="http') !== false and strpos($v2, $_SERVER['SERVER_NAME']) === false and strpos($v2, 'target="_blank"') === false) { $content = str_replace($v2, substr($v2, 0, strlen($v2) - 1) . ' target="_blank">', $content); } } } return $content; } function imgsrc_rm_domain($imgsrc) { $b = false; $a = array($_SERVER['SERVER_NAME'], LIVE_DOMAIN, LIVE_DOMAIN_WITH_WWW); $a = array_unique($a); foreach ($a as $domain) { if (strpos($imgsrc, $domain) !== false) { $b = $domain; break; } } if ($b) { list($tmp, $imgsrc) = explode($b, $imgsrc); } return $imgsrc; } function get_attribute_value_in_one_tag($tag_html, $attr = 'src') { preg_match('/ ' . $attr . '=".+?"/i', $tag_html, $m); return str_replace(array(' ' . $attr . '="', '"'), '', $m[0]); } function get_all_imgsrc($html) { preg_match_all('/ src=".*?"/', $html, $m); $ret = array(); if ($m) { foreach ($m[0] as $v) { $v = str_replace(' src=', '', $v); $v = substr($v, 1); $v = substr($v, 0, strlen($v) - 1); $ret[] = $v; } } return $ret; } function display_img($imgsrc, $attr = '', $need_lazy_loading = true) { if ($attr and strpos($attr, ' ') !== 0) { $attr = ' ' . $attr; } $img = ''; if (!$need_lazy_loading) { return $img; } return '' . implode(' data-original=', explode(' src=', $img, 2)) #https://stackoverflow.com/questions/1252693/ ; } function get_featured_imgsrc($post_id, $ary_size_conf = array(320, 320)) { $imgsrc = ''; $html_thumb = get_the_post_thumbnail($post_id, $ary_size_conf); $thumb = preg_match('/ src=".*?"/', $html_thumb, $m); if (isset($m[0]) && $m[0] != '') { $imgsrc = str_replace(array('"', " src="), '', $m[0]); } return $imgsrc; } $ary_frontend_modules_config = array( // https://github.com/kazzkiq/balloon.css/blob/master/balloon.css // 'balloon'=>array('CSS'=>$IS_PC ? array(CSS_URL.'balloon.css') : array()) // using Javascript dynamic loading /* */ 'bootstrap' => array( 'CSS' => array(BOOTSTRAP_URL . 'css/bootstrap.min.css', BOOTSTRAP_URL . 'css/bootstrap-theme.min.css'), 'JS' => array(BOOTSTRAP_URL . 'js/bootstrap.min.js') ), 'bootstrap_daterangepicker' => array( 'CSS' => array( BS_DATERANGEPICKER_URL . 'daterangepicker.css' ), 'JS' => array( BS_DATERANGEPICKER_URL . 'moment.min.js', BS_DATERANGEPICKER_URL . 'daterangepicker.js', // // 'https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js', // lt IE9 // 'https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js', // lt IE9 ) ), 'base' => array('CSS' => array(CSS_URL . 'base.css' . FE_VER)), 'lazyload' => array('JS' => array(JS_URL . 'lazyload.js')), 'banner' => array('CSS' => array(CSS_URL . 'banner.css'), 'JS' => array(JS_URL . 'banner.js')), 'fonts' => array('CSS' => array(CSS_URL . 'fonts.css')), 'animations' => array('CSS' => array(CSS_URL . 'animations.css')), ); array_unshift( $ary_frontend_modules_config['bootstrap_daterangepicker']['CSS'], $ary_frontend_modules_config['bootstrap']['CSS'][0], $ary_frontend_modules_config['bootstrap']['CSS'][1] ); array_unshift( $ary_frontend_modules_config['bootstrap_daterangepicker']['JS'], $ary_frontend_modules_config['bootstrap']['JS'][0] ); function get_frontend_by_page_id($page_id, $type) { $ary_conf = array( '439' => array('CSS' => CSS_URL . 'articles-of-association.css', 'JS' => JS_URL . 'articles-of-association.js') ); $ret = ''; if (isset($ary_conf[$page_id]) and isset($ary_conf[$page_id][$type]) and $ary_conf[$page_id][$type]) { $asset = $ary_conf[$page_id][$type]; if ($type == 'JS') { $ret .= ''; } else { $ret .= ''; } } return $ret; } function collect_frontend_assets($ary_frontend_modules) { global $ary_frontend_modules_config; $ary_CSS = $ary_JS = array(); foreach ($ary_frontend_modules as $module) { $assets = $ary_frontend_modules_config[$module]; foreach (array('JS', 'CSS') as $type) { // if(!is_array($assets[$type])){var_dump($assets[$type]);continue;} if (!isset($assets[$type]) or !is_array($assets[$type])) { continue; } foreach ($assets[$type] as $url) { if (!in_array($url, ${'ary_' . $type})) { array_push(${'ary_' . $type}, $url); } } } } return array('CSS' => $ary_CSS, 'JS' => $ary_JS); } function get_css_js_assets_handle($css_js_relative_url) { if (strpos($css_js_relative_url, '?') !== false) { list($css_js_relative_url, $_) = explode('?', $css_js_relative_url); } $css_js_relative_url = str_replace('/', '-', $css_js_relative_url); $css_js_relative_url = str_replace('.', '_', $css_js_relative_url); $handle = 'ZZZ' . $css_js_relative_url; return $handle; } function load_css_assets($ary_css, $launch_css_path = '') { if (!is_array($ary_css)) { var_dump($ary_css); return; } if ($launch_css_path) { array_push($ary_css, $launch_css_path); } foreach ($ary_css as $v) { if ($v) { // echo''; wp_enqueue_style(get_css_js_assets_handle($v), $v); } } } function load_js_assets($ary_js, $launch_js_path = '') { if (!is_array($ary_js)) { var_dump($ary_js); return; } if ($launch_js_path) { array_push($ary_js, $launch_js_path); } foreach ($ary_js as $v) { if ($v) { // echo''; wp_enqueue_script(get_css_js_assets_handle($v), $v); } } } function get_customize_field_post_meta($post_id, $is_force_convert_to_string) { $a = get_post_meta($post_id); $ret = array(); foreach ($a as $k => $v) { if (substr($k, 0, 1) === '_') { continue; } if ($is_force_convert_to_string) { $ret[$k] = is_array($v) && count($v) > 0 ? $v[0] : ''; } else { $ret[$k] = $v; } } return $ret; } function get_uri_without_querystring() { $uri = $_SERVER['REQUEST_URI']; if (strpos($uri, '?') !== false) { list($uri,) = explode('?', $uri); } return $uri; } function get_sql_limit($page, $pagesize) { if ($page == 1) { return ' LIMIT ' . $pagesize; } return ' LIMIT ' . (($page - 1) * $pagesize) . ', ' . $pagesize; } function display_date($date, $find = '-', $to = '/') { $s = str_replace($find, $to, $date); return $s; } function convert_num2day($num) { $a = array('?', '一', '二', '三', '四', '五', '六', '日'); return isset($a[$num]) ? $a[$num] : '---'; } function get_video_title($post, $video_cat_area_code, $video_cat_joinno) { $debug = isset($_GET['deb']); $title_prefix = ''; $s = get_post_meta($post->ID, 'limit_at_join_no_and_place', true); if ($s) { $a = explode(',', $s); foreach ($a as $_) { list($course_date, $area_code, $join_no) = explode('-', $_); if ( $area_code == $video_cat_area_code /*lowercase*/ and $join_no == $video_cat_joinno ) { $title_prefix = $course_date; # for student break; } } if ($title_prefix == '') { ## for /wp-admin/ if ($debug) { $title_prefix = $s; } else { $title_prefix = explode('-', $a[0]); $title_prefix = $title_prefix[0]; } } } return ($title_prefix ? $title_prefix . ' ' : '') . $post->post_title . ($debug ? 'debug=' . $video_cat_area_code : ''); } function bread($uri) { $ret = '
  • 首頁
  • '; if (is_category()) { $cat_id = get_query_var('cat') + 0; $ret .= '
  • ' . get_cat_name($cat_id) . '
  • '; } elseif (is_single()) { global $post; $cats = get_the_category(); $IS_LECTURER_CAT = $IS_VIDEO_CAT = false; $v = $cats[0]; if ($v->cat_ID == LECTURER_CAT_ID) { $IS_LECTURER_CAT = true; } if ($IS_LECTURER_CAT) { $ret .= '
  • 全部師資
  • '; } elseif ($IS_VIDEO_CAT) { $ary_video_cats_parent = array(); $ary_video_cats_parent[TAIPEI_AREA_CODE] = TP_TECH_VIDEO_CAT_ID; $ary_video_cats_parent[HSINCHU_AREA_CODE] = HC_TECH_VIDEO_CAT_ID; $ary_video_cats_parent[TAICHUNG_AREA_CODE] = TC_TECH_VIDEO_CAT_ID; $ary_video_cats_parent[SOUTH_AREA_CODE] = ST_TECH_VIDEO_CAT_ID; foreach ($cats as $c) { if (in_array($c->parent, $ary_video_cats_parent)) { $IS_VIDEO_CAT = true; } $tmp = explode('-', $c->slug); if ( $c->parent === $ary_video_cats_parent[$video_cat_area_code] and $tmp[count($tmp) - 1] == $video_cat_joinno ) { $v = $c; } } $ret .= '
  • ' . $v->cat_name . '
  • '; } if ($IS_VIDEO_CAT) { $post_title = get_video_title($post, $video_cat_area_code, $video_cat_joinno); } else { $post_title = $post->post_title; } $ret .= '
  • ' . $post_title . '
  • '; } else { // start not-single $define_names = get_post_meta(HOME_PAGE_ID, 'bread_names_by_nodejs_crontab', true); if (!$define_names) { # avoid nodejs/crontab disable $define_names = get_post_meta(HOME_PAGE_ID, 'bread_names', true); } $define_names = explode("\n", $define_names); $ary_define_names = array(); foreach ($define_names as $v) { $_ = explode('=', $v); $ary_define_names[$_[0]] = $_[1]; } $paths = get_post_meta(HOME_PAGE_ID, 'bread_paths_by_nodejs_crontab', true); if (!$paths) { # avoid nodejs/crontab disable $paths = get_post_meta(HOME_PAGE_ID, 'bread_paths', true); } $ary_paths = explode("\n", $paths); # $slug = ''; foreach (explode('/', $uri) as $v) { if ($v) { $slug = $v; } #get the last one post_name } $slug = str_replace("\r", '', $slug); # foreach ($ary_paths as $v) { if (strlen($v) <= 1) { continue; } $_ = explode('<', $v); $_0 = str_replace("\r", '', $_[0]); #if(isset($_GET['ee'])){echo$slug.'--'.$_0;var_dump($slug==$_0);echo'
    ';} if ($slug == $_0) { $count_ = count($_); for ($i = $count_ - 1; $i > 0; $i--) { $href = str_replace("\r", '', $_[$i]); $ret .= '
  • ' . $ary_define_names[$href] . '
  • '; } $ret .= '
  • ' . $ary_define_names[$slug] . '
  • '; break; } } } //end not-single return '
      ' . $ret . '
    '; } define('TBL_EXAM', 'exam'); # might rename to exam_answer define('TBL_EXAM_SCORE', 'exam_score'); # might rename to exam_answer_score define('TBL_AM_I_STUDENT', 'am_i_student'); define('TBL_SUBSCRIBE', $table_prefix . '_subscribe'); define('TBL_SUBSCRI_HISTORY', $table_prefix . '_subscri_history'); /* 設定完成,請儲存檔案。然後開始 Blogging 吧! */ // error_reporting(E_ALL); // ini_set('display_errors', 1); /** WordPress 目錄的絕對路徑。 */ if (!defined('ABSPATH')) define('ABSPATH', dirname(__FILE__) . '/'); define('MMR_CACHE_DIR', ABSPATH . 'fe'); # front-end define('MMR_CACHE_URL', '/fe'); define('COMPETITION201803_OPEN_DATETIME', '2018-04-02 13:00'); define('TBL_COMPETITION_UPLOAD', 'competition_upload'); define('TBL_COMPETITION_TEAM', 'competition_team'); define('TBL_COMPETITION_MEMBER', 'competition_member'); define('COMPETITION_MAX_UPLOAD_TIMES', 25); define('COMPETITION_DATA_FILEPATH', ABSPATH . '/competition_data/201803ans.csv'); #official define('COMPETITION_TEAM_DATA_FILEPATH', ABSPATH . '/competition_data/team/'); #team define('COMPETITION_TEAM_DATA_URI', WEB_URL . 'competition_data/team/'); function get_competition_team_members($team_id = '') { global $wpdb; $where = $team_id ? ' AND team_id=' . $team_id : ''; $ret = $wpdb->get_results('SELECT * FROM ' . TBL_COMPETITION_MEMBER . ' INNER JOIN ' . TBL_COMPETITION_TEAM . ' USING(team_id) WHERE 1 ' . $where); return $ret; } function get_competition_team_name($school_no, $key = '') { global $wpdb; $where = ' AND school_no="' . $school_no . '"'; $ret = $wpdb->get_row('SELECT * FROM ' . TBL_COMPETITION_MEMBER . ' INNER JOIN ' . TBL_COMPETITION_TEAM . ' USING(team_id) WHERE 1' . $where); if (!$key) { return $ret; } elseif ($key == 'team_id') { return $ret->team_id; } elseif ($key == 'team_name') { return $ret->team_name; } } if (0 and isset($_GET['amp'])) { die(' Hello, AMP world. '); } //check cache START function get_keycloak_login_cache_cookie_value($string_keycloak_user) { return md5('academy---' . $string_keycloak_user . '---AI'); } function get_keycloak_login_cache_row($cookie_value) { global $wpdb; $sql = 'SELECT * FROM ' . TBL_KEYCLOAK_LOGIN_CACHE . ' WHERE cookie_value="' . $cookie_value . '" AND create_datetime>=((NOW() - INTERVAL 30 DAY))'; $row = $wpdb->get_row($sql); return $row; } function get_keycloak_user_by_session_or_cache() { #var_dump($_SESSION['keycloak_user']); echo'
    '; var_dump($_COOKIE[KEYCLOAK_COOKIE_KEY]); // Session if (isset($_SESSION['keycloak_user']) and $_SESSION['keycloak_user']) { // die(unserialize($_SESSION['keycloak_user'])); $data_unserialize = unserialize($_SESSION['keycloak_user']); // return unserialize($_SESSION['keycloak_user']); if ($_SERVER['REMOTE_ADDR'] == '61.222.27.93') { // print_r($data_unserialize); // die("###end###"); } return $data_unserialize; } // Cookie if (isset($_COOKIE[KEYCLOAK_COOKIE_KEY]) and $_COOKIE[KEYCLOAK_COOKIE_KEY]) { $cookie_value = $_COOKIE[KEYCLOAK_COOKIE_KEY]; $row = get_keycloak_login_cache_row($cookie_value); if ($row and $row->keycloak_user) { return unserialize(base64_decode($row->keycloak_user)); } } return null; } // // Save user into DB // $ALSO_UPDATE_CACHEandDB_START_TIME = false; // unknow 100% Spec/Goal. Set `false` for current. // $cookie_value=null; // if(isset($_SESSION['keycloak_user']) and $_SESSION['keycloak_user']){ // from session // $cookie_value = get_keycloak_login_cache_cookie_value($_SESSION['keycloak_user']); // }elseif($ALSO_UPDATE_CACHEandDB_START_TIME){ // from cache // $_keycloak_user_from_cache = serialize(get_keycloak_login_cache_row()); // if($_keycloak_user_from_cache){ // $cookie_value = get_keycloak_login_cache_cookie_value($_keycloak_user_from_cache); // } // } // $bool = ((isset($_SESSION['keycloak_user']) and $_SESSION['keycloak_user']) # <--- means ONLY ADD/UPDATE while just loginned // or $ALSO_UPDATE_CACHEandDB_START_TIME); // #var_dump($bool);var_dump($cookie_value); // if($bool){ // setcookie(KEYCLOAK_COOKIE_KEY, $cookie_value, time()+2678400); // 1 month // $_keycloak_user = serialize(get_keycloak_user_by_session_or_cache()); // #var_dump($_keycloak_user); #var_dump($cookie_value); // $row = get_keycloak_login_cache_row($cookie_value); // if($row){ // $wpdb->update(TBL_KEYCLOAK_LOGIN_CACHE, // array('create_datetime'=>shell_exec("date '+%Y-%m-%d %H:%M:%S'"), 'keycloak_user'=>base64_encode($_keycloak_user)), // array('cookie_value'=>$cookie_value)); // }else{ // $wpdb->insert(TBL_KEYCLOAK_LOGIN_CACHE, array( // 'cookie_value'=>$cookie_value, // 'create_datetime'=>shell_exec("date '+%Y-%m-%d %H:%M:%S'"), // 'keycloak_user'=>base64_encode($_keycloak_user), // )); // } // } // $uri = $_SERVER['REQUEST_URI']; // $uri_without_querystring = explode('?',$uri)[0]; // $is_whitelist_no_need_student_login = false; // $ary_bypass_uri = array( // '/stedglogin', // '/enter_logs', // '/wp-admin', // '/wp-login.php', // '/tools/vimeo/', // '/staff/', // STUDENT_MGR_URL, // '/exam/', // '/notification/', // '/vote/', // '/aigc2023-ddmc', // '/wp-content/themes/bridge/css/custom_css.php', // '/wp-content/themes/bridge/css/style_dynamic.php', // '/wp-content/themes/bridge/css/style_dynamic_responsive.php', // '/wp-content/themes/bridge/js/default_dynamic.php', // HR_WEB_URL // ); // $ary_bypass_uri[] = '/student'; // $ary_bypass_uri[] = '/api/v2'; // $ary_bypass_uri[] = '/api'; // foreach($ary_bypass_uri as$uri){ // if(strpos($uri_without_querystring, $uri)===0){$is_whitelist_no_need_student_login=true;break;} // } // if($is_whitelist_no_need_student_login || $uri_without_querystring==='' || $uri_without_querystring==='/' // || (isset($_GET['door_key']) && $_GET['door_key']==='sadfoiweuSLKJKLIOSFewS12148978090232lajslf') // ){ // //do nothing // }else{ // if(!can_view_content()){ // $KEYCLOAK_USER = get_keycloak_user_by_session_or_cache(); // # mgr can access class now. // #if(is_mgr_student($KEYCLOAK_USER)){ // # header('location:http://video.aiacademy.tw/?cannot_access_class'); // # exit; // #} // die('
    請先登入
    '); // #die('
    請先登入:
    經理人班技術班
    '); // } // } $need_login_data = preg_match(AIA_CALENDAR_URL_PATTERN, $_SERVER['REQUEST_URI']) === 1; foreach (array('/competition-upload', '/competition-upload-history', '/competition-result') as $v) { if (strpos($_SERVER['REQUEST_URI'], $v) === 0) { $need_login_data = true; break; } } # 20180327 START IBM Competition // $u = wp_get_current_user(); // $user_login = ($u->user_login); // if(in_array($user_login, array('fareastone','ibm')) and strpos($_SERVER['REQUEST_URI'], WEB_URL.'competition')!==0 and strpos($_SERVER['REQUEST_URI'], WEB_URL.'wp-admin')!==0 and $_SERVER['REQUEST_URI']!=='/' and strpos($_SERVER['REQUEST_URI'], '/wp-login.php')!==0){ // die('Not allow for this username.'); // } # 20180327 END IBM Competition #implement cache $USE_CACHE = !isset($_GET['nc']); #nc means no_Vcache if ( $USE_CACHE and !$need_login_data and false # <-- because everypage need correct window.studentUserName ) { define('VCACHE_FOLDER_NAME', 'Vcache-aiaaia'); $uri = $_SERVER['REQUEST_URI']; $a = explode('?', $uri); #while development $uri = $a[0]; if ($uri === '' || $uri === '/') { $filename = 'DO-NOT-CACHE-AT-HOME'; #'index'; } else { if (substr($uri, 0, 1) === '/') { $uri = substr($uri, 1); } if (substr($uri, -1) === '/') { $uri = substr($uri, 0, -1); } $filename = str_replace('/', '---', $uri); } $cache_file = __DIR__ . '/' . VCACHE_FOLDER_NAME . '/' . $filename; if (file_exists($cache_file)) { $html = file_get_contents($cache_file); if ($html) { die($html); } } } function get_string_by_tmpl($str_tmpl, $dict = array()) { $ret = $str_tmpl; foreach ($dict as $k => $v) { $ret = str_replace('{{' . $k . '}}', $dict[$k], $ret); } $ret = preg_replace('/{{.*?}}/', '', $ret); return $ret; } function _get_week_day($date, $is_display_chinese_number = true) { $w = date('w', strtotime($date)); if ($is_display_chinese_number) { $A = array('日', '一', '二', '三', '四', '五', '六'); return $A[$w]; } return $w; } function post_request($url, $ary_data, $referer = '') { # http://www.jonasjohn.de/snippets/php/post-request.htm // Convert the data array into URL Parameters like a=b&foo=bar etc. $data = http_build_query($ary_data); // parse the given URL $url = parse_url($url); if ($url['scheme'] != 'http') { die('Error: Only HTTP request are supported !'); } // extract host and path: $host = $url['host']; $path = $url['path']; // open a socket connection on port 80 - timeout: 30 sec $fp = fsockopen($host, 80, $errno, $errstr, 30); if ($fp) { // send the request headers: fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); if ($referer != '') fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: " . strlen($data) . "\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = ''; while (!feof($fp)) { // receive the results of the request $result .= fgets($fp, 128); } } else { return array( 'status' => 'err', 'error' => "$errstr ($errno)" ); } // close the socket connection: fclose($fp); // split the result header from the content $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; // return as structured array: return array( 'status' => 'ok', 'header' => $header, 'content' => $content ); } /** 設定 WordPress 變數和包含的檔案。 */ require_once(ABSPATH . 'wp-settings.php'); // define('FS_METHOD', 'direct'); // define('WP_MEMORY_LIMIT', '256M'); // define('WP_MAX_MEMORY_LIMIT', '256M'); //set php debug by ini_set // if ( // strpos($_SERVER['HTTP_HOST'], 'dev') !== false // ) { // ini_set('display_errors', 1); // ini_set('display_startup_errors', 1); // error_reporting(E_ALL); // } // require_once __DIR__ . '/../student/app/Helpers/get_laravel_auth_status.php'; // require_once $_SERVER['DOCUMENT_ROOT'] . '/../student/app/Helpers/get_laravel_auth_status.php';