We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29635
    • 361 Posts
    Hi all,
    For a site I’m setting up there’s a good deal of content that needs to be in a web document group, but I want the items to show up in DropMenu (to entice the visitor to register). Can anybody offer suggestions on whether that’s possible? I can’t find any code that seems to control that in the snippet

    Thanks for any help.
    -Brett
      Need MODx Ecommerce? Try FoxyCart!
      • 7923
      • 4,213 Posts
      Dropmenu uses getActiveChildren API call to retrieve the menu items. It seems that all of the MODx api functions are checking the access rights when retrieving documents, so don’t know if this is possible without doing an own function for this. But you could achieve this by putting a new function to your MODx document.parser.class.inc.php (or straight to the snippet and replace $this with $modx) like:

      (same as getActiveChildren but access permission checking removed)

      <?php
      	function getAllActiveChildren($id=0, $sort='menuindex', $dir='ASC', $fields='id, pagetitle, description, parent, alias, menutitle') {
      		$tblsc = $this->getFullTableName("site_content");
      		$tbldg = $this->getFullTableName("document_groups");
      
      		// modify field names to use sc. table reference
      		$fields = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$fields)));
      		$sort = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$sort)));
      		// get document groups for current user
      		if($docgrp = $this->getUserDocGroups()) $docgrp = implode(",",$docgrp);
      		// build query
      		$sql = "SELECT DISTINCT $fields FROM $tblsc sc
      				LEFT JOIN $tbldg dg on dg.document = sc.id
      				WHERE sc.parent = '$id' AND sc.published=1 AND sc.deleted=0
      				ORDER BY $sort $dir;";
      		$result = $this->dbQuery($sql);
      		$resourceArray = array();
      		for($i=0;$i<@$this->recordCount($result);$i++)  {
      			array_push($resourceArray,@$this->fetchRow($result));
      		}
      		return $resourceArray;
      	}
      ?>


      And then replace getActiveChildren calls in DropMenu with getAllActiveChildren. But I don’t know that is this the best/correct way to do it or could this produce some security issues. So you better wait until someone with more knowledge on security can comment this. And I’m not totally sure what happens when user clicks to the page links that he don’t have rights to, I’m sure they won’t be displayed, but don’t know that will it show access denied error or redirect to so some page or what..


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 29635
        • 361 Posts
        Wow, thanks Doze for the great explanation and detailed response. I’ll do some testing and let you know how it behaves (where it spits you out, I’m assuming the unauthorized page as specified in the settings, but maybe not).

        As an aside (and this could probably use a full thread), is there a way to add custom functions without hacking the core? It might be a really neat if MODx came with an extra "custom core" that was avilable by default and could be called like #modxCustom->myCustomFunction();

        Just a thought. Maybe I’ll play with that too.
          Need MODx Ecommerce? Try FoxyCart!
          • 29635
          • 361 Posts
          Hmmm... so, I’ve attempted this every way I can think of and can’t seem to make any progress. The funny thing is that if I change :

          $children = $modx->getActiveChildren(

          to
          $children = $modx->get_THIS_SHOULD_NOT_WORK_AllActiveChildren(


          It still works normally, so... what’s that function doing? (Doze, adding the custom class and trying to call it doesn’t do anything either, because this function’s not actually doing anything?)

          Thanks for any help. I’m lost.
            Need MODx Ecommerce? Try FoxyCart!
            • 7923
            • 4,213 Posts
            Just to be sure before I look more into it, are you calling the snippet uncached? [!DropMenu!] in cached page or [[DropMenu]] when page is uncached.


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 29635
              • 361 Posts
              Good question, but yes. I actually made a new snippet, so I’m calling [!DropMenuAll? &etc...!]
              Thanks a ton for you help.
                Need MODx Ecommerce? Try FoxyCart!
                • 7923
                • 4,213 Posts
                Ok, I tried this and it works ok. Here’s what I did:

                1. Copy pasted the function above to document.parser.class.inc.php and placed it above the getActiveChildren function.
                2. Copy pasted the code from DropMenu to a text editor and did search/replace to replace getActiveChildren with getAllActiveChildren.
                3. Created a new menu snippet and pasted the code there.
                4. Made some template that uses this menu snippet.
                4. Made some web user and web user groups / document groups in web permissions and liked them together.
                5. Assigned some document to the created document group (note that in the document page data section, you should see "Web access: Private")
                6. Viewed the results. The private pages are shown in the menu, but when clicking to them, MODx redirects to the "unauthorized page" that you have set in the manager at System Configuration.

                What did you mean that it worked "normally" when you tried it?


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                  • 27
                  • 117 Posts
                  hi.

                  i get "Missing argument 28 for makemap()" as a Modx Parse error when i add that function (im on 0961p1 in case that matters)

                  any clues?

                  cheers in advance, thanks for the thread on this topic, im hoping to reveal my secured links to encourage signups =)

                  0
                    • 27
                    • 117 Posts
                    i took the caching off the snippet and the error changed to:

                    « Execution of a query to the database failed - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ’) GROUP BY sc.id ORDER BY sc.menuin »
                    SQL: SELECT DISTINCT sc.id,sc.pagetitle,sc.description,sc.isfolder,sc.parent,sc.alias,sc.longtitle,sc.menutitle,sc.hidemenu,sc.introtext,sc.content_dispo,sc.contentType,sc.type,sc.template FROM `db_modx_sd`.`modx_site_content` sc LEFT JOIN `db_modx_sd`.`modx_document_groups` dg on dg.document = sc.id WHERE sc.parent = ’47’ AND sc.published=1 AND sc.deleted=0 AND () GROUP BY sc.id ORDER BY sc.menuindex ASC;
                      • 27
                      • 117 Posts
                      got it going (thanks to disco phill)

                      remove:

                      AND ($access)


                      in document.parser.class.inc.php

                      wink