⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storage.php.svn-base

📁 j2me is based on j2mepolish, client & server for mobile application. server part
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
<?php/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * * The Initial Developer of the Original Code is * The Mozilla Foundation. * Portions created by the Initial Developer are Copyright (C) 2006 * the Initial Developer. All Rights Reserved. * * Contributor(s): *   Wil Clouser <clouserw@mozilla.com> * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */vendor('magpierss/rss_fetch.inc');vendor('microsummary');vendor('joeywidget');/** * Some mildly associated functions for storing files on the disk.  Maybe there is a * better place for this? */class StorageComponent extends Object{    var $suffix = array ("text/plain" => "txt",                         "image/png" => "png",                         "image/jpeg" => "jpg",                         "image/gif" => "gif",                         "image/tiff" => "tif",                         "image/bmp" => "bmp",                         "video/3gpp" => "3gp",                         "video/flv" => "flv",                         "video/mpeg" => "mpg",                         "video/avi" => "avi",                         "video/quicktime" => "mov",                         "audio/x-wav" => "wav",                         "audio/mpeg" => "mp3",                         "audio/mid" => "mid",                         "rss-source/text" => "rss",                         "microsummary/xml" => "mcs",                         "widget/joey" => "jwt");    /**     * Save a reference to the controller on startup     * @param object &$controller the controller using this component     */    function startup(&$controller) {        $this->controller =& $controller;    }    /**     * Check to see if the user has available space for the     * additional content.     * @param int user id     * @param int size (in bytes) of requested space     */    function hasAvailableSpace($userid, $additional) {            $totalused = $this->controller->User->totalSpaceUsedByUserId($userid);      // $additional and $totalused is in bytes, MAX_DISK_USAGE is in MB      if ( ($additional + $totalused) > (MAX_DISK_USAGE * 1024 * 1024)) {        return false;      }            return true;    }    /**     * @return mixed true on success, false on failure     */    function createFileForUploadId($id, $type) {        if (!is_numeric($id)) { return false; }        if (empty($type))     { return false; }        $rand = uniqid();        $_filename    = "joey-{$rand}.{$this->suffix[$type]}";        $_previewname = "joey-{$rand}.png";                $_file = new File();        $_file->set('upload_id', $id);        $_file->set('name', basename($_filename));        $_file->set('size', 0);        $_file->set('type', "text/html"); //@todo dougt: why is this text/html?        //$_file->set('preview_name', basename($_previewname));        //$_file->set('preview_type', "image/png");        //$_file->set('preview_size', 0);        if (!$_file->save()) {          return false;        }              if ( !touch(UPLOAD_DIR."/{$this->controller->_user['id']}/{$_filename}")) {          return false;      }        return $_file->getLastInsertId();    }    /**     * Given a file id, this will update the file from it's associated content     * source.  (Obviously, this only works if there is a contentsource for the     * upload).     *     * @param int ID of the Upload that is associated with the file to update     * @return mixed true on success, false on failure     */    function updateFileByUploadId($id, $forceUpdate)    {      $_upload = $this->controller->Upload->FindDataById($id);      // This Upload doesn't have a contentsource      if (empty($_upload['Contentsourcetype']['name'])) {          return false;      }      if (empty($_upload['File']))      {          if ($this->createFileForUploadId($id, $_upload['Contentsourcetype']['name']) == false) {              return false;          }                    // this not should not fail since we just saved it.  Since this is the same          // query that we did at the beginning, the built in cake-cache will give us          // the same results unless we temporarily disable the cache.          $this->controller->Upload->cacheQueries = false;          $_upload = $this->controller->Upload->FindDataById($id);          $this->controller->Upload->cacheQueries = true;      }      $_owner = $this->controller->Upload->findOwnerDataFromUploadId($id);      // There is a small chance this could be an empty array      if (empty($_owner)) { return false; }            // check to see if we should do anything      if (false && $forceUpdate == false)       {        $expiry = strtotime($_upload['File']['modified'] . " + " . CONTENTSOURCE_REFRESH_TIME . " minutes");        $nowstamp = strtotime("now");        if (($expiry == false) || $expiry > $nowstamp)          return true; //  don't process anything just yet.      }      // These are the file to operate on:      $_filename = UPLOAD_DIR."/{$_owner['User']['id']}/{$_upload['File']['name']}";      $_previewname = UPLOAD_DIR."/{$_owner['User']['id']}/previews/{$_upload['File']['preview_name']}";      if (!empty($_upload['Contentsource']['source'])) {          // Depending on the type, update the file          switch ($_upload['Contentsourcetype']['name']) {              case 'rss-source/text':                // Go get the rss feed.                $rss = fetch_rss( chop($_upload['Contentsource']['source']) );                if (empty($rss)) {                    return false;                }                                $rss_result = "RSS: " . $rss->channel['title'] . "\n\n";                foreach ($rss->items as $item) {                  // fix up a bit                  //echo print_r($item);                  $rss_result = $rss_result . "-----\n\n" . $item['title'] . "\n\n";                                    if (isset($item['description']))                  {                    $rss_result .= $item['description'] . "\n\n";                  }                }                // does the user have enough space to proceed                if ($this->controller->Storage->hasAvailableSpace($_owner['User']['id'],                                                                  strlen($rss_result) - filesize($_filename)) == false)                 {                  $this->log("User " . $_owner['User']['id'] . " is out of space.");                  return false;                }                // write the file.                if (!file_put_contents($_filename, $rss_result)) {                  $this->log("file_put_contents failed for " . $_filename);                  return false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -