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


PHP Image::write方法代码示例

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


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

示例1: Thumbnail

 public function Thumbnail($page = 1)
 {
     // Only thumbnail PDF files
     if (strtolower($this->owner->getExtension()) != 'pdf') {
         return false;
     }
     $file_filename = Director::baseFolder() . '/' . $this->owner->getFilename();
     if (!file_exists($file_filename)) {
         return false;
     }
     $cache_filename = $this->owner->getFilename() . '.page-' . (int) $page . '.jpg';
     // Check for existing cached thumbnail
     if (file_exists(Director::baseFolder() . '/' . $cache_filename) && filemtime(Director::baseFolder() . '/' . $cache_filename) > filemtime($file_filename)) {
         $img = DataObject::get_one('Image', "Filename = '" . $cache_filename . "'");
         if ($img) {
             return $img;
         }
     }
     // Create and cache the thumbnail
     $command = self::$convert_path . ' -density 300x300 ' . escapeshellarg($file_filename . '[' . ((int) $page - 1) . ']') . ' -quality 100 -resize 2000x -units PixelsPerInch ' . escapeshellarg(Director::baseFolder() . '/' . $cache_filename);
     $out = shell_exec($command);
     //var_dump( $command );
     if (!file_exists(Director::baseFolder() . '/' . $cache_filename)) {
         return false;
     }
     $img = new Image();
     $img->setFilename($cache_filename);
     $img->write();
     $img = DataObject::get_one('Image', "Filename = '" . $cache_filename . "'");
     return $img;
 }
开发者ID:NobrainerWeb,项目名称:silverstripe-pdf-thumbnailer,代码行数:31,代码来源:PdfThumbnailerExtension.php

示例2: createFromUpload

 public static function createFromUpload($basePath, $uploadPath)
 {
     $image = new Image($uploadPath);
     if (!$image->valid) {
         return null;
     }
     $targetName = self::getNewName($image->extension);
     $scaledTargetPath = $basePath . $targetName;
     $originalTargetPath = $scaledTargetPath;
     // Do we want to create a scaled down version of this image?
     if ($image->width > CONFIG::IMAGE_MAX_WIDTH) {
         $scaledWidth = CONFIG::IMAGE_MAX_WIDTH;
         $scaledHeight = $scaledWidth / $image->width * $image->height;
         $image->writeThumb($scaledTargetPath, CONFIG::IMAGE_JPEG_QUALITY, $scaledWidth, $scaledHeight, CONFIG::IMAGE_SHARPEN);
         setFileMode($scaledTargetPath);
         // We created a scaled down version, so the original has to be moved
         // in a separate big/ folder
         $originalTargetPath = $basePath . CONFIG::IMAGE_BIG_PATH . $targetName;
     }
     // If the image had an exif orientation, save the rotated version
     // and delete the original.
     if ($image->exifRotated) {
         $image->write($originalTargetPath, CONFIG::IMAGE_JPEG_QUALITY);
         unlink($uploadPath);
     } else {
         move_uploaded_file($uploadPath, $originalTargetPath);
     }
     setFileMode($originalTargetPath);
     return self::open($scaledTargetPath);
 }
开发者ID:Norvares,项目名称:nemex,代码行数:30,代码来源:node-image.php

示例3: getPdfPreviewImage

 public function getPdfPreviewImage()
 {
     $pdfFile = Director::getAbsFile($this->owner->getFileName());
     $pathInfo = pathinfo($pdfFile);
     if (strtolower($pathInfo['extension']) != 'pdf') {
         //@Todo if dev then exception? else fail silently
         return null;
     }
     $fileName = $pathInfo['filename'];
     $savePath = __DIR__ . '/../../';
     $saveImage = $this->imagePrefix . '-' . $fileName . '.jpg';
     // Fix illegal characters
     $filter = FileNameFilter::create();
     $saveImage = $filter->filter($saveImage);
     $saveTo = $savePath . $this->folderToSave . $saveImage;
     $image = DataObject::get_one('Image', "`Name` = '{$saveImage}'");
     if (!$image) {
         $folderObject = DataObject::get_one("Folder", "`Filename` = '{$this->folderToSave}'");
         if ($folderObject) {
             if ($this->generator->generatePreviewImage($pdfFile, $saveTo)) {
                 $image = new Image();
                 $image->ParentID = $folderObject->ID;
                 $image->setName($saveImage);
                 $image->write();
             }
         }
     } else {
         //check LastEdited to update
         $cacheInValid = false;
         if (strtotime($image->LastEdited) < strtotime($this->owner->LastEdited)) {
             $cacheInValid = true;
         }
         if ($cacheInValid) {
             $this->generator->generatePreviewImage($pdfFile, $saveTo);
             $image->setName($saveImage);
             $image->write(false, false, true);
         }
     }
     return $image;
 }
开发者ID:helpfulrobot,项目名称:ivoba-silverstripe-simple-pdf-preview,代码行数:40,代码来源:SimplePdfPreviewImageExtension.php

示例4: getFileByURL

 private function getFileByURL($url, $fileName)
 {
     $folder = Folder::find_or_make(self::$media_upload_folder);
     // relative to assets
     // create the file in database (sets title and safely names)
     $file = new Image();
     $file->ParentID = $folder->ID;
     $file->setName($fileName);
     $file->write();
     // download the file
     $fp = fopen($file->getFullPath(), 'w');
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_FILE, $fp);
     $data = curl_exec($ch);
     curl_close($ch);
     fclose($fp);
     return $file;
 }
开发者ID:helpfulrobot,项目名称:briceburg-silverstripe-sitemedia,代码行数:18,代码来源:SiteYouTubeVideo.php

示例5: save_snapshot

 /**
  * Save Snapshots of extension in assets folder
  *
  * @param string $thumbnailUrl, $extensionName
  * @return int
  */
 public static function save_snapshot($thumbnailUrl, $extensionName)
 {
     $folderToSave = 'assets/Uploads/Snapshots/';
     $folderObject = Folder::get()->filter("Filename", $folderToSave)->first();
     if (!$folderObject) {
         $folderObject = Folder::find_or_make('Uploads/Snapshots/');
         $folderObject->write();
     }
     $fileExtension = preg_replace('/^.*\\.([^.]+)$/D', '$1', $thumbnailUrl);
     $thumbnailBaseName = str_replace('/', '-', $extensionName);
     $thumbnailName = $thumbnailBaseName . '-thumbnail.' . $fileExtension;
     $ch = curl_init();
     $timeout = 30;
     curl_setopt($ch, CURLOPT_URL, $thumbnailUrl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     $data = curl_exec($ch);
     $response = curl_getinfo($ch);
     curl_close($ch);
     if ($response['http_code'] == '404') {
         throw new InvalidArgumentException("Image not found on given Url Please check 'Snapshot' field in composer.json file");
     }
     $imageContent = $data;
     if ($folderObject) {
         $thumbnailFile = fopen(BASE_PATH . DIRECTORY_SEPARATOR . $folderToSave . $thumbnailName, 'w');
         fwrite($thumbnailFile, $imageContent);
         fclose($thumbnailFile);
     } else {
         throw new InvalidArgumentException("Could not create {$folderToSave} , Please create it mannually ");
     }
     if ($thumbnailObject = Image::get()->filter("Name", $thumbnailName)->first()) {
         return $thumbnailObject->ID;
     } else {
         $thumbnailObject = new Image();
         $thumbnailObject->ParentID = $folderObject->ID;
         $thumbnailObject->Name = $thumbnailName;
         $thumbnailObject->OwnerID = Member::currentUser() ? Member::currentUser()->ID : 0;
         $thumbnailObject->write();
         return $thumbnailObject->ID;
     }
 }
开发者ID:helpfulrobot,项目名称:vikas-srivastava-extensionmanager,代码行数:47,代码来源:ExtensionSnapshot.php

示例6: run

 public function run($request)
 {
     $this->deleteAll(ArticlePage::get());
     $faker = Faker\Factory::create();
     $blogPage = BlogPage::get()->first();
     $img = new Image();
     $imgFile = 'themes/Helix/assets/images/doof.jpg';
     // var_dump($imgFile);
     $img->Filename = $imgFile;
     $img->Title = 'Template image';
     $img->write();
     for ($articles = 0; $articles < 20; $articles++) {
         $articlePage = new ArticlePage();
         $articlePage->Title = "Article " . $articles;
         $articlePage->Content = $faker->text(400);
         // $articlePage->summarySize = rand(1,3);
         $articlePage->summarySize = 1;
         $articlePage->SummaryImageID = $img->ID;
         $articlePage->setParent($blogPage);
         $articlePage->write();
         $articlePage->publish("Stage", "Live");
         $articlePage->flushCache();
     }
 }
开发者ID:4j5,项目名称:Helixnexus-Silverstripe,代码行数:24,代码来源:articleSeeder.php

示例7: addNewImage

 /**
  * Adds a new image to the given product.
  * 
  * @param SilvercartProduct $product           Product to add image to
  * @param string            $filename          Filename
  * @param string            $description       Description
  * @param int               $consecutiveNumber Consecutive number
  */
 protected function addNewImage(SilvercartProduct $product, $filename, $description, $consecutiveNumber)
 {
     $fileEnding = strrev(substr(strrev($filename), 0, strpos(strrev($filename), '.')));
     $nameFilter = FileNameFilter::create();
     $targetFilename = $product->ProductNumberShop . '-' . $nameFilter->filter($product->Title) . '-' . $consecutiveNumber . '.' . $fileEnding;
     $originalFile = self::get_absolute_upload_folder() . '/' . $filename;
     $targetFile = self::get_absolute_product_image_folder() . '/' . $targetFilename;
     $parentFolder = Folder::find_or_make('Uploads/product-images');
     rename($originalFile, $targetFile);
     $image = new Image();
     $image->Name = basename($targetFilename);
     $image->ParentID = $parentFolder->ID;
     $image->write();
     $silvercartImage = new SilvercartImage();
     $silvercartImage->ImageID = $image->ID;
     $silvercartImage->Title = $description;
     $silvercartImage->write();
     $product->SilvercartImages()->add($silvercartImage);
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:27,代码来源:SilvercartProductImageAdmin.php

示例8: importSet

 public function importSet()
 {
     $page = 1;
     static $only_new_photos = false;
     $canAccess = Director::isDev() || Director::is_cli() || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this);
     }
     /*
     // For testing
     $flickrPhoto = FlickrPhoto::get()->filter('ID',100)->first();
     $flickrPhoto->loadExif();
     die;
     */
     // Code for the register action here
     $flickrSetID = $this->request->param('ID');
     $path = $_GET['path'];
     $parentNode = SiteTree::get_by_link($path);
     if ($parentNode == null) {
         echo "ERROR: Path " . $path . " cannot be found in this site\n";
         die;
     }
     $this->FlickrSetId = $flickrSetID;
     $photos = $this->f->photosets_getPhotos($flickrSetID, 'license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, url_o, url_l,description', null, 500);
     $photoset = $photos['photoset'];
     $flickrSet = $this->getFlickrSet($flickrSetID);
     // reload from DB with date - note the use of quotes as flickr set id is a string
     $flickrSet = DataObject::get_one('FlickrSet', 'FlickrID=\'' . $flickrSetID . "'");
     $flickrSet->FirstPictureTakenAt = $photoset['photo'][0]['datetaken'];
     $flickrSet->KeepClean = true;
     $flickrSet->Title = $photoset['title'];
     $flickrSet->write();
     echo "Title set to : " . $flickrSet->Title;
     if ($flickrSet->Title == null) {
         echo "ABORTING DUE TO NULL TITLE FOUND IN SET - ARE YOU AUTHORISED TO READ SET INFO?";
         die;
     }
     $datetime = explode(' ', $flickrSet->FirstPictureTakenAt);
     $datetime = $datetime[0];
     list($year, $month, $day) = explode('-', $datetime);
     echo "Month: {$month}; Day: {$day}; Year: {$year}<br />\n";
     // now try and find a flickr set page
     $flickrSetPage = DataObject::get_one('FlickrSetPage', 'FlickrSetForPageID=' . $flickrSet->ID);
     if (!$flickrSetPage) {
         $flickrSetPage = new FlickrSetPage();
         $flickrSetPage->Title = $photoset['title'];
         $flickrSetPage->Description = $flickrSet->Description;
         //update FlickrSetPage set Description = (select Description from FlickrSet where FlickrSet.ID = FlickrSetPage.FlickrSetForPageID);
         $flickrSetPage->FlickrSetForPageID = $flickrSet->ID;
         $flickrSetPage->write();
         // create a stage version also
     }
     $flickrSetPage->Title = $photoset['title'];
     $flickrSetPage->ParentID = $parentNode->ID;
     $flickrSetPage->write();
     $flickrSetPage->publish("Live", "Stage");
     $flickrSetPageID = $flickrSetPage->ID;
     gc_enable();
     $f1 = Folder::find_or_make("flickr/{$year}");
     $f1->Title = $year;
     $f1->write();
     $f1 = Folder::find_or_make("flickr/{$year}/{$month}");
     $f1->Title = $month;
     $f1->write();
     $f1 = Folder::find_or_make("flickr/{$year}/{$month}/{$day}");
     $f1->Title = $day;
     $f1->write();
     exec("chmod 775 ../assets/flickr/{$year}");
     exec("chmod 775 ../assets/flickr/{$year}/{$month}");
     exec("chmod 775 ../assets/flickr/{$year}/{$month}/{$day}");
     exec("chown gordon:www-data ../assets/flickr/{$year}");
     exec("chown gordon:www-data ../assets/flickr/{$year}/{$month}");
     exec("chown gordon:www-data ../assets/flickr/{$year}/{$month}/{$day}");
     $folder = Folder::find_or_make("flickr/{$year}/{$month}/{$day}/" . $flickrSetID);
     $cmd = "chown gordon:www-data ../assets/flickr";
     exec($cmd);
     exec('chmod 775 ../assets/flickr');
     // new folder case
     if ($flickrSet->AssetFolderID == 0) {
         $flickrSet->AssetFolderID = $folder->ID;
         $folder->Title = $flickrSet->Title;
         $folder->write();
         $cmd = "chown gordon:www-data ../assets/flickr/{$year}/{$month}/{$day}/" . $flickrSetID;
         exec($cmd);
         $cmd = "chmod 775 ../assets/flickr/{$year}/{$month}/{$day}/" . $flickrSetID;
         exec($cmd);
     }
     $flickrSetAssetFolderID = $flickrSet->AssetFolderID;
     $flickrSetPageDatabaseID = $flickrSetPage->ID;
     //$flickrSet = NULL;
     $flickrSetPage = NULL;
     $numberOfPics = count($photoset['photo']);
     $ctr = 1;
     foreach ($photoset['photo'] as $key => $value) {
         echo "Importing photo {$ctr}/{$numberOfPics}\n";
         $flickrPhoto = $this->createFromFlickrArray($value);
         if ($value['isprimary'] == 1) {
             $flickrSet->MainImage = $flickrPhoto;
         }
         $flickrPhoto->write();
//.........这里部分代码省略.........
开发者ID:gordonbanderson,项目名称:flickr-editor,代码行数:101,代码来源:FlickrController.php

示例9: loadTranscodedFiles

 public function loadTranscodedFiles()
 {
     // get (a) source file to deduct name etc from...
     $source = false;
     if (!$source && $this->SourceID) {
         $source = $this->Source();
     }
     if (!$source && $this->MP4ID) {
         $source = $this->MP4();
     }
     if (!$source && $this->WEBMID) {
         $source = $this->WEBM();
     }
     if (!$source && $this->OGVID) {
         $source = $this->OGV();
     }
     $ext = pathinfo($source->getFilename(), PATHINFO_EXTENSION);
     $vid_name = basename($source->getFilename(), "." . $ext);
     // with extension stripped
     $vid_path = Config::inst()->get('Transcoding', 'transcode_relative_video_path_base');
     $poster_path = "{$vid_path}{$vid_name}-01.jpg";
     $mp4_path = "{$vid_path}{$vid_name}.mp4";
     $webm_path = "{$vid_path}{$vid_name}.webm";
     $ogv_path = "{$vid_path}{$vid_name}.ogv";
     if (!$this->PosterID && file_exists(BASE_PATH . "/" . $poster_path)) {
         $file = new Image();
         $file->setFilename($poster_path);
         $file->write();
         $this->PosterID = $file->ID;
     }
     if (!$this->MP4ID && file_exists(BASE_PATH . "/" . $mp4_path)) {
         $file = new File();
         $file->setFilename($mp4_path);
         $file->write();
         $this->MP4ID = $file->ID;
     }
     if (!$this->WEBMID && file_exists(BASE_PATH . "/" . $webm_path)) {
         $file = new File();
         $file->setFilename($webm_path);
         $file->write();
         $this->WEBMID = $file->ID;
     }
     if (!$this->OGVID && file_exists(BASE_PATH . "/" . $ogv_path)) {
         $file = new File();
         $file->setFilename($ogv_path);
         $file->write();
         $this->OGVID = $file->ID;
     }
     $this->write();
 }
开发者ID:helpfulrobot,项目名称:micschk-silverstripe-html5-media,代码行数:50,代码来源:Video.php

示例10: writeImage

 /**
  * @param string $format
  * @return \Sokil\Image\AbstractWriteStrategy
  */
 public function writeImage(Image $image, $format, $configuratorCallable = null)
 {
     $writeStrategyClassName = $this->getWriteStrategyClassNameByWriteFormat($format);
     $writeStrategy = new $writeStrategyClassName();
     if (!$writeStrategy instanceof \Sokil\Image\AbstractWriteStrategy) {
         throw new \Exception('Write strategy must extend AbstractWriteStrategy');
     }
     // configure
     if ($configuratorCallable) {
         if (!is_callable($configuratorCallable)) {
             throw new \Exception('Wrong configurator specified');
         }
         call_user_func($configuratorCallable, $writeStrategy);
     }
     $image->write($writeStrategy);
     return $this;
 }
开发者ID:sokil,项目名称:php-image,代码行数:21,代码来源:ImageFactory.php

示例11: requireDefaultRecords

 public function requireDefaultRecords()
 {
     // If "no product image" is not in DB, add it
     if (!Image::get()->filter('Name', 'no-image.png')->first()) {
         $image = new Image();
         $image->Name = 'no-image.png';
         $image->Title = 'No Image';
         $image->Filename = 'commerce/images/no-image.png';
         $image->ShowInSearch = 0;
         $image->write();
         DB::alteration_message('No image file added to DB', 'created');
     }
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:13,代码来源:Ext_Commerce_SiteConfig.php

示例12: createLogoImageObjects

 /**
  * Creates the upload folder for payment images if it doesn't exist.
  *
  * @param array  $paymentLogos      The payment logos as associative array:
  *                                  ['LogoName' => 'PATH_TO_FILE', ....]
  * @param string $paymentModuleName The name of the payment module
  *
  * @return void
  *
  * @author Sebastian Diel <sdiel@pixeltricks.de>,
  *         Sascha Koehler <skoehler@pixeltricks.de>
  * @since 16.06.2014
  */
 public function createLogoImageObjects($paymentLogos, $paymentModuleName)
 {
     //make sure that the folder "Uploads" exists
     Folder::find_or_make('Uploads');
     $paymentModule = SilvercartPaymentMethod::get()->filter(array("ClassName" => $paymentModuleName))->sort(array("ID" => "ASC"))->first();
     if ($paymentModule) {
         if (count($this->getPossiblePaymentChannels()) > 0) {
             // Multiple payment channels
             foreach ($paymentLogos as $paymentChannel => $logos) {
                 $paymentChannelMethod = DataObject::get_one($paymentModuleName, sprintf("\"PaymentChannel\"='%s'", $paymentChannel), true, $paymentModuleName . ".ID");
                 if ($paymentChannelMethod) {
                     if (!$paymentChannelMethod->PaymentLogos()->exists()) {
                         foreach ($logos as $title => $logo) {
                             $paymentLogo = new SilvercartImage();
                             $paymentLogo->Title = $title;
                             $storedLogo = Image::get()->filter('Name', basename($logo))->first();
                             if ($storedLogo) {
                                 $paymentLogo->ImageID = $storedLogo->ID;
                             } else {
                                 file_put_contents(Director::baseFolder() . '/' . $this->uploadsFolder->Filename . basename($logo), file_get_contents(Director::baseFolder() . $logo));
                                 $image = new Image();
                                 $image->setFilename($this->uploadsFolder->Filename . basename($logo));
                                 $image->setName(basename($logo));
                                 $image->Title = basename($logo, '.png');
                                 $image->ParentID = $this->uploadsFolder->ID;
                                 $image->write();
                                 $paymentLogo->ImageID = $image->ID;
                             }
                             $paymentLogo->write();
                             $paymentChannelMethod->PaymentLogos()->add($paymentLogo);
                         }
                     }
                 }
             }
         } else {
             // Single payment channels
             foreach ($paymentLogos as $title => $logo) {
                 if (!$paymentModule->PaymentLogos()->exists()) {
                     $paymentLogo = new SilvercartImage();
                     $paymentLogo->Title = $title;
                     $storedLogo = Image::get()->filter('Name', basename($logo))->first();
                     if ($storedLogo) {
                         $paymentLogo->ImageID = $storedLogo->ID;
                     } else {
                         file_put_contents(Director::baseFolder() . '/' . $this->uploadsFolder->Filename . basename($logo), file_get_contents(Director::baseFolder() . $logo));
                         $image = new Image();
                         $image->setFilename($this->uploadsFolder->Filename . basename($logo));
                         $image->setName(basename($logo));
                         $image->Title = basename($logo, '.png');
                         $image->ParentID = $this->uploadsFolder->ID;
                         $image->write();
                         $paymentLogo->ImageID = $image->ID;
                     }
                     $paymentLogo->write();
                     $paymentModule->PaymentLogos()->add($paymentLogo);
                 }
             }
         }
     }
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:73,代码来源:SilvercartPaymentMethod.php

示例13: updateFromUpdate

 public function updateFromUpdate(stdClass $update, $save = true)
 {
     // print_r($update);
     $pageid = SiteConfig::current_site_config()->FacebookPageId;
     $postid = str_replace($pageid . '_', '', $update->id);
     try {
         $picUrl = $this->resolveUrl('https://graph.facebook.com/' . $postid . '/picture');
     } catch (Exception $e) {
         $picUrl = '';
     }
     if ($picUrl && $picUrl != 'https://fbstatic-a.akamaihd.net/rsrc.php/v2/yA/r/gPCjrIGykBe.gif' && $picUrl != 'https://fbstatic-a.akamaihd.net/rsrc.php/v2/y6/r/_xS7LcbxKS4.gif') {
         // get url
         $img = $picUrl;
         // sanity check
         if (!is_dir(ASSETS_PATH . '/social-updates/')) {
             mkdir(ASSETS_PATH . '/social-updates/');
         }
         // prep img data
         $noq = explode('?', $img);
         $pi = pathinfo($noq[0]);
         $absPath = ASSETS_PATH . '/social-updates/' . $pi['basename'];
         $relPath = ASSETS_DIR . '/social-updates/' . $pi['basename'];
         // pull down image
         if (!file_exists($absPath)) {
             $imgData = file_get_contents($img);
             file_put_contents($absPath, $imgData);
         }
         // does the file exist
         if (file_exists($absPath)) {
             // try to find the existing image
             if (!($image = DataObject::get_one('Image', "Filename='" . $relPath . "'"))) {
                 // create image record
                 $image = new Image();
                 $image->setFilename($relPath);
                 $image->write();
             }
             // associate
             if ($image->ID) {
                 $this->PrimaryImageID = $image->ID;
             }
         }
     }
     // extract content
     $content = empty($update->message) ? empty($update->description) ? empty($update->story) ? null : $update->story : $update->description : $update->message;
     if (!$content) {
         echo 'Encountered error with: ' . print_r($update, 1);
         return false;
     } else {
         $this->Title = 'Facebook Update - ' . $update->id;
         $this->URLSegment = 'FBUpdate-' . $update->id;
         $this->UpdateID = $update->id;
         $this->OriginalCreated = date('Y-m-d H:i:s', strtotime($update->created_time));
         $this->Content = $content;
         $this->OriginalUpdate = json_encode($update);
         $this->findParent();
         return $save ? $this->write() : true;
     }
 }
开发者ID:helpfulrobot,项目名称:azt3k-abc-silverstripe-social,代码行数:58,代码来源:FBUpdate.php

示例14: requireDefaultRecords

 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $data = ClassInfo::subclassesFor("SiteTree");
     $templateOverviewPage = TemplateOverviewPage::get()->First();
     $fileList = null;
     if ($this->Config()->get("image_source_folder")) {
         $fileList = CMSHelp::get_list_of_files($this->Config()->get("image_source_folder"));
         if (!is_array($fileList)) {
             $fileList = null;
         } elseif (!count($fileList)) {
             $fileList = null;
         }
     }
     if ($fileList) {
         $destinationDir = Director::baseFolder() . "/assets/" . $this->Config()->get("image_folder_name") . "/";
         $destinationFolder = Folder::find_or_make($this->Config()->get("image_folder_name"));
     }
     if ($data && $templateOverviewPage) {
         foreach ($data as $className) {
             $object = TemplateOverviewDescription::get()->filter(array("ClassNameLink" => $className))->First();
             if (!$object) {
                 $object = new TemplateOverviewDescription();
                 $object->ClassNameLink = $className;
                 $object->ParentID = $templateOverviewPage->ID;
                 $object->write();
                 DB::alteration_message("adding template description for {$className}", "created");
             } else {
                 $otherObjects = TemplateOverviewDescription::get()->filter(array("ClassNameLink" => $className))->exclude(array("ID" => $object->ID));
                 foreach ($otherObjects as $otherObject) {
                     DB::alteration_message("Deleting superfluous TemplateOverviewDescription with Class Name Link: {$className}", "deleted");
                     $otherObject->delete();
                 }
             }
             if ($fileList) {
                 $i = 0;
                 foreach ($fileList as $fileArray) {
                     $explodeByDot = explode(".", $fileArray["FileName"]);
                     if (is_array($explodeByDot) && count($explodeByDot)) {
                         $base = $explodeByDot[0];
                         $explodeByUnderscore = explode("_", $base);
                         if (is_array($explodeByUnderscore) && count($explodeByUnderscore)) {
                             $base = $explodeByUnderscore[0];
                             $classNameOptionArray = array($className);
                             for ($j = 0; $j < 10; $j++) {
                                 $classNameOptionArray[] = $className . $j;
                             }
                             foreach ($classNameOptionArray as $potentialBase) {
                                 if ($base == $potentialBase) {
                                     $i++;
                                     $filename = "" . $this->Config()->get("image_folder_name") . "/" . $fileArray["FileName"];
                                     if (!file_exists($destinationDir . $fileArray["FileName"])) {
                                         copy($fileArray["FullLocation"], $destinationDir . $fileArray["FileName"]);
                                     }
                                     $image = $Image::get()->filter(array("ParentID" => $destinationFolder - ID, "Name" => $fileArray["FileName"]))->First();
                                     if (!$image) {
                                         $image = new Image();
                                         $image->ParentID = $destinationFolder->ID;
                                         $image->Filename = $filename;
                                         $image->Name = $fileArray["FileName"];
                                         $image->Title = $fileArray["Title"];
                                         $image->write();
                                     }
                                     $fieldName = "Image{$i}" . "ID";
                                     if ($object->{$fieldName} != $image->ID) {
                                         $object->{$fieldName} = $image->ID;
                                         $object->write();
                                         DB::alteration_message("adding image to {$className}: " . $image->Title . " (" . $image->Filename . ") using {$fieldName} field.", "created");
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 DB::alteration_message("no design images found for {$className}", "deleted");
             }
         }
     }
     $helpDirectory = Director::baseFolder() . "/" . Config::inst()->get("CMSHelp", "help_file_directory_name") . "/";
     if (!file_exists($helpDirectory)) {
         mkdir($helpDirectory);
     }
     $this->createManifestExcludeFile($helpDirectory);
     $devDirectory = Director::baseFolder() . "/" . Config::inst()->get("CMSHelp", "dev_file_directory_name") . "/";
     if (!file_exists($devDirectory)) {
         mkdir($devDirectory);
     }
     $this->createManifestExcludeFile($devDirectory);
     $this->createHTACCESSDenyAll($devDirectory);
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-templateoverview,代码行数:91,代码来源:TemplateOverviewDescription.php

示例15: updateFromTweet

 public function updateFromTweet(stdClass $tweet, $save = true)
 {
     if (!empty($tweet->entities->media[0])) {
         // extract media
         $media = $tweet->entities->media[0];
         // only process photos
         if ($media->type == 'photo') {
             // get url
             $img = $media->media_url;
             // sanity check
             if (!is_dir(ASSETS_PATH . '/social-updates/')) {
                 mkdir(ASSETS_PATH . '/social-updates/');
             }
             // prep img data
             $pi = pathinfo($img);
             $absPath = ASSETS_PATH . '/social-updates/' . $pi['basename'];
             $relPath = ASSETS_DIR . '/social-updates/' . $pi['basename'];
             // pull down image
             if (!file_exists($absPath)) {
                 $imgData = file_get_contents($img);
                 file_put_contents($absPath, $imgData);
             }
             // does the file exist
             if (file_exists($absPath)) {
                 // try to find the existing image
                 if (!($image = DataObject::get_one('Image', "Filename='" . $relPath . "'"))) {
                     // create image record
                     $image = new Image();
                     $image->setFilename($relPath);
                     $image->write();
                 }
                 // associate
                 if ($image->ID) {
                     $this->PrimaryImageID = $image->ID;
                 }
             }
         }
     }
     $this->Title = 'Tweet - ' . $tweet->id_str;
     $this->URLSegment = 'Tweet-' . $tweet->id_str;
     $this->TweetID = $tweet->id_str;
     $this->OriginalCreated = date('Y-m-d H:i:s', strtotime($tweet->created_at));
     $this->Content = $tweet->text;
     $this->OriginalTweet = json_encode($tweet);
     $this->findParent();
     return $save ? $this->write() : true;
 }
开发者ID:helpfulrobot,项目名称:azt3k-abc-silverstripe-social,代码行数:47,代码来源:Tweet.php


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