Maybe I'm overlooking something, but I thought there was an option to convert underscores into spaces when they appear in album/photo title? If there isn't, can we have an option or just permanently make it so.
I think it would be easy to convert underscores to spaces. However, I don't think it's been updated to work with the current code. You'd have to either ask the author to update it or do it yourself.
thefatman
Joined: 2005-07-30
Posts: 24
Posted: Wed, 2005-08-03 01:55
Oh ok cool. Thanks. I'll just modify it for my own use. It might be a good example for me to figure out how to write simple modules. Hate learning new APIs...
Oh, btw, in that example you pasted, g2b4 seems to do that automatically. Has it been incorporated into the gallery or does the .jpg or whatever extension only get added if you use gallery remote or something?
nivekiam
Joined: 2002-12-10
Posts: 16503
Posted: Wed, 2005-08-03 02:00
Yeah it does look like they assign them to the base filename now. I forgot that sanitize module also strips out underscores.
I remember when I tried it back in May I was able to easily change it to do something else. I think it was to remove the titles all together.
thefatman
Joined: 2005-07-30
Posts: 24
Posted: Wed, 2005-08-03 02:19
It does strip out underscores? I imported bunch of dirs and all of them have underscore. My old gallery software converted underscores into spaces, so I had underscores everywhere. I imported all my galleries from the local harddrive on the server. Or did you mistype that?
I'm gonna just modify the original db to take out underscores. Actually is there something that explains the db schema? I guess it shouldn't be too hard to figure out.
nivekiam
Joined: 2002-12-10
Posts: 16503
Posted: Wed, 2005-08-03 02:37
I'm just talking strictly about the title of the photo, not the directories or the actual filename.
Your statement of "My old gallery software converted underscores into spaces, so I had underscores everywhere." doesn't make any sense. Did you end up with a bunch of spaces or a bunch of underscores?
You may want to ask the devs specifically about editing the DB. It's a very complex beast.
I guess I'm not following you, do you want to remove the underscore from the title or from the actual filename?
thefatman
Joined: 2005-07-30
Posts: 24
Posted: Wed, 2005-08-03 03:14
Hehe, sory, I meant I used underscores everywhere, because the old gallery would automatically convert the underscore into spaces before displaying them.
They stayed underscores in the original file/album name.
thefatman
Joined: 2005-07-30
Posts: 24
Posted: Wed, 2005-08-03 03:17
Sorry, I just want to display spaces instead of underscores... original filenames should stay with underscores. If the titles in the db get updated with spaces thats fine. Main thing is that they show up on the html with spaces, i.e. before it renders them to html, it removes the underscores.
nivekiam
Joined: 2002-12-10
Posts: 16503
Posted: Wed, 2005-08-03 04:13
So where do you want to get rid of the underscore, area 1 or area 2 or both of the attached image.
thefatman, there's a forum topic why we convert spaces to underscores, you might find it with the search function.
thefatman
Joined: 2005-07-30
Posts: 24
Posted: Wed, 2005-08-03 07:28
nivekiam: Hehe, I'll take option #2, Alex.
What I meant was that internally they be stored as underscores. just when the show up under albums icons, or titles for pictures etc., that they show up as spaces. I don't mind that internal title gets converted to space. original filename though, i'd rather have it with underscore, as I hate having spaces on my linux box.
thefatman
Joined: 2005-07-30
Posts: 24
Posted: Wed, 2005-08-03 07:36
Valiant: yeah, i don't mind that spaces are converted into underscores. I probably prefer it. I'm just talking about when it shows it as thumbnail name or photo title or whatever. I store things with underscores on the server.
Well I think i will just end up fixing all my photos/albums via the db. It would be too long and painful to use the gallery interface to edit. Or actually I can probably write a script... OR I can dump the whole db and then edit the text, and reimport it in. easier to script text files than dbs.
Anyway. I think i'm probably taking too much of both of your time... and confusing you both too.
valiant
Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-08-03 12:22
hmm, actually, it should replace the chars in the title with underscores. just in the filename and in the url.
thefatman
Joined: 2005-07-30
Posts: 24
Posted: Thu, 2005-08-04 01:01
Valiant: hehe, no, thats not what i'm talking about. That probably does fine.
I'm talking about files/directories that had underscores to begin with and when the gallery imports them into the system, it should first replace the underscores with space. And then it should search for invalid characters and replace them with underscores. It could be a toggleable option. But if people don't like that, then only when it renders the html, that it replace the underscores with spaces in title, etc.
Internally it should preserve underscores. and on the disk.
well I can just work on a module. Is there docs somewhre on writing modules? Well I would use the following url as an example:
But, I'm not sure if that in it self would work. By the way, I'm assuming the functionality of that above module was integrated into the gallery? (i.e. stripping the extension before putting it in the title field).
valiant
Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-08-04 10:00
thefatman, sorry, should have read the thread more carefully.
no, g2 doesn't replace underscores with spaces when adding items.
you'll have to adjust it such that it does what you want. then you can run site admin -> maintenance -> your task name.
g2 offers also another feature, you could write an itemAddOption (which would provide a checkbox like the create thumbnails when adding photos option).
anohman
Joined: 2005-09-17
Posts: 2
Posted: Sun, 2005-09-18 13:57
FYI:
I order to replace underscores with spaces in item titles on my G2 install, I added the following to the settitle($value) function in modules/core/classes/interfaces/GalleryItem.inc:
$value = str_replace('_', ' ', $value);
The whole function now looks like this:
/**
* Set the value of title
*
* @param STRING the value
*/
function settitle($value) {
/* Convert unset values to null, to avoid generating warnings. */
$value = isset($value) ? $value : null;
$value = $this->_truncateString($value, 128);
/* automatically replace uderscores with spaces in all titles */
$value = str_replace('_', ' ', $value);
$orig = isset($this->_title) ? $this->_title : null;
/* Only take action if the value actually changes */
if ($value != $orig) {
$this->setModifiedFlag('title', $value);
$this->_title = $value;
}
}
This only fixes new items, not items already containing uderscores. The same code in gettitle() would make the existing items have their underscores replaced with spaces too.
valiant
Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2005-09-18 14:02
cool that you found out how to make it work
while this certainly works, i'd do it as a site admin -> maintenance task. which is a) modular, so no editing of files needed but b) would require more code than a little hacking.
jmarvin
Joined: 2008-06-08
Posts: 4
Posted: Sun, 2008-06-08 19:31
Thanks to all you guys from many years ago! I was having the same issue with version 2.24 and here's what I came up with...
in /GALLERY/themes/THEME/templates/album.tpl around line #130~
copy paste to a text file then save as '.vbs'
paste in the folder you want to use it on and double click/ pop-up for complete will appear. no more spaces!
you can edit the script to use it on whichever conversions you like.
'========================================================
' VBScript to replace underscore in file name with space
' for each files in a folder
' Written by ApOgEE of http://coderstalk.blogspot.com
'========================================================
Dim sName
Dim fso
Dim fol
' create the filesystem object
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
' get current folder
Set fol = fso.GetFolder(".")
' go thru each files in the folder
For Each fil In fol.Files
' check if the file name contains underscore
If InStr(1, fil.Name, "_") <> 0 Then
' replace underscore with space
sName = Replace(fil.Name, "_", " ")
' rename the file
fil.Name = sName
End If
Next
' echo the job is completed
WScript.Echo "Completed!"
Posts: 16503
There was this routine to strip.jpg off , http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=29642&postdays=0&postorder=asc&start=15
I think it would be easy to convert underscores to spaces. However, I don't think it's been updated to work with the current code. You'd have to either ask the author to update it or do it yourself.
Posts: 24
Oh ok cool. Thanks. I'll just modify it for my own use. It might be a good example for me to figure out how to write simple modules. Hate learning new APIs...
Oh, btw, in that example you pasted, g2b4 seems to do that automatically. Has it been incorporated into the gallery or does the .jpg or whatever extension only get added if you use gallery remote or something?
Posts: 16503
Yeah it does look like they assign them to the base filename now. I forgot that sanitize module also strips out underscores.
I remember when I tried it back in May I was able to easily change it to do something else. I think it was to remove the titles all together.
Posts: 24
It does strip out underscores? I imported bunch of dirs and all of them have underscore. My old gallery software converted underscores into spaces, so I had underscores everywhere. I imported all my galleries from the local harddrive on the server. Or did you mistype that?
I'm gonna just modify the original db to take out underscores. Actually is there something that explains the db schema? I guess it shouldn't be too hard to figure out.
Posts: 16503
I'm just talking strictly about the title of the photo, not the directories or the actual filename.
Your statement of "My old gallery software converted underscores into spaces, so I had underscores everywhere." doesn't make any sense. Did you end up with a bunch of spaces or a bunch of underscores?
You may want to ask the devs specifically about editing the DB. It's a very complex beast.
I guess I'm not following you, do you want to remove the underscore from the title or from the actual filename?
Posts: 24
Hehe, sory, I meant I used underscores everywhere, because the old gallery would automatically convert the underscore into spaces before displaying them.
They stayed underscores in the original file/album name.
Posts: 24
Sorry, I just want to display spaces instead of underscores... original filenames should stay with underscores. If the titles in the db get updated with spaces thats fine. Main thing is that they show up on the html with spaces, i.e. before it renders them to html, it removes the underscores.
Posts: 16503
So where do you want to get rid of the underscore, area 1 or area 2 or both of the attached image.
Posts: 32509
thefatman, there's a forum topic why we convert spaces to underscores, you might find it with the search function.
Posts: 24
nivekiam: Hehe, I'll take option #2, Alex.
What I meant was that internally they be stored as underscores. just when the show up under albums icons, or titles for pictures etc., that they show up as spaces. I don't mind that internal title gets converted to space. original filename though, i'd rather have it with underscore, as I hate having spaces on my linux box.
Posts: 24
Valiant: yeah, i don't mind that spaces are converted into underscores. I probably prefer it. I'm just talking about when it shows it as thumbnail name or photo title or whatever. I store things with underscores on the server.
Well I think i will just end up fixing all my photos/albums via the db. It would be too long and painful to use the gallery interface to edit. Or actually I can probably write a script... OR I can dump the whole db and then edit the text, and reimport it in. easier to script text files than dbs.
Anyway. I think i'm probably taking too much of both of your time... and confusing you both too.
Posts: 32509
hmm, actually, it should replace the chars in the title with underscores. just in the filename and in the url.
Posts: 24
Valiant: hehe, no, thats not what i'm talking about. That probably does fine.
I'm talking about files/directories that had underscores to begin with and when the gallery imports them into the system, it should first replace the underscores with space. And then it should search for invalid characters and replace them with underscores. It could be a toggleable option. But if people don't like that, then only when it renders the html, that it replace the underscores with spaces in title, etc.
Internally it should preserve underscores. and on the disk.
well I can just work on a module. Is there docs somewhre on writing modules? Well I would use the following url as an example:
http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=29642&postdays=0&postorder=asc&start=0
But, I'm not sure if that in it self would work. By the way, I'm assuming the functionality of that above module was integrated into the gallery? (i.e. stripping the extension before putting it in the title field).
Posts: 32509
thefatman, sorry, should have read the thread more carefully.
no, g2 doesn't replace underscores with spaces when adding items.
nivekiam linked the right topic in his 1st reply in this thread, see:
http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=29642&postdays=0&postorder=asc&start=0
you'll have to adjust it such that it does what you want. then you can run site admin -> maintenance -> your task name.
g2 offers also another feature, you could write an itemAddOption (which would provide a checkbox like the create thumbnails when adding photos option).
Posts: 2
FYI:
I order to replace underscores with spaces in item titles on my G2 install, I added the following to the settitle($value) function in modules/core/classes/interfaces/GalleryItem.inc:
$value = str_replace('_', ' ', $value);The whole function now looks like this:
/** * Set the value of title * * @param STRING the value */ function settitle($value) { /* Convert unset values to null, to avoid generating warnings. */ $value = isset($value) ? $value : null; $value = $this->_truncateString($value, 128); /* automatically replace uderscores with spaces in all titles */ $value = str_replace('_', ' ', $value); $orig = isset($this->_title) ? $this->_title : null; /* Only take action if the value actually changes */ if ($value != $orig) { $this->setModifiedFlag('title', $value); $this->_title = $value; } }This only fixes new items, not items already containing uderscores. The same code in gettitle() would make the existing items have their underscores replaced with spaces too.
Posts: 32509
cool that you found out how to make it work
while this certainly works, i'd do it as a site admin -> maintenance task. which is a) modular, so no editing of files needed but b) would require more code than a little hacking.
Posts: 4
Thanks to all you guys from many years ago! I was having the same issue with version 2.24 and here's what I came up with...
in /GALLERY/themes/THEME/templates/album.tpl around line #130~
This does what I want and leaves all underscores as underscores, but DISPLAYS spaces instead.
Peace,
------------------------------
liquidpurple.com
Posts: 1
copy paste to a text file then save as '.vbs'
paste in the folder you want to use it on and double click/ pop-up for complete will appear. no more spaces!
you can edit the script to use it on whichever conversions you like.
found it here by ATOM he says it's ok to post it anywhere it can be of helphttp://coderstalk.blogspot.com/2007/09/vbscript-to-replace-underscores-in.html