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:
- Download the attachment below:
portalEZgallery.php (Size: 10.44 KB / Downloads: 334)
- Upload the file to inc > plugins >
- Go to your AdminCP > configuration > plugins
- 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