Plugin Directory

Changeset 2198016


Ignore:
Timestamp:
11/21/2019 12:18:12 PM (6 years ago)
Author:
restpack
Message:

enhacement

Location:
save-as-pdf/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • save-as-pdf/trunk/readme.txt

    r2196715 r2198016  
    44Requires at least: 4.1
    55Tested up to: 5.2.1
    6 Stable tag: 1.7
     6Stable tag: 1.8
    77Requires PHP: 5.2.4
    88License: GNUGPLv3
     
    5555== Changelog ==
    5656
     57= 1.8 =
     58* Improvements
     59
    5760= 1.7 =
    5861* Minor
  • save-as-pdf/trunk/restpack.js

    r2196715 r2198016  
    77  x.parentNode.insertBefore(s, x);
    88})(window.document);
    9 
    10 window.document.addEventListener("click", function (event) {
    11   if (event.target.classList.contains("restpack-api")) {
    12     event.preventDefault();
    13     var elem = event.target;
    14 
    15     var props = elem.getAttribute("data-props");
    16 
    17     document.body.style.cursor = "wait";
    18     var ajaxcallurl = window.ajaxcallurl || [window.location.protocol, '', window.location.host, 'wp-admin', 'admin-ajax.php'].join('/');
    19 
    20     fetch(ajaxcallurl, {
    21       method: "POST",
    22       body: "action=restpack_ajax",
    23       headers: {
    24         "Content-Type": "application/x-www-form-urlencoded;"
    25       }
    26     })
    27       .then(function (data) {
    28         document.body.style.cursor = "default";
    29         return data.json();
    30       })
    31       .then(function (data) {
    32         if (data.error || data.errors) return alert(data.error || JSON.stringify(data.errors));
    33         window.open(data.image);
    34       })
    35       .catch(function (error) {
    36         alert(error);
    37       });
    38 
    39     try {
    40       JSON.parse(props);
    41     } catch (e) { }
    42 
    43     console.log("clicked");
    44   }
    45 });
  • save-as-pdf/trunk/save-as-pdf.php

    r2196715 r2198016  
    55 * Plugin URI: https://restpack.io/html2pdf
    66 * Description: Allows visitors to save current page as PDF file
    7  * Version: 1.7
     7 * Version: 1.8
    88 * Text Domain: save-as-pdf
    99 * Author: Restpack Inc
     
    306306    );
    307307
     308    add_settings_field($this->key("width"), 'Width', array(&$this, 'render_settings_field'), __FILE__, $third_section, array(
     309      "key" => "width"
     310    ));
     311
    308312    add_settings_field(
    309313      $this->key("emulate_media"),
     
    330334
    331335    add_settings_field(
     336      $this->key("form_data"),
     337      'Get dynamic form data',
     338      array(&$this, 'render_settings_field'),
     339      __FILE__,
     340      $third_section,
     341      array(
     342        "key" => "form_data"
     343      )
     344    );
     345
     346    add_settings_field(
    332347      $this->key("block_cookie_warnings"),
    333348      'Block EU cookie warning',
     
    399414        break;
    400415
     416
     417      case 'form_data':
    401418      case 'block_ads':
    402419      case 'block_cookie_warnings':
     
    496513  {
    497514    $options = get_option($this->key("options"));
     515
     516    $_props = array(
     517      'pdf_page' => $options['pdf_page'],
     518      "pdf_margins" => $options['pdf_margins'],
     519      "pdf_header" => $options['pdf_header'],
     520      "pdf_orientation" => $options['pdf_orientation'],
     521      "pdf_footer" => $options['pdf_footer'],
     522      "emulate_media" => $options['emulate_media'],
     523      "js" => $options['js'],
     524      "css" => $options['css'],
     525      "block_cookie_warnings" => $options['block_cookie_warnings'],
     526      "block_ads" => $options['block_ads'],
     527      "filename" => $options['filename'],
     528      "headers" => $options['http_headers'],
     529      "access_token" => $options['api_key'],
     530      'delay' => $options['delay'],
     531    );
     532
     533    if($options['form_data'])
     534      $_props["private"] = true;
     535
    498536    $props = shortcode_atts(
    499       array(
    500         'pdf_page' => $options['pdf_page'],
    501         'pdf_orientation' => $options['pdf_orientation'],
    502         'delay' => $options['delay']
    503       ),
     537      array_filter($_props),
    504538      $attrs
    505539    );
    506 
    507     $have_key = $options['api_key'];
    508540
    509541    $button_text = $options['button_text'];
     
    514546    $query = http_build_query($props);
    515547
    516     return "<a class=\"restpack-button" .
    517       ($have_key ? ' restpack-api' : '') .
    518       "\" data-props=" .
    519       json_encode($props) .
    520       (!$have_key ? " href=\"https://restpack.io/html2pdf/save-as-pdf?" . $query . "\"" : " href='#'") .
    521       ">
    522     <img style='display: inline; width:" .
    523       $options['button_width'] .
    524       "' src='" .
    525       plugin_dir_url(__FILE__) .
    526       'assets/' .
    527       $options['button_icon'] .
    528       "' alt='" .
    529       $button_text .
    530       "' title='" .
    531       $button_text .
    532       "'/>
    533     " .
    534       $button_text .
    535       "</a>";
    536   }
     548    return "<a class=\"restpack-button\"  href=\"https://restpack.io/html2pdf/save-as-pdf?" . $query . "\" data-props=" . json_encode($props) .">
     549      <img style='display: inline; width:" . $options['button_width'] . "' src='" . plugin_dir_url(__FILE__) . 'assets/' . $options['button_icon'] . "' alt='" . $button_text . "' title='" . $button_text . "'/> " . $button_text . "</a>";
     550   }
    537551
    538552  function restpack_ajax()
     
    593607    wp_die();
    594608  }
     609
     610
    595611  function render_settings_page()
    596612  {
Note: See TracChangeset for help on using the changeset viewer.