PHP Web Host - Quality Web Hosting For All PHP Applications $35/month $250/year (Unlimited) - $25/month - 200,000 impressions - Your Ad Could be Here - Click For Details
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
spasticdonkey
RavenNuke(tm) Development Team


Joined: Dec 02, 2006
Posts: 1364
Location: Texas, USA

PostPosted: Sun Jan 23, 2011 5:47 am Reply with quote Back to top

Working on a new theme and looking to convert the block title to a CSS ID.. This is working but I thought I would throw it out there if anyone has ideas for improvements; or a situation where it might fail to produce a valid id.

Code:
function TitleToID($title) {
   if (!empty($title)){
   $BlockID = trim(str_replace(array('"', '&', '?', '.', '\''), '', $title));
   $BlockID = strtolower($BlockID);
   $BlockID = preg_replace('/[^a-z0-9_\-\.]/i', '-', $BlockID);
   $BlockID = preg_replace('/[-]{2,}/', '-', $BlockID);
   $BlockID = trim($BlockID, '-');
   return $BlockID;
   }else{
   static $notitle;
   if (isset($notitle)){$notitle++;}else{$notitle=1;}
   $BlockID = 'notitle'.$notitle;
   return $BlockID;
   }
}


basically what this does is if the title is not empty, it strips out some unwanted characters, converts to lowercase, replaces invalid characters with hyphens, replaces multiple hyphens with a single hyphen, and trims hyphens from beginning and end of the string. If the title is empty it will generate notitle1, notitle2, etc; to ensure even untitled blocks receive a unique id.
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Sat Jan 29, 2011 9:22 pm Reply with quote Back to top

I am actually curious as to why you would want a unique id on each block? If you are doing this for a jQuery implementation you may still be able to accomplish what you are after by using class names instead, even if you never reference them in your CSS.
View user's profile Send private message Visit poster's website
spasticdonkey
RavenNuke(tm) Development Team


Joined: Dec 02, 2006
Posts: 1364
Location: Texas, USA

PostPosted: Sat Jan 29, 2011 10:50 pm Reply with quote Back to top

Yes this would be for jQuery or styling targeted toward a specific block.. and I agree most times a class would do the job. Working with a few features that require a specific ID, like a block that does not display if JS is disabled, or hiding a block that can then be opened in a modal window inline, or a bottom-side block that has the cool "fixed-floating" effect:
Only registered users can see links on this board!
Get registered or login to the forums!


I can probably think of more examples, but that's as far as I've been able to tweak thus far Smile
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Tue Feb 01, 2011 8:37 pm Reply with quote Back to top

Ok, so you definitely need control over the entire block and not just the content. Makes sense.

I suppose you could do it this way. You could also used the "bid" field in the table as you know with 100% certainty that it is unique, just need a consistent suffix in front that starts with a letter instead of a number, like "block" followed by the ID, so like "block5".

My thinking here is that you can then change the block title to anything you want at any point in time and the CSS reference wouldn't change. It is always unique. Even if you use the titles, if you want to change a title, you have to tweak your CSS, so not much added value in the descriptive id names. In addition, if you end up having some kind of configuration page, you'll be reading the nuke_blocks table anyways to get both bid and title.

Just some thoughts since you asked. Of course, in the end, you need to do what makes the most sense to you.
View user's profile Send private message Visit poster's website
spasticdonkey
RavenNuke(tm) Development Team


Joined: Dec 02, 2006
Posts: 1364
Location: Texas, USA

PostPosted: Tue Feb 01, 2011 9:05 pm Reply with quote Back to top

montego wrote:
Ok, so you definitely need control over the entire block and not just the content. Makes sense.

I suppose you could do it this way. You could also used the "bid" field in the table as you know with 100% certainty that it is unique, just need a consistent suffix in front that starts with a letter instead of a number, like "block" followed by the ID, so like "block5".

My thinking here is that you can then change the block title to anything you want at any point in time and the CSS reference wouldn't change. It is always unique. Even if you use the titles, if you want to change a title, you have to tweak your CSS, so not much added value in the descriptive id names. In addition, if you end up having some kind of configuration page, you'll be reading the nuke_blocks table anyways to get both bid and title.

Just some thoughts since you asked. Of course, in the end, you need to do what makes the most sense to you.


thanks for the input Smile
I had similar thoughts originally, as building the ID from the title is not the optimum solution. But I was pretty much working with what was available in the default themesidebox($title, $content) function. It didn't seem very efficient to query the blocks table every time that function is called, so I figured I would deal with the title. I also learned that some modules call themesidebox so in those cases there would be no block id.

In a perfect world I suppose it would be
themesidebox($title, $content, $id)
but whatcha gonna do? Smile
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Wed Feb 02, 2011 4:15 am Reply with quote Back to top

There you go again confusing the issue with facts. killing me Didn't even realize that. Embarassed Smile So there you go, what he said...
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum