Page 1 of 1

[SOLVED] Search page-hierarchy UDT breaks site

Posted: Tue Feb 12, 2013 6:25 pm
by Larrybear
Hello!

CMS MS: 1.11.4
CMSMailer 5.2.1
CMSPrinting 1.0.3
FileManager 1.4.3
MenuManager 1.8.5
MicroTiny 1.2.5
ModuleManager 1.5.5
News 2.12.10
Search 1.7.7
ThemeManager 1.1.7
CGExtensions 1.31.4
JQueryTools 1.2.3
MleCMS 1.11.4
MultiDomains 2.1.1
CGSimpleSmarty 1.5.2
CompanyDirectory 1.17
CGGoogleMaps 2.4.3

I am trying to set up the Search so that it only display results from a specified parent page and it's children. Original post: http://forum.cmsmadesimple.org/viewtopic.php?t=41537

The reason for this is because i am setting up a multi-domain site. And i want the search module to only display pages from a specific site.

For example the page structure could look like this:
site one (1)
Site 1 page 1 (1.1)
Site 1 page 2 (1.2)
Site two (2)
Site 2 page 1 (2.1)
Site 2 page 2 (2.2)

But when i insert the UDT call in a page or template the site breaks. (No CSS, no error msg)

Code: Select all

 {all_content assign='children' parent_hierarchy='00001'}
I have tried mixing around with it, and reading here on the forum but i can't figure out what the problem is.

UDT:

Code: Select all

/*$params['assign']*/
/*$params['parent_hierarchy']*/

if (!empty($params['assign']) && !empty($params['parent_hierarchy'])){
   global $gCms;
   $contentops =& $gCms->GetContentOperations();
   $all_content = $contentops->GetAllContent(false);
   $assign = array();
   foreach($all_content as $one_page){
      if (strpos($one_page->mHierarchy, $params['parent_hierarchy']) === 0){
         $assign[] = $one_page->mAlias;
      }
   }
   $smarty = $gCms->GetSmarty();
   $smarty->assign($params['assign'], $assign);
}
Search module result template (This should only display results from parent 2 and it's children 2.1 and 2.2)

Code: Select all

{assign var="nocount" value=0}

{if $itemcount > 0}

<ul>
  {foreach from=$results item=entry}

  {all_content assign='children' parent_hierarchy='00001'}

  {foreach from=$children item=child}
    {cms_selflink href=$child assign='childurl'}
    {if $childurl == $entry->url}
       {assign var="show" value="no"}
    {/if}
  {/foreach}

  {if $show != "no"}
  <li><a href="{$entry->url}">{$entry->title}</a> ({$entry->weight}%){$entry->id}</li>
  {*
     You can also instantiate custom behaviour on a module by module basis by looking at
     the $entry->module and $entry->modulerecord fields in $entry
      ie: {if $entry->module == 'News'}{News action='detail' article_id=$entry->modulerecord detailpage='News'}
  *}
  {else}
    {assign var="nocount" value=$nocount+1}
  {/if}
  {assign var="show" value=""}
  {/foreach}
</ul>
{else}
<ul></ul>
{/if}

{if $nocount == $itemcount}
  <p><strong>{$noresultsfound}</strong></p>
{/if}
Menu template (if that has anything to do with it)

Code: Select all

{* CSS classes used in this template:
#menuwrapper - The id for the <div> that the menu is wrapped in. Sets the width, background etc. for the menu.
#primary-nav - The id for the <ul>
.menuparent - The class for each <li> that has children.
.menuactive - The class for each <li> that is active or is a parent (on any level) of a child that is active. *}

{assign var='number_of_levels' value=10000}
{if isset($menuparams.number_of_levels)}
  {assign var='number_of_levels' value=$menuparams.number_of_levels}
{/if}

{if $count > 0}
<div id="menuwrapper">
<ul id="primary-nav">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string='<ul class="unli">' times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string='</li></ul>' times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->parent == true or $node->current == true}
  {assign var='classes' value='menuactive'}
  {if $node->parent == true}
    {assign var='classes' value='menuactive menuparent'}
  {/if}
  {if $node->children_exist == true and $node->depth < $number_of_levels}
    {assign var='classes' value=$classes|cat:' parent'}
  {/if}
  <li class="{$classes}"><a class="{$classes}" 
{elseif $node->type == 'sectionheader' and $node->haschildren == true}
  <li class="menuparent"><a class="menuparent"><span class="sectionheader">{$node->menutext}</span></a>
{elseif $node->type == 'sectionheader'}
  <li><a ><span class="sectionheader">{$node->menutext}</span></a>
{elseif $node->type == 'separator'}
  <li style="list-style-type: none;"> <hr class="menu_separator" />
{elseif $node->children_exist == true and $node->depth < $number_of_levels and $node->type != 'sectionheader' and $node->type != 'separator'}
  <li class="menuparent"><a class="menuparent" 
{else}
  <li>
  <a 
{/if}

{if ($node->type != 'sectionheader' and $node->type != 'separator') or $node->parent == true or $node->current == true }
 {if $node->target}target="{$node->target}" {/if}
href="{$node->url}"><span>{$node->menutext}</span></a>
{/if}
{/foreach}
{repeat string='</li></ul>' times=$node->depth-1}
</li>
</ul>
<div class="clearb"></div>
</div>
{/if}
Any ideas what the problem could be? Or do you need more information?

Big thanks in advance for taking the time to help!

/Regards
- Larry

Re: Search page-hierarchy UDT breaks site

Posted: Sat Feb 16, 2013 1:11 pm
by Larrybear
Some additional information. When i put this tag in a page or template: (When i say the page breaks, all CSS and code is gone, all content floated to the left side of the screen, and not even debug mode showing up)

Code: Select all

  {all_content assign='children' parent_hierarchy='00001'}
The site breaks, if i remove one part of the tag, say like

Code: Select all

  {all_content parent_hierarchy='00001'}
The site works again, but the UDT has no effect.

I tried going to the config.php file and changed debug to true, but no debug information shows up on the "broken page".

I am not really that good with php and such, but i am learning after hand, and often i have a clue what the problem is, but this UDT comes from, and worked for others, and i have really no idea why it crashes the site.

Any help would be great!

/Best Regards
Larry

Re: Search page-hierarchy UDT breaks site

Posted: Sat Feb 16, 2013 4:55 pm
by klenkes
The problem lies most likely in your UDT:

Code: Select all

/*$params['assign']*/
/*$params['parent_hierarchy']*/

if (!empty($params['assign']) && !empty($params['parent_hierarchy'])){
   global $gCms;
   $contentops =& $gCms->GetContentOperations();
   $all_content = $contentops->GetAllContent(false);
   $assign = array();
   foreach($all_content as $one_page){
      if (strpos($one_page->mHierarchy, $params['parent_hierarchy']) === 0){
         $assign[] = $one_page->mAlias;
      }
   }
   $smarty = $gCms->GetSmarty();
   $smarty->assign($params['assign'], $assign);
}
You are using old methods, which are not allowed in CMSMS 1.11 anymore.

Example:
Instead of ->mAlias you have to use ->Alias()
Same for mHierarchy

Re: Search page-hierarchy UDT breaks site

Posted: Sun Feb 17, 2013 3:39 am
by Larrybear
Thanks for your reply!

Ah... Great...

I changed the two arrays and now the site don't break anymore! :D but the "setup" does not work, the children of page one still appear in the search results. Anyone have any idea if this is easy to fix?

I read the announcements about the 1.11 releases, and did some digging around the admin area, but to be honest, since i did not make this myself, and it's a bit beyond my skill level, i have no idea to fix it.

From what i could gather from everything, alot of changes was made when CMSMS 1.11 was released. So i have no clue if the problem still is the UDT or not.

Current UDT:

Code: Select all

/*$params['assign']*/
/*$params['parent_hierarchy']*/

if (!empty($params['assign']) && !empty($params['parent_hierarchy'])){
   global $gCms;
   $contentops =& $gCms->GetContentOperations();
   $all_content = $contentops->GetAllContent(false);
   $assign = array();
   foreach($all_content as $one_page){
      if (strpos($one_page->Hierarchy, $params['parent_hierarchy']) === 0){
         $assign[] = $one_page->Alias;
      }
   }
   $smarty = $gCms->GetSmarty();
   $smarty->assign($params['assign'], $assign);
}
As always, thanks for all the help!

/Best Regards
- Larry

Re: Search page-hierarchy UDT breaks site

Posted: Sun Feb 17, 2013 2:35 pm
by klenkes
I just tried on a test install and it works.

First:
In your UDT it has to be:

Code: Select all

$one_page->Hierarchy();
and $one_page->Alias();

and instead of:
$smarty = $gCms->GetSmarty();
it better be:
$smarty = cmsms()->GetSmarty();
Second:
Call the UDT like this:

Code: Select all

{all_content assign='children' parent_hierarchy='4'}
Note the single digit hierarchy!

Re: Search page-hierarchy UDT breaks site

Posted: Sun Feb 24, 2013 5:19 pm
by Larrybear
klenkes wrote:I just tried on a test install and it works.

First:
In your UDT it has to be:

Code: Select all

$one_page->Hierarchy();
and $one_page->Alias();

and instead of:
$smarty = $gCms->GetSmarty();
it better be:
$smarty = cmsms()->GetSmarty();
Second:
Call the UDT like this:

Code: Select all

{all_content assign='children' parent_hierarchy='4'}
Note the single digit hierarchy!
You are a lifesaver! Can't thank you enough! :D