コード例 #1
0
ファイル: facebook.php プロジェクト: mrdeadmouse/u136006
 public function prepareUser($arFBUser, $short = false)
 {
     $arFields = array('EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arFBUser["id"], 'LOGIN' => "FB_" . $arFBUser["id"], 'EMAIL' => $arFBUser["email"] != '' ? $arFBUser["email"] : '', 'NAME' => $arFBUser["first_name"], 'LAST_NAME' => $arFBUser["last_name"], 'OATOKEN' => $this->entityOAuth->getToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires());
     if (!$short && isset($arFBUser['picture']['data']['url']) && !$arFBUser['picture']['data']['is_silhouette']) {
         $picture_url = CFacebookInterface::GRAPH_URL . '/' . $arFBUser['id'] . '/picture?type=large';
         $temp_path = CFile::GetTempName('', 'picture.jpg');
         $ob = new \Bitrix\Main\Web\HttpClient(array("redirect" => true));
         $ob->download($picture_url, $temp_path);
         $arPic = CFile::MakeFileArray($temp_path);
         if ($arPic) {
             $arFields["PERSONAL_PHOTO"] = $arPic;
         }
     }
     if (isset($arFBUser['birthday'])) {
         if ($date = MakeTimeStamp($arFBUser['birthday'], "MM/DD/YYYY")) {
             $arFields["PERSONAL_BIRTHDAY"] = ConvertTimeStamp($date);
         }
     }
     if (isset($arFBUser['gender']) && $arFBUser['gender'] != '') {
         if ($arFBUser['gender'] == 'male') {
             $arFields["PERSONAL_GENDER"] = 'M';
         } elseif ($arFBUser['gender'] == 'female') {
             $arFields["PERSONAL_GENDER"] = 'F';
         }
     }
     $arFields["PERSONAL_WWW"] = $this->getProfileUrl($arFBUser['id']);
     if (strlen(SITE_ID) > 0) {
         $arFields["SITE_ID"] = SITE_ID;
     }
     return $arFields;
 }
コード例 #2
0
ファイル: yandex.php プロジェクト: mrdeadmouse/u136006
 public function prepareUser($yandexUser, $short = false)
 {
     $id = $yandexUser['id'];
     $userFields = array('EXTERNAL_AUTH_ID' => static::ID, 'XML_ID' => $id, 'LOGIN' => static::LOGIN_PREFIX . $id, 'NAME' => $yandexUser['first_name'], 'LAST_NAME' => $yandexUser['last_name'], 'OATOKEN' => $this->entityOAuth->getToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires());
     if (strlen($userFields["NAME"]) <= 0) {
         $userFields["NAME"] = $yandexUser["login"];
     }
     if (isset($yandexUser["emails"]) && is_array($yandexUser["emails"]) && count($yandexUser["emails"]) > 0) {
         $userFields["EMAIL"] = $yandexUser['emails'][0];
     }
     if (!$short && !empty($yandexUser['default_avatar_id'])) {
         $picture_url = "https://avatars.yandex.net/get-yapic/" . $yandexUser["default_avatar_id"] . "/islands-200";
         $temp_path = CFile::GetTempName('', 'picture.jpg');
         $ob = new \Bitrix\Main\Web\HttpClient(array("redirect" => true));
         $ob->download($picture_url, $temp_path);
         $arPic = CFile::MakeFileArray($temp_path);
         if ($arPic) {
             $userFields["PERSONAL_PHOTO"] = $arPic;
         }
     }
     if (strlen(SITE_ID) > 0) {
         $userFields["SITE_ID"] = SITE_ID;
     }
     return $userFields;
 }
コード例 #3
0
ファイル: file.php プロジェクト: k-kalashnikov/geekcon_new
 function MakeFileArray($path, $mimetype = false)
 {
     $io = CBXVirtualIo::GetInstance();
     $arFile = array();
     if (intval($path) > 0) {
         $res = CFile::GetByID($path);
         if ($ar = $res->Fetch()) {
             $bExternalStorage = false;
             foreach (GetModuleEvents("main", "OnMakeFileArray", true) as $arEvent) {
                 if (ExecuteModuleEventEx($arEvent, array($ar, &$arFile))) {
                     $bExternalStorage = true;
                     break;
                 }
             }
             if (!$bExternalStorage) {
                 $arFile["name"] = strlen($ar['ORIGINAL_NAME']) > 0 ? $ar['ORIGINAL_NAME'] : $ar['FILE_NAME'];
                 $arFile["size"] = $ar['FILE_SIZE'];
                 $arFile["type"] = $ar['CONTENT_TYPE'];
                 $arFile["description"] = $ar['DESCRIPTION'];
                 $arFile["tmp_name"] = $io->GetPhysicalName(preg_replace("#[\\\\\\/]+#", "/", $_SERVER['DOCUMENT_ROOT'] . '/' . COption::GetOptionString('main', 'upload_dir', 'upload') . '/' . $ar['SUBDIR'] . '/' . $ar['FILE_NAME']));
             }
             return $arFile;
         }
     }
     $path = preg_replace("#(?<!:)[\\\\\\/]+#", "/", $path);
     if (strlen($path) == 0 || $path == "/") {
         return NULL;
     }
     if (preg_match("#^(http[s]?)://#", $path)) {
         $temp_path = '';
         $bExternalStorage = false;
         foreach (GetModuleEvents("main", "OnMakeFileArray", true) as $arEvent) {
             if (ExecuteModuleEventEx($arEvent, array($path, &$temp_path))) {
                 $bExternalStorage = true;
                 break;
             }
         }
         if (!$bExternalStorage) {
             $temp_path = CFile::GetTempName('', bx_basename($path));
             $ob = new CHTTP();
             $ob->follow_redirect = true;
             if ($ob->Download($path, $temp_path)) {
                 $arFile = CFile::MakeFileArray($temp_path);
             }
         } elseif ($temp_path) {
             $arFile = CFile::MakeFileArray($temp_path);
         }
     } elseif (preg_match("#^(ftp[s]?|php)://#", $path)) {
         if ($fp = fopen($path, "rb")) {
             $content = "";
             while (!feof($fp)) {
                 $content .= fgets($fp, 4096);
             }
             if (strlen($content) > 0) {
                 $temp_path = CFile::GetTempName('', bx_basename($path));
                 if (RewriteFile($temp_path, $content)) {
                     $arFile = CFile::MakeFileArray($temp_path);
                 }
             }
             fclose($fp);
         }
     } else {
         if (!file_exists($path)) {
             if (file_exists($_SERVER["DOCUMENT_ROOT"] . $path)) {
                 $path = $_SERVER["DOCUMENT_ROOT"] . $path;
             } else {
                 return NULL;
             }
         }
         if (is_dir($path)) {
             return NULL;
         }
         $arFile["name"] = $io->GetLogicalName(bx_basename($path));
         $arFile["size"] = filesize($path);
         $arFile["tmp_name"] = $path;
         $arFile["type"] = $mimetype;
         if (strlen($arFile["type"]) <= 0) {
             $arFile["type"] = CFile::GetContentType($path, true);
         }
     }
     if (strlen($arFile["type"]) <= 0) {
         $arFile["type"] = "unknown";
     }
     return $arFile;
 }
コード例 #4
0
ファイル: storage.php プロジェクト: rasuldev/torino
 public static function OnMakeFileArray($arSourceFile, &$arDestination)
 {
     if (!is_array($arSourceFile)) {
         $file = $arSourceFile;
         if (substr($file, 0, strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"]) {
             $file = ltrim(substr($file, strlen($_SERVER["DOCUMENT_ROOT"])), "/");
         }
         if (!preg_match("/^http:\\/\\//", $file)) {
             return false;
         }
         $bucket = CCloudStorage::FindBucketByFile($file);
         if (!is_object($bucket)) {
             return false;
         }
         $filePath = substr($file, strlen($bucket->GetFileSRC("/")) - 1);
         $filePath = urldecode($filePath);
         $target = CFile::GetTempName('', bx_basename($filePath));
         $target = preg_replace("#[\\\\\\/]+#", "/", $target);
         if ($bucket->DownloadToFile($filePath, $target)) {
             $arDestination = $target;
         }
         return true;
     } else {
         if ($arSourceFile["HANDLER_ID"] <= 0) {
             return false;
         }
         $bucket = new CCloudStorageBucket($arSourceFile["HANDLER_ID"]);
         if (!$bucket->Init()) {
             return false;
         }
         $target = CFile::GetTempName('', $arSourceFile["FILE_NAME"]);
         $target = preg_replace("#[\\\\\\/]+#", "/", $target);
         if ($bucket->DownloadToFile($arSourceFile, $target)) {
             $arDestination["name"] = strlen($arSourceFile['ORIGINAL_NAME']) > 0 ? $arSourceFile['ORIGINAL_NAME'] : $arSourceFile['FILE_NAME'];
             $arDestination["size"] = $arSourceFile['FILE_SIZE'];
             $arDestination["type"] = $arSourceFile['CONTENT_TYPE'];
             $arDestination["description"] = $arSourceFile['DESCRIPTION'];
             $arDestination["tmp_name"] = $target;
         }
         return true;
     }
 }
コード例 #5
0
ファイル: box.php プロジェクト: mrdeadmouse/u136006
 public function prepareUser($boxUser, $short = false)
 {
     $nameDetails = explode(" ", $boxUser['name'], 2);
     $id = $boxUser['id'];
     $arFields = array('EXTERNAL_AUTH_ID' => static::ID, 'XML_ID' => $id, 'LOGIN' => static::LOGIN_PREFIX . $id, 'NAME' => $nameDetails[0], 'LAST_NAME' => $nameDetails[1], 'EMAIL' => $boxUser["login"], 'OATOKEN' => $this->entityOAuth->getToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires(), 'REFRESH_TOKEN' => $this->entityOAuth->getRefreshToken());
     if (!$short && !empty($boxUser['avatar_url'])) {
         $picture_url = $boxUser['avatar_url'];
         $temp_path = CFile::GetTempName('', 'picture.jpg');
         $ob = new HttpClient(array("redirect" => true));
         $ob->download($picture_url, $temp_path);
         $arPic = CFile::MakeFileArray($temp_path);
         if ($arPic) {
             $arFields["PERSONAL_PHOTO"] = $arPic;
         }
     }
     if (strlen(SITE_ID) > 0) {
         $arFields["SITE_ID"] = SITE_ID;
     }
     return $arFields;
 }
コード例 #6
0
ファイル: urlpreview.php プロジェクト: DarneoStudio/bitrix
 /**
  * @param string $url Image's URL.
  * @return integer Saved file identifier
  */
 protected static function saveImage($url)
 {
     $fileId = false;
     $file = new \CFile();
     $httpClient = new HttpClient();
     $httpClient->setTimeout(5);
     $httpClient->setStreamTimeout(5);
     $urlComponents = parse_url($url);
     if ($urlComponents && strlen($urlComponents["path"]) > 0) {
         $tempPath = $file->GetTempName('', bx_basename($urlComponents["path"]));
     } else {
         $tempPath = $file->GetTempName('', bx_basename($url));
     }
     $httpClient->download($url, $tempPath);
     $fileName = $httpClient->getHeaders()->getFilename();
     $localFile = \CFile::MakeFileArray($tempPath);
     if (is_array($localFile)) {
         if (strlen($fileName) > 0) {
             $localFile['name'] = $fileName;
         }
         if (\CFile::CheckImageFile($localFile, 0, 0, 0, array("IMAGE")) === null) {
             $fileId = $file->SaveFile($localFile, 'urlpreview', true);
         }
     }
     return $fileId === false ? null : $fileId;
 }
コード例 #7
0
ファイル: facebook.php プロジェクト: rasuldev/torino
    public function Authorize()
    {
        global $APPLICATION;
        $APPLICATION->RestartBuffer();
        $authError = SOCSERV_AUTHORISATION_ERROR;
        if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '' && CSocServAuthManager::CheckUniqueKey()) {
            if (IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME')) {
                $redirect_uri = self::CONTROLLER_URL . "/redirect.php?redirect_to=" . urlencode(CSocServUtil::GetCurUrl('auth_service_id=' . self::ID, array("code")));
            } else {
                $redirect_uri = CSocServUtil::GetCurUrl('auth_service_id=' . self::ID, array("code"));
            }
            $this->entityOAuth = new CFacebookInterface(false, false, $_REQUEST["code"]);
            if ($this->entityOAuth->GetAccessToken($redirect_uri) !== false) {
                $arFBUser = $this->entityOAuth->GetCurrentUser();
                if (is_array($arFBUser) && isset($arFBUser["id"])) {
                    $arFields = array('EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arFBUser["id"], 'LOGIN' => "FB_" . $arFBUser["id"], 'EMAIL' => $arFBUser["email"] != '' ? $arFBUser["email"] : '', 'NAME' => $arFBUser["first_name"], 'LAST_NAME' => $arFBUser["last_name"], 'OATOKEN' => $this->entityOAuth->getToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires());
                    if (isset($arFBUser['picture']['data']['url']) && !$arFBUser['picture']['data']['is_silhouette']) {
                        $picture_url = CFacebookInterface::GRAPH_URL . '/' . $arFBUser['id'] . '/picture?type=large';
                        $temp_path = CFile::GetTempName('', 'picture.jpg');
                        $ob = new \Bitrix\Main\Web\HttpClient(array("redirect" => true));
                        $ob->download($picture_url, $temp_path);
                        $arPic = CFile::MakeFileArray($temp_path);
                        if ($arPic) {
                            $arFields["PERSONAL_PHOTO"] = $arPic;
                        }
                    }
                    if (isset($arFBUser['birthday'])) {
                        if ($date = MakeTimeStamp($arFBUser['birthday'], "MM/DD/YYYY")) {
                            $arFields["PERSONAL_BIRTHDAY"] = ConvertTimeStamp($date);
                        }
                    }
                    if (isset($arFBUser['gender']) && $arFBUser['gender'] != '') {
                        if ($arFBUser['gender'] == 'male') {
                            $arFields["PERSONAL_GENDER"] = 'M';
                        } elseif ($arFBUser['gender'] == 'female') {
                            $arFields["PERSONAL_GENDER"] = 'F';
                        }
                    }
                    $arFields["PERSONAL_WWW"] = $this->getProfileUrl($arFBUser['id']);
                    if (strlen(SITE_ID) > 0) {
                        $arFields["SITE_ID"] = SITE_ID;
                    }
                    $authError = $this->AuthorizeUser($arFields);
                }
            }
        }
        $bSuccess = $authError === true;
        $aRemove = array("logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key", "current_fieldset");
        if ($bSuccess) {
            CSocServUtil::checkOAuthProxyParams();
            $url = $GLOBALS["APPLICATION"]->GetCurDir() == "/login/" ? "" : $GLOBALS["APPLICATION"]->GetCurDir();
            if (isset($_REQUEST['backurl'])) {
                $parseUrl = parse_url($_REQUEST['backurl']);
                $urlPath = $parseUrl["path"];
                $arUrlQuery = explode('&', $parseUrl["query"]);
                foreach ($arUrlQuery as $key => $value) {
                    foreach ($aRemove as $param) {
                        if (strpos($value, $param . "=") === 0) {
                            unset($arUrlQuery[$key]);
                            break;
                        }
                    }
                }
                $url = !empty($arUrlQuery) ? $urlPath . '?' . implode("&", $arUrlQuery) : $urlPath;
            }
        }
        if ($authError === SOCSERV_REGISTRATION_DENY) {
            $url = preg_match("/\\?/", $url) ? $url . '&' : $url . '?';
            $url .= 'auth_service_id=' . self::ID . '&auth_service_error=' . $authError;
        } elseif ($bSuccess !== true) {
            $url = isset($urlPath) ? $urlPath . '?auth_service_id=' . self::ID . '&auth_service_error=' . $authError : $GLOBALS['APPLICATION']->GetCurPageParam('auth_service_id=' . self::ID . '&auth_service_error=' . $authError, $aRemove);
        }
        if (CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false) {
            $url .= (strpos($url, "?") === false ? '?' : '&') . "current_fieldset=SOCSERV";
        }
        ?>
<script type="text/javascript">
if(window.opener)
	window.opener.location = '<?php 
        echo CUtil::JSEscape($url);
        ?>
';
window.close();
</script>
<?php 
        die;
    }