rename image-path makes problems for static pages

Found a bug? Tell us!!
Post Reply
stm999999999
Regular
Posts: 1531
Joined: Tue Mar 07, 2006 11:25 pm
Location: Berlin, Germany
Contact:

rename image-path makes problems for static pages

Post by stm999999999 »

hello,

there is a bitchy bug in the backend_media_rename part:

Moving a picture into another image-folder, all appearances in articles are changed in the database, so every article has imge-links to the new path.

serendipity_event_staticpage does the some for the appearances in static pages. BUT: Not only the path of the moved picture is changed in the database - ALL pathes for pictures in the same old-dir are changed (of course the pictures themselve are not moved), so in every static page there are wrong urls pointing to the new path of the one picture which should moved! :x :shock:

code problem:

the backend_media_rename part in the plugin does not know the name of the moved picture, only the path, so it changed them all

solution: :D

staticpage must differ between a renaming of a directory-name (type=dir) and the moving of one single picture (type=filedir)

serendipity_event_staticpage old line 2705:

Code: Select all

                case 'backend_media_rename':


                    // Only MySQL supported, since I don't know how to use REGEXPs differently.
                    if ($serendipity['dbType'] != 'mysql' && $serendipity['dbType'] != 'mysqli') {
                        echo STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRY . '<br />';
                        break;
                    }

                    if (!isset($eventData[0]['oldDir'])) {
                        return true;
                    }

                    $q = "SELECT id, content, pre_content
                            FROM {$serendipity['dbPrefix']}staticpages
                           WHERE content     REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
                              OR pre_content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
                    ";

                    $dirs = serendipity_db_query($q);
                    if (is_array($dirs)) {
                        foreach($dirs AS $dir) {

                            $dir['content']     = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['content']);
                            $dir['pre_content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['pre_content']);

                            $uq = "UPDATE {$serendipity['dbPrefix']}staticpages
                                                     SET content     = '" . serendipity_db_escape_string($dir['content']) . "' ,
                                                         pre_content = '" . serendipity_db_escape_string($dir['pre_content']) . "'
                                                   WHERE id       = " . serendipity_db_escape_string($dir['id']);
                            serendipity_db_query($uq);
                        }

                        printf(STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs));
                    }

                    break;
new:

Code: Select all

                case 'backend_media_rename':


                    // Only MySQL supported, since I don't know how to use REGEXPs differently.
                    if ($serendipity['dbType'] != 'mysql' && $serendipity['dbType'] != 'mysqli') {
                        echo STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRY . '<br />';
                        break;
                    }

                    if (!isset($eventData[0]['oldDir'])) {
                        return true;
                    }

					if ($eventData[0]['type'] == 'dir'){
					
                        $q = "SELECT id, content, pre_content
                                FROM {$serendipity['dbPrefix']}staticpages
                               WHERE content     REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
                                  OR pre_content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
                        ";

                        $dirs = serendipity_db_query($q);
                        if (is_array($dirs)) {
                            foreach($dirs AS $dir) {

                                $dir['content']     = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['content']);
                                $dir['pre_content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['pre_content']);

                                $uq = "UPDATE {$serendipity['dbPrefix']}staticpages
                                                         SET content     = '" . serendipity_db_escape_string($dir['content']) . "' ,
                                                             pre_content = '" . serendipity_db_escape_string($dir['pre_content']) . "'
                                                       WHERE id       = " . serendipity_db_escape_string($dir['id']);
                                serendipity_db_query($uq);
                            }

                            printf(STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs));
                            printf($eventData[0]['type']);
                        }
                        
                    }

					if ($eventData[0]['type'] == 'filedir'){
					
						 $eventData[0]['oldDir'] .= $eventData[0]['name'];
        			     $eventData[0]['newDir'] .= $eventData[0]['name'];
					
                        $q = "SELECT id, content, pre_content
                                FROM {$serendipity['dbPrefix']}staticpages
                               WHERE content     REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
                                  OR pre_content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
                        ";
						
					
                        $dirs = serendipity_db_query($q);
                        if (is_array($dirs)) {
                            foreach($dirs AS $dir) {

                                $dir['content']     = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['content']);
                                $dir['pre_content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['pre_content']);

                                $uq = "UPDATE {$serendipity['dbPrefix']}staticpages
                                                         SET content     = '" . serendipity_db_escape_string($dir['content']) . "' ,
                                                             pre_content = '" . serendipity_db_escape_string($dir['pre_content']) . "'
                                                       WHERE id       = " . serendipity_db_escape_string($dir['id']);
                                serendipity_db_query($uq);
                            }

                            printf(STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs));
                        }
                  
                                                                
                    }

and functions_images.inc.php must give the name of the picture:

line 3378:

Code: Select all

    } elseif ($type == 'filedir') {
        serendipity_db_query("UPDATE {$serendipity['dbPrefix']}images
                                 SET path = '" . serendipity_db_escape_string($newDir) . "'
                               WHERE id   = " . (int)$item_id);
        $pick = serendipity_db_query("SELECT * FROM  {$serendipity['dbPrefix']}images
                               WHERE id   = " . (int)$item_id, true, 'assoc');

        // Move thumbs
        $oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir . $pick['name'] . '.' . $pick['extension'];
        $newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir . $pick['name'] . '.' . $pick['extension'];

        $renameValues = array(array(
            'from'   => $oldfile,
            'to'     => $newfile,
            'thumb'  => $serendipity['thumbSuffix'],
            'fthumb' => $pick['thumbnail_name'],
            'oldDir' => $oldDir,
            'newDir' => $newDir,
            'type'   => $type,
            'item_id'=> $item_id,
            'file'   => $file,
            'name'	 => $pick['name']
        ));
the last assignment
Ciao, Stephan
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: rename image-path makes problems for static pages

Post by garvinhicking »

Hi!

Can you attach the two new files here so that I can commit them?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
stm999999999
Regular
Posts: 1531
Joined: Tue Mar 07, 2006 11:25 pm
Location: Berlin, Germany
Contact:

Re: rename image-path makes problems for static pages

Post by stm999999999 »

no problem,


but be aware the plugin version is up to date, but I am not using the newest core snapshot, but 1.4(.1?) - perhaps here it would be better just to add this single line by hand?

Code: Select all

'name'    => $pick['name']
for the plugin: I just make a little change today - the only real change for the issue here is the thing with the file-name, so I delete my yesterday made duplication of the whole rename-code and just do this here:

Code: Select all

					if ($eventData[0]['type'] == 'dir'){

					}

					elseif ($eventData[0]['type'] == 'filedir'){

						 $eventData[0]['oldDir'] .= $eventData[0]['name'];
        			     $eventData[0]['newDir'] .= $eventData[0]['name'];
                    }
Attachments
s9y.zip
(46.61 KiB) Downloaded 282 times
Ciao, Stephan
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: rename image-path makes problems for static pages

Post by garvinhicking »

Hi!

Thanks & committed! :) :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Ashley123
Posts: 1
Joined: Fri Jul 17, 2009 8:43 pm

Re: rename image-path makes problems for static pages

Post by Ashley123 »

Thanks stm.....
What Goth Quiz Character are you?
Post Reply