MyBB Community Forums

Full Version: Portal Block--Gallery Slideshow
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Hello! I've recently begun working on making the transfer of my community from phpbb to MyBB. So far, things seem much more progressive and less archaic, but I'm hitting some snags in some areas.

I've looked all over for this so hopefully I didn't miss one that already exists. But I was hoping someone here would be able to provide details and/or code to create a portal block that pulls from the ezGallery plugin for a slideshow of recent/random images. Sort of how Enjin has it set up preferably. As an example, you can view this site and the gallery block there (upper right corner): http://www.crystalline-rp.net/home

I have something similar to this setup on my current/old phpbb community site, but it's much more archaic and only shows a single image at a time (no slideshow). If anyone can just accomplish that, I'd still be very content. I just want to make sure the new MyBB site I'm transferring the group to will have at least all the same features as our current site, if not more advanced ^^. And a gallery block is a huge deal for this community.

Failing an inability to integrate such a block into the default portal, I'd welcome the creation of a Pro_Portal block as well, though I'm really trying to stay away from that portal due to what appears to be lack of support for it as of now.

Thanks in advance and hope someone can pull this off Smile
http://community.mybb.com/thread-105289-...#pid898635
Can try to make it into a plugin if you wish (though i have never made a block for the portal before).
Mostly the plugin is done except one weird bug
Need to fix one bug after that the plugin will work like it is supposed to




Hopefully this works (still advice to always test it locally first) but normally it should function and do what you need it to do.

Installation instructions:

  1. Download the attachment below:
    [attachment=28037]
  2. Upload the file to inc > plugins >
  3. Go to your AdminCP > configuration > plugins
  4. Install the plugin

That should do it, change the settings to what you need it to be.
Also you can change the template (global templates portalezgallery_*)

The code for people who want to read it below:

<?php
/*
* Portal block to add a EZ gallery based gallery to the portal page. 
*
* Copyright 2012 Anori
*/

$plugins->add_hook('portal_start', 'portalEZgallery_portal_block');
$plugins->add_hook('index_start', 'portalEZgallery_index_block');

function portalEZgallery_info()
{
    return array(
        "name"        => "EzGallery Portal / Index block",
        "description"    => "Adds a block to the portal / index showing the latest images from Ezgallery",
        "website"        => "http://community.mybb.com/user-59864.html",
        "author"        => "Anori",
        "authorsite"    => "http://community.mybb.com/user-59864.html",
        "version"        => "1.1",
        "compatibility" => "16*"
    );
}

function portalEZgallery_install()
{

	global $mybb, $db;

    if(portalEZgallery_confirm() == true)
	{
		    $insert_array = array(
		        'title'        => 'portalezgallery_template_portal',
		        'template'    => $db->escape_string('<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
<script type="text/javascript">
	jQuery.noConflict();
	jQuery(document).ready(function($)
	{
	$(document).ready(function(){
	    $(\'#myslides\').cycle({
	        fx:    \'fade\',  
	        speed:    2500
	    });
	});
}); 
</script>
<style type="text/css">
	#myslides {
		width: 340px;
		float: left;
		padding: 0;
		margin:  0 auto;
		margin-top: 20px;
		text-align: center;
	} 
</style>
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
	<tr>
		<td class="thead"><strong>Gallery Slideshow</strong></td>
	</tr>
	<tr>
		<td class="trow1" align="center">
			<div id="myslides">
				{$ezgallery_img}
			</div>
		</td>
	</tr>
</table>
<br />'),
		        'sid'        => '-1',
		        'version'    => '',
		        'dateline'    => TIME_NOW
		    );
		    $db->insert_query("templates", $insert_array);

		    $insert_array3 = array(
		        'title'        => 'portalezgallery_template_index',
		        'template'    => $db->escape_string('<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
<script type="text/javascript">
	jQuery.noConflict();
	jQuery(document).ready(function($)
	{
	$(document).ready(function(){
	    $(\'#myslides\').cycle({
	        fx:    \'fade\',  
	        speed:    2500
	    });
	});
}); 
</script>
<style type="text/css">
	#myslides {
		width: 340px;
		padding: 0;
		margin:  0 auto;
		margin-top: 20px;
		text-align: center;
	} 
</style>
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
	<tr>
		<td class="thead"><strong>Gallery Slideshow</strong></td>
	</tr>
	<tr>
		<td class="trow1" align="center">
			<div id="myslides">
				{$ezgallery_img}
			</div>
		</td>
	</tr>
</table>
<br />'),
		        'sid'        => '-1',
		        'version'    => '',
		        'dateline'    => TIME_NOW
		    );
		    $db->insert_query("templates", $insert_array3);

		    $insert_array2 = array(
		    	'title'        => 'portalezgallery_image',
		        'template'    => $db->escape_string('<a href="{$iPath}">
<img src="{$iPath}" style="max-height:280px;max-width:300px;"></a>'),
		        'sid'        => '-1',
		        'version'    => '',
		        'dateline'    => TIME_NOW
		    );
		    $db->insert_query("templates", $insert_array2);

		    $gid = $db->insert_query('settinggroups', array(
		        'name' => 'portalezgallery',
		        'title' => 'EZ portal / index gallery',
		        'description' => "Settings for the EZ portal /index gallery block.",
		        'disporder' => 1,
		        'isdefault' => 0
		    ));
		    $db->insert_query('settings', array(
		        'name' => 'portalezgallery_enable',
		        'title' => 'Enable or Disable Plugin',
		        'description' => 'Enable or disable the plugin',
		        'optionscode' => 'onoff',
		        'value' => '1',
		        'disporder' => 1,
		        'gid' => $gid
		    ));
		    $db->insert_query('settings', array(
		        'name' => 'portalezgallery_lim',
		        'title' => 'Select the number of images.',
		        'description' => 'Select the number of latest images displayed in the gallery.',
		        'optionscode' => 'text',
		        'value' => '10',
		        'disporder' => 2,
		        'gid' => $gid
		    ));
		    $db->insert_query('settings', array(
		        'name' => 'portalezgallery_galleryurl',
		        'title' => 'URL to the gallery',
		        'description' => 'Only change this if the url does not match the gallery URL.',
		        'optionscode' => 'text',
		        'value' => "".$mybb->settings['bburl']."/gallery/",
		        'disporder' => 3,
		        'gid' => $gid
		    ));
		     $db->insert_query('settings', array(
		        'name' => 'portalezgallery_portal',
		        'title' => 'Enable or Disable Portal block',
		        'description' => 'Enable or disable the portal block',
		        'optionscode' => 'onoff',
		        'value' => '1',
		        'disporder' => 4,
		        'gid' => $gid
		    ));
		    $db->insert_query('settings', array(
		        'name' => 'portalezgallery_index',
		        'title' => 'Enable or Disable Index block',
		        'description' => 'Enable or disable the index block',
		        'optionscode' => 'onoff',
		        'value' => '1',
		        'disporder' => 5,
		        'gid' => $gid
		    ));
		  	rebuild_settings();
	}
	else
	{
		flash_message('<bold><font color="red">EZgallery is not installed, this has to be installed for this plugin to work !!!</font></bold>');
		admin_redirect('index.php?module=config-plugins');
	}
}

function portalEZgallery_is_installed()
{
    global $db;

    $query = $db->simple_select("settinggroups", "name", "name = 'portalezgallery'");
    $result = $db->fetch_array($query);
    if($result)
        return true;
    else return false;
}
function portalEZgallery_activate()
{
	global $db, $mybb;
	require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';

	find_replace_templatesets('portal', '#{\$latestthreads}#', "{\$latestthreads}{\$portalezgallery}");
	find_replace_templatesets('index', '#{\$boardstats}#', "{\$indexezgallery}{\$boardstats}");
}
function portalEZgallery_deactivate()
{
	global $db, $mybb;
	require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';

	find_replace_templatesets('portal', '#{\$portalezgallery}#', "");    
	find_replace_templatesets('index', '#{\$indexezgallery}#', ""); 
}
function portalEZgallery_uninstall()
{
    global $db;
    require_once MYBB_ROOT . "inc/adminfunctions_templates.php";
    
    $db->delete_query("templates", "title IN ('portalezgallery_template_portal')");
    $db->delete_query("templates", "title IN ('portalezgallery_template_index')");
    $db->delete_query("templates", "title IN ('portalezgallery_image')");


    $db->delete_query("settinggroups", "name = ('portalezgallery')");
    $db->delete_query("settings", "name IN ('portalezgallery_enable')");
    $db->delete_query("settings", "name IN ('portalezgallery_lim')");
    $db->delete_query("settings", "name IN ('portalezgallery_galleryurl')");
    $db->delete_query("settings", "name IN ('portalezgallery_portal')");
    $db->delete_query("settings", "name IN ('portalezgallery_index')");

    rebuild_settings();
}
function portalEZgallery_portal_block()
{
	global $db, $mybb, $templates, $portalezgallery;

	if($mybb->settings['portalezgallery_enable'] == "1")  
    {
    	if($mybb->settings['portalezgallery_portal'] == "1")
    	{	
	    	$ezgallery_img = '';    	

	    	$portalezgallery_lim = $db->escape_string($mybb->settings['portalezgallery_lim']);
	    	$portalezgallery_galleryurl = $db->escape_string($mybb->settings['portalezgallery_galleryurl']);
	    	$portalezgallery_styletag = $db->escape_string($mybb->settings['portalezgallery_styletag']);

	    	$pezgguery = $db->query("SELECT filename FROM ".TABLE_PREFIX."gallery_pic ORDER BY ID_PICTURE DESC LIMIT ".$portalezgallery_lim."");

	    	$pezgrows = $db->num_rows($pezgguery);

	    	if($pezgrows == 0)
	    	{
	    		$ezgallery_img .= "<p>There are no pictures in the gallery yet.<br />Or the gallery is not installed yet.</p>";
	    	}
	    	else
	    	{
		    	while($pezgrows = $db->fetch_array($pezgguery))
		    	{
		    		$iPath = $portalezgallery_galleryurl.$pezgrows["filename"];
		    		eval("\$ezgallery_img .= \"".$templates->get("portalezgallery_image")."\";");
		    	}
		    }

	    	if($ezgallery_img != '')
	    	{
	    		eval("\$portalezgallery = \"".$templates->get("portalezgallery_template_portal")."\";");  	
	    	}
	    }
    }
}
function portalEZgallery_index_block()
{
	global $db, $mybb, $templates, $indexezgallery;

	if($mybb->settings['portalezgallery_enable'] == "1")  
    {
    	if($mybb->settings['portalezgallery_index'] == "1")
    	{
	    	$ezgallery_img = '';    	

	    	$portalezgallery_lim = $db->escape_string($mybb->settings['portalezgallery_lim']);
	    	$portalezgallery_galleryurl = $db->escape_string($mybb->settings['portalezgallery_galleryurl']);
	    	$portalezgallery_styletag = $db->escape_string($mybb->settings['portalezgallery_styletag']);

	    	$pezgguery = $db->query("SELECT filename FROM ".TABLE_PREFIX."gallery_pic ORDER BY ID_PICTURE DESC LIMIT ".$portalezgallery_lim."");

	    	$pezgrows = $db->num_rows($pezgguery);

	    	if($pezgrows == 0)
	    	{
	    		$ezgallery_img .= "<p>There are no pictures in the gallery yet.<br />Or the gallery is not installed yet.</p>";
	    	}
	    	else
	    	{
		    	while($pezgrows = $db->fetch_array($pezgguery))
		    	{
		    		$iPath = $portalezgallery_galleryurl.$pezgrows["filename"];
		    		eval("\$ezgallery_img .= \"".$templates->get("portalezgallery_image")."\";");
		    	}
		    }

	    	if($ezgallery_img != '')
	    	{
	    		eval("\$indexezgallery = \"".$templates->get("portalezgallery_template_index")."\";");  	
	    	}
	    }
    }
}
function portalEZgallery_confirm()
{
	global $db;

	if($db->table_exists("gallery_settings"))
	{
		$query = $db->query("SELECT	value FROM ".TABLE_PREFIX."gallery_settings	WHERE variable = 'gallery_version'");
		$row = $db->fetch_array($query);

		if (!empty($row['value']))
			return true;
		else
			return false;
	}
	return false;
}
?>

Any suggestions / tips etc. are always welcome Smile
Very nice! Does exactly what I want Smile

I just have a few little issues that hopefully you (or someone else) can assist with.

1. Resizing the block. I tried to change the width values in the php file but it didn't seem to have an impact in the slightest.

2. Being compatible with the sidebox plugin made for the portal. I'm trying to make everything look uniform so hopefully someone can figure out how to allow this block on the forum index (as well as forum and thread pages since the portal sidebox plugin adds those in as well).

3. Display order. This is actually more of an issue with the portal itself than the block. There seems to be no means to shift the order in which the blocks appear (I'd like the image block toward the top rather than bottom). I assume this can be modified in the actual portal template coding though by just moving code around without any real additions/removals.
Got an improved version:

It ads the ability to ad the gallery to the index to and has a custom template for the index page. So it can be changed separately from the portal version.

[attachment=28039] version 1.1

Quote:1. Resizing the block. I tried to change the width values in the php file but it didn't seem to have an impact in the slightest.

To change the width you can tweak the settings in the template files (template > global templates) there you can change it. You can change the whole way it looks there just make sure you leave anything that looks like { .... } something. In a template those are important Smile

Quote:2. Being compatible with the sidebox plugin made for the portal. I'm trying to make everything look uniform so hopefully someone can figure out how to allow this block on the forum index (as well as forum and thread pages since the portal sidebox plugin adds those in as well).

Uninstall / install the newest version linked above it ads support for a block on the index page where you place it is up to you just edit the index template.

index template variable to move where you wish:
{$indexezgallery}

Quote:3. Display order. This is actually more of an issue with the portal itself than the block. There seems to be no means to shift the order in which the blocks appear (I'd like the image block toward the top rather than bottom). I assume this can be modified in the actual portal template coding though by just moving code around without any real additions/removals.

You will have to edit the portal template and place the variable where you want it. IT currently is below lattest threads but you can move:

{$portalezgallery}

Anywhere you wish on the portal.
Very nice. I should be able to make any other minor adjustments to get it where/how I want it at this point. Thank you very much for the help. You rock Smile

After I get everything in order, I'll try to post back here again with an update.
(2012-12-16, 11:56 PM)Kylin Wrote: [ -> ]Very nice. I should be able to make any other minor adjustments to get it where/how I want it at this point. Thank you very much for the help. You rock Smile

After I get everything in order, I'll try to post back here again with an update.

Glad i could help, might post it as a tutorial in the other section not sure yet.
Ok, found a little glitch (unless I did something to mess it up myself without realizing, which is possible!). On Chrome, the image appears completely outside the box. This occurs both on the portal and index page. IE and Firefox have no issues however. You can view my testsite on chrome here if you wish: http://ffxiv-roleplayers.com/testsite/

Gallery block is presently at the bottom.
(2012-12-17, 04:45 PM)Kylin Wrote: [ -> ]Ok, found a little glitch (unless I did something to mess it up myself without realizing, which is possible!). On Chrome, the image appears completely outside the box. This occurs both on the portal and index page. IE and Firefox have no issues however. You can view my testsite on chrome here if you wish: http://ffxiv-roleplayers.com/testsite/

Gallery block is presently at the bottom.

You could fix this by adding into the css (in the templates (this case portalezgallery_template_portal) )

#myslides {
		width: 260px;
		float: left;
		padding: 0;
		margin:  0 auto;
		margin-top: 20px;
		text-align: center;
                height: 135px;
	}

A height like: 135px (look above for the example). This is due to the position absolute that was i think by you added to the image template.

(PS: it also happens with your settings on firefox default settings it does not happen though).
Ah ok. That fixed it. Thanks again Smile
No worries Smile
Pages: 1 2 3 4