/**
  * @param $images\Models\ViewModels\ImageViewModel[]
  * @return bool
  */
 public function removeMultiple(array $images)
 {
     if (empty($images)) {
         return true;
     }
     $imagesId = array();
     foreach ($images as $image) {
         $imagesId[] = $image->id;
         $this->unlinkImage($image->name);
     }
     return $this->image->deleteMultiple($imagesId) > 0;
 }
Exemplo n.º 2
0
 /**
  * Finds updates by their tags that match the given search query.
  * @param string $term the search term.
  * @param integer $page the current page.
  * @return array found tags.
  */
 public static function searchFor($term, $page = 0)
 {
     if (empty($term)) {
         return [];
     }
     $tagIds = static::getTagIds($term);
     if (0 === count($tagIds)) {
         return [];
     }
     $query = "SELECT u.*," . (CW::$app->user->isLogged() ? "0 < (SELECT count(*) FROM `update_upvoters` WHERE `update_id` = `u`.`id` AND `user_id` = " . CW::$app->user->identity->id . ") " : ' false ') . " `voted` FROM updates u JOIN (SELECT distinct update_id FROM update_tags WHERE tag_id IN (" . ArrayHelper::getArrayToString($tagIds, ',') . ") LIMIT " . static::LOAD_FACTOR . " OFFSET " . static::LOAD_FACTOR * $page . ") ut ON ut.update_id = u.id ORDER BY u.rate DESC, u.created_at DESC";
     $stmt = CW::$app->db->executeQuery($query);
     $updates = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     foreach ($updates as &$update) {
         $update['imgUrl'] = '/images/updates/' . $update['id'] . '/' . Update::IMAGE_MEDIUM_WIDTH . 'xX.jpeg';
         $update['updateUrl'] = Update::getUpdateUrl($update['id']);
         $update['postedAgo'] = BaseModel::getPostedAgoTime($update['created_at']);
         $update['created_at'] = strtotime($update['created_at']);
         $update['voted'] = (bool) $update['voted'];
     }
     if (0 < count($updates)) {
         Update::setUpdateTags($updates);
         Update::setUpdatePostedFrom($updates);
         Image::setUpdateImages($updates);
     }
     return $updates;
 }
Exemplo n.º 3
0
 public function actionDelete()
 {
     if (!isset($_POST['imageId'])) {
         App::instance()->show404();
         exit;
     }
     /** @var \models\Image $model */
     $model = Image::findByID((int) $_POST['imageId']);
     if (!$model || $model->uid != App::instance()->getUser()->getId()) {
         App::instance()->show404();
         exit;
     }
     if ($model->delete()) {
         $response['error'] = false;
     } else {
         $response = json_encode(['error' => true]);
     }
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['HTTP_X_REQUESTED_WITH']) {
         $response['totalCount'] = Image::countByProp('uid', App::instance()->getUser()->getId());
         echo json_encode($response);
     } else {
         $this->redirect('/site/index/');
         echo $response;
     }
 }
Exemplo n.º 4
0
 public function save()
 {
     $imageDg = $this->image->getImage();
     $ext = "jpeg";
     $usersDir = CW::$app->params['sitePath'] . 'public_html/images/users';
     $userDir = "{$usersDir}/{$this->userId}";
     if (!is_dir($usersDir)) {
         mkdir($usersDir);
     }
     if (!is_dir($userDir)) {
         mkdir($userDir);
     }
     $imageMedium = ImageHelper::scaleAndCrop(0, 0, User::IMAGE_MEDIUM_SIZE, User::IMAGE_MEDIUM_SIZE, $imageDg, User::IMAGE_MEDIUM_SIZE, User::IMAGE_MEDIUM_SIZE);
     $imageSmall = ImageHelper::scaleAndCrop(0, 0, User::IMAGE_SMALL_SIZE, User::IMAGE_SMALL_SIZE, $imageDg, User::IMAGE_SMALL_SIZE, User::IMAGE_SMALL_SIZE);
     imagejpeg($imageMedium, sprintf("%s/%dx%d.%s", $userDir, User::IMAGE_MEDIUM_SIZE, User::IMAGE_MEDIUM_SIZE, $ext));
     imagejpeg($imageSmall, sprintf("%s/%dx%d.%s", $userDir, User::IMAGE_SMALL_SIZE, User::IMAGE_SMALL_SIZE, $ext));
     imagedestroy($imageMedium);
     imagedestroy($imageSmall);
     $imageId = Image::create(['rel_id' => CW::$app->user->identity->id, 'rel_type' => Image::REL_TYPE_USER, 'type' => Image::TYPE_PROFILE_PIC, 'image_type' => Image::IMAGE_TYPE_NORMAL]);
     if (null !== $imageId) {
         CW::$app->db->executeUpdate("UPDATE `users` SET `profile_img_id` = {$imageId} WHERE id = " . CW::$app->user->identity->id);
         $_SESSION['user']->profile_img_id = $imageId;
     }
     return true;
 }
Exemplo n.º 5
0
 public function __construct()
 {
     $this->pageContentModel = \Models\PageContent::instance();
     $this->contentListModel = \Models\ContentListElement::instance();
     $this->contentListEltModel = \Models\ContentListElement::instance();
     $this->contentGroupEltModel = \Models\ContentGroupElement::instance();
     $this->imageModel = \Models\Image::instance();
     $this->textModel = \Models\Texte::instance();
     $this->f3 = \Base::instance();
     $this->contentGroupModel = \Models\ContentGroup::instance();
     $this->pageModel = $pageModel = \Models\Page::instance();
 }
Exemplo n.º 6
0
 public static function boot()
 {
     parent::boot();
     Main::$app->connection->validator->extend('imageExists', function ($attribute, $value, $parameters, $validator) {
         $validator->setCustomMessages([$attribute => 'Image already exists']);
         list($scene, $server, $id) = $parameters;
         $image = Image::where([$attribute => $value, 'scene' => $scene, 'server' => $server]);
         if ($id) {
             $image = $image->where('id', '!=', $id);
         }
         return $image->count() === 0;
     });
 }
 /**
  * @param $id
  * @param EstateAdBindingModel $estate
  */
 public function addEstateAdditionalImages($id, EstateAdBindingModel $estate)
 {
     foreach ($estate->images as $image) {
         $imageName = $this->saveFile($image, EstateController::IMAGE_DIR . DIRECTORY_SEPARATOR);
         if (!empty($imageName)) {
             $imageId = $this->image->add($imageName);
             $this->image->addImageToEstate($id, $imageId);
             if ($this->validateImageDimensions(EstateController::IMAGE_DIR . DIRECTORY_SEPARATOR . $imageName, EstateController::IMAGE_MAX_WIDTH_WITHOUT_RESIZE, EstateController::IMAGE_MAX_HEIGHT_WITHOUT_RESIZE)) {
                 $this->createImageThumbnail($imageName, EstateController::IMAGE_THUMBNAIL_WIDTH, EstateController::IMAGE_THUMBNAIL_HEIGHT, EstateController::IMAGE_THUMBNAIL_PREFIX, EstateController::IMAGE_DIR);
             }
         }
     }
 }
Exemplo n.º 8
0
 public function delete($f3)
 {
     header('Cache-Control: no-cache, must-revalidate');
     header('Content-type: application/json');
     $lang = $f3->get('PARAMS.lang');
     $id = $f3->get('PARAMS.id');
     $image = \Models\Image::instance()->get($id, $lang);
     if ($image) {
         $newPath = dirname($f3->get('SERVER.SCRIPT_FILENAME')) . '/' . $f3->get('IMAGES_PATH') . 'deleted/' . $image['id'] . '_' . basename($image['file']);
         $oldPath = dirname($f3->get('SERVER.SCRIPT_FILENAME')) . $image['file'];
         rename($oldPath, $newPath);
         echo json_encode(\Models\Image::instance()->delete($id));
     }
 }
Exemplo n.º 9
0
 public function getTotalImageRequired()
 {
     $total = 0;
     if ($this->is_male) {
         return $total;
     }
     if ($this->is_only_dmm) {
         $total = Image::IMAGE_PER_SERVER;
     } else {
         $total = Image::IMAGE_PER_SERVER * count(Image::getImageSchemeArray());
     }
     if ($this->has_aw_image) {
         $total++;
     }
     return $total;
 }
Exemplo n.º 10
0
 public function saveEditedGallery($id)
 {
     $gal = GalleryQuery::create()->findPk($id);
     $dir = "includes/images/fullsize/";
     foreach ($_POST["image"] as $post) {
         $d = explode(',', $post);
         $img = imagecreatefromstring(base64_decode($d[1]));
         do {
             $name = token(20) . ".png";
             $path = $dir . $name;
         } while (file_exists($path));
         $i = new Image();
         $i->setPath($name)->setDescription("Fotografie z galerie " . $gal->getName())->setThumbnailPath($name)->setType("fullsize")->save();
         imagepng(resizeImg($img, 1280, 720), $path);
         $dir = "includes/images/960x540/";
         $path = $dir . $name;
         imagepng(resizeImg($img, 960, 540), $path);
         $dir = "includes/images/50x50/";
         $path = $dir . $name;
         imagepng(resizeImg($img, 50, 50), $path);
         $names[] = $name;
     }
     $imgs = ImageQuery::create()->filterByPath($names)->find();
     foreach ($imgs as $i) {
         $map = new ImageGalleryMap();
         $map->setIdImage($i->getId());
         $map->setIdGallery($id);
         $map->save();
     }
     $this->addPopup('success', 'Fotografie byly úspěšné přidány do galerie.');
     redirectTo('/administrace/galerie');
 }
Exemplo n.º 11
0
?>
" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <form enctype="multipart/form-data" class="ws-validate" method="post" role="form" action=<?php 
echo Main::$app->router->pathFor('imageUpload', ['id' => $model->id]);
?>
>
            <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Upload images</h4>
                </div>
                <div class="modal-body">
                    <?php 
foreach (Image::getImageSchemeArray() as $server => $sceneList) {
    foreach ($sceneList as $scene) {
        if ($model->isImageRequired($server, $scene)) {
            echo $this->render('image/ajax/modal-body', ['image' => (object) ['server' => $server, 'scene' => $scene]]);
        }
    }
}
?>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">upload images</button>
                </div>
            </div>
        </form>
    </div>
Exemplo n.º 12
0
 public function save()
 {
     $imageDg = $this->image->getImage();
     $ext = "jpeg";
     $stmt = CW::$app->db->prepare("INSERT INTO `updates` (`user_id`, `description`, `is_gif`, `created_at`) VALUES (:userId, :description, " . ($this->image->isGif() ? 1 : 0) . ", :created_at)");
     if (0 >= $stmt->execute([':userId' => \CW::$app->user->identity->id, ':description' => $this->title, ':created_at' => time()])) {
         return false;
     }
     $this->newUpdateId = CW::$app->db->getLastInsertedId();
     if (!Update::addActivity($this->newUpdateId, CW::$app->user->identity->id, Update::ACTIVITY_TYPE_POST)) {
         return false;
     }
     $this->addTags();
     $a = [];
     foreach ($this->categories as $category) {
         $c = (int) $category;
         $a[] = "({$this->newUpdateId}, {$c})";
     }
     $categoryInsert = 'INSERT INTO `update_categories` (`update_id`, `category_id`) VALUES ' . implode(',', $a);
     if (0 >= CW::$app->db->executeUpdate($categoryInsert)) {
         return false;
     }
     $updateDir = CW::$app->params['sitePath'] . 'public_html/images/updates/' . $this->newUpdateId;
     if (!file_exists(CW::$app->params['sitePath'] . 'public_html/images/updates')) {
         mkdir(CW::$app->params['sitePath'] . 'public_html/images/updates');
     }
     mkdir($updateDir);
     if ('image/gif' === $this->image->getExt()) {
         if (!file_exists(CW::$app->params['sitePath'] . 'public_html/images/tmp')) {
             mkdir(CW::$app->params['sitePath'] . 'public_html/images/tmp');
         }
         $i = ImageHelper::loadImage($this->image->getImage());
         if (!$i) {
             $this->addError('image', 'Invalid gif.');
             return false;
         }
         imagejpeg(ImageHelper::scaleImage($i->getImage(), 500), CW::$app->params['sitePath'] . "public_html/images/updates/{$this->newUpdateId}/poster.jpeg");
         $inpFile = CW::$app->params['sitePath'] . "public_html/images/tmp/{$this->newUpdateId}_medium.gif";
         $outFileMedium = "{$updateDir}/medium";
         foreach (['mp4', 'webm'] as $ext) {
             $mediumBytes = ImageHelper::resizeGif($this->image->getImage(), 500);
             file_put_contents($inpFile, $mediumBytes);
             ImageHelper::gifToVideo($inpFile, "{$outFileMedium}.{$ext}");
             unlink($inpFile);
         }
         $imageType = Image::IMAGE_TYPE_VIDEO;
         $type = Image::TYPE_IMAGE;
     } else {
         $imageBig = ImageHelper::scaleImage($imageDg, Update::IMAGE_BIG_WIDTH, PHP_INT_MAX);
         $imageMedium = ImageHelper::scaleImage($imageDg, Update::IMAGE_MEDIUM_WIDTH, PHP_INT_MAX);
         $highImage = imagesy($imageMedium) > imagesx($imageMedium) + 150;
         if ($highImage) {
             $imageMedium = ImageHelper::cropImage(0, 0, imagesx($imageMedium), 300, $imageMedium);
         }
         $imageSmall = ImageHelper::scaleImage($imageDg, Update::IMAGE_SMALL_WIDTH, PHP_INT_MAX);
         if ($highImage) {
             $imageSmall = ImageHelper::cropImage(0, 0, imagesx($imageSmall), 150, $imageSmall);
         }
         imagejpeg($imageBig, sprintf("%s/%dxX.%s", $updateDir, Update::IMAGE_BIG_WIDTH, $ext));
         imagejpeg($imageMedium, sprintf("%s/%dxX.%s", $updateDir, Update::IMAGE_MEDIUM_WIDTH, $ext));
         imagejpeg($imageSmall, sprintf("%s/%dxX.%s", $updateDir, Update::IMAGE_SMALL_WIDTH, $ext));
         imagedestroy($imageBig);
         imagedestroy($imageMedium);
         imagedestroy($imageSmall);
         $imageType = Image::IMAGE_TYPE_NORMAL;
         $type = $highImage ? Image::TYPE_HIGH_IMAGE : Image::TYPE_IMAGE;
     }
     Image::create(['rel_id' => $this->newUpdateId, 'rel_type' => Image::REL_TYPE_UPDATE, 'type' => $type, 'image_type' => $imageType]);
     return true;
 }
Exemplo n.º 13
0
<?php

use models\Image;
use app\core\View;
/* @var $this View */
$name = $image->server . $image->scene;
?>
<div class="row">
    <h4 class="text-center"><?php 
echo $image->server;
?>
 <?php 
echo Image::imageSceneToHuman($image->scene);
?>
</h4>
    <div class="col-xs-12 form-group">
        <div class="col-xs-3">
            <label>File:</label>
        </div>
        <div class="col-xs-9">
            <input name="<?php 
echo $name;
?>
" type="file">
        </div>
    </div>
    <div class="col-xs-12">
        <div class="col-xs-3"><label>or</label></div>
    </div>
    <div class="col-xs-12 form-group">
        <div class="col-xs-3">
Exemplo n.º 14
0
 /**
  * Filter the query by a related \Models\Image object
  *
  * @param \Models\Image|ObjectCollection $image The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @throws \Propel\Runtime\Exception\PropelException
  *
  * @return ChildUserQuery The current query, for fluid interface
  */
 public function filterByImage($image, $comparison = null)
 {
     if ($image instanceof \Models\Image) {
         return $this->addUsingAlias(UserTableMap::COL_ID_IMAGE, $image->getId(), $comparison);
     } elseif ($image instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(UserTableMap::COL_ID_IMAGE, $image->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByImage() only accepts arguments of type \\Models\\Image or Collection');
     }
 }
Exemplo n.º 15
0
 /**
  * Exclude object from result
  *
  * @param   ChildImage $image Object to remove from the list of results
  *
  * @return $this|ChildImageQuery The current query, for fluid interface
  */
 public function prune($image = null)
 {
     if ($image) {
         $this->addUsingAlias(ImageTableMap::COL_ID, $image->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Exemplo n.º 16
0
 /**
  * 
  * @param type $time
  * @param type $userId
  * @param type $type
  * @return boolean
  */
 public static function getUserUpdates($userId, $type, $page = 0)
 {
     if (!is_numeric($userId)) {
         return false;
     }
     static::validateActivityType($type);
     if ('all' === $type) {
         $where = '';
     } else {
         if ('posted' === $type) {
             $where = 'AND ua.type_posted= 1';
         } else {
             if ('upvoted' === $type) {
                 $where = 'AND ua.type_upvoted = 1';
             } else {
                 if ('commented' === $type) {
                     $where = 'AND ua.type_commented = 1';
                 } else {
                     $where = '';
                 }
             }
         }
     }
     $query = "SELECT u.*, ua.type_posted, ua.type_upvoted, ua.type_commented, " . (CW::$app->user->isLogged() ? "0 < (SELECT count(*) FROM `update_upvoters` WHERE `update_id` = `u`.`id` AND `user_id` = " . CW::$app->user->identity->id . ") " : ' false ') . " `voted` FROM `updates` u JOIN `user_update_activity` ua ON ua.update_id = u.id WHERE ua.`user_id` = {$userId} {$where} ORDER BY ua.`time` DESC LIMIT " . self::UPDATES_LOAD_COUNT . " OFFSET " . self::UPDATES_LOAD_COUNT * $page;
     $stmt = CW::$app->db->executeQuery($query);
     $updates = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $updatesCount = count($updates);
     for ($i = 0; $i < $updatesCount; $i++) {
         $updates[$i]['description'] = htmlspecialchars($updates[$i]['description']);
         $updates[$i]['imgUrl'] = '/images/updates/' . $updates[$i]['id'] . '/' . self::IMAGE_MEDIUM_WIDTH . 'xX.jpeg';
         $updates[$i]['updateUrl'] = self::getUpdateUrl($updates[$i]['id']);
         $updates[$i]['postedAgo'] = BaseModel::getPostedAgoTime($updates[$i]['created_at']);
         $updates[$i]['created_at'] = strtotime($updates[$i]['created_at']);
         $updates[$i]['voted'] = (bool) $updates[$i]['voted'];
         $updates[$i]['activity_type'] = ($updates[$i]['type_posted'] ? Update::ACTIVITY_TYPE_POST : 0) | ($updates[$i]['type_upvoted'] ? Update::ACTIVITY_TYPE_UPVOTE : 0) | ($updates[$i]['type_commented'] ? Update::ACTIVITY_TYPE_COMMENT : 0);
     }
     if (0 < $updatesCount) {
         self::setUpdateTags($updates);
         self::setUpdatePostedFrom($updates);
         Image::setUpdateImages($updates);
     }
     return $updates;
 }
Exemplo n.º 17
0
 public function actionIndex(Request $request)
 {
     $images = Image::getImageSetByUnitId($request->getAttribute('id'));
     return $this->render('image/index', ['images' => $images]);
 }
Exemplo n.º 18
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aUser) {
         $this->aUser->removeArticle($this);
     }
     if (null !== $this->aImage) {
         $this->aImage->removeArticle($this);
     }
     if (null !== $this->aCategory) {
         $this->aCategory->removeArticle($this);
     }
     $this->id = null;
     $this->id_user = null;
     $this->id_image = null;
     $this->id_category = null;
     $this->title = null;
     $this->url = null;
     $this->keywords = null;
     $this->content = null;
     $this->created_at = null;
     $this->updated_at = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Exemplo n.º 19
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aImage) {
         $this->aImage->removeUser($this);
     }
     if (null !== $this->aMember) {
         $this->aMember->removeUser($this);
     }
     $this->id = null;
     $this->id_member = null;
     $this->username = null;
     $this->member_from = null;
     $this->url = null;
     $this->email = null;
     $this->email_confirmed_at = null;
     $this->email_confirm_token = null;
     $this->email_change_token = null;
     $this->password = null;
     $this->password_reset_token = null;
     $this->permissions = null;
     $this->signin_count = null;
     $this->id_image = null;
     $this->last_signin_at = null;
     $this->created_at = null;
     $this->updated_at = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Exemplo n.º 20
0
 public function rules()
 {
     return array_merge(parent::rules(), ['file' => ['required'], 'height' => ['required', 'integer', 'min:' . self::MIN_HEIGHT, 'max:' . self::MAX_HEIGHT], 'width' => ['required', 'integer', 'min:' . self::MIN_WIDTH, 'max:' . self::MAX_WIDTH], 'size' => ['required', 'integer', 'min:' . self::MIN_FILESIZE, 'max:' . self::MAX_FILESIZE], 'mime' => ['required', 'in:image/png']]);
 }