Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Themes
Author Message
spasticdonkey
RavenNuke(tm) Development Team



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

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

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 Visit poster's website
montego
Site Admin



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

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

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.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
spasticdonkey







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

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! ]

I can probably think of more examples, but that's as far as I've been able to tweak thus far Smile
 
montego







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

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.
 
spasticdonkey







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

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
 
montego







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

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...
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Themes

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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©