Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use PHPImageWorkshop\ImageWorkshop;
- class mainContent {
- // Metoda CSS
- function myCSS() {
- return '
- #apigui .block {
- background: white;
- margin: 5px 10px;
- box-shadow: -1px 1px 5px #CCC;
- border: 1px solid #CCC;
- border-radius: 5px;
- width: 35%;
- color: black;
- padding: 15px;
- display: inline-block;
- text-align: left;
- font-size: 12px;
- padding-right: 100px;
- position: relative;
- }
- #apigui .block .description {
- display:block;
- padding-right:6px;
- }
- #apigui .block input[type~=text] {
- width: 100% !important;
- }
- #apigui .block input[type~=radio] {
- margin: 3px 5px;
- }
- #apigui .block select {
- margin: 5px 0px;
- width: 100%;
- }
- #apigui .block h2 {
- font-weight: normal !important;
- }
- #apigui .warning {
- font-weight: bold;
- color: red;
- }
- ';
- }
- //Podstrony
- function subpages() {
- return array(
- 'Import z adresu' => 1,
- 'Import z katalogu' => 2,
- );
- }
- //Wywolanie podstron
- function init($get) {
- switch($get) {
- case 1: $this->fromUrl(); break;
- case 2: $this->fromDir(); break;
- default: $this->fromUrl();
- }
- }
- function fromUrl() {
- if(isset($_POST['import'])) {
- $url = $_POST['url'];
- $parse_url = parse_url($url);
- $dir = '../upload/';
- $min_width = $_POST['min_width'];
- $min_height = $_POST['min_height'];
- $cropp = $_POST['cropp'];
- $date = date('Y-m-d H:i:s');
- $settings = mysql_fetch_array(mysql_query("SELECT * FROM `tentego_settings` WHERE `id`='1'"));
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 4);
- curl_setopt($ch, CURLOPT_URL, $url);
- $html = curl_exec($ch);
- $errors = 0;
- $images = 0;
- set_time_limit(60);
- if(preg_match_all("/<img .*?(?=src)src=\"([^\"]+)\"/si", $html, $matches))
- {
- foreach($matches[1] as $img) {
- if(strpos($img, "http://") === FALSE) {
- $ex = explode("/",$img);
- if(reset($ex)==NULL) $img = $parse_url['scheme'].'://'.$parse_url['host'].$img;
- else $img = $parse_url['scheme'].'://'.$parse_url['host'].'/'.$img;
- }
- list($width, $height, $type, $attr) = getimagesize($img);
- if($width>$min_width && $height>$min_height) {
- $info = $this->file_info($img);
- if(!file_exists($dir.$info['basename'])) {
- $import = file_put_contents($dir.$info['basename'],file_get_contents($img));
- if($import) {
- if($cropp>0) $this->cropp($dir.$info['basename'], $cropp, $width, $height, $dir);
- if($settings['watermark']) {
- if(strpos($settings['watermark'], "http://") === FALSE) $watermark = '../'.$settings['watermark'];
- else $watermark = $settings['watermark'];
- $this->watermark($dir.$info['basename'], $watermark, $dir);
- }
- $query = mysql_query("INSERT INTO `tentego_img` (`title`,`src`,`type`,`owner`,`cat`,`date`,`rel_date`,`source`,`is_waiting`) VALUES ('".$info['filename']."','".$info['basename']."','img',1,1,'$date',0,'-----',1)");
- }
- if(!$import || !$query) $errors++;
- else $images++;
- }
- }
- }
- if($errors) kernel::make_notify("Nie udało się zaimportować obrazków");
- else kernel::make_notify("Zaimportowano ".$images." obrazków");
- }
- else kernel::make_notify("Nie znaleziono żadnych obrazków");
- }
- echo "<script type=\"text/javascript\">
- $(document).ready(function(){
- $('input[name$=\"import\"]').click( function() { $('img[class$=\"loading\"]').attr('style', 'visibility: visible;'); });
- });
- </script>";
- echo '<div id="apigui">
- <form method="post" action="?go=getimg&feature=1">
- <div id="options">
- '.($this->checkExtension('curl') ? '<input type="submit" value="Importuj" name="import">' : '<input type="submit" value="Importuj" name="import" disabled> <span class="warning">Rozszerzenie <em>curl</em> nie jest włączone na serwerze!</span>').'
- <img src="apps/getimg/loading.gif" class="loading" style="visibility: hidden;" valign="middle" />
- </div>
- <div class="block">
- <h2>Minimalna szerokość</h2>
- <span class="description">Określa minimalną szerokość obrazków, które zostaną zaimportowane.</span>
- <input type="text" name="min_width" value="300" />
- </div>
- <div class="block">
- <h2>Minimalna wysokość</h2>
- <span class="description">Określa minimalną wysokość obrazków, które zostaną zaimportowane.</span>
- <input type="text" name="min_height" value="200" />
- </div>
- <div class="block">
- <h2>Przycięcie</h2>
- <span class="description">Wartość w pikselach, która zostanie odcięta od dołu obrazka.</span>
- <input type="text" name="cropp" value="0" />
- </div>
- <div class="block">
- <h2>Adres URL</h2>
- <span class="description">Adres do strony, z której mają zostać pobrane obrazki <em>(bez / na końcu)</em>.</span>
- <input type="text" name="url" value="http://" />
- </div>
- </form>
- </div>';
- }
- function fromDir() {
- if(isset($_GET['import'])) {
- $file_types = array(1=>'jpg','jpeg','gif','png','JPG','JPEG','GIF','PNG');
- $settings = mysql_fetch_array(mysql_query("SELECT * FROM `tentego_settings` WHERE `id`='1'"));
- $date = date('Y-m-d H:i:s');
- $errors = 0;
- $loop = 0;
- if(is_dir('../'.$_GET['import'])) {
- $dir = opendir('../'.$_GET['import']);
- while(false !== ($file = readdir($dir))) {
- $file_name = date('YmdHis').$loop.'uid1';
- $info = pathinfo($file);
- if($file != '.' && $file != '..' && array_search($info['extension'],$file_types))
- $przeniesienie = rename('../'.$_GET['import'].'/'.$file, '../upload/'.$file_name.'.'.$info['extension']);
- if($przeniesienie) {
- if($settings['watermark']) {
- if(strpos($settings['watermark'], "http://") === FALSE) $watermark = '../'.$settings['watermark'];
- else $watermark = $settings['watermark'];
- $this->watermark('../upload/'.$file_name.'.'.$info['extension'], $watermark, '../upload/');
- }
- $query = mysql_query("INSERT INTO `tentego_img` (`title`,`src`,`type`,`owner`,`cat`,`date`,`rel_date`,`source`,`is_waiting`) VALUES ('".$info['filename']."','".$file_name.'.'.$info['extension']."','img',1,1,'$date',0,'-----',1)");
- ### USTAWIANIE OSTATNIEGO ID ###
- $last_id = mysql_insert_id();
- ### KONIEC OSTATNIEGO ID ###
- ### FACEBOOK #
- require_once('_core/fbapi/autoload.php');
- $fb = new Facebook\Facebook([
- 'app_id' => '',
- 'app_secret' => '',
- 'default_graph_version' => 'v2.11',
- ]);
- $pageAccessToken ='';
- $page_id = 123104298384383;
- ### KONIEC FACEBOOK ###
- ### UDOSTĘPNIANIE FB ###
- $linkData = [
- 'message' => $info['filename'],
- 'picture' => "https://memuje.pl/upload/".$file_name,
- 'url' => "https://memuje.pl/img/".$last_id."/".$$info['filename']."/",
- 'link' => "https://memuje.pl/img/".$last_id."/".$$info['filename']."/",
- ];
- try {
- $response = $fb->post($page_id.'/feed', $linkData, $pageAccessToken);
- } catch(Facebook\Exceptions\FacebookResponseException $e) {
- echo 'Graph returned an error: '.$e->getMessage();
- exit;
- } catch(Facebook\Exceptions\FacebookSDKException $e) {
- echo 'Facebook SDK returned an error: '.$e->getMessage();
- exit;
- }
- $graphNode = $response->getGraphNode();
- ### KONIEC UDOSTĘPNIANIA ###
- if(!$query) $errors++;
- }
- $loop++;
- }
- }
- if(!$errors) kernel::make_notify("Poprawnie zaimportowano obrazki");
- else kernel::make_notify("Nie udało się zaimportować obrazków");
- }
- echo '<div id="apigui">
- <div id="options">Wybierz folder z katalogu głównego, z którego mają zostać zaimportowane obrazy.</div>
- <table>
- <tbody>';
- $this->cat_list('../');
- $cats = 0;
- for( $x = 0, $cnt = count($this->katalogi); $x < $cnt; $x++ ) {
- if($this->katalogi[$x]!='_core' && $this->katalogi[$x]!='_js' && $this->katalogi[$x]!='_themes' && $this->katalogi[$x]!='admin' && $this->katalogi[$x]!='upload') {
- echo '<tr><td>'.$this->katalogi[$x].'</td> <td><em>'.$this->numberOfPictures('../'.$this->katalogi[$x]).' obrazków</em></td> <td align="right"><a href="?go=getimg&feature=2&import='.$this->katalogi[$x].'">importuj</a></td></tr>';
- $cats++;
- }
- }
- if($cats==0) echo '<tr><td>Nie wykryto żadnego dodatkowego folderu prócz folderów skryptu.</td></tr>';
- echo '</tbody>
- </table>
- </div>';
- }
- /*****************************************/
- /* DODATKOWE FUNKCJE
- /*****************************************/
- function checkExtension($name) {
- if(in_array($name, get_loaded_extensions())) return true;
- else return false;
- }
- function file_info($path) {
- $qpos = strpos($path, "?");
- if ($qpos!==false) $path = substr($path, 0, $qpos);
- $array = array(
- "extension" => pathinfo($path, PATHINFO_EXTENSION),
- "dirname" => pathinfo($path, PATHINFO_DIRNAME),
- "basename" => pathinfo($path, PATHINFO_BASENAME),
- "filename" => pathinfo($path, PATHINFO_FILENAME),
- );
- return $array;
- }
- function cat_list($katalog) {
- $dir = opendir($katalog);
- while ($file = readdir($dir)) {
- if (is_dir($katalog.'/'.$file) && $file != "." && $file != "..") {
- $this->katalogi[] = $file;
- }
- }
- }
- function numberOfPictures($katalog) {
- $file_types = array(1=>'jpg','jpeg','gif','png','JPG','JPEG','GIF','PNG');
- $dir = opendir($katalog);
- $files = 0;
- while(false !== ($file = readdir($dir))) {
- $info = pathinfo($file);
- if($file != '.' && $file != '..' && array_search($info['extension'],$file_types))
- $files++;
- }
- return $files;
- }
- function watermark($file, $watermark, $dir) {
- $info = pathinfo($file);
- if($info['extension'] != 'gif') {
- if(file_exists('lib/imageworkshop.lib.php')) {
- require_once('lib/imageworkshop.lib.php');
- $imageLayer = new ImageWorkshop(array(
- "imageFromPath" => $file,
- ));
- $watermarkLayer = new ImageWorkshop(array(
- "imageFromPath" => $watermark,
- ));
- } else {
- require_once('lib/imageworkshop/ImageWorkshop.php');
- $imageLayer = ImageWorkshop::initFromPath($file);
- $watermarkLayer = ImageWorkshop::initFromPath($watermark);
- }
- $imageLayer->addLayer(1, $watermarkLayer, 5, 5, "RB");
- $createFolders = false;
- $backgroundColor = null;
- $imageQuality = 100;
- $imageLayer->save($dir, $info['filename'].'.'.$info['extension'], $createFolders, $backgroundColor, $imageQuality);
- }
- }
- function cropp($file, $px, $img_width, $img_height, $dir) {
- $info = pathinfo($file);
- if($info['extension'] != 'gif') {
- if(file_exists('lib/imageworkshop.lib.php')) {
- require_once('lib/imageworkshop.lib.php');
- $imageLayer = new ImageWorkshop(array(
- "imageFromPath" => $file,
- ));
- } else {
- require_once('lib/imageworkshop/ImageWorkshop.php');
- $imageLayer = ImageWorkshop::initFromPath($file);
- }
- $imageLayer->cropInPixel($img_width, $img_height-$px, 0, $px, 'LB');
- $createFolders = false;
- $backgroundColor = null;
- $imageQuality = 100;
- $imageLayer->save($dir, $info['filename'].'.'.$info['extension'], $createFolders, $backgroundColor, $imageQuality);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement