-
Posts
95 -
Joined
-
Last visited
Never
Everything posted by Mouse
-
Ok so i have been playing with my site for a while and getting there very slowly... but heres the rub i am DYSLEXIC and am having issues following a tutorial and the code therein... the tutorial / code is over at http://www.scriptplayground.com/tutorials/php/Tag-Cloud/ and where i am at is [code] <html> <head> <style type="text/css"> .tag_cloud { padding: 3px; text-decoration: none; } .tag_cloud:link { color: #81d601; } .tag_cloud:visited { color: #019c05; } .tag_cloud:hover { color: #ffffff; background: #69da03; } .tag_cloud:active { color: #ffffff; background: #ACFC65; } </style> </head> <body> <?php function get_tag_data() { $host = "localhost"; $dbname = "###"; $dbuser = "###"; $dbpass = "###"; $connection = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); $db = mysql_select_db($dbname) or die(mysql_error()); $result = mysql_query("SELECT uid ,firstname ,lastname FROM user ORDER BY uid DESC limit 20"); while($row = mysql_fetch_array($result)) { $arr[$row['firstname, lastname']] = $row['count']; } ksort($arr); return $arr; } function get_tag_cloud() { $min_font_size = 100%; $max_font_size = 250$; $tags = get_tag_data(); $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); $spread = $maximum_count - $minimum_count; if($spread == 0) { $spread = 1; } $cloud_html = ''; $cloud_tags = array(); // create an array to hold tag code foreach ($tags as $tag => $count) { $size = $min_font_size + ($count - $minimum_count) * ($max_font_size - $min_font_size) / $spread; $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="http://www.mouse.nodstrum.com/full_profile?u$uid . '" title="\'' . $firstname $lastname . '\' profile">' . htmlspecialchars(stripslashes($tag)) . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; ?> //Here is some example HTML to call this tag builder. <h3>Sample Tag Cloud results</h3> <div id="wrapper" <!-- BEGIN Tag Cloud --> <?php print get_tag_cloud(); ?> <!-- END Tag Cloud --> </div> </body> </html> [/code] okay, so it is only likely to be a missing ; or me mixing $uid and $did <b>BUT</b> if anyone can help i would be most appreciative many thanks Mouse
-
[SOLVED] My first SQL trial... but where am i going wrong?
Mouse replied to Mouse's topic in PHP Coding Help
getting the error:- Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource for the following code:- $row = mysql_fetch_assoc($max); -
My first SQL trial... but where am i going wrong? [Code] <?php // connect to database $host = "localhost"; $dbname = "###"; $dbuser = "###"; $dbpass = "###"; $connection = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); $db = mysql_select_db($dbname) or die(mysql_error()); // Bah Humbug! i will have this work!!! $max = mysql_query("SELECT MAX(uid) FROM user") or die ("nope. Didn't work...!"); echo $max; ?> [/Code] Ok so this is my first SQL trial... but where am i going wrong? i get the message "Resource id #3" where i was expecting to see "14"
-
I have a problem, which I am sure is easy enough to work out but hey, if only my PHP skills were better! Problem. Have a look at my member profile page [http://mouse.nodstrum.com/full_profile.php?u=11], in the top right hand corner is the “Tim’s Time With Disney” box… I want to add the content dynamically. In the Database there are six relevant tables, A, B, C, D, E, and F and each of them has the following contents: [code] # Dump of table A `did` int(9) NOT NULL auto_increment, `uid` int(9) NOT NULL default '0', `start` int(4) NOT NULL default '0', `finish` int(4) NOT NULL default '0', `Job1` int(1) NOT NULL default '0', `Job2` int(1) NOT NULL default '0', `Job3` int(1) NOT NULL default '0', `Job4` int(1) NOT NULL default '0', `Job5` int(1) NOT NULL default '0', PRIMARY KEY (`did`) ) TYPE=MyISAM; [/code] What I (think I) am aiming to do is roughly… Look in table a >> are there values in ‘Start’ and ‘finish’ >> if so, then put in the right logo >> on the next line echo $start & $finish >> list the ‘jobs’ where there is a ‘1’ not a ‘0’ >> move on to the next table and repeat. If a PHP guru type could give me a pointer or two I’ll go on to do the rest. As I have said before, I hate asking for code, but as a dyslexic learning to write new stuff is a bugger and I need a few pointers. Many thanks Mouse
-
[quote author=redarrow link=topic=112850.msg458457#msg458457 date=1161932807] mouse you sure that the .js file your using issint gone dead i think a re install ha. [/quote]Works for me...
-
thinking about it, now that i am at work and away from my PHP machine would [code] <?php echo strrev (txet yM); ?> work in the JavaScript/CSS tag??? [/code] Mouse
-
[quote author=mjdamato link=topic=112850.msg458319#msg458319 date=1161903613] I think you need to find another approach. Perhaps serializing the value? [/quote] so what were you thinking? i didn't get what you meant...
-
Oh well seemed like such a good idea... at the time! many thanks Mouse
-
I have been using a language filter to add tooltips (informative mousovers) to my site but I had an issue with the filter finding keywords within the added mousover script… erm… a little clearer? Well if I used “Duck” as a keyword and then I put the phrase “Donald Duck” into the mouesover explanation the function died so I tried this… I reversed all the content with [code] <?php $outputtext = strrev($inputtext); echo $outputtext ?> [/code] So “Donald ‘Fauntleroy’ Duck He usually wears a sailor shirt and cap — but no pants (except when he goes swimming). Although usually easygoing, Donald's most famous trait is his short and often explosive temper. Donald's famous voice, and semi-intelligible is one of the most identifiable voices in the world” Became “dlrow eht ni seciov elbaifitnedi tsom eht fo eno si elbigilletni-imes dna ,eciov suomaf sdlanoD .repmet evisolpxe netfo dna trohs sih si tiart suomaf tsom sdlanoD ,gniogysae yllausu hguohtlA .)gnimmiws seog eh nehw tpecxe( stnap on tub — pac dna trihs rolias a sraew yllausu eH kcuD yoreltnuaF dlanoD” then I used a little CSS to put it right again… [code] .backwards {unicode-bidi:bidi-override; direction: rtl;} [/code] Well I thought so… but have a look for yourself what happens… http://mouse.nodstrum.com/backwards.php Any ideas??? Please Mouse
-
another unknown function... many thanks...
-
Hello… quick question, I need to know how to build a simple form that I put text into and it will spit it out reversed… i.e. I put in “Hello!” It will return “!olleH” any answers? Mouse
-
Better rude word filter... when they change le++er5 for characters
Mouse replied to Mouse's topic in PHP Coding Help
sorry i meant in the scripts pages... my bad for not explaining too well Mouse -
Better rude word filter... when they change le++er5 for characters
Mouse replied to Mouse's topic in PHP Coding Help
Shoz, thank you very much for all your assistance on the bad word filter. It is much appreciated! I think you’re on to a good thing with the switchable filter, It’ll preserve personal expression and peoples sensibilities. So yes… and the false positives would become a null issue. For my part I have been working on the bad words array/list. (I don’t have php on my works laptop.) I was also thinking that as a combined project it should be posted on the site for use by all… what would you say? Again, many thanks Mouse -
Better rude word filter... when they change le++er5 for characters
Mouse replied to Mouse's topic in PHP Coding Help
gentlemen this is going far further than i though... many thanks, i'll work on it when i get to my home pc... many thanks Mouse -
Better rude word filter... when they change le++er5 for characters
Mouse replied to Mouse's topic in PHP Coding Help
ok, what if we went for take each word, explode it, if first character is a letter then this is a word carry on filtering if you find a space then go to next group if you find a number before you find a space treat as bad_word if first character is a number then this is a number group carry on filtering if you find a space then go to next group if you find a letter before you find a space treat as bad_word ok, your stuffed if you're telling the world about your love of U2, otherwise you should be ok... what do you think? Mouse -
I am using a simple but effective “bad word” filter on my site – Bad_word Filter code: Code: [code] $bad_words = explode('|', 'badword1|badword2|badword3|etc|etc'); foreach ($bad_words as $naughty) { $comments = eregi_replace($naughty, "#!@%*#", $comments); } [/code] but as always when you solve one little problem you come up with another, those pesky kids and their rude #!@%*# words. As I’ve added words to the filter they are replaced with other words where one or more characters have been replace with symbols or digits. i.e. in the word ‘*****’, [sorry for any offence to Meredith Brooks fans, or anybody else for that matter] this is easily be filtered on its own using a list, but the same word spelt w1tch, wi+ch etc. could be equally offensive. Any ideas? (Short of trying to work out every connotation of every word) Mouse [b]MOD EDIT(shoz): edited for language[/b]
-
[already posted in third party scripts] I hope someone out there may be able to help me out here. I have been trying to pull a few feeds into my page from Blogger and a couple of other sources with mixed success. I have to date been using Aaron Dunlaps script RSS_Get [http://www.aarondunlap.com/?content=rss_get] and if you look to the bottom right of my page [http://mouse.nodstrum.com/blog_links.php] you’ll see that under the heading of ‘The After the Mouse blog’ the feed from Aaron’s blog comes through just fine but all the others are, well useless! And that’s because they’re Atom feeds from Blogger… I will admit I know zip about the workings of XML weather its Atom or RSS so can anyone tell me where I need to make alterations to the code to make it Atom friendly RSS_Get code [code] <?php #========================== # The following line declares how long to wait before reloading the RSS feed. # Keep in mind, many sites discourage people from pulling its feed more often than 30 minutes. # For example, Slashdot.org may ban your server if it tries to load the rss feed too often. # You may change the below line. #========================== $minutes = 30; //How often to update the image. 0 indicates that image updates every time it is called (heavy strain on bandwidth & server) #========================== # The next line is what directory to dump the htm files generated by this script. # It should be relative to the location of this script, and it *MUST* have a trailing slash if it's a seperate dir. # If you want the files to be dumped in the same dir as this script, set it to "" # You may change the next line #========================== $filename = "rss/"; #========================== # The next 4 lines are default settings for the script to use, if they are not set prior to including this script # You may change the next 4 lines. #========================== $default_url = "http://www.aarondunlap.com/rss.php?mode=hl"; //URL for the RSS/XML feed you're subscribing to. $default_displayname = "|| aarondunlap.com ||"; //Title to appear before headlines. Should be feed-specific $default_number = 5; //How many headlines to display. If you set it higher than the ammount of headlines, it will stop there $default_target = "_self"; //Target for headline links. Options: "_self" and "_blank" #========================== # The next line is whether or not the script should auto-update. # If enabled, the script will check to see if a newer version of this script is available and will # automatically download and install it. Your current version of the script will be backed up in your $filename # directory. # If you have manually edited this script, you should disable this. Otherwise, it is recomended that you enable it. # Also note, your customized settings (default_url, default_displayname, filename, etc) WILL be kept during # auto-updates. Alterations to the actual function code (beneath) would be overwritten in an update. # During updates, your existing script is backed up into the $filename directory as "backup_[date]_(time).php" # You may change the next line #========================== $autoupdate = TRUE; #========================== # The settings below are for advanced headline truncation. # $default_trunc is how many characters to cut off at, # the default is FALSE, which wont truncate # at all. # You may use $trunc when calling this script # to define the truncation for specific feeds # $default_delim is what character to cut off the headline at # for example, if your headlines contain useless # data at the end, like "(via Reuters)", setting # the delimiter to "(" will stop that from showing. # You may use $delim when calling this script # to define the truncation for specific feeds #=========================== $default_trunc = FALSE; $default_delim = FALSE; #XXXXXXXXXXXXXXXXXXXXXXXXXX # Everything below is functional code. # You should not change it unless you know what you're doing, # and even if you do know what you're doing, are you sure you're # awake enough to do it? Maybe take a nap, rethink things, try again. #XXXXXXXXXXXXXXXXXXXXXXXXXX $version = 1.481; //If these variables aren't declared already, use defaults. if (!isset($url)) { $url = $default_url; } if (!isset($displayname)) { $displayname = $default_displayname; } if (!isset($number)) { $number = $default_number; } if (!isset($target)) { $target = $default_target; } if (!isset($trunc)) { $trunc = $default_trunc; } if (!isset($delim)) { $delim = $default_delim; } //In-URL definitions. Cannot be used for including, but it works great for testing. if (isset($_GET['url'])) { $url = $_GET['url'];} if (isset($_GET['number'])) { $number = $_GET['number'];} if (isset($_GET['displayname'])) { $displayname = $_GET['displayname'];} if (isset($_GET['rssHeadline'])) { $rssHeadline = $_GET['rssHeadline'];} $basefile = $filename; $versionfile = $filename."updatelog.htm"; //File for update attempt log $filename .= md5($url).".htm"; //Prepare filename for htm output #========================== # Script updating. Checks to see if an update attempt has been made in 24 hours, then goes ahead. #========================== if (((is_file($versionfile)) && (((time()-filemtime($versionfile)) >= (24 * 60 * 60))) || (!is_file($versionfile))) && ($autoupdate == TRUE)) { $out = ""; //If updatelog.htm is too big, clear it out. if (filesize($versionfile) > 102400) { unlink($versionfile); $out .= "<i>[".date("m/d/y H:i:s")."]</i> <b>Cleared update log because it was too big (>100kB)</b><hr>"; } $fd = fopen ($versionfile , "a+"); $out .= "<i>[".date("m/d/y H:i:s")."]</i> Attempting to acquire latest version number: "; fwrite ($fd , $out); require 'http://www.aarondunlap.com/code/rss_get_version.php'; if ((isset($latestversion)) && (isset($versionURL))) { $out = "<b>Acquired!</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Comparing version numbers: "; fwrite ($fd , $out); if ($version < $latestversion) { $out = "<b>Your version ($version) is out-of-date. Updating to version $latestversion.</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Loading updated script: "; fwrite ($fd , $out); //Reads the new file from my server if (@$newversfile = fopen($versionURL,"r")) { while (!feof($newversfile)) { $newvers .= fgets($newversfile); } //Transfers currently existing settings onto the update. $newvers = str_replace("http://www.aarondunlap.com/rss.php?mode=hl",$default_url,$newvers); $newvers = str_replace("|| aarondunlap.com ||",$default_displayname,$newvers); $newvers = str_replace('$default_number = 5;','$default_number = '.$default_number.';',$newvers); $newvers = str_replace('$autoupdate = TRUE;','$autoupdate = '.$autoupdate.';',$newvers); $newvers = str_replace('$filename = "rss/";','$filename = "'.$basefile.'";',$newvers); $newvers = str_replace('$minutes = 30;','$minutes = '.$minutes.';',$newvers); $newvers = str_replace('$default_target = "_self";','$default_target = '.$default_target.';',$newvers); $out = "<b>Opened</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Checking write-access in directory: "; fwrite ($fd , $out); //Checks to make sure we can write in this directory if (is_writable(getcwd())) { $out = "<b>Writable!</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Writing new version to temporary file: "; fwrite ($fd , $out); $outfile = fopen("rss_get_temp.txt","w+"); fwrite($outfile, $newvers); fclose($outfile); $out = "<b>Written.</b><br>\n<i>[".date("m/d/y H:i:s")."]</i> Backing up outdated file in $basefile directory:"; fwrite ($fd , $out); //Backs up the current script (this one) into the rss folder if (!copy("rss_get.php",$basefile."backup_".date("m-d-y_(H.i)").".php")) { $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } else { $out = "<b>Moved.</b><br>\n<i>[".date("m/d/y H:i:s")."]</i> Replacing script with new version:"; fwrite ($fd , $out); //Renames the temp file as this file, effectively replacing it. if (@!rename("rss_get_temp.txt","rss_get.php")) { /*Dude, look at these if blocks!*/ $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } else { chmod("rss_get.php",774); $out = "<b>Replaced</b><br>\n<i>[".date("m/d/y H:i:s")."]</i><b> RSS_GET updating complete. </b>\n<br><i>[".date("m/d/y H:i:s")."]</i><b>Version note from author:</b>".$message."<hr>\n"; fwrite ($fd , $out); fclose($fd); } } } else { $out = "<b>Not Writable.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } } else { $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } } else { $out = "<b>Your version is current</b><hr>\n"; fwrite ($fd , $out); } } else { $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } } // That's a lot of elses! Alright, we're done with the update thing. #========================== # Check the modify time of the htm file for this feed, and see if it's too new to reload the feed. # If the file is too new, it loads the htm file. This stops the script from constantly pulling the feed. #========================== if (($minutes > 0) && (is_file($filename)) && (((time()-filemtime($filename)) < ($minutes * 60)))) { include $filename; $time = floor((time()-filemtime($filename)) / 60); //See how many "minutes ago" the file was made. echo "<br><i><span class=\"updated\">Updated $time minutes ago.</span></i>"; //Include "minutes ago" after output. } elseif (@fopen($url,"r")) { //Makes sure the file can actually be accessed. #========================== # If we're down here, it means that the feed needs to be reloaded. #========================== $rssHandle = fopen($url,"r") ; // Open the rss file for reading while (!feof($rssHandle)) { $rssData .= fgets($rssHandle); } #========================== # Feed parsing #========================== $tag = "item "; $rssData = preg_replace("/<" . $tag . "(.|\s)*?>/","<item>",$rssData); $rssData = chop($rssData); // Strip any whitespace from the end of the string $rssData = ereg_replace("[\r,\n]", "", $rssData); //Clear line breaks $rssData = strstr($rssData,"<item>"); //Remove everything before <item>. #========================== # Strip specific tags and their content from the feed, to lighten the strain on the processor. # Currently, only the <description></description> tags are stripped, we don't need them and sometimes # they are REALLY long, getting rid of them now makes it easier to parse later. #========================== $tags_and_content_to_strip = Array("description"); foreach ($tags_and_content_to_strip as $tag) { $rssData = preg_replace("/<" . $tag . ">(.|\s)*?<\/" . $tag . ">/","",$rssData); } $rssData = str_replace("<item>","", $rssData); //Remove <item> itself $rssData = urldecode($rssData); //Replace any silly %20-type characters with their readable replacement. $rssData = str_replace(strstr("</channel>",$rssData),"",$rssData); $rssArray = explode("</item>",$rssData); //Creates an Array from all the headlines $title = array(); $link = array(); #========================== # This loop creates an array for links and another for titles. #========================== $x = 0; while($x < $number) { $link[$x] = strstr($rssArray[$x],"<link>"); //Remove everything before <link> $link[$x] = ereg_replace("<link>","",$link[$x]); $link[$x] = str_replace(strstr($link[$x],"</link>"),"",$link[$x]); $link[$x] = trim($link[$x]); $title[$x] = strstr($rssArray[$x],"<title>"); $title[$x] = ereg_replace("<title>","",$title[$x]); // Remove the leading <title> tags from the selected headline $title[$x] = str_replace(strstr($title[$x],"</title>"),"",$title[$x]); // Remove </title> and anything after it $title[$x] = trim($title[$x]); if ($trunc != FALSE) { $title[$x] = str_replace(substr($title[$x],$trunc),"",$title[$x]); } if ($delim != FALSE) { $title[$x] = str_replace(strstr($title[$x],$delim),"",$title[$x]); } if ($title[$x] == "") { $number = $x; break; } //If there are no more headlines, reset $number to the max. $x++; } #========================== # Writing the file #========================== $fp = fopen($filename, "w+"); $x=0; fwrite($fp,"<b><span class=\"displayname\">$displayname</span></b> \n"); //Write the displayname to the file while ($x < $number) { //This loop writes each line individualy. fwrite($fp,"<br>\n-<a class=\"headlinellink\" target=\"$target\" href=\"$link[$x]\">$title[$x]</a>"); $x++; } fclose($fp); include $filename; echo "<br><i><span class=\"updated\">Live.</span></i>"; } else { #========================== # Error handling: # (rss url given is unreadable) #========================== echo "<b>Could not connect to $url. </b>"; } ?> [/code] Many thanks Mouse
-
[code] "1410", "tim created script...", "2006", "1510", "tim posts script on site...", "2006", "1610", "tim has minimal success...", "2006", [color=red]<--[/color] [/code] thought it might be the last comma, the code would have been searching another value... but no....! Mouse
-
Quite right... sorry. i am not getting any errors... but in stead of the "tim created this script on this day in 2006" i was expecting i am getting the oooops message. hope that helps Mouse
-
On This day in History… Array issues Hello all, can someone spot the mistake in here… cos I can’t! I am aiming to get an on this day on history function on my site… (eventually to do a google type image change in the header…) but for now theres a bug here and my brain cant see where I am going wrong Many thanks Mouse [code] <?php // Array Structure: "Date","Quote","Year" $allqts = array ( "1410", "tim created script...", "2006", "1510", "tim posts script on site...", "2006", "1610", "tim has minimal success...", "2006", ); // Gets the Total number of Items in the array then Divides by 3 because there is a date then a Quote followed by a year $totalqts = (count($allqts)/3); // Subtracted 1 from the total because '0' is not accounted for otherwise $nmbr =($totalqts-1); $nmbr = $nmbr*3; // I think this is where it's going wrong... $quote = $allqts[$nmbr]; $nmbr = $nmbr+1; $year = $allqts[$nmbr]; $nmbr = $nmbr+2; $today = date(dm); // check var is correct - remove later echo $today; if ($today == $allqts) { echo '$quote', '<br /> On this day in $year' ; } else echo ' - oooops no!'; ?> [/code]
-
I hope someone out there may be able to help me out here. I have been trying to pull a few feeds into my page from Blogger and a couple of other sources with mixed success. I have to date been using Aaron Dunlaps script RSS_Get [http://www.aarondunlap.com/?content=rss_get] and if you look to the bottom right of my page [http://mouse.nodstrum.com/blog_links.php] you’ll see that under the heading of ‘The After the Mouse blog’ the feed from Aaron’s blog comes through just fine but all the others are, well useless! And that’s because they’re Atom feeds from Blogger… I will admit I know zip about the workings of XML weather its Atom or RSS so can anyone tell me where I need to make alterations to the code to make it Atom friendly RSS_Get code [code] <?php #========================== # The following line declares how long to wait before reloading the RSS feed. # Keep in mind, many sites discourage people from pulling its feed more often than 30 minutes. # For example, Slashdot.org may ban your server if it tries to load the rss feed too often. # You may change the below line. #========================== $minutes = 30; //How often to update the image. 0 indicates that image updates every time it is called (heavy strain on bandwidth & server) #========================== # The next line is what directory to dump the htm files generated by this script. # It should be relative to the location of this script, and it *MUST* have a trailing slash if it's a seperate dir. # If you want the files to be dumped in the same dir as this script, set it to "" # You may change the next line #========================== $filename = "rss/"; #========================== # The next 4 lines are default settings for the script to use, if they are not set prior to including this script # You may change the next 4 lines. #========================== $default_url = "http://www.aarondunlap.com/rss.php?mode=hl"; //URL for the RSS/XML feed you're subscribing to. $default_displayname = "|| aarondunlap.com ||"; //Title to appear before headlines. Should be feed-specific $default_number = 5; //How many headlines to display. If you set it higher than the ammount of headlines, it will stop there $default_target = "_self"; //Target for headline links. Options: "_self" and "_blank" #========================== # The next line is whether or not the script should auto-update. # If enabled, the script will check to see if a newer version of this script is available and will # automatically download and install it. Your current version of the script will be backed up in your $filename # directory. # If you have manually edited this script, you should disable this. Otherwise, it is recomended that you enable it. # Also note, your customized settings (default_url, default_displayname, filename, etc) WILL be kept during # auto-updates. Alterations to the actual function code (beneath) would be overwritten in an update. # During updates, your existing script is backed up into the $filename directory as "backup_[date]_(time).php" # You may change the next line #========================== $autoupdate = TRUE; #========================== # The settings below are for advanced headline truncation. # $default_trunc is how many characters to cut off at, # the default is FALSE, which wont truncate # at all. # You may use $trunc when calling this script # to define the truncation for specific feeds # $default_delim is what character to cut off the headline at # for example, if your headlines contain useless # data at the end, like "(via Reuters)", setting # the delimiter to "(" will stop that from showing. # You may use $delim when calling this script # to define the truncation for specific feeds #=========================== $default_trunc = FALSE; $default_delim = FALSE; #XXXXXXXXXXXXXXXXXXXXXXXXXX # Everything below is functional code. # You should not change it unless you know what you're doing, # and even if you do know what you're doing, are you sure you're # awake enough to do it? Maybe take a nap, rethink things, try again. #XXXXXXXXXXXXXXXXXXXXXXXXXX $version = 1.481; //If these variables aren't declared already, use defaults. if (!isset($url)) { $url = $default_url; } if (!isset($displayname)) { $displayname = $default_displayname; } if (!isset($number)) { $number = $default_number; } if (!isset($target)) { $target = $default_target; } if (!isset($trunc)) { $trunc = $default_trunc; } if (!isset($delim)) { $delim = $default_delim; } //In-URL definitions. Cannot be used for including, but it works great for testing. if (isset($_GET['url'])) { $url = $_GET['url'];} if (isset($_GET['number'])) { $number = $_GET['number'];} if (isset($_GET['displayname'])) { $displayname = $_GET['displayname'];} if (isset($_GET['rssHeadline'])) { $rssHeadline = $_GET['rssHeadline'];} $basefile = $filename; $versionfile = $filename."updatelog.htm"; //File for update attempt log $filename .= md5($url).".htm"; //Prepare filename for htm output #========================== # Script updating. Checks to see if an update attempt has been made in 24 hours, then goes ahead. #========================== if (((is_file($versionfile)) && (((time()-filemtime($versionfile)) >= (24 * 60 * 60))) || (!is_file($versionfile))) && ($autoupdate == TRUE)) { $out = ""; //If updatelog.htm is too big, clear it out. if (filesize($versionfile) > 102400) { unlink($versionfile); $out .= "<i>[".date("m/d/y H:i:s")."]</i> <b>Cleared update log because it was too big (>100kB)</b><hr>"; } $fd = fopen ($versionfile , "a+"); $out .= "<i>[".date("m/d/y H:i:s")."]</i> Attempting to acquire latest version number: "; fwrite ($fd , $out); require 'http://www.aarondunlap.com/code/rss_get_version.php'; if ((isset($latestversion)) && (isset($versionURL))) { $out = "<b>Acquired!</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Comparing version numbers: "; fwrite ($fd , $out); if ($version < $latestversion) { $out = "<b>Your version ($version) is out-of-date. Updating to version $latestversion.</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Loading updated script: "; fwrite ($fd , $out); //Reads the new file from my server if (@$newversfile = fopen($versionURL,"r")) { while (!feof($newversfile)) { $newvers .= fgets($newversfile); } //Transfers currently existing settings onto the update. $newvers = str_replace("http://www.aarondunlap.com/rss.php?mode=hl",$default_url,$newvers); $newvers = str_replace("|| aarondunlap.com ||",$default_displayname,$newvers); $newvers = str_replace('$default_number = 5;','$default_number = '.$default_number.';',$newvers); $newvers = str_replace('$autoupdate = TRUE;','$autoupdate = '.$autoupdate.';',$newvers); $newvers = str_replace('$filename = "rss/";','$filename = "'.$basefile.'";',$newvers); $newvers = str_replace('$minutes = 30;','$minutes = '.$minutes.';',$newvers); $newvers = str_replace('$default_target = "_self";','$default_target = '.$default_target.';',$newvers); $out = "<b>Opened</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Checking write-access in directory: "; fwrite ($fd , $out); //Checks to make sure we can write in this directory if (is_writable(getcwd())) { $out = "<b>Writable!</b><br>\n <i>[".date("m/d/y H:i:s")."]</i> Writing new version to temporary file: "; fwrite ($fd , $out); $outfile = fopen("rss_get_temp.txt","w+"); fwrite($outfile, $newvers); fclose($outfile); $out = "<b>Written.</b><br>\n<i>[".date("m/d/y H:i:s")."]</i> Backing up outdated file in $basefile directory:"; fwrite ($fd , $out); //Backs up the current script (this one) into the rss folder if (!copy("rss_get.php",$basefile."backup_".date("m-d-y_(H.i)").".php")) { $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } else { $out = "<b>Moved.</b><br>\n<i>[".date("m/d/y H:i:s")."]</i> Replacing script with new version:"; fwrite ($fd , $out); //Renames the temp file as this file, effectively replacing it. if (@!rename("rss_get_temp.txt","rss_get.php")) { /*Dude, look at these if blocks!*/ $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } else { chmod("rss_get.php",774); $out = "<b>Replaced</b><br>\n<i>[".date("m/d/y H:i:s")."]</i><b> RSS_GET updating complete. </b>\n<br><i>[".date("m/d/y H:i:s")."]</i><b>Version note from author:</b>".$message."<hr>\n"; fwrite ($fd , $out); fclose($fd); } } } else { $out = "<b>Not Writable.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } } else { $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } } else { $out = "<b>Your version is current</b><hr>\n"; fwrite ($fd , $out); } } else { $out = "<b>Failed.</b><hr>\n"; fwrite ($fd , $out); fclose($fd); } } // That's a lot of elses! Alright, we're done with the update thing. #========================== # Check the modify time of the htm file for this feed, and see if it's too new to reload the feed. # If the file is too new, it loads the htm file. This stops the script from constantly pulling the feed. #========================== if (($minutes > 0) && (is_file($filename)) && (((time()-filemtime($filename)) < ($minutes * 60)))) { include $filename; $time = floor((time()-filemtime($filename)) / 60); //See how many "minutes ago" the file was made. echo "<br><i><span class=\"updated\">Updated $time minutes ago.</span></i>"; //Include "minutes ago" after output. } elseif (@fopen($url,"r")) { //Makes sure the file can actually be accessed. #========================== # If we're down here, it means that the feed needs to be reloaded. #========================== $rssHandle = fopen($url,"r") ; // Open the rss file for reading while (!feof($rssHandle)) { $rssData .= fgets($rssHandle); } #========================== # Feed parsing #========================== $tag = "item "; $rssData = preg_replace("/<" . $tag . "(.|\s)*?>/","<item>",$rssData); $rssData = chop($rssData); // Strip any whitespace from the end of the string $rssData = ereg_replace("[\r,\n]", "", $rssData); //Clear line breaks $rssData = strstr($rssData,"<item>"); //Remove everything before <item>. #========================== # Strip specific tags and their content from the feed, to lighten the strain on the processor. # Currently, only the <description></description> tags are stripped, we don't need them and sometimes # they are REALLY long, getting rid of them now makes it easier to parse later. #========================== $tags_and_content_to_strip = Array("description"); foreach ($tags_and_content_to_strip as $tag) { $rssData = preg_replace("/<" . $tag . ">(.|\s)*?<\/" . $tag . ">/","",$rssData); } $rssData = str_replace("<item>","", $rssData); //Remove <item> itself $rssData = urldecode($rssData); //Replace any silly %20-type characters with their readable replacement. $rssData = str_replace(strstr("</channel>",$rssData),"",$rssData); $rssArray = explode("</item>",$rssData); //Creates an Array from all the headlines $title = array(); $link = array(); #========================== # This loop creates an array for links and another for titles. #========================== $x = 0; while($x < $number) { $link[$x] = strstr($rssArray[$x],"<link>"); //Remove everything before <link> $link[$x] = ereg_replace("<link>","",$link[$x]); $link[$x] = str_replace(strstr($link[$x],"</link>"),"",$link[$x]); $link[$x] = trim($link[$x]); $title[$x] = strstr($rssArray[$x],"<title>"); $title[$x] = ereg_replace("<title>","",$title[$x]); // Remove the leading <title> tags from the selected headline $title[$x] = str_replace(strstr($title[$x],"</title>"),"",$title[$x]); // Remove </title> and anything after it $title[$x] = trim($title[$x]); if ($trunc != FALSE) { $title[$x] = str_replace(substr($title[$x],$trunc),"",$title[$x]); } if ($delim != FALSE) { $title[$x] = str_replace(strstr($title[$x],$delim),"",$title[$x]); } if ($title[$x] == "") { $number = $x; break; } //If there are no more headlines, reset $number to the max. $x++; } #========================== # Writing the file #========================== $fp = fopen($filename, "w+"); $x=0; fwrite($fp,"<b><span class=\"displayname\">$displayname</span></b> \n"); //Write the displayname to the file while ($x < $number) { //This loop writes each line individualy. fwrite($fp,"<br>\n-<a class=\"headlinellink\" target=\"$target\" href=\"$link[$x]\">$title[$x]</a>"); $x++; } fclose($fp); include $filename; echo "<br><i><span class=\"updated\">Live.</span></i>"; } else { #========================== # Error handling: # (rss url given is unreadable) #========================== echo "<b>Could not connect to $url. </b>"; } ?> [/code] Many thanks Mouse
-
Note to self:- I should explain this better… Ok so here goes. I haven seen this done much but I am sure it is out there… I have set up a page on my site where I intend to offer RSS or Atom feeds from several blogs on a similar or complimentary theme to my main site. The page is at http://mouse.nodstrum.com/blog_links.php and I am just wondering how the adding feeds thing works. There must be a trick to it but I am at a loss where to start. I have looked around for a simple tutorial or even a prewritten script but to no avail… Can anyone point me in the right direction? Mouse
-
Hi all, My php skills are ok, and I thought I’d got things sorted but… my site will be heavily dependant on word of mouth for its proliferation so I used a “tell-a-friend” script. Put it on line and 12 hours later my first spammer hit and I took the script offline! So, does anyone have any suggestions, scripts, ideas on how a script can be made more secure? To be honest I am now getting bogged down with work on other areas of the site and could use a ready-made script… Many thanks Mouse
-
if date then do this if not go do that.... ????? Grrrrrr!!!!
Mouse replied to Mouse's topic in PHP Coding Help
i think i should also point out that while the site is mone, i tend to do mostly the design side and let my coding partner do the back end bits... but pride is getting to me and i need to do some of the coding myself... Mouse