| Server IP : 127.0.0.1 / Your IP : 216.73.216.109 Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10 System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64 User : SERVERWEB ( 0) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/laragon/backup/www/php/ |
Upload File : |
<?php
use Illuminate\Pagination\LengthAwarePaginator;
$apiUrl = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/posts";
function decode_api($api_url) {
$response = file_get_contents($api_url);
if ($response === false) {
return array();
}
$data = json_decode($response, true);
if ($data === null) {
return array();
}
return $data;
}
function getAllByCategory(){
$categoryIds = [261,13,1, 27,273,5,25,17,24,266];
$noticiasByCategory = [];
foreach ($categoryIds as $categoryId) {
$url = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/posts?categories={$categoryId}";
$noticias = decode_api($url);
$noticiasByCategory[$categoryId] = $noticias;
}
return $noticiasByCategory;
}
function get3NewsByCategory(string $categoryId){
$url = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/posts?categories={$categoryId}&per_page=3";
$noticiasByCategory = decode_api($url);
return $noticiasByCategory;
}
function getNewsByCategory(string $categoryId){
$url = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/posts?categories={$categoryId}";
$noticiasByCategory = decode_api($url);
return $noticiasByCategory;
}
function getNewsByUser(string $userId){
$url = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/posts?author={$userId}";
$noticiasByUser = decode_api($url);
return $noticiasByUser;
}
function getListC($i){
$urlUser ="https://prensa.quillacollo.gob.bo/wp-json/wp/v2/users";
$urlCategories ="https://prensa.quillacollo.gob.bo/wp-json/wp/v2/categories";
$urlTags ="https://prensa.quillacollo.gob.bo/wp-json/wp/v2/tags";
switch ($i) {
case "categories":
$List = decode_api($urlCategories);
break;
case "users":
$List = decode_api($urlUser);
break;
case "tags":
$List = decode_api($urlTags);
break;
}
return $List;
}
function getList($filtro) {
$List = [];
$url = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/{$filtro}";
$i = 1;
do {
$urlC = $url . "?page={$i}";
$ListC = decode_api($urlC);
if (!empty($ListC)) {
$List = array_merge($List, $ListC);
$i++;
} else {
break;
}
} while (true);
return $List;
}
function getAllNews()
{ global $apiUrl;
$noticias = decode_api($apiUrl);
return $noticias;
}
// function getAll()
// { global $apiUrl;
// $urlUsers ="https://prensa.quillacollo.gob.bo/wp-json/wp/v2/users";
// $urlCategories ="https://prensa.quillacollo.gob.bo/wp-json/wp/v2/categories";
// $urlTags ="https://prensa.quillacollo.gob.bo/wp-json/wp/v2/tags";
// $noticias = decode_api($apiUrl);
// $userList = decode_api($urlUsers);
// $catList = decode_api($urlCategories);
// $tagList = decode_api($urlTags);
// $currentPage = LengthAwarePaginator::resolveCurrentPage();
// $perPage = 5; // Number of items per page
// $items = collect($noticias);
// $total = count($items);
// $noticias = new LengthAwarePaginator(
// $items->forPage($currentPage, $perPage),
// $total,
// $perPage,
// $currentPage
// );
// $noticias->setPath('news');
// return $noticias;
// }
function truncateDescription($description, $maxWords = 15, $maxChars = 100) {
// Truncate by words
$words = explode(' ', $description);
if (count($words) > $maxWords) {
$description = implode(' ', array_slice($words, 0, $maxWords)) . '...';
}
// Truncate by characters
if (strlen($description) > $maxChars) {
$description = substr($description, 0, $maxChars) . '...';
}
return $description;
}
?>