Random Front Page Image for Ver 3.13-r1

General discussion about installation and use of the Archon software. (Link to your site here.)

Moderators: paulnsorensen, kylefox2, prom, rishel, sgriffin

Random Front Page Image for Ver 3.13-r1

Postby beltramie » Mon Jan 24, 2011 5:21 pm

I previously posted similar code to set up a randomly generated front page image that links back to the parent digital collection. I just upgraded from version 2.x to 3.x, and the field headings in the database changed enough that this code needed some updates. Here is a new version of this random image generator that is working at least for version 3.13-r1. Here is an example of what the final product will look like

http://archon.nl.edu

It queries the database, pulls out a single image id, the id of the parent digital collection, some title info, assigns all these to variables, and uses these variables to call up the image and the collection info on the front page.

Below is the code for my randomizer called "randomblobid.php", which sits the same directory as my theme.

<?php

/*
*
* @original author Nat Wilson
*
*This script picks a random blob file from the digital library, links that blob with its parent
*digital collection record and and assigns information about those records to 3 variables
* 1) The blobs record ID # is set to a variable named $id.
* 2) The title field in the parent collection is set to a variable named $title.
* 3) The blob's DigitalContentID field is set to a variable named $collection.
*
*These variables can be used to create displayed images and links to their parent digital collections.
*
*I will put any setting or phrase that needs configuration in square brackets, i.e. [user name], replace the brackets and everything in it
*with the setting that is specific to your instance of Archon.
*
*The following lines will have to be changed depending on the institution's database and system configuration:
*
*$mysql_link = mysql_connect("localhost", "[database user name]", "[user password]");
*Note: "localhost" should work for most instances.
*
*mysql_select_db("[database name]", $mysql_link) or die("Could not select database");
*
*FileTypeID = '[numeric type ID of the kind of file you want to include]'
*Note: this is to prevent pdf's from coming up in the result. Until we figure out how to automatically generate thumbnail previews for
*these we will have to limit the search to just images. See the FileTypeID field in the table for #'s associated with file types.
*
*It is also necessary to make a new limited database user for this function. In the case below, I made a user
*named "archon" with the following database privileges:
*
*Select
*Show/View
*Execute

*Bug: Certain special characters dont get passed well through the variables and come out as "?." This might be fixed if we
*decoded the characters as they come out in index.php

*/
$mysql_link = mysql_connect("localhost", "[login]", "[password]");
if (!$mysql_link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("[database name]", $mysql_link) or die("Could not select database");

$result = mysql_query(
"Select
tblDigitalLibrary_Files.ID,
tblDigitalLibrary_DigitalContent.Title,
tblDigitalLibrary_Files.DigitalContentID
from tblDigitalLibrary_Files,
tblDigitalLibrary_DigitalContent
where tblDigitalLibrary_Files.FileTypeID = '2'
and tblDigitalLibrary_Files.DigitalContentID = tblDigitalLibrary_DigitalContent.ID
ORDER BY RAND() LIMIT 1");

while($row = mysql_fetch_object($result))
{
$id=$row->ID;
$title=$row->Title;
$collection=$row->DigitalContentID;
}

mysql_close($mysql_link);

?>

----------------------------------------------------------------------------------------------------------------

The main index.php file in my theme directory calls variables from the randomblobid.php file like this:

<div id='themeindex' class='bground'>
<dl>
<dt class='index'>
<?php include("randomblobid.php");
echo "<a href='..?p=digitallibrary/digitalcontent&id=".$collection.
"'><img src='..?p=digitallibrary/getfile&id=".$id."&preview=long' height=250></a>";
echo "<br>Learn more about this collection: <a href='..?p=digitallibrary/digitalcontent&id=".$collection."'>"
.$title."</a>";
?>
</dt>
</dl>
</div>
Last edited by beltramie on Mon Jun 13, 2011 10:43 am, edited 1 time in total.
beltramie
 
Posts: 157
Joined: Mon Feb 16, 2009 3:58 pm
Location: Carleton College, Northfield MN

Re: Random Front Page Image for Ver 3.13-r1

Postby sgriffin » Mon Jan 24, 2011 5:44 pm

Wow, that's really cool! Do you ever have problems with different size images, like portrait versus horizontal?
(I'm not code-literate person, so if there was some blip in there about sizing issues, I didn't/couldn't recognize it...)
sgriffin
 
Posts: 56
Joined: Mon Dec 27, 2010 10:56 am
Location: Central Ohio

Re: Random Front Page Image for Ver 3.13-r1

Postby beltramie » Mon Jan 24, 2011 6:08 pm

Thanks,
There was one set of images on that site that had a really long horizontal dimension which came out looking a little disproportionate. I never figured out how to make those look good through this randomizer without throwing off the display of the other images the random image display might pull up.

If anyone on the forum knows a better way of sizing the random image then how I did it, let me know and Ill update the original post.

But for all the other typically proportioned images, both portrait and landscape, it worked well.
beltramie
 
Posts: 157
Joined: Mon Feb 16, 2009 3:58 pm
Location: Carleton College, Northfield MN

Re: Random Front Page Image for Ver 3.13-r1

Postby beltramie » Mon Jun 13, 2011 10:47 am

I edited the display code above so it pulls out the long preview blob (closer to the image dimensions as on the thumbnail display page). This should constrain the image size if its an unusual dimension.
beltramie
 
Posts: 157
Joined: Mon Feb 16, 2009 3:58 pm
Location: Carleton College, Northfield MN

Re: Random Front Page Image for Ver 3.13-r1

Postby david.b.malone » Wed Jun 15, 2011 4:42 pm

beltramie wrote:I edited the display code above so it pulls out the long preview blob (closer to the image dimensions as on the thumbnail display page). This should constrain the image size if its an unusual dimension.


Thanks for the update. I've wanted to add something like this to our front page and had forgotten about it. After having installed it I find that it takes about 20-25 seconds for the page to build as it calls for the necessary data. Any thoughts on why this would be? This is likely a database issue and I wonder, not being a database manager-type, what would need to be looked at to speed up the response.

David Malone
Wheaton College (IL)
v3.20 on Solaris using MySQL
David B. Malone
Wheaton College Archives & Special Collections
david.b.malone
 
Posts: 186
Joined: Mon Apr 21, 2008 1:44 pm
Location: Wheaton, IL

Re: Random Front Page Image for Ver 3.13-r1

Postby paulnsorensen » Wed Jun 15, 2011 5:05 pm

You might be able to speed it up if you use the new file caching feature.

Code: Select all
$objFile = New File($row['ID']);
$url = $objFile->getFileURL(DIGITALLIBRARY_FILE_PREVIEWLONG);
// use $url in the img tag instead of the getfile?id= url
paulnsorensen
Site Admin
 
Posts: 631
Joined: Mon Mar 31, 2008 8:55 am

Re: Random Front Page Image for Ver 3.13-r1

Postby david.b.malone » Thu Jun 16, 2011 8:43 am

paulnsorensen wrote:You might be able to speed it up if you use the new file caching feature.

Code: Select all
$objFile = New File($row['ID']);
$url = $objFile->getFileURL(DIGITALLIBRARY_FILE_PREVIEWLONG);
// use $url in the img tag instead of the getfile?id= url


Thanks for the response and input. As I am php-coding challenged I'd welcome a bit more direction. Does the "$"-code go into the randomblobid file or the index file? Or, a mixture of both? Is there code from randomblobid that will need to be removed??

Our sysadmins don't like when I nuke the system.... ;-)

David "I'm no coder-though if I were I could make a ton o' cash" Malone
Wheaton College (IL)
David B. Malone
Wheaton College Archives & Special Collections
david.b.malone
 
Posts: 186
Joined: Mon Apr 21, 2008 1:44 pm
Location: Wheaton, IL

Re: Random Front Page Image for Ver 3.13-r1

Postby paulnsorensen » Tue Jun 21, 2011 5:28 pm

This should be a faster way to do this, and though it's 2 more queries, they are all faster. I had this all in my index.php page of a theme.

Code: Select all
<?php
$result = $_ARCHON->mdb2->query("SELECT ID FROM tblDigitalLibrary_Files WHERE FileTypeID = '2' AND DigitalContentID > 0");
$arrIDs = array();
while($row = $result->fetchRow()){
  $arrIDs[] = $row['ID'];
}
// we use a random index of the array to get our ID
$objFile = New File($arrIDs[rand(0,count($arrIDs)-1)]);
$objFile->dbLoad();
$objDigitalContent = New DigitalContent($objFile->DigitalContentID);
$url = $objFile->getFileURL(DIGITALLIBRARY_FILE_PREVIEWLONG);
?>

<div id='themeindex' class='bground'>
   <dl>
      <dt class='index'>
<?php 
       echo "<a href='..?p=digitallibrary/digitalcontent&id=".$objDigitalContent->ID."'><img src='".$url."' height=250></a>";
       echo "<br/>Learn more about this collection: <a href='..?p=digitallibrary/digitalcontent&id=".$objDigitalContent->ID."'>".$objDigitalContent->toString()."</a>";
?>
     </dt>
   </dl>
</div>
paulnsorensen
Site Admin
 
Posts: 631
Joined: Mon Mar 31, 2008 8:55 am

Re: Random Front Page Image for Ver 3.13-r1

Postby beltramie » Tue Jul 05, 2011 9:43 am

Hi Paul,

I just tried this script out and got this error.

Warning: Call to undefined function File::getFileURL in /var/www/Archon/themes/carleton/index.php

I have not yet upgraded to 3.2 yet, is this a function that is only available in the newest version?
beltramie
 
Posts: 157
Joined: Mon Feb 16, 2009 3:58 pm
Location: Carleton College, Northfield MN

Re: Random Front Page Image for Ver 3.13-r1

Postby paulnsorensen » Fri Jul 08, 2011 3:42 pm

Yeah. You'll need 3.2
paulnsorensen
Site Admin
 
Posts: 631
Joined: Mon Mar 31, 2008 8:55 am

Re: Random Front Page Image for Ver 3.13-r1

Postby arinekhen » Tue Feb 12, 2013 2:49 pm

Hi. Just wanted you to know I added this feature to archives.lib.siu.edu and I really like it. I notice that once in a while it picks a collection with a missing image, so maybe I'll add code to check and pick another one if this is the case.

Thanks.
arinekhen
 
Posts: 4
Joined: Wed Aug 22, 2012 11:46 am


Return to Archon Discussion

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

cron