Jump to content

doubleJ

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by doubleJ

  1. include/getrss2.php Note that this is almost exactly like the code in freedownloads.php. There's probably a good way to combine the two code bases. I was thinking about having all the <div id="articles"> code in getrss2.php and then just include_once("getrss2.php"), but I couldn't figure out how to get it to load all the records or just the $category records. I might start working on that, again, now that this is working. JJ <?php $category = $_GET["category"]; // php5 required for SimpleXMLElement $rss = new SimpleXMLElement("http://www.moorelife.org/rss/FreeDownloads.xml", null, true); // step through all the items of the xml file // reference parts by $item->partname foreach($rss->xpath("channel/item[category='$category']") as $item) {
  2. freedownloads.php <?php // maybe find a way to do this with SimpleXMLElement include_once("include/SimpleDOM.php"); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <link rel="alternate" type="application/rss+xml" title="Free Downloads" href="http://www.moorelife.org/rss/FreeDownloads.xml" /> </head> <body> <div id="content" role="main"> <h1 id="title">Free Downloads</h1> <section id="series"> <h2>Moore Life Ministries series</h2> <nav> <h3>Alphabetical series links</h3> <ol> <?php // requires the loading of SimpleDOM (see beginning of file) $rss = simpledom_load_file("http://www.moorelife.org/rss/FreeDownloads.xml"); // sorts the array alphabetically (note you can use SORT_ASC or SORT_DESC as a third option foreach($rss->sortedXPath('channel/item', 'title') as $item) { $nospacetitle = basename($item->guid,".xml"); echo <<<END <li><a href="#$nospacetitle">$item->title</a></li>\n END; } ?> </ol> </nav> <aside> <script type="text/javascript"> function showRSS(str) { if (str.length==0) { document.getElementById("articles").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("articles").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","include/getrss2.php?category="+str,true); xmlhttp.send(); } </script> <a href="javascript:location.reload()">Show all</a> <a href="javascript:showRSS('Faith')">Faith</a> <a href="javascript:showRSS('Marriage')">Marriage</a> <a href="javascript:showRSS('Victory')">Victory</a> </aside> <div id="articles"> <?php // SimpleXMLElement requires php5 $rss = new SimpleXMLElement("http://www.moorelife.org/rss/FreeDownloads.xml", null, true); // if I can figure out how to get if ($category) else working // foreach($rss->xpath("channel/item[category='$category']") as $item) { foreach($rss->xpath("channel/item") as $item) { $filename = basename($item->guid,".xml"); // required for reading namespace parts // reference namespace parts by $ns_mlm->partname $ns_mlm = $item->children("http://www.moorelife.org/"); $address = explode(", ", $ns_mlm->address); $city = $address[0]; $state = $address[1]; $iso8601 = date("c", strtotime($item->pubDate)); $date = date("l, F d, Y", strtotime($item->pubDate)); echo <<<END <article id="$filename" class="vevent"> <img src="$ns_mlm->thumbnail" alt="" title="$item->title" /> <hgroup> <h3><a class="summary url" href="http://$fqdn/rss/$filename.xml">$item->title</a></h3> <h4>$ns_mlm->subtitle</h4> </hgroup> <p>Series started: <time class="dtstart" pubDate datetime="$iso8601">$date</time></p> <div class="location vcard"> <p class="fn org">$ns_mlm->location</p> <p class="adr"><span class="locality">$city</span>, <span class="region">$state</span></p> </div> <p><strong>$ns_mlm->availability</strong></p> </article>\n END; } ?> </div> </section> </div> <!-- end content --> </body> </html>
  3. Well, I'm not sure what happened. I tried one last bit of code that I was working on, hours ago, and it works perfectly. I'm even re-using the SimpleXMLElement setup, instead of DOMDocument. I don't know why it's working, now, when it wasn't working, earlier. I don't particularly care, though. I think I'll post all the code, for posterity. I know I've been scouring the internet for hours trying to get this all to work. As I post, please, feel free to critique my code. I'm not a php guru, by any stretch. JJ
  4. Hello... I'm working on a webpage (http://66.119.8.164/freedownloads.php) that pulls from an rss feed (http://www.moorelife.org/rss/FreeDownloads.xml). Please keep in mind that I'm working on content, not design. It's a very long page, currently. I want to have links on a sidebar that will allow sorting and filtering, based on <category>. I got the idea from, get this, Internet Explorer's built-in rss reader. It's great. I have a section of the page populating with SimpleXMLElement (that's where the case cover images and titles are). Above that is an alphabetic listing of all those entries populated by SimpleDOM's sortedXPath. Between those two are a few category links that use ajax to overwrite the section pulled with SimpleXMLElement. Now, I don't have any idea if I'm even doing this in an intelligent manner. As a matter of fact, I'm sure it's very far away from resourceful code. It's just what I have gotten to work when other options didn't work. Now, on to the problem. The code, below, is the php file (http://66.119.8.164/include/getrss.php) that ajax uses to overwrite the original list. <?php //get the category from URL $category = $_GET["category"]; $xml = "http://www.moorelife.org/rss/FreeDownloads.xml"; $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $item = $xmlDoc->getElementsByTagName('item'); for ($i=0; $i<=5; $i++) { $item_title = $item->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; $item_category = $item->item($i)->getElementsByTagName('category')->item(0)->childNodes->item(0)->nodeValue; echo "<p>".$item_title."</p>"; echo "<p>".$item_category."</p>"; } ?> How do I only show the entries where $catagory match <category>? JJ
  5. Bah... You with your fancy databases. I'll have to look into that. Unfortunately, it will probably mean that I will have to do all the maintenance, whereas multiple people maintain their own .txt files. I was hoping that it would be something simple like... if (%i >15 && >30) echo ""; elseif (%i >30 && <45) echo ""; etc... JJ
  6. Sorry for resurrecting, but it seemed pertinent... How would I show the next 15 records on a second page, third, etc? Thanks... JJ
  7. I'll check it out. Thanks... BTW... Would your name be referencing Masta Ace Inc.? JJ
  8. Hello... I know, a lot of times, I hack some code together. It's not necessarily the most efficient or cleanest way to do it, but it works. I thought it might be useful to have a place where people (maybe just myself) could post a chunk of code that others could analyze and recommend a better way of doing it. This looks to see if a file for a particular date is available and, if it is, creates a link to it. This is a prime example of what looks like it is way too much code for the task at hand. You'll note that nothing is indented. This isn't how I normally code, but when putty pastes vim tabs, it turns into spaces (which is annoying). I left-justified for ease of copy/paste, as I had to do it for multiple days (not just Friday). Just so it's clear, the code is looking for 110211Audio.mp3 (as of this week). JJ <?php if (date("l")=="Friday") { if(file_exists("services/2011/".date("ymd"))."Audio.mp3") { echo "<a href='services/2011/".date("ymd")."Audio.mp3'>Listen To Friday Sermon</a>"; } } elseif (date("l")=="Saturday") { if(file_exists("services/2011/".date("ymd", strtotime("-1 day"))."Audio.mp3")) { echo "<a href='services/2011/".date("ymd", strtotime("-1 day"))."Audio.mp3'>Listen To Friday Sermon</a>"; } } elseif (date("l")=="Sunday") { if(file_exists("services/2011/".date("ymd", strtotime("-2 day"))."Audio.mp3")) { echo "<a href='services/2011/".date("ymd", strtotime("-2 day"))."Audio.mp3'>Listen To Friday Sermon</a>"; } } elseif (date("l")=="Monday") { if(file_exists("services/2011/".date("ymd", strtotime("-3 day"))."Audio.mp3")) { echo "<a href='services/2011/".date("ymd", strtotime("-3 day"))."Audio.mp3'>Listen To Friday Sermon</a>"; } } elseif (date("l")=="Tuesday") { if(file_exists("services/2011/".date("ymd", strtotime("-4 day"))."Audio.mp3")) { echo "<a href='services/2011/".date("ymd", strtotime("-4 day"))."Audio.mp3'>Listen To Friday Sermon</a>"; } } elseif (date("l")=="Wednesday") { if(file_exists("services/2011/".date("ymd", strtotime("-5 day"))."Audio.mp3")) { echo "<a href='services/2011/".date("ymd", strtotime("-5 day"))."Audio.mp3'>Listen To Friday Sermon</a>"; } } elseif (date("l")=="Thursday") { if(file_exists("services/2011/".date("ymd", strtotime("-6 day"))."Audio.mp3")) { echo "<a href='services/2011/".date("ymd", strtotime("-6 day"))."Audio.mp3'>Listen To Friday Sermon</a>"; } } ?>
  9. That worked, perfectly. Thanks... JJ
  10. Ah... I'll test that out, tomorrow. Thanks a lot for the help. JJ
  11. Hello... I have a .txt database with ~100 records. I only want to show the 15 records that are at the top (referring to reading order of the file). Here is my php code to display the records. http://www.flcbranson.org/mobile.php?content=mobile-freedownloads.php if you want to see the results of the code, below. <?php $index_file = 'services/series/Index-Date.txt'; $fd = fopen($index_file, 'r'); if ($fd) { while (!feof ($fd)) { $seriestitle = trim(fgets($fd, 1024)); // Series Title if(feof ($fd)) break; $seriessubtitle = trim(fgets($fd, 1024)); // Series subtitle $seriesinfo = trim(fgets($fd, 1024)); // Series Info (Church name) $serieslocation = trim(fgets($fd, 1024)); // City, State $seriesindex = trim(fgets($fd, 1024)); // Series index file $seriesstatus = trim(fgets($fd, 1024)); //Online Only? $divider = trim(fgets($fd, 1024)); // Divider $seriestitle2 = $seriestitle; $seriestitle3 = str_replace("'", "%27", $seriestitle); // Kind of makes the alt= below work "God's Will" ends up being "God%27s Will" but without is "God" if(strstr($seriestitle,"<")) { $seriestitle2 = strip_tags($seriestitle); } $seriestitle2 = urlencode($seriestitle2); if(file_exists("images/ProductCovers/".substr($seriesindex,0,-4).".jpg")) { echo "<img src='images/ProductCovers/".substr($seriesindex,0,-4).".jpg' width='115' height='150' border='0' alt='".substr($seriestitle3,7)."'><br />"; } } fclose ($fd); } ?> I'm assuming that "for" would do the trick, but when I tried I got 10 copies of every record. Hehehe... I'm guessing that it's a quick fix. Thanks... JJ
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.