public function testShortVersion()
 {
     $node = Node::from(array('constructor' => 'articles'));
     $image = Image::from(array('nid' => 1));
     $relation = new NodeRelation($node, $image);
     $this->assertEquals('/api/images/1/thumbnails/articles-list', $relation->thumbnail(':list')->url);
     $this->assertEquals('/api/images/1/thumbnails/articles-view', $relation->thumbnail->url);
 }
 public static function on_node_save(Event $event, \Icybee\Modules\Nodes\SaveOperation $operation)
 {
     global $core;
     $params =& $event->request->params;
     $nid = $event->rc['key'];
     if (empty($params['nodes_attachments'])) {
         return;
     }
     $model = $core->models['nodes.attachments'];
     $files_model = $core->models['files'];
     $images_model = $core->models['images'];
     $root = \ICanBoogie\DOCUMENT_ROOT;
     $repository = $core->config['repository.temp'] . '/';
     $weight = 0;
     $attached_fileids = array();
     foreach ($params['nodes_attachments'] as $attached_params) {
         if (isset($attached_params['file'])) {
             #
             # create
             #
             $path = $repository . $attached_params['file'];
             $attached_params['path'] = $path;
             $attached_params['is_online'] = true;
             if (getimagesize($root . $path)) {
                 $fileid = \Icybee\Modules\Images\Image::from($attached_params + array(Node::SITEID => $core->site_id, Node::CONSTRUCTOR => 'images'))->save();
             } else {
                 $fileid = \Icybee\Modules\Files\File::from($attached_params + array(Node::SITEID => $core->site_id, Node::CONSTRUCTOR => 'files'))->save();
             }
             if (!$fileid) {
                 $operation->errors[] = new FormattedString('Unable to save file: {0}', array($attached_params));
                 continue;
             }
             $model->save(array('nodeid' => $nid, 'fileid' => $fileid, 'title' => $attached_params['title'], 'weight' => $weight));
             $attached_fileids[] = $fileid;
         } else {
             if (isset($attached_params['fileid'])) {
                 $fileid = $attached_params['fileid'];
                 if ($attached_params['title'] == '!delete') {
                     $file = $files_model[$fileid];
                     $delete_request = Request::from(array('path' => "/api/{$file->constructor}/{$fileid}/delete"));
                     $delete_request->post();
                     continue;
                 } else {
                     if ($attached_params['title'] == '!remove') {
                         continue;
                     }
                 }
                 $model->execute('UPDATE {self} SET title = ?, weight = ? WHERE nodeid = ? AND fileid = ?', array($attached_params['title'], $weight, $nid, $fileid));
                 $attached_fileids[] = $fileid;
             }
         }
         $weight++;
     }
     #
     # we remove the link to unspecified files.
     #
     $model->execute('DELETE FROM {self} WHERE nodeid = ?' . ($attached_fileids ? ' AND fileid NOT IN(' . implode(',', $attached_fileids) . ')' : ''), array($nid));
 }
Beispiel #3
0
<?php

/*
 * This file is part of the Icybee package.
 *
 * (c) Olivier Laviale <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Icybee\Modules\Images;

use ICanBoogie\Modules\Thumbnailer\Version;
use ICanBoogie\Modules\Thumbnailer\Versions;
use ICanBoogie\Prototype;
require __DIR__ . '/../vendor/autoload.php';
#
# Thumbnailer setup
#
$prototype = Prototype::from(__NAMESPACE__ . '\\Image');
$prototype['thumbnail'] = 'ICanBoogie\\Modules\\Thumbnailer\\Hooks::method_thumbnail';
#
# Image setup
#
$prototype = Prototype::from('Icybee\\Modules\\Nodes\\Node');
$prototype['lazy_get_image'] = __NAMESPACE__ . '\\Hooks::prototype_get_image';
#
# Mocking core
#
$core = (object) array('models' => array('images' => array(1 => Image::from(array('nid' => 1)), 2 => Image::from(array('nid' => 2)), 3 => Image::from(array('nid' => 3)))), 'thumbnailer_versions' => new Versions(array('articles-list' => new Version('w:120;h:100'), 'articles-view' => new Version('w:420;h:340'))));