Esempio n. 1
0
include "lib/GrabzItClient.class.php";
include "config.php";
$message = '';
if (count($_POST) > 0) {
    if (isset($_POST["delete"]) && $_POST["delete"] == 1) {
        $files = glob('results/*');
        foreach ($files as $file) {
            if (is_file($file)) {
                unlink($file);
            }
        }
    } else {
        $url = $_POST["url"];
        $format = $_POST["format"];
        try {
            $grabzIt = new GrabzItClient($grabzItApplicationKey, $grabzItApplicationSecret);
            if ($format == "pdf") {
                $grabzIt->SetPDFOptions($url);
            } else {
                $grabzIt->SetImageOptions($url);
            }
            $grabzIt->Save($grabzItHandlerUrl);
        } catch (Exception $e) {
            $message = $e->getMessage();
        }
    }
}
?>
<html>
<head>
<title>GrabzIt Demo</title>
Esempio n. 2
0
<?php

include "lib/GrabzItClient.class.php";
include "config.php";
//This PHP file handles the GrabzIt callback
$message = $_GET["message"];
$customId = $_GET["customid"];
$id = $_GET["id"];
$filename = $_GET["filename"];
$format = $_GET["format"];
//Custom id can be used to store user ids or whatever is needed for the later processing of the
//resulting screenshot
$grabzIt = new GrabzItClient($grabzItApplicationKey, $grabzItApplicationSecret);
$result = $grabzIt->GetResult($id);
if (!$result) {
    return;
}
//Ensure that the application has the correct rights for this directory.
file_put_contents("results" . DIRECTORY_SEPARATOR . $filename, $result);
 /**
  * Module settings
  *  
  * @access public
  */
 function settings()
 {
     $message = '';
     $message_type = '';
     $this->EE->load->library('hyperlink_lib');
     //save
     if (isset($_POST['button_submit'])) {
         $validation_errors = array();
         //fetch settings
         $settings = array();
         $settings["screenshot_service"] = $this->EE->input->post('screenshot_service');
         $settings["screenshot_services"] = $this->EE->input->post('screenshot_services');
         $settings["screenshot_dir"] = $this->EE->input->post('screenshot_dir');
         $settings["publish_entry_with_invalid_links"] = $this->EE->input->post('publish_entry_with_invalid_links');
         $settings["schedule_validation_of_links"]['schedule'] = isset($_POST['schedule_validation_of_links']['schedule']);
         $settings["schedule_validation_of_links"]['change_status'] = $_POST['schedule_validation_of_links']['change_status'];
         $settings = $this->_settings_merge($this->EE->hyperlink_lib->default_settings, $settings);
         //validate
         $this->EE->lang->load('form_validation');
         if ($settings['screenshot_service'] == 'GrabzIt') {
             if (!$settings["screenshot_services"]["GrabzIt"]["api_key"]) {
                 $validation_errors["screenshot_services"]["GrabzIt"]["api_key"] = sprintf(lang("required"), 'API key');
             }
             if (!$settings["screenshot_services"]["GrabzIt"]["api_secret"]) {
                 $validation_errors["screenshot_services"]["GrabzIt"]["api_secret"] = sprintf(lang("required"), 'API secret');
             }
             $max_height = $this->EE->hyperlink_lib->grabzit_packages[$settings["screenshot_services"]["GrabzIt"]["service_package"]]['max_height'];
             $max_width = $this->EE->hyperlink_lib->grabzit_packages[$settings["screenshot_services"]["GrabzIt"]["service_package"]]['max_width'];
             if ($max_width < (int) $settings["screenshot_services"]["GrabzIt"]["image_width"]) {
                 $validation_errors["screenshot_services"]["GrabzIt"]["image_width"] = sprintf(lang("msg_error_image_width_too_big"), $max_width);
             }
             if ($max_height < (int) $settings["screenshot_services"]["GrabzIt"]["image_height"]) {
                 $validation_errors["screenshot_services"]["GrabzIt"]["image_height"] = sprintf(lang("msg_error_image_height_too_big"), $max_height);
             }
             if ((int) $settings["screenshot_services"]["GrabzIt"]["image_width"] < 20) {
                 $validation_errors["screenshot_services"]["GrabzIt"]["image_width"] = sprintf(lang("msg_error_image_width_too_small"), 20);
             }
             if ((int) $settings["screenshot_services"]["GrabzIt"]["image_height"] < 20) {
                 $validation_errors["screenshot_services"]["GrabzIt"]["image_height"] = sprintf(lang("msg_error_image_height_too_small"), 20);
             }
             if (!$settings["screenshot_dir"]) {
                 $validation_errors["screenshot_dir"] = sprintf(lang("required"), lang("label_download_directory"));
             }
             if ($settings["screenshot_services"]["GrabzIt"]["api_key"] && $settings["screenshot_services"]["GrabzIt"]["api_secret"]) {
                 include_once "libraries/grabzit/GrabzItClient.class.php";
                 try {
                     $grabzIt = new GrabzItClient($settings["screenshot_services"]["GrabzIt"]["api_key"], $settings["screenshot_services"]["GrabzIt"]["api_secret"]);
                     $id = $grabzIt->TakePicture("http://www.google.com", null, null, 1024, 768, $max_width, $max_height);
                 } catch (Exception $e) {
                     if (strpos($e->getMessage(), 'Image height too large') !== FALSE) {
                         $validation_errors["screenshot_services"]["GrabzIt"]["service_package"] = lang("msg_error_invalid_service_package");
                     } elseif (strpos($e->getMessage(), 'Invalid signature detected') !== FALSE) {
                         $validation_errors["screenshot_services"]["GrabzIt"]["api_secret"] = $e->getMessage();
                     } else {
                         $validation_errors["screenshot_services"]["GrabzIt"]["api_key"] = $e->getMessage();
                     }
                 }
             }
         }
         if (count($validation_errors)) {
             $message = lang('msg_error_settings_validaton_failed');
             $message_type = 'error';
         } else {
             $data = array('settings' => base64_encode(serialize($settings)));
             $this->EE->db->update('exp_hyperlink_settings', $data, 'site_id = ' . $this->EE->config->item('site_id'));
             $message = lang('msg_settings_saved');
             $message_type = 'success';
         }
     }
     $sites = $this->EE->db->select("*")->from('exp_sites')->order_by('site_id', 'ASC')->get()->result_array();
     //** -----------------------------
     //**	directory options
     //** -----------------------------
     $directory_options = array('' => lang('label_choose_directory'));
     foreach ($sites as $site) {
         $site_dirs = array();
         foreach ($this->EE->hyperlink_lib->upload_preferences() as $preference) {
             if ($preference["site_id"] == $site["site_id"]) {
                 $site_dirs[$preference["id"]] = $preference["name"];
             }
         }
         $directory_options[$site["site_label"]] = $site_dirs;
     }
     //** -----------------------------
     //**	grabzit_packages
     //** -----------------------------
     $grabzit_packages = array();
     foreach ($this->EE->hyperlink_lib->grabzit_packages as $package_id => $package) {
         $grabzit_packages[$package_id] = $package["name"];
     }
     //** -----------------------------
     //**	statuses
     //** -----------------------------
     $statuses = array('' => lang('label_status_do_not_change'));
     foreach ($this->EE->db->select("status")->from("exp_statuses")->get()->result() as $status) {
         $statuses[$status->status] = $status->status;
     }
     //** -----------------------------
     //**	get ACT
     //** -----------------------------
     $act_id = (int) @$this->EE->db->select('action_id')->from('exp_actions')->where('class', 'Hyperlink')->where('method', 'hyperlink_schedule_validation_of_links')->get()->row()->action_id;
     $hyperlink_schedule_validation_url = $this->EE->functions->create_url('/') . '?ACT=' . $act_id;
     $vars = array("settings" => isset($_POST['button_submit']) ? $settings : $this->EE->hyperlink_lib->settings, "directory_options" => $directory_options, "grabzit_packages" => $grabzit_packages, "statuses" => $statuses, "hyperlink_schedule_validation_url" => $hyperlink_schedule_validation_url, "message" => $message, "message_type" => $message_type, "validation_errors" => isset($validation_errors) ? $validation_errors : null);
     return $this->_view('settings', $vars, TRUE, lang('title_settings'));
 }
Esempio n. 4
0
 function make_images($user)
 {
     $files = $this->projects[$user]["files"]["html"];
     if (!$files) {
         echo "pole html/PHP faile  <br>";
         return;
     }
     $grabzItHandlerUrl = $this->base_url . "lib/webimg/handler.php";
     $i = 0;
     try {
         global $grabzItApplicationKey, $grabzItApplicationSecret;
         foreach ($files as $file) {
             $grabzIt = new GrabzItClient($grabzItApplicationKey, $grabzItApplicationSecret);
             $grabzIt->SetImageOptions($this->base_url . $file, $user . "-" . $i++, null, null);
             $grabzIt->Save($grabzItHandlerUrl);
         }
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
 /**
  * Take screenshot
  *
  * @return	
  */
 function take_screenshot($hyperlink_id, $screenshot_id = FALSE)
 {
     //**
     //**	Get info about link
     //**
     $query = $this->EE->db->select('*')->from('exp_hyperlink')->where('hyperlink_id', $hyperlink_id)->where('hyperlink_http_status >=', 200)->where('hyperlink_http_status <', 400)->get();
     if ($query->num_rows == 0) {
         return FALSE;
     }
     $hyperlink = $query->row_array();
     //**
     //**	Load settings
     //**
     $this->_load_settings($hyperlink["site_id"]);
     //**
     //**	No Dir, No Screenshot
     //**
     if (!$this->settings['screenshot_dir']) {
         return FALSE;
     }
     //**
     //**	No Service, No Screenshot
     //**
     if (!$this->settings['screenshot_service']) {
         return FALSE;
     }
     //**	---------------------------------------------
     //**	GrabzIt
     //**	---------------------------------------------
     if ($this->settings['screenshot_service'] == 'GrabzIt') {
         include_once "grabzit/GrabzItClient.class.php";
         //if EXPIRED, get new request
         if ($hyperlink['screenshot_status'] == 'expired') {
             $screenshot_id = false;
         }
         try {
             //one connect is ok
             global $__GRABZIT_CLIENT__;
             if (!isset($__GRABZIT_CLIENT__)) {
                 $__GRABZIT_CLIENT__ = new GrabzItClient($this->settings['screenshot_services']['GrabzIt']['api_key'], $this->settings['screenshot_services']['GrabzIt']['api_secret']);
             }
             if (!$screenshot_id) {
                 $screenshot_id = (string) $__GRABZIT_CLIENT__->TakePicture($hyperlink['hyperlink_url'], null, null, $this->settings['screenshot_services']['GrabzIt']['browser_width'], $this->settings['screenshot_services']['GrabzIt']['browser_height'], $this->settings['screenshot_services']['GrabzIt']['image_width'], $this->settings['screenshot_services']['GrabzIt']['image_height']);
                 if ($screenshot_id) {
                     $data = array('screenshot_id' => $screenshot_id, 'screenshot_status' => 'send');
                 } else {
                     $data = array('screenshot_error' => 'GrabzIt request failed', 'screenshot_status' => 'error');
                 }
                 $this->EE->db->update('exp_hyperlink', $data, 'hyperlink_id = ' . (int) $hyperlink_id);
             }
             $screenshotTaked = 0;
             //get status
             if ($screenshot_id) {
                 $status = $__GRABZIT_CLIENT__->GetStatus($screenshot_id);
                 if ($status->Processing) {
                     $data = array('screenshot_id' => $screenshot_id, 'screenshot_status' => 'processing');
                     $this->EE->db->update('exp_hyperlink', $data, 'hyperlink_id = ' . (int) $hyperlink_id);
                 }
                 if ($status->Cached) {
                     $data = array('screenshot_id' => $screenshot_id, 'screenshot_status' => 'cached');
                     $this->EE->db->update('exp_hyperlink', $data, 'hyperlink_id = ' . (int) $hyperlink_id);
                     $screenshotTaked = 1;
                 }
                 if ($status->Expired) {
                     $data = array('screenshot_status' => 'expired', 'screenshot_error' => $status->Message);
                     $this->EE->db->update('exp_hyperlink', $data, 'hyperlink_id = ' . (int) $hyperlink_id);
                     //log errors
                     $this->errors[] = $status->Message;
                 }
             }
             if ($screenshotTaked) {
                 $screenshot = $__GRABZIT_CLIENT__->GetPicture($screenshot_id);
                 $screenshot_name = 'screenshot-grabzit-' . uniqid() . '.jpg';
                 $screenshot_dir = $this->settings['screenshot_dir'];
                 if ($this->save_image($screenshot_name, $screenshot, $screenshot_dir)) {
                     $data = array('screenshot_name' => $screenshot_name, 'screenshot_dir' => $screenshot_dir, 'screenshot_status' => 'ok', 'screenshot_error' => null);
                     $this->EE->db->update('exp_hyperlink', $data, 'hyperlink_id = ' . (int) $hyperlink_id);
                 }
             }
         } catch (Exception $e) {
             $this->errors[] = 'Caught exception: ' . $e->getMessage();
             $data = array('screenshot_status' => 'error', 'screenshot_error' => $e->getMessage());
             $this->EE->db->update('exp_hyperlink', $data, 'hyperlink_id = ' . (int) $hyperlink_id);
             return FALSE;
         }
     }
 }
Esempio n. 6
0
     $_POST = array_map('stripslashes', $_POST);
 }
 if (isset($_POST["delete"]) && $_POST["delete"] == 1) {
     $files = glob('results/*');
     foreach ($files as $file) {
         if (is_file($file)) {
             unlink($file);
         }
     }
 } else {
     $url = $_POST["url"];
     $html = $_POST["html"];
     $format = $_POST["format"];
     $convert = $_POST["convert"];
     try {
         $grabzIt = new GrabzItClient($grabzItApplicationKey, $grabzItApplicationSecret);
         if ($format == "pdf") {
             if ($convert == 'html') {
                 $grabzIt->HTMLToPDF($html);
             } else {
                 $grabzIt->URLToPDF($url);
             }
         } else {
             if ($format == "gif") {
                 $grabzIt->URLToAnimation($url);
             } else {
                 if ($convert == 'html') {
                     $grabzIt->HTMLToImage($html);
                 } else {
                     $grabzIt->URLToImage($url);
                 }
Esempio n. 7
0
//The absolute path that you have placed the handler.php on your website
$grabzItHandlerUrl = "http://85.253.172.147:8080/koik_tagid/lib/webing/handler.php";
$message = '';
if (count($_POST) > 0) {
    if (isset($_POST["delete"]) && $_POST["delete"] == 1) {
        $files = glob('results/*');
        foreach ($files as $file) {
            if (is_file($file)) {
                unlink($file);
            }
        }
    } else {
        $url = $_POST["url"];
        $format = $_POST["format"];
        try {
            $grabzIt = new GrabzItClient($grabzItApplicationKey, $grabzItApplicationSecret);
            if ($format == "pdf") {
                $grabzIt->SetPDFOptions($url, null, null, -1);
            } else {
                if ($format == "gif") {
                    $grabzIt->SetAnimationOptions($url);
                } else {
                    $grabzIt->SetImageOptions($url, null, null, null);
                }
            }
            $grabzIt->Save($grabzItHandlerUrl);
        } catch (Exception $e) {
            $message = $e->getMessage();
        }
    }
}
Esempio n. 8
-1
 public function test_screenshot()
 {
     include "GrabzItClient.class.php";
     $grabzIt = new GrabzItClient("M2NhMmU0MzkxZjJmNGVhNGE5N2M5YjZlZjI4M2QwODE=", "PzVPVDoIGj8/Pz8/Pz9lTD8tEj9sJhtHIj8CUz8/BWE=");
     $grabzIt->SetImageOptions("http://www.google.com");
     $filepath = $_SERVER["DOCUMENT_ROOT"] . "/webroot/img/test.jpg";
     $grabzIt->SaveTo($filepath);
     return $filepath;
 }