collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 393
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

Author Topic: Tabbed Content - Blocks in Block  (Read 18991 times)

0 Members and 1 Guest are viewing this topic.

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #20 on: February 18, 2014, 10:47:09 PM »
:/

The problem is, I don't know the bare basics of PHP at all. I've been playing with the code, but I honestly don't know how to change it or edit it to do... whatever it is you just said haha XD

I'll keep playing, but yeah. I know nothing xD

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #21 on: February 20, 2014, 03:15:27 PM »
If you keep playing, you will probably learn something :)

Like I said -- take it one step at a time.  If you can
1) create php block 121 that works ( and then set block 121 inactive).
2) create another php block that just has the code I posted in http://simpleportal.net/index.php?topic=13176.msg65306#msg65306, then you will have made a good start on the whole thing.

Maybe Tarista will be interested in this, as well.
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #22 on: February 25, 2014, 11:23:12 PM »
Yeah... I can't get it to work.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #23 on: February 27, 2014, 07:12:33 PM »
replace 64 with the number that is for the block you already saved -- the one that is already working.
Code: [Select]
$myBlock = 64;
$block_info = getBlockInfo(,$myBlock);
$parameters = $block_info['parameters'];
sp_php($parameters,0);


Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #24 on: February 28, 2014, 10:18:52 AM »
Okay; did and tried and that code doesn't work for me either - by itself or built into any other kind of code.

I'm not a coder. I don't know how to build code, and I'm growing increasingly frustrated and upset with the half-given answers. I am not able to do this and I would really appreciate it if someone could lay out how to put a block together in simple step-by-step instructions to create a block that will function as desired. Please.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #25 on: February 28, 2014, 12:57:39 PM »
FireDitto,

I can certainly understand that you are not interested in learning to code for your site.
Unfortunately, I do not have the time to come to your site and develop this custom code for you.

If you can find a good php coder willing to help, this little project should go pretty quickly, especially if the coder has a little familiarity with SMF.

Good luck to you with this project and everything else!
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #26 on: March 01, 2014, 12:20:59 AM »
I'm not asking anyone to come to my site, and I'm certainly not so stupid as to be incapable of inserting the right numbers in order to pull the correct blocks.

I hardly see how what I'm asking for is any different than what has already been asked for or offered by other people on the site, and it certainly doesn't need anyone to come to my site. All I want is the below block to call up custom PHP blocks.

Code: [Select]
global $txt;

$txt['recent_topics'] = 'Recent Topics';
$txt['recent_posts'] = 'Recent Posts';

$buttons = array(
   'recent_topics' => array(
      'text' => 'recent_topics',
      'image' => '',
      'lang' => true,
      'url' => '#recent_topics" id="b_rt" onclick="change_display(\'rp\'); return false;',
      'active' => true,
   ),
   'recent_posts' => array(
      'text' => 'recent_posts',
      'image' => '',
      'lang' => true,
      'url' => '#recent_posts" id="b_rp" onclick="change_display(\'rt\'); return false;',
   ),
);

echo '
<div style="overflow: auto;">
   ', template_button_strip($buttons), '
</div>
<div id="recent_topics">
   ', sp_recent(array('type' => 1, 'display' => 1), 0), '
</div>
<div id="recent_posts" style="display: none;">
   ', sp_recent(array('display' => 1), 0), '
</div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
   function change_display(block)
   {
      var current = block == \'rt\' ? 1 : 0;

      document.getElementById(\'recent_topics\').style.display = current ? \'none\' : \'\';
      document.getElementById(\'recent_posts\').style.display = current ? \'\' : \'none\';
      document.getElementById(\'b_rt\').className = current ? \'button_strip_recent_topics\' : \'button_strip_recent_topics active\';
      document.getElementById(\'b_rp\').className = current ? \'button_strip_recent_posts active\' : \'button_strip_recent_posts\';
   }
// ]]></script>';

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: Tabbed Content - Blocks in Block
« Reply #27 on: March 02, 2014, 05:53:24 PM »
Sure, Fireditto.

Where you are calling "sp_recent", just call "sp_php" instead.  And use the code I gave you to get the parameter of the custom php block you already have working.

I am sorry I do not have the time to write and test some more code for you, on your site or on my own site.
Good Luck!
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #28 on: March 03, 2014, 08:15:33 AM »
Pretty sure if it were that easy for me, I would have figured it out about a page and a half ago. Don't you think I would have tried that before asking for help? Like I said; I'm not stupid. I got the gist of the rules and I've been experimenting. My issue is that I am not knowledgeable enough to turn your whispy half-arsed replies into what I want.

I appreciate your trying to help. But to avoid further frustration, if you're not going to actually help I'd appreciate if you didn't bother; I am incredibly frustrated and feel like the past several days have been entirely wasted in regards to getting the code I want. I've stated several times, I am not a coder so giving me three or four lines and going "Try this!" doesn't help me, especially when you haven't even tested it yourself. I need to know more than that (like where it goes), and it helps if you know what you're talking about, too, which frankly, I'm doubting you do.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Tabbed Content - Blocks in Block
« Reply #29 on: March 03, 2014, 09:56:52 AM »
Ouch! That hurts. I'd rather you didn't say that to someone trying to help you. I can assure you that she is trying to help you as best as she can. I'll overlook this one as you seem to be really frustrated but I may not be as nice if this happens again. ;)

As for your question, I had an updated Blocks in Blocks code here:

http://simpleportal.net/index.php?topic=5332.msg37841#msg37841

Basically, this is the code you need:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block',
'type' => 'sp_php',
'parameters' => array('content' => '$some_var = "sinan"; $some_other_var = "test"; echo $some_var . $some_other_var;'),
),
);

global $txt;

$button_list = array();
foreach ($blocks as $id => $block)
{
$txt['sp_bib_label_' . $id] = $block['label'];

$button_list[] = array(
'text' => 'sp_bib_label_' . $id,
'image' => '',
'lang' => true,
'url' => '#sp_bib_' . $id . '" id="sp_bib_button_' . $id . '" onclick="sp_bib_change(' . $id . '); return false;',
);
}

$button_list[0]['active'] = true;

echo '
<div style="overflow: auto;">
', template_button_strip($button_list), '
</div>';

foreach ($blocks as $id => $block)
{
echo '
<div id="sp_bib_', $id, '"', $id != 0 ? ' style="display: none;"' : '', '>';

$block['type']($block['parameters'], 0);

echo '
</div>';
}

echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function sp_bib_change(id)
{
for (var i = 0; i < ', count($blocks), '; i++)
{
document.getElementById(\'sp_bib_\' + i).style.display = i == id ? \'\' : \'none\';
document.getElementById(\'sp_bib_button_\' + i).className = \'button_strip_\' + i + (i == id ? \' active\' : \'\');
}
}
// ]]></script>';

What you need to do is to extend the $blocks array. Here's the structure:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block 1', // title
'type' => 'sp_php', // type
'parameters' => array('content' => '$some_var = "sinan"; $some_other_var = "test"; echo $some_var . $some_other_var;'), // parameters
),
array(
'label' => 'My Custom Block 2', // title
'type' => 'sp_php', // type
'parameters' => array('content' => '$some_var = "sinan"; $some_other_var = "test"; echo $some_var . $some_other_var;'), // parameters
),
);

To make it easier, you can use the following code in a Custom PHP Block:

Code: [Select]
global $sourcedir;

$blocks = array(
array(
'label' => 'My Custom Block 1',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock1.php')),
),
);

global $txt;

$button_list = array();
foreach ($blocks as $id => $block)
{
$txt['sp_bib_label_' . $id] = $block['label'];

$button_list[] = array(
'text' => 'sp_bib_label_' . $id,
'image' => '',
'lang' => true,
'url' => '#sp_bib_' . $id . '" id="sp_bib_button_' . $id . '" onclick="sp_bib_change(' . $id . '); return false;',
);
}

$button_list[0]['active'] = true;

echo '
<div style="overflow: auto;">
', template_button_strip($button_list), '
</div>';

foreach ($blocks as $id => $block)
{
echo '
<div id="sp_bib_', $id, '"', $id != 0 ? ' style="display: none;"' : '', '>';

$block['type']($block['parameters'], 0);

echo '
</div>';
}

echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function sp_bib_change(id)
{
for (var i = 0; i < ', count($blocks), '; i++)
{
document.getElementById(\'sp_bib_\' + i).style.display = i == id ? \'\' : \'none\';
document.getElementById(\'sp_bib_button_\' + i).className = \'button_strip_\' + i + (i == id ? \' active\' : \'\');
}
}
// ]]></script>';

Then just create a file with the name spcustomblock1.php in ./Sources directory and put the PHP code you want for that block in that file.

If you want to add more PHP blocks, here's how you can extend $blocks array:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block 1',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock1.php')),
),
array(
'label' => 'My Custom Block 2',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock2.php')),
),
);

Then just create spcustomblock2.php file and put the PHP code in that file.

If you wanted to add Recent Topics block as well, you'd change $blocks array to the following:

Code: [Select]
$blocks = array(
array(
'label' => 'My Custom Block 1',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock1.php')),
),
array(
'label' => 'My Custom Block 2',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/spcustomblock2.php')),
),
array(
'label' => 'Recent Topics',
'type' => 'sp_recent',
'parameters' => array('type' => 1, 'display' => 1),
),
);
And slowly, you come to realize... It's all as it should be...

Offline qwert321

  • Newbie
  • Posts: 4
  • SMF Version: 2.0.7
  • SP Version: 2.3.4
Re: Tabbed Content - Blocks in Block
« Reply #30 on: March 03, 2014, 10:00:21 PM »
I have been following this post as I also wanted to use the tabbed block with my own custom blocks.

I am good at manipulating already written code but not good at from scratch type of thing.

Anyhow I used your code from above Sinan and had a few issues but nothing major.

I could not get the source php files to load with the $sourcedir then noticed it was not loaded using global(at least I believe global is a means to load)

Then I kept getting an error" unexpected < " traced that down to making sure the<?php and ?> were not in the php files I was trying to load the content in.

I am not posting to say hey you missed this and that but to help out FireDitto as he/she seems to be at my level of understanding how to code.

Thanks for the help as I never would have been able to figure it out either, now I have so many more options available to customize my site.

FireDitto copy the code below and it will give you 3 tabs you can customize by changing the labels and source files you put in the source directory.

just remeber NO </php and ?> in the files you put in the source directory.

Code: [Select]
global  $sourcedir;

$blocks = array(
array(
'label' => 'Up Coming Events!',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/article_block2.php')),
),
array(
'label' => 'News!',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/article_block3.php')),
),
array(
'label' => 'Meetings!',
'type' => 'sp_php',
'parameters' => array('content' => file_get_contents($sourcedir . '/article_block.php')),
),
);

global $txt;

$button_list = array();
foreach ($blocks as $id => $block)
{
$txt['sp_bib_label_' . $id] = $block['label'];

$button_list[] = array(
'text' => 'sp_bib_label_' . $id,
'image' => '',
'lang' => true,
'url' => '#sp_bib_' . $id . '" id="sp_bib_button_' . $id . '" onclick="sp_bib_change(' . $id . '); return false;',
);
}

$button_list[0]['active'] = true;

echo '
<div style="overflow: auto;">
', template_button_strip($button_list), '
</div>';

foreach ($blocks as $id => $block)
{
echo '
<div id="sp_bib_', $id, '"', $id != 0 ? ' style="display: none;"' : '', '>';

$block['type']($block['parameters'], 0);

echo '
</div>';
}

echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function sp_bib_change(id)
{
for (var i = 0; i < ', count($blocks), '; i++)
{
document.getElementById(\'sp_bib_\' + i).style.display = i == id ? \'\' : \'none\';
document.getElementById(\'sp_bib_button_\' + i).className = \'button_strip_\' + i + (i == id ? \' active\' : \'\');
}
}
// ]]></script>'; /code]

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Tabbed Content - Blocks in Block
« Reply #31 on: March 04, 2014, 01:09:55 AM »
I could not get the source php files to load with the $sourcedir then noticed it was not loaded using global(at least I believe global is a means to load)

The original code does not have it and you don't need it unless you want to fetch the code from a file. It's there though in the 3rd code block of my last post which I suggested as an easier alternative.

Then I kept getting an error" unexpected < " traced that down to making sure the<?php and ?> were not in the php files I was trying to load the content in.

The code is there to handle cases both where you have the PHP open/close tags and you don't. In my tests, I had the PHP open tag. Can you attach the file that gives the error here so I can use it to debug and see where the code fails?

Thanks for the help as I never would have been able to figure it out either, now I have so many more options available to customize my site.

You're welcome. ;)
And slowly, you come to realize... It's all as it should be...

Offline FireDitto

  • Jr. Member
  • **
  • Posts: 91
  • Gender: Female
    • Second Pass Weyr
  • SMF Version: 2.0.11
  • SP Version: 2.3.5
  • Elkarte Version: None
Re: Tabbed Content - Blocks in Block
« Reply #32 on: March 04, 2014, 04:35:47 AM »
Thank you very much, Sinan; it works wonderfully and I really appreciate your help.

Offline qwert321

  • Newbie
  • Posts: 4
  • SMF Version: 2.0.7
  • SP Version: 2.3.4
Re: Tabbed Content - Blocks in Block
« Reply #33 on: March 04, 2014, 08:51:22 AM »

The code is there to handle cases both where you have the PHP open/close tags and you don't. In my tests, I had the PHP open tag. Can you attach the file that gives the error here so I can use it to debug and see where the code fails?


Funny thing I put the tags back in the file so i could attach it for you to debug and tried it again before i was going to post it and i no longer get the error.

Sorry I missed the file you had put the $global $sourcedir in

but like I said not posting to offend anyone I wish i could do this stuff from scratch.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Tabbed Content - Blocks in Block
« Reply #34 on: March 04, 2014, 11:39:10 AM »
You're both welcome!

And it's okay. I just wanted to make sure that there isn't anything I'm missing.
And slowly, you come to realize... It's all as it should be...