We are in the process of evaluating Drupal as a possibility to switch from Joomla.

I have three remaining issues I cannot get resolved on my own. I tried posting about one of them in the "Post Installation" forum and got little help. So, I am going to give it a go in this forum and see if some of you have solved these issues.

1) I need to have an image randomly change, in a block, each time the user clicks a link or reloads the page. I have gotten bits and pieces to this issue, and not much of any of it makes any sense. Does anyone know a good resource I can read that explains it in step-by-step detail? I am stumped.

2) I need to embed Youtube videos on the fron page of the site. While I think I have loaded all the modules to do this, the help page in the "media: Youtube" module references a lot of things I have never heard of nor seen in Drupal. Again, stumped.

3) We have a few custom PHP scripts I need to run from links and their own block as well. I have no idea where to start with this.

I have a finite amount of time to evaluate the potential of moving the site from Joomla. Any help would be very much appreciated. I feel confident I am not asking for anything many, many of you have successfully done. I am not opposed to reading whatever I need to read, but so far, I have not been able to find anything that really helps demystify the Drupal implementation.

Comments

VM’s picture

1) I'd use the views.module. Step by step here is difficult without knowing how you are dealing with images in drupal.

2) You don't need the full features media module for this. You can simply use https://drupal.org/project/youtube and then use views to generate blocks and add the blocks to your front page

3) what do you mean custom php scripts? if they are intended to interact with drupal you need to write modules. see the examples.module for examples on how to write a custom block.module

Skuzzy’s picture

1) I am trying to use the "Views" module. I tried 52 variations of the options and have not been able to get one image to show up. I have not found an option that would take a path to where the images are stored on the server. I am pretty sure that has to happen unless Drupal emulates osmosis and absorbs images from the ether. Not sure how to tell you "how we are dealing with images". The images are located in a folder on the server.

2) The trouble I have with "Views" is none of it makes any sense. For example, when I go to Stuctures->Views, then hit the "Add new view", I am lost after that. I cannot relate what I see on the page to what I need to set in order to accomplish any give task. I have had zero success using this for anything, so far.

3) We have scripts which access information stored in a MySQL database which allows comparisons to be made between various objects. The comparison is displayed via a dynamically generated chart (PNG image). Here is a link to the current page: http://www.hitechcreations.com/gameinfo/plane-performance

VM’s picture

1)

I have not found an option that would take a path to where the images are stored on the server.

That would be correct. Views won't do that and expects the paths to the image to be in the database as fields. you may want to look at the filefield sources module to have drupal interact with images in a folder. If you are bypassing Drupal for image handling, then you will need to write your own php and randomizing code in a block module.

2) I suggest using google and use keywords 'node one views' - the video tutorials you find there are (IMO) the best ones out there.

3) to the best of my knowledge if what you are interacting with is in Drupal then you will be writing a module.

* note, i don't suggest the phpfilter as it can pose security issues and is being removed from Drupal 8. If you've code you want drupal to run. Generate a module.

Skuzzy’s picture

I am not trying to by-pass Drupal for anything. I just do not have a clue how to get things done in Drupal. I am very well versed in C, PHP, MySQL, and Apache. I want to take the shortest path to get this done. Time is not on my side. What is on our WEB now, is what I want to be presented by Drupal, nothing more.

I just cannot figure out how to get, what I think is something quite simple, to work within the framework of Drupal.

I do not understand the phrase, "interacting with Drupal" as it pertains to spewing a chart out from a collection of database elements which do not reside within Drupal's database.

Unfortunately, we cannot view anything at vimeo due to security. Apparently, a few systems caught some viruses there once and that site is permanently blocked. Time not being on my side is causing high levels of stress for me.

I do appreciate the help. Just not certain if this is going to work out, in the time frame I have been tasked with.

Skuzzy’s picture

Well, I just got told to drop Drupal. I went to the boss to see what we could do about opening up so I could see that 27 part video series on "Views" and he told me to find another solution.

His concerns are, if it is that complicated to put up a random image, then we are looking at the wrong solution.

If I could have gotten the site up and running, it would have given me time to learn the intricacies of Drupal, but after 5 days and the front page not being done, it is time to make the call.

Again, thank you for the help. It was appreciated. I wish it would have worked out.

VM’s picture

You didn't need to watch all 27 parts to generate a random image block with views. views is a query writer which saves one from having to manually write their own queries in custom modules. As such, it's an extensive tool which is why there are 27 parts to the node one video collection.

Skuzzy’s picture

I had no idea which parts to watch. All I could tell him was there were 27 parts to the series and I had no idea how much longer it was going to take to accomplish the task.

My back was against the wall. He already knew I could write a PHP program to accomplish the task in about 15 minutes, because I have done that. I was already 5 days (12 hours a day) into trying to get this to work and it became a matter of cost versus functionality.

I badly underestimated how much effort it was going to take to move to Drupal. I wish I could have gotten this figured out in a timely manner. I really like many of the features of Drupal over Joomla. I dread going back there as I am going to have to migrate the site by hand.

He is not being unreasonable. I had to do this once before and it took me a week to get the entire site moved, by hand (major site update). I am nearly into the same time period and have not gotten a working front page yet. I have been stagnate on this one problem for too long. I did not realize how complex it was going to be.

I do appreciate your effort to help. I wish I had the time to get a good grasp on how to get things done in Drupal. I think it is still a better choice.

VM’s picture

if you don't want to use views, you can use your own PHP as has been stated at least twice in this thread.

If you want a custom front page and your boss decides to ignore best practices under the premise of time savings, you can generate a page--front.tpl.php file in your theme and do whatever you want with whatever PHP you want and be done in 15 minutes.

Note that time savings earned up front when ignoring best practices are spent later when something breaks, another developer takes over, or the code used is insecure now or in the future.

Skuzzy’s picture

VM, please do not take my tone as being confrontational. It is not intended. I do not ever wish to work around a given implementation. Had that been my thought process, I would not have bothered to ask how to accomplish something, using the tools available.

This is not my first rodeo. I am frustrated and there is no doubt it came through my posts. It was not personal and not meant to put Drupal in a bad light. For this type of system I prefer Drupal to Joomla, or Wordpress. I think it is a better solution. It was my recommendation to go to Drupal and drop Joomla.

I am just under some very severe time constraints. Our broken WEB site is costing us money, everyday. I just want to get our site up and working, then I can worry about the elegance and understanding of it all.

I still intend on getting to Drupal, but at this time, my time constraints make it almost impossible due to the perceived complications of Drupal. My inability to make a proper schedule is the real issue. I cannot say, with any confidence, I can have something done in X period of time.

I would not be spending my time answering and posting here if I did not truly think Drupal is a better solution.

VM’s picture

I just want to get our site up and working, then I can worry about the elegance and understanding of it all.

The statement quoted above is where I believe most if not all of your frustration and issues come from. One must have some understanding of what tool they are using to effectively use the tool.

Skuzzy’s picture

I agree 100%.

VM’s picture

For others who actually have the desire to explore and learn or with a "boss" who has some where-with-all:

if drupal knows about your images (ie: they've been uploaded in a filefield or sourced by filefield)

generate a new view
generate a block display in the view
set your image field in the block display
add a sort for Global: Random
set the pager for 1 item
save the view
enable the block
done.

Skuzzy’s picture

That is the first time I have heard anything at all about "filefield". What is that? Where is that?

VM’s picture

I mentioned filefields in my second common on this thread in reference to the filefield sources module which (based on my reading) can utilize images in fields from a folder which is what you stated you wanted to do.

if you are adding an image to a content type to handle images see below.

see: https://drupal.org/node/774742

add field: image - it's a core filefield that handles image files.

Skuzzy’s picture

I am sorry, I do remember that and did look at that. I could not figure out what that was for and how to use it.

VM’s picture

if you meant filefield_sources module it has a feature in which it will "Attach server-side files uploaded via FTP". I mentioned it because you stated "I have not found an option that would take a path to where the images are stored on the server" & "Not sure how to tell you "how we are dealing with images". The images are located in a folder on the server." *note - you mentioned these things in relation to views.module. the filefield_sources module isn't for views. It is for aiding in getting the images to be managed by Drupal via a content type and the fields api which would then open the features that the views.module provides.

In short, Drupal must be aware of the images for any part of drupal to use the images unless you are hardcoding the links to the images (which isn't necessary). Drupal is designed to manage content. images can be content. Work with it and not against it.

if you meant the link: it's core documentation for adding fields to a new content type form. With those fields content is added to Drupal.

As an example; To generate a blog content type or news content type one would create a new content type and title it blog or news.
If one wanted to add images to be displayed when the content type is viewed one would add an imagefield

Those fields are presented to a user when a new blog post is added to the site.
The user utilizes those fields to add the data
that data is saved to the database via the content type form

that data can then be extracted and displayed using core features or the views.module or any of the contrb modules that alter default features in core.

In your use case you are dealing with images. What are those images associated with (if anything)? Will they be reused througout the site in any way?
In its most simple form you can generate a new content type can name it image
you can add an imagefield to the new content type called image
you can remove the default body field that is generated when a new content type is created
you can add any other fields you may need that are associated with the image (if any)
you then go to node/add/image and generate your image nodes
once those nodes are saved to the database you can generate a view of those images in a page, or a block with the views.module.

If using Drupal to handle the images isn't something you want to do then again I state you can use your PHP skills and write a small block.module to randomly pull from the folder where the images are stored. To write a custom block module I suggest downloading the examples.module in contrib. Else if you don't want to write a custom block module you can enable the core phpfilter.module and add your php directly to a block body using the newly acquired php text format provided by the aforementioned phpfilter.module.

afterthought (mileage may vary as I am being very quick about typing the following out):

add your images folder to your theme folder
in it add the following and name it random.php

<?php

/*

	AUTOMATIC IMAGE ROTATOR
	Version 2.2 - December 4, 2003
	Copyright (c) 2002-2003 Dan P. Benjamin, Automatic, Ltd.
	All Rights Reserved.

	http://www.hiveware.com/imagerotator.php
	
	http://www.automaticlabs.com/
	
	
	DISCLAIMER
	Automatic, Ltd. makes no representations or warranties about
	the suitability of the software, either express or
	implied, including but not limited to the implied
	warranties of merchantability, fitness for a particular
	purpose, or non-infringement. Dan P. Benjamin and Automatic, Ltd.
	shall not be liable for any damages suffered by licensee
	as a result of using, modifying or distributing this
	software or its derivatives.
	
	
	ABOUT
	This PHP script will randomly select an image file from a
	folder of images on your webserver.  You can then link to it
	as you would any standard image file and you'll see a random
	image each time you reload.
	
	When you want to add or remove images from the rotation-pool,
	just add or remove them from the image rotation folder.


	VERSION CHANGES
	Version 1.0
		- Release version
	
	Version 1.5
		- Tweaked a few boring bugs
	
	Version 2.0
		- Complete rewrite from the ground-up
		- Made it clearer where to make modifications
		- Made it easier to specify/change the rotation-folder
		- Made it easier to specify/change supported image types
		- Wrote better instructions and info (you're them reading now)
		- Significant speed improvements
		- More error checking
		- Cleaner code (albeit more PHP-specific)
		- Better/faster random number generation and file-type parsing
		- Added a feature where the image to display can be specified
		- Added a cool feature where, if an error occurs (such as no
		  images being found in the specified folder) *and* you're
		  lucky enough to have the GD libraries compiled into PHP on
		  your webserver, we generate a replacement "error image" on
		  the fly.
		
    Version 2.1
        - Updated a potential security flaw when value-matching
          filenames

    Version 2.2
        - Updated a few more potential security issues
        - Optimized the code a bit.
        - Expanded the doc for adding new mime/image types.

        Thanks to faithful ALA reader Justin Greer for
        lots of good tips and solid code contribution!


	INSTRUCTIONS
	1. Modify the $folder setting in the configuration section below.
	2. Add image types if needed (most users can ignore that part).
	3. Upload this file (rotate.php) to your webserver.  I recommend
	   uploading it to the same folder as your images.
	4. Link to the file as you would any normal image file, like this:

			<img src="http://example.com/rotate.php">

	5. You can also specify the image to display like this:

			<img src="http://example.com/rotate.php?img=gorilla.jpg">
		
		This would specify that an image named "gorilla.jpg" located
		in the image-rotation folder should be displayed.
	
	That's it, you're done.

*/




/* ------------------------- CONFIGURATION -----------------------


	Set $folder to the full path to the location of your images.
	For example: $folder = '/user/me/example.com/images/';
	If the rotate.php file will be in the same folder as your
	images then you should leave it set to $folder = '.';

*/


	$folder = '.';


/*	

	Most users can safely ignore this part.  If you're a programmer,
	keep reading, if not, you're done.  Go get some coffee.

    If you'd like to enable additional image types other than
	gif, jpg, and png, add a duplicate line to the section below
	for the new image type.
	
	Add the new file-type, single-quoted, inside brackets.
	
	Add the mime-type to be sent to the browser, also single-quoted,
	after the equal sign.
	
	For example:
	
	PDF Files:

		$extList['pdf'] = 'application/pdf';
	
    CSS Files:

        $extList['css'] = 'text/css';

    You can even serve up random HTML files:

	    $extList['html'] = 'text/html';
	    $extList['htm'] = 'text/html';

    Just be sure your mime-type definition is correct!

*/

    $extList = array();
	$extList['gif'] = 'image/gif';
	$extList['jpg'] = 'image/jpeg';
	$extList['jpeg'] = 'image/jpeg';
	$extList['png'] = 'image/png';
	

// You don't need to edit anything after this point.


// --------------------- END CONFIGURATION -----------------------

$img = null;

if (substr($folder,-1) != '/') {
	$folder = $folder.'/';
}

if (isset($_GET['img'])) {
	$imageInfo = pathinfo($_GET['img']);
	if (
	    isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
		$img = $folder.$imageInfo['basename'];
	}
} else {
	$fileList = array();
	$handle = opendir($folder);
	while ( false !== ( $file = readdir($handle) ) ) {
		$file_info = pathinfo($file);
		if (
		    isset( $extList[ strtolower( $file_info['extension'] ) ] )
		) {
			$fileList[] = $file;
		}
	}
	closedir($handle);

	if (count($fileList) > 0) {
		$imageNumber = time() % count($fileList);
		$img = $folder.$fileList[$imageNumber];
	}
}

if ($img!=null) {
	$imageInfo = pathinfo($img);
	$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
	header ($contentType);
	
 /* fixes cahce issue, thanks to dchapiesky */
        header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
        header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
        header( "Cache-Control: no-cache, must-revalidate" );
        header( "Pragma: no-cache" );
	
	readfile($img);
} else {
	if ( function_exists('imagecreate') ) {
		header ("Content-type: image/png");
		$im = @imagecreate (100, 100)
		    or die ("Cannot initialize new GD image stream");
		$background_color = imagecolorallocate ($im, 255, 255, 255);
		$text_color = imagecolorallocate ($im, 0,0,0);
		imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
		imagepng ($im);
		imagedestroy($im);
	}
}

?>

then call the rotate.php file from your css with something like:

#header {
background: #000033 url(images/random.php) no-repeat 0px 0px; /*rotates images in the images folder */
}

note: #header is a placeholder. If you want it in a box in a sidebar or something you would have to alter the tpl.php file where the images are expected to be shown. If the entire site, use page.tpl.php. You would also have to alter the #header placeholder to match the div you set up for the images.

** the above is culled from the Drupal 6.x version of the marinelli theme where the functionality is used to generate random banner images. As the functionality bypassing Drupal handling of the images it should also work in Drupal 7.