Advertisement
Guest User

paste.php

a guest
Dec 15th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.49 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * Copyright (c) 2019 <cvar1984>
  5.  *
  6.  * Licensed unter the Apache License, Version 2.0 or the MIT license, at your
  7.  * option.
  8.  *
  9.  * ********************************************************************************
  10.  *
  11.  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  12.  * this software and associated documentation files (the "Software"), to deal in
  13.  * the Software without restriction, including without limitation the rights to
  14.  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  15.  * the Software, and to permit persons to whom the Software is furnished to do so,
  16.  * subject to the following conditions:
  17.  *
  18.  * The above copyright notice and this permission notice shall be included in all
  19.  * copies or substantial portions of the Software.
  20.  *
  21.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  23.  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  24.  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  25.  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  26.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27.  *
  28.  * ********************************************************************************
  29.  *
  30.  * Licensed under the Apache License, Version 2.0 (the "License");
  31.  * you may not use this file except in compliance with the License.
  32.  * You may obtain a copy of the License at
  33.  *
  34.  *   http://www.apache.org/licenses/LICENSE-2.0
  35.  *
  36.  * Unless required by applicable law or agreed to in writing, software
  37.  * distributed under the License is distributed on an "AS IS" BASIS,
  38.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  39.  * See the License for the specific language governing permissions and
  40.  * limitations under the License.
  41.  */
  42.  
  43. class PasteBin
  44. {
  45.     protected static $api_dev_key = 'ff9314e0164f30accec4ef969637aa07';
  46.     protected static $api_paste_private = '0';
  47.     protected static $api_paste_expire_date = 'N';
  48.     protected static $api_user_key = '';
  49.  
  50.     private static function post(string $url, array $fields)
  51.     {
  52.         $ch = curl_init($url);
  53.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  54.         curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  55.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  56.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  57.         // curl_setopt($ch, CURLOPT_NOBODY, 0);
  58.         return curl_exec($ch);
  59.         curl_close($ch);
  60.     }
  61.  
  62.     public static function paste(string $code, string $name, string $syntax)
  63.     {
  64.         $api_paste_name = urlencode($name);
  65.         $api_paste_format = urlencode($syntax);
  66.         $options = [
  67.             'api_option' => 'paste',
  68.             'api_user_key' => self::$api_user_key,
  69.             'api_paste_private' => self::$api_paste_private,
  70.             'api_paste_name' => $api_paste_name,
  71.             'api_paste_expire_date' => self::$api_paste_expire_date,
  72.             'api_paste_format' => $api_paste_format,
  73.             'api_dev_key' => self::$api_dev_key,
  74.             'api_paste_code' => $code
  75.         ];
  76.         return PasteBin::post('http://pastebin.com/api/api_post.php', $options);
  77.     }
  78. }
  79. $code = readline('Code : ');
  80. $code = trim($code);
  81. $code = file_get_contents(getcwd() . DIRECTORY_SEPARATOR . $code);
  82.  
  83. $name = readline('Paste name : ');
  84. $name = trim($name);
  85.  
  86. $syntax = pathinfo($name, PATHINFO_EXTENSION);
  87.  
  88. echo PasteBin::paste($code, $name, $syntax).PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement