iwato

Members
  • Content count

    664
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by iwato

  1. OK. This is the code. I am exhausted. <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $host = "..."; $user = "..."; $pwd = "..."; $mysqli_obj = new mysqli($host, $user, $pwd); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $mysqli_obj->set_charset("utf8"); $db = "thege0_grammarcaptive"; $mysqli_obj->select_db($db); $tbl_name = 'rss2_podcast_channel'; $sql_1 = "SELECT * FROM ". $tbl_name . " ORDER BY channel_pubdate DESC LIMIT 1"; $chan_arr = array(); $result_obj = $mysqli_obj->query($sql_1); while($row = $result_obj->fetch_assoc()) { foreach($row as $key => $value) { $chan_arr[$key] = $value; } } $tbl_name = 'rss2_podcast_item'; $sql_1 = "SELECT * FROM ". $tbl_name . " ORDER BY item_pubdate DESC LIMIT 5"; $item_arr = array(); $result_obj = $mysqli_obj->query($sql_1); while($row = $result_obj->fetch_assoc()) { foreach($row as $key => $value) { $item_arr[$key] = $value; } $items[] = $item_arr; } $tbl_name = 'rss2_podcast_itunes'; $sql_1 = "SELECT * FROM ". $tbl_name . " ORDER BY publish_date_itunes DESC LIMIT 5"; $itunes_arr = array(); $result_obj = $mysqli_obj->query($sql_1); while($row = $result_obj->fetch_assoc()) { foreach($row as $key => $value) { $itunes_arr[$key] = $value; } $itunes[] = $itunes_arr; } include('/Users/kiusau/Sites/reflexive/php_practice/libraries/rssgen2.0/rss_generator.inc.php'); $rss_feed = new rssGenerator_rss(); $atomLinkHref = '../../../../grammarcaptive.com/feed/gc_podcasts.xml'; $chan_categories = array(0 => array('domain' => '', 'name' => $chan_arr['channel_category1']),1 => array('domain' => '', 'name' => $chan_arr['channel_category2']),2 => array('domain' => '', 'name' => $chan_arr['channel_category3'])); $i = 0; $length = count($items); while ($i < $length) { foreach ($items[$i] as $key => $value) { if ($key == 'item_category1') { $item_categories[$i][$key] = array('domain'=>'','name'=>$value); } if ($key == 'item_category2') { $item_categories[$i][$key] = array('domain'=>'','name'=>$value); } if ($key == 'item_category3') { $item_categories[$i][$key] = array('domain'=>'','name'=>$value); } } $i++; } $i = 0; $length = count($itunes); while ($i < $length) { foreach ($itunes[$i] as $key => $value) { if ($key == 'itunes_category1') { $itunes_categories[$i][$key] = array('domain'=>'','name'=>$value); } if ($key == 'itunes_category2') { $itunes_categories[$i][$key] = array('domain'=>'','name'=>$value); } if ($key == 'itunes_category3') { $itunes_categories[$i][$key] = array('domain'=>'','name'=>$value); } } $i++; } $i = 0; $length = count($items); while ($i < $length) { $rss_item = new rssGenerator_item(); foreach ($items[$i] as $key => $value) { $rss_item->title = $items[$i]['item_title']; $rss_item->description = $items[$i]['item_description']; $rss_item->link = $items[$i]['item_link']; $rss_item->pubDate = $items[$i]['item_pubdate']; $rss_item->author = $items[$i]['item_author']; $rss_item->comments = $items[$i]['item_comments']; $rss_item->guid = $items[$i]['item_guid']; $rss_item->guid_isPermaLink = 'false'; $rss_item->source = 'Grammar Captive'; $rss_item->source_url = $items[$i]['item_source']; $rss_item->enclosure_url = $items[$i]['item_enclurl']; $rss_item->enclosure_length = $items[$i]['item_encllength']; $rss_item->enclosure_type = $items[$i]['item_encltype']; $rss_item->categories = $item_categories[$i]; } $rss_items[] = $rss_item; $i++; } $rss_image = new rssGenerator_image(); $rss_image->title = $chan_arr['channel_img_title']; $rss_image->url = $chan_arr['channel_img_url']; $rss_image->link = $chan_arr['channel_img_link']; $rss_image->width = $chan_arr['channel_img_width']; $rss_image->height = $chan_arr['channel_img_height']; $rss_image->description = $chan_arr['channel_img_description']; $rss_channel = new rssGenerator_channel(); $rss_channel->atomLinkHref = $atomLinkHref; $rss_channel->title = $chan_arr['channel_title']; $rss_channel->link = $chan_arr['channel_link']; $rss_channel->description = $rss_feed->cData($chan_arr['channel_description']); $rss_channel->language = $chan_arr['channel_language']; $rss_channel->copyright = $chan_arr['channel_copyright']; $rss_channel->webMaster = $chan_arr['channel_link']; $rss_channel->pubDate = $chan_arr['channel_pubdate']; $rss_channel->lastBuildDate = $chan_arr['channel_lastbuilddate']; $rss_channel->categories = $chan_categories; $rss_channel->image = $rss_image; $rss_channel->items = $rss_items; $rss_feed->encoding = 'UTF-8'; $rss_feed->version = '2.0'; $rss_feed->createFeed($rss_channel); // header('Location: gc_podcasts.xml'); $result_obj->free(); $mysqli_obj->close(); ?> Now, mind you. This identical code works in an HTML file with all kinds of HTML mark-up, but when set aside unto its own without the mark-up it fails resulting in the PHP white sheet.
  2. BACKGROUND: I have recently created the content of an automatically generated podcast using a PHP Class that I found on a webpage found https://www.phpclasses.org/package/2957-PHP-Generate-RSS-2-0-feeds.html. Unfortunately, when I attempt to display the generated feed all that is displayed are the values of the input variables, or alternatively nothing (see (below)depending on the method of display. In short, the desired formatting -- the reason that I downloaded the PHP Class -- is missing. The page that creates the above result is a text file with a .php extension and a header( ) function. $rss_feed->encoding = 'UTF-8'; $rss_feed->version = '2.0'; $rss_feed->createFeed($rss_channel); header('Content-Type: text/xml; $rss_channel = the object that combines the formatting with the values of the input variables and their respective objects. The Class is relatively straight-forward and easily customized, but for two lines that I do not understand and could well be preventing the display of the XML code, if not properly configured. Interestingly, whether they are commented out or left in tact, they have no affect on what is displayed. $selfUrl = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://'); $selfUrl .= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; When I run the .php file the following message appears at the top of the completed page. Still nothing below the message appears. Also, I do not know the source of this message. it does not appear to come from the .php document. Now, I have not constructed a style-sheet for the Feed page, but I hardly see how this could stop the feed from appearingl Please advise.
  3. This problem has been resolved. After a night's rest I discovered that I was accidentally querying the same table twice. A condition likely caused by an improper copy and paste. LESSON: When everything appears correct, do not doubt its correctness. Look elsewhere for the error.
  4. QUESTION ONE: How does one suppress duplicate row entries? QUESTION TWO: In the following case what is causing them to occur? BACKGROUND: I created several tables only to discover that they were not as I wanted them. AFter truncateng each, I dropped what I believed to be poorly structured columns, rearranged some, and added still others. When I tested the result, everything worked great except for one problem -- a single table entry reuslted in duplicate rows. THE TABLE STRUCTURE CREATE TABLE 'table_name' (obs` int(5) NOT NULL AUTO_INCREMENT . . . PRIMARY KEY (`obs`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 A SAMPLE SQL STATEMENT INSERT INTO rss2_podcast_itunes (podcast_no_itunes, itunes_category1, itunes_category2, itunes_category3, itunes_complete, itunes_new_feed_url, itunes_name, itunes_email, itunes_duration, itunes_order, itunes_author, itunes_block, itunes_image, itunes_explicit, itunes_summary) VALUES ('54', 'education', 'language', 'English', '', '', 'Roddy A. Stegemann', 'kiusau@me.com', '00:01:01', '', 'Roddy A. Stegemann', '', 'http://www.grammarcaptive.com/_images/captive.png', '', 'Test') Please note the following: No value is entered for the obs field/column. The auto increment advances one for each row entered. Below each successfully loaded row entry appears another row identical in every way but one -- the appearance of an incremental advance in the value of the obs field. Please advise. Roddy
  5. Please ignore the missing back-tick before the obs column. it was a typo incurred while editing code taken from the results of a SHOW CREATE TABLE statement.
  6. QUESTION ONE: Please suggest what might be entered where the three ? marks appear in order to achieve the following goal. THE GOAL: See appear the value of mil in the input control text field and have this value become the value of $_POST['item_encllength'] when the form is submitted. var min = $('#min').val(); var sec = $('#sec').val(); var mil = function(min, sec) { var millisec = ((min * 60) + sec) * 1000; return millisec; } $('#item_encllength').mousedown(mil, function() { $(this).???; }); <input id='min' type='number' value='Minutes'> <input id='sec' type='number' value='Seconds'> <input id='item_encllength' form='rss2_feed' type='text' name='item_encllength'> I have experimented in a variety of ways, but have not been able to find the code necessary to achieve my goal. Perhaps my approach to the problem is inappropriate. Roddy
  7. Thank you. I will add these links to my notes. Roddy
  8. BACKGROUND: Please find below a portion of a PHP class used to create an RSS feed. Included are only the constructor function and the function used to create the actual document. All other functions have been omitted so as to focus on the question at hand. My reason for posting this code is to better understand the proper way to create a class. As you can readily see from the __construct( ) function of this class each new instance of the class requires six parameter values. Although the author lists these parameters at the beginning of the class definition, he comments them out, rather than initializing them. QUESTION: Is this standard practice? What is to be gained by not declaring them outside of the __construct( ) function? It appears to create an unnecessary repetitious use of the pseudo $this variable. <?php /** * rss_feed (simple rss 2.0 feed creator php class) * * @author Christos Pontikis http://pontikis.net * @copyright Christos Pontikis * @license MIT http://opensource.org/licenses/MIT * @version 0.1.0 (28 July 2013) * */ class rss_feed { /** * Constructor * * @param array $a_db database settings * @param string $xmlns XML namespace * @param array $a_channel channel properties * @param string $site_url the URL of your site * @param string $site_name the name of your site * @param bool $full_feed flag for full feed (all topic content) */ public function __construct($a_db, $xmlns, $a_channel, $site_url, $site_name, $full_feed = false) { // initialize $this->db_settings = $a_db; $this->xmlns = ($xmlns ? ' ' . $xmlns : ''); $this->channel_properties = $a_channel; $this->site_url = $site_url; $this->site_name = $site_name; $this->full_feed = $full_feed; } /** * Generate RSS 2.0 feed * * @return string RSS 2.0 xml */ public function create_feed() { $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; $xml .= '<rss version="2.0"' . $this->xmlns . '>' . "\n"; // channel required properties $xml .= '<channel>' . "\n"; $xml .= '<title>' . $this->channel_properties["title"] . '</title>' . "\n"; $xml .= '<link>' . $this->channel_properties["link"] . '</link>' . "\n"; $xml .= '<description>' . $this->channel_properties["description"] . '</description>' . "\n"; // channel optional properties if(array_key_exists("language", $this->channel_properties)) { $xml .= '<language>' . $this->channel_properties["language"] . '</language>' . "\n"; } if(array_key_exists("image_title", $this->channel_properties)) { $xml .= '<image>' . "\n"; $xml .= '<title>' . $this->channel_properties["image_title"] . '</title>' . "\n"; $xml .= '<link>' . $this->channel_properties["image_link"] . '</link>' . "\n"; $xml .= '<url>' . $this->channel_properties["image_url"] . '</url>' . "\n"; $xml .= '</image>' . "\n"; } // get RSS channel items $now = date("YmdHis"); // get current time // configure appropriately to your environment $rss_items = $this->get_feed_items($now); foreach($rss_items as $rss_item) { $xml .= '<item>' . "\n"; $xml .= '<title>' . $rss_item['title'] . '</title>' . "\n"; $xml .= '<link>' . $rss_item['link'] . '</link>' . "\n"; $xml .= '<description>' . $rss_item['description'] . '</description>' . "\n"; $xml .= '<pubDate>' . $rss_item['pubDate'] . '</pubDate>' . "\n"; $xml .= '<category>' . $rss_item['category'] . '</category>' . "\n"; $xml .= '<source>' . $rss_item['source'] . '</source>' . "\n"; if($this->full_feed) { $xml .= '<content:encoded>' . $rss_item['content'] . '</content:encoded>' . "\n"; } $xml .= '</item>' . "\n"; } $xml .= '</channel>'; $xml .= '</rss>'; return $xml; } } ?>
  9. This is what I thought too, but it does not appear to run.
  10. BACKGROUND: I have recently discovered a file on my test server that opens to the wrong file. Not only does this same phenomenon appear in different browsers, but clearing the browsers' cache and rebooting the computer does not help. It has been suggested by two of my colleagues that the problem lies with the Apache cache. Although I have discovered something called htcacheclean on the Apache website, nowhere have I been able to find instructions about how to implement this instruction properly. i want simply to clean one URL from the cache, but am baffled about how to implement what I have already learned. QUESTION ONE: Is it not possible to run htcacheclean from the UNIX terminal? QUESTION ONE: Whether it is possible or not, how does one go about doing it? Source: htcacheclean
  11. JSG - Up until now I have understood that a Javascript script can be entered via an <input> or <textarea> control form, or for that matter any other data that is passed from a form to the same or another processing page when the <submit> control is triggered. What you seem to be suggesting is something else. Am I in error? If not, could you provide an example. I would like to see what i am up against. Roddy
  12. I have never heard of a static class -- only static properties and methods of a class. Do you mean by non-static class a class without static properties or methods? If I have understood correctly, the purpose of the pseudo $this variable is to distinguish between variables within a specific scope or class from regular variables -- these latter being variable that can be used anywhere except within a class or specified scope. In effect, one can speak of three different kinds of variables: 1) regular variables -- variables defined and used outside of specific scopes and classes. 2) $this -> variables -- variables defined within a specific scope or class and accessed from within the scope or class using the $this-> notation of from without using a class object and the -> operator. 3) global variables -- variables defined within a specific scope (not class) that can be accessed from without the scope as regular variables and presumably within the scope as same. Is this assessment correct? Have you anything to add?
  13. Are you saying then that the object, because it is an object is global in nature, and that, if created outside of the function, the same object can be accessed either in or outside of the function?
  14. Not really. In both cases it is documentation. Although it may be more likely that documentation included with the code is more current than documentation that is external to the code, either could be neglected with regard to an update of the code. Still, there is no sample code, and the implementation of htcacheclear on the UNIX terminal is unclear.
  15. Dsonesuk: I am still a little confused by this statement The condition is true when AJAX is absent, but false when it is present. So, if AJAX is present, ajax_comment.php' will be called, and if AJAX is absent config.php is called. As we do not know what is contained in config.php, it is difficult to know why there would be two different PHP pages to process the same code. Does this make sense to you? Loois: Could you show us config.php? JSG: OK. I appear to understand that sanitization, perhaps not validation, should always take place on the server side. And, in the event that the user has turned Javascript off, one would also want to sanitize on the server-side. What I am unclear about is the nature of the manipulation of the Javascript. Can the user actually rewrite the author's Javascript? Or, is it that the user submits his own Javascript as input data that takes advantage of the Javascript that the author has written?
  16. OK. The advantage of using AJAX is to prevent having to reload the page each time the form is submitted, and the advantage of using PHP is to insure that the submitted data is sanitized and validated. Are implying with this that it is not possible to use Javascript for the purpose of sanitization and validation? If I have understood correctly, AJAX serves only as an intermediary between the form page and the PHP page. In other words, the PHP page should be written, as if the AJAX did not exist, and the AJAX should always refer to the PHP page via the following piece of code $.ajax({ url: 'ajax_comment.php', What is more, the PHP code should only be included in the page, if the following condition is satisfied. !isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) Thus, it was wrong for Loois to have included the following code at the bottom of his form page include ("jquery.js"); Under the assumption that all of the above is correct, why is the following code not entered at the top of the form page? include ("jquery.js"); My very best, Roddy
  17. Yes. In other words, it is telling me that it is there, but that I am not employing it properly.
  18. So, why use AJAX at all? Since AJAX depends on Javascript being turned on or off, and since this decision is made by the user-client, why not use PHP whose functioning is determined solely by the host-server?
  19. Got it! Security is number one. Roddy
  20. This is another strategy question. Multiple answers are welcome. What is written in present tense should be thought of as future, not yet realized activity. BACKGROUND: I have constructed a form whose intended purpose is to create chunks of data including text, links, and images that can be entered into a MySQL database for both immediate and future use. For the moment, I am only concerned about their immediate use. From the database these same chunks of data are retrieved and entered into an HTML template that serves as the backbone for an email insert that is, in fact, a weekly newsletter that can be viewed directly in one's mailbox or viewed on line should the insert fail. The mail insert is then distributed using PHPMailer that takes advantage of an assembled list of subscribers stored in the same database. Based on previous experience I believe that I am well able to handle this routine except for one hitch -- the treatment of the HTML data. MY DILEMMA: In the form are <textarea> elements that I intend to fill with a combination of plain text, HTML, and CSS styling attributes. That the HTML does not render as anything but the code itself is not a cause for concern on my part. Rather, I am bothered about how to send this data to the remote server. Now, I have been taught to filter and sanitize $_POST variable data as it is received and before processing. This time, however, I am sending the data to myself, and what will be generated and sent to my subscribers will also be generated by me. Do I even need to worry how about filtration and sanitation when I am both the source and the receiver of the data? Further, it is my understanding that MySQL is indifferent how the data is received, and that it will automatically return data in the same format that it is received. Am I making a big ado about nothing? By the way, it is not just a matter of filtration and sanitization. Take, for example, the following script used to process form data on the same page that it is entered. <form id="sevengates" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
  21. Never mind unless, of course, you know something about array mapping that I do not and would like to teach me. Certainly I am willing to learn. For the moment, I have resolved the problem using the array_combine( ) method. Roddy
  22. I would like to preserve the keys to the associative input array ($varnames) and replace the values with those of $_POST. This function replaces the both the keys and values and returns an index array with the $_POST values. function replace_value($a, $b) { $a = $b; return $a; }; $varnames = array_map(replace_value, $varnames, $_POST); print_r($varnames); Any suggestions? Roddy
  23. OK. Thank you for the correction, Dsonesuk. I have never used AJAX and looked only for what was different from what I use -- namely, PHP. Upon a more careful reading I now see the statement include ("ajax_comment.php"); If I have further understood, you find the following statement to be ill-conceived, if (isset( $_SERVER['HTTP_X_REQUESTED_WITH'] )):include('../config.php'); and give as a reason that the PHP will only be used, if the Javascript succeeds. So, if Loois were to write, if (!isset( $_SERVER['HTTP_X_REQUESTED_WITH'] )):include('../config.php'); would this fix his problem.
  24. There is no action attribute in the following line of code <form id="form" method="post"> You must enter an URL for ajax_comment.php as the value of your action attribute in the above <form> element. <form id="form" method="post" action='pathto/ajax_comment.php'> Replace the word "pathto" with whatever is necessary to connect the document that contains your form with the document that processes your $_POST variable -- namely, ajax_comment.php.