[plugin] EnhancedPlaceholders: Add more placeholders

3rd party code for phpList

[plugin] EnhancedPlaceholders: Add more placeholders

Postby drmike » 7:54pm, Mon 18 Oct, 2010

This plugin enables one to create placeholders beyond those native to phpList.

The latest version (0.97) of this plugin is given with my post of Sat 08 Oct, 2011.

See my post of Tue 05 Jul, 2011 at 5:59pm, for some changes as to how this plugin is to be implemented.

(The version which was attached here had been updated to version 0.953 on 20110616 to fix problems reported by boxbreak on 14 and 16 June 2011. This version has now been removed. The latest version is 0.97 and attached to my post of Sat 08 Oct, 2011.)

Four types of placeholders are available: HTML, text, PHP:Date, and PHP:Eval. There are in addition four "hard-wired" placeholders (see below).

Enhanced Placeholders use the convention of "{" and "}" -- rather than "[" and "]" -- for placeholder delimiters. This allows "[" and "]" to be used for constructs in emails other than placeholders without creating possible conflicts.

These placeholders can be used in the subject line as well as the content of HTML and text messages. They can also be nested -- i.e., a placeholder can be used as part of a different placeholder.

Placeholders of the form {PLACEHOLDER} can be used instead of those of the form [PLACEHOLDER] for many instances of the latter.

You can create placeholders of a number of different types using the "add a new placeholder" link on the "Enhanced Placeholders" page of the phpList administrative section. Any of the placeholders that you add can then be edited or deleted/removed .

If the type of the placeholder is "HTML," a field is available for entering what should be used in the text portion of an email or in the subject line.

There are four "hard-wired" enhanced placeholders:
  • {EMAIL}: the email address of the person to whom an email is sent.
  • {MID}: the message id.
  • {UID}: the unique id of the person to whom the email is sent.
  • {VIA_LIST_NAMES}: the names of the lists via which a specific message is sent. The names of the lists are separated by a dash (-).
To install this plugin, put the code from the attached file (EnhancedPlaceholders_0-95.zip) in the phpList plugins directory and insert the lines:
Code: Select all
// Use the Enhanced Placeholders plugin to process placeholders before the legacy code does. MDG 10101020
   $GLOBALS['plugins']['enhancedPlaceholders']->processEnhancedPlaceholders($messageid, $userdata, $user_att_values, $html, $text, $cached[$messageid]["template"], $htmlmessage, $textmessage, $cached[$messageid]["subject"]);
// End of change for use the Enhanced Placeholders plugin to process placeholders before the legacy code does.

at line 239 of sendemaillib.php, just before "## Parse placeholders." (This is the line number for phpList 2.10.12. It may be different for other versions.)

This plugin is still a "beta" version. It has, however, been tested fairly extensively and found to work well for those cases for which it has been tested.

The option to use placeholders which evaluate PHP code has not been thoroughly tested. It is possible even that it may be found to caused more problems than it solves, in which case it will be removed from future versions.

When this plugin is used, in order to process queues using cron jobs one must use something similar to "What finally worked for me was to set up a curl call in a php script as follows:" at http://docs.phplist.com/CronJobExamples. Other approaches seem not to properly initialize the plugin.
Last edited by drmike on 7:45pm, Mon 10 Oct, 2011, edited 10 times in total.
drmike
PL Nut
 
Posts: 19
Joined: 8:40pm, Sat 14 Aug, 2010
Location: Chesterfield, MO, USA

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby pbraconnot » 5:53pm, Mon 15 Nov, 2010

Hi, nice work but I have this error when cueing, no message sent:

Started
Sending in batches of 30 emails
Processing has started, 2 message(s) to process.
Please leave this window open. You have batch processing enabled, so it will reload several times to send the messages. Reports will be sent by email to my@email.com
Processing message 46
Looking for users
Found them: 1 to process
Script stage: 4
Finished, Nothing to do
Finished, All done

my system
# phplist version: 2.10.12
# PHP version: 5.2.14
# Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12
# Webserver: Apache
# Mysql Info: 5.1.49-gpl-log
# PHP Modules:
pbraconnot
phpLister
 
Posts: 9
Joined: 3:04pm, Thu 11 Nov, 2010

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby drmike » 6:32pm, Mon 15 Nov, 2010

This may have to do with the fact that phpList will not send the same message twice to the same recipient, except under the specific option to do so. I frequently ran into this feature when testing what I did and had to create a new message for each test.
drmike
PL Nut
 
Posts: 19
Joined: 8:40pm, Sat 14 Aug, 2010
Location: Chesterfield, MO, USA

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby pbraconnot » 8:16pm, Mon 15 Nov, 2010

I can see default plugins beside default placeholers in the admin page but defaut placeholers is giving these errors on top of the admin page when present in plugins folder:

Notice: Undefined index: database_connection in /home/.../lists/admin/mysql.inc on line 113

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/.../lists/admin/mysql.inc on line 113

Notice: Undefined index: database_connection in /home/.../lists/admin/mysql.inc on line 115

Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/.../lists/admin/mysql.inc on line 52

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/.../lists/admin/mysql.inc on line 168

and more...

thanks
pbraconnot
phpLister
 
Posts: 9
Joined: 3:04pm, Thu 11 Nov, 2010

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby drmike » 8:41pm, Mon 15 Nov, 2010

This would appear to be something related to your configuration parameters for MySQL (lines 21-31 of ...lists/config/config.php), rather anything related to the plugin.
drmike
PL Nut
 
Posts: 19
Joined: 8:40pm, Sat 14 Aug, 2010
Location: Chesterfield, MO, USA

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby pbraconnot » 8:53pm, Mon 15 Nov, 2010

Hi, thanks for the quick response,

I don't think it is the MySql configuration, PHP List is working normal without Enhanced Placeholders Plugin. these errors show only when the plugin is enabled.

Also the messages get stuck in cue status "submitted" but never come.

I am making new messages each time and the script level 4 message still appearing.
pbraconnot
phpLister
 
Posts: 9
Joined: 3:04pm, Thu 11 Nov, 2010

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby pbraconnot » 9:39pm, Mon 15 Nov, 2010

commented line 49 in enhancedPlaceholers.php and errors are gone

// error_reporting(E_ALL | E_STRICT);

still trying to make it work though, this plugin hangs the cue.
pbraconnot
phpLister
 
Posts: 9
Joined: 3:04pm, Thu 11 Nov, 2010

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby drmike » 4:37am, Tue 16 Nov, 2010

Are you using PHP 5 and MySQL 5? I developed the plugin in that environment. Perhaps earlier version of PHP and/or MySQL do not play well with it. It has also only been tested with phpList 2.10.12. Perhaps it does not work with the version you are using...
drmike
PL Nut
 
Posts: 19
Joined: 8:40pm, Sat 14 Aug, 2010
Location: Chesterfield, MO, USA

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby duncanc » 1:48pm, Sat 27 Nov, 2010

I couldn't get the original code to work, processing the queue seemed to hang, as it is not clear to me whether plugins are loaded when processqueue is run from a command line or cron job.
I have changed the modification to sendemaillib.php to create a new instance of the plugin before calling it:
Code: Select all
    // Use the Enhanced Placeholders plugin to process placeholders before the legacy code does. MDG 10101020
      include_once PLUGIN_ROOTDIR."/" . 'enhancedPlaceholders.php';
      $class = new enhancedPlaceholders();
      $class->processEnhancedPlaceholders($messageid, $userdata, $user_att_values, $html, $text, $cached[$messageid]["template"], $htmlmessage, $textmessage, $cached[$messageid]["subject"]);
    // End of change for use the Enhanced Placeholders plugin to process placeholders before the legacy code does.


Seems to work correctly when processing the queue either through the admin UI or command line/cron job.
duncanc
Moderator
 
Posts: 2440
Joined: 6:34am, Sat 08 May, 2010
Location: London

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby boxbreak » 9:17pm, Tue 14 Jun, 2011

This plugin is a fantastic idea. I installed it, but get the following error within the Admin page (/admin/?page=main&pi=enhancedPlaceholders&id=add_new_placeholder):

Sorry a software error occurred:
Please report a bug when reporting the bug, please include URL and the entire content of this page.

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/myhost/public_html/phplist/admin/plugins/enhanced_placeholders/enhancedPlaceholdersAdmin.php on line 78
phplist version 2.10.12

Sorry a software error occurred:
Please report a bug when reporting the bug, please include URL and the entire content of this page.

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/myhost/public_html/phplist/admin/plugins/enhanced_placeholders/enhancedPlaceholdersAdmin.php on line 78
phplist version 2.10.12

Sorry a software error occurred:
Please report a bug when reporting the bug, please include URL and the entire content of this page.

Warning: Invalid argument supplied for foreach() in /home/myhost/public_html/phplist/admin/plugins/enhanced_placeholders/enhancedPlaceholdersAdmin.php on line 80
phplist version 2.10.12



I do not know if this is relevant, but I had to first make the following change in order to get the Plugin's Admin screen to load, based on my server set-up:

File: plugins/enhanced_placeholders/enhancedPlaceholdersAdmin.php

Line 78 Original
Code: Select all
      echo '<p><a href="/admin/?page=main&pi=enhancedPlaceholders&id='.$this->add_new_placeholder.'">add a new placeholder</a><br /><br /><hr/></p>';


Line 78 Modified
Code: Select all
      echo '<p><a href="/phplist/admin/?page=main&pi=enhancedPlaceholders&id='.$this->add_new_placeholder.'">add a new placeholder</a><br /><br /><hr/></p>';
boxbreak
phpLister
 
Posts: 7
Joined: 3:34pm, Thu 13 Aug, 2009

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby duncanc » 7:31am, Thu 16 Jun, 2011

I found the same problems that you describe and also the mysql error messages reported by other posters.

I have made some fixes for those problems and, to solve the mysql error messages, restructured the plugin into two classes, one for the admin and the second for the population of placeholders when a message is sent. The version works fine for me, let me know if you want to try it.
duncanc
Moderator
 
Posts: 2440
Joined: 6:34am, Sat 08 May, 2010
Location: London

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby boxbreak » 11:12am, Thu 16 Jun, 2011

Absolutely! Please post here.
boxbreak
phpLister
 
Posts: 7
Joined: 3:34pm, Thu 13 Aug, 2009

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby duncanc » 7:50pm, Thu 16 Jun, 2011

Here is my modified version of the plugin that fixes various problems.
Two changes are required to file admin/sendemaillib.php. Copy and paste the text rather than retyping.

1) add this line after the require statement on line 2

Code: Select all
include_once PLUGIN_ROOTDIR.'/enhanced_placeholders/enhancedPlaceholdersPopulate.php';


2) add these lines immediately before line 240 , ## Parse placeholders

Code: Select all
  /*
   *   Addition to process enhanced placeholders
   */
  $obj = enhancedPlaceholdersPopulate::instance();
  $obj->processEnhancedPlaceholders(
   $messageid, $userdata, $user_att_values, $html, $text, $cached[$messageid]['template'],
   $htmlmessage, $textmessage, $cached[$messageid]['subject']
  );
Attachments
EnhancedPlaceholders.zip
(8.76 KiB) Downloaded 255 times
duncanc
Moderator
 
Posts: 2440
Joined: 6:34am, Sat 08 May, 2010
Location: London

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby boxbreak » 8:06pm, Thu 16 Jun, 2011

Thank you. The errors persist on the Add New Placeholder screen. Here they are:

Sorry a software error occurred:
Please report a bug when reporting the bug, please include URL and the entire content of this page.

Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/myhost/public_html/phplist/admin/plugins/enhanced_placeholders/enhancedPlaceholdersAdmin.php on line 78
phplist version 2.10.12

Sorry a software error occurred:
Please report a bug when reporting the bug, please include URL and the entire content of this page.

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/myhost/public_html/phplist/admin/plugins/enhanced_placeholders/enhancedPlaceholdersAdmin.php on line 78
phplist version 2.10.12

Sorry a software error occurred:
Please report a bug when reporting the bug, please include URL and the entire content of this page.

Warning: Invalid argument supplied for foreach() in /home/myhost/public_html/phplist/admin/plugins/enhanced_placeholders/enhancedPlaceholdersAdmin.php on line 80
phplist version 2.10.12
boxbreak
phpLister
 
Posts: 7
Joined: 3:34pm, Thu 13 Aug, 2009

Re: [plugin:EnhancedPlaceholders] Add more placeholders

Postby duncanc » 9:15pm, Thu 16 Jun, 2011

From the references to line numbers 78 and 80 in file enhancedPlaceholdersAdmin.php it looks like you are still using the old version.

Possibly you did not install the new version correctly. Copy the zip file to your plugins directory and then expand in that directory. Then should have
enhancedPlaceholders.php
directory enhanced_placeholders containing
main.php
enhancedPlaceholdersPopulate.php
enhancedPlaceholdersAdmin.php
duncanc
Moderator
 
Posts: 2440
Joined: 6:34am, Sat 08 May, 2010
Location: London

Next

Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 3 guests