|^)\\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( "%^(\"'/]++|/+?|\"[^\"]*\"|'[^']*')*?(/?>)%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=true){ if(!$id){ echo json_encode("No id!"); die(); } 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'); /*require_once( 'c:/laragon/www/conferencias/v3/inc/epub/EPub.php'); require_once( 'c:/laragon/www/conferencias/v3/inc/epub/EPubChapterSplitter.class.php'); require_once( 'c:/laragon/www/conferencias/v3/inc/epub/Zip.class.php');*/ $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $count = $activity->get_post_interventions($id); $row = $count->fetch(PDO::FETCH_ASSOC); $interventions = $row['meta_value']; $interventionData = $activity->get_interventions($id,$interventions); $stmt = $activity->detail($id,LOCALE); $num = $stmt->rowCount(); if($num>0){ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ //echo json_encode($row); //die(); extract($row); $date = $creation_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']; } $count = $activity->get_post_interventions($id); $confmeta = $activity->activity_meta( $ID ); extract($confmeta); //Get interventions //$intervention_count = "SELECT * FROM `wp_postmeta` WHERE `post_id` = " . $id . " AND `meta_key` = 'intervenciones'"; /*$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 ) ) . '-' . $actividad; //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. José Benjamín Pérez","Dr. José Benjamín Pérez"); $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" . "". $title ."\n" . "\n" . "\n"; $svgData = ''; $book->addFile("logo_lgccc_epub.svg", "logo_svg", $svgData, "image/svg+xml"); $cover = $content_start . "

".$title."

\n

Dr. José Benjamín Pérez
".$nicedate."
Cayey, Puerto Rico


\"La
\n" . "\n\n"; $book->addChapter("Cover", "Cover.html", $cover); //$content = autop($content); $x = 1; foreach($interventionData as $intervention){ $content = preg_replace('/[\x00-\x1F\x7F]/u', '', $intervention['texto']); $dt = new DateTime($intervention['fecha']); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $intervention['fecha'] ) ); $nicedate = ucfirst($formatter->format($dt)); $contenido = $content_start . "

".$intervention['titulo']."

\n

".$intervention['autor']."
".$nicedate."
" . $intervention['lugar'] . "

\n" . $content. "\n\n"; $book->addChapter("Contenido: " . $intervention['titulo'], "Chapter00".$x.".html", $contenido); $x++; } $book->finalize(); // Finalize the book, and build the archive. //save file $fp = fopen( $file ,'w'); fwrite( $fp , $book->getBook() ); fclose( $fp ); if($return=='true'){ $zipData = $book->sendBook( $newFilename ); } //die(); } else { if($return=='true'){ $newTitle = sanitize_title( $title ); $fixedNewTitle = str_replace( '-','_',$newTitle ); $newFilename = $code . "-" . $fixedNewTitle . "-" . strtoupper( substr( $city , 0 , 3 ) ) . strtoupper( $country ) . ".epub"; //Send current file header($_SERVER["SERVER_PROTOCOL"] . " 200 OK"); header("Cache-Control: public"); // needed for internet explorer header("Content-Type: application/epub+zip"); header("Content-Transfer-Encoding: Binary"); header("Content-Length:".filesize($file)); header("Content-Disposition: attachment; filename=".$newFilename); readfile($file); } } } } $db = $database->closeConnection(); } function sanitize_title($text, string $divider = '-') { // replace non letter or digits by divider $text = preg_replace('~[^\pL\d]+~u', $divider, $text); // transliterate $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // remove unwanted characters $text = preg_replace('~[^-\w]+~', '', $text); // trim $text = trim($text, $divider); // remove duplicate divider $text = preg_replace('~-+~', $divider, $text); // lowercase $text = strtolower($text); if (empty($text)) { return 'n-a'; } return $text; } function nl2p($string, $line_breaks = false, $xml = true) { $string = str_replace(array('

', '

', '
', '
'), '', $string); // It is conceivable that people might still want single line-breaks // without breaking into a new paragraph. if ($line_breaks == true) return '

'.preg_replace(array("/([\n]{2,})/i", "/([^>])\n([^<])/i"), array("

\n

", '$1$2'), trim($string)).'

'; else return '

'.preg_replace( array("/([\n]{2,})/i", "/([\r\n]{3,})/i","/([^>])\n([^<])/i"), array("

\n

", "

\n

", '$1$2'), trim($string)).'

'; } function autop($pee, $br = false) { $pre_tags = array(); if ( trim($pee) === '' ) return ''; $pee = $pee . "\n"; // just to make things a little easier, pad the end if ( strpos($pee, '', $pee ); $last_pee = array_pop($pee_parts); $pee = ''; $i = 0; foreach ( $pee_parts as $pee_part ) { $start = strpos($pee_part, ''; $pee .= substr( $pee_part, 0, $start ) . $name; $i++; } $pee .= $last_pee; } $pee = preg_replace('|
\s*
|', "\n\n", $pee); // Space things out a little $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|samp|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); $pee = preg_replace('!()!', "$1\n\n", $pee); $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines if ( strpos($pee, ']*)>\s*|', "", $pee); // no pee inside object/embed $pee = preg_replace('|\s*\s*|', '', $pee); } $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates // make paragraphs, including one at the end $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY); $pee = ''; foreach ( $pees as $tinkle ) $pee .= '

' . trim($tinkle, "\n") . "

\n"; $pee = preg_replace('|

\s*

|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace $pee = preg_replace('!

([^<]+)!', "

$1

", $pee); $pee = preg_replace('!

\s*(]*>)\s*

!', "$1", $pee); // don't pee all over a tag $pee = preg_replace("|

(|", "$1", $pee); // problem with nested lists $pee = preg_replace('|

]*)>|i', "

", $pee); $pee = str_replace('

', '

', $pee); $pee = preg_replace('!

\s*(]*>)!', "$1", $pee); $pee = preg_replace('!(]*>)\s*

!', "$1", $pee); if ( $br ) { $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "", $matches[0]);'), $pee); $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks $pee = str_replace('', "\n", $pee); } $pee = preg_replace('!(]*>)\s*
!', "$1", $pee); $pee = preg_replace('!
(\s*]*>)!', '$1', $pee); $pee = preg_replace( "|\n

$|", '

', $pee ); if ( !empty($pre_tags) ) $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee); return $pee; } function conference_download($h,$p,$file){ header_remove(); header("X-Accel-Redirect: /downloadfile/" . $h . $p .'?' . $file); } 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 listAllActivities(){ header('Content-Type: application/json; charset=utf-8'); $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->translation_list( '', '', null, false, LOCALE, null, true, true, false ); $num = $stmt->rowCount(); $data = []; if($num>0){ $activities_array=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $response_item=array( "_id" => $ID, "title" => $title, "date" => $date, "slug" => $slug ); $confmeta = $activity->activity_meta( $ID ); extract($confmeta); if($mensaje_json){ $j = json_decode($mensaje_json); $response_item['mensaje_json'] = $j; array_push($data,$response_item); } } } $db = $database->closeConnection(); send_response( $data ); } function listActivities( $year, $month, $history=false, $limit ){ header('Content-Type: application/json; charset=utf-8'); $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->translation_list( $year, $month, null, false, LOCALE, null, false, $history, $limit ); $num = $stmt->rowCount(); $data = []; if($num>0){ $activities_array=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $response_item=array( "_id" => $ID, "title" => $title, "slug" => $slug ); $confmeta = $activity->activity_meta( $ID ); extract($confmeta); $response_item['lugar'] = $lugar; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['bible_study'] = $numero_de_estudio_biblico; $response_item['activity'] = $actividad; $response_item['youtube'] = $youtube; //Revisado $response_item['revisado'] = $revisado; $translations = unserialize($translationmeta); if( !$_REQUEST['fat'] ){ foreach($translations as $translation_locale=>$translation_id){ if( $translation_locale === 'sync' ){ continue; } $the_slug = $activity->translation_slug( $translation_locale, $translation_id); $row = $the_slug->fetch(PDO::FETCH_ASSOC); $translations[$translation_locale.'_slug'] = $row['slug']; } $response_item['translations'] = $translations; } $response_item['date'] = $date; $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['files'] = []; //Get filedata $fileData = $activity->get_activity_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $fileTypes = ['videos','audios','textos','enlaces']; if($files['use_files']){ $tempFiles = []; foreach($fileTypes as $type){ if(!is_array($tempFiles[$type])){ $tempFiles[$type] = []; } if($files[$type] > 0){ $t = $activity->get_files( $ID, $type, $files[$type]); array_push($tempFiles[$type],$t); } } $response_item['files'] = $tempFiles; } /*if( $thumbnail == '') { $response_item['thumbnail'] = '2021/07/maxresdefault.jpg'; } else {*/ $response_item['thumbnail'] = $thumbnail; //} $response_item['mensaje'] = $mensaje; $response_item['mensaje_json'] = $mensaje_json; array_push($data,$response_item); } } $db = $database->closeConnection(); send_response( $data ); } 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 activity_years( $history=false ){ if(!defined('LOCALE')){ $locale = 'es'; } else { $locale = LOCALE; } $locale = 'es'; $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); if($history){ $stmt = $activity->year_list_history($locale); } else { $stmt = $activity->year_list($locale); } $num = $stmt->rowCount(); if($num>0){ $conferences_arr=array(); $years = []; $formattedYears = []; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); if ($currentYear != $year){ $currentYear = $year; $years[$currentYear] = []; } $format = new IntlDateFormatter($locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE, NULL, NULL, "MMMM"); $monthName = datefmt_format($format, mktime(0, 0, 0, $month)); array_push( $years[$currentYear], array('name'=>$monthName,'month'=>str_pad($month,2,'0',STR_PAD_LEFT),'count' => $total)); } } $newYears = []; foreach($years as $year=>$months){ $totalyear = 0; foreach($months as $month=>$count){ $totalyear += $count['count']; } array_push($newYears, array('year'=>$year, 'count'=>$totalyear, 'months' => $months)); } $data = array( 'result' => array ( 'years' => $newYears ) ); $db = $database->closeConnection(); send_response( $data ); } function activity_summary( $id ){ $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->summary($id,LOCALE); $num = $stmt->rowCount(); if($num>0){ $conferences_arr = []; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $response_item=array( "_id" => $ID, "title" => $title, "date" => $creation_date, "slug" => $slug, "activity" => $activity, "lugar" => $lugar, "city" => $city, "state" => $state, "country" => $country, "bible_study" => $bible_study ); array_push($conferences_arr, $response_item); } } $data = $conferences_arr; send_response( $data ); } function activity_detail( $id ){ $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); if(is_numeric($id)){ $stmt = $activity->detail($id,LOCALE); } else { $stmt = $activity->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, "title" => $title, "body" => wpautop($content), "slug" => $slug, "hasText" => ($bodylength>0?true:false) ); $response_item['mensaje'] = $mensaje; $translations = unserialize($translationmeta); foreach($translations as $translation_locale=>$translation_id){ $the_slug = $activity->translation_slug( $translation_locale, $translation_id); $row = $the_slug->fetch(PDO::FETCH_ASSOC); $translations[$translation_locale.'_slug'] = $row['slug']; } $response_item['translations'] = $translations; $confmeta = $activity->activity_meta( $ID ); extract($confmeta); $response_item['bible_study'] = $numero_de_estudio_biblico; $response_item['activity'] = $actividad; $response_item['youtube'] = $youtube; $response_item['date'] = $creation_date; $response_item['related_content'] = $related_content; $dt = new DateTime($creation_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 = $activity->get_activity_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); //Get filedata $fileData = $activity->get_activity_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $fileTypes = ['videos','audios','textos','enlaces']; if($files['use_files']){ $tempFiles = []; foreach($fileTypes as $type){ if(!is_array($tempFiles[$type])){ $tempFiles[$type] = []; } if($files[$type] > 0){ $t = $activity->get_files( $ID, $type, $files[$type]); array_push($tempFiles[$type],$t); } } $response_item['files'] = $tempFiles; } //Thumbnmail $response_item['thumbnail'] = $files['thumbnail']; //Translations $response_item['translations'] = $translations; //Image metadata for thumbnail use. TODO: Optimize this return array $response_item['meta'] = unserialize($meta); //Interventions $count = $activity->get_post_interventions($ID); $row = $count->fetch(PDO::FETCH_ASSOC); $interventions = $row['meta_value']; $temp = $activity->get_interventions($ID,$interventions); $response_item['interventions'] = []; foreach($temp as $t){ $t['texto'] = wpautop($t['texto']); array_push($response_item['interventions'],$t); } //Related content if($related_content){ $response_item['related'] = $activity->get_related_content($ID,$related_content_count); } //Revisado $response_item['revisado'] = $revisado; array_push($conferences_arr, $response_item); } } $data = $conferences_arr; $db = $database->closeConnection(); send_response( $data ); } function listVue(){ $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->translation_list( $year, $month, null, false, LOCALE, null, false, false, 1000 ); $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, "title" => $title, //"body" => wpautop($content), "slug" => $slug, "hasText" => ($bodylength>0?true:false) ); $response_item['mensaje'] = $mensaje; $translations = unserialize($translationmeta); foreach($translations as $translation_locale=>$translation_id){ $the_slug = $activity->translation_slug( $translation_locale, $translation_id); $row = $the_slug->fetch(PDO::FETCH_ASSOC); $translations[$translation_locale.'_slug'] = $row['slug']; } $response_item['translations'] = $translations; $confmeta = $activity->activity_meta( $ID ); extract($confmeta); $response_item['bible_study'] = $numero_de_estudio_biblico; $response_item['activity'] = $actividad; $response_item['youtube'] = $youtube; $response_item['date'] = $creation_date; $response_item['related_content'] = $related_content; $dt = new DateTime($creation_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 = $activity->get_activity_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); //Get filedata $fileData = $activity->get_activity_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $fileTypes = ['videos','audios','textos','enlaces']; if($files['use_files']){ $tempFiles = []; foreach($fileTypes as $type){ if(!is_array($tempFiles[$type])){ $tempFiles[$type] = []; } if($files[$type] > 0){ $t = $activity->get_files( $ID, $type, $files[$type]); array_push($tempFiles[$type],$t); } } $response_item['files'] = $tempFiles; } //Thumbnmail $response_item['thumbnail'] = $files['thumbnail']; //Translations //$response_item['translations'] = $translations; //Image metadata for thumbnail use. TODO: Optimize this return array $response_item['meta'] = unserialize($meta); //Interventions $count = $activity->get_post_interventions($ID); $row = $count->fetch(PDO::FETCH_ASSOC); $interventions = $row['meta_value']; $temp = $activity->get_interventions($ID,$interventions); $response_item['interventions'] = []; // foreach($temp as $t){ // $t['texto'] = wpautop($t['texto']); // array_push($response_item['interventions'],$t); // } //Related content if($related_content){ $response_item['related'] = $activity->get_related_content($ID,$related_content_count); } //Revisado $response_item['revisado'] = $revisado; array_push($conferences_arr, $response_item); } } $data = $conferences_arr; $db = $database->closeConnection(); send_response( $data ); } function listSearchActivities( $id ){ $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->translation_list( $year, $month, null, false, LOCALE, null, false, false, 1000 ); $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, "title" => $title, "body" => wpautop($content), "slug" => $slug, "hasText" => ($bodylength>0?true:false) ); $response_item['mensaje'] = $mensaje; $translations = unserialize($translationmeta); foreach($translations as $translation_locale=>$translation_id){ $the_slug = $activity->translation_slug( $translation_locale, $translation_id); $row = $the_slug->fetch(PDO::FETCH_ASSOC); $translations[$translation_locale.'_slug'] = $row['slug']; } $response_item['translations'] = $translations; $confmeta = $activity->activity_meta( $ID ); extract($confmeta); $response_item['bible_study'] = $numero_de_estudio_biblico; $response_item['activity'] = $actividad; $response_item['youtube'] = $youtube; $response_item['date'] = $creation_date; $response_item['related_content'] = $related_content; $dt = new DateTime($creation_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 = $activity->get_activity_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); //Get filedata $fileData = $activity->get_activity_files( $ID ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $fileTypes = ['videos','audios','textos','enlaces']; if($files['use_files']){ $tempFiles = []; foreach($fileTypes as $type){ if(!is_array($tempFiles[$type])){ $tempFiles[$type] = []; } if($files[$type] > 0){ $t = $activity->get_files( $ID, $type, $files[$type]); array_push($tempFiles[$type],$t); } } $response_item['files'] = $tempFiles; } //Thumbnmail $response_item['thumbnail'] = $files['thumbnail']; //Translations $response_item['translations'] = $translations; //Image metadata for thumbnail use. TODO: Optimize this return array $response_item['meta'] = unserialize($meta); //Interventions $count = $activity->get_post_interventions($ID); $row = $count->fetch(PDO::FETCH_ASSOC); $interventions = $row['meta_value']; $temp = $activity->get_interventions($ID,$interventions); $response_item['interventions'] = []; foreach($temp as $t){ $t['texto'] = wpautop($t['texto']); array_push($response_item['interventions'],$t); } //Related content if($related_content){ $response_item['related'] = $activity->get_related_content($ID,$related_content_count); } //Revisado $response_item['revisado'] = $revisado; array_push($conferences_arr, $response_item); } } $data = $conferences_arr; $db = $database->closeConnection(); send_response( $data ); } function listActivitiesWithText($year, $month){ $limit = 10000; header('Content-Type: application/json; charset=utf-8'); $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->translation_list( $year, $month, null, false, LOCALE, null, false, $history, $limit ); $num = $stmt->rowCount(); $data = []; if($num>0){ $activities_array=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $response_item['_id'] = $ID; extract($row); $response_item=array( "title" => $title, ); $confmeta = $activity->activity_meta( $ID ); extract($confmeta); $response_item['date'] = $date; $response_item['activity'] = $actividad; $response_item['bible_study'] = $numero_de_estudio_biblico; $response_item['place'] = $lugar; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['draft'] = ($revisado?true:false); $response_item['youtube'] = $youtube; $translations = []; $translation_items = unserialize($translationmeta); foreach($translation_items as $translation_locale=>$translation_id){ $tactivitydata = $activity->detail($translation_id,$translation_locale); $tactivity = $tactivitydata->fetch(PDO::FETCH_ASSOC); //$response_item['tactivity'] = $tactivity; //Interventions $count = $activity->get_post_interventions($translation_id); $row = $count->fetch(PDO::FETCH_ASSOC); $interventions = $row['meta_value']; $intervention_items = $activity->get_interventions($translation_id,$interventions); $translation = []; $translation['languages_code'] = $translation_locale; $translation['interventions'] = []; foreach($intervention_items as $intervention){ $int = []; $int['title'] = $intervention['titulo']; $int['author'] = getAuthor($intervention['autor']); $int['slug'] = $tactivity['slug']; $html = wpautop( $intervention['texto'] ); $converter = new Markdownify\ConverterExtra; $int['text'] = $converter->parseString($html); array_push($translation['interventions'],$int); } array_push($translations,$translation); } $response_item['translations'] = $translations; array_push($data,$response_item); } } $db = $database->closeConnection(); send_response( $data ); } function getAuthor($a){ $code = ''; switch($a){ case "Dr. William Soto Santiago": $code = 'wss'; break; case "Rev. Miguel Bermúdez Marin": $code = 'mbm'; break; case "Dr. José Benjamín Pérez Matos": default: $code = 'jbp'; break; } return $code; } function exportToSQLite($year, $month, $limit=5){ header('Content-Type: application/json; charset=utf-8'); $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->translation_list( $year, $month, null, false, LOCALE, null, false, null, $limit ); $num = $stmt->rowCount(); $data = []; if($num>0){ $activities_array=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $response_item=array( "wpid" => (int)$ID, "title" => $title ); $confmeta = $activity->activity_meta( $ID ); extract($confmeta); $response_item['date'] = $date; $response_item['activity'] = ($actividad!=''?(int)$actividad:null); $response_item['bible_study'] = ($numero_de_estudio_biblico!=''?(int)$numero_de_estudio_biblico:null); $response_item['place'] = $lugar; $response_item['city'] = $city; $response_item['state'] = $state; $response_item['country'] = $country; $response_item['thumbnail_url'] = ($thumbnail!=''?'https://actividadeswp.carpa.com/wp-content/uploads/'.$thumbnail:false); $response_item['youtube'] = $youtube; $response_item['draft'] = ($revisado!=''?true:false); $translations = []; $translation_items = unserialize($translationmeta); foreach($translation_items as $translation_locale=>$translation_id){ //Only get current language $tactivitydata = $activity->detail($translation_id,$translation_locale); $tactivity = $tactivitydata->fetch(PDO::FETCH_ASSOC); //$response_item['tactivity'] = $tactivity; //Interventions $count = $activity->get_post_interventions($translation_id); $row = $count->fetch(PDO::FETCH_ASSOC); $interventions = $row['meta_value']; $intervention_items = $activity->get_interventions($translation_id,$interventions); $translation = []; $translation['languages_code'] = $translation_locale; $translation['interventions'] = []; foreach($intervention_items as $intervention){ $int = []; $int['title'] = $intervention['titulo']; $int['author'] = 1; $html = wpautop( $intervention['texto'] ); $converter = new Markdownify\ConverterExtra; $int['text'] = $converter->parseString($html); array_push($translation['interventions'],$int); } //File info per language //Get filedata $fileData = $activity->get_activity_files( $translation_id ); $files = $fileData->fetch(PDO::FETCH_ASSOC); $fileTypes = ['textos','audios']; $tempFiles = []; $pdf_file = ''; foreach($fileTypes as $type){ if($files[$type] > 0){ $t = $activity->get_files( $translation_id, $type, $files[$type]); foreach($t as $tfile){ if($tfile["title"] == "PDF Sencillo"){ //array_push($tempFiles,$tfile); $pdf_url = $tfile['file']; } if($tfile["title"] == "PDF Booklet"){ $pdf_booklet_url = $tfile['file']; } if($tfile['title'] == "Audio"){ $mp3_url = $tfile['file']; } } } } $translation['pdf_url'] = $pdf_url; $translation['pdf_booklet_url'] = $pdf_booklet_url; $translation['mp3_url'] = $mp3_url; array_push($translations,$translation); } $response_item['translations'] = $translations; // foreach($translations as $translation_locale=>$translation_id){ // $the_slug = $activity->translation_slug( $translation_locale, $translation_id); // $row = $the_slug->fetch(PDO::FETCH_ASSOC); // $translations[$translation_locale.'_slug'] = $row['slug']; // } // $response_item['translations'] = $translations; // $response_item['files'] = []; // //Get filedata // $fileData = $activity->get_activity_files( $ID ); // $files = $fileData->fetch(PDO::FETCH_ASSOC); // $fileTypes = ['videos','audios','textos','enlaces']; // if($files['use_files']){ // $tempFiles = []; // foreach($fileTypes as $type){ // if(!is_array($tempFiles[$type])){ // $tempFiles[$type] = []; // } // if($files[$type] > 0){ // $t = $activity->get_files( $ID, $type, $files[$type]); // array_push($tempFiles[$type],$t); // } // } // $response_item['files'] = $tempFiles; // } // /*if( $thumbnail == '') { // $response_item['thumbnail'] = '2021/07/maxresdefault.jpg'; // } else {*/ // $response_item['thumbnail'] = $thumbnail; // //} // $response_item['mensaje'] = $mensaje; // $response_item['mensaje_json'] = $mensaje_json; array_push($data,$response_item); } } $db = $database->closeConnection(); send_response( $data ); } function guidv4($data = null) { // Generate 16 bytes (128 bits) of random data or use the data passed into the function. $data = $data ?? random_bytes(16); assert(strlen($data) == 16); // Set version to 0100 $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set bits 6-7 to 10 $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Output the 36 character UUID. return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } function activity_list_lgccctv(){ $database = new Database(); $db = $database->getConnection(); $activity = new Actividad($db); $stmt = $activity->lgccctv_list(); $num = $stmt->rowCount(); if($num>0){ $activities_arr=array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ extract($row); $date = ''; $no_activity = ''; $city = ''; $state = ''; $country = ''; $response_item=array( "title" => $titulo ); //$response_item['debug'] = $titulo; $metadata = $activity->activity_meta( $ID ); extract($metadata); $response_item['date'] = substr($creation_date,0,10); $response_item['activity'] = $actividad; $response_item['author'] = 'Dr. José Benjamín Pérez Matos'; $dt = new DateTime($creation_date); $formatter = new IntlDateFormatter(LOCALE, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $formatter->setPattern( datePattern( $creation_date ) ); $response_item['nicedate'] = ucfirst($formatter->format($dt)); $response_item['location'] = implode(', ',array_filter(array($city,$state,Locale::getDisplayRegion('-'.strtoupper($country), LOCALE )))); array_push($activities_arr, $response_item); } } send_response( $activities_arr ); }