Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate(ObjectTypeRequest $request)
 {
     $objecttype = new Object();
     $objecttype->author_id = Auth::user()->id;
     $objecttype->type = 'object_type';
     $objecttype->name = "_object_type_" . str_replace(' ', '-', $request->title);
     $objecttype->title = "Object Type: {$request->title}";
     $objecttype->status = 'published';
     $objecttype->guid = Hash::getUniqueId();
     $objecttype->save();
     return redirect('admin/object-types')->with('message', 'Type saved successfully');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id = false)
 {
     $this->validate($request, ['a_name' => 'required|max:55']);
     if ($id) {
         $object = Object::findOrFail($id);
     } else {
         $object = new Object();
     }
     $object->name = $request->a_name;
     $saved = $object->save();
     if (!$id) {
         $id = $object->id;
     }
     return redirect('/objects/' . $id . '?saved=' . $saved);
 }
Exemplo n.º 3
0
function addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, $fieldName)
{
    list($source_image_width, $source_image_height, $source_image_type) = getimagesize($destinationPath . $picture);
    $imageObjectInfo = array();
    $imageObjectInfo['width'] = $source_image_width;
    $imageObjectInfo['height'] = $source_image_height;
    $imageObjectInfo['filePath'] = $filename;
    $imageObjectInfo['sizes'] = array();
    if ($source_image_width > 1920) {
        //} || $source_image_height > 1080) {
        Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.' . $extension, 1920, 1080);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.' . $extension);
        rename($destinationPath . $newfileName . '-resized.' . $extension, $destinationPath . $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $destinationPath . $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension;
        $imageInfo['width'] = $siw;
        $imageInfo['height'] = $sih;
        $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['large'] = $imageInfo;
    }
    if ($source_image_width > 1024) {
        // || $source_image_height > 768) {
        Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.' . $extension, 1024, 768);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.' . $extension);
        rename($destinationPath . $newfileName . '-resized.' . $extension, $destinationPath . $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension;
        $imageInfo['width'] = $siw;
        $imageInfo['height'] = $sih;
        $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['medium'] = $imageInfo;
    }
    if ($source_image_width > 350) {
        //|| $source_image_height > 350) {
        Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.' . $extension, 350, 350);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.' . $extension);
        rename($destinationPath . $newfileName . '-resized.' . $extension, $destinationPath . $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension;
        $imageInfo['width'] = $siw;
        $imageInfo['height'] = $sih;
        $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['small'] = $imageInfo;
    }
    if ($source_image_width > 300) {
        //|| $source_image_height > 350) {
        Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.' . $extension, 300, 300);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.' . $extension);
        rename($destinationPath . $newfileName . '-resized.' . $extension, $destinationPath . $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-' . $siw . 'x' . $sih . '.' . $extension;
        $imageInfo['width'] = $siw;
        $imageInfo['height'] = $sih;
        $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['thumbnail'] = $imageInfo;
    }
    // Save image object
    if ($imageObjectId = ObjectMeta::getValue($object->id, $fieldName)) {
        $imageObject = Object::find($imageObjectId);
    }
    if (empty($imageObject)) {
        $imageObject = new Object();
    }
    $imageObject->author_id = Auth::user()->id;
    $imageObject->type = 'image';
    $imageObject->name = $newfileName . '.' . $extension;
    $imageObject->title = $filename;
    $imageObject->status = 'inherit';
    $imageObject->guid = $newfileName;
    $imageObject->save();
    ObjectMeta::setValue($imageObject->id, '_file_path', $newfileName . '.' . $extension);
    ObjectMeta::setValue($imageObject->id, '_image_info', serialize($imageObjectInfo));
    ObjectMeta::setValue($object->id, $fieldName, $imageObject->id);
    return $imageObject;
}
Exemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate(ObjectRequest $request)
 {
     $object = new Object();
     $object->author_id = Auth::user()->id;
     $object->type = $request->_object_type;
     $object->name = str_replace(' ', '-', $request->title);
     $object->title = $request->title;
     $object->status = 'published';
     $object->guid = Hash::getUniqueId();
     $object->save();
     foreach (array_keys($_POST) as $key) {
         if (substr($key, 0, 7) == '_field_') {
             $object->setValue($key, $request->input($key));
         }
     }
     if ($request->hasFile('featuredImage')) {
         $file = $request->file('featuredImage');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $mimeType = $file->getMimeType();
         $destinationPath = public_path() . '/uploads/';
         $newfileName = sha1($filename . time());
         $picture = $newfileName . '.' . $extension;
         $request->file('featuredImage')->move($destinationPath, $picture);
         if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_featured_image')) {
         }
     }
     if ($request->hasFile('contentImage')) {
         $file = $request->file('contentImage');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $mimeType = $file->getMimeType();
         $destinationPath = public_path() . '/uploads/';
         $newfileName = sha1($filename . time());
         $picture = $newfileName . '.' . $extension;
         $request->file('contentImage')->move($destinationPath, $picture);
         if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_content_image')) {
         }
     }
     return redirect('admin/object-types')->with('message', 'Type saved successfully');
 }
Exemplo n.º 5
0
function addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, $fieldName)
{
    list($source_image_width, $source_image_height, $source_image_type) = getimagesize($destinationPath . $picture);
    $imageObjectInfo = array();
    $imageObjectInfo['width'] = $source_image_width;
    $imageObjectInfo['height'] = $source_image_height;
    $imageObjectInfo['fileName'] = $filename;
    $imageObjectInfo['filePath'] = $newfileName . '.' . $extension;
    $imageObjectInfo['sizes'] = array();
    $x = autoCrop($destinationPath, $picture, $fieldName);
    if ($x !== false) {
        $round = (int) \App\ResizesTinypng::max('round') + 1;
        insertIntoTableResizes($round, getTheImageSize($picture, $fieldName), $destinationPath . 'cropped/' . getTheImageSize($picture, $fieldName), 0, 'N', 0, false);
        $results_table = selectByRoundNumber($round);
        if (!empty($results_table)) {
            foreach ($results_table as $res_row) {
                $result_array = array('id' => intval($res_row['id']), 'round' => intval($res_row['round']), 'filename' => $res_row['file_name'], 'path' => $res_row['path'], 'runTiny' => intval($res_row['run_tiny']), 'error' => $res_row['error'], 'timeTiny' => intval($res_row['time_tiny']), 'timeAdded' => intval($res_row['created_at']));
                $row_obj = array_to_object($result_array);
                $error_message = "N";
                //START >> tinify images
                $tmp_path = str_replace(getcwd() . '/', "", $row_obj->path);
                //GET SERVER PATH
                $save_path = str_replace($row_obj->filename, "", $tmp_path);
                //OVERRIDE CURRENT LOCATION
                $flag = tinifyImage($row_obj->path, $save_path);
                if ($flag === false) {
                    if ($error_message == "N") {
                        $error_message = "Y - Compression failed";
                    } else {
                        $error_message .= " - Compression failed";
                    }
                }
                //END << tinify image
                //UPDATE DB
                updateTableResizes($row_obj->id, $row_obj->round, $row_obj->filename, $row_obj->path, 1, $error_message, time(), $row_obj->timeAdded);
            }
        }
    }
    /*
        if ($source_image_width > 1920) {//} || $source_image_height > 1080) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1920, 1080);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['large'] = $imageInfo;
        }
    if ($source_image_width > 1024) { // || $source_image_height > 768) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1024, 768);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['medium'] = $imageInfo;
        }
    if ($source_image_width > 350) {//|| $source_image_height > 350) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 350, 350);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['small'] = $imageInfo;
        }
    if ($source_image_width > 300) {//|| $source_image_height > 350) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 300, 300);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['thumbnail'] = $imageInfo;
        }
    */
    // Save image object
    if ($imageObjectId = ObjectMeta::getValue($object->id, $fieldName)) {
        $imageObject = Object::find($imageObjectId);
    }
    if (empty($imageObject)) {
        $imageObject = new Object();
    }
    $imageObject->author_id = Auth::user()->id;
    $imageObject->type = 'image';
    $imageObject->name = $newfileName . '.' . $extension;
    $imageObject->title = $filename;
    $imageObject->status = 'inherit';
    $imageObject->guid = $newfileName;
    $imageObject->save();
    ObjectMeta::setValue($imageObject->id, '_file_path', $newfileName . '.' . $extension);
    ObjectMeta::setValue($imageObject->id, '_image_info', serialize($imageObjectInfo));
    ObjectMeta::setValue($object->id, $fieldName, $imageObject->id);
    return $imageObject;
}