Cpmfetch V2.2 Test Programs and Include files Cpmfetch V2.2 Test Programs and Include files
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Cpmfetch V2.2 Test Programs and Include files

Started by 406man, August 08, 2024, 04:11:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

406man

Cpmfetch can be awkward to get working until you are familiar with it and, even then, it's easy to make silly mistakes during the development process. I've introduced a new way of working for V2.2 to make it easier to get cpmfetch commands working before integrating them into Wordpress and other types of web site. I recommend those who are new to cpmfetch use this method but it's entirely optional and someone experienced with cpmfetch might prefer to continue the old way of working.

The principle it that the cpmfetch commands are written in a small, simple file which is read into other programs when needed. In the IT world this is often known as an Include file. Web site developers only have to change this Include file. The test program reads in the Include file and displays the results. When this process is complete and delivers the results that are wanted the same Include file is run from Wordpress or other web site without having to change it. This should hopefully mean fewer mistakes and technical errors. When integrating the results into Wordpress there can be unexpected changes in appearance due to the CSS styling applied by the Wordpress theme or plugin. Having a simple test program means the basic appearance can be developed first, then integrated into Wordpress / other web site and revised to suit in an iterative process.

There are two test programs:
testfetch.php   This tests cpmfetch when it returns a simple grid of pictures or text
testslideshow.php This tests the slideshow feature
The Include files are all in the /inc sub-directory below the main cpmfetch directory
Both of them can work with many different Include files. I'll explain how you select the Include file to use. The principles are the same for both test programs but the file names are different

testfetch.php
It tries to include a file called cpmfetchsetup.inc.php     If this exists, it always uses it. If it doesn't exist it looks for similarly named files: cpmfetchsetup*.inc.php     where * can be any text which I've called the suffix. This allows you to develop multiple configurations each with its own name. For example, you might have Wordpress shortcodes (more about this in the Wordpress topic) numbered 508 and 509 for two different places where you pull in pictures from your gallery. You could name your setup files cpmfetchsetup508.inc.php  and cpmfetchsetup509.inc.php so you can easily recognise how they relate to the shortcode       When it finds a file with this pattern of name testfetch lists all of them and asks which one to use. Once chosen, the test program URL is updated so you can keep using that Include file by Refreshing the web browser after making changes. This method avoids the need to keep making changes to the Wordpress / web site configuration as only the Include file has to be changed.  Only update the Include file between the ===== divisions because the === section is used to recognise the code block. To run a test use the URL below, updated to suit your gallery:

https://www.yourdomain.com/yourgallery/cpmfetch/testfetch.php

The test program displays the cpmfetch code that has been used as I found this helped the development process.

testslideshow.php
This works in the same way as testfetch.php above, the only difference being that the Include files are named cpmslideshowsetup.inc.php     and  cpmslideshowsetup*.inc.php     

The Include files in the zip file should retrieve pictures from any gallery once the cpmfetch code is installed so I recommend running the unaltered Include files first, then rename them to something else and edit those copies to suit what you want to show on your web site.

The Include file for the slideshow has a lot more CSS styling to set up the basic appearance. Change it if you wish but be ready for the appearance to look strange and the Wordpress / web site styling will inevitably change it again.

Below is an example of an Include file for cpmfetchtest.php. I've split the $options definition over multiple lines as I think it's easier to read and spot any errors.

<?php
// cpmfetchsetup3.inc.php
//------------------------------------------------------------------------------------------------------------
// THIS SECTION CONTAINS THE PHP CODE TO BE USE BY ANOTHER APPLICATION, FOR EXAMPLE WORDPRESS. ADD YOUR
// CPMFETCH COMMANDS BETWEEN THE ===== LINES AND COMMENT OUT ANY LINES OF CODE YOU DON'T NEED USING //   
// DON'T TOUCH THE START OF CODE AND END OF CODE LINES
//============================================================================================================
//= Start of code for the application ==

$options = array(
'cellstyleproperties' => 'vertical-align:top',
'imageheight' => '250',
'imagesize' => 'int' ,
'subtitle' => 'Title: {{pTitle}}, Photographer: {{uUser_name}}',
'subtitlestyleproperties' => 'color:green;', 'subtitlelink' => 'x',
'tableattributes' => array("width" => "100%"),
'tablestyleproperties' => 'text-align:center; width:70%;margin-left:auto;margin-right:auto;vertical-align:top',
'windowtarget' => '_blank-js',
);
$objCpm-> cpm_viewRandomMediaFrom("album=228",2, 2, $options);

//= End of code for the application ==
//============================================================================================================

?>


The Include files all live in the /inc directory below the main cpmfetch directory. Don't change any of the directory structure or names as the coding will break. In the cpmfetch/inc/examples directory I've included a large number of example include files that create a grid of static images or text output. There are none for slide shows. They have very long names which indicate the cpmfetch function that they run. It means you don't have to type in the names and can hopefully avoid making typing errors. With a handful of exceptions which I'll explain they all work so you can check out the functionality without creating any Include files yourself. All you need to do is copy or move them up one level into the /inc directory and then run the test program. The exceptions are a couple of functions that need an Albumid passed in. I've included a number which works in my gallery but may not work in yours. The example Include files in their current form all choose images from the entire set of publically available images. You may wish to narrow down the set to, for example, a particular category or album, pictures uploaded since a certain date or pictures containing a particular keyword. These options are all possible and will require the source parameter in the Include file to be updated. For example "cat=5", "album=23,25" or "keyword=vacation2023".

Exceptions
cpm_listMediaCountForAlbum
cpm_viewMediaFromAlbum


Finally
Remember:
i) the Include files must be in the /inc directory to be able to be seen by the test programs and work correctly.
ii) if you have either cpmfetchsetup.inc.php or cpmslideshowsetup.inc.php present in the /inc directory, these will be run automatically and any others will not be seen. Rename them or delete if you wish to use other setup files.