Forums | MacLife
You are not logged in.
#1 2005-04-09 5:11 pm
- jb
- Member
- From: Melbourne, Australia.
- Registered: 2004-01-04
- Posts: 2179
There has GOT to be an easier way
Code:
if(((strpos($loc, $first) !== false) AND ($realm == 1) AND ((!isset($page)) OR ($page == "index.php"))) OR ((strpos($loc, $first) !== false) AND (strpos($page, $second) !== false) AND ($realm == 2)) OR ((strpos($loc, $first) !== false) AND (strpos($query, $third) !== false) AND ($realm == 3))) {
echo " id=\"current\"";
}Can that be simplified?
It takes me about 5 minutes to get my head around every time I got to code with it, and I wrote it!
It actually does have a purpose - I used to use this instead:
Code:
if((strpos($loc, $first) !== false) AND ($realm == 1) AND ((!isset($page)) OR ($page == "index.php"))) {
echo " id=\"current\"";
} elseif ((strpos($loc, $first) !== false) AND (strpos($page, $second) !== false) AND ($realm == 2)) {
echo " id=\"current\"";
} elseif ((strpos($loc, $first) !== false) AND (strpos($query, $third) !== false) AND ($realm == 3)) {
echo " id=\"current\"";
}So - is there any simpler way to put the first chunk of code?
Or is that about as small as it can get?
I'm just thinking that there has to be a better way to do that.
Thanks,
jb
Last edited by jb (2005-04-09 5:37 pm)
They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.
Offline
#3 2005-04-09 5:37 pm
- jb
- Member
- From: Melbourne, Australia.
- Registered: 2004-01-04
- Posts: 2179
Re: There has GOT to be an easier way
What are sticky rollovers?
They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.
Offline
#5 2005-04-09 5:42 pm
- jb
- Member
- From: Melbourne, Australia.
- Registered: 2004-01-04
- Posts: 2179
Re: There has GOT to be an easier way
Well then - yes.
It just goes bold.
But yeah, that's right. (hence it echoing ' id=current')
They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.
Offline
#7 2005-04-09 5:47 pm
- jb
- Member
- From: Melbourne, Australia.
- Registered: 2004-01-04
- Posts: 2179
Re: There has GOT to be an easier way
How about I just post the function?
Code:
function active_page($first, $second, $third, $realm) {
$url = explode("/",$_SERVER['PHP_SELF']);
$loc = $url[1];
$page = $url[2];
$query = $_SERVER['QUERY_STRING'];
if(((strpos($loc, $first) !== false) AND ($realm == 1) AND ((!isset($page)) OR ($page == "index.php"))) OR ((strpos($loc, $first) !== false) AND (strpos($page, $second) !== false) AND ($realm == 2)) OR ((strpos($loc, $first) !== false) AND /*(strpos($page, $second) !== false) } AND */(strpos($query, $third) !== false) AND ($realm == 3))) {
echo " id=\"current\"";
}
}They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.
Offline
#8 2005-04-09 5:57 pm
Re: There has GOT to be an easier way
What I did with a site I made recently with tabs was:
Code:
foreach ($tabs as $name => $url) {
if ($name == $pagename) {
echo '<li id="current">';
} else {
echo '<li>';
}
echo "<a href='$url'>$name</a></li>";
}and that was that.
Offline
#9 2005-04-09 6:15 pm
Re: There has GOT to be an easier way
Ah, here is an example of how objects are cool and efficent.
I have an object called URLManager. It is called inside a config file that every page calls. Just by urlManager = new URLManager();
It handles everthing related to the url. Domain, page, passed vars and redirects.
So on any page the var $urlManager->page returns the page name. The function you have listed would appear to fail if you are in folders off the root.
Regardless, what I do for marking pages as active is just pass the page name as a key into a empty array. Like this:
Code:
$navState = array($urlManager->page => " id=\"current\"");
(that is actually in the config as well.)
Then in the nav:
Code:
<ul>
<li><a href="/home"<?=$navState['home']?>>Home</a></li>
<li><a href="/about"<?=$navState['about']?>>About</a></li>
<li><a href="/gallery"<?=$navState['gallery']?>>Gallery</a></li>
<li><a href="/contact"<?=$navState['contact']?>>Contact</a></li>
</ul>That's it. Simple and clean.
Offline
#10 2005-04-09 7:05 pm
Re: There has GOT to be an easier way
Yeah, this site was before I got into object-orientedness.
Offline
#11 2005-04-09 7:47 pm
- jb
- Member
- From: Melbourne, Australia.
- Registered: 2004-01-04
- Posts: 2179
Re: There has GOT to be an easier way
Yeah, that's cool, and I would do that (though I would probably just do the foreach thing with the array) if I didn't have to insert this in the middle -
Code:
$dir = "/Users/joel/htdocs/photos/albums/";
if(is_dir($dir)) {
if($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$mystring = $file;
$findme = ".";
$pos = strpos($mystring, $findme);
if($pos === false) {
echo "\t<li><a href=\"/photos/albums/$file/\"";
active_page("photos", null, $file, 3);
echo ">" . ucfirst($file) . "</a></li>\n\t\t\t";
}
}
closedir($dh);
}
}That makes it harder.
They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.
Offline
#13 2005-04-09 8:06 pm
- jb
- Member
- From: Melbourne, Australia.
- Registered: 2004-01-04
- Posts: 2179
Re: There has GOT to be an easier way
Hmmmm....
resists urge to scam of Scott, or at least, resists urge to attempt to scam off scott.
I like the concept. It's really easy. Especially if you run your server with a GUI. Just drag n' drop! And you have yourself a working photo gallery. 
Although I'm sure yours will totally own mine.
They say that the most secure computer is the one not connected to the internet.
That's why security experts recommend Telstra BigPond.
Offline
#14 2005-04-09 8:09 pm
Re: There has GOT to be an easier way
The reason I am doing it this way is to reduce stress on the database. I get crawled all the time by bots, and a gallery could represent quite a bit of uneeded db activity. And as you mentioned, it could be a breeze to manage.
Offline
#15 2005-04-09 8:42 pm
Re: There has GOT to be an easier way
Just recently rebuilt my gallery. I have the source code in my resources section. Be warned this is an extremely old version. I have since made it completely validate and its much faster with some more improvements I have made. I have not had the time however to post the new version. It is so much faster than the database driven one and as Scott said it takes stress of the db. I also believe having a gallery like this is easier on you to.
Mine works with a structure sort of like this.
you got a root directory for your gallery mine is called well gallery/
inside here is the main index file and an albums/ directory
each directory name that i throw in albums will be the name of the album when the directory is read. I replace all spaces with underscores for validation purposes in the URLs.
So inside each album directory you have an images directory as well as a thumbnails directory.
If I add 1.jpg as my image then the thumbnail has to have the same name which would be 1.jpg. In my next version I am giong to make it so the file extension in the name doesnt make a difference. So it could point to .gif and so on. I have big plans for it and the main thing I did was keep it lean.
I can see if I can post the newer version later this week but I have been sort of busy as of late.
However, again as Scott said its FAST. I also believe its more efficient as he said. It requires no backend to update you can do it through ftp. This also is one less thing for me to maintain.
At any rate for what I do I don't need to store huge descriptions and other information either.
One last thing I have a description.txt in each album directory that gets read when you click the album to view the images in it the description is on top. Its great!
Feature wise my gallery isn't that great. No page numbers or next and previous buttons. At least not yet and probably not for a long time. I only like to add things if I feel I need them. If i do it then it would be for those who would like to use my script which can be downloaded.
Last edited by Crontab (2005-04-09 9:07 pm)
Offline


