Advertisement
nephalim

Avatars_importer

Sep 3rd, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.29 KB | None | 0 0
  1. <?php
  2.  
  3. //
  4. //  NephoSoftLab  15.04.2015   Замовлення № 543-433.39 : php ~ target -> ./admin/sources/loginauth/internal/avatar_importer.php
  5. //  Імпортувач аватарів між CMS InstantCMS та Invision Power Board 3.х
  6. //  Замовник volchonok ::  timelimit until 15.06.2015 :: Штамп часу: 130f69d7cae2619081b0db0a55e783ec
  7. //  Ліцензія: EULA (копіювання, редагування, продаж та використання лише з письмового дозволу правотримача)
  8. //  Залежності:
  9. //  ./ips_kernel/classRM_DB_PDO.php
  10. //  ./admin/sources/loginauth/external/auth.php
  11. //  Модифікати:
  12. //  ./admin/sources/loginauth/external/acp.php
  13. //  ./admin/sources/loginauth/internal/auth.php
  14. //  
  15. //  ЗАСТЕРЕЖЕННЯ: Видалення цього копірайту призведе до втрати роботоспроможності обох сайтів, не радимо робити цього!
  16. //
  17.  
  18. if ( ! defined( 'IN_IPB' ) )
  19. {
  20.     print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
  21.     exit();
  22. }
  23.  
  24. if(empty($LOGIN_CONF))include("./admin/sources/loginauth/external/conf.php");
  25.  
  26. define('DB_AVAT', $LOGIN_CONF['REMOTE_FIELD_AVATAR']);
  27. define('DB_NICK', $LOGIN_CONF['REMOTE_FIELD_NAME']);
  28. define('DB_TNME', $LOGIN_CONF['REMOTE_TABLE_NAME']);
  29. define('DB_PREF', $LOGIN_CONF['REMOTE_TABLE_PREFIX']);
  30.  
  31. if (!class_exists('RM_DB')) require_once( IPS_KERNEL_PATH.'classRM_DB_PDO.php' );
  32.  
  33. $membr_id = array();
  34. $log_file_str = 'logged user with ';
  35. if (!empty($username))
  36. {
  37. $avatar_string = RM_DB::run("SELECT ".DB_AVAT." FROM ".DB_PREF.DB_TNME." WHERE ".DB_NICK." = ?", $username)->fetchColumn();
  38. $all = RM_DB::run("SELECT ".DB_NICK." , id FROM ".DB_PREF.DB_TNME , $empvar)->fetchAll(PDO::FETCH_KEY_PAIR);
  39. $id = $all[$username];
  40. $membr_id = $this->DB->buildAndFetch( array( 'select' => 'member_id', 'from' => 'members', 'where' => "name='".$username."'" ) );
  41. $log_file_str .= 'nickname = '.$username.' ';
  42. }
  43. else
  44. {
  45. $all = RM_DB::run("SELECT email , id FROM ".DB_PREF.DB_TNME , $empvar)->fetchAll(PDO::FETCH_KEY_PAIR);
  46. $id = $all[$email_address];
  47. $log_file_str .= 'email = '.$email_address.' ';
  48.  
  49. if(isset($id)) $avatar_string = RM_DB::run("SELECT ".DB_AVAT." FROM ".DB_PREF.DB_TNME." WHERE id = ?", $id)->fetchColumn();
  50. $membr_id = $this->DB->buildAndFetch( array( 'select' => 'member_id', 'from' => 'members', 'where' => "email='".$email_address."'" ) );
  51. }
  52. $in_member_id = $membr_id['member_id'];
  53. $log_file_str .= 'and has member_id = '.$in_member_id.' in DB and id = '.$id.' ';
  54.  
  55.  
  56.  
  57. if (isset($avatar_string) && isset($in_member_id))
  58. {
  59. preg_match("/normal:\w*(?<pathhhhh>.+)/", $avatar_string, $matches);
  60. $avatar_string =trim($matches['1']);
  61.  
  62. $avat_norm_url = $LOGIN_CONF['REMOTE_UPLOAD_DIR']. $avatar_string;
  63.  
  64. $file_headers = @get_headers($avat_norm_url);
  65.  
  66. $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'));
  67.  
  68. $in_avat_f = $this->DB->buildAndFetch( array( 'select' => 'avatar_location', 'from' => 'profile_portal', 'where' => "pp_member_id=".$in_member_id ) );
  69. $in_avat_field = $in_avat_f['avatar_location'];
  70.  
  71. if ((empty($in_avat_field) && isset($avat_norm_url)) || ((strpos($in_avat_field,'://') && isset($avat_norm_url)) && ($avat_norm_url != $in_avat_field)))
  72. {
  73. $image_geo = getimagesize ($avat_norm_url);
  74.  
  75. if (isset($image_geo))
  76. {
  77. $this->DB->update( 'profile_portal', array( 'avatar_location' => $avat_norm_url ), "pp_member_id = ".$in_member_id );
  78. $this->DB->update( 'profile_portal', array( 'avatar_type' => 'url' ), "pp_member_id = ".$in_member_id );  
  79. }
  80.  
  81. if (($image_geo[0] > 150 || $image_geo[1] > 150) && isset($image_geo))
  82. {
  83.  
  84. switch ($image_geo[2])
  85. {
  86.   case 1: // GIF
  87. $im = imagecreatefromgif ($avat_norm_url);
  88.     break;
  89.   case 2: // JPG
  90. $im = imagecreatefromjpeg ($avat_norm_url);
  91.     break;
  92.   case 3: // PNG
  93. $im = imagecreatefrompng ($avat_norm_url);    
  94.     break;
  95.   default:
  96. $wrong_format = true;
  97. $total_img_size = '150x150';    
  98. }
  99.  
  100. if(!$wrong_format)
  101. {
  102. if (imagesx($im) > imagesy($im)) // width > height
  103. {
  104. $im_width = 150;
  105. $ratio = $im_width / imagesx($im);
  106. $im_height = imagesy($im) * $ratio;  
  107. }
  108. else // width < height
  109. {
  110. $im_height = 150;
  111. $ratio = $im_height / imagesy($im);
  112. $im_width = imagesx($im) * $ratio;
  113. }
  114. $total_img_size = strval(floor($im_width))."x".strval(floor($im_height));
  115.  
  116. }
  117. if(isset($im)) imagedestroy($im);
  118. }
  119. else $total_img_size = strval($image_geo[0])."x".strval($image_geo[1]);
  120. if(isset($image_geo))$this->DB->update( 'profile_portal', array( 'avatar_size' => $total_img_size ), "pp_member_id = ".$in_member_id );  
  121. }
  122. if (empty($avat_norm_url) && isset($in_avat_field) && strpos($in_avat_field,'://') && isset($in_member_id))
  123. {
  124. $this->DB->update( 'profile_portal', array( 'avatar_location' => "''" ), "pp_member_id = ".$in_member_id );
  125. $this->DB->update( 'profile_portal', array( 'avatar_type' => "''" ), "pp_member_id = ".$in_member_id );
  126. $this->DB->update( 'profile_portal', array( 'avatar_size' => "''" ), "pp_member_id = ".$in_member_id );  
  127. }
  128. }
  129. file_put_contents('log.txt', date("H:i:s d.m.Y").'  '.print_r($log_file_str , 1)."\n", FILE_APPEND);
  130.  
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement