Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //
- // NephoSoftLab 15.04.2015 Замовлення № 543-433.39 : php ~ target -> ./admin/sources/loginauth/internal/avatar_importer.php
- // Імпортувач аватарів між CMS InstantCMS та Invision Power Board 3.х
- // Замовник volchonok :: timelimit until 15.06.2015 :: Штамп часу: 130f69d7cae2619081b0db0a55e783ec
- // Ліцензія: EULA (копіювання, редагування, продаж та використання лише з письмового дозволу правотримача)
- // Залежності:
- // ./ips_kernel/classRM_DB_PDO.php
- // ./admin/sources/loginauth/external/auth.php
- // Модифікати:
- // ./admin/sources/loginauth/external/acp.php
- // ./admin/sources/loginauth/internal/auth.php
- //
- // ЗАСТЕРЕЖЕННЯ: Видалення цього копірайту призведе до втрати роботоспроможності обох сайтів, не радимо робити цього!
- //
- if ( ! defined( 'IN_IPB' ) )
- {
- print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
- exit();
- }
- if(empty($LOGIN_CONF))include("./admin/sources/loginauth/external/conf.php");
- define('DB_AVAT', $LOGIN_CONF['REMOTE_FIELD_AVATAR']);
- define('DB_NICK', $LOGIN_CONF['REMOTE_FIELD_NAME']);
- define('DB_TNME', $LOGIN_CONF['REMOTE_TABLE_NAME']);
- define('DB_PREF', $LOGIN_CONF['REMOTE_TABLE_PREFIX']);
- if (!class_exists('RM_DB')) require_once( IPS_KERNEL_PATH.'classRM_DB_PDO.php' );
- $membr_id = array();
- $log_file_str = 'logged user with ';
- if (!empty($username))
- {
- $avatar_string = RM_DB::run("SELECT ".DB_AVAT." FROM ".DB_PREF.DB_TNME." WHERE ".DB_NICK." = ?", $username)->fetchColumn();
- $all = RM_DB::run("SELECT ".DB_NICK." , id FROM ".DB_PREF.DB_TNME , $empvar)->fetchAll(PDO::FETCH_KEY_PAIR);
- $id = $all[$username];
- $membr_id = $this->DB->buildAndFetch( array( 'select' => 'member_id', 'from' => 'members', 'where' => "name='".$username."'" ) );
- $log_file_str .= 'nickname = '.$username.' ';
- }
- else
- {
- $all = RM_DB::run("SELECT email , id FROM ".DB_PREF.DB_TNME , $empvar)->fetchAll(PDO::FETCH_KEY_PAIR);
- $id = $all[$email_address];
- $log_file_str .= 'email = '.$email_address.' ';
- if(isset($id)) $avatar_string = RM_DB::run("SELECT ".DB_AVAT." FROM ".DB_PREF.DB_TNME." WHERE id = ?", $id)->fetchColumn();
- $membr_id = $this->DB->buildAndFetch( array( 'select' => 'member_id', 'from' => 'members', 'where' => "email='".$email_address."'" ) );
- }
- $in_member_id = $membr_id['member_id'];
- $log_file_str .= 'and has member_id = '.$in_member_id.' in DB and id = '.$id.' ';
- if (isset($avatar_string) && isset($in_member_id))
- {
- preg_match("/normal:\w*(?<pathhhhh>.+)/", $avatar_string, $matches);
- $avatar_string =trim($matches['1']);
- $avat_norm_url = $LOGIN_CONF['REMOTE_UPLOAD_DIR']. $avatar_string;
- $file_headers = @get_headers($avat_norm_url);
- $wrong_format = (($file_headers[0] == 'HTTP/1.0 404 Not Found') || ($file_headers[0] == 'HTTP/1.0 302 Found' && $file_headers[7] == 'HTTP/1.0 404 Not Found'));
- $in_avat_f = $this->DB->buildAndFetch( array( 'select' => 'avatar_location', 'from' => 'profile_portal', 'where' => "pp_member_id=".$in_member_id ) );
- $in_avat_field = $in_avat_f['avatar_location'];
- if ((empty($in_avat_field) && isset($avat_norm_url)) || ((strpos($in_avat_field,'://') && isset($avat_norm_url)) && ($avat_norm_url != $in_avat_field)))
- {
- $image_geo = getimagesize ($avat_norm_url);
- if (isset($image_geo))
- {
- $this->DB->update( 'profile_portal', array( 'avatar_location' => $avat_norm_url ), "pp_member_id = ".$in_member_id );
- $this->DB->update( 'profile_portal', array( 'avatar_type' => 'url' ), "pp_member_id = ".$in_member_id );
- }
- if (($image_geo[0] > 150 || $image_geo[1] > 150) && isset($image_geo))
- {
- switch ($image_geo[2])
- {
- case 1: // GIF
- $im = imagecreatefromgif ($avat_norm_url);
- break;
- case 2: // JPG
- $im = imagecreatefromjpeg ($avat_norm_url);
- break;
- case 3: // PNG
- $im = imagecreatefrompng ($avat_norm_url);
- break;
- default:
- $wrong_format = true;
- $total_img_size = '150x150';
- }
- if(!$wrong_format)
- {
- if (imagesx($im) > imagesy($im)) // width > height
- {
- $im_width = 150;
- $ratio = $im_width / imagesx($im);
- $im_height = imagesy($im) * $ratio;
- }
- else // width < height
- {
- $im_height = 150;
- $ratio = $im_height / imagesy($im);
- $im_width = imagesx($im) * $ratio;
- }
- $total_img_size = strval(floor($im_width))."x".strval(floor($im_height));
- }
- if(isset($im)) imagedestroy($im);
- }
- else $total_img_size = strval($image_geo[0])."x".strval($image_geo[1]);
- if(isset($image_geo))$this->DB->update( 'profile_portal', array( 'avatar_size' => $total_img_size ), "pp_member_id = ".$in_member_id );
- }
- if (empty($avat_norm_url) && isset($in_avat_field) && strpos($in_avat_field,'://') && isset($in_member_id))
- {
- $this->DB->update( 'profile_portal', array( 'avatar_location' => "''" ), "pp_member_id = ".$in_member_id );
- $this->DB->update( 'profile_portal', array( 'avatar_type' => "''" ), "pp_member_id = ".$in_member_id );
- $this->DB->update( 'profile_portal', array( 'avatar_size' => "''" ), "pp_member_id = ".$in_member_id );
- }
- }
- file_put_contents('log.txt', date("H:i:s d.m.Y").' '.print_r($log_file_str , 1)."\n", FILE_APPEND);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement