Jump to content

iwato

Members
  • Posts

    1,506
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by iwato

  1. Actually, I cannot test it -- well, at least not on my own machine. Traits were introduced with PHP 5.4, and I am currently running with PHP 5.3.6. The test will have to wait until I upload my completed files to my host server. Thanks, anyway. I thought you might know. Roddy
  2. I would like to thank you both for the wonderful suggestions, clarifications, and implementing strategies. This topic must now wait, however, while I attend to other matters that are equally, if not more, pressing. Long turn-around times between questions-asked and questions-answered have taught me to appreciate multi-tasking. In this particular instance, I discovered that some of my already implemented code was not robust. It worked in one instance, but not in another. I finally replaced it, but in the meantime several answers to questions for other tasks entered in, and I set this task on hold weary of my misfortune. Roddy
  3. I followed up on your link and discovered something that was invented after I left Thailand. I believe this is the path that I will take. I do have one remaining question, though. Is the absence of parentheses in the following sample code a misprint. If not, when are the parentheses required and not required? <?php trait PropertiesTrait { public $x = 1; } class PropertiesExample { use PropertiesTrait; } $example = new PropertiesExample; $example->x; ?> The Suspicious Line of Code $example = new PropertiesExample; Roddy
  4. So, if one places all of the non-volatile data in a PHP configuration class file what are the best ways to include the information contained within into the PHPMailerFactory class? Having to include all of the non-volatile information in the factory class via a constructor function is awkward at best. As a general practice can/does one extend to the factory class the configuration class? Say, class PHPMailerFactory extend PHPMailer PHPConfig { ... } Roddy
  5. OK. In the following block of code, for example, I assume that create() is a static function defined in a class called PHPMailerFactory that inherits the class PHPMailer from a file that has been included by your global.init.php file. Also, I can understand that your create() function takes a series of arguments that are used to satisfy the specifications of an instance of PHPMailerFactor aka PHPMailer and the eventual sending of an email. What I do not understand is how the values of those arguments are assigned. $newsletter = PHPMailerFactory::create( $config::NEWSLETTER_HOST, $config::NEWSLETTER_USER, $config::NEWSLETTER_PASSWORD, $to, $from ); To what, for example, does $config::NEWSLETTER_HOST refer? Is it a constant predefined in PHPMailerFactory that you are accessing by a variable called $config to which you assigned the class PHPMailerFactor something on the order of $config = 'PHPMailerFactory'; where class PHPMailerFactory { ... const NEWSLETTER_HOST = 'some_hostname.com'; const NEWSLETTER_USER = 'some_accountname'; const NEWSLETTER_PSWD = 'some_password'; ... create( ..., ..., ...) {...} } Or, does $config refer to some sort of configuration class in which the values of some_hostname.com, some_accountname, and some_password are stored on the order of class ConfigureThisHost { const NEWSLETTER_HOST = 'some_hostname.com'; const NEWSLETTER_USER = 'some_accountname'; const NEWSLETTER_PSWD = 'some_password'; } $config = 'ConfigureThisHost'; $config::NEWSLETTER_HOST; Please clarify and explain why you have done what you are suggesting. Roddy
  6. Yes, I have reviewed your most recent post and can understand well the gist of what you are proposing. I am at a loss, however, when it comes to your first line of code -- namely, require_once 'include/global.init.php'; What is the purpose of this statement? Roddy
  7. The Console is found differently in different browsers. In my old Firefox browser I simply click on the wrench in the bottom-right corner of my browser window. You can also find it in the Web Developer submenu of the Tools menu. It will say Web Console. In my old Chrome browser I click on the Developer submenu of the View menu and then on Javascript Console. Your initial view of the Console page will likely be intimidating, but do not be put off, for the Console page is far too powerful a tool to simply discount, because you do not understand it at first. After you have opened the Console page look for your cursor and enter some Javascript that includes some of the variables on your loaded page and watch what happens. Then go to your source code and enter the following with the appropriate substitutes into the body of your script. It will have no effect on your script, but it will tell you whether your script is doing what you think it should. console.log('variable_name: ' + variable_name); The result will appear in your Web Console page. From this you can determine the values of your variables as they are being created. Roddy
  8. COMMENT: Based upon the above discussion, my desire to accommodate my site's own specific needs with a minimum of additional study I have come up with the following tentative solution. As my site will send mail for a variety of purposes from a variety of email accounts -- some of which are repeatedly used, some of which are not, I have decided to create a different class for each purpose. The underlying logic is that it is easier to copy classes than it is to write a multi-purpose class that satisfies all of my PHPMailer needs. PURPORTED SATISFIED OBJECTIVES -- CONVENIENCE If ever there is a change of server, I can enter into the class and change the values of two constants knowing well that the changes will be passed along to all instances of PHPMailer. I can use the same class structure to create new classes for new default email accounts by simply changing the name of the class and the default values of the corresponding email account name and password. I can use the same class for a variety of different messages from the same email account and for a large number of different users with different email addresses. I can change the password at any time for all instances of the class no matter where they are employed within my site. I have full access to the content of any single instance where access would likely be advantageous to have including changing the subject heading of the mail or the content of the message. With three simple lines of code I can employ PHPMailer in nearly any place that I desire. <?php class PHPLetterMailer extends PHPMailer { const hostserver = "vps.antistate.io"; const smtp_port = 587; private $charset = 'UTF-8'; private $smpt_debug = 0; private $smpt_output = 'html'; private $smpt_auth = 'true'; private $email_account = '...'; private $password = '...'; private $sender_addr = 'newsletter@grammarcaptive.com'; private $sender_name = 'Grammar Captive'; private $replyto_addr = 'admin@grammarcaptive.com'; private $replyto_name = 'Grammar Captive Administration'; public $this->subject = ''; public $html_message = ''; public $alt_message = ''; public function __construct($username, $email) { parent::__construct() $this->addAddress($email, $username); $this->Host = self::hostserver; $this->Port = self::smpt_port; $this->isSMTP(); $this->SMTPDebug = $this->smpt_debug; $this->Debugoutput = $this->smpt_output; $this->SMTPAuth = $this->smpt_auth; $this->Username = $this->email_account; $this->Password = $this->password; $this->CharSet = $this->charset; $this->setFrom($this->sender_addr, $this->sender_name); $this->addReplyTo($this->replyto_addr, $this->replyto_name); $this->Subject = $this->subject; $this->msgHTML($this->html_message); $this->AltBody = $this->alt_message; } public function set_letter_contents($subject, $html_message, $alt_message) { $this->Subject = $subject; $this->msgHTML($html_message); $this->AltBody = $alt_message; } public function get_letter_contents() { return array($this->$subject, $this->html_message, $this->alt_message); } public function set_mail_account($mail_account, $password) { $this->mail_account = $mail_account; $this->password = $password; } public function set_sender($sender_addr, $sender_name) { $this->sender_addr = $sender_addr; $this->sender_name = $sender_name; ) public function get_sender() { return array($this->sender_addr, $this->sender_name); } public function set_replyto($replyto_addr, $replyto_name) { $this->replyto_addr = $replyto_addr; $this->replyto_name = $replyto_name; } public function get_replyto() { return array($this->replyto_addr, $this->replyto_name); } public function set_charset($charset) { $this->charset = $charset; } public function get_charset() { return $this->charset; } public function set_smpt_debug($debug, $output, $auth) { $this->smpt_debug = $debug; $this->smpt_output = $output; $this->smpt_auth = $auth; } public function get_smpt_debug() { return array ($this->smpt_debug, $this->smpt_output, $this->smpt_auth); } } ?> SAMPLE EXECUTION require_once('./_utilities/php/PHPMailerAutoload.php'); require_once('./_utilities/php/class.phplettermailer.php'); $email = 'name@sample.addr'; $username = 'sample_name'; $subject = 'Effortless Deployment'; $html_content = '<!DOCTYPE html><html> ... <table><tr><td>Content Here</td></tr></table ... </html>'; $alternate_message = 'Content Here'; $anInstance = new PHPLetterMailer($username, $email); $anInstance->set_letter_content($subject, $html_content, $alternate_message); if (!$anInstance->send()) { echo "PHPLetterMailer Error: " . $anInstance->ErrorInfo; } else { header('Location: ./gate_confirmation.html'); echo "Message sent!"; } QUESTION: Have I achieved my purported objectives?
  9. DSONESUK: The Matomo reporting API will return the data in a variety of ways depending on the value of the format parameter that I use to call it. I could easily have it returned in XML format, but am wondering why you suggest this format and not another. I have just gotten use to used to JSON and quite prefer it. Also, why do you suggest that it be entered into a database? Is this to protect it from public exposure? FUNCE: Could you direct me to the page where you have implemented your model. I am not sure that I understand it, and I would be loathe to reinventing the wheel , if it were not necessary. Roddy
  10. Thank you for responding. I hope that you are feeling well and that everything is still good at W3Schools. Please consider the following simplified piece of code and respond to the question that follows. It is a heuristic test case, if you will. PHP Class Inclusion require_once('./_utilities/php/PHPMailerAutoload.php'); require_once('./_utilities/php/class.globalmailer.php'); PHPGlobalMailer CLASS <?php class PHPGlobalMailer extends PHPMailer { private $mail; const hostserver = "vps.antistate.io"; const smtp_port = 587; private static $char_set = 'UTF-8'; public function __construct($email, $username) { $this->mail = new PHPMailer(); } $this->mail->CharSet=self::$char_set; } ?> SAMPLE APPLICATION $email = 'anonymous@antistate.io'; $username = 'Anonymous'; $user_mail = new PHPGlobalMailer($email, $username); Please answer the following questions: BACKGROUND: In the absence of the PHPGlobalMailer helping class, the character set of an instance of the PHPMailer class would be set by the following several lines of code: require_once('./_utilities/php/PHPMailerAutoload.php'); $mail = new PHPMailer(); $mail->CharSet = 'ISO-8859-1'; QUESTION ONE: Since the class PHPGlobalMailer has inherited the class PHPMailer is it even necessary to instantiate an instance of PHPMailer within the PHPGlobalMailer class in order to get an instance of PHPGlobalMailer to function, as if it were an instance of PHPMailer? QUESTION TWO: Using the PHPGlobalMailer class with or without the instantiation of a PHPMailer object would the following piece of code change the character set for the instance $user_mail? If so, would it change the character set only for the instance of $user_mail and no other? $user_mail->CharSet = 'ISO-8859-1'; It is my sincere hope that the above two questions are a clear expression of my confusion. Roddy
  11. Is JSG sick? Is he still with W3Schools? He appears to have disappeared. Roddy
  12. The Furtive Fox strikes again! Thank you for the wonderful elucidation, Ingolme. Roddy
  13. Do you use jQuery? $("body").css("background-color", "red"); and if you want to change more properties create an object, but notice how the formatting of each property-value pair changes. $("body").css({"background-color": "red", "font-size": "1.2em"}); Roddy
  14. JSG: Roddy: So, why not use inheritance and then include both classes outside of the child class? JSG: Roddy: The idea is to consolidate code so that I only have to copy and paste a single line rather than so many. Copying code sometimes leads to unwanted omissions or additions that lead to errors that often take forever to discover. Also, when I go to change my password I only want to have to do it once, and not within third party software that is subject to updates. Does this not make sense? JSG: Roddy: it is my understand that self is used to call the values of statically defined variables. Have a I misunderstood? JSG: Having better understood the problem do you still think that I should explore the factory pattern. Certainly I recall reading about it already back in 2010 when I was still in Thailand. Roddy
  15. Do you mean like setting up a CRON job that keeps the data current, but only runs once every six-hours or so? Roddy
  16. BACKGROUND: I am using AJAX to make a call to my Matomo database. This call runs in PHP and returns a set of data far too large for any particular use. This said, it can satisfy a lot of different needs separately. As I would like to provide users with the ability to build their own dynamic graphs from this very large data set I must plan an efficient strategy. From my still very naïve understanding of web applications I envision two possible scenarios only one of which is likely correct -- probably the second. AJAX calls PHP. PHP calls the Matomo reporting API Matomo reports and fills the PHP file with data Scenario One: AJAX makes makes a new call for the generation of each dynamic graph. Scenario Two: AjAX is only called once, and the same data set is used over and over again. QUESTION: If Scenario Two is the preferred method, as I strongly suspect is true, what is the best way of dealing with the data set? Do I reassign its contents to a separate file and then retrieve that portion of its contents required to build a new and different graph each and every time a new and different graph is desired? Or, do I simply leave the data where it is, and perform all subsequent calls to the PHP file from within the AJAX success function? Please elaborate your response. Roddy
  17. Thank you, ingolme, for the excellent presentation. As a new object will be added to the current search and recover operation with each new day, the number of objects required to generate the designated graph for which this function was created will soon become very large. It would appear that the two-step approach that you have outlined in the above diagrams is more efficient than the one-step approach initially suggested. What do you think? Roddy
  18. OK. I think I have it. Using your last example as my heuristic template, then 1) Create a space in memory called entry. var entry; 2) Fill that space with a new object called entry with each iteration of the $.each() function. entry = {}; // Create a new instance of an object and place it in the reserved memory for(var property in propertyArr) { var prop = propertyArr[property]; entry[prop] = object.prop; // Set the properties of the object } 3) From that storage space retrieve the current value of entry (the just created object) and add it to a predefined array called entryArr. entryArr.push(entry); Is this correct? Roddy
  19. You appear to be saying that each iteration of the same function is a different function. Have I understood correctly? Roddy
  20. That was it! Thank you, Ingolme. Now, if I could only understand it. There appears to be much more involved in this case than a simple matter of scope. How is it that I am able to recreate the same variable over and over again? Roddy var entry = {}:
  21. Almost there, a portion of the problem has been resolved with the following alteration. entry[prop] = object[prop]; I have just learned that there is a reason for having two ways to call the values of object properties. Unfortunately, the iteration is not working properly, for every object returns the same key-value pairs -- those of the last object only. Woe unto me! Roddy
  22. BACKGROUND: I have created a function whose job is to recreate an array of objects whose objects contain a vastly reduced, pre-selected number of property-value pairs. Although my function recreates the desired properties, the values are returned undefined. THE CODE: var propertyArr = ['serverDate', 'visitorId', 'visitCount']; function getEntries (propertyArr, inputArr) { var entryArr = []; var entry = {}; $.each(inputArr, function(key, object) { for(var property in propertyArr) { var prop = propertyArr[property]; entry[prop] = object.prop; } entryArr.push(entry); }); return entryArr; } console.log('entryArr', getEntries(propertyArr, jsonData)); THE RESULT SET entryArr Array [ Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, 90 more… ] where a typical object appears as follows: Object: serverDate: undefined visitorId: undefined visitCount: undefined QUESTION: Where have I gone wrong, and what can I do to fix my error. Roddy
  23. Funce, what make you think that he is placing a script tag in a style element. It appears to me that he wants to style a DOM element that he has not properly identified. For example, if he wants to change the background color of the body of his page he must write. window.body.style.backgroundColor = red Roddy
  24. OK. I believe that I have wisely ceded ground in a battle that I was not winning and redirected my energy along the path of least resistance. With the burden of ignorance finally removed, I was able to achieve a successful beachhead in the display of time series display. You can see the first result of this effort by clicking on the Charts & Graphs option in the Visitor Profile menu in the navigation bar on the Grammar Captive mainpage. I dare not count the number of hours spent on achieving this humble task, but when I contemplate everything that has resulted from the attempt, it was surely well worth the effort. Slowly, but surely I am conquering Matomo despite the lack of active support from the Matomo team. Roddy
  25. BACKGROUND: I am creating a custom class for use with PHPMailer that will hopefully eliminate redundancy in its application and even facilitate my use of the class. One of my questions deals with inheritance and the other has to do with scope. My current use of PHPMailer is quite simple. It consists of a folder containing four files: three of these are PHP class definitions and one of them is an autoloader. PHPMailer is called in the following manner: require_once '../../../PHPMailerAutoload.php'; $mail = new PHPMailer; Once the instance $mail has been created I have access to a large number of public functions that I have thought to consolidate into a single class of my own making called PHPGlobalMailer. My construction of this class appears awkward, and I would like to solicit your feedback in an attempt to remove its clumsiness. class PHPGlobalMailer { private $mail; private static $char_set = 'UTF-8'; private static $smtp_debug = 0; // SMTP::DEBUG_OFF (0): Disable debugging (default). // SMTP::DEBUG_CLIENT (1): Output messages sent by the client. // SMTP::DEBUG_SERVER (2): as 1, plus responses received from the server. // SMTP::DEBUG_CONNECTION (3): as 2, plus more information about the initial connection (used to diagnose STARTTLS failures. // SMTP::DEBUG_LOWLEVEL (4): as 3 (Verbose). private static $debug_output = 'html'; // 'echo': Plain text output (default). // 'html': Browser output. // 'error_log': Output to php.ini configured error.log. // function($str, $level) {echo "Debug Level: " . $level; "Error Message: " . $str;} private static $hostserver = '...'; private static $server_port = ...; private static $smpt_auth = 'true'; private static $mail_account_name = '...'; private static $mail_account_password = '...'; private static $from_mail_address = '...'; private static $from_mail_name = '...'; private static $reply_to_address = '...'; private static $reply_to_name = '...'; public $email = ''; public $name = ''; public $subject = ''; public $html_message = ''; public $alt_message = ''; public function __construct($email, $name, $subject, $html_message, $alt_message) { if ($this->mail new PHPMailer) { $this->mail->CharSet=self::$char_set; $this->mail->isSMPT(); $this->mail->SMTPDebug = self::$smpt_debug; $this->mail->Debugoutput = self::$debug_output; $this->mail->Host = self::$hostserver; $this->mail->Port = self::$server_port; $this->mail->SMPTAuth = self::$smpt_auth; $this->mail->Username = self::$mail_account_name; $this->mail->Password = self::$mail_account_password; $this->mail->setFrom(self::$from_mail_address, self::$from_mail_name); $this->mail->addReplyTo(self::$reply_to_address, self::$reply_to_name); $this->mail->addAddress($this->email, $this->name); $this->mail->Subject = $this->subject; $this->mail->msgHTML($html_message); $this->mail->altBody = $alt_message; } else { echo "Error: Failure to create new PHPMailer instance."; } } public function get_character_set() { return self::$char_set; } public function set_character_set($char_set) { self::$char_set = $char_set; } public function get_smtp_debug() { return self::$smtp_debug; } public function set_password($smtp_debug) { self::$smtp_debug = $smtp_debug; } public function get_debug_format() { return self::$debug_output; } public function set_debug_format($debug_output) { self::$debug_output = $debug_output; } public function get_debug_format() { return self::$debug_output; } public function set_debug_format($debug_output) { self::$debug_output = $debug_output; } public function get_mail_instance() { return $this->mail; } } The AWKWARDNESS 1) In order to make it work I must include PHPMailerAutoload.php file. Is there someway that I could avoid this, say through inheritance? 2) Notice that I am creating an instance of PHPMailer inside my class and then using the instance's public functions to modify it. Is this proper? If not, what would be a more appropriate way of constructing my class. 3) I am concerned that adjustments to an instance of PHPGlobalMailer will affect other instances created in a similar manner. For example, were I to change the value of $smpt_debug for a particular instance of PHPGlobalMailer would it not effect the value of that same parameter for other instances of PHPGlobalMailer? In effect, I would like full control of each instance, but still maintain constancy with regard to the $account_name and $account_password and other values across all instances. Could you please comment on each of three points. Roddy
×
×
  • Create New...