We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3743
    • 42 Posts
    I badly need a way to add/edit some custom fields to every picture. Any suggestions how to do this? Hack-ish ways (if there’s no regular ones) are also appreciated (-;
      • 7923
      • 4,213 Posts
      Atleast I haven’t seen anything hacked for this yet.. Basicly you need to do the following things:

      1. add new fields to the maxigallery database table
      2. find "if($_REQUEST[’modified’.$i]==’yes’) {" from the maxigallery.php file and edit that block so that it updates also your new fields
      3. find "$managePictureTplData = array();" from the maxigallery.php file and edit that section so that your new fields are taken to the template data
      4. modify manage pictures templates so that there are fields to manage your new fields

      I guess that’s all.. let’s take another look into it when you have done those. Good luck! smiley

      EDIT: oh and you need to add stripslashes into various steps for your fields if you do addslashes in the 2nd step. Search the file for "stripslashes" to find the positions.


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 6726
        • 7,075 Posts
        I am currently trying to do this and I have a question regarding the first part : If I understand correctly, you made sure that if descvalid doesn’t exist, the description query is not run. Same for custpostvalid. When I create custom fields, would it be better to add a [tt]$mycustfieldvalid=0[/tt] them to the "Initialize variables" and set them to "0" ?

        Around line 225 e.g :

        //Initialize variables
        $mg->pics_tbl = $modx->db->config[’dbase’].".".$modx->db->config[’table_prefix’].$mg->mgconfig[’gtable’];
        $descvalid = 0; // assume descriptions not supported
        $custposvalid = 0; // assume that custom image ordering not supported
        $mycustfieldvalid=0 // assume that my custom field is not supported

        And then I would modify as instructed at step 2 :

        if($_REQUEST[’modified’.$i]==’yes’) {

        (.....)
        if($descvalid==1)
        $updateQueryString.=", descr=’".addslashes($_REQUEST[’descr’.$i])."’"; //MF add descr content
        if($custposvalid==1 && is_numeric($_REQUEST[’pos’.$i]))
        $updateQueryString.=", pos=".$_REQUEST[’pos’.$i]; //add pos value
        if($mycustfieldvalid==1)
        $updateQueryString.=", descr=’".addslashes($_REQUEST[’mycustfield’.$i])."’"; //add my custom field value

        (...)

        }

        Then I guess I would have to add to my call &mycustfieldvalid=`1` for it to be used

        Am I correct so far ?

        Thanks !

          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 6726
          • 7,075 Posts
          Here is what I did :

          Line 225 :

          //Initialize variables
          $mg->pics_tbl = $modx->db->config[’dbase’].".".$modx->db->config[’table_prefix’].$mg->mgconfig[’gtable’];
          $descvalid = 0; // assume descriptions not supported
          $custposvalid = 0; // assume that custom image ordering not supported
          $context_idvalid= 0; // partir du principe que le lien vers le contexte n’est pas supporté
          $filesizevalid= 0; // partir du principe que le poids du fichier n’est pas supporté

          Then around line 418 I added my fields

          // Ajout des champs customs pour soleil.info 
          if($context_idvalid==1)
          $updateQueryString.=", descr=’".addslashes($_REQUEST[’context_id’.$i])."’"; // Ajout du lien vers le contexte
          if($filesizevalid==1)
          $updateQueryString.=", descr=’".addslashes($_REQUEST[’filesize’.$i])."’"; // Ajout de la taille de fichier
          // Fin des modification pour l’ajout des champs custom

          Around line 580 :

          // Modification pour l’ajout du lien vers le contexte de l’image et du poids du fichier
          $pic[’context_id’] = stripslashes($pic[’context_id’]);
          $pic[’filesize’] = stripslashes($pic[’filesize’]);
          // Modification pour l’ajout du lien vers le contexte de l’image et du poids du fichier

          Of course then I had to edit managepicturetpl.html, and add the fields, since they are short fields (one is the ID of the document where the image can be seen "in context", the other the filesize manually added) :


          	<div class="shortfields">
          		ID: [+maxigallery.picture.id+]
          		<br />
          		[+maxigallery.strings.delete+]:
          		<input type="checkbox" name="[+maxigallery.fieldnames.delete+]" value="yes" title="[+maxigallery.strings.check_to_delete_this_picture+]"/>
          		<br />
          		[+maxigallery.strings.hide+]:
          		<input type="checkbox" name="[+maxigallery.fieldnames.hide+]" value="yes" title="[+maxigallery.strings.check_to_hide_this_picture+]" onClick="document.editform.[+maxigallery.fieldnames.modified+].value='yes'" [+maxigallery.picture.hide:is=`1`:then=`checked="checked"`+]/>
          		<br />
          		ID doc contexte <input type="text" size="4" name="[+maxigallery.fieldnames.context_id+]" id="[+maxigallery.fieldnames.context_id+]" onKeyDown="document.editform.[+maxigallery.fieldnames.modified+].value='yes'" value="[+maxigallery.picture.context_id+]"/><br />
          			<br />
          		Poids de l'image : <input type="text" size="8" name="[+maxigallery.fieldnames.filesize+]" id="[+maxigallery.fieldnames.filesize+]" onKeyDown="document.editform.[+maxigallery.fieldnames.modified+].value='yes'" value="[+maxigallery.picture.filesize+]"/><br />
          		
          		[+maxigallery.strings.position+]:
          		<input type="text" size="3" name="[+maxigallery.fieldnames.position+]" id="[+maxigallery.fieldnames.position+]" onKeyDown="document.editform.[+maxigallery.fieldnames.modified+].value='yes'" value="[+maxigallery.picture.pos+]"/>
          	</div>


          Then last but not least, I added the &context_idvalid=`1` &filesizevalid=`1`parameters, to make sure both fields would be used.

          I must have done something wrong, because when I submit the data, it’s not inserted in the DB.

          Maybe something to do with the way I created the fields in the DB ?
          Is there anything to be aware of ?

          Thanks !


            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 7923
            • 4,213 Posts
            Replace this:
            Quote from: davidm at Feb 18, 2008, 10:55 AM

            Then around line 418 I added my fields

            // Ajout des champs customs pour soleil.info 
            if($context_idvalid==1)
            $updateQueryString.=", descr=’".addslashes($_REQUEST[’context_id’.$i])."’"; // Ajout du lien vers le contexte
            if($filesizevalid==1)
            $updateQueryString.=", descr=’".addslashes($_REQUEST[’filesize’.$i])."’"; // Ajout de la taille de fichier
            // Fin des modification pour l’ajout des champs custom
            with:

            // Ajout des champs customs pour soleil.info 
            if($context_idvalid==1)
            $updateQueryString.=", context_id=’".addslashes($_REQUEST[’context_id’.$i])."’"; // Ajout du lien vers le contexte
            if($filesizevalid==1)
            $updateQueryString.=", filesize=’".addslashes($_REQUEST[’filesize’.$i])."’"; // Ajout de la taille de fichier
            // Fin des modification pour l’ajout des champs custom

            Also it’s not necessary to check that are the fields valid, because you have made the db table altering manually and know that the fields are there. The checks in MaxiGallery are because in first versions, there was only the title field. Later that fields were added, I made a check to see if the fields were in the database table and if they were not, I tried to create them. If the table altering would fail somehow, I had those variables to tell that description or picture position is not valid field and MaxiGallery wouldn’t then render those fields. But in your case when you know that you have those fields, you don’t have to do such checks.

            You also need to add your new field names to the fieldname array, so search this from maxigallery.php:


            $managePictureTplFieldNameData = array();

            Then add the following there:


            $managePictureTplFieldNameData[’context_id’] = ’context_id’.$i;
            $managePictureTplFieldNameData[’filesize’] = ’filesize’.$i;


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 6726
              • 7,075 Posts
              Thanks a lot Doze !

              I can’t believe I missed the remaining descr string embarrassed

              I think I’ll try to write this all down and make a tutorial for the wiki smiley

              Edit : I report that it’s working fine now !
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 7923
                • 4,213 Posts
                Quote from: davidm at Feb 18, 2008, 02:43 PM

                I think I’ll try to write this all down and make a tutorial for the wiki smiley
                That would be nice smiley


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                  • 6726
                  • 7,075 Posts
                  That’s the least I can do, you’ll have to oversee / edit for technical aspects though tongue

                  I don’t know if I’ll be able to do something with PHP one day, I don’t seem to click with it sad
                  Maybe when I have less work I’ll take a full month to really get into it ! Who knows...

                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 7923
                    • 4,213 Posts
                    The SVN version and upcoming release now has &customFields parameter to do this.


                      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                      • 6726
                      • 7,075 Posts
                      I’ll make sure to check this out !

                      I haven’t written a tuto yet embarrassed
                      But maybe it’s not needed anymore with this new parameter smiley
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l&#39;outil id