A little PHP help please (McJiffy Easy)

guerilla

All we do is win
Aug 18, 2007
11,426
428
0
No
I need to alter some PHP code in McJiffy Easy.

Pages are pulled by keyword. If a text file with the keyword name is in a subdirectory, it adds that text to the page.

So if I have

hxxp://mysite.com/buy/donkey+punches

And I have have a text file, donkey+punches.txt in the text subdirectory, it will add that text to the page.

If no text file exists, nothing will be added.

I want to change the code, so that if a text file with the keyword name DOES NOT exist, it pulls a default text file and inserts that.

Code:
<?php if (!empty($keywordtext)) {
    echo '<div class="keywordtext">' . $keywordtext. '</div>';

} ?>

I'm thinking I will need to either include another text file, or I could echo text from a variable set in the config.

But where I am stuck is the conditional, I know some smarty, but not php.

Can I use an else?

Help pls? :D
 


I don't think so.

I want the existing functionality, so

if !emptykeywordstuff = keyword stuff
????else???
other stuff

I just need the PHP for the conditional, I think I can figure out the rest.
 
Change this
Code:
// look for text file for this keyword
if (empty($site["textdirectory"])) {
	$site["textdirectory"] = "text";
}
if (file_exists(ROOT_DIR.$site["textdirectory"].'/'.urlencode($q).'.txt')) {
	$keywordtext = file_get_contents(ROOT_DIR.$site["textdirectory"].'/'.urlencode($q).'.txt');
}
else {
	$keywordtext = null;
}

To this
Code:
// look for text file for this keyword
if (empty($site["textdirectory"])) {
	$site["textdirectory"] = "text";
}
if (file_exists(ROOT_DIR.$site["textdirectory"].'/'.urlencode($q).'.txt')) {
	$keywordtext = file_get_contents(ROOT_DIR.$site["textdirectory"].'/'.urlencode($q).'.txt');
}
else {
	$keywordtext = file_get_contents(ROOT_DIR.$site["textdirectory"].'/default.txt');
}

and place a file called "default.txt", with whatever default text you want displayed, in the directory with the other keyword files.
 
  • Like
Reactions: guerilla
Wow, change the function. Much spiffier. Thanks. Another name on my rep list. Thank you!