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

    I’m using maxigallery. I’m looking for a solution, that my publishers are able to add a document (new gallery) trough frontend.

    What is the best way to do this?

    Thanks a lot!
      • 3041
      • 4 Posts
      No solution for this? I’m only looking for a gallery-snipped, which is able to add new galleries trough frontend without using FDM..

      Thanks for help!
        • 26931
        • 2,314 Posts
        QuickManager?
          • 28148
          • 6 Posts
          Hi!

          I suppose you want to provide your editors a textfield where they can simply input the gallery name and then just click some sort of "generate" button. If this is the case here’s my very-quick-and-very-dirty snipppet:

          <?php
          $output='';
          
          // ------------------- START CAKEMODX -------------------
          
          class CakeMODx {
          
          	/**
          	 * DBAPI object
          	 * @var object
          	 */
          	var $db;
          
              /**
               * The CakeMODx Constructor.
               *
               * Setting class properties.
               * @return void
               */
          	function CakeMODx()
          	{
          		global $modx;
          		$this->db = $modx->db;
          	}
          
              /**
               * Creates a new MODx document.
               *
               * @param array $fields An associative array of `site_content` table.
               * @return mixed ID of new document as integer on success and FALSE on failure.
               */
          	function newDocument($fields=array())
          	{
          	
          		global $modx;
          		
          		if(! $id = $this->db->insert($fields, $modx->getFullTableName('site_content')))
          			$this->logError('newDocument', $this->db->getLastError(), time());
          
          		return $id;
          	}
          
          }
          
          // ------------------- END CAKEMODX -------------------
          
          
          
          if(isset($_POST['save_doc'])) {
          
          	$CakeModx = new CakeModx;
          
          	$fields = array(
                  "pagetitle" => htmlentities($_POST['title']),
                  "content" => "[!MaxiGallery? &display=`normal` &pics_per_row=`3` &max_thumb_size=`250` &max_pic_size=`550` &thumb_use_dropshadow=`1` &pic_use_dropshadow=`1` &use_flash_upload=`1` &lang=`ge_du`!]",
                  "published" => 1,
                  "template" => 5,
                  "parent" => 4
          	);
          
          	if(!empty($_POST['title'])) {
          
          		$id = $CakeModx->newDocument($fields);
          
          		$output .= '"Neue Galerie mit dem Titel "' . $fields['pagetitle'] . '" (ID: ' . $id . ') angelegt! Du kannst jetzt Bilder hochladen.';
          	} else {
          
          		$output.='Neue Galerie konnte nicht angelegt werden. Bitte einen gültigen Titel eingeben!';
          
          	}
          
          } else {
          
          	$output .= '<form method="post" action="'.$_SERVER['REQUEST_URI'].'">
          					Galerie Titel: <input type="text" name="title" value="'.$pce_ar_charts['title'].'"/><br/>
          					<input type="submit" name="save_doc" value="anlegen" />
          				</form>';
          				
          }
          
          return $output;
          ?>
          


          I just took the newDocument function from CakeModX and came out with this. And yes, i do know this is anything but great code but it works for my testing purposes. There should be some better error checking and chunk utilisation. I will probably implement this in the near future.
            • 7923
            • 4,213 Posts
            it would also be nice if you’d do a configuration option there to include &manager_webusers parameter to the maxigallery call which would contain the logged in user’s username.. e.g. you could use it to create galleries that only the person who created it can edit. Thanks for the post!


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 28148
              • 6 Posts
              @doze:
              Currently I’m very busy with finishing my bachelor thesis. As soon as I’m done with that, I will have enough time to review this snippet and implement some cool features smiley
                • 26931
                • 2,314 Posts
                Hi speedbird88,

                thanks for you Snippet ... working great smiley

                got one question though. Is it possible to run the TransAlias plugin from within the Snippet? because when i set the Alias field:
                	$fields = array(
                        "pagetitle" => $_POST['title'],
                        "alias" => $_POST['title'],
                        "content" => "[!MaxiGallery? ... !]",
                        "published" => 1,
                        "richtext" => 0,
                        "template" => 6,
                        "parent" => 6
                	);
                the plugin will only be executed when i save the ressource from within the manager. Any ideas?

                thanks, j
                  • 20413
                  • 2,877 Posts
                  What if you paste this function in the code http://modxcms.com/forums/index.php/topic,48656.msg285037.html#msg285037
                  Or maybe you don’t even have to(!)
                  $alias = $modx->stripAlias($_POST['title']);
                  
                  	$fields = array(
                          "pagetitle" => $_POST['title'],
                          "alias" => $alias,
                          "content" => "[!MaxiGallery? ... !]",
                          "published" => 1,
                          "richtext" => 0,
                          "template" => 6,
                          "parent" => 6
                  	);
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                    • 26931
                    • 2,314 Posts
                    excellent mrhaw grin
                    $alias = $modx->stripAlias($_POST['title']);
                    works perfect!

                    thanks! j

                    // i also added the clearCache function so that the new ressource would appear in Ditto listings etc.

                    class CakeMODx {
                    
                    	var $db;
                    
                    	function CakeMODx()
                    	{
                    		global $modx;
                    		$this->db = $modx->db;
                    	}
                    
                    	function newDocument($fields=array())
                    	{
                    	
                    		global $modx;
                    		if(! $id = $this->db->insert($fields, $modx->getFullTableName('site_content')))
                    		$this->logError('newDocument', $this->db->getLastError(), time());
                    		clearCache();
                    		return $id;
                    	}
                    
                    }
                    
                    function clearCache() {
                        include_once "manager/processors/cache_sync.class.processor.php";
                        $sync = new synccache();
                        $sync->setCachepath("assets/cache/");
                        $sync->setReport(false);
                        $sync->emptyCache();
                    }


                    btw. OpenGeek mentioned to trigger plugins within Snippet code by using:
                    $modx->invokeEvent('OnStripAlias', $parameters);

                    and someone else:
                    eval($modx -> pluginCache[ 'pluginName' ]);


                    *i’ll try to add doze’s suggestion*
                      • 26931
                      • 2,314 Posts
                      okay, i edited the Snippet code so that only the WebUser who created the gallery is able to edit this particular gallery ( i also changed the class name to "MGnew" ) + added the createdon timestamp + empty cache and mrhaws TransAlias & menuindex solution + after creation a link to the new gallerie is displayed :

                      <?php
                      $output='';
                      
                      class MGnew {
                      
                      	var $db;
                      
                      	function MGnew() {
                      		global $modx;
                      		$this->db = $modx->db;
                      		}
                      
                      	function newDocument($fields=array()) {
                      		global $modx;
                      		if(! $id = $this->db->insert($fields, $modx->getFullTableName('site_content')))
                      		$this->logError('newDocument', $this->db->getLastError(), time());
                      		clearCache();
                      		return $id;
                      		}
                      
                      	}
                      
                      	function clearCache() {
                      		include_once "manager/processors/cache_sync.class.processor.php";
                      		$sync = new synccache();
                      		$sync->setCachepath("assets/cache/");
                      		$sync->setReport(false);
                      		$sync->emptyCache();
                      		}
                      
                      
                      	if(isset($_POST['save_doc'])) {
                      
                      	$MGnew = new MGnew;
                      
                      	$parent = isset( $parent ) ? $parent : '0';
                      	$alias = $modx->stripAlias($_POST['title']);
                      	$timestamp = time();
                      	$webusername = $_SESSION['webShortname'];
                      	$mnuidx = $modx->db->getValue('SELECT MAX(menuindex)+1 as \'mnuidx\' FROM '.$modx->getFullTableName ('site_content').' WHERE parent=\''.$parent.'\'');
                            if($mnuidx<1) $mnuidx = 0;
                      
                      	$fields = array(
                      	"pagetitle" => $_POST['title'],
                      	"alias" => $alias,
                      	"content" => "[!MaxiGallery? &manager_webusers=`$webusername` !]",
                      	"published" => 1,
                      	"createdon" => $timestamp,
                      	"richtext" => 0,
                      	"template" => 6,
                      	"menuindex" => $mnuidx,
                      	"parent" => $parent
                      	);
                      
                      	if(!empty($_POST['title'])) {
                      
                      		$id = $MGnew->newDocument($fields);
                      		$url = $modx->makeUrl($id, '', '', 'full');
                      		$name = $fields['pagetitle'];
                      		$output .= "upload images: <a href=\"$url\">$name</a>";
                      	}
                      
                      	else {
                      		$output.='Gallery could not be created. Please enter a valid title!';
                      	}
                      
                      	}
                      	
                      	else {
                      	$output .= '<form method="post" action="'.$_SERVER['REQUEST_URI'].'">
                      			Gallery Title: <input type="text" name="title" value="'.$pce_ar_charts['title'].'"/>
                      			<input type="submit" name="save_doc" value="create" />
                      			</form>';
                      		}
                      
                      return $output;
                      ?>


                      you need to edit the Snippet code under "customize to fit your setup": content ( your snippet parameters) / template id etc. -> "&manager_webusers=`$webusername`" should stay in the MG call if you want to use that feature.

                      one thing i need to figure out is, how to set the Menu Index, since this is currently 0 for all new galleries ... any ideas, pointers smiley ?

                      -> call the Snippet like this: [!Snippetname? &parent=`yourparentid`!] if no value for parent is declared, it defaults to "0" and the gallery is created in the site root.

                      thanks, j