We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9496
    • 113 Posts
    I was trying to retrieve the user information for a specific picture in my managepicturetpl.

    I figured I could probably use phx to accomplish this but I can’t seem to figure out the placeholder.

    So my template placeholder looks like this.

    This displays the owner id in the MG table ...
    [+maxigallery.picture.own_id+]


    So in my head this would display the user info associated with the owner id own_id = ModX userID

    [+maxigallery.picture.own_id:userinfo=`email`+]




    I’ve seen extended placeholders like this in other circumstances {*createdby:userinfo=`email`*} for instance. I figure since own_id outputs a number (such as 2) phx should parse it this way.

    Or am I totally missing something...


      • 7923
      • 4,213 Posts
      Yes, that’s how it should work..

      Is the picture uploaded by webuser or manager user?

      The source for the phx userinfo modifier is:

      <?php
      case "userinfo":
        if ($output == "&_PHX_INTERNAL_&") $output = $this->user["id"];
        $output = $this->ModUser($output,$modifier_value[$i]);
        break;
      


      And the function..
      <?php
        // Returns the specified field from the user record
        // positive userid = manager, negative integer = webuser
        function ModUser($userid,$field) {
        	global $modx;
        	if (intval($userid) < 0) {
        		$user = $modx->getWebUserInfo(-($userid));
        	} else {
        		$user = $modx->getUserInfo($userid);
        	}
        	return $user[$field];
        }
      


      So it expects that the web user ids are negative and manager user ids positive. Check that they are stored that way in MaxiGallery.

      Also you could debug that adding die(print_r($user)) to the end of phx ModUser function before the return to see what it finds.. also print the contents of ModUser function call parameters.


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 9496
        • 113 Posts
        Hey Doze-
        Thanks, thats what I thought. I think since I was logged in as a manager in the backend when I uploaded them (and a web-user in the front end) I think the manager took precedence. I’ll take a look at the table and see what I can find out.

        thanks-
        P

        UPDATE: Looks like they are being saved as positive integers so Im not sure whats affecting that. Ill have some more time this afternoon to mess around with it a bit. The users in the main modx webusers table are also showing positive numbers instead of negative. hmmm, I remember reading that same thing about webusers being negative and manager users being positive but Ill have to look into it further.

        I had been using a workaround with custom fields but thats duplicating things so its not ideal obviously. But Ill report back anyway.

        thanks again-
        P
          • 9496
          • 113 Posts
          Looks like the modX user tables are like I thought and whether I create the users via backend manager or through the weblogin register they all are returned positive. Im using the evo version 1.0 so I dont know if they changed that or not. Ill try and adjust the phx.parser.class to see if that makes a difference.

          UPDATE: When I look under the modx_active users they return a negative integer, which kind of explains why a blank phx call works...hmm
          ANother UPDATE: So it looks like the problem has to do with MG returning a positive own_id to the own_id MG table. If I go in and manually switch to a negative number (indicating a WU) then all is good and the modifier works.

          So the question becomes, where in the script do I find where it originates the owner id? I would think its simply a matter of adding a - to the db write statement.

          -P
            • 9496
            • 113 Posts
            So Doze feel free to chime in here, but I found by changing the maxigallery.class.inc.php line 485 from this:

            $rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date, own_id) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ",'".$modx->getLoginUserID()."')");


            to this

            $rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date, own_id) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ",'"."-".$modx->getLoginUserID()."')");


            and changing line 667 in the maxigallery php file:

            	$sql = "SELECT * FROM " . $mg->pics_tbl . " WHERE gal_id='" . $mg->pageinfo['id'] . "' AND own_id='" . $modx->getLoginUserID() . "' ORDER BY " . $orderby . " " . $mg->mgconfig['order_direction'];


            to this:

            $sql = "SELECT * FROM " . $mg->pics_tbl . " WHERE gal_id=’" . $mg->pageinfo[’id’] . "’ AND own_id=’-" . $modx->getLoginUserID() . "’ ORDER BY " . $orderby . " " . $mg->mgconfig[’order_direction’];



            Changing the first line allows maxigallery to process uploads with a -(userid) and then the subsequent phx modifier to work. The second change allows maxigallery to read the new negative owner id when managing.

            Now my question becomes, what if anything have I broken and whether or not this is the appropriate method to go about it. And two, could a simple change to the phx parser code in the chunkie directory (to read the positive UID) been a better approach (without modifying the class & snippet script)?

            any insight would be great.
            -P
              • 7923
              • 4,213 Posts
              Yes, that is a correct way to fix it. It’s more like a bug in MaxiGallery. I have not made it store the user id’s as negative values what comes through $modx->getLoginUserID(). I’ve probably just thought that they come ok through the API already.

              I haven’t been looking into the whole negative web users id thing a lot, so I don’t know why they are designed to work that way. But it seems that you should first check if a user is a web user via $modx->getLoginUserType() and then translate the user id to a negative one.

              Good job, I will make a note to myself to fix this for the final version.


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 9496
                • 113 Posts
                Yeah I was trying to figure that out myself. I suppose it has something to do with being able to differentiate user permissions on a more granular level for the management side of things, but who knows.

                Since I had been using a different method (sans the maxigallery modifiers) by using custom fields and straight phx modifiers instead, I had to go in and reset some things (like adding modx users manually and then manually altering the maxigallery table to reflect these new users, rather than the custom fields output) but it makes for a far more manageable, and logical set-up. Especially when it comes to generating user data, which is now only located in the user table, which is where it should be.

                Im getting close to launching this sucker, and I figure when its live I’ll post a walkthrough on how to use Maxigallery as a framework for photo contests.

                thanks again-
                P

                [UPDATE] Site is launched. Doze, if yer at all interested send me a pm and I’ll send you the admin credentials so you can login and see how the manager side of things is working.


                  • 17921
                  • 101 Posts
                  Hallo! I`d like to do the same on my site, but I`m not a programmer smiley

                  Could someone please explain how it should look like.

                  I mean in my pictureTpl I have:

                  [+maxigallery.picture.own_id:userinfo=`username`+]

                  And I have snippet username:

                  <?php
                  case "userinfo":
                  if ($output == "&_PHX_INTERNAL_&") $output = $this->user["id"];
                  $output = $this->ModUser($output,$modifier_value[$i]);
                  break;

                  And where I should paste this?

                  <?php
                  // Returns the specified field from the user record
                  // positive userid = manager, negative integer = webuser
                  function ModUser($userid,$field) {
                  global $modx;
                  if (intval($userid) < 0) {
                  $user = $modx->getWebUserInfo(-($userid));
                  } else {
                  $user = $modx->getUserInfo($userid);
                  }
                  return $user[$field];
                  }

                    samurai smiley
                    • 7923
                    • 4,213 Posts
                    You don’t need to create any snippets, the userinfo modifier is in PHx.

                    What you need to do is to open maxigallery.class.inc.php and find this around line 485:
                    $rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date, own_id) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ",'".$modx->getLoginUserID()."')");


                    And change it to this:
                    $rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date, own_id) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ",'"."-".$modx->getLoginUserID()."')");


                    Then open maxigallery.php and find this around line 667:
                    $sql = "SELECT * FROM " . $mg->pics_tbl . " WHERE gal_id='" . $mg->pageinfo['id'] . "' AND own_id='" . $modx->getLoginUserID() . "' ORDER BY " . $orderby . " " . $mg->mgconfig['order_direction'];


                    And change it to this:

                    $sql = "SELECT * FROM " . $mg->pics_tbl . " WHERE gal_id='" . $mg->pageinfo['id'] . "' AND own_id='-" . $modx->getLoginUserID() . "' ORDER BY " . $orderby . " " . $mg->mgconfig['order_direction'];


                    Then upload some pictures and see if it gives the username. This should do it for web users. Don’t know what happens about manager users..


                      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                      • 17921
                      • 101 Posts
                      Thank you, doze. Now it works!
                        samurai smiley