SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: josh4596 on April 07, 2015, 08:00:35 PM

Title: How to add a scroll bar to a custom block?
Post by: josh4596 on April 07, 2015, 08:00:35 PM
So this block is for Arantor's Levertine Gallery mod.

Code: [Select]
<?php
/**
 * @name Levertine Gallery
 * @copyright 2014-2015 Peter Spicer (levertine.com)
 * @license proprietary
 *
 * @version 1.0.3
 */

/**
 * This file provides the integration for SimplePortal.
 *
 * @package levgal
 * @since 1.0
 */

class LevGal_Portal_SimplePortal
{
public static function portal($parameters$id$return_parameters false)
{
if ($return_parameters)
{
return self::getParameters();
}
else
{
self::execute($parameters$id);
}
}

protected static function getParameters()
{
return array(
'type' => 'select',
'rows' => 'int',
'columns' => 'int',
);
}

protected static function execute($parameters$id)
{
global $txt$scripturl;

$type = !empty($parameters['type']) ? (int) $parameters['type'] : 0;
$rows = !empty($parameters['rows']) ? abs((int) $parameters['rows']) : 2;
$columns = !empty($parameters['columns']) ? abs((int) $parameters['columns']) : 6;
if (empty($rows))
{
$rows 2;
}
if (empty($columns))
{
$columns 6;
}

if (!allowedTo(array('lgal_view''lgal_manage')))
{
echo '
'
$txt['error_sp_no_pictures_found'];
return;
}

$qty $rows $columns;
switch ($type)
{
case 0:
default:
$itemList LevGal_Bootstrap::getModel('LevGal_Model_ItemList');
$items $itemList->getLatestItems($qty);
break;
case 1:
$itemList LevGal_Bootstrap::getModel('LevGal_Model_ItemList');
$items $itemList->getRandomItems($qty);
break;
}

if (empty($items))
{
echo '
'
$txt['error_sp_no_pictures_found'];
return;
}

echo '
<table class="sp_auto_align sp_levgal sp_levgal_'
$id'" style="width:100%;">';

$cellwidth floor(100 $columns);

$list array_keys($items);
for ($y 0$y $rows$y++)
{
if (empty($list[$y*$columns]))
{
continue;
}
echo '
<tr>'
;
for ($x 0$x $columns$x++)
{
$pos $y $columns $x;
if (empty($list[$pos]))
{
continue;
}
$item = &$items[$list[$pos]];
echo '
<td style="width:'
$cellwidth'%;">
<div class="sp_image smalltext">
<a href="'
$item['item_url'], '">'$item['item_name'], '</a><br />
<a href="'
$item['item_url'], '"><img src="'$item['thumbnail'], '" alt="'$item['item_name'], '" title="'$item['item_name'], '" /></a><br />
'
$txt['lgal_posted_by'], ' ', !empty($item['id_member']) ? '<a href="' $scripturl '?action=profile;u=' $item['id_member'] . '">' $item['poster_name'] . '</a>' $item['poster_name'], '<br />
'
$txt['lgal_posted_in'], ' <a href="'$item['album_url'], '">'$item['album_name'], '</a><br />
</div>
</td>'
;
}
echo '
</tr>'
;
}

echo '
</table>'
;
}

public function isPortalInstalled()
{
return LevGal_Helper_Database::matchTable('{db_prefix}sp_functions');
}

public function ensureInstalled()
{
global $smcFunc;

$request $smcFunc['db_query']('''
SELECT id_function
FROM {db_prefix}sp_functions
WHERE name = {string:sp_levgal}'
,
array(
'sp_levgal' => 'sp_levgal',
)
);
if ($smcFunc['db_num_rows']($request) == 0)
{
$smcFunc['db_insert']('',
'{db_prefix}sp_functions',
array('function_order' => 'int''name' => 'string'),
array(0'sp_levgal'),
array('id_function')
);
}
$smcFunc['db_free_result']($request);
}
}

?>

I tried adding height and max height everywhere I seen width but that doesn't seem to work. I'd like to have 2 rows shown and anything more than that hidden with a scrollbar able to be used. With a total of 4 rows, 6 columns. Thanks if anyone can help with this, like I said I tried myself but didn't have much luck. I asked Arantor for help to no avail. Thanks again
Title: Re: How to add a scroll bar to a custom block?
Post by: ♦ Ninja ZX-10RR ♦ on April 07, 2015, 08:31:35 PM
I asked Arantor for help to no avail.
He should help you instead since it's a paid mod.
Also, I kindly refuse to patch/edit his code given some bad crap he said at my back.
Best regards.
Title: Re: How to add a scroll bar to a custom block?
Post by: Chen Zhen on April 08, 2015, 07:12:04 PM
josh4596,

  Since it is a paid application that I do not have access to, it would probably be best if I had access to your forum as an Admin to adjust the block code directly and test it at the same time. Also I have a feeling that once the block is under way you will most likely change your mind a bit on how it displays. I am willing to help you in this way which is up to you to allow me that access.

Let me know and send me a PM with the relevant info if you decide to go that route.

Regards.
Title: Re: How to add a scroll bar to a custom block?
Post by: josh4596 on April 08, 2015, 07:18:31 PM
I asked Arantor for help to no avail.
He should help you instead since it's a paid mod.
Also, I kindly refuse to patch/edit his code given some bad crap he said at my back.
Best regards.

Right, but he doesn't even get around to bug fixes. The audio streaming doesn't work in firefox and I've been trying for nearly a month to get that fixed yet, still not fixed. Said it's because of work but he had 4 days off work this past week and didn't attempt to fix it at all. Felt like I'd have better luck coming here. Honestly if there were more/better options for streaming audio within a gallery in smf or ipb/vb I wouldn't even continue using it.

@Chen I pm'd you an admin login to my site. This code above is actually a file that builds the block into simple portal though, it's not a code put into a custom php block. Thanks if you're able to help.
Title: Re: How to add a scroll bar to a custom block?
Post by: ♦ Ninja ZX-10RR ♦ on April 08, 2015, 08:24:12 PM
So sad that recently he turned into a bad person IMHO. By the way I am sure that Chen Zhen will fix it :) thanks for that mate, I really cannot provide support in this specific case.
Title: Re: How to add a scroll bar to a custom block?
Post by: Chen Zhen on April 08, 2015, 08:40:00 PM
josh4596,

I made a mod a while back that was a mp3 gallery. However I never got around to updating it as it will only work with mp3 files and uses flash for playing the music and upload/download. This means it will not work with most mobile devices however it does work well with laptops or towers (non-mobile) that have adobe flash installed. It is called premiumbeat but as I said it will not work with most mobile browsers since both Apple & Android no longer support Adobe flash.

  I will have a look tomorrow in the evening & get back to you.

Regards.
Title: Re: How to add a scroll bar to a custom block?
Post by: josh4596 on April 08, 2015, 10:19:47 PM
Well I wasn't totally fair. There are a lot of other features I use. Just sucks that the main feature I use it for has been broken for my favorite browser since I got it. I did notice preamiumbeat but I like that the gallery can keep all the members music organized in once place. I did consider premiumbeat though good job on it.
Title: Re: How to add a scroll bar to a custom block?
Post by: Chen Zhen on April 08, 2015, 10:38:00 PM
josh4596,

That Levertine mod looks pretty good and Imo Arantor did a nice job thus far.
If I understand you correctly, he appears to have already given the ability to have the rows and columns adjusted.
As for displaying only 2 rows and having a way to hide what is below that (the other 2 rows since you want to display only 4 total), a simple block height adjustment will not work because of variable thumbnail heights therefore the block code itself will have to be adjusted.  I will come up with something that is a bit more aesthetic compared to a scroll bar. Leave it with me for a day or so & I will post an alternate block code solution for you.

Regards.




Title: Re: How to add a scroll bar to a custom block?
Post by: josh4596 on April 08, 2015, 10:45:26 PM
Right I noticed that as I was uploading some icons so more than 2 rows would actually be taken up. I mostly wanted to just control the height, it didn't need to show 2 rows perfectly depending on thumbnail size. But if you want to take that on that'd be great.

Honestly didn't even realize you could change the block max height right within the editing interface, thought that was something that had to be done within the code
Title: Re: How to add a scroll bar to a custom block?
Post by: Chen Zhen on April 08, 2015, 10:51:20 PM
josh4596,

  Simple Portal is fairly flexible whereas it allows you to adjust each block's css attributes with specifics if necessary.
 
Title: Re: How to add a scroll bar to a custom block?
Post by: josh4596 on April 08, 2015, 11:20:32 PM
josh4596,

  Simple Portal is fairly flexible whereas it allows you to adjust each block's css attributes with specifics if necessary.

Just tried adding the max-height to my blocksinblock and it worked perfectly. Thanks Chen! If you want to try to get that other code working I'd appreciate it but it's not necessary.

P.S would it be possible to show each row separately and how would I go about doing that? Considering integrating this with the easy slider so it can have pages instead of scrolling.
Title: Re: How to add a scroll bar to a custom block?
Post by: ♦ Ninja ZX-10RR ♦ on April 09, 2015, 10:05:06 AM
If you need more info about SP's css: http://simpleportal.net/index.php?topic=13732.0 this topic turned out to be even more efficient than the docs for that specific subject ;D It's definitely not the first time I link it.

That Levertine mod looks pretty good and Imo Arantor did a nice job thus far.
Sure he did, wasn't talking about his code before. :)
Title: Re: How to add a scroll bar to a custom block?
Post by: Chen Zhen on April 09, 2015, 10:57:31 PM
josh4596,

File: ../Themes/default/languages/levgal_lng/LevGal-Portals.english.php

find:
Code: [Select]
$txt['sp_param_sp_levgal_type_options'] = 'Latest items|Random items';

replace with:
Code: [Select]
$txt['sp_param_sp_levgal_type_options'] = 'Latest items|Random items';
$txt['sp_param_sp_levgal_per_page'] = 'Number of rows per dynamic page';



File: ../Sources/levgal_src/Portal/SimplePortal.php

! Replace entire contents with the following:
Code: [Select]
<?php
/**
 * @name Levertine Gallery
 * @copyright 2014-2015 Peter Spicer (levertine.com)
 * @license proprietary
 *
 * @version 1.0.3
 */

/**
 * This file provides the integration for SimplePortal.
 *
 * @package levgal
 * @since 1.0
 */

class LevGal_Portal_SimplePortal
{
public static function portal($parameters$id$return_parameters false)
{
if ($return_parameters)
{
return self::getParameters();
}
else
{
self::execute($parameters$id);
}
}

protected static function getParameters()
{
return array(
'type' => 'select',
'rows' => 'int',
'columns' => 'int',
'per_page' => 'int',
);
}

protected static function execute($parameters$id)
{
global $txt$scripturl$context$settings;

$type = !empty($parameters['type']) ? (int) $parameters['type'] : 0;
$rows = !empty($parameters['rows']) ? abs((int) $parameters['rows']) : 0;
$columns = !empty($parameters['columns']) ? abs((int) $parameters['columns']) : 0;
$rowsPerPage = !empty($parameters['per_page']) ? abs((int) $parameters['per_page']) + 2;
if (empty($rows))
{
$rows 1;
}
if (empty($columns))
{
$columns 4;
}

if (!allowedTo(array('lgal_view''lgal_manage')))
{
echo '
'
$txt['error_sp_no_pictures_found'];
return;
}

$qty $rows $columns;
switch ($type)
{
case 0:
default:
$itemList LevGal_Bootstrap::getModel('LevGal_Model_ItemList');
$items $itemList->getLatestItems($qty);
break;
case 1:
$itemList LevGal_Bootstrap::getModel('LevGal_Model_ItemList');
$items $itemList->getRandomItems($qty);
break;
}

if (empty($items))
{
echo '
'
$txt['error_sp_no_pictures_found'];
return;
}

echo '
<table id="levgal_pages" class="sp_auto_align sp_levgal sp_levgal_'
$id'" style="width:100%;">';

$cellwidth floor(100 $columns);
$list array_keys($items);
for ($y 0$y $rows$y++)
{
if (empty($list[$y*$columns]))
{
continue;
}

echo '
<tr>
<td style="display: none;">&nbsp;</td>
</tr>
<tr>'
;
for ($x 0$x $columns$x++)
{
$pos $y $columns $x;
if (empty($list[$pos]))
{
continue;
}
$item = &$items[$list[$pos]];
echo '
<td style="width:'
$cellwidth'%;">
<div class="sp_image smalltext">
<a href="'
$item['item_url'], '">'$item['item_name'], '</a><br />
<a href="'
$item['item_url'], '"><img src="'$item['thumbnail'], '" alt="'$item['item_name'], '" title="'$item['item_name'], '" /></a><br />
'
$txt['lgal_posted_by'], ' ', !empty($item['id_member']) ? '<a href="' $scripturl '?action=profile;u=' $item['id_member'] . '">' $item['poster_name'] . '</a>' $item['poster_name'], '<br />
'
$txt['lgal_posted_in'], ' <a href="'$item['album_url'], '">'$item['album_name'], '</a><br />
</div>
</td>'
;
}
echo '
</tr>'
;
}

echo '
</table>
<div id="levgalNavPosition" class="centertext"></div>
<script type="text/javascript"><!--
var pager = new LevgalPager("levgal_pages", '
$rowsPerPage');
pager.init();
pager.showPageNav("pager", "levgalNavPosition");
pager.showPage(1);
//--></script>'
;
}

public function isPortalInstalled()
{
return LevGal_Helper_Database::matchTable('{db_prefix}sp_functions');
}

public function ensureInstalled()
{
global $smcFunc;

$request $smcFunc['db_query']('''
SELECT id_function
FROM {db_prefix}sp_functions
WHERE name = {string:sp_levgal}'
,
array(
'sp_levgal' => 'sp_levgal',
)
);
if ($smcFunc['db_num_rows']($request) == 0)
{
$smcFunc['db_insert']('',
'{db_prefix}sp_functions',
array('function_order' => 'int''name' => 'string'),
array(0'sp_levgal'),
array('id_function')
);
}
$smcFunc['db_free_result']($request);
}
}
?>




File: ../Themes/default/scripts/portal.js

find:
Code: [Select]
// This function is for SMF 2 RC2 and above.

replace with:
Code: [Select]
/*
 * This function provides the dynamic pagination for Levgal
 *
 * @package levgal
 * @since 1.1.1
 */
 
function LevgalPager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.inited = false;
   
    this.showRecords = function(from, to) {       
        var rows = document.getElementById(tableName).rows;
       
        for (var i = 1; i < rows.length; i++) {
            if (i < from || i > to) 
                rows[i].style.display = 'none';
            else
                rows[i].style.display = '';
        }
    }
   
    this.showPage = function(pageNumber) {
    if (! this.inited) {
    alert("not inited");
    return;
    }

        var oldPageAnchor = document.getElementById('pg'+this.currentPage);
        oldPageAnchor.style.color = "black";
        oldPageAnchor.innerHTML = oldPageAnchor.innerHTML.replace(/\[/g, "").replace(/\]/g, "");

        this.currentPage = pageNumber;
        var newPageAnchor = document.getElementById('pg'+this.currentPage);       
newPageAnchor.innerHTML = '[' + newPageAnchor.innerHTML + ']';
newPageAnchor.style.color = "green";

        var from = (pageNumber - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to);
    }   
   
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
   
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                       
   
    this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1);
        this.pages = Math.ceil(records / itemsPerPage);
        this.inited = true;
    }

    this.showPageNav = function(pagerName, positionId) {
    if (! this.inited) {
    alert("not inited");
    return;
    }
    var element = document.getElementById(positionId);
   
    var pagerHtml = '<span onclick="' + pagerName + '.prev();"> &#171 Prev </span> | ';
        for (var page = 1; page <= this.pages; page++)
            pagerHtml += '<span id="pg' + page + '" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
        pagerHtml += '<span onclick="'+pagerName+'.next();"> Next &#187;</span>';           
       
        element.innerHTML = pagerHtml;
    }
}

// This function is for SMF 2 RC2 and above.



Within the Levgal SP block settings, enter the following attribute within the custom body style input:
Code: [Select]
overflow: hidden;



  Note: In some scenarios you may want the block height to be uniform for all the dynamic pages. To create that effect you simply add the height attribute to the custom body style input. This is not necessary but may be desired.

  This is just some fairly basic javascript that introduces dynamic pagination to the levgal SP block display.
Initially you will most likely need to clear your browser history/cache to have the page reload the portal's javascript file.

There will be a new heading in the Levgal portal block options which you need to configure.
With what you specifically requested the integer to enter will be 2

Regards.
 
SimplePortal 2.3.8 © 2008-2024, SimplePortal