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


PHP CFactory::getUserFromTokenId方法代码示例

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


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

示例1: upload

 /**
  * Called during photo uploading.
  * @return type
  */
 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = $jinput->request->get('token', '', 'NONE');
         $userId = $jinput->request->get('uploaderid', '', 'NONE');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session = JFactory::getSession();
         $session->set('user', $my);
     }
     if (CLimitsLibrary::exceedDaily('photos', $my->id)) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_PHOTOS_LIMIT_PERDAY_REACHED'));
         return;
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     $photos = JRequest::get('Files');
     $albumId = $jinput->request->get('albumid', '', 'INT');
     $album = $this->_getRequestUserAlbum($albumId);
     // Uploaded images count in this batch
     $batchCount = $jinput->request->get('batchcount', '', 'INT');
     $handler = $this->_getHandler($album);
     /* Do process for all photos */
     foreach ($photos as $imageFile) {
         /* Validating */
         $result = $this->_checkUploadedFile($imageFile, $album, $handler);
         if (!$result['photoTable']) {
             continue;
         }
         //assign the result of the array and assigned to the right variable
         $photoTable = $result['photoTable'];
         $storage = $result['storage'];
         $albumPath = $result['albumPath'];
         $hashFilename = $result['hashFilename'];
         $thumbPath = $result['thumbPath'];
         $originalPath = $result['originalPath'];
         $imgType = $result['imgType'];
         $isDefaultPhoto = $result['isDefaultPhoto'];
         // Remove the filename extension from the caption
         if (JString::strlen($photoTable->caption) > 4) {
             $photoTable->caption = JString::substr($photoTable->caption, 0, JString::strlen($photoTable->caption) - 4);
         }
         // @todo: configurable options?
         // Permission should follow album permission
         $photoTable->published = '1';
         $photoTable->permissions = $album->permissions;
         // Set the relative path.
         // @todo: configurable path?
         $storedPath = $handler->getStoredPath($storage, $album->id);
         $storedPath = $storedPath . '/' . $albumPath . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         $photoTable->image = CString::str_ireplace(JPATH_ROOT . '/', '', $storedPath);
         $photoTable->thumbnail = CString::str_ireplace(JPATH_ROOT . '/', '', $thumbPath);
         //In joomla 1.6, CString::str_ireplace is not replacing the path properly. Need to do a check here
         if ($photoTable->image == $storedPath) {
             $photoTable->image = str_ireplace(JPATH_ROOT . '/', '', $storedPath);
         }
         if ($photoTable->thumbnail == $thumbPath) {
             $photoTable->thumbnail = str_ireplace(JPATH_ROOT . '/', '', $thumbPath);
         }
         //photo filesize, use sprintf to prevent return of unexpected results for large file.
         $photoTable->filesize = sprintf("%u", filesize($originalPath));
         // @rule: Set the proper ordering for the next photo upload.
         $photoTable->setOrdering();
         // Store the object
         $photoTable->store();
         // We need to see if we need to rotate this image, from EXIF orientation data
         // Only for jpeg image.
         if ($config->get('photos_auto_rotate') && $imgType == 'image/jpeg') {
             $this->_rotatePhoto($imageFile, $photoTable, $storedPath, $thumbPath);
         }
         // Trigger for onPhotoCreate
         $apps = CAppPlugins::getInstance();
         $apps->loadApplications();
         $params = array();
         $params[] = $photoTable;
         $apps->triggerEvent('onPhotoCreate', $params);
         // Set image as default if necessary
         // Load photo album table
         if ($isDefaultPhoto) {
             // Set the photo id
             $album->photoid = $photoTable->id;
             $album->store();
         }
         // @rule: Set first photo as default album cover if enabled
         if (!$isDefaultPhoto && $config->get('autoalbumcover')) {
             $photosModel = CFactory::getModel('Photos');
             $totalPhotos = $photosModel->getTotalPhotos($album->id);
             if ($totalPhotos <= 1) {
                 $album->photoid = $photoTable->id;
//.........这里部分代码省略.........
开发者ID:Jougito,项目名称:DynWeb,代码行数:101,代码来源:photos.php

示例2: multiUpload

 public function multiUpload()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $type = $jinput->get('type', NULL, 'NONE');
     $id = $jinput->get('id', '0', 'Int');
     if ($my->id == 0) {
         $tokenId = $jinput->request->get('token', '', 'STRING');
         $userId = $jinput->request->get('uploaderid', '', 'INT');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session = JFactory::getSession();
         $session->set('user', $my);
     }
     $parentTable = JTable::getInstance(ucfirst($type), 'CTable');
     $parentTable->load($id);
     $table = JTable::getInstance('File', 'CTable');
     $_file = $jinput->files->get('file');
     $fileLib = new CFilesLibrary();
     if (CLimitsLibrary::exceedDaily('files', $my->id)) {
         $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED'));
         echo json_encode($json);
         exit;
     }
     if ($type == 'discussion' && !CLimitsHelper::exceededGroupFileUpload($parentTable->groupid)) {
         $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED'));
         echo json_encode($json);
         exit;
     }
     $now = new JDate();
     $ext = pathinfo($_file['name']);
     $file = new stdClass();
     $file->creator = $my->id;
     $file->filesize = sprintf("%u", $_file['size']);
     $file->name = JString::substr($_file['name'], 0, JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1));
     $file->created = $now->toSql();
     $file->type = CFileHelper::getExtensionIcon(CFileHelper::getFileExtension($_file['name']));
     $fileName = JApplication::getHash($_file['name'] . time()) . JString::substr($_file['name'], JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1));
     if ($_file['error'] > 0 && $_file['error'] !== 'UPLOAD_ERR_OK') {
         $json = array('msg' => JText::sprintf('COM_COMMUNITY_PHOTOS_UPLOAD_ERROR', $_file['error']));
         echo json_encode($json);
         exit;
     }
     if (!$fileLib->checkType($_file['name'])) {
         $json = array('msg' => JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'));
         echo json_encode($json);
         exit;
     }
     switch ($type) {
         case 'discussion':
             $file->discussionid = $parentTable->id;
             $file->groupid = $parentTable->groupid;
             $file->filepath = 'images/files' . '/' . $type . '/' . $file->discussionid . '/' . $fileName;
             break;
         case 'bulletin':
             $file->bulletinid = $parentTable->id;
             $file->groupid = $parentTable->groupid;
             $file->filepath = 'images/files' . '/' . $type . '/' . $file->bulletinid . '/' . $fileName;
             break;
         case 'message':
             $file->messageid = -1;
             // set as -1 just in case this is not used and cron can clear it later
             if ($id) {
                 $file->filepath = 'images/files/' . $type . '/' . $id . '/' . $fileName;
                 if (!JFolder::exists(JPATH_ROOT . '/images/files/' . $type . '/' . $id)) {
                     JFolder::create(JPATH_ROOT . '/images/files/' . $type . '/' . $id, (int) octdec($config->get('folderpermissionsphoto')));
                     JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/images/files/' . $type . '/' . $id . '/index.html');
                 }
                 JFile::copy($_file['tmp_name'], JPATH_ROOT . '/' . $file->filepath);
             } else {
                 //this could be from new message, and there is no id given
                 $file->filepath = 'images/files/' . $type . '/temp/' . $fileName;
                 //create the folder here as the logic for bulletin and discussion is not the same
                 if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/temp')) {
                     JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/temp', (int) octdec($config->get('folderpermissionsphoto')));
                     JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/temp/index.html');
                 }
                 JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/temp/' . $fileName);
             }
             break;
     }
     if ($type != 'message') {
         if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/' . $parentTable->id)) {
             JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id, (int) octdec($config->get('folderpermissionsphoto')));
             JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/' . $parentTable->id . '/index.html');
         }
         JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id . '/' . $fileName);
     }
     $table->bind($file);
     $table->store();
     $params = new CParameter('');
     switch ($type) {
         case 'discussion':
             // Get repliers for this discussion and notify the discussion creator too
             $discussionModel = CFactory::getModel('Discussions');
             $discussion = JTable::getInstance('Discussion', 'CTable');
             $discussion->load($parentTable->id);
             $users = $discussionModel->getRepliers($discussion->id, $discussion->groupid);
             $users[] = $discussion->creator;
//.........这里部分代码省略.........
开发者ID:joshjim27,项目名称:jobsglobal,代码行数:101,代码来源:files.php

示例3: upload

 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = JRequest::getVar('token', '', 'REQUEST');
         $userId = JRequest::getVar('uploaderid', '', 'REQUEST');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     CFactory::load('libraries', 'photos');
     CFactory::load('models', 'photos');
     CFactory::load('helpers', 'image');
     $photos = JRequest::get('Files');
     $albumId = JRequest::getVar('albumid', '', 'REQUEST');
     $album =& JTable::getInstance('Album', 'CTable');
     $album->load($albumId);
     $handler = $this->_getHandler($album);
     foreach ($photos as $imageFile) {
         if (!$this->_validImage($imageFile)) {
             $this->_showUploadError(true, $this->getError());
             return;
         }
         if ($this->_imageLimitExceeded(filesize($imageFile['tmp_name']))) {
             $this->_showUploadError(true, JText::_('CC IMAGE FILE SIZE EXCEEDED'));
             return;
         }
         // We need to read the filetype as uploaded always return application/octet-stream
         // regardless od the actual file type
         $info = getimagesize($imageFile['tmp_name']);
         $isDefaultPhoto = JRequest::getVar('defaultphoto', false, 'REQUEST');
         if ($album->id == 0 || $my->id != $album->creator && $album->type != PHOTOS_GROUP_TYPE) {
             $this->_showUploadError(true, JText::_('CC INVALID ALBUM'));
             return;
         }
         if (!$album->hasAccess($my->id, 'upload')) {
             $this->_showUploadError(true, JText::_('CC INVALID ALBUM'));
             return;
         }
         // Hash the image file name so that it gets as unique possible
         $fileName = JUtility::getHash($imageFile['tmp_name'] . time());
         $hashFilename = JString::substr($fileName, 0, 24);
         $imgType = image_type_to_mime_type($info[2]);
         // Load the tables
         $photoTable =& JTable::getInstance('Photo', 'CTable');
         // @todo: configurable paths?
         $storage = JPATH_ROOT . DS . $config->getString('photofolder');
         $albumPath = empty($album->path) ? '' : $album->id . DS;
         // Test if the photos path really exists.
         jimport('joomla.filesystem.file');
         jimport('joomla.filesystem.folder');
         CFactory::load('helpers', 'limits');
         $originalPath = $handler->getOriginalPath($storage, $albumPath, $album->id);
         CFactory::load('helpers', 'owner');
         // @rule: Just in case user tries to exploit the system, we should prevent this from even happening.
         if ($handler->isExceedUploadLimit() && !COwnerHelper::isCommunityAdmin()) {
             $config = CFactory::getConfig();
             $photoLimit = $config->get('groupphotouploadlimit');
             echo JText::sprintf('CC GROUP PHOTO UPLOAD LIMIT REACHED', $photoLimit);
             return;
         }
         if (!JFolder::exists($originalPath)) {
             if (!JFolder::create($originalPath, (int) octdec($config->get('folderpermissionsphoto')))) {
                 $this->_showUploadError(true, JText::_('CC ERROR CREATING USERS PHOTO FOLDER'));
                 return;
             }
         }
         $locationPath = $handler->getLocationPath($storage, $albumPath, $album->id);
         if (!JFolder::exists($locationPath)) {
             if (!JFolder::create($locationPath, (int) octdec($config->get('folderpermissionsphoto')))) {
                 $this->_showUploadError(true, JText::_('CC ERROR CREATING USERS PHOTO FOLDER'));
                 return;
             }
         }
         $thumbPath = $handler->getThumbPath($storage, $album->id);
         $thumbPath = $thumbPath . DS . $albumPath . 'thumb_' . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         CPhotos::generateThumbnail($imageFile['tmp_name'], $thumbPath, $imgType);
         // Original photo need to be kept to make sure that, the gallery works
         $useAlbumId = empty($album->path) ? 0 : $album->id;
         $originalFile = $originalPath . $hashFilename . CImageHelper::getExtension($imgType);
         $this->_storeOriginal($imageFile['tmp_name'], $originalFile, $useAlbumId);
         $photoTable->original = JString::str_ireplace(JPATH_ROOT . DS, '', $originalFile);
         // Set photos properties
         $photoTable->albumid = $albumId;
         $photoTable->caption = $imageFile['name'];
         $photoTable->creator = $my->id;
         $photoTable->created = gmdate('Y-m-d H:i:s');
         // Remove the filename extension from the caption
         if (JString::strlen($photoTable->caption) > 4) {
             $photoTable->caption = JString::substr($photoTable->caption, 0, JString::strlen($photoTable->caption) - 4);
         }
         // @todo: configurable options?
         // Permission should follow album permission
         $photoTable->published = '1';
         $photoTable->permissions = $album->permissions;
//.........这里部分代码省略.........
开发者ID:bizanto,项目名称:Hooked,代码行数:101,代码来源:photos.php

示例4: upload

 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = JRequest::getVar('token', '', 'REQUEST');
         $userId = JRequest::getVar('uploaderid', '', 'REQUEST');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session =& JFactory::getSession();
         $session->set('user', $my);
     }
     CFactory::load('libraries', 'limits');
     if (CLimitsLibrary::exceedDaily('photos', $my->id)) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_PHOTOS_LIMIT_PERDAY_REACHED'));
         return;
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     CFactory::load('libraries', 'photos');
     CFactory::load('models', 'photos');
     CFactory::load('helpers', 'image');
     $photos = JRequest::get('Files');
     $albumId = JRequest::getVar('albumid', '', 'REQUEST');
     $album =& JTable::getInstance('Album', 'CTable');
     $album->load($albumId);
     $handler = $this->_getHandler($album);
     foreach ($photos as $imageFile) {
         $result = $this->_checkUploadedFile($imageFile, $album, $handler);
         if (!$result['photoTable']) {
             continue;
         }
         //assign the result of the array and assigned to the right variable
         $photoTable = $result['photoTable'];
         $storage = $result['storage'];
         $albumPath = $result['albumPath'];
         $hashFilename = $result['hashFilename'];
         $thumbPath = $result['thumbPath'];
         $originalPath = $result['originalPath'];
         $imgType = $result['imgType'];
         $isDefaultPhoto = $result['isDefaultPhoto'];
         // Remove the filename extension from the caption
         if (JString::strlen($photoTable->caption) > 4) {
             $photoTable->caption = JString::substr($photoTable->caption, 0, JString::strlen($photoTable->caption) - 4);
         }
         // @todo: configurable options?
         // Permission should follow album permission
         $photoTable->published = '1';
         $photoTable->permissions = $album->permissions;
         // Set the relative path.
         // @todo: configurable path?
         $storedPath = $handler->getStoredPath($storage, $albumId);
         $storedPath = $storedPath . DS . $albumPath . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         $photoTable->image = CString::str_ireplace(JPATH_ROOT . DS, '', $storedPath);
         $photoTable->thumbnail = CString::str_ireplace(JPATH_ROOT . DS, '', $thumbPath);
         //In joomla 1.6, CString::str_ireplace is not replacing the path properly. Need to do a check here
         if ($photoTable->image == $storedPath) {
             $photoTable->image = str_ireplace(JPATH_ROOT . DS, '', $storedPath);
         }
         if ($photoTable->thumbnail == $thumbPath) {
             $photoTable->thumbnail = str_ireplace(JPATH_ROOT . DS, '', $thumbPath);
         }
         //photo filesize, use sprintf to prevent return of unexpected results for large file.
         $photoTable->filesize = sprintf("%u", filesize($originalPath));
         // @rule: Set the proper ordering for the next photo upload.
         $photoTable->setOrdering();
         // Store the object
         $photoTable->store();
         // We need to see if we need to rotate this image, from EXIF orientation data
         // Only for jpeg image.
         if ($config->get('photos_auto_rotate') && $imgType == 'image/jpeg') {
             $this->_rotatePhoto($imageFile, $photoTable, $storedPath, $thumbPath);
         }
         // Trigger for onPhotoCreate
         CFactory::load('libraries', 'apps');
         $apps =& CAppPlugins::getInstance();
         $apps->loadApplications();
         $params = array();
         $params[] =& $photoTable;
         $apps->triggerEvent('onPhotoCreate', $params);
         // Set image as default if necessary
         // Load photo album table
         if ($isDefaultPhoto) {
             // Set the photo id
             $album->photoid = $photoTable->id;
             $album->store();
         }
         // @rule: Set first photo as default album cover if enabled
         if (!$isDefaultPhoto && $config->get('autoalbumcover')) {
             $photosModel = CFactory::getModel('Photos');
             $totalPhotos = $photosModel->getTotalPhotos($album->id);
             if ($totalPhotos <= 1) {
                 $album->photoid = $photoTable->id;
                 $album->store();
             }
         }
         // Generate activity stream
//.........这里部分代码省略.........
开发者ID:Simarpreet05,项目名称:joomla,代码行数:101,代码来源:photos.php


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