• Resolved jyd44

    (@jyd44)


    After a migration to Nextgen 2.0.66.27 from 2.0.66.17, galleries attached to a post using the green button in TinyMce are not correctly displayed, when WP is installed in its own directory, following the way described here: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

    The problem comes from the code in the file nextgen-gallery/products/photocrati_nextgen/modules/wordpress_routing/adapter.wordpress_router.php into the function get_base_url(). The case statements of the switch are incorrectly coded.

    Once the bug removed, plugin works as before the migration.

    https://wordpress.org/plugins/nextgen-gallery/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor photocrati

    (@photocrati)

    @jyd44 – We are not aware of this specific issue … can you share the specific changes you made?

    – Cais.

    Thread Starter jyd44

    (@jyd44)

    OK,
    just have a look to an abstract of the code:

    switch ($site_url) {
                case $site_url === TRUE:
                case 'site':
                    $retval = site_url();
                    break;
                case $site_url === FALSE:
                case 'home':
                    $retval = home_url();
                    break;
                case 'plugins':
                case 'plugin':
                    $retval = plugins_url();
                    $add_index_dot_php = FALSE;
                    break;
                 ......
                 ......
                 default:
                    $retval = site_url();
             }

    Looking to this code, we may expect that the goal of the developer was: “if $site_url is equal to FALSE the result should be home_url()”.
    Unfortunately, this will never happens. Why ? because if $site_url is set to FALSE, the case $site_url === FALSE will be evaluated as TRUE and so does not fit with the searched value. The switch statement will fall back to the default case, whose result is not the one expected.

    To overcome this issue, and if you want to follow the same structure, the switch statement need to be written like:

    switch (TRUE) {
                case $site_url === TRUE:
                case $site_url === 'site':
                    $retval = site_url();
                    break;
                case $site_url === FALSE:
                case $site_url === 'home':
                    $retval = home_url();
                    break;
                case $site_url === 'plugins':
                case $site_url === 'plugin':
                    $retval = plugins_url();
                    $add_index_dot_php = FALSE;
                    break;
                case $site_url === 'plugins_mu':
                case $site_url === 'plugin_mu':
                    $retval = WPMU_PLUGIN_URL;
                    $retval = set_url_scheme($retval);
                    $retval = apply_filters( 'plugins_url', $retval, '', '');
                    $add_index_dot_php = FALSE;
                    break;
                case $site_url === 'templates':
                case $site_url === 'template':
                case $site_url === 'themes':
                case $site_url === 'theme':
                    $retval = get_template_directory_uri();
                    $add_index_dot_php = FALSE;
                    break;
                case $site_url === 'styles':
                case $site_url === 'style':
                case $site_url === 'stylesheets':
                case $site_url === 'stylesheet':
                    $retval = get_stylesheet_directory_uri();
                    $add_index_dot_php = FALSE;
                    break;
                case $site_url === 'content':
                    $retval = content_url();
                    $add_index_dot_php = FALSE;
                    break;
                case $site_url === 'root':
                    $retval = get_option('home');
                    if (is_ssl())
                        $scheme = 'https';
                    else
                        $scheme = parse_url($retval, PHP_URL_SCHEME);
                    $retval = set_url_scheme($retval, $scheme);
                    break;
                case $site_url === 'gallery':
                case $site_url === 'galleries':
                    $root_type = defined('NGG_GALLERY_ROOT_TYPE') ? NGG_GALLERY_ROOT_TYPE : 'site';
                    $add_index_dot_php = FALSE;
                    if ($root_type === 'content')
                        $retval = content_url();
                    else
                        $retval = site_url();
                    break;
                default:
                    $retval = site_url();
            }

    Thread Starter jyd44

    (@jyd44)

    Sorry, I made a mistake in my explanations.
    If $site_url is set to FALSE, the switch statement will not end by the default case, but by the case case $site_url === TRUE: whose evaluation is FALSE => which is clearly not the expected result.

    Plugin Contributor photocrati

    (@photocrati)

    @jyd44 – Thanks for the detailed explanation! I will get this to the developers as soon as I can for them to review.

    – Cais.

    Thread Starter jyd44

    (@jyd44)

    @cais,
    version 2.0.66.29 solves the issue by another way, but the bug is still there, silent.
    jyd

    Plugin Contributor photocrati

    (@photocrati)

    @jyd44 – Please feel free to go into detail how the bug is still there … if you would care to elaborate or suggest a patch we would be happy to review this further.

    Thanks!

    – Cais.

    Thread Starter jyd44

    (@jyd44)

    OK Cais, I will try to be as clear as possible.
    Back to the version 2.0.66.27 (the one for which the first post of this thread was published). When you attach a gallery to a post using the green button in TinyMCE, the attached gallery is inserted in the body of the post as an image using the <img> tag, in which the href was set a value built from the “home” url of the hosting web site, to which is added the shortcode :nextgen-attach_to_post/preview/id–xxxx withh xxxx the id of a draft custom post describing the display options for the gallery (display_type, liste of images, etc..), url which is:
    1)used to give the opportunity to display at least the first image when viewving the post in the visual tab of the editor TinyMCE,
    2) used as a kind of shortcode to be replaced whenever the post is requested, thanks to the decoding function added to the wp filter “the_content”.

    What was causing the issue in version 2.0.66.7 ?: the fact that during the substitution process, at display time, a full url was searched into the post content (function substitute_placeholder_imgs in the file module.attach_to_post.php of the module attach_to_post). In this function, the scheme searched as a shortcode into the content was partly based on the result of the call to the function get_base_url(‘root’) in the file adapter.wordpress_router.php of the module wordpress_routing. Unfortunately, the url set into the post, at edition time, was partly based on the field ->object->context of the “router”, itself initialized by a call to the same function, but with the value “FALSE” as a parameter.

    Looking to the code of this function, and if we assume, based on this analysis, that the goal of the author of this function was to deliver the following results for the given value of the parameter: ‘true’ =>
    site_url(), ‘false’ => home_url(), ‘root’=> home_url() or something based on that, we can see that in fact, the result will be: ‘true’ => site_url(), ‘false’ => site_url(), ‘root’=> home_url() or something based on that.
    It’s clear that, as written in the function substitute_placeholder_imgs, the search pattern could not match.

    What did change in version 2.0.66.29 ? Only the fact that, instead of looking for the full url, in the function substitute_placeholder_imgs, the searched pattern is reduced to “nextgen-attach_to_post/preview/id–“, which works in every case and is certainly legitimate (I don’t discuss about that point).

    As such, the consequence of the bug in the function get_base_url() disappear, but not the bug itself, whose consequence may reappear at other places, whenever a developer will use it, relying on the spec of this function, or if anyone use the “router”->object->context still initialized at a wrong value.

    That the reason why I said that the issue described in the first post of this thread was solved, but the bug in the function get_base_url is still there. (and looking to other threads in this forum, I’m pretty sure that this bug has consequences in other parts of your code, but I do not want to make a full validation process).

    Hello,
    I think, I may have the same problem. Pressing the green button opens a page error 404.

    (The other thing: It’s possible to create a new gallery – but it’s not possible to upload pictures (0 images were uploaded). I have to use FTP, than it’s working.

    I did all the suggestions with permalinks and checking the other plugins.

    http://www.theaterzeppelin.de/

    May you have other suggestions, what I could do?

    thanks a lot

    Andrea

    Plugin Contributor photocrati

    (@photocrati)

    @jyd44 – Thank you very, very much! I do believe I understand what you were getting at with the bug is “silent” … in this particular case it is simply not being triggered but could be triggered elsewhere. I will have our developers re-review the get_base_url function for further ramifications.

    @agatha_org – It would be best for you to start a new topic so these two(?) issues are not mixed up and both potentially lost in the confusion. Also see http://codex.wordpress.org/Forum_Welcome#Where_To_Post

    Thanks!

    – Cais.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Gallery attach to post not working’ is closed to new replies.