当前位置: 首页>>代码示例>>PHP>>正文


PHP XenForo_Helper_File::getTempDir方法代码示例

本文整理汇总了PHP中XenForo_Helper_File::getTempDir方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Helper_File::getTempDir方法的具体用法?PHP XenForo_Helper_File::getTempDir怎么用?PHP XenForo_Helper_File::getTempDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XenForo_Helper_File的用法示例。


在下文中一共展示了XenForo_Helper_File::getTempDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionZip

 /**
  * Exports an add-on's XML data.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionZip()
 {
     $addOnId = $this->_input->filterSingle('addon_id', XenForo_Input::STRING);
     $addOn = $this->_getAddOnOrError($addOnId);
     $rootDir = XenForo_Application::getInstance()->getRootDir();
     $zipPath = XenForo_Helper_File::getTempDir() . '/addon-' . $addOnId . '.zip';
     if (file_exists($zipPath)) {
         unlink($zipPath);
     }
     $zip = new ZipArchive();
     $res = $zip->open($zipPath, ZipArchive::CREATE);
     if ($res === TRUE) {
         $zip->addFromString('addon-' . $addOnId . '.xml', $this->_getAddOnModel()->getAddOnXml($addOn)->saveXml());
         if (is_dir($rootDir . '/library/' . $addOnId)) {
             $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/library/' . $addOnId));
             foreach ($iterator as $key => $value) {
                 $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key));
             }
         }
         if (is_dir($rootDir . '/js/' . strtolower($addOnId))) {
             $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/js/' . strtolower($addOnId)));
             foreach ($iterator as $key => $value) {
                 $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key));
             }
         }
         $zip->close();
     }
     if (!file_exists($zipPath) || !is_readable($zipPath)) {
         return $this->responseError(new XenForo_Phrase('devkit_error_while_creating_zip'));
     }
     $this->_routeMatch->setResponseType('raw');
     $attachment = array('filename' => 'addon-' . $addOnId . '_' . $addOn['version_string'] . '.zip', 'file_size' => filesize($zipPath), 'attach_date' => XenForo_Application::$time);
     $viewParams = array('attachment' => $attachment, 'attachmentFile' => $zipPath);
     return $this->responseView('XenForo_ViewAdmin_Attachment_View', '', $viewParams);
 }
开发者ID:Sywooch,项目名称:forums,代码行数:40,代码来源:AddOn.php

示例2: _createFiles

 protected function _createFiles(sonnb_XenGallery_Model_ContentData $model, $filePath, $contentData, $useTemp = true, $isVideo = false)
 {
     $smallThumbFile = $model->getContentDataSmallThumbnailFile($contentData);
     $mediumThumbFile = $model->getContentDataMediumThumbnailFile($contentData);
     $largeThumbFile = $model->getContentDataLargeThumbnailFile($contentData);
     $originalFile = $model->getContentDataFile($contentData);
     if ($useTemp) {
         $filename = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
         @copy($filePath, $filename);
     } else {
         $filename = $filePath;
     }
     if ($isVideo === false && $originalFile) {
         $directory = dirname($originalFile);
         if (XenForo_Helper_File::createDirectory($directory, true)) {
             @copy($filename, $originalFile);
             XenForo_Helper_File::makeWritableByFtpUser($originalFile);
         } else {
             return false;
         }
     }
     if ($isVideo === false) {
         $ext = sonnb_XenGallery_Model_ContentData::$typeMap[$contentData['extension']];
     } else {
         $ext = sonnb_XenGallery_Model_ContentData::$typeMap[sonnb_XenGallery_Model_VideoData::$videoEmbedExtension];
     }
     $model->createContentDataThumbnailFile($filename, $largeThumbFile, $ext, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_LARGE);
     $model->createContentDataThumbnailFile($largeThumbFile, $mediumThumbFile, $ext, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_MEDIUM);
     $model->createContentDataThumbnailFile($largeThumbFile, $smallThumbFile, $ext, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_SMALL);
     @unlink($filename);
     return true;
 }
开发者ID:Sywooch,项目名称:forums,代码行数:32,代码来源:Abstract.php

示例3: buildThumb

 public function buildThumb($mediaID, $thumbURL)
 {
     $targetLoc = XenForo_Helper_File::getExternalDataPath() . '/media/' . $mediaID . '.jpg';
     $thumbLoc = XenForo_Helper_File::getTempDir() . '/media' . $mediaID;
     if (substr($thumbURL, 0, 7) == 'http://') {
         $client = new Zend_Http_Client($thumbURL);
         $response = $client->request();
         $image = $response->getBody();
         file_put_contents($thumbLoc, $image);
     } else {
         copy($thumbURL, $thumbLoc);
     }
     $imageInfo = getimagesize($thumbLoc);
     if ($image = XenForo_Image_Abstract::createFromFile($thumbLoc, $imageInfo[2])) {
         $ratio = 160 / 90;
         $width = $image->getWidth();
         $height = $image->getHeight();
         if ($width / $height > $ratio) {
             $image->thumbnail($width, '90');
         } else {
             $image->thumbnail('160', $height);
         }
         $width = $image->getWidth();
         $height = $image->getHeight();
         $offWidth = ($width - 160) / 2;
         $offHeight = ($height - 90) / 2;
         $image->crop($offWidth, $offHeight, '160', '90');
         $image->output(IMAGETYPE_JPEG, $targetLoc);
     }
     if (file_exists($thumbLoc)) {
         unlink($thumbLoc);
     }
 }
开发者ID:Sywooch,项目名称:forums,代码行数:33,代码来源:Thumbs.php

示例4: download

 public static function download($url)
 {
     if (isset(self::$_cached[$url]) and file_exists(self::$_cached[$url])) {
         // use cached temp file, no need to re-download
         return self::$_cached[$url];
     }
     $tempFile = tempnam(XenForo_Helper_File::getTempDir(), self::_getPrefix());
     self::cache($url, $tempFile);
     $fh = fopen($tempFile, 'wb');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_FILE, $fh);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_exec($ch);
     $downloaded = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE)) == 200;
     curl_close($ch);
     fclose($fh);
     if (XenForo_Application::debugMode()) {
         $fileSize = filesize($tempFile);
         XenForo_Helper_File::log(__CLASS__, call_user_func_array('sprintf', array('download %s -> %s, %s, %d bytes%s', $url, $tempFile, $downloaded ? 'succeeded' : 'failed', $fileSize, !$downloaded && $fileSize > 0 ? "\n\t" . file_get_contents($tempFile) : '')));
     }
     if ($downloaded) {
         return $tempFile;
     } else {
         return false;
     }
 }
开发者ID:billyprice1,项目名称:bdApi,代码行数:28,代码来源:TempFile.php

示例5: _applyIcon

 protected static function _applyIcon($node, $upload, $number, $size, $nodeType)
 {
     if (!$upload->isValid()) {
         throw new XenForo_Exception($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $imageType = $upload->getImageInfoField('type');
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $outputFiles = array();
     $fileName = $upload->getTempFile();
     $imageType = $upload->getImageInfoField('type');
     $outputType = $imageType;
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfa');
     $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType);
     if (!$image) {
         continue;
     }
     if ($size > 0) {
         $image->thumbnailFixedShorterSide($size);
         if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) {
             $x = floor(($image->getWidth() - $size) / 2);
             $y = floor(($image->getHeight() - $size) / 2);
             $image->crop($x, $y, $size, $size);
         }
     }
     $image->output($outputType, $newTempFile, self::$imageQuality);
     unset($image);
     $icons = $newTempFile;
     switch ($nodeType) {
         case 'forum':
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Forum');
             $dwData = array('brcns_pixel_' . $number => $size, 'brcns_icon_date_' . $number => XenForo_Application::$time, 'brcns_select' => 'file');
             break;
         case 'page':
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Page');
             $dwData = array('brcns_pixel' => $size, 'brcns_icon_date' => XenForo_Application::$time, 'brcns_select' => 'file');
             break;
         case 'link':
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_LinkForum');
             $dwData = array('brcns_pixel' => $size, 'brcns_icon_date' => XenForo_Application::$time, 'brcns_select' => 'file');
             break;
         case 'category':
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Category');
             $dwData = array('brcns_pixel' => $size, 'brcns_icon_date' => XenForo_Application::$time, 'brcns_select' => 'file');
             break;
     }
     $dw->setExistingData($node['node_id']);
     $dw->bulkSet($dwData);
     $dw->save();
     return $icons;
 }
开发者ID:darkearl,项目名称:projectT122015,代码行数:57,代码来源:Icon.php

示例6: applyResourceIcon

 /**
  *
  * @see XenResource_Model_Resource::applyResourceIcon()
  *
  */
 public function applyResourceIcon($resourceId, $fileName, $imageType = false, $width = false, $height = false)
 {
     if (!$imageType || !$width || !$height) {
         $imageInfo = getimagesize($fileName);
         if (!$imageInfo) {
             return parent::applyResourceIcon($resourceId, $fileName, $imageType, $width, $height);
         }
         $width = $imageInfo[0];
         $height = $imageInfo[1];
         $imageType = $imageInfo[2];
     }
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         return parent::applyResourceIcon($resourceId, $fileName, $imageType, $width, $height);
     }
     if (!XenForo_Image_Abstract::canResize($width, $height)) {
         return parent::applyResourceIcon($resourceId, $fileName, $imageType, $width, $height);
     }
     $imageQuality = self::$iconQuality;
     $outputType = $imageType;
     $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType);
     if (!$image) {
         return false;
     }
     $maxDimensions = max(array($image->getWidth(), $image->getHeight()));
     if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) {
         $x = floor(($maxDimensions - $image->getWidth()) / 2);
         $y = floor(($maxDimensions - $image->getHeight()) / 2);
         $image->resizeCanvas($x, $y, $maxDimensions, $maxDimensions);
     }
     $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
     if (!$newTempFile) {
         return false;
     }
     $image->output($outputType, $newTempFile, $imageQuality);
     unset($image);
     $returnValue = parent::applyResourceIcon($resourceId, $newTempFile, $imageType, $width, $height);
     if ($returnValue) {
         $filePath = $this->getResourceIconFilePath($resourceId);
         $image = XenForo_Image_Abstract::createFromFile($filePath, $imageType);
         if (!$image) {
             return false;
         }
         $width = XenForo_Application::get('options')->th_resourceIcons_width;
         $height = XenForo_Application::get('options')->th_resourceIcons_height;
         $x = floor(($width - $image->getWidth()) / 2);
         $y = floor(($height - $image->getHeight()) / 2);
         $image->resizeCanvas($x, $y, $width, $height);
         $image->output($outputType, $filePath, $imageQuality);
         unset($image);
     }
 }
开发者ID:ThemeHouse-XF,项目名称:ResourceIcons,代码行数:56,代码来源:Resource.php

示例7: insertUploadedAttachmentData

 public function insertUploadedAttachmentData(XenForo_Upload $file, $userId, array $extra = array())
 {
     $filename = $file->getFileName();
     $extension = XenForo_Helper_File::getFileExtension($filename);
     if ($extension == 'svg') {
         list($svgfile, $dimensions) = $this->extractDimensionsForSVG($file->getTempFile(), XenForo_Application::getOptions()->SV_RejectAttachmentWithBadTags);
         if (!empty($svgfile) && !empty($dimensions)) {
             if ($dimensions['thumbnail_width'] && $dimensions['thumbnail_height']) {
                 $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
                 if ($tempThumbFile) {
                     // update the width/height attributes
                     $svgfile['width'] = (string) $dimensions['thumbnail_width'];
                     $svgfile['height'] = (string) $dimensions['thumbnail_height'];
                     $svgfile->asXML($tempThumbFile);
                     SV_AttachmentImprovements_Globals::$tempThumbFile = $tempThumbFile;
                 }
             }
             SV_AttachmentImprovements_Globals::$forcedDimensions = $dimensions;
         }
     }
     return parent::insertUploadedAttachmentData($file, $userId, $extra);
 }
开发者ID:Xon,项目名称:XenForo-AttachmentImprovements,代码行数:22,代码来源:Attachment.php

示例8: stepAttachments

    public function stepAttachments($start, array $options)
    {
        $options = array_merge(array('limit' => 50, 'max' => false), $options);
        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        if ($options['max'] === false) {
            $options['max'] = $sDb->fetchOne('
				SELECT MAX(attach_id)
				FROM ' . $prefix . 'attachments
			');
        }
        $attachments = $sDb->fetchAll($sDb->limit('
				SELECT
					attach_id, attach_date, attach_hits,
					attach_file, attach_location,
					attach_member_id AS member_id,
					attach_rel_id AS post_id
				FROM ' . $prefix . 'attachments
				WHERE attach_id > ' . $sDb->quote($start) . '
					AND attach_rel_module = \'post\'
				ORDER BY attach_id
			', $options['limit']));
        if (!$attachments) {
            return true;
        }
        $next = 0;
        $total = 0;
        $userIdMap = $model->getUserIdsMapFromArray($attachments, 'member_id');
        $postIdMap = $model->getPostIdsMapFromArray($attachments, 'post_id');
        $posts = $model->getModelFromCache('XenForo_Model_Post')->getPostsByIds($postIdMap);
        foreach ($attachments as $attachment) {
            $next = $attachment['attach_id'];
            $newPostId = $this->_mapLookUp($postIdMap, $attachment['post_id']);
            if (!$newPostId) {
                continue;
            }
            $attachFileOrig = $this->_config['ipboard_path'] . '/uploads/' . $attachment['attach_location'];
            if (!file_exists($attachFileOrig)) {
                continue;
            }
            $attachFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
            copy($attachFileOrig, $attachFile);
            $isTemp = true;
            $success = $model->importPostAttachment($attachment['attach_id'], $this->_convertToUtf8($attachment['attach_file']), $attachFile, $this->_mapLookUp($userIdMap, $attachment['member_id'], 0), $newPostId, $attachment['attach_date'], array('view_count' => $attachment['attach_hits']), array($this, 'processAttachmentTags'), $posts[$newPostId]['message']);
            if ($success) {
                $total++;
            }
            if ($isTemp) {
                @unlink($attachFile);
            }
        }
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }
开发者ID:namgiangle90,项目名称:tokyobaito,代码行数:56,代码来源:IPBoard.php

示例9: stepAttachments

    /**
     * Currently handles attachments for posts and conversation messages only
     *
     * @param integer $start
     * @param array $options
     */
    public function stepAttachments($start, array $options)
    {
        $options = array_merge(array('data' => isset($this->_config['dir']['data']) ? $this->_config['dir']['data'] : '', 'internal_data' => isset($this->_config['dir']['internal_data']) ? $this->_config['dir']['internal_data'] : '', 'limit' => 50, 'max' => false), $options);
        $sDb = $this->_sourceDb;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        $attachmentSqlContentInfo = $model->getAttachmentContentSqlInfo();
        if ($options['max'] === false) {
            $options['max'] = $sDb->fetchOne('
				SELECT MAX(attachment_id)
				FROM xf_attachment
				WHERE content_type IN (' . $sDb->quote(array_keys($attachmentSqlContentInfo)) . ')
			');
        }
        $attachments = $sDb->fetchAll($sDb->limit('
				SELECT *
				FROM xf_attachment AS a
				LEFT JOIN xf_attachment_data AS ad ON (ad.data_id = a.data_id)
				WHERE a.content_type IN (' . $sDb->quote(array_keys($attachmentSqlContentInfo)) . ')
					AND a.attachment_id > ' . $sDb->quote($start) . '
				ORDER BY a.attachment_id
			', $options['limit']));
        if (!$attachments) {
            return true;
        }
        $next = 0;
        $total = 0;
        $userIdMap = $model->getUserIdsMapFromArray($attachments, 'user_id');
        $groupedAttachments = array();
        foreach ($attachments as $attachment) {
            $groupedAttachments[$attachment['content_type']][$attachment['attachment_id']] = $attachment;
        }
        $db = XenForo_Application::getDb();
        /* @var $attachModel XenForo_Model_Attachment */
        $attachModel = XenForo_Model::create('XenForo_Model_Attachment');
        foreach ($groupedAttachments as $contentType => $attachments) {
            list($sqlTableName, $sqlIdName) = $attachmentSqlContentInfo[$contentType];
            $contentIdMap = $model->getImportContentMap($contentType, XenForo_Application::arrayColumn($attachments, 'content_id'));
            if ($contentIdMap) {
                $contentItems = $db->fetchPairs("\r\r\n\t\t\t\t\tSELECT {$sqlIdName}, message\r\r\n\t\t\t\t\tFROM {$sqlTableName}\r\r\n\t\t\t\t\tWHERE {$sqlIdName} IN (" . $db->quote($contentIdMap) . ")\r\r\n\t\t\t\t");
            } else {
                $contentItems = array();
            }
            foreach ($attachments as $attachment) {
                $next = max($next, $attachment['attachment_id']);
                $contentId = $this->_mapLookUp($contentIdMap, $attachment['content_id']);
                if (!$contentId || !isset($contentItems[$contentId])) {
                    continue;
                }
                $attachFileOrig = $attachModel->getAttachmentDataFilePath($attachment, $options['internal_data']);
                if (!file_exists($attachFileOrig)) {
                    continue;
                }
                $userId = $this->_mapLookUp($userIdMap, $attachment['user_id'], 0);
                $attachFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
                copy($attachFileOrig, $attachFile);
                $success = $model->importAttachment($attachment['attachment_id'], $attachment['filename'], $attachFile, $userId, $contentType, $contentId, $attachment['upload_date'], array('view_count' => $attachment['view_count']), array($this, 'processAttachmentTags'), $contentItems[$contentId]);
                if ($success) {
                    $total++;
                }
                @unlink($attachFile);
            }
        }
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }
开发者ID:Sywooch,项目名称:forums,代码行数:72,代码来源:XenForo.php

示例10: applyCategoryIcon

 public function applyCategoryIcon($categoryId, $fileName, $imageType = false, $width = false, $height = false)
 {
     if (!$imageType || !$width || !$height) {
         $imageInfo = getimagesize($fileName);
         if (!$imageInfo) {
             throw new XenForo_Exception('Non-image passed in to applyCategoryIcon');
         }
         $width = $imageInfo[0];
         $height = $imageInfo[1];
         $imageType = $imageInfo[2];
     }
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     if (!XenForo_Image_Abstract::canResize($width, $height)) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_image_is_too_big'), true);
     }
     $maxDimensions = self::$iconSize;
     $imageQuality = self::$iconQuality;
     $outputType = $imageType;
     $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType);
     if (!$image) {
         return false;
     }
     $image->thumbnailFixedShorterSide($maxDimensions);
     if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) {
         $cropX = floor(($image->getWidth() - $maxDimensions) / 2);
         $cropY = floor(($image->getHeight() - $maxDimensions) / 2);
         $image->crop($cropX, $cropY, $maxDimensions, $maxDimensions);
     }
     $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
     if (!$newTempFile) {
         return false;
     }
     $image->output($outputType, $newTempFile, $imageQuality);
     unset($image);
     $filePath = $this->getCategoryIconFilePath($categoryId);
     $directory = dirname($filePath);
     if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
         $writeSuccess = XenForo_Helper_File::safeRename($newTempFile, $filePath);
         if ($writeSuccess && file_exists($newTempFile)) {
             @unlink($newTempFile);
         }
     } else {
         $writeSuccess = false;
     }
     if ($writeSuccess) {
         $dw = XenForo_DataWriter::create('Nobita_Teams_DataWriter_Category');
         $dw->setExistingData($categoryId);
         $dw->set('icon_date', XenForo_Application::$time);
         $dw->save();
     }
     return $writeSuccess;
 }
开发者ID:Sywooch,项目名称:forums,代码行数:57,代码来源:Category.php

示例11: stepAttachments

    public function stepAttachments($start, array $options)
    {
        $options = array_merge(array('path' => isset($this->_config['attachmentPath']) ? $this->_config['attachmentPath'] : '', 'limit' => 50, 'max' => false), $options);
        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        if ($options['max'] === false) {
            $options['max'] = $sDb->fetchOne('
				SELECT MAX(attach_id)
				FROM ' . $prefix . 'attachments
			');
        }
        $attachments = $sDb->fetchAll($sDb->limit('
				SELECT *
				FROM ' . $prefix . 'attachments
				WHERE attach_id > ' . $sDb->quote($start) . '
					AND is_orphan = 0
					AND post_msg_id > 0
				ORDER BY attach_id
			', $options['limit']));
        if (!$attachments) {
            return true;
        }
        $next = 0;
        $total = 0;
        $userIdMap = $model->getUserIdsMapFromArray($attachments, 'poster_id');
        $postIdMap = $model->getPostIdsMapFromArray($attachments, 'post_msg_id');
        foreach ($attachments as $attachment) {
            $next = $attachment['attach_id'];
            $newPostId = $this->_mapLookUp($postIdMap, $attachment['post_msg_id']);
            if (!$newPostId) {
                continue;
            }
            $attachFileOrig = "{$options['path']}/{$attachment['physical_filename']}";
            if (!file_exists($attachFileOrig) || !is_file($attachFileOrig)) {
                continue;
            }
            $attachFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
            copy($attachFileOrig, $attachFile);
            $success = $model->importPostAttachment($attachment['attach_id'], $this->_convertToUtf8($attachment['real_filename'], true), $attachFile, $this->_mapLookUp($userIdMap, $attachment['poster_id'], 0), $newPostId, $attachment['filetime'], array('view_count' => $attachment['download_count']));
            if ($success) {
                $total++;
            }
            @unlink($attachFile);
        }
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }
开发者ID:VoDongMy,项目名称:xenforo-laravel5.1,代码行数:49,代码来源:PhpBb3.php

示例12: actionFacebookRegister

 /**
  * Registers a new account (or associates with an existing one) using Facebook.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionFacebookRegister()
 {
     $this->_assertPostOnly();
     $fbToken = $this->_input->filterSingle('fb_token', XenForo_Input::STRING);
     $fbUser = XenForo_Helper_Facebook::getUserInfo($fbToken);
     if (empty($fbUser['id'])) {
         return $this->responseError(new XenForo_Phrase('error_occurred_while_connecting_with_facebook'));
     }
     $userModel = $this->_getUserModel();
     $userExternalModel = $this->_getUserExternalModel();
     $doAssoc = $this->_input->filterSingle('associate', XenForo_Input::STRING) || $this->_input->filterSingle('force_assoc', XenForo_Input::UINT);
     if ($doAssoc) {
         $associate = $this->_input->filter(array('associate_login' => XenForo_Input::STRING, 'associate_password' => XenForo_Input::STRING));
         $loginModel = $this->_getLoginModel();
         if ($loginModel->requireLoginCaptcha($associate['associate_login'])) {
             return $this->responseError(new XenForo_Phrase('your_account_has_temporarily_been_locked_due_to_failed_login_attempts'));
         }
         $userId = $userModel->validateAuthentication($associate['associate_login'], $associate['associate_password'], $error);
         if (!$userId) {
             $loginModel->logLoginAttempt($associate['associate_login']);
             return $this->responseError($error);
         }
         $userExternalModel->updateExternalAuthAssociation('facebook', $fbUser['id'], $userId);
         XenForo_Helper_Facebook::setUidCookie($fbUser['id']);
         XenForo_Application::get('session')->changeUserId($userId);
         XenForo_Visitor::setup($userId);
         $redirect = XenForo_Application::get('session')->get('fbRedirect');
         XenForo_Application::get('session')->remove('fbRedirect');
         if (!$redirect) {
             $redirect = $this->getDynamicRedirect(false, false);
         }
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $redirect);
     }
     $this->_assertRegistrationActive();
     $data = $this->_input->filter(array('username' => XenForo_Input::STRING, 'timezone' => XenForo_Input::STRING));
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         return $this->responseError(new XenForo_Phrase('you_must_agree_to_terms_of_service'));
     }
     $options = XenForo_Application::get('options');
     $gender = '';
     if (isset($fbUser['gender'])) {
         switch ($fbUser['gender']) {
             case 'man':
             case 'male':
                 $gender = 'male';
                 break;
             case 'woman':
             case 'female':
                 $gender = 'female';
                 break;
         }
     }
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     $writer->bulkSet($data);
     $writer->bulkSet(array('gender' => $gender, 'email' => $fbUser['email'], 'location' => isset($fbUser['location']['name']) ? $fbUser['location']['name'] : ''));
     if (!empty($fbUser['birthday'])) {
         $birthdayParts = explode('/', $fbUser['birthday']);
         if (count($birthdayParts) == 3) {
             list($month, $day, $year) = $birthdayParts;
             $userAge = $this->_getUserProfileModel()->calculateAge($year, $month, $day);
             if ($userAge < intval($options->get('registrationSetup', 'minimumAge'))) {
                 // TODO: set a cookie to prevent re-registration attempts
                 return $this->responseError(new XenForo_Phrase('sorry_you_too_young_to_create_an_account'));
             }
             $writer->bulkSet(array('dob_year' => $year, 'dob_month' => $month, 'dob_day' => $day));
         }
     }
     if (!empty($fbUser['website'])) {
         list($website) = preg_split('/\\r?\\n/', $fbUser['website']);
         if ($website && Zend_Uri::check($website)) {
             $writer->set('homepage', $website);
         }
     }
     $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
     $writer->set('scheme_class', $auth->getClassName());
     $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $writer->advanceRegistrationUserState(false);
     $writer->preSave();
     // TODO: option for extra user group
     $writer->save();
     $user = $writer->getMergedData();
     $avatarFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
     if ($avatarFile) {
         $data = XenForo_Helper_Facebook::getUserPicture($fbToken);
         if ($data && $data[0] != '{') {
             file_put_contents($avatarFile, $data);
             try {
                 $user = array_merge($user, $this->getModelFromCache('XenForo_Model_Avatar')->applyAvatar($user['user_id'], $avatarFile));
             } catch (XenForo_Exception $e) {
             }
//.........这里部分代码省略.........
开发者ID:hahuunguyen,项目名称:DTUI_201105,代码行数:101,代码来源:Register.php

示例13: getTempFile

 /**
  * Gets the path to the written file for a stream URI
  *
  * @param string $path
  *
  * @return string
  */
 public static function getTempFile($path)
 {
     $path = preg_replace('#^[a-z0-9_-]+://#i', '', $path);
     return XenForo_Helper_File::getTempDir() . '/' . strtr($path, '/\\.', '---') . '.temp';
 }
开发者ID:VoDongMy,项目名称:xenforo-laravel5.1,代码行数:12,代码来源:ImageProxyStream.php

示例14: stepAttachments

    public function stepAttachments($start, array $options)
    {
        $options = array_merge(array('attachmentPaths' => isset($this->_config['attachmentPaths']) ? $this->_config['attachmentPaths'] : '', 'limit' => 50, 'max' => false), $options);
        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        if ($options['max'] === false) {
            $options['max'] = $sDb->fetchOne('
				SELECT MAX(id_attach)
				FROM ' . $prefix . 'attachments
			');
        }
        $attachments = $sDb->fetchAll($sDb->limit('
				SELECT attachments.*, messages.id_member, messages.poster_time
				FROM ' . $prefix . 'attachments AS attachments
				INNER JOIN ' . $prefix . 'messages AS messages ON
				 	(messages.id_msg = attachments.id_msg)
				WHERE attachments.id_attach > ' . $sDb->quote($start) . '
					AND attachments.id_msg > 0
					AND attachments.id_member = 0
					AND attachments.attachment_type = 0
				ORDER BY attachments.id_attach
			', $options['limit']));
        if (!$attachments) {
            return true;
        }
        $next = 0;
        $total = 0;
        $userIdMap = $model->getUserIdsMapFromArray($attachments, 'id_member');
        $postIdMap = $model->getPostIdsMapFromArray($attachments, 'id_msg');
        foreach ($attachments as $attachment) {
            $next = $attachment['id_attach'];
            $newPostId = $this->_mapLookUp($postIdMap, $attachment['id_msg']);
            if (!$newPostId) {
                continue;
            }
            if (!isset($options['attachmentPaths'][$attachment['id_folder']])) {
                // Single attachment folder environment.
                $attachmentPath = $options['attachmentPaths'][0];
            } else {
                $attachmentPath = $options['attachmentPaths'][$attachment['id_folder']];
            }
            $filePath = "{$attachmentPath}/{$attachment['id_attach']}_{$attachment['file_hash']}";
            if (!file_exists($filePath)) {
                continue;
            }
            $attachFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
            copy($filePath, $attachFile);
            $success = $model->importPostAttachment($attachment['id_attach'], $this->_convertToUtf8($attachment['filename'], true), $attachFile, $this->_mapLookUp($userIdMap, $attachment['id_member'], 0), $newPostId, $attachment['poster_time'], array('view_count' => $attachment['downloads']));
            if ($success) {
                $total++;
            }
            @unlink($attachFile);
        }
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }
开发者ID:namgiangle90,项目名称:tokyobaito,代码行数:58,代码来源:SMF.php

示例15: applyAvatar

 /**
  * Applies the avatar file to the specified user.
  *
  * @param integer $teamId
  * @param string $fileName
  * @param constant|false $imageType Type of image (IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)
  * @param integer|false $width
  * @param integer|false $height
  *
  * @return array
  */
 public function applyAvatar($teamId, $fileName, $imageType = false, $width = false, $height = false)
 {
     if (!$imageType || !$width || !$height) {
         $imageInfo = getimagesize($fileName);
         if (!$imageInfo) {
             throw new Nobita_Teams_Exception_Abstract('Non-image passed in to applyAvatar');
         }
         $width = $imageInfo[0];
         $height = $imageInfo[1];
         $imageType = $imageInfo[2];
     }
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new Nobita_Teams_Exception_Abstract('Invalid image type passed in to applyAvatar');
     }
     if (!XenForo_Image_Abstract::canResize($width, $height)) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_image_is_too_big'), true);
     }
     $maxFileSize = XenForo_Application::getOptions()->Teams_avatarFileSize;
     if ($maxFileSize && filesize($fileName) > $maxFileSize) {
         @unlink($fileName);
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('your_avatar_file_size_large_smaller_x', array('size' => XenForo_Locale::numberFormat($maxFileSize, 'size'))), true);
     }
     // should be use 280x280px because of grid style
     $maxDimensions = 280;
     $imageQuality = intval(Nobita_Teams_Setup::getInstance()->getOption('logoQuality'));
     $outputType = $imageType;
     $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType);
     if (!$image) {
         return false;
     }
     $image->thumbnailFixedShorterSide($maxDimensions);
     if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) {
         $cropX = floor(($image->getWidth() - $maxDimensions) / 2);
         $cropY = floor(($image->getHeight() - $maxDimensions) / 2);
         $image->crop($cropX, $cropY, $maxDimensions, $maxDimensions);
     }
     $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
     if (!$newTempFile) {
         return false;
     }
     $image->output($outputType, $newTempFile, $imageQuality);
     unset($image);
     $filePath = $this->getAvatarFilePath($teamId);
     $directory = dirname($filePath);
     if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
         $writeSuccess = XenForo_Helper_File::safeRename($newTempFile, $filePath);
         if ($writeSuccess && file_exists($newTempFile)) {
             @unlink($newTempFile);
         }
     } else {
         $writeSuccess = false;
     }
     $date = XenForo_Application::$time;
     if ($writeSuccess) {
         $dw = XenForo_DataWriter::create('Nobita_Teams_DataWriter_Team');
         $dw->setExistingData($teamId);
         $dw->set('team_avatar_date', $date);
         $dw->save();
     }
     return $writeSuccess ? $date : 0;
 }
开发者ID:Sywooch,项目名称:forums,代码行数:75,代码来源:Avatar.php


注:本文中的XenForo_Helper_File::getTempDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。