We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10076
    • 1,024 Posts
    Hi,

    does anyone know if I can have users register to a website. And with the webuser registration, have a gallery created at the same time? So when they recieve login details and link, they will be redirected to that page allowing them to upload pictures? All automaticly?

    thanks, Frank.
      • 7923
      • 4,213 Posts
      Yes, you can have it, but you need to implement such thing first.

      Eg. you need to possibly make a plugin or something that triggers on user registration and which will make a new document that has a maxigallery call with a &manager_webusers parameter in the snippet call with the registered users username. Then mail a link to the user with url to that document.



        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 10076
        • 1,024 Posts
        Hi and happy 2010,

        So as an idea, would that be able using WebLoginPE with a &loginFormTpl and somehow call this snippet (in a TV)to create a resource in that logingformtpl. Guess not, because how could the just created document ID be send to the newly registered webuser as a link. Any suggestions?
        <?php
        function createNewResource( &$fields ){
            
            global $modx;
            $values = array();
        	
            $values['pagetitle'] = $modx->db->escape($fields['title']);
            $values['longtitle'] = '';
            $values['description'] = '';
            $values['alias'] = '';
            $values['published'] = 1; //0 - if you want the document to be created unpublished
            $values['parent'] = 0; //id of the container for the the new document
            $values['introtext'] = '';
            $values['content'] = $modx->db->escape($fields['content']);
            $values['template'] = 4; //the template of your new document
            $values['searchable'] = 1;
            $values['cacheable'] = 1;
            $values['createdby'] = 1; //this is not the web user ID. Change it to an existing manager id
            $values['createdon '] = time();
            $values['editedby'] = 1; //this is not the web user ID. Change it to an existing manager id
            $values['editedon '] = time();
            //you can find more document properties by browsing the modx_site_content table
        	
            //insert the new document. In case you need the id of the new document use the  $newId variable
            $newId = $modx->db->insert( $values, $modx->getFullTableName('site_content') );
            
            //clear the cache. in case you use Ditto to display the new document
            clearCache();
        	
            return true;
        }
        
        function clearCache() {
            include_once "manager/processors/cache_sync.class.processor.php";
            $sync = new synccache();
            $sync->setCachepath("assets/cache/");
            $sync->setReport(false);
            $sync->emptyCache();
        }
        ?>


        Code from http://modxrules.com

        Thanks
          • 5340
          • 1,624 Posts
          HI,

          If you want to send users a link to a resource you should use the WebLoginPE events
          More info here:
          http://svn.modxcms.com/crucible/browse/~raw,r=37/modx-components/webloginpe/trunk/assets/snippets/webloginpe/docs/api.html#events

          Maybe you can use OnBeforeWebSaveUser or OnWebSaveUser to modify the email that gets sent on authentication. You can also use one of those events to create your new resource.

          Let me know if that makes sense.
            • 10076
            • 1,024 Posts
            Hi Cipa,

            it does make sence. however my knowledge of PHP is 0,000 something.
            I have been trying to squeeze in that bit of script from your site somewehere inside the webloginpe.class.php.
            Returns 500 errors, hmmm. Another tip perhaps?

            Frank.
              • 10076
              • 1,024 Posts
              Hi,

              would this be the direction to go in to create a new resource in webloginpe.class.php
              	function OnBeforeWebSaveUser($Attributes = array(), $ExtendedFields = array(), $values = array())
              	{
              		global $modx;
              
              		$parameters = array(
              			'Attributes'	=> $Attributes,
              			'ExtendedFields'=> $ExtendedFields
              			);
              			
              			$values = array(
              	
                  /*'pagetitle' 	=> $this-> $modx->db->escape($fields'title'),*/
              			'longtitle' 	=> $this->longtitle,
              			'description' 	=> $this->description,
              			'alias' 		=> $this->alias
              		);
              		$modx->invokeEvent('OnBeforeWebSaveUser', $parameters , $values);
              	}


              How ever the code is (very) incomplete cause I dont see how to wrap the rest of the fields:
               $values['pagetitle'] = $modx->db->escape($fields['title']);
                  $values['longtitle'] = '';
                  $values['description'] = '';
                  $values['alias'] = '';
                  $values['published'] = 1; //0 - if you want the document to be created unpublished
                  $values['parent'] = 0; //id of the container for the the new document
                  $values['introtext'] = '';
                  $values['content'] = $modx->db->escape($fields['content']);
                  $values['template'] = 4; //the template of your new document
                  $values['searchable'] = 1;
                  $values['cacheable'] = 1;
                  $values['createdby'] = 1; //this is not the web user ID. Change it to an existing manager id
                  $values['createdon '] = time();
                  $values['editedby'] = 1; //this is not the web user ID. Change it to an existing manager id
                  $values['editedon '] = time();




                • 2912
                • 315 Posts
                I did this a little while agousing the template and a snippet. The snippet was taken from NewsEditor snippet and it works on every page view (lame I know). If a user gallery isn’t found then one is created using the users Username.

                Create Template Variable:
                [*WebUserOwner*]
                


                Maxigallery Code:
                [!MaxiGallery? &admin_webusers=`[*WebUserOwner*]` &manager_webusers=`[*WebUserOwner*]` !]
                

                Note the use of the template variable. Don’t forget the rest of your Maxigallery parameters the above is just a brief example.

                Create new snippet called NewGallery with code below:
                <?php
                /*
                // C Hunton 22/1/09
                // NewGallery
                // This code should create a modx document in the relevant gallery and generate the TV's to associate it as a user gallery
                */
                
                // Default parameters required - Change where applicable
                // To find your template varaiable number goto Template Variable page in the manager.  
                // Hover over your template variable and you'll notice: example: /manager/index.php?id=2&a=301
                // The id= is your template variable number
                
                $gallery = isset($gallery) ? $gallery: "8";  // This is the document where you user gallery is stored
                $tmplvar = isset($tmplvar) ? $tmplvar: "2"; // This is the TemplateVariable where the Username is stored.
                $folder = $gallery;
                $clearcache = "1";
                // get template
                $template = isset($template) ? $modx->db->getValue('SELECT id FROM '.$modx->getFullTableName('site_templates').' WHERE templatename=\''.mysql_escape_string($template).'\'') : $modx->config['default_template'];
                // get menu status
                $hidemenu = 1;
                
                // get created date
                $createdon = time();
                
                // set menu index
                $mnuidx = $modx->db->getValue('SELECT MAX(menuindex)+1 as \'mnuidx\' FROM '.$modx->getFullTableName('site_content').' WHERE parent=\''.$folder.'\'');
                if($mnuidx<1) $mnuidx = 0; 
                
                $user = $modx->getWebUserInfo($modx->getLoginUserID());
                $userid = $modx->getLoginUserID();
                
                // Username valid check
                if (!$user['username']) {
                 echo "You must log in to create your gallery.";
                return;
                }
                
                // Make the alias for the document
                // remove any unnecessary tags
                $aliasname = $modx->stripTags($user['username']);
                $aliasname = strtolower($aliasname);
                $aliasname = preg_replace('/&.+?;/', '', $aliasname); // kill entities
                $aliasname = preg_replace('/[^\.%a-z0-9 _-]/', '', $aliasname);
                $aliasname = preg_replace('/\s+/', '-', $aliasname);
                $aliasname = preg_replace('|-+|', '-', $aliasname);
                $aliasname = trim($aliasname, '-');			
                $aliasname = $modx->db->escape($aliasname);
                $aliasname = str_replace('.', '', $aliasname); // remove any .'s just incase
                $alias = $aliasname;
                $aliasname = $aliasname."-gallery";
                
                // Make the title for the document
                $title = $alias."'s Gallery";
                
                // Check if the user already has a gallery
                $rs = $modx->db->query("SELECT * 
                			FROM ".$modx->getFullTableName('site_tmplvar_contentvalues')."
                			WHERE tmplvarid = '".$tmplvar."' AND value = '".$user['username']."'");
                $count = $modx->db->getRecordCount($rs);
                $row = mysql_fetch_array($rs);
                
                
                if ($count >= 1) {
                	echo 'Your <a href="'.$aliasname.'" title="Your Gallery">Gallery</a> is Ready!';
                	return;
                }
                
                
                $published= 1;
                $pub_date = 0;
                $unpub_date = 0;
                
                $flds = array(
                          'pagetitle'   => mysql_escape_string($modx->stripTags($title)),
                          'longtitle'   => mysql_escape_string($modx->stripTags($title)),
                          'description' => mysql_escape_string($modx->stripTags($title)),
                          'introtext'   => mysql_escape_string($modx->stripTags($title)),
                          'alias'       => $aliasname,
                          'parent'      => $folder, 
                          'createdon'    => $createdon,
                          'createdby'    => ($userid>0 ? $userid * -1:0),
                          'editedon'    => '0',
                          'editedby'    => '0',
                          'published'   => $published,
                          'pub_date'    => $pub_date,
                          'unpub_date'  => $unpub_date,
                          'deleted'     => '0',
                          'hidemenu'    => $hidemenu,
                          'menuindex'   => $mnuidx,
                          'template'    => $template,
                          'cacheable'    => '0',
                          'content'     => "<p>{{Screenshots}}</p>"
                        );
                $redirectid = $modx->db->insert($flds,$modx->getFullTableName('site_content'));
                echo "Gallery Created!<br />";
                $lastInsertId = $modx->db->getInsertId();
                
                $flds = array(
                          'tmplvarid'   => $tmplvar,
                          'contentid'   => $lastInsertId,
                          'value' => $user['username']
                		  );
                
                $tmpInsert = $modx->db->insert($flds,$modx->getFullTableName('site_tmplvar_contentvalues'));
                echo 'Your <a href="'.$aliasname.'" title="Your Gallery">Gallery</a> is ready!';
                
                      // empty cache
                      if($clearcache == 1) {
                        include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
                        $sync = new synccache();
                        $sync->setCachepath("assets/cache/");
                        $sync->setReport(false);
                        $sync->emptyCache(); // first empty the cache		
                      }
                
                        // Get doc groups based on $folder (parent id)
                        $parentDocGroupsSql = "SELECT * FROM " . $modx->getFullTableName('document_groups'). " where document=".$folder;
                        $parentDocGroupsRs = $modx->db->query($parentDocGroupsSql);
                        $parentDocGroupsLimit = $modx->db->getRecordCount($parentDocGroupsRs);
                        for ($pdgi = 0; $pdgi < $parentDocGroupsLimit; $pdgi++) { 
                          $currentDocGroup = $modx->db->getRow($parentDocGroupsRs);
                          $parentDocGroupsArray[$pdgi] = $currentDocGroup['document_group'];
                        }
                
                        // put the document in the document_groups it should be in
                        // check that up_perms are switched on!
                        if($modx->config['use_udperms']==1) {
                          if(is_array($parentDocGroupsArray)) {
                            foreach ($parentDocGroupsArray as $dgKey=>$dgValue) {
                              $insertDocSql = "INSERT INTO ".$modx->getFullTableName('document_groups')."(document_group, document) values(".stripslashes($dgValue).", $lastInsertId)";
                              $insertDocRs = $modx->db->query($insertDocSql);
                              if(!$insertDocRs){
                                exit;
                              }
                            } // end foreach
                          } // end if doc group array exists
                        } // end if perms are used
                
                      // empty cache
                      if($clearcache == 1) {
                        include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
                        $sync = new synccache();
                        $sync->setCachepath("assets/cache/");
                        $sync->setReport(false);
                        $sync->emptyCache(); // first empty the cache		
                      }
                ?>
                


                Add snippet into your template (close to webloginpe snippet call is a good idea) with:

                [!NewGallery?!]
                


                If a user is not logged in there will be a message saying: You must log in to create your gallery

                When you first log in a new document resource is created with the Template Variable of the username.

                There is one caveat that I have yet to figure out. WebLoginPE isn’t bothered about username case sensitivity when logging in but Maxigallery is. Therefore if I were to login using "bbloke" but my actual username and Template Variable for my Galley is "BBloke" then it won’t show me the "manage pictures" buttons.

                I have it working here. The login in fields are at the top left hand corner.

                EDIT: amended snippet details and where to put the snippet call in the template.
                  BBloke
                  • 10076
                  • 1,024 Posts
                  Hi,

                  got that working, great thanks.
                  Still would like to strip some stuff.
                  Would be great to get somehow a button appearing after login for the webuser linking to their upload page.
                  Now the get there after logging in, but once they start browsing the site, they need to re log to get to their upload page. Or is that an error in my setup?

                  Thanks, Frank.

                  PS do you think one could edit maxgallery somehow to get rid of the lower/uppercase username problem (strtolower)?
                    • 7923
                    • 4,213 Posts
                    For the case sensitive usernames, add this function to maxigallery class file:
                    <?php
                        function in_arrayi( $needle, $haystack ) {
                            $found = false;
                            foreach( $haystack as $value ) {
                                if( strtolower( $value ) == strtolower( $needle ) ) {
                                    $found = true;
                                }
                            }   
                            return $found;
                        }
                    


                    And then in the checkPermissions function, change in_array to in_arrayi when it’s checking for manager_webusers and admin_webusers.


                      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                      • 10076
                      • 1,024 Posts
                      Okay thanks Doze,

                      one small problem remains, no folders are created in the gallerie root, all images are stored in one folder (1). Anyway to alter that,

                      thanks, Frank.