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


PHP FileUtil::getExtension方法代码示例

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


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

示例1: create_sub

    /**
     * Check the information received from the form of creation of a submenu item and call the api function to create it
     * @author:     Albert Pérez Monfort (aperezm@xtec.cat)
     * @param:	Array with the form information needed in case the form is reloaded
     * @return:	Redirect to the main admin page
     */
    public function create_sub($args) {
        // Get parameters from whatever input we need
        $text = FormUtil::getPassedValue('text', isset($args['text']) ? $args['text'] : null, 'POST');
        $url = FormUtil::getPassedValue('url', isset($args['url']) ? $args['url'] : null, 'POST');
        $descriu = FormUtil::getPassedValue('descriu', isset($args['descriu']) ? $args['descriu'] : null, 'POST');
        $icon = FormUtil::getPassedValue('icon', isset($args['icon']) ? $args['icon'] : null, 'FILES');
        $target = FormUtil::getPassedValue('target', isset($args['target']) ? $args['target'] : null, 'POST');
        $grup = FormUtil::getPassedValue('grup', isset($args['grup']) ? $args['grup'] : null, 'POST');
        $active = FormUtil::getPassedValue('active', isset($args['active']) ? $args['active'] : null, 'POST');
        $mid = FormUtil::getPassedValue('mid', isset($args['mid']) ? $args['mid'] : null, 'POST');
        $level = FormUtil::getPassedValue('level', isset($args['level']) ? $args['level'] : null, 'POST');

        // Security check
        if (!SecurityUtil::checkPermission('IWmenu::', '::', ACCESS_ADMIN)) {
            throw new Zikula_Exception_Forbidden();
        }

        // Confirm authorisation code
        $this->checkCsrfToken();

        // Construct the group string
        $groups = '$' . $grup . '$';

        $textSerialized = serialize($text);
        $urlSerialized = serialize($url);

        // Create a submenu item
        $lid = ModUtil::apiFunc('IWmenu', 'admin', 'create_sub', array('mid' => $mid,
                    'text' => $textSerialized,
                    'descriu' => $descriu,
                    'active' => $active,
                    'target' => $target,
                    'url' => $urlSerialized,
                    'groups' => $groups,
                    'id_parent' => $mid,
                    'level' => $level,
                    'icon' => $icon));
        if ($lid != false) {
            if ($icon['name'] != '') {
                $iconsFolderPath = ModUtil::getVar('IWmain', 'documentRoot') . '/' . ModUtil::getVar('IWmenu', 'imagedir');
                // get file extension
                $fileName = $icon['name'];
                $fileExtension = FileUtil::getExtension(strtolower($fileName));
                $fileNewName = $lid . '.' . $fileExtension;
                if ($fileExtension == 'gif' || $fileExtension == 'png' || $fileExtension == 'jpg') {
                    $destination = $iconsFolderPath . '/' . $fileNewName;
                    if (!move_uploaded_file($icon['tmp_name'], $destination)) {
                        LogUtil::registerError($this->__("The item has been created without the icon because the upload of the file has failed."));
                        return System::redirect(ModUtil::url('IWmenu', 'admin', 'main'));
                    }
                    $width = 16;
                    $height = 16;
                    // thumbnail image to $width (max.) x $height (max.)
                    $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
                    $msg = ModUtil::func('IWmain', 'user', 'thumbnail', array('sv' => $sv,
                                'imgSource' => $destination,
                                'imgDest' => $destination,
                                'widthImg' => $width,
                                'heightImg' => $height));
                    if ($msg != '') {
                        LogUtil::registerError($msg);
                        return System::redirect(ModUtil::url('IWmenu', 'admin', 'main'));
                    }
                } else {
                    LogUtil::registerError($this->__("The item has been created without the icon because the file extension for the icon is not valid."));
                    return System::redirect(ModUtil::url('IWmenu', 'admin', 'main'));
                }
                // change the image name acording with the new name
                ModUtil::apiFunc('IWmenu', 'admin', 'updateIcon', array('mid' => $lid,
                    'icon' => $fileNewName));
            }
            // Successfull creation
            LogUtil::registerStatus($this->__('A new option has been created'));

            // Reorder the menu items
            ModUtil::func('IWmenu', 'admin', 'reorder', array('id_parent' => $mid));

            // Reset the users menus for all users
            $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
            ModUtil::func('IWmain', 'user', 'usersVarsDelModule', array('module' => 'IWmenu',
                'name' => 'userMenu',
                'sv' => $sv));
        }

        // Redirect to admin main page
        return System::redirect(ModUtil::url('IWmenu', 'admin', 'main'));
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:93,代码来源:Admin.php

示例2: _get_auto_filename

 /**
  * Get a concrete filename for automagically created content.
  *
  * @param string $path        The base path.
  * @param string $auto_source The file name (optional).
  * @param string $auto_id     The ID (optional).
  *
  * @return string The concrete path and file name to the content.
  */
 public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null)
 {
     // enables a flags to detect when is treating compiled templates
     $tocompile = $path == $this->compile_dir ? true : false;
     // format auto_source for os to make sure that id does not contain 'ugly' characters
     $auto_source = DataUtil::formatForOS($auto_source);
     // build a hierarchical directory path
     $path .= '/' . $this->modinfo['directory'];
     if ($this instanceof Zikula_View_Plugin) {
         $path .= '_' . $this->getPluginName();
     }
     // add the cache_id path if set
     $path .= !empty($auto_id) ? '/' . $auto_id : '';
     // takes in account the source subdirectory
     if ($auto_source) {
         if (strpos($auto_source, 'file:') === 0) {
             // This is an absolute path needing special handling.
             $auto_source = substr($auto_source, 5);
             $cwd = DataUtil::formatForOS(getcwd());
             if (strpos($auto_source, $cwd) !== 0) {
                 throw new \RuntimeException('The template path cannot be outside the Zikula root.');
             }
             $path .= '/absolutepath' . substr(dirname($auto_source), strlen($cwd));
         } else {
             $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : '';
         }
     }
     // make sure the path exists to write the compiled/cached template there
     if (!file_exists($path)) {
         mkdir($path, $this->serviceManager['system.chmod_dir'], true);
     }
     // if there's a explicit source, it
     if ($auto_source) {
         $path .= '/';
         $extension = FileUtil::getExtension($auto_source);
         // isolates the filename on the source path passed
         $path .= FileUtil::getFilebase($auto_source);
         // add theme and language to our path
         if (empty($themedir)) {
             $themedir = $this->themeinfo['directory'];
         }
         $path .= '--t_' . $themedir . '-l_' . $this->language;
         // if we are not compiling, end with a suffix
         if (!$tocompile) {
             $path .= $extension ? ".{$extension}" : '';
         }
     }
     return $path;
 }
开发者ID:Silwereth,项目名称:core,代码行数:58,代码来源:View.php

示例3: _get_auto_filename

 /**
  * Get a concrete filename for automagically created content.
  *
  * Generates a filename path like: Theme / auto_id [/ source_dir / filename-l{lang}.ext]
  * the final part gets generated only if $auto_source is specified.
  *
  * @param string $path        The base path.
  * @param string $auto_source The file name (optional).
  * @param string $auto_id     The ID (optional).
  *
  * @return string The concrete path and file name to the content.
  */
 public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null)
 {
     // enables a flags to detect when is treating compiled templates
     $tocompile = $path == $this->compile_dir ? true : false;
     // format auto_source for os to make sure that id does not contain 'ugly' characters
     $auto_source = DataUtil::formatForOS($auto_source);
     // add the Theme name as first folder
     if (empty($themedir)) {
         $path .= '/' . $this->directory;
     } else {
         $path .= '/' . $themedir;
     }
     // the last folder is the cache_id if set
     $path .= !empty($auto_id) ? '/' . $auto_id : '';
     // takes in account the source subdirectory
     $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : '';
     // make sure the path exists to write the compiled/cached template there
     if (!file_exists($path)) {
         mkdir($path, $this->serviceManager['system.chmod_dir'], true);
     }
     // if there's a explicit source, it
     if ($auto_source) {
         $path .= '/';
         $extension = FileUtil::getExtension($auto_source);
         // isolates the filename on the source path passed
         $path .= FileUtil::getFilebase($auto_source);
         // if we are compiling we do not include cache variables
         if (!$tocompile) {
             // add the variable stuff only if $auto_source is present
             // to allow a easy flush cache for all the languages (if needed)
             $path .= '-l';
             if (System::getVar('multilingual') == 1) {
                 $path .= $this->language;
             }
             // end with a suffix convention of filename--Themename-lang.ext
             $path .= $extension ? ".{$extension}" : '';
         }
     }
     return $path;
 }
开发者ID:rmaiwald,项目名称:core,代码行数:52,代码来源:Theme.php

示例4: deleteUploadFile

 /**
  * Deletes an existing upload file.
  * For images the thumbnails are removed, too.
  *
  * @param string  $objectType Currently treated entity type.
  * @param string  $objectData Object data array.
  * @param string  $fieldName  Name of upload field.
  * @param integer $objectId   Primary identifier of the given object.
  *
  * @return mixed Array with updated object data on success, else false.
  */
 public function deleteUploadFile($objectType, $objectData, $fieldName, $objectId)
 {
     if (!in_array($objectType, $this->allowedObjectTypes)) {
         return false;
     }
     if (empty($objectData[$fieldName])) {
         return $objectData;
     }
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     // determine file system information
     try {
         $basePath = $controllerHelper->getFileBaseFolder($objectType, $fieldName);
     } catch (\Exception $e) {
         LogUtil::registerError($e->getMessage());
     }
     $fileName = $objectData[$fieldName];
     // path to original file
     $filePath = $basePath . $fileName;
     // check whether we have to consider thumbnails, too
     $fileExtension = FileUtil::getExtension($fileName, false);
     if (in_array($fileExtension, $this->imageFileTypes) && $fileExtension != 'swf') {
         // remove thumbnail images as well
         $manager = ServiceUtil::getManager()->getService('systemplugin.imagine.manager');
         $manager->setModule('MUVideo');
         $fullObjectId = $objectType . '-' . $objectId;
         $manager->removeImageThumbs($filePath, $fullObjectId);
     }
     // remove original file
     if (!unlink($filePath)) {
         return false;
     }
     $objectData[$fieldName] = '';
     $objectData[$fieldName . 'Meta'] = array();
     return $objectData;
 }
开发者ID:robbrandt,项目名称:MUVideo,代码行数:47,代码来源:UploadHandler.php

示例5: uploadImport

    /**
     * Import several users from a CSV file. Checks needed values and format.
     *
     * Parameters passed via GET:
     * --------------------------
     * None.
     *
     * Parameters passed via POST:
     * ---------------------------
     * None.
     *
     * Parameters passed via SESSION:
     * ------------------------------
     * None.
     *
     * @param array $importFile Information about the file to import. Used as the default
     *                            if $_FILES['importFile'] is not set. Allows this function to be called internally,
     *                            rather than as a result of a form post.
     * @param integer $delimiter A code indicating the delimiter used in the file. Used as the
     *                            default if $_POST['delimiter'] is not set. Allows this function to be called internally,
     *                            rather than as a result of a form post.
     *
     * @return a empty message if success or an error message otherwise
     */
    protected function uploadImport(array $importFile, $delimiter)
    {
        // get needed values
        $is_admin = (SecurityUtil::checkPermission('Users::', '::', ACCESS_ADMIN)) ? true : false;
        $minpass = $this->getVar('minpass');
        $defaultGroup = ModUtil::getVar('Groups', 'defaultgroup'); // Create output object;
        // calcs $pregcondition needed to verify illegal usernames
        $reg_illegalusername = $this->getVar('reg_Illegalusername');
        $pregcondition = '';
        if (!empty($reg_illegalusername)) {
            $usernames = explode(" ", $reg_illegalusername);
            $count = count($usernames);
            $pregcondition = "/((";
            for ($i = 0; $i < $count; $i++) {
                if ($i != $count-1) {
                    $pregcondition .= $usernames[$i] . ")|(";
                } else {
                    $pregcondition .= $usernames[$i] . "))/iAD";
                }
            }
        }

        // get available groups
        $allGroups = ModUtil::apiFunc('Groups', 'user', 'getall');

        // create an array with the groups identities where the user can add other users
        $allGroupsArray = array();
        foreach ($allGroups as $group) {
            if (SecurityUtil::checkPermission('Groups::', $group['gid'] . '::', ACCESS_EDIT)) {
                $allGroupsArray[] = $group['gid'];
            }
        }

        // check if the user's email must be unique
        $reg_uniemail = $this->getVar('reg_uniemail');

        // get the CSV delimiter
        switch ($delimiter) {
            case 1:
                $delimiterChar = ",";
                break;
            case 2:
                $delimiterChar = ";";
                break;
            case 3:
                $delimiterChar = ":";
                break;
        }

        // check that the user have selected a file
        $fileName = $importFile['name'];
        if ($fileName == '') {
            return $this->__("Error! You have not chosen any file.");
        }

        // check if user have selected a correct file
        if (FileUtil::getExtension($fileName) != 'csv') {
            return $this->__("Error! The file extension is incorrect. The only allowed extension is csv.");
        }

        // read the choosen file
        if (!$lines = file($importFile['tmp_name'])) {
            return $this->__("Error! It has not been possible to read the import file.");
        }
        $expectedFields = array('uname', 'pass', 'email', 'activated', 'sendmail', 'groups');
        $counter = 0;
        $importValues = array();
        // read the lines and create an array with the values. Check if the values passed are correct and set the default values if it is necessary
        foreach ($lines as $line_num => $line) {
            $line = str_replace('"', '', trim($line));
            if ($counter == 0) {
                // check the fields defined in the first row
                $firstLineArray = explode($delimiterChar, $line);
                foreach ($firstLineArray as $field) {
                    if (!in_array(trim(strtolower($field)), $expectedFields)) {
                        return $this->__f("Error! The import file does not have the expected field %s in the first row. Please check your import file.", array($field));
//.........这里部分代码省略.........
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:Admin.php

示例6: getFiles


//.........这里部分代码省略.........
            $errorMsg = $this->__('Invalid folder') . ': ' . $folder;
            $this->view->assign('errorMsg', $errorMsg);
            $this->view->assign('external', 1);
            $this->view->display('Files_user_errorMsg.tpl');
            exit;
        }
        // get folder name
        $folderName = str_replace($initFolderPath . '/' , '', $folder);
        $folder = $initFolderPath . '/' .  $folder;
        // users can not browser the thumbnails folders
        if(strpos($folder, '.tbn') !== false) {
            LogUtil::registerError($this->__('It is not possible to browse this folder'));
            return System::redirect(ModUtil::url('Files', 'external', 'getFiles',
                                                  array('folder' => substr($folderName, 0, strrpos($folderName, '/')))));
        }
        // needed arguments
        // check if the folder exists
        if(!file_exists($folder)){
            $errorMsg = $this->__('Invalid folder').': '.$folderName;
            $this->view->assign('errorMsg',  $errorMsg);
            $this->view->assign('external', 1);
            $this->view->display('Files_user_errorMsg.tpl');
            exit;
        }
        // get user's disk use
        $userDiskUse = ModUtil::apiFunc('Files', 'user', 'get');
        $usedSpace = $userDiskUse['diskUse'];
        // get user's allowed space
        $userAllowedSpace = ModUtil::func('Files', 'user', 'getUserQuota');
        $maxDiskSpace = round($userAllowedSpace * 1024 * 1024);
        $percentage = round($usedSpace * 100 / $maxDiskSpace);
        $widthUsage = ($percentage > 100) ? 100 : $percentage;
        $usedSpaceArray = array('maxDiskSpace' => ModUtil::func('Files', 'user', 'diskUseFormat',
                                                                 array('value' => $maxDiskSpace)),
                                                                       'percentage' => $percentage,
                                'usedDiskSpace' => ModUtil::func('Files', 'user', 'diskUseFormat',
                                                                  array('value' => $usedSpace)),
                                                                        'widthUsage' => $widthUsage);
        // create output object
        $this->view = Zikula_View::getInstance('Files', false);
        // get folder files and subfolders
        $fileList = ModUtil::func('Files', 'user', 'dir_list',
                                   array('folder' => $folder,
                                         'external' => 1,
                                         'hook' => $hook,
                                         'editor' => $editor));
        sort($fileList['dir']);
        sort($fileList['file']);
        $notwriteable = (!is_writable($folder)) ? true : false;
        // check if it is a public directori
        $is_public = (!file_exists($folder.'/.locked')) ? true : false ;
        $this->view->assign('publicFolder',  $is_public);
        $this->view->assign('folderPrev', substr($folderName, 0 ,  strrpos($folderName, '/')));
        $folderPath = (SecurityUtil::checkPermission( 'Files::', '::', ACCESS_ADMIN)) ? $folderName : ModUtil::getVar('Files', 'usersFolder') . '/' . strtolower(substr(UserUtil::getVar('uname'), 0 , 1)) . '/' . UserUtil::getVar('uname') . '/' .$folderName;
        $imagesArray = array();
        // get folder files and subfolders
        if(file_exists($folder . '/.tbn')) {
            $images = ModUtil::func('Files', 'user', 'dir_list',
                                array('folder' => $folder . '/.tbn',
                                      'external' => 1));
            foreach($images['file'] as $file) {
                $fileExtension = FileUtil::getExtension($file['name']);
                if(in_array(strtolower($fileExtension), array('gif','png','jpg','jpeg'))) {
                    list($width, $height) = getimagesize($folder . '/' . $file['name']);
                    list($newWidth, $newHeight) = getimagesize($folder . '/.tbn/' . $file['name']);
                    $factor = round($width/$newWidth,2);
                    $imagesArray[] = array('name' => $file['name'],
                                        'viewWidth' => $newWidth,
                                        'width' => $width,
                                        'viewHeight' => $newHeight,
                                        'height' => $height,
                                        'factor' => $factor);
                }
            }
        }
		$scribite_v4 = ModUtil::getVar('Files', 'scribite_v4');
        $this->view->assign('scribite_v4', $scribite_v4);
		$scribite_v5 = ModUtil::getVar('Files', 'scribite_v5');
        $this->view->assign('scribite_v5', $scribite_v5);
		$scribite_v4_name = ModUtil::getVar('Files', 'scribite_v4_name');
        $this->view->assign('scribite_v4_name', $scribite_v4_name);
		$scribite_v5_name = ModUtil::getVar('Files', 'scribite_v5_name');
        $this->view->assign('scribite_v5_name', $scribite_v5_name);
        $defaultPublic = ModUtil::getVar('Files', 'defaultPublic');
        $this->view->assign('defaultPublic', $defaultPublic);
		$this->view->assign('editor', $editor);
        $this->view->assign('folderPath', DataUtil::formatForDisplay($folderPath));
        $this->view->assign('folderName', DataUtil::formatForDisplay($folderName));
        $this->view->assign('fileList', $fileList);
        $this->view->assign('hook', $hook);
        $this->view->assign('imagesArray', DataUtil::formatForDisplay($imagesArray));
        $this->view->assign('usedSpace',  $usedSpaceArray);
        $this->view->assign('notwriteable', $notwriteable);
        //path to zk jquery lib
        $js =new JCSSUtil;
        $scripts = $js->scriptsMap();
        $jquery = $scripts['jquery']['path'];
        $this->view->assign('jquery',$jquery);
        return $this->view->display('Files_external_getFiles.tpl');
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:External.php

示例7: viewDocumentVersions

    public function viewDocumentVersions($args) {
        $documentId = FormUtil::getPassedValue('documentId', isset($args['documentId']) ? $args['documentId'] : 0, 'GET');

        // get document
        $documentOrigin = ModUtil::apiFunc($this->name, 'user', 'getDocument', array('documentId' => $documentId));
        if (!$documentOrigin) {
            LogUtil::registerError($this->__('Document not found.'));
            return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs'));
        }

        $documentOrigin['extension'] = FileUtil::getExtension($documentOrigin['fileName']);
        $documentOrigin['filesize'] = ModUtil::func($this->name, 'user', 'getReadableFileSize', array('filesize' => $documentOrigin['filesize']));

        $categoryId = $documentOrigin['categoryId'];

        // check if user can access to this category
        $canAccess = ModUtil::func($this->name, 'user', 'canAccessCategory', array('categoryId' => $categoryId,
                    'accessType' => 'read',
                ));

        if (!$canAccess) {
            LogUtil::registerError($this->__('You can not access to this document.'));
            return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs'));
        }

        // versions
        $documents = ModUtil::apiFunc($this->name, 'user', 'getDocumentVersions', array('documentId' => $documentId));

        if (!$documents) {
            LogUtil::registerError($this->__('This document have not versions.'));
            return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs', array('categoryId' => $categoryId)));
        }

        $usersList = $documentOrigin['cr_uid'] . '$$';
        $users = array();
        $canEdit = false;
        $canDelete = false;
        $canAdd = false;

        $canEditCategory = (SecurityUtil::checkPermission('IWdocmanager::', "$categoryId::", ACCESS_EDIT)) ? true : false;
        $canDeleteCategory = (SecurityUtil::checkPermission('IWdocmanager::', "$categoryId::", ACCESS_DELETE)) ? true : false;

        foreach ($documents as $document) {
            $extensionIcon['icon'] = '';
            if ($document['fileName'] != '') {
                $extension = FileUtil::getExtension($document['fileName']);
                $extensionIcon = ($extension != '') ? ModUtil::func('IWmain', 'user', 'getMimetype', array('extension' => $extension)) : '';
            }
            $documents[$document['documentId']]['extension'] = $extensionIcon['icon'];
            if ($document['authorName'] == '') {
                $usersList .= $document['cr_uid'] . '$$';
            }
            $documents[$document['documentId']]['canEdit'] = false;
            $documents[$document['documentId']]['canDelete'] = false;
            if ($canEditCategory || ($document['validated'] == 0 && UserUtil::getVar('uid') == $document['cr_uid'] && DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('editTime') * 30 > time())) {
                $documents[$document['documentId']]['canEdit'] = true;
                $canEdit = true; // in order to show edit icon in legend
            }

            if ($canDeleteCategory || ($document['validated'] == 0 && UserUtil::getVar('uid') == $document['cr_uid'] && DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('deleteTime') * 30 > time())) {
                $documents[$document['documentId']]['canDelete'] = true;
                $canDelete = true; // in order to show delete icon in legend
            }

            $documents[$document['documentId']]['filesize'] = ModUtil::func($this->name, 'user', 'getReadableFileSize', array('filesize' => $document['filesize']));
        }

        if ($usersList != '') {
            // get all users information
            $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
            $users = ModUtil::func('IWmain', 'user', 'getAllUsersInfo', array('sv' => $sv,
                        'info' => 'ncc',
                        'list' => $usersList));
        }

        return $this->view->assign('documentOrigin', $documentOrigin)
                        ->assign('documents', $documents)
                        ->assign('canAdd', $canAdd)
                        ->assign('users', $users)
                        ->assign('canEdit', $canEdit)
                        ->assign('canDelete', $canDelete)
                        ->assign('versionsVision', 1)
                        ->fetch('IWdocmanager_user_viewDocumentVersions.tpl');
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:84,代码来源:User.php

示例8: importGtafEntities

        /**
     * Importa les taules de entitats-gtaf i grups d'entitats a partir d'un csv a la base de dades de Sirius
     * 
     * Esborra el contingut previ de les taules i importa el contingut del fitxer
     * 
     * @return void Retorna a la funció *gtafEntitiesGest* amb els missatges d'execució
     */
    public function importGtafEntities() {
        if (!SecurityUtil::checkPermission('Cataleg::', '::', ACCESS_ADMIN)) {
            return LogUtil::registerPermissionError();
        }
        // get input values. Check for direct function call first because calling function might be either get or post
        if (isset($args) && is_array($args) && !empty($args)) {
            $confirmed = isset($args['confirmed']) ? $args['confirmed'] : false;
            $case = isset($args['case']) ? $args['case'] : false;
        } elseif (isset($args) && !is_array($args)) {
            throw new Zikula_Exception_Fatal(LogUtil::getErrorMsgArgs());
        } elseif ($this->request->isGet()) {
            $confirmed = 1;
        } elseif ($this->request->isPost()) {
            $this->checkCsrfToken();
            $confirmed = $this->request->request->get('confirmed', false);
            $case = $this->request->request->get('case',false);
        }
        if ($confirmed == 2) {
            if ($case == 'entities') {
                $caps = array(
                    'gtafEntityId'   => 'gtafEntityId',
                    'nom'            => 'nom',
                    'tipus'          => 'tipus',
                    'gtafGroupId'    => 'gtafGroupId'
                );
                $caps_man = $caps;
                $taula = 'cataleg_gtafEntities';
                $mes = "Importació d'entitats-gtaf";
                $field_id = 'gtafEntityId';
            } else {
                $caps = array(
                    'gtafGroupId'   => 'gtafGroupId',
                    'nom'           => 'nom',
                    'resp_uid'      => 'resp_uid'
                );
                $caps_man = array(
                    'gtafGroupId'   => 'gtafGroupId',
                    'nom'           => 'nom'
                );
                $taula = 'cataleg_gtafGroups';
                $mes = "Importació de grups d'entitats-gtaf";
                $field_id = 'gtafGroupId';
            }
            // get other import values
            $importFile = $this->request->files->get('importFile', isset($args['importFile']) ? $args['importFile'] : null);

            $fileName = $importFile['name'];
            $importResults = '';
            if ($fileName == '') {
                $importResults = $this->__("No heu triat cap fitxer.");
            } elseif (FileUtil::getExtension($fileName) != 'csv') {
                $importResults = $this->__("L'extensió del fitxer ha de ser csv.");
            } elseif (!$file_handle = fopen($importFile['tmp_name'], 'r')) {
                $importResults = $this->__("No s'ha pogut llegir el fitxer csv.");
            } else {
                while (!feof($file_handle)) {
                    $line = fgetcsv($file_handle, 1024, ';', '"');
                    if ($line != '') {
                        $lines[] = $line;
                    }
                }
                fclose($file_handle);
                //
                foreach ($lines as $line_num => $line) {
                    if ($line_num != 0) {
                        if (count($lines[0]) != count($line)) {
                            $importResults .= $this->__("<div>Hi ha registres amb un número de camps incorrecte.</div>");
                        } else {
                                $import[] = array_combine($lines[0], $line);
                                $import_id[] = $line[0];
                        }
                    } else {
                        $difs = array_diff($line, $caps);
                        $difs2 = array_diff($caps_man,$line);
                        if (count($line) != count(array_unique($line))) {
                            $importResults .= $this->__("<div>La capçalera del csv té columnes repetides.</div>");
                        } elseif (!in_array($field_id, $line)) {
                            $importResults .= $this->__("<div>Falta el camp obligatori de la clau primària (id).</div>");
                        } elseif ($line[0] != $field_id) {
                            $importResults .= $this->__("<div>El camp obligatori de la clau primària (id) ha d'ocupar el primer lloc.</div>");
                        } elseif (!empty($difs2)) {
                            $importResults .= $this->__("<div>Falten camps obligatoris.</div>");
                        } elseif (!empty($difs)) {
                            $importResults .= $this->__("div>El csv té camps incorrectes.</div>");
                        }
                    }
                }
                if (count($import_id) != count(array_unique($import_id))) $importResults .= $this->__("<div>El fitxer té alguna id repetida.</div>"); 
            }
            
            if ($importResults == '') {
                $old_reg = DBUtil::selectObjectCount($taula);
                DBUtil::deleteWhere($taula);
//.........这里部分代码省略.........
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:Admin.php

示例9: _get_auto_filename

 /**
  * Get a concrete filename for automagically created content.
  *
  * @param string $path        The base path.
  * @param string $auto_source The file name (optional).
  * @param string $auto_id     The ID (optional).
  *
  * @return string The concrete path and file name to the content.
  */
 public function _get_auto_filename($path, $auto_source = null, $auto_id = null, $themedir = null)
 {
     // enables a flags to detect when is treating compiled templates
     $tocompile = $path == $this->compile_dir ? true : false;
     // format auto_source for os to make sure that id does not contain 'ugly' characters
     $auto_source = DataUtil::formatForOS($auto_source);
     // build a hierarchical directory path
     $path .= '/' . $this->modinfo['directory'];
     if ($this instanceof Zikula_View_Plugin) {
         $path .= '_' . $this->pluginName;
     }
     // add the cache_id path if set
     $path .= !empty($auto_id) ? '/' . $auto_id : '';
     // takes in account the source subdirectory
     $path .= strpos($auto_source, '/') !== false ? '/' . dirname($auto_source) : '';
     // make sure the path exists to write the compiled/cached template there
     if (!file_exists($path)) {
         mkdir($path, $this->container['system.chmod_dir'], true);
     }
     // if there's a explicit source, it
     if ($auto_source) {
         $path .= '/';
         $extension = FileUtil::getExtension($auto_source);
         // isolates the filename on the source path passed
         $path .= FileUtil::getFilebase($auto_source);
         // add theme and language to our path
         if (empty($themedir)) {
             $themedir = $this->themeinfo['directory'];
         }
         $path .= '--t_' . $themedir . '-l_' . $this->language;
         // if we are not compiling, end with a suffix
         if (!$tocompile) {
             $path .= $extension ? ".{$extension}" : '';
         }
     }
     return $path;
 }
开发者ID:rtznprmpftl,项目名称:Zikulacore,代码行数:46,代码来源:View.php

示例10: unzipFile

    /**
     * Unzip a zip file.
     * @author: Albert Pérez Monfort & Robert Barrera
     * @param:  args
     * @return: True if success and false if not
     */
    public function unzipFile($args) {
        $fileName = FormUtil::getPassedValue('fileName', isset($args['fileName']) ? $args['fileName'] : null, 'REQUEST');
        $folder = FormUtil::getPassedValue('folder', isset($args['folder']) ? $args['folder'] : null, 'REQUEST');
        $folder = str_replace("|", "/", $folder);
        $external = FormUtil::getPassedValue('external', isset($args['external']) ? $args['external'] : null, 'GET');
        $hook = FormUtil::getPassedValue('hook', isset($args['hook']) ? $args['hook'] : null, 'GET');
        $editor  = FormUtil::getPassedValue('editor', isset($args['editor']) ? $args['editor'] : null, 'GET');
        // security check
        if (!SecurityUtil::checkPermission('Files::', "::", ACCESS_ADD)) {
            return LogUtil::registerError($this->__('Error! You are not authorized to access this module.'), 403);
        }
        $returnType = ($external == 1) ? 'external' : 'user';
        $returnFunc = ($external == 1) ? 'getFiles' : 'main';
        $check = ModUtil::func('Files', 'user', 'checkingModule');
        if ($check['status'] != 'ok') {
	    $this->view->assign('check', $check);
            return $this->view->fetch('Files_user_failedConf.tpl');
        }
        $initFolderPath = $check['initFolderPath'];
        // protection. User can not navigate out their root folder
        if ($folder == ".." || $folder == "." || strpos($folder, "..") !== false) {
            $errorMsg = $this->__('Invalid folder') . ': ' . $folder;
            $this->view->assign('errorMsg', $errorMsg);
            return $this->view->fetch('Files_user_errorMsg.tpl');
        }
        $file = ($folder != "") ? $initFolderPath . "/" . $folder . "/" . $fileName : $initFolderPath . "/" . $fileName;
        require_once ('modules/Files/includes/pclzip.lib.php');
        $archive = new PclZip($file);
        if (($list = $archive->listContent()) == 0) {
            LogUtil::registerError($this->__('Failed to list content zip file.') . ': ' . $fileName);
            $folder = str_replace("/", "|", $folder);
            return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder,
                        'hook' => $hook)));
        }
        $filesSize = 0;
        $allowedExtensions = ModUtil::getVar('Files', 'allowedExtensions');
        $allowedExtensionsArray = explode(',', $allowedExtensions);
        foreach ($list as $file) {
            // calc the size of the file unziped
            $filesSize += $file['size'];
            // checks if user can unzip the file because the extensions into this file
            // get file extension
            $file_extension = FileUtil::getExtension($file['filename']);
            if ($file_extension != '') {
                if (!in_array(strtolower($file_extension), $allowedExtensionsArray) && !in_array(strtoupper(($file_extension)), $allowedExtensionsArray)) {
                    LogUtil::registerError($this->__f('The zip file contains at least one file with the extension <strong>%s</strong> which is not allowed. The allowed extensions are: <strong>%s</strong>.', array(
                                $file_extension,
                                str_replace(',', ', ', $allowedExtensions))));
                    $folder = str_replace("/", "|", $folder);
                    return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder,
                                'hook' => $hook)));
                }
            }
        }
        // check if user have enough space to unzip the file
        // get user used space in folder
        $userDiskUse = ModUtil::apiFunc('Files', 'user', 'get');
        $usedSpace = $userDiskUse['diskUse'];
        // get user allowed space
        $userAllowedSpace = ModUtil::func('Files', 'user', 'getUserQuota') * 1024 * 1024;
        // check if user have enough space to unzip the file
        if ($filesSize + $usedSpace > $userAllowedSpace && $userAllowedSpace != -1048576) {
            LogUtil::registerError($this->__f('You have not enough disk space to unzip the file. You need %s extra bytes.', $filesSize + $usedSpace - $userAllowedSpace));
            $folder = str_replace("/", "|", $folder);
            return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder,
                        'hook' => $hook)));
        }
        if ($archive->extract(PCLZIP_OPT_PATH, ($initFolderPath . "/" . $folder)) == 0) {
            LogUtil::registerError($this->__('Failed to unzip'));
            $folder = str_replace("/", "|", $folder);
            return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder,
                        'hook' => $hook)));
        }
        // update the number of bytes used by user
        ModUtil::apiFunc('Files', 'user', 'updateUsedSpace');
        // protect the folders with the .htaccess and .locked files
        ModUtil::func('Files', 'user', 'createProtectFiles', array('folder' => $folder));
        LogUtil::registerStatus($this->__('Successfully unzipped'));
        $folder = str_replace("/", "|", $folder);
        return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder,
                    'hook' => $hook, 'editor' => $editor)));
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:88,代码来源:User.php

示例11: validateImages

    /**
     * Count the valid uploaded pictures and mark them as resizable
     * convert status of news item to DRAFT if unsuccessful upload
     *
     * @author msshams
     * @author craigh
     * @param array $files
     * @param array $item
     * @return array ($files, $item)
     */
    public static function validateImages($files, $item)
    {
        $uploadNoFile = false;
        $count = 0;
        $modvars = ModUtil::getVar('News');

        $allowedExtensionsArray = explode(',', $modvars['picupload_allowext']);
        foreach ($files as $key => $file) {
            $files[$key]['resize'] = false; // set default to no resize
            if ($file['size'] > $modvars['picupload_maxfilesize']) {
                $file['error'] = UPLOAD_ERR_FORM_SIZE;
            }
            $dom = ZLanguage::getModuleDomain('News');
            switch ($file['error']) {
                case UPLOAD_ERR_FORM_SIZE:
                    $uploadNoFile = true;
                    LogUtil::registerStatus(__f('Warning! Picture %s is not uploaded, since the filesize was too large (max. %s kB).', array($key+1, $modvars['picupload_maxfilesize']/1000), $dom));
                    break;
                case UPLOAD_ERR_NO_FILE:
                    $uploadNoFile = true;
                    break;
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_PARTIAL:
                case UPLOAD_ERR_NO_TMP_DIR:
                case UPLOAD_ERR_CANT_WRITE:
                case UPLOAD_ERR_EXTENSION:
                    $uploadNoFile = true;
                    LogUtil::registerStatus(__f('Warning! Picture %1$s gave an error (code %2$s, explained on this page: %3$s) during uploading.', array($key+1, $error, 'http://php.net/manual/features.file-upload.errors.php'), $dom));
                    break;
                case UPLOAD_ERR_OK:
                    $file_extension = FileUtil::getExtension($file['name']);
                    if (!in_array(strtolower($file_extension), $allowedExtensionsArray) && !in_array(strtoupper(($file_extension)), $allowedExtensionsArray)) {
                        LogUtil::registerStatus(__f('Warning! Picture %s is not uploaded, since the file extension is now allowed (only %s is allowed).', array($key+1, $modvars['picupload_allowext']), $dom));
                    } else {
                        $files[$key]['resize'] = true;
                        $count++;
                    }
                    break;
            }
        }
        $item['pictures'] = $count;

        // make the article draft when there is an upload error and ADD permission is present
        // TODO why only for ADD ???
        if (($uploadNoFile) && SecurityUtil::checkPermission('News::', '::', ACCESS_ADD)) {
            $item['action'] = 6;
        }

        return array($files, $item);
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:60,代码来源:ImageUtil.php

示例12: thumbnail

 /**
  * create a thumbnail of an image
  * @author:	Albert Pérez Monfort (aperezm@xtec.cat)
  * @param: imgSource => Path of the source of the image
  * @param: imgDest => Path of the destiny of the image
  * @param: widthImg => Maximum width of the image
  * @param: heightImg => Maximum height of the image
  * @return:	True if success and false otherwise
  */
 public function thumbnail($args) {
     $sv = FormUtil::getPassedValue('sv', isset($args['sv']) ? $args['sv'] : null, 'POST');
     $imgSource = FormUtil::getPassedValue('imgSource', isset($args['imgSource']) ? $args['imgSource'] : null, 'POST');
     $imgDest = FormUtil::getPassedValue('imgDest', isset($args['imgDest']) ? $args['imgDest'] : null, 'POST');
     $widthImg = FormUtil::getPassedValue('widthImg', isset($args['widthImg']) ? $args['widthImg'] : 0, 'POST');
     $heightImg = FormUtil::getPassedValue('heightImg', isset($args['heightImg']) ? $args['heightImg'] : 0, 'POST');
     $imageName = FormUtil::getPassedValue('imageName', isset($args['imageName']) ? $args['imageName'] : null, 'POST');
     if (!ModUtil::func('IWmain', 'user', 'checkSecurityValue', array('sv' => $sv))) {
         return LogUtil::registerError($this->__('You are not allowed to access to use this functionality.'));
     }
     $errorMsg = '';
     if (($widthImg == 0 && $heightImg == 0) ||
             $imgSource == null ||
             $imgDest == null ||
             !file_exists($imgSource)) {
         return $this->__('Error! The parameters receiver are not correct.');
     }
     // seems that all the parameters required are available and the thumbnail is created
     $fileExtension = ($imageName != numm && $imageName != '') ? FileUtil::getExtension($imageName) : FileUtil::getExtension($imgSource);
     $thumbnailExtensions = array('gif',
         'jpg',
         'jpeg',
         'png');
     if (!in_array(strtolower($fileExtension), $thumbnailExtensions)) {
         return $this->__('Error! Thumbnailing the image file.');
     }
     $format = '';
     if (strtolower($fileExtension) == 'jpg' || strtolower($fileExtension) == 'jpeg') {
         $format = 'image/jpeg';
     } elseif (strtolower($fileExtension) == 'gif') {
         $format = 'image/gif';
     } elseif (strtolower($fileExtension) == 'png') {
         $format = 'image/png';
     }
     // size calculation
     // get original image size
     list($width, $height) = getimagesize($imgSource);
     // set the default vaules like the original
     $newWidth = $width;
     $newHeight = $height;
     // fix the width to the value set in the module configuration (or lower if the image is smaller) and calc the height
     if ($widthImg > 0) {
         // fix the width
         $newWidth = ($width <= $widthImg) ? $width : $widthImg;
         $newHeight = $height * $newWidth / $width;
         if (($newHeight > $heightImg) && $heightImg > 0) {
             $newHeight = $heightImg;
             $newWidth = $width * $newHeight / $height;
         }
     }
     if ($heightImg > 0 && $widthImg == 0) {
         // fix the width
         $newHeight = ($height <= $heightImg) ? $height : $heightImg;
         $newWidth = $width * $newHeight / $height;
     }
     if (!$destimg = imagecreatetruecolor($newWidth, $newHeight)) {
         return $this->__('Error! Thumbnailing the image file.');
     }
     // set alphablending to on
     imagesavealpha($destimg, true);
     imagealphablending($destimg, true);
     // create the image
     switch ($format) {
         case 'image/gif':
             if (!$srcimg = imagecreatefromgif($imgSource)) {
                 return $this->__('Error! Thumbnailing the image file.');
             }
             // preserve the transparency
             $transIndex = imagecolortransparent($srcimg);
             if ($transIndex >= 0) {
                 // get transparent colors from the received image
                 $transColor = imagecolorsforindex($srcimg, $transIndex);
                 // allocate the color to the destiny image
                 $transIndex = imagecolorallocate($destimg, $transColor['red'], $transColor['green'], $transColor['blue']);
                 // fills the background of destiny image with the allocated color.
                 imagefill($destimg, 0, 0, $transIndex);
                 // set the background color for destiny image to transparent
                 imagecolortransparent($destimg, $transIndex);
             }
             if (!imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $newWidth, $newHeight, imagesx($srcimg), imagesy($srcimg))) {
                 return $this->__('Error! Thumbnailing the image file.');
             }
             if (!imagegif($destimg, $imgDest)) {
                 return $this->__('Error! Thumbnailing the image file.');
             }
             break;
         case 'image/jpeg':
             if (!$srcimg = imagecreatefromjpeg($imgSource)) {
                 return $this->__('Error! Thumbnailing the image file.');
             }
             if (!imagecopyresampled($destimg, $srcimg, 0, 0, 0, 0, $newWidth, $newHeight, ImageSX($srcimg), ImageSY($srcimg))) {
//.........这里部分代码省略.........
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:User.php

示例13: deleteUploadFile

 /**
  * Deletes an existing upload file.
  * For images the thumbnails are removed, too.
  *
  * @param string $objectType Currently treated entity type.
  * @param string $objectData Object data array.
  * @param string $fieldName  Name of upload field.
  *
  * @return mixed Array with updated object data on success, else false.
  */
 public function deleteUploadFile($objectType, $objectData, $fieldName)
 {
     if (!in_array($objectType, $this->allowedObjectTypes)) {
         return false;
     }
     if (empty($objectData[$fieldName])) {
         return $objectData;
     }
     // determine file system information
     $basePath = MUBoard_Util_Controller::getFileBaseFolder($objectType, $fieldName);
     $fileName = $objectData[$fieldName];
     // remove original file
     if (!unlink($basePath . $fileName)) {
         return false;
     }
     $objectData[$fieldName] = '';
     $objectData[$fieldName . 'Meta'] = array();
     $fileExtension = FileUtil::getExtension($fileName, false);
     if (!in_array($fileExtension, $this->imageFileTypes)) {
         // we are done, so let's return
         return $objectData;
     }
     // get extension again, but including the dot
     $fileExtension = FileUtil::getExtension($fileName, true);
     $thumbFileNameBase = str_replace($fileExtension, '', $fileName) . '_tmb_';
     $thumbFileNameBaseLength = strlen($thumbFileNameBase);
     // remove image thumbnails
     $thumbPath = $basePath . 'tmb/';
     $thumbFiles = FileUtil::getFiles($thumbPath, false, true, null, 'f');
     // non-recursive, relative pathes
     foreach ($thumbFiles as $thumbFile) {
         $thumbFileBase = substr($thumbFile, 0, $thumbFileNameBaseLength);
         if ($thumbFileBase != $thumbFileNameBase) {
             // let other thumbnails untouched
             continue;
         }
         unlink($thumbPath . $thumbFile);
     }
     return $objectData;
 }
开发者ID:rmaiwald,项目名称:MUBoard,代码行数:50,代码来源:UploadHandler.php


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