getConnection(); $conference = new Conferencia($db); $stmt = $conference->file_list( LOCALE ); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); $thumb_urls = []; $youtube_urls = []; $video_urls = []; $audio_urls = []; $pdf_simple_urls = []; $pdf_booklet_urls = []; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $response_item=array( //"title" => $title, "wpid" => $ID ); $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $code = getFilePrefix() . '-' . date("Y-m-d", strtotime( $date ) ) . '-' . $no_activity; //Title $newTitle = sanitize_title( $title ); $fixedNewTitle = str_replace( '-','_',$newTitle ); $newFilename = $code . "-" . $fixedNewTitle . "-" . strtoupper( substr( $city , 0 , 3 ) ) . strtoupper( $country ); //$response_item['date'] = $date; //$response_item['activity'] = $no_activity; $response_item['fileslug'] = getFilePrefix() . '-' . $date . '-' . $no_activity . '_' . $slug; if($thumbnail != '' && $thumbnail != null){ //$response_item['thumbnail'] = 'https://ewr1.vultrobjects.com/lgccc-conferences/' . $thumbnail; array_push($thumb_urls,'https://ewr1.vultrobjects.com/lgccc-conferences/' . $thumbnail); } $fileData = $conference->get_post_files( $ID, LOCALE ); $files = $fileData->fetch(PDO::FETCH_ASSOC); if($files['youtube']!=''){ //$response_item['youtube'] = str_replace( 'http://', 'https://', $files['youtube']); array_push($youtube_urls,str_replace( 'http://', 'https://', $files['youtube'])); } if($files['videofile'] != '' && $files['videofile'] !== null){ //$response_item['video'] = $conference->get_post_file($files['videofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; array_push($video_urls,$conference->get_post_file($files['videofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']); } else if($files['video'] != '' && $files['video'] !== null) { //$response_item['video'] = str_replace( 'http://', 'https://',$files['video']); array_push($video_urls,str_replace( 'http://', 'https://',$files['video'])); } if($files['audiofile'] != '' && $files['audiofile'] !== null){ array_push($audio_urls,$conference->get_post_file($files['audiofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']); } else if ($files['audio'] != '' && $files['audio'] !== null){ array_push($audio_urls,str_replace( 'http://', 'https://',$files['audio'])); } if($files['pdffile'] != '' && $files['pdffile'] !== null){ array_push($pdf_booklet_urls,$conference->get_post_file($files['pdffile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']); } else if ( $files['pdf'] != '' && $files['pdf'] !== null ){ array_push($pdf_booklet_urls,str_replace( 'http://', 'https://',$files['pdf'])); } if($files['pdfsimplefile'] != '' && $files['pdfsimplefile'] !== null){ array_push($pdf_simple_urls,$conference->get_post_file($files['pdfsimplefile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']); } else if ( $files['pdf_simple'] != '' && $files['pdf_simple'] !== null){ array_push($pdf_simple_urls,str_replace( 'http://', 'https://',$files['pdf_simple'])); } //$response_item['translations'] = $translations; //Image metadata for thumbnail use. TODO: Optimize this return array //$response_item['meta'] = unserialize($meta); /*$dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $date ) ); $response_item['nicedate'] = ucfirst($formatter->format($dt)); $response_item['location'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE ))));*/ array_push($conferences_arr, $response_item); } } //Add activities data as well //$activities_json = json_decode(file_get_contents('https://actividadeswp.carpa.com/wp-admin/admin-ajax.php?action=processQueue'), JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK ); //$all_data = array_merge($conferences_arr,$activities_json); $temp_arr = array_reverse($conferences_arr); $data = array( 'count' => count($temp_arr), 'result' => array ( 'conferencias' => $temp_arr, 'thumbs' => $thumb_urls, 'videos' => $video_urls, 'audios' => $audio_urls, 'pdfs' => $pdf_simple_urls, 'pdf_booklets' => $pdf_booklet_urls ) ); send_response( $data ); } function conference_list_lgccctv(){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $stmt = $conference->lgccctv_list( LOCALE ); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $response_item=array( "title" => $title ); $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = $date; $response_item['activity'] = $no_activity; $dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $date ) ); $response_item['nicedate'] = ucfirst($formatter->format($dt)); $response_item['location'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); array_push($conferences_arr, $response_item); } } //Add activities data as well $activities_json = json_decode(file_get_contents('https://actividadeswp.carpa.com/wp-admin/admin-ajax.php?action=processQueue'), JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK ); $all_data = array_merge($conferences_arr,$activities_json); $data = array( 'count' => count($all_data), 'result' => array ( 'conferencias' => $all_data ) ); send_response( $data ); } /** * Create conference list with cache option */ function conferences_list( $year, $month, $last_update, $text, $cache, $algolia=false ){ if( $cache==false ){ //Cache directory $dir = '/var/www/html/v3/cache'; //Define filename $filen = 'conferencias_' . LOCALE; //Set filename for relevant conferences if( RELEVANT ){ $filen .= '_relevant'; } else { //If year if($year != ''){ $filen .= '_' . $year; if($month != ''){ $filen .= '_' . $month; } } } if($text){ $filen .= '_texts'; } $file = $dir . '/' . $filen . '.json'; if(!file_exists( $file ) || $_REQUEST['forceupdate']==true ){ $data = build_conferences_list( $year, $month, $last_update, $text, $algolia ); $data['cache'] = time(); $data['filename'] = $filen; $res = file_put_contents( $file , json_encode($data) ); $data['res'] = $res; } else { readfile( $file ); die(); } } else { $data = build_conferences_list( $year, $month, $last_update, $text, $algolia ); $data['cache'] = $cache; } send_response( $data ); } /** * Conferences country list */ function conferences_country_list( $country, $limit=100 ){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $data = []; $stmt = $conference->country_list( $country, $limit ); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $thumbnail = ''; $response_item=array( "_id" => $ID, "title" => $title, "slug" => $slug ); if(!$algolia){ $response_item["hasText"] = ($bodylength>0?true:false); } $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } foreach($translations as $translation_locale=>$translation_id){ $the_slug = $conference->translation_slug( $translation_locale, $translation_id); $row = $the_slug->fetch(PDO::FETCH_ASSOC); $translations[$translation_locale.'_slug'] = $row['slug']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->format('Y-m-d'); $response_item['timestamp'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->getTimestamp(); $response_item['activity'] = $no_activity; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; if(!$algolia){ $response_item['private'] = $private; } $response_item['thumbnail'] = $thumbnail; $dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $date ) ); $response_item['nicedate'] = ucfirst($formatter->format($dt)); $response_item['location'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); $response_item['duration'] = gmdate("H:i:s", (int)$duration); array_push($conferences_arr,$response_item); } } $data = array( 'count' => $num, 'result' => array ( 'conferencias' => $conferences_arr ) ); echo json_encode($data); die(); return $data; } /** * Conferences letter list */ function conferences_letter_list( $letter, $limit=100 ){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $data = []; $stmt = $conference->letter_list( $letter, LOCALE ); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $thumbnail = ''; if(!$text){ $response_item=array( "_id" => $ID, "title" => $title, "slug" => $slug ); if(!$algolia){ $response_item["hasText"] = ($bodylength>0?true:false); } $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } foreach($translations as $translation_locale=>$translation_id){ $the_slug = $conference->translation_slug( $translation_locale, $translation_id); $row = $the_slug->fetch(PDO::FETCH_ASSOC); $translations[$translation_locale.'_slug'] = $row['slug']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->format('Y-m-d'); $response_item['timestamp'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->getTimestamp(); $response_item['activity'] = $no_activity; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; if(!$algolia){ $response_item['private'] = $private; } $response_item['thumbnail'] = $thumbnail; if(!$algolia){ $dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $date ) ); $response_item['nicedate'] = ucfirst($formatter->format($dt)); $response_item['location'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); } $response_item['duration'] = gmdate("H:i:s", (int)$duration); if( !EXPORT && !$algolia ){ $fileData = $conference->get_post_files( $ID, LOCALE ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $response_item['files'] = []; $response_item['files']['youtube'] = str_replace( 'http://', 'https://', $files['youtube']); if($files['videofile'] != ''){ $response_item['files']['video'] = $conference->get_post_file($files['videofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['video'] == ''){ $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); } } else { $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); } if($files['audiofile'] != ''){ $response_item['files']['audio'] = $conference->get_post_file($files['audiofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['audio'] == ''){ $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); } } else { $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); } if($files['pdffile'] != ''){ $response_item['files']['pdf'] = $conference->get_post_file($files['pdffile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['pdf'] == ''){ $response_item['files']['pdf'] = str_replace( 'http://', 'https://',$files['pdf']); } } else { $response_item['files']['pdf'] = str_replace( 'http://', 'https://',$files['pdf']); } if($files['pdfsimplefile'] != ''){ $response_item['files']['pdf_simple'] = $conference->get_post_file($files['pdfsimplefile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['pdf_simple'] == ''){ $response_item['files']['pdf_simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); } } else { $response_item['files']['pdf_simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); } //Image metadata for thumbnail use. TODO: Optimize this return array if(!$algolia){ $response_item['meta'] = unserialize($meta); } $imeta = unserialize($meta); $images = []; $images['small'] = explode('.',$imeta['file'])[0].'-'.$imeta['sizes']['medium']['width'].'x'.$imeta['sizes']['medium']['height'].'.'.explode('.',$imeta['file'])[1]; $images['medium'] = explode('.',$imeta['file'])[0].'-'.$imeta['sizes']['medium_large']['width'].'x'.$imeta['sizes']['medium_large']['height'].'.'.explode('.',$imeta['file'])[1]; $images['large'] = explode('.',$imeta['file'])[0].'-'.$imeta['sizes']['large']['width'].'x'.$imeta['sizes']['large']['height'].'.'.explode('.',$imeta['file'])[1]; $images['original'] = $imeta['file']; if(!$algolia){ $response_item['images'] = $images; } } else { $response_item['body'] = wpautop( $content ); } $response_item['translations'] = $translations; } else { $response_item=[]; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['_id'] = $ID; $response_item['title'] = $title; $response_item['date'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->format('Y-m-d'); $response_item['activity'] = $no_activity; $response_item['duration'] = (int)$duration; $response_item['duration_hms'] = format_time((int)$duration); $response_item['rm'] = $private; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $tdata = []; foreach($translations as $translation_locale=>$translation_id){ $messagedata = $conference->detail($translation_id,$translation_locale); $message = $messagedata->fetch(PDO::FETCH_ASSOC); $translation = []; $translation['languages_code'] = fixLocale($translation_locale); $translation['title'] = $message['title']; $translation['slug'] = $message['slug']; /*$html = wpautop( $message['content'] ); $converter = new Markdownify\ConverterExtra; $translation['text'] = $converter->parseString($html);*/ array_push($tdata,$translation); } $response_item['translations'] = $tdata; } if($algolia){ $response_item['body'] = wpautop( $content ); if( $response_item['body'] != '' ){ array_push($data, $response_item); } } else { array_push($conferences_arr, $response_item); } } } if(!$algolia){ $data = array( 'count' => $num, 'result' => array ( 'conferencias' => $conferences_arr ) ); } echo json_encode($data); die(); return $data; } /** * Generate conference list */ function build_conferences_list( $year, $month, $last_update, $text, $algolia = false ){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $data = []; if( EXPORT || $algolia){ $gettext = true; } else { $gettext = $text; } if( RELEVANT ){ $stmt = $conference->translation_list( $year, $month, $last_update, $gettext, LOCALE, 'relevantes' ); } else { $stmt = $conference->translation_list( $year, $month, $last_update, $gettext, LOCALE ); } $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $thumbnail = ''; if(!$text){ $response_item=array( "id" => $ID, "locale" => fixLocale(LOCALE), "type" => "conference" ); $translations = unserialize($translationmeta); $newtranslations = []; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } foreach($translations as $translation_locale=>$translation_id){ $t = []; $t['locale'] = fixLocale($translation_locale); $t['id'] = $translation_id; array_push($newtranslations,$t); } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->format('Y-m-d'); $response_item['activity'] = $no_activity; $response_item['place'] = ""; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['rm'] = $private; $response_item['biblestudy'] = ''; $response_item['duration'] = (int)$duration; $response_item['thumbnail'] = $thumbnail; if( !EXPORT && !$algolia ){ $fileData = $conference->get_post_files( $ID, LOCALE ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $response_item['files'] = []; $response_item['files']['youtube'] = str_replace( 'http://', 'https://', $files['youtube']); if($files['videofile'] != ''){ $response_item['files']['video'] = $conference->get_post_file($files['videofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['video'] == ''){ $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); } } else { $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); } if($files['audiofile'] != ''){ $response_item['files']['audio'] = $conference->get_post_file($files['audiofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['audio'] == ''){ $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); } } else { $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); } if($files['pdffile'] != ''){ $response_item['files']['booklet'] = $conference->get_post_file($files['pdffile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['booklet'] == ''){ $response_item['files']['booklet'] = str_replace( 'http://', 'https://',$files['pdf']); } } else { $response_item['files']['booklet'] = str_replace( 'http://', 'https://',$files['pdf']); } if($files['pdfsimplefile'] != ''){ $response_item['files']['simple'] = $conference->get_post_file($files['pdfsimplefile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['simple'] == ''){ $response_item['files']['simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); } } else { $response_item['files']['simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); } } else { $response_item['body'] = wpautop( $content ); } $response_item['translations'] = $newtranslations; $response_item['timestamp'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->getTimestamp(); } else { $response_item=[]; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['_id'] = $ID; $response_item['title'] = $title; $response_item['date'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->format('Y-m-d'); $response_item['activity'] = $no_activity; $response_item['duration'] = (int)$duration; $response_item['duration_hms'] = format_time((int)$duration); $response_item['rm'] = $private; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $tdata = []; foreach($translations as $translation_locale=>$translation_id){ $messagedata = $conference->detail($translation_id,$translation_locale); $message = $messagedata->fetch(PDO::FETCH_ASSOC); $translation = []; $translation['languages_code'] = fixLocale($translation_locale); $translation['title'] = $message['title']; $translation['slug'] = $message['slug']; /*$html = wpautop( $message['content'] ); $converter = new Markdownify\ConverterExtra; $translation['text'] = $converter->parseString($html);*/ array_push($tdata,$translation); } $response_item['translations'] = $tdata; } if($algolia){ $response_item['body'] = wpautop( $content ); if( $response_item['body'] != '' ){ array_push($data, $response_item); } } else { array_push($conferences_arr, $response_item); } } } if( $text ){ echo json_encode($conferences_arr); die(); } return $conferences_arr; } function format_time($t,$f=':'){ return sprintf("%02d%s%02d%s%02d", floor($t/3600), $f, ($t/60)%60, $f, $t%60); } function fixLocale($l){ switch ($l){ case "pt_BR": case "pt": $prefix = "pt"; break; case "en_US": case "en": $prefix = "en"; break; case "fr_FR": case "fr": $prefix = "fr"; break; case "es_ES": case "es": default: $prefix = "es"; break; } return $prefix; } function datePattern( $date ){ $format = ''; switch( LOCALE ){ case "en_US": $format = "EEEE, MMMM d, yyyy"; break; case "fr": case "pt_BR": case "es_ES": default: $format = "EEEE, d 'de' MMMM 'de' yyyy"; break; } return $format; } function conference_detail( $id, $showBody=true ){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); if(is_numeric($id)){ $stmt = $conference->detail($id,LOCALE); } else { $stmt = $conference->detailBySlug($id,LOCALE); } $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $thumbnail = ''; extract($row); $response_item=array( "id" => $ID, "locale" => fixLocale(LOCALE), "type" => "conference" ); $translations = unserialize($translationmeta); $newtranslations = []; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } foreach($translations as $translation_locale=>$translation_id){ $t = []; $t['locale'] = fixLocale($translation_locale); $t['id'] = $translation_id; array_push($newtranslations,$t); } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->format('Y-m-d'); $response_item['activity'] = $no_activity; $response_item['place'] = ""; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['rm'] = $private; $response_item['biblestudy'] = ''; $response_item['duration'] = (int)$duration; $response_item['thumbnail'] = $thumbnail; $fileData = $conference->get_post_files( $ID, LOCALE ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $response_item['files'] = []; $response_item['files']['youtube'] = str_replace( 'http://', 'https://', $files['youtube']); if($files['videofile'] != ''){ $response_item['files']['video'] = $conference->get_post_file($files['videofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['video'] == ''){ $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); } } else { $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); } if($files['audiofile'] != ''){ $response_item['files']['audio'] = $conference->get_post_file($files['audiofile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['audio'] == ''){ $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); } } else { $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); } if($files['pdffile'] != ''){ $response_item['files']['booklet'] = $conference->get_post_file($files['pdffile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['booklet'] == ''){ $response_item['files']['booklet'] = str_replace( 'http://', 'https://',$files['pdf']); } } else { $response_item['files']['booklet'] = str_replace( 'http://', 'https://',$files['pdf']); } if($files['pdfsimplefile'] != ''){ $response_item['files']['simple'] = $conference->get_post_file($files['pdfsimplefile'], LOCALE)->fetch(PDO::FETCH_ASSOC)['url']; if( $response_item['files']['simple'] == ''){ $response_item['files']['simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); } } else { $response_item['files']['simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); } $response_item['translations'] = $newtranslations; $response_item['timestamp'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->getTimestamp(); if($showBody){ $response_item['body'] = wpautop($content); } array_push($conferences_arr, $response_item); } } send_response( $conferences_arr ); } function send_response( $data ){ // set response code - 200 OK header('Content-Type: application/json; charset=utf-8'); http_response_code(200); echo json_encode( $data, JSON_UNESCAPED_UNICODE ); } function conference_search( $q ){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $stmt = $conference->title_search($q, LOCALE); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $thumbnail = ''; $response_item=array( "_id" => $ID, "title" => $title, "body" => wpautop($content), "slug" => $slug, "hasText" => ($bodylength>0?true:false) ); $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = $date; $response_item['activity'] = $no_activity; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['thumbnail'] = $thumbnail; $dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $date ) ); $response_item['nicedate'] = ucfirst($formatter->format($dt)); $response_item['location'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); $response_item['duration'] = gmdate("H:i:s", (int)$duration); $fileData = $conference->get_post_files( $ID, LOCALE ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $response_item['files'] = []; $response_item['files']['youtube'] = str_replace( 'http://', 'https://', $files['youtube']); $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); $response_item['files']['pdf'] = str_replace( 'http://', 'https://',$files['pdf']); $response_item['files']['pdf_simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); $response_item['translations'] = $translations; //Image metadata for thumbnail use. TODO: Optimize this return array $response_item['meta'] = unserialize($meta); array_push($conferences_arr, $response_item); } } $data = array( 'count' => $num, 'query' => $q, 'result' => array ( 'conferencias' => $conferences_arr ) ); send_response( $data ); } function conference_content_search( $q ){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $stmt = $conference->content_search($q); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $response_item=array( "_id" => $ID, "ty" => 'conferencia', "d" => date("Y-m-d", strtotime( $creation_date ) ), "t" => $title, "a" => $no_activity, "c" => $city, "st" => $state, "co" => $country, "s" => $duration, "sl" => $slug, "th" => $thumbnail, "ex" => "..." . preg_replace("/\w*?$q\w*/i", '$0', better_strip_tags($excerpt)) . "..." ); $dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern("EEEE, d 'de' MMMM 'de' yyyy"); $response_item['date'] = ucfirst($formatter->format($dt)); $response_item['lo'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); $response_item['dur'] = gmdate("H:i:s", (int)$duration); $response_item['slug'] = 'https://conferenciaswp.carpa.com/conferencias/'.$slug; $fileData = $conference->get_post_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $response_item['yt'] = str_replace( 'http://', 'https://', $files['youtube']); $response_item['v'] = str_replace( 'http://', 'https://',$files['video']); $response_item['au'] = str_replace( 'http://', 'https://',$files['audio']); $response_item['p'] = str_replace( 'http://', 'https://',$files['pdf']); $response_item['ps'] = str_replace( 'http://', 'https://',$files['pdf_simple']); array_push($conferences_arr, $response_item); } } $data = array( 'count' => $num, 'query' => $q, 'result' => array ( 'conferencias' => $conferences_arr ) ); send_response( $data ); } function countries_list(){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $stmt = $conference->country_summary(); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $response_item=array( 'code' => $row['country_code'], 'country' => $row['country'], 'total' => $row['total'] ); array_push($conferences_arr, $response_item); } } $data = array( 'count' => $num, 'countries' => $conferences_arr ); send_response( $data ); } function country_conferences($co){ $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $stmt = $conference->country_list($co,LOCALE); $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $thumbnail = ''; $response_item=array( "_id" => $ID, "title" => $title, "slug" => $slug, "hasText" => ($bodylength>0?true:false) ); $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = $date; $response_item['activity'] = $no_activity; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['thumbnail'] = $thumbnail; $dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $date ) ); $response_item['nicedate'] = ucfirst($formatter->format($dt)); $response_item['location'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); $response_item['duration'] = gmdate("H:i:s", (int)$duration); $fileData = $conference->get_post_files( $ID, LOCALE ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $response_item['files'] = []; $response_item['files']['youtube'] = str_replace( 'http://', 'https://', $files['youtube']); $response_item['files']['video'] = str_replace( 'http://', 'https://',$files['video']); $response_item['files']['audio'] = str_replace( 'http://', 'https://',$files['audio']); $response_item['files']['pdf'] = str_replace( 'http://', 'https://',$files['pdf']); $response_item['files']['pdf_simple'] = str_replace( 'http://', 'https://',$files['pdf_simple']); //Image metadata for thumbnail use. TODO: Optimize this return array $response_item['meta'] = unserialize($meta); $response_item['translations'] = $translations; array_push($conferences_arr, $response_item); } } $data = array( 'count' => $num, 'result' => array ( 'conferencias' => $conferences_arr ) ); $data['country'] = Locale::getDisplayRegion('-'.strtoupper($country), LOCALE ); send_response( $data ); } function better_strip_tags( $str, $allowable_tags = '', $strip_attrs = false, $preserve_comments = false, callable $callback = null ) { $allowable_tags = array_map( 'strtolower', array_filter( // lowercase preg_split( '/(?:>|^)\\s*(?:<|$)/', $allowable_tags, -1, PREG_SPLIT_NO_EMPTY ), // get tag names function( $tag ) { return preg_match( '/^[a-z][a-z0-9_]*$/i', $tag ); } // filter broken ) ); $comments_and_stuff = preg_split( '/(|$))/', $str, -1, PREG_SPLIT_DELIM_CAPTURE ); foreach ( $comments_and_stuff as $i => $comment_or_stuff ) { if ( $i % 2 ) { // html comment if ( !( $preserve_comments && preg_match( '//', $comment_or_stuff ) ) ) { $comments_and_stuff[$i] = ''; } } else { // stuff between comments $tags_and_text = preg_split( "/(<(?:[^>\"']++|\"[^\"]*+(?:\"|$)|'[^']*+(?:'|$))*(?:>|$))/", $comment_or_stuff, -1, PREG_SPLIT_DELIM_CAPTURE ); foreach ( $tags_and_text as $j => $tag_or_text ) { $is_broken = false; $is_allowable = true; $result = $tag_or_text; if ( $j % 2 ) { // tag if ( preg_match( "%^(?)([a-z][a-z0-9_]*)\\b(?:[^>\"'/]++|/+?|\"[^\"]*\"|'[^']*')*?(/?>)%i", $tag_or_text, $matches ) ) { $tag = strtolower( $matches[2] ); if ( in_array( $tag, $allowable_tags ) ) { if ( $strip_attrs ) { $opening = $matches[1]; $closing = ( $opening === '' ) ? '>' : $closing; $result = $opening . $tag . $closing; } } else { $is_allowable = false; $result = ''; } } else { $is_broken = true; $result = ''; } } else { // text $tag = false; } if ( !$is_broken && isset( $callback ) ) { // allow result modification call_user_func_array( $callback, array( &$result, $tag_or_text, $tag, $is_allowable ) ); } $tags_and_text[$j] = $result; } $comments_and_stuff[$i] = implode( '', $tags_and_text ); } } $str = implode( '', $comments_and_stuff ); return $str; } function getFilePrefix(){ switch (LOCALE){ case "pt_BR": case "pt": $prefix = "POR"; break; case "en_US": case "en": $prefix = "ENG"; break; case "fr_FR": case "fr": $prefix = "FRA"; break; case "es_ES": case "es": default: $prefix = "SPA"; break; } return $prefix; } function conference_epub($id,$return,$overwrite){ require_once( '/var/www/html/v3/inc/epub/EPub.php'); require_once( '/var/www/html/v3/inc/epub/EPubChapterSplitter.class.php'); require_once( '/var/www/html/v3/inc/epub/Zip.class.php'); $database = new Database(); $db = $database->getConnection(); $conference = new Conferencia($db); $stmt = $conference->detail($id,LOCALE); $num = $stmt->rowCount(); if($num>0){ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $thumbnail = ''; $response_item=array( "_id" => $ID, "title" => $title, "body" => wpautop($content), "slug" => $slug, "hasText" => ($bodylength>0?true:false) ); $translations = unserialize($translationmeta); $translations[LOCALE] = (int)$ID; if(LOCALE=='es_ES'){ $original_id = $ID; } else { $original_id = $translations['es_ES']; } $confmeta = $conference->conference_meta( $original_id ); extract($confmeta); $response_item['date'] = $date; $response_item['activity'] = $no_activity; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['thumbnail'] = $thumbnail; $dt = new DateTime($date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $date ) ); $nicedate = ucfirst($formatter->format($dt)); $lo = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); $code = getFilePrefix() . '-' . date("Y-m-d", strtotime( $date ) ) . '-' . $no_activity; //Title $newTitle = sanitize_title( $title ); $fixedNewTitle = str_replace( '-','_',$newTitle ); $newFilename = $code . "-" . $fixedNewTitle . "-" . strtoupper( substr( $city , 0 , 3 ) ) . strtoupper( $country ) . ".epub"; $file = $newFilename; $generate = 'true'; if(file_exists( $file )){ $generate = 'false'; } if($generate == 'true' || $overwrite == 'true'){ $book = new EPub(); // Title and Identifier are mandatory! $book->setTitle( $title ); $book->setIdentifier( $code , EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. $book->setLanguage( LOCALE ); // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc. $book->setDescription( $t . ', predicado el ' . $nicedate . ', en ' . $lo ); $book->setAuthor("Dr. William Soto Santiago","Dr. William Soto Santiago"); $book->setPublisher("La Gran Carpa Catedral, Corp.", "https://www.carpa.com/"); // I hope this is a non existant address :) $book->setDate(time()); // Strictly not needed as the book date defaults to time(). $book->setRights("Copyright and licence information specific for the book."); $book->setSourceURL( $u ); $cssData = " h1 {\n text-transform : uppercase;\n text-align : center;\n}\n h2 {\n text-align : center;\n text-transform : capitalize;\n}"; $book->addCSSFile("styles.css", "css1", $cssData); // ePub uses XHTML 1.1, preferably strict. $content_start = "\n" . "\n" . "\n" . "
" . "\n" . "\n" . "