Accessing Menu Manager stuff from outside cmsms? [SOLVED]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
alastair_scs
Forum Members
Forum Members
Posts: 23
Joined: Sun Aug 17, 2008 6:41 pm

Accessing Menu Manager stuff from outside cmsms? [SOLVED]

Post by alastair_scs »

Hi

I'm going to try to make this make sense.  I apologise in advance if what I am about to ask is really stupid or in the wrong place but I couldn't figure out where to put it.

I am trying to integrate blogs, forums and potentially other 3rd party solutions into a cmsms site.  Lets take a PHPBB3 forum as an example since there seem to have been several posts on this question. 

So far the best solution seems to be to install the phpbb in a folder and in the nav of my site just point to this folder.  I then port the design of the site into the phpBB3 template and hey presto, visual integration.  I do the same thing with blogs, which I do in Wordpress.

There seem to be modules that try to bridge front end users into these 3rd party systems so I'll try those out as I need them.  My problem is this.  If I put the site in the hands of someone with no technical knowledge they can add and remove content in the cmsms site and it will show up in the menus.  The menus on the blog pages or on the Forum however, won't get updated and will be out of date.

I have tried embedding the forum in an iframe and have used this on a couple of sites but it is less than ideal.  I have tried using embed tag but it didn't work and even if it did, is less than ideal. 

So I decided to try to make the menu's in my blog or forum etc. generate their menu's from the cmsms database.

Unfortunately, I have no idea how to do this.  So I was hoping someone could help.  Is there a relatively simple way of generating the menu from outside cmsms?

This could either be much harder or much easier than I think it is and I just thought that I should ask because someone is bound to have tried it before.

I hope this makes some sense and would appreciate any help.

Alastair
Last edited by alastair_scs on Sun Nov 02, 2008 6:15 pm, edited 1 time in total.
alastair_scs
Forum Members
Forum Members
Posts: 23
Joined: Sun Aug 17, 2008 6:41 pm

Re: Accessing Menu Manager stuff from outside cmsms?

Post by alastair_scs »

Still don't know if this is in the wrong place but I managed to get this done.

I don't know any PHP so it's a total hack but I now have PHPBB3 visually integrated without the use of frames or iframes etc.

The nav automatically updates when new pages are added etc.

As I say, it's a total hack but if anyone is interested let me know and I will post it here.

Thanks

Alastair
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Accessing Menu Manager stuff from outside cmsms? [SOLVED]

Post by Nullig »

Yes, please do post your "hack".

Nullig
alastair_scs
Forum Members
Forum Members
Posts: 23
Joined: Sun Aug 17, 2008 6:41 pm

Re: Accessing Menu Manager stuff from outside cmsms? [SOLVED]

Post by alastair_scs »

Ok.  Here goes.

All the "nide" stuff is just cause I didn't want to call it "node" but that is what I meant.  No idea what happens in PHP if I confuse variable names somehow and I didn't want to find out.

Code: Select all

<!-- PHP -->

class nide { 
var $id = '3'; 
} 

$prevdepth = 1;
$origdepth = 1;
$count = 0;
$number_of_levels = 1;
$current = 58;   # set this to the id of your page
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = '';
mysql_select_db($dbname);

$query  = "SELECT * FROM cms_content WHERE show_in_menu = 1 ORDER BY hierarchy ASC";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    $depth = count(explode('.', $row['id_hierarchy'])) - ($origdepth - 1);
    if ($depth <= $number_of_levels)
    {
    $thisnide = new nide();

    $thisnide->id = $row['content_id'];
    $thisnide->type = strtolower($row['type']);
    if ($thisnide->type == 'content')
               $thisnide->url = 'http://www.yoursiteurl.com/index.php?page=' . $row['content_alias'];
    elseif ($thisnide->type == 'link')
               $thisnide->url = 'http://www.yoursiteurl.com/' . $row['content_alias'];
    $thisnide->accesskey = $row['accesskey'];
    $thisnide->tabindex = $row['tabindex'];
    $thisnide->titleattribute = $row['titleattribute'];
    $thisnide->hierarchy = $row['hierarchy'];
    $thisnide->depth = $depth;
    $newarray = explode('.', $row['id_hierarchy']);
    if ($newarray[0] != $thisnide->id)
            $haschildren[$newarray[0]] = 'true';

    
    $thisnide->prevdepth = $prevdepth;
    if ($thisnide->prevdepth == 0)
	$thisnide->prevdepth = 1;
    $thisnide->menutext = $row['menu_text'];
    $thisnide->index = $count;
    $thisnide->alias = $row['content_alias'];
    if ($thisnide->parent != true)
              $thisnide->parent = false;
    $count++;

    if ($current == $thisnide->id) {
              $thisnide->current = true;
              $parent[$newarray[0]] = 'true';    
    }
    else
              $thisnide->current = false;

    $nodelist[]=$thisnide;
    $prevdepth = $thisnide->depth; 
    }
} 

echo "<div id=\"menu_horiz\">";
echo "<h2 class=\"accessibility\">Navigation</h2>";

if ($count > 0)
{
    echo "<ul>";

   foreach ($nodelist as $node)
   {
       if ($haschildren[$node->id])
            $node->haschildren = true;

       if ($parent[$node->id])
            $node->parent = true;

       if ($node->depth > $node->prevdepth) 
       {
           echo "<ul>";
       }
       elseif ($node->depth < $node->prevdepth)
       {
           echo "</li></ul>";
           echo "</li>";
       }
       
       elseif ($node->index > 0)
       {
           echo "</li>";
       }

       if ($node->current == true)
       {
            echo"<li class=\"currentpage\"><h3><dfn>Current page is {$node->hierarchy}: </dfn>{$node->menutext}</h3>";
       }
       elseif ($node->parent == true)
       {
          echo"<li class=\"activeparent\"><a class=\"activeparent\" href=\"{$node->url}\"";
          if ($node->accesskey != '')
                 echo " accesskey=\"{$node->accesskey}\"";
          if ($node->tabindex != '')
                 echo " tabindex=\"{$node->tabindex}\"";
          if ($node->titleattribute != '')
                 echo " title=\"{$node->titleattribute}\"";
          echo "><dfn>{$node->hierarchy}: </dfn>{$node->menutext}</a>";
        }
        elseif ($node->type == 'sectionheader')
                echo "<li class=\"sectionheader\">{$node->menutext}";
        elseif ($node->type == 'separator')
                echo "<li class=\"separator\" style=\"list-style-type: none;\"> <hr />";
        else {
                echo "<li><a href=\"{$node->url}\"";
                if ($node->accesskey != '')
                     echo " accesskey=\"{$node->accesskey}\"";
                if ($node->tabindex != '')
                     echo " tabindex=\"{$node->tabindex}\"";
                if ($node->titleattribute != '')
                     echo " title=\"{$node->titleattribute}\"";
                if ($node->target != '')
                     echo " target=\"{$node->target}\"";
                echo "><dfn>{$node->hierarchy}: </dfn>{$node->menutext}</a>";

          }

    }

    echo "</li></ul>";
  

}
echo "<hr class=\"accessibility\" />";
echo "</div>";

<!-- ENDPHP -->
So basically, I just queried the DB for the content info.  Made node objects from that and pushed them into an array ($nodelist).  Then I tried to copy the logic from the .tpl file in menu manager that I needed to imitate.

I will need to write the foreach loop above again for each different .tpl I need to use which is a pain.  I am sure there is a way to use the smarty template but I couldn't figure it out.

The version above is working for me.  Should note however that I am only showing the top level nodes in my nav so I can't be sure it would draw the rest properly.  It ought to be close though.

I think I came up with a better way of doing this aswell but it is way beyond me.  If you could have some kind of module that captured whatever event would indicate that the menu has been updated then it could output a .html file with the menu in it.  Applications that you are bridging (BB or blog or whatever) could then simply call this file in their templates.

Anyway, what I have above seems to work.  The whole lot can be just inserted into a PHPBB3 template and will draw the menu.  Need to switch PHPBB to allow php in template files before it will process it but then it works.
Last edited by alastair_scs on Sun Nov 02, 2008 7:21 pm, edited 1 time in total.
Kenny McCormick
New Member
New Member
Posts: 3
Joined: Sat Dec 20, 2008 2:50 pm

Re: Accessing Menu Manager stuff from outside cmsms? [SOLVED]

Post by Kenny McCormick »

alastair_scs wrote: Ok.  Here goes.

All the "nide" stuff is just cause I didn't want to call it "node" but that is what I meant.  No idea what happens in PHP if I confuse variable names somehow and I didn't want to find out.

Code: Select all

<!-- PHP -->

class nide { 
var $id = '3'; 
} 

$prevdepth = 1;
$origdepth = 1;
$count = 0;
$number_of_levels = 1;
$current = 58;   # set this to the id of your page
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = '';
mysql_select_db($dbname);

$query  = "SELECT * FROM cms_content WHERE show_in_menu = 1 ORDER BY hierarchy ASC";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    $depth = count(explode('.', $row['id_hierarchy'])) - ($origdepth - 1);
    if ($depth <= $number_of_levels)
    {
    $thisnide = new nide();

    $thisnide->id = $row['content_id'];
    $thisnide->type = strtolower($row['type']);
    if ($thisnide->type == 'content')
               $thisnide->url = 'http://www.yoursiteurl.com/index.php?page=' . $row['content_alias'];
    elseif ($thisnide->type == 'link')
               $thisnide->url = 'http://www.yoursiteurl.com/' . $row['content_alias'];
    $thisnide->accesskey = $row['accesskey'];
    $thisnide->tabindex = $row['tabindex'];
    $thisnide->titleattribute = $row['titleattribute'];
    $thisnide->hierarchy = $row['hierarchy'];
    $thisnide->depth = $depth;
    $newarray = explode('.', $row['id_hierarchy']);
    if ($newarray[0] != $thisnide->id)
            $haschildren[$newarray[0]] = 'true';

    
    $thisnide->prevdepth = $prevdepth;
    if ($thisnide->prevdepth == 0)
	$thisnide->prevdepth = 1;
    $thisnide->menutext = $row['menu_text'];
    $thisnide->index = $count;
    $thisnide->alias = $row['content_alias'];
    if ($thisnide->parent != true)
              $thisnide->parent = false;
    $count++;

    if ($current == $thisnide->id) {
              $thisnide->current = true;
              $parent[$newarray[0]] = 'true';    
    }
    else
              $thisnide->current = false;

    $nodelist[]=$thisnide;
    $prevdepth = $thisnide->depth; 
    }
} 

echo "<div id="menu_horiz">";
echo "<h2 class="accessibility">Navigation</h2>";

if ($count > 0)
{
    echo "<ul>";

   foreach ($nodelist as $node)
   {
       if ($haschildren[$node->id])
            $node->haschildren = true;

       if ($parent[$node->id])
            $node->parent = true;

       if ($node->depth > $node->prevdepth) 
       {
           echo "<ul>";
       }
       elseif ($node->depth < $node->prevdepth)
       {
           echo "</li></ul>";
           echo "</li>";
       }
       
       elseif ($node->index > 0)
       {
           echo "</li>";
       }

       if ($node->current == true)
       {
            echo"<li class="currentpage"><h3><dfn>Current page is {$node->hierarchy}: </dfn>{$node->menutext}</h3>";
       }
       elseif ($node->parent == true)
       {
          echo"<li class="activeparent"><a class="activeparent" href="{$node->url}"";
          if ($node->accesskey != '')
                 echo " accesskey="{$node->accesskey}"";
          if ($node->tabindex != '')
                 echo " tabindex="{$node->tabindex}"";
          if ($node->titleattribute != '')
                 echo " title="{$node->titleattribute}"";
          echo "><dfn>{$node->hierarchy}: </dfn>{$node->menutext}</a>";
        }
        elseif ($node->type == 'sectionheader')
                echo "<li class="sectionheader">{$node->menutext}";
        elseif ($node->type == 'separator')
                echo "<li class="separator" style="list-style-type: none;"> <hr />";
        else {
                echo "<li><a href="{$node->url}"";
                if ($node->accesskey != '')
                     echo " accesskey="{$node->accesskey}"";
                if ($node->tabindex != '')
                     echo " tabindex="{$node->tabindex}"";
                if ($node->titleattribute != '')
                     echo " title="{$node->titleattribute}"";
                if ($node->target != '')
                     echo " target="{$node->target}"";
                echo "><dfn>{$node->hierarchy}: </dfn>{$node->menutext}</a>";

          }

    }

    echo "</li></ul>";
  

}
echo "<hr class="accessibility" />";
echo "</div>";

<!-- ENDPHP -->
So basically, I just queried the DB for the content info.  Made node objects from that and pushed them into an array ($nodelist).  Then I tried to copy the logic from the .tpl file in menu manager that I needed to imitate.

I will need to write the foreach loop above again for each different .tpl I need to use which is a pain.  I am sure there is a way to use the smarty template but I couldn't figure it out.

The version above is working for me.  Should note however that I am only showing the top level nodes in my nav so I can't be sure it would draw the rest properly.  It ought to be close though.

I think I came up with a better way of doing this aswell but it is way beyond me.  If you could have some kind of module that captured whatever event would indicate that the menu has been updated then it could output a .html file with the menu in it.  Applications that you are bridging (BB or blog or whatever) could then simply call this file in their templates.

Anyway, what I have above seems to work.  The whole lot can be just inserted into a PHPBB3 template and will draw the menu.  Need to switch PHPBB to allow php in template files before it will process it but then it works.
I've been trying to modify your hack to work with my menu, but I can't get it to work. It only gives me a 500 error page. The script posted above works but I need to mod it to make it fit into my page.
Here is my menucode:

Code: Select all

{if $count > 0}
<div class="MenuLinks">
	{foreach from=$nodelist item=node}
	<a href="{$node->url}">{$node->menutext}</a> |
	{/foreach}	
</div>
{/if}
Last edited by Kenny McCormick on Wed Dec 31, 2008 1:25 am, edited 1 time in total.
essexboyracer
Forum Members
Forum Members
Posts: 85
Joined: Wed Jun 20, 2007 5:40 pm

Re: Accessing Menu Manager stuff from outside cmsms? [SOLVED]

Post by essexboyracer »

I know this topic is 2 years old, but I thought I would post this as I was looking for the same solution today. I have in the past used a different method to achieve bridging, at the following link

http://tring-web-design.co.uk/2010/10/s ... templates/

It essentially works along the lines of alastair's better solution, reading in a html file for inclusion in other scripts
dazzyweb
Forum Members
Forum Members
Posts: 29
Joined: Mon May 30, 2011 1:21 pm

Re: Accessing Menu Manager stuff from outside cmsms? [SOLVED

Post by dazzyweb »

Hi
Does this code still work that was put here by Kenny McCormick?

Also i am confused by this section
$current = 58; # set this to the id of your page

Why is id of page a number?

Does anyone have another solution to pull the menu out and have it working in an outside page such as in phpbb3 or the menu from the cmsms database.
Post Reply

Return to “Modules/Add-Ons”