From 8291a9a10600b812f7e561bdb736f826ef6069a2 Mon Sep 17 00:00:00 2001 From: Julio Ruiz Date: Fri, 26 Dec 2025 23:15:56 -0500 Subject: [PATCH] Adding translations list function so that we can comparte what files are missing from a specific language. Up at : https://actividadeswp.carpa.com/v5/translations/pt/index.html https://actividadeswp.carpa.com/v5/translations/en/index.html https://actividadeswp.carpa.com/v5/translations/fr/index.html --- ActividadesWP/v5/inc/actividad.php | 52 ++++++++- ActividadesWP/v5/items/index.php | 173 ++++++++++++++++++++++++++++- 2 files changed, 214 insertions(+), 11 deletions(-) diff --git a/ActividadesWP/v5/inc/actividad.php b/ActividadesWP/v5/inc/actividad.php index 127cdaa..e00cb5c 100644 --- a/ActividadesWP/v5/inc/actividad.php +++ b/ActividadesWP/v5/inc/actividad.php @@ -68,7 +68,7 @@ class Actividad{ } - function translation_list( $year, $month, $last_update, $text, $locale, $termid="ultimas", $all=false, $history=false, $limit=16 ){ //Default last updated + function translation_list( $year, $month, $last_update, $text, $locale, $termid="ultimas", $all=false, $history=false, $limit=16, $from='' ){ //Default last updated //Check locale and change accordingly to the right DB prefix for that locale $sql = "SELECT P.ID, @@ -103,6 +103,10 @@ class Actividad{ AND PMA.meta_value != ''"; } + if($from != ''){ + $sql .= " AND P.post_date >= '$from'"; + } + if($year!=''){ $sql .= " AND YEAR(P.post_date) = '$year'"; if($month!=''){ @@ -115,11 +119,11 @@ class Actividad{ } else { $sql .= " ORDER BY P.post_date DESC"; if(!$all){ -if(!$limit){ - $sql .= " LIMIT 16"; -} else { -$sql .= " LIMIT " . $limit; -} + if(!$limit){ + $sql .= " LIMIT 16"; + } else { + $sql .= " LIMIT " . $limit; + } } } return $this->execute_sql( $sql ); @@ -223,6 +227,42 @@ LEFT JOIN wp_postmeta PML ON P.ID = PML.post_id AND PML.meta_key = 'lugar' return $this->execute_sql( $sql ); } + /** + * Summary function + */ + function activity_summary($id,$locale){ + + $sql = "SELECT + P.ID, + P.post_title AS title, + P.post_date AS creation_date, + P.post_name AS slug, + P.post_modified AS last_updated, + PMA.meta_value AS activity, + PML.meta_value AS lugar, + PMC.meta_value AS city, + PMS.meta_value AS state, + PMCO.meta_value AS country, + PMN.meta_value AS bible_study, + CASE + WHEN PMT.meta_value IS NOT NULL AND PMT.meta_value <> '' THEN 1 -- Or 'True' + ELSE 0 -- Or 'False' + END AS has_text + FROM wp_posts P + LEFT JOIN wp_postmeta PMA ON PMA.post_id = P.ID AND PMA.meta_key = 'actividad' + LEFT JOIN wp_postmeta PML ON PML.post_id = P.ID AND PML.meta_key = 'lugar' + LEFT JOIN wp_postmeta PMC ON PMC.post_id = P.ID AND PMC.meta_key = 'city' + LEFT JOIN wp_postmeta PMS ON PMS.post_id = P.ID AND PMS.meta_key = 'state' + LEFT JOIN wp_postmeta PMCO ON PMCO.post_id = P.ID AND PMCO.meta_key = 'country' + LEFT JOIN wp_postmeta PMN ON PMN.post_id = P.ID AND PMN.meta_key = 'numero_de_estudio_biblico' + LEFT JOIN wp_postmeta PMT ON PMT.post_id = P.ID AND PMT.meta_key = 'intervenciones_0_texto' + WHERE P.ID = $id + AND P.post_status = 'publish' + AND P.post_type = 'actividades'"; + return $this->execute_sql( $sql ); + } + + /** * Summary function */ diff --git a/ActividadesWP/v5/items/index.php b/ActividadesWP/v5/items/index.php index a12a65b..71918de 100644 --- a/ActividadesWP/v5/items/index.php +++ b/ActividadesWP/v5/items/index.php @@ -74,6 +74,12 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&locale=es switch ( $func ){ + case "translations": + listActivitiesTranslations(); + break; + case "thumbnail": + activity_thumbnail($id); + break; case "sqlite": exportToSQLite($year, $month, $limit=10); break; @@ -641,7 +647,9 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&local $response_item=array( "id" => $ID, "locale" => LOCALE, - "type" => "activity" + "type" => "activity", + "slug" => $slug, + "title" => $title ); $confmeta = $activity->activity_meta( $ID ); @@ -657,7 +665,12 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&local $response_item['rm'] = false; $response_item['biblestudy'] = $numero_de_estudio_biblico; $response_item['duration'] = ''; - $response_item['thumbnail'] = $thumbnail; + + if($thumbnail != ''){ + $response_item['thumbnail'] = 'https://actividadeswp.carpa.com/wp-content/uploads/' . $thumbnail; + } else { + $response_item['thumbnail'] = 'https://ik.imagekit.io/lgccc/tr:w-1920,f-auto/youtube_thumbnail_46396.png'; + } // $response_item['youtube'] = $youtube; @@ -799,8 +812,48 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&local $db = $database->closeConnection(); } - function activity_summary( $id ){ + function activity_thumbnail( $id ){ + $database = new Database(); + $db = $database->getConnection(); + + $activity = new Actividad($db); + + $stmt = $activity->detail($id,LOCALE); + + $num = $stmt->rowCount(); + if($num>0){ + $conferences_arr = []; + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ + extract($row); + + $confmeta = $activity->activity_meta( $ID ); + + extract($confmeta); + + $response_item=array( + "id" => $ID, + ); + + if($thumbnail != ''){ + $response_item['thumbnail'] = 'https://actividadeswp.carpa.com/wp-content/uploads/' . $thumbnail; + } else { + $response_item['thumbnail'] = 'https://ik.imagekit.io/lgccc/tr:w-1920,f-auto/youtube_thumbnail_46396.png'; + } + + array_push($conferences_arr, $response_item); + + } + } + + $data = $conferences_arr; + + send_response( $conferences_arr[0]['thumbnail'] ); + $db = $database->closeConnection(); + } + + + function activity_summary( $id ){ $database = new Database(); $db = $database->getConnection(); @@ -819,6 +872,8 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&local "id" => $ID, "locale" => LOCALE, "type" => "activity", + "slug" => $slug, + "title" => $title, "date" => $creation_date, "activity" => $activity, "place" => $lugar, @@ -866,7 +921,8 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&local $response_item=array( "id" => $ID, "locale" => LOCALE, - "type" => "activity" + "type" => "activity", + "slug" => $slug ); $confmeta = $activity->activity_meta( $ID ); @@ -882,7 +938,12 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&local $response_item['rm'] = false; $response_item['biblestudy'] = $numero_de_estudio_biblico; $response_item['duration'] = ''; - $response_item['thumbnail'] = $thumbnail; + + if($thumbnail != ''){ + $response_item['thumbnail'] = 'https://actividadeswp.carpa.com/wp-content/uploads/' . $thumbnail; + } else { + $response_item['thumbnail'] = 'https://ik.imagekit.io/lgccc/tr:w-1920,f-auto/youtube_thumbnail_46396.png'; + } // $response_item['youtube'] = $youtube; @@ -1527,4 +1588,106 @@ https://actividadeswp.carpa.com/v3/actividades/?cache=false&f=list&limit=8&local // Output the 36 character UUID. return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); + } + + function listActivitiesTranslations(){ + 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, 'es', null, false, $history, 10000, '2021-12-24' ); + + $num = $stmt->rowCount(); + + $data = []; + + if($num>0){ + $activities_array=array(); + + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ + + extract($row); + + $response_item=array( + "id" => $ID, + "locale" => 'es', + "type" => "activity", + "slug" => $slug, + "title" => $title + ); + + $confmeta = $activity->activity_meta( $ID ); + + extract($confmeta); + + $response_item['date'] = substr($date,0,10); + $response_item['activity'] = $actividad; + $response_item['place'] = $lugar; + $response_item['city'] = $city; + $response_item['state'] = $state; + $response_item['country'] = $country; + $response_item['rm'] = false; + $response_item['biblestudy'] = $numero_de_estudio_biblico; + $response_item['duration'] = ''; + $response_item['slug'] = 'https://www.carpa.com/es/actividades/'.substr($date,0,4).'/'.substr($date,5,2).'/'.$slug; + + $translations = unserialize($translationmeta); + $newtranslations = []; + + $t['files'] = []; + + foreach($translations as $translation_locale=>$translation_id){ + if($translation_locale == LOCALE){ + $t = []; + $t['locale'] = $translation_locale; + $t['id'] = $translation_id; + + $a3 = new Actividad($db); + $summary = $activity->activity_summary($translation_id, $translation_locale); + $s = $summary->fetch(PDO::FETCH_ASSOC); + $t['title'] = $s['title']; + $t['hasText'] = $s['has_text']; + $t['slug'] = 'https://www.carpa.com/'.$translation_locale.'/actividades/'.substr($date,0,4).'/'.substr($date,5,2).'/'.$s['slug']; + $t['files'] = []; + + $tempFiles = []; + + // // //Get filedata + $a2 = new Actividad($db); + $fileData = $a2->get_activity_files( $translation_id ); + $files = $fileData->fetch(PDO::FETCH_ASSOC); + $fileTypes = ['videos','audios','textos','enlaces']; + if($files['use_files']){ + + foreach($fileTypes as $type){ + if(!is_array($tempFiles[$type])){ + $tempFiles[$type] = []; + } + if($files[$type] > 0){ + $t1 = $activity->get_files( $translation_id, $type, $files[$type]); + array_push($tempFiles[$type],$t1); + } + } + + } + + $t['files'] = $tempFiles; + + array_push($newtranslations,$t); + } + } + + $response_item['translations'] = $newtranslations; + + $response_item['timestamp'] = (new DateTime($date, new DateTimeZone('America/Bogota')))->getTimestamp(); + + array_push($data,$response_item); + } + } + + send_response( $data ); + $db = $database->closeConnection(); } \ No newline at end of file