Jump to content

iwato

Members
  • Content Count

    1,328
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by iwato

  1. iwato

    A Flexible PHPMailer Factory Class with Traits

    This has already been achieved elsewhere, separately and differently, for each case. I am sure that the five lines of code of which you speak are included in the code that I have described above, else the code would not perform its most essential task. These lines of code, however, are hardly the purpose of my having gone through the trouble of writing the code. This said, do you find any errors in that what I have presented beyond those which Funce has already addressed? Roddy
  2. BACKGROUND: After a careful study of the use of traits I have come up with the following schema for PHPMailer factory class to cover a large variety of circumstances. ./global.init.php <?php error_reporting(E_ALL ^ E_STRICT); ini_set('error_log', __DIR__ . '/error.log'); include './php_mailer/PHPMailerAutoload.php'; include './classes/class.phpmailer_factory.php'; include './classes/trait.smtpserver_config.php'; include './classes/trait.phpmailer_newsletter_config.php'; include './classes/trait.phpmailer_verification_config.php': include './classes/trait.phpmailer_confirmation_config.php'; ?> trait.smtpserver_config.php <?php trait SmtpServerConfig { static $smtp_server = ''; static $smtp_port = ''; } ?> trait.phpmailer_newsletter_config.php <?php trait PHPMailerNewsletterConfig { use SmtpServerConfig; private $email_account_name = '...'; private $email_account_pswd = '...'} private $sender_addr = '...'; private $sender_name = '...'; private $replyto_addr = '...'; private $replyto_name = '...'; private $subject = '...'; private $html_message = '...'; private $alt_message = '...'; public function set_letter_contents($subject, $html_message, $alt_message) { $this->Subject = $subject; $this->msgHTML($html_message); $this->AltBody = $alt_message; } } ?> class.phpmailer_factory.php <?php class PHPMailerFactory extends PHPMailer { error_reporting(E_ALL ^ E_STRICT); ini_set('error_log', __DIR__ . '/error.log'); use SmtpServerConfig; private $use = ''; if ($this->use = 'newsletter') { use PHPMailerNewsletterConfig; } else if ($this->use = 'verification') { use PHPMailerVerifyConfig; } else if ($this->use = 'confirmation') { use PHPMailerConfirmConfig; } else { die('Please designate an appropriate trait'); } private $charset = ''; private $smtp_debug = 0; private $smtp_output = 'html'; private $smtp_auth = 'true'; public function __construct($use, $username, $email, $charset='UTF-8', $debug=0) { parent::__construct() $this->use = $use; $this->addAddress($email, $username); $this->CharSet = $this->charset; $this->Host = self::hostserver; $this->Port = self::smpt_port; $this->isSMTP(); $this->SMTPDebug = $this->smtp_debug; $this->Debugoutput = $this->smtp_output; $this->SMTPAuth = $this->smtp_auth; $this->Username = $this->email_account_name; $this->Password = $this->email_account_pswd; $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_charset($charset) { $this->charset = $charset; } public function get_charset() { return $this->charset; } } ?> Please comment on its efficacy. Your criticism and praise are both welcome. Roddy
  3. iwato

    A Flexible PHPMailer Factory Class with Traits

    Ingolme, I hope to correspond with my visitors in a variety of ways, and I find the language of PHPMailer awkward and confusing. I am trying to rewrite it in a way that I can understand quickly what is going on and make changes without a lot of research each and every time that I need to modify it. If the above can eventually be made to work, then I am very comfortable with the new structure. Where for example do you think the trait use SmtpServerConfig; should be entered? I have entered it in two places, and it likely needs to be entered only once. Roddy
  4. iwato

    A Flexible PHPMailer Factory Class with Traits

    Thank you, Funce. Both of those were silly errors on my part. I have been a little overwhelmed with this entire task, and if this is all the errors that can be found, then I will be most elated. Already you have earned a trophy. Simply I have not added it yet out of fear that everyone will stop looking for more holes to poke. :-) Roddy
  5. iwato

    JavaScript function collision?

    Is the $.when() function what you are looking for? This function provides a way to execute callback functions based on zero or more Thenable objects. These latter are usually Deferred objects that represent asynchronous events. Roddy
  6. iwato

    A Flexible PHPMailer Factory Class with Traits

    OK. I have tried to follow your factory design model as best as I could. Does the following look like it might have a chance of successful execution? Please pay careful attention to the use of the include and require_once commands, the $this variable, visibility issues, class hierarchy, trait insertion, and the overall effective strategy. And, please, if I have omitted anything or become redundant in some manner, bring it to my attention. NOTES: The three dots indicate that information must be entered. The double hash marks represent omitted files or lines of code that will be added later. The CODE /*********************************************/ ./global.init.php <?php error_reporting(E_ALL ^ E_STRICT); ini_set('error_log', __DIR__ . '/error.log'); include './php_mailer/PHPMailerAutoload.php'; include './classes/trait.smtpserver_config.php'; include './classes/php_mailer/phpmailer_abstract.php'; include './classes/class.phpmailer_newsletter_config.php'; // include './classes/class.phpmailer_verification_config.php': // include './classes/class.phpmailer_confirmation_config.php'; include './classes/class.phpmailer_factory.php'; ?> /*********************************************/ trait.smtpserver_config.php <?php trait SmtpServerConfig { static $smtp_server = ''; static $smtp_port = ''; } ?> /*********************************************/ class.phpmailer_abstract.php <?php class PHPMailerAbstract extends PHPMailer { use SmtpServerConfig; protected $charset = ''; protected $smtp_debug = 0; protected $smtp_output = 'html'; protected $smtp_auth = 'true'; public function __construct($username, $email, $charset='UTF-8', $debug=0) { parent::__construct() $this->addAddress($email, $username); $this->CharSet = $this->charset; $this->Host = self::hostserver; $this->Port = self::smpt_port; $this->isSMTP(); $this->SMTPDebug = $this->smtp_debug; $this->Debugoutput = $this->smtp_output; $this->SMTPAuth = $this->smtp_auth; $this->Username = $this->email_account_name; $this->Password = $this->email_account_pswd; $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_charset($charset) { $this->charset = $charset; } public function get_charset() { return $this->charset; } } ?> /*********************************************/ class.phpmailer_newsletter.php <?php class PHPMailerNewsletter extends PHPMailerAbstract { use SmtpServerConfig; private $email_account_name = '...'; private $email_account_pswd = '...'} private $sender_addr = '...'; private $sender_name = '...'; private $replyto_addr = '...'; private $replyto_name = '...'; private $subject = '...'; private $html_message = '...'; private $alt_message = '...'; public function set_letter_contents($subject, $html_message, $alt_message) { $this->Subject = $subject; $this->msgHTML($html_message); $this->AltBody = $alt_message; } } ?> /*********************************************/ class.phpmailer_factory.php'; <?php class PHPMailerFactory { public static function create($use_type, $username, $email, $charset='UTF-8', $debug=0) { switch ($use_type) { case 'newsletter': return new PHPMailerNewsletter($username, $email, $charset, $debug); // case 'verification': // return new PHPMailerVerification($username, $email, $charset, $debug); // case 'confirmation': // return new PHPMailerConfirmation($username, $email, $charset, $debug); default: throw new Exception('Invalid PHPMailer type.'); } } } ?> SAMPLE IMPLEMENTATION <?php $username = '...'; $email = '...'; $subject = '...'; $html_message = '...'; $alt_message = '...'; require_once = global.init.php $newsletter = new PHPMailerFactory('newsletter', $username, $email); $newsletter->set_letter_contents($subject, $html_message, $alt_message); $newsletter->send(); ?> Roddy
  7. iwato

    A Flexible PHPMailer Factory Class with Traits

    So, why must the parent class be abstract? For each abstract method that I put in the class I must duplicate that method in each of the child classes. Where is the gain in this? Roddy
  8. iwato

    how make many id in one getElementById

    Then too, you could use jQuery, it will do the counting for you. document.getElementById("Test1").value = Dotoff; document.getElementById("Test2").value = Dotoff; document.getElementById("Test3").value = Dotoff; <element1 class='test'></element1> <element2 class='test'></element2> <element3 class='test'></element3> $('.test').val('Dotoff'); Roddy
  9. iwato

    Installing MeCab

    More multi-tasking BACKGROUND: I discovered the following passage at <https://dev.mysql.com/doc/refman/5.7/en/fulltext-search-mecab.html> and would like to know clearly what it means The reasons that I do not understand it are several, but the primary results from this discovery within my on system. /usr/lib64/mysql/plugin/libpluginmecab.so /usr/lib64/mysql/mecab The above suggests that MeCab is already installed, does it not? However, when I try to alter my current table to accommodate the MeCab functionality, I am rejected with an error that reads MeCab is undefined. This suggests that it is not installed. Please advise. Roddy
  10. BACKGROUND: I have recently discovered GreenSock AP that is an interesting blend of Javascript and CSS for the purpose of producing animation. Like all new such discoveries I spend a lot of time exploring before I begin coding, and as a result learn a lot of new code and make more robust what I already know. In particular, I am curious about the value of the y parameter in the following .from() tween specification. TweenLite.from($box, 1, {y: '-=40', autoAlpha: 0, ease:Power4.easeInOut}); Now, $box refers to a jQuery object where $box = $('#box') and #box refers to a div whose id attribute has been set to box. QUESTIONS: 1) In the absence of the tween could the expression y: '-=40' be rewritten as box.y = '-=40'; box.y = '-=40'; 2) When the tween is invoked there is a downward vertical displacement of the object. The statement appears to set the starting position of the tween 40 pixels higher than its final position. In discursive English what exactly does the expression '-=40' say? I am baffled by the -= syntax. Roddy
  11. iwato

    Installing MeCab

    Please ignore this question. I just discovered the source of my problem. I was not logging in at the top of folder hierarchy. Yes, that was it. Will it, however, overcome the problem that I am having accessing my hostserver? Write now I am working with both BBEdit and FETCH, but am limited in my ability to access those folders closest to my root. Roddy
  12. iwato

    Installing MeCab

    Thank you. Yes, really that was all that I was asking. Now, I recall sometime back that you recommended a terminal editor that would not cost me and arm and leg in learning costs. What was it again, please? Roddy
  13. iwato

    Installing MeCab

    OK. So, how would you determine the "install path" of any installation, if you yourself did not perform the installation? Roddy
  14. iwato

    Installing MeCab

    Firstly, thank you for your response. Now, I understand what an environmental variable is. Unfortunately, the environmental variable MYSQL_HOME is not defined for my system. The MySQL statements mysqladmin global variables and mysqladmin variables show no variable with the name MYSQL_HOME, and the list for each statement is quite long. Please consider carefully the following and advise again: The Absolute Path to the mecabrc File is: /usr/lib64/mysql/mecab/etc/mecabrc The Absolute Path to the MySQL Application is: /usr/bin/mysql What I want to know is how to fill in MYSQL_HOME in the phrase MYSQL_HOME/lib/mecab/etc/mecabrc as designated by the following MySQL directive: /usr/bin/mysql_config_editor loose-mecab-rc-file=MYSQL_HOME/lib/mecab /etc/mecabrc Could you write the phrase based upon what is given? Roddy
  15. iwato

    Installing MeCab

    The Absolute Path to the mecabrc File is: /usr/lib64/mysql/mecab/etc/mecabrc The Absolute Path to the MySQL Application is: /usr/bin/mysql What I want to know is how to fill in MYSQL_HOME in the phrase MYSQL_HOME/lib/mecab/etc/mecabrc as designated by the following MySQL directive: /usr/bin/mysql_config_editor loose-mecab-rc-file=MYSQL_HOME/lib/mecab /etc/mecabrc Could you write the phrase based upon what is given? Roddy
  16. iwato

    A Flexible PHPMailer Factory Class with Traits

    I don't get it. Please, if you would, give me one example as how to get from if ($this->use = 'newsletter') { use PHPMailerNewsletterConfig; } else if ($this->use = 'verification') { use PHPMailerVerifyConfig; } else if ($this->use = 'confirmation') { use PHPMailerConfirmConfig; } else { die('Please designate an appropriate trait'); } } to what it is that you are describing. Roddy
  17. iwato

    Installing MeCab

    Installation path? I think in terms of relative and absolute paths. What exactly do you mean by installation path? In any case, the problem in utmost clarity is the following: The Absolute Path to the mecabrc File is: /usr/lib64/mysql/mecab/etc/mecabrc The Absolute Path to the MySQL Application is: /usr/bin/mysql What I want to know is how to fill in MYSQL_HOME in the phrase MYSQL_HOME/lib/mecab/etc/mecabrc as designated by the following MySQL directive: /usr/bin/mysql_config_editor loose-mecab-rc-file=MYSQL_HOME/lib/mecab/etc/mecabrc Roddy
  18. iwato

    Getting the last 4 uploaded images from a directory

    Where and how have you stored the images? In a folder or in a data base? If in a folder does each image have a filename that reflects the order in which it was saved? If in a data base, are you using a time stamp with each entry? Roddy
  19. iwato

    A Flexible PHPMailer Factory Class with Traits

    OK. So, I have verified what you stated, but I am not very happy with your remedy, for the whole purpose of my design was to eliminate having to create new variable names for each set of mailing uses, on the one hand, and not have to enter each and every value for each and every use as an argument of a constructor function on the other. What if I were to enter the values as elements of a unique array -- one for each use -- via the constructor function. In this way I could still use the same variable names for all uses, but perform the logic within the constructor function. How then would I access the arrays? Could I include a path to each via the global.init.php file? How would this work? Roddy
  20. iwato

    Installing MeCab

    And, if it is the location, how would you write it relative to /usr/bin/mysql? Or, would you use an absolute URL? Or, does it even make a difference? Also, I have chosen to use the mysql_config_editor, because I am not permitted to enter the required directories with my usual editing software. Moreover, I do not want to learn still another Terminal editor; they are simply cumbersome and so infrequently used. I would venture to guess that this is the reason mysql_config_editor was created. Roddy
  21. iwato

    A Flexible PHPMailer Factory Class with Traits

    Certainly not without the required data. For the moment I am only concerned about the overall concept. With the exception of my if-else statements I have adhered very closely to the manual's restrictions with regard to the use of traits. There was no example for my use of the if-else statements. This I invented on my own. As far as I can tell, the trait is little more than a code-assisted cut-and-paste -- well, this is least how it has been interpreted by several PHP manual contributors. It is not a precise analogy, because traits have class-like stand alone functionality, as well. Roddy
  22. iwato

    Installing MeCab

    Much research and exploration later I believe that all I really have to do is connect the dots. In https://dev.mysql.com/doc/refman/8.0/en/fulltext-search-mecab.html I am told Now, I have discovered the location of mecabrc /usr/lib64/mysql/mecab/etc/mecabrc Also, I have found something called /usr/bin/mysql_config_editor This program is in the same folder as mysql and the mysql_config and mysql_config-64 files Further, I have been told Further, the help manual to the mysql_config_editor provides the following MySQL Configuration Utility. Usage: mysql_config_editor [program options] [command [command options]] -#, --debug[=#] This is a non-debug version. Catch this and exit. -?, --help Display this help and exit. -v, --verbose Write more information. -V, --version Output version information and exit. Variables (--variable-name=value) and boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- ---------------------------------------- verbose FALSE Where command can be any one of the following : set [command options] Sets user name/password/host name/socket/port for a given login path (section). remove [command options] Remove a login path from the login file. print [command options] Print all the options for a specified login path. reset [command options] Deletes the contents of the login file. help Display this usage/help information. Now I am inclined to call the mecab_config_editor with the following command, but am unsure how to interpret MYSQL_HOME /usr/bin/mecab_config_editor loose-mecab-rc-file=MYSQL_HOME/lib/mecab/etc/mecabrc relative to /usr/bin/mysql QUESTION: How would you write the above mecab_config_editor command? Or, would you do something completely different? Roddy
  23. iwato

    A Nested Class? Or, Inheritance?

    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
  24. iwato

    A Nested Class? Or, Inheritance?

    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
  25. 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
×