We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • So Jason (Opengeek) says that static resources don't recognize media sources. What would it take to hook them up? They're like chocolate and peanut butter, good separate but great together!
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
    • Don't quite understand the meaning of "static resources don't recognize media sources". Can you explain?

      I changed the basePath of Filesystem (default media source). Then I create new static resource, and it's conform with the basePath of media sources's Filesystem.

        zaenal.lokamaya
      • Oh, I see.... When I select the file and save the resource, only subfolder/filename.ext stored in Static Resource field without baseURL.
          zaenal.lokamaya
        • There is a system events called "OnMediaSourceGetProperties". This event invoked by modmediasource.class.php at line 409-418:

          409        /** @var array $results Allow manipulation of media source properties via event */
          410        $results = $this->xpdo->invokeEvent('OnMediaSourceGetProperties',array(
          411            'properties' => $this->xpdo->toJSON($properties),
          412        ));
          413        if (!empty($results)) {
          414            foreach ($results as $result) {
          415                $result = is_array($result) ? $result : $this->xpdo->fromJSON($result);
          416                $properties = array_merge($properties,$result);
          417            }
          418        }
          


          However if we create a new plugin with OnMediaSourceGetProperties activated, this will make all media browser error and unavailable to load files.

          I think this is a bug. And this bugs produced by modmediasource.class.php around line 415-416 (merging properties & result without checking the $result). Its should be:


          414            foreach ($results as $result) {
          415                $result = is_array($result) ? $result : $this->xpdo->fromJSON($result);
          416                if (is_array($result) && !empty($result)) $properties = array_merge($properties,$result);
          417            }
          


            zaenal.lokamaya
          • Back to the topic about static resources and media source: what would it take to hook them up?
              zaenal.lokamaya
            • Well, that's why I threw this topic open, hoping Jason or someone else more knowledgeable about it than I could at least give some insight into the issue.

              http://forums.modx.com/thread/80134/static-resource-won-t-download#dis-post-441695
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • Both static resource and media source are native features of MODx. I guess the best solution is modifying the core code and released it in the next version.

                Even with the help of a new plugin, this will not solve the whole problem. As I write in "Plugin: System Event Sequences" (http://forums.modx.com/thread/80538/plugin-system-events-sequences), the plugin did not affect Quick Update/Create resources hence the static resources can be created/updated by this way. [ed. note: lokamaya last edited this post 11 years, 6 months ago.]
                  zaenal.lokamaya
                • Since 2.2.1-pl, modResource has a new properties field that proposed to store json format data.

                  - Tracker: http://tracker.modx.com/issues/6651
                  - Github: https://github.com/modxcms/revolution/commit/111e54674fcd63d07d3fa61f29e7ef54059f3364

                  By chance, Media Source also use json to list files and folder. For example when OnMediaSourceGetProperties event system fired, it send $properties variable in following format:

                  {"basePath":{"name":"basePath","desc":"prop_file.basePath_desc","type":"textfield","options":"","value":"","lexicon":"core:source"},"basePathRelative":{"name":"basePathRelative","desc":"prop_file.basePathRelative_desc","type":"combo-boolean","options":"","value":true,"lexicon":"core:source"},"baseUrl":{"name":"baseUrl","desc":"prop_file.baseUrl_desc","type":"textfield","options":"","value":"","lexicon":"core:source"},"baseUrlRelative":{"name":"baseUrlRelative","desc":"prop_file.baseUrlRelative_desc","type":"combo-boolean","options":"","value":true,"lexicon":"core:source"},"allowedFileTypes":{"name":"allowedFileTypes","desc":"prop_file.allowedFileTypes_desc","type":"textfield","options":"","value":"","lexicon":"core:source"},"imageExtensions":{"name":"imageExtensions","desc":"prop_file.imageExtensions_desc","type":"textfield","value":"jpg,jpeg,png,gif","lexicon":"core:source"},"thumbnailType":{"name":"thumbnailType","desc":"prop_file.thumbnailType_desc","type":"list","options":[{"name":"PNG","value":"png"},{"name":"JPG","value":"jpg"},{"name":"GIF","value":"gif"}],"value":"png","lexicon":"core:source"},"thumbnailQuality":{"name":"thumbnailQuality","desc":"prop_s3.thumbnailQuality_desc","type":"textfield","options":"","value":90,"lexicon":"core:source"},"skipFiles":{"name":"skipFiles","desc":"prop_file.skipFiles_desc","type":"textfield","options":"","value":".svn,.git,_notes,nbproject,.idea,.DS_Store","lexicon":"core:source"}} 
                  


                  So why not copying modMediaSource properties to modResource properties? Here the hacking step:

                  Backend Manager

                  • check if/else: modStaticResource
                  • modMediaSource fired:
                    - if resource properties not empty: set default media-source properties
                    - if media source changed: get media-source properties
                  • modStaticResource saved:
                    - resource content (static resource) = file
                    - resource properties = media-source properties (in JSON format)
                    - save!

                  Frontend Client

                  • check if/else: modStaticResource
                  • get resource properties if any
                    - if basePath not empty && basePathRelative is true: file = modxpath/basePath/file
                    - elseif basePath not empty && basePathRelative is false: file = basePath/file
                    - else: file = modxpath/file
                  • get the file

                  So I think it's should be more easier to modify the core code rather than creating a new addon/plugin. Is it right Jason (Opengeek)? [ed. note: lokamaya last edited this post 11 years, 6 months ago.]
                    zaenal.lokamaya
                  • Instead of get the properties, the better option is to get MediaSource ID and save it in modStaticResource properties. So if the MediaSource properties changed then the modStaticResource properties would follow this change.

                    Example:
                    {"mediaSourceID":"1"}


                    The refactoring step:

                    Backend Manager

                    • check if/else: modStaticResource
                    • get MediaSource ID from modStaticResource properties (if any)
                      - mediaSourceID > 0: get MediaSource properties
                    • modMediaSource fired:
                      - if modStaticResource MediaSource properties not empty: set default modMediaSource properties
                      - if modMediaSource ID changed: get MediaSource ID
                    • modStaticResource saved:
                      - resource content (static resource) = file
                      - resource properties = {"mediaSourceID":"n"} (where n: MediaSource ID)
                      - save!

                    Frontend Client

                    • check if/else: modStaticResource
                    • get MediaSource ID from modStaticResource properties (if any)
                      - mediaSourceID > 0: get MediaSource properties
                      - if basePath not empty && basePathRelative is true: file = modxpath/basePath/file
                      - elseif basePath not empty && basePathRelative is false: file = basePath/file
                      - else: file = modxpath/file
                    • get the file
                      zaenal.lokamaya
                    • I submited this 'refactor' to tracker http://tracker.modx.com/issues/9153
                        zaenal.lokamaya