Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

test [2013/07/18 15:45]
Daniele Neroni creata
test [2019/02/12 05:59] (versione attuale)
Daniele Neroni
Linea 6: Linea 6:
   $objCpm1->​cpm_viewRandomMedia(1,​1,​$options);​   $objCpm1->​cpm_viewRandomMedia(1,​1,​$options);​
 </​php>​ </​php>​
 +
 +
 +{{stars>​1/​5}}
 +{{stars>​-1/​5}}
 +{{stars>​2}}
 +
 +<php>
 +
 +
 +
 + ​$base_url = "​http://​gallery.carrimerci.it/​random/​piwigo-random-backend.php";​
 +         echo file_get_contents($base_url . "?​mode=html&​cat_id=119"​); ​
 +
 +</​php>​
 +
 +
 +
 +~~NOCACHE~~
 +
 +<​html>​
 +<​h1>​Random image, no style</​h1>​
 +    <​p>​This <span id="​random_image">​
 +      <script type="​text/​javascript"​
 +     src="//​gallery.carrimerci.it/​random/​piwigo-random-backend.php?​element_name=cat&​amp;​cat_id=8"​
 +     async>
 +      </​script>​
 +    </​span>​ is a random image</​p>​
 +    ​
 +    ​
 +<​h1>​Specifying a category</​h1>​
 +    <div id="​cat">​
 +      <script type="​text/​javascript"​
 +       src="//​gallery.carrimerci.it/​random/​piwigo-random-backend.php?​element_name=cat&​amp;​maximages=3&​amp;​cat_id=8&​amp;"​
 +       async>
 +      </​script>​
 +    </​div>​
 +    <​h1>​Several images at a time</​h1>​
 +    <div id="​several">​
 +      <script type="​text/​javascript"​
 +       src="//​gallery.carrimerci.it/​random/​piwigo-random-backend.php?​element_name=several&​amp;​cat_id=8"​
 +       async>
 +      </​script>​
 +    </​div>​
 +    ​
 +    ​
 +        <​h1>​Styling the images</​h1>​
 +        <div id="​styled_random_image">​
 +      <style type="​text/​css"​ scoped>
 + #​styled_random_image img {border: solid 1px grey; padding:​5px;​ margin:​5px;​}
 + #​styled_random_image img:hover {opacity: .8}
 + #​styled_random_image {text-align:​right;​ display: inline; background-color:​ white;}
 + @media all and (max-device-width:​ 599px),
 + all and (max-width: 599px)
 + {
 + #​styled_random_image {display: none}
 + }
 +      </​style>​
 +      <script type="​text/​javascript"​
 +       src="//​gallery.carrimerci.it/​random/​piwigo-random-backend.php?​element_name=styled_random_image&​amp;​cat_id=8"​
 +       async>
 +      </​script>​
 +    </​div>​
 +
 +    ​
 +    ​
 +    ​
 +    </​html>​
 +    ​
 +    ​
 +----
 + 
 +
 +<php>
 +$cat_id = 119;
 +$per_page = 2;
 +
 +$webapi1 = "​http://​gallery.carrimerci.it/​ws.php?​format=rest&​method=pwg.categories.getImages&​cat_id=$cat_id&​per_page=$per_page"​ ;
 +
 +$strXml1 = file_get_contents($webapi1);​
 +$objXml1 = new SimpleXmlElement($strXml1);​
 +
 +$piwigo = array();
 +$counter = 1;
 +foreach($objXml1->​images->​image as $value) {
 + $thumbs_string = strval($value->​derivatives->​square->​url);​
 + $url_string = strval($value->​categories->​category->​attributes()->​page_url);​
 + $data_available = strval($value->​categories->​category->​attributes()->​page_url);​ //modify
 + $piwigo[$counter]['​thumb'​] = $thumbs_string;​
 + $piwigo[$counter]['​url'​] = $url_string;​
 + $counter++;​
 +}
 +foreach($piwigo as $value) {
 + echo '​ <​a target="​_blank"​ href="'​ . $value["​url"​] . '">'​ . '<​img src="'​ . $value["​thumb"​] . '"></​a>'​ . PHP_EOL;
 +}
 +
 +?>
 + <​hr>​
 + <​p>​DEMO OF THE WORKAROUD SOLUTION </p>
 +<?php
 +//we need to calculate the total number of pictures in the gallery
 +$cat_id = "​8";​
 +$per_page = "​10";​ //number of latest pictures you want to show
 +$webapi2 = "​http://​gallery.carrimerci.it/​ws.php?​format=rest&​method=pwg.categories.getList&​cat_id=&​public=true"; ​
 +$strXml2 = file_get_contents($webapi2);​
 +$objXml2 = new SimpleXmlElement($strXml2);​
 +$count_images = 0;
 +foreach($objXml2->​categories->​category as $value) {
 + $count_images += $value->​attributes()->​total_nb_images;​
 +}
 +echo '<​p>​Calculated total images: ' . $count_images . ' => Calculated number of pages: ' . intval($count_images/​$per_page) . '</​p>';​
 +
 +//start parsing the web api output with the workaround logic
 +$per_page1 = $per_page * 2; //we need to retrive double number of specified pages because $count_images/​$per_page is float number. we will slice it at the end
 +$pages1 = intval($count_images/​$per_page1);​ //
 +$webapi3 = "​http://​gallery.carrimerci.it/​ws.php?​format=rest&​method=pwg.categories.getImages&​order=date_available&​per_page="​ . $per_page1 . "&​page="​ . $pages1;
 +echo '<​p>​The calculated Web Api request is: <​strong>'​ . $webapi3 . '</​strong></​p>';​
 +$strXml3 = file_get_contents($webapi3);​
 +$objXml3 = new SimpleXmlElement($strXml3);​
 +
 +$piwigo2 = array();
 +$counter2 = 1;
 +foreach($objXml3->​images->​image as $value) {
 + $thumbs_string = strval($value->​derivatives->​square->​url);​
 + $url_string = strval($value->​categories->​category->​attributes()->​page_url);​
 + $piwigo2[$counter2]['​thumb'​] = $thumbs_string;​
 + $piwigo2[$counter2]['​url'​] = $url_string;​
 + $counter2++;​
 +}
 +$piwigo2 = array_reverse($piwigo2);​
 +$piwigo2 = array_slice($piwigo2,​ 0, $per_page);
 +
 +foreach($piwigo2 as $value) {
 + echo '​ <​a target="​_blank"​ href="'​ . $value["​url"​] . '">'​ . '<​img src="'​ . $value["​thumb"​] . '"></​a>'​ . PHP_EOL;
 +}
 +</​php>​
 +
  • Ultima modifica: 2019/02/12 05:59