• Resolved Arno Welzel

    (@awelzel)


    I am the author of “Lightbox with Photoswipe” and recently got a support request because images served by mapped domains will be identified as “external” images.

    However this can cause issues in some cases, depending on the configuration of the webserver – also see https://www.ads-software.com/support/topic/bug-402/ and the proposed workaround which at least works in my local test environment.

    To make life easier for the users of our plugins I wonder if there is an API I could use in my plugin to determine the URL mapping and use that to make sure that even on mapped URLs images are properly detected as “local” images and not images coming from other websites.

    My idea:

    1. Check if a specific class or global variable exists as an indicator that your plugin is installed.
    2. If the plugin is installed use a specific API to get the list of mapped domains, so I can use them to identify images which are served using one of those domains but are originating from the main website – that way I can still retrieve meta data and attachement information properly.

    As a result, users of your plugin don’t have to manually deal with adding additional mappings as CDN urls to the plugin settings in “Lightbox with PhotoSwipe” and don’t wonder, why the images are either not displayed at all in Photoswipe or with missing captions or missing EXIF data.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Arno Welzel

    (@awelzel)

    I came up with another solution. Just let me know, if this is OK for you or if you plan to change the options structure at any time.

    The whole procedure can be disabled by an option in the backend settings, just in case this won’t work any longer with future updates of your plugin.

    First during initialization I will check if your plugin is active and if this is the case, I will use the mappings option, so I know if there any domains mappings defined:

    class LightboxPhotoSwipe
    {
        // ...
        private $domainMappings;
        // ...
    
        public function __construct($pluginFile)
        {
            // ...
            $this->domainMappings = false;
            if (is_plugin_active('multiple-domain-mapping-on-single-site/multidomainmapping.php')) {
                $this->domainMappings = get_option('falke_mdm_mappings');
            }
            // ...
        }

    The structure I identified for the settings is, that there is an array mappings which contains a set of three values for each domain. Therefore to check wether an image link may need to get fixed internally before working with it for getting image meta data etc., I will do the following:

    // $baseurlHttp contains the base URL of the
    // website - e.g. "https://my-site.example"
    
    if ($this->domainMappings !== false && is_array($this->domainMappings['mappings'])) {
        if (substr($file, 0, 7) === 'https://') {
             $fileSchemaPrefix = 'https://';
        } else {
             $fileSchemaPrefix = 'https://';
        }
        foreach ($this->domainMappings['mappings'] as $mapping) {
            if (isset($mapping['domain'])) {
                $mappingBaseUrl = $fileSchemaPrefix.$mapping['domain'];
                $length = strlen($mappingBaseUrl);
                if ($length>0 && substr($file, 0, $length) === $mappingBaseUrl) {
                    $file = $baseurlHttp.'/'.ltrim(substr($file, $length),'/');
                }
            }
        }
    }
    Plugin Author matthias.wagner

    (@matthiaswagner)

    hy arno,
    thanks for getting in touch ??

    it’s absolutely fine to use the mappings-option for that purpose. by now we do not have any plans for refacturing our code or options.

    best,
    matt

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘API for Support by other plugins (Lightbox with Photoswipe)’ is closed to new replies.