How to add print option to any plugin

Jimako, Mon Oct 29 2018, 13:07

Adding print options has 2 parts: 1. add button with option /link to print displayed page 2. solve printing itself.

Adding print button

Already existing print button in core: news: -
new way
{PRINTICON} {PRINTICON: class=btn btn-default} forum: -
semiold way
{PRINTITEM}
PRINTICON
require_once(e_HANDLER.'emailprint_class.php');
return emailprint::render_emailprint($plugin_name, $record_id, 2, $parm);
note: this shortcode can be used only for news. There are attemps to make it as general solution, but it's not finished, print.php still counts of text "plugin" in first parameter.
{PRINTITEM}
using single shortcode 
{PRINT_ITEM=Print^plugin:forum. $record_id}
for any of this way link for printing is created this way: href='".e_HTTP."print.php?".$print.".".$record_id."' where $print is 'news' or plugin:$plugin_name For custom plugin is maybe better direct method (
old way
) Note: I don't see point to call shortcode, then template for next shortcode inside. Example: {REVIEWER_VIEW_PRINT} - custom shortcode
SC_BEGIN REVIEWER_VIEW_PRINT
global $reviewer_reviewer_ep;
$reviewer_print .= " <a href='../../print.php?plugin:reviewer.$reviewer_reviewer_ep' title='" . REVIEWER_V022 . "'><img src='" . e_IMAGE . "generic/" . IMODE . "/printer.png' style='border:0;' alt='" . REVIEWER_V022 . "' /></a>";
return $reviewer_print;
SC_END
Note: There is still used ICONPRINT with path THEME."images/".ICONPRINT or e_IMAGE_ABS."generic/printer.png"; and hardcoded glyphicon icons: <span class='glyphicon glyphicon-print' aria-hidden='true'></span>

Printing itself

Printing is managed by print.php file. Each printable plugin has to have e_emailprint.php addons. Function print_item() defines what is printed. News are exception, news are reading directly in print.php and news_template is used for output. Print.php can use THEME.'print_template.php' there is no core print_template.php file. If template doesn't exist, it just display print content with white background and button with window.print(). Note: old Reviewer plugin is example of fully customized solution for plugin with printing option.