public static function returnExtFormElements() { $mod_tpl = static::returnTpl(); $class = __CLASS__; ## ## EXTFORM SEO ## ExtForm::add("seo", function ($name = 'seo', $value = '', $params = null) use($mod_tpl, $class) { if (!Allow::action('seo', 'edit', true)) { return false; } ## default template $tpl = "extform_seo"; ## custom template if (@$params['tpl']) { $tpl = $params['tpl']; unset($params['tpl']); } #$value = $element_meta->seo; /* ## Don't work with i18n versions if ( $value === false || $value === null ) { $val = Form::text($name); Helper::dd($val); preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches); Helper::dd($matches); $val = @$matches[1]; $array = json_decode($val, true); if ($array) $value = $array; } #*/ ## return view with form element return View::make($mod_tpl . $tpl, compact('name', 'value', 'params')); }, function ($params) use($mod_tpl, $class) { #Helper::dd($params); $module = isset($params['module']) ? $params['module'] : false; $unit_id = isset($params['unit_id']) ? $params['unit_id'] : false; $data = isset($params['data']) ? $params['data'] : false; $locale = isset($params['locale']) ? $params['locale'] : NULL; if (!$module || !$unit_id) { return false; } #Helper::dd($data); #$data['module'] = $module; #$data['unit_id'] = $unit_id; #Helper::dd($data); foreach ($data as $d => $dat) { if (!is_string($dat)) { continue; } $data[$d] = trim($dat); } $seo = Seo::firstOrCreate(array('module' => $module, 'unit_id' => $unit_id, 'language' => $locale)); $seo->update($data); return $seo; }); }
public static function returnExtFormElements() { $mod_tpl = static::returnTpl(); $class = __CLASS__; ## ## EXTFORM GALLERY ## /* ################################################ ## Process gallery ################################################ if (Allow::action('admin_galleries', 'edit')) { ExtForm::process('gallery', array( 'module' => self::$name, 'unit_id' => $id, 'gallery' => Input::get('gallery'), )); } ################################################ */ ExtForm::add("gallery", function ($name = 'gallery', $value = '', $params = null) use($mod_tpl, $class) { ## default template $tpl = "extform_gallery"; ## custom template if (@$params['tpl']) { $tpl = $params['tpl']; unset($params['tpl']); } #Helper::dd($value); #Helper::dd($params); if (!is_object($value)) { $gallery = NULL; } if ($value === false || $value === null) { $val = Form::text($name); preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches); #Helper::d($matches); $val = (int) @$matches[1]; #Helper::tad($val); if ($val > 0) { $gallery = Gallery::where('id', $val)->with('photos')->first(); #Helper::tad($gallery); } } elseif (is_numeric($value)) { $gallery = Gallery::where('id', $value)->with('photos')->first(); } #Helper::tad($gallery); ## return view with form element return View::make($mod_tpl . $tpl, compact('name', 'value', 'gallery', 'params'))->render(); }, function ($params) use($mod_tpl, $class) { #dd($params); $module = isset($params['module']) ? $params['module'] : false; $unit_id = isset($params['unit_id']) ? $params['unit_id'] : false; $gallery = isset($params['gallery']) ? $params['gallery'] : false; $gallery_id = isset($gallery['gallery_id']) ? $gallery['gallery_id'] : 0; $uploaded_images = isset($gallery['uploaded_images']) ? $gallery['uploaded_images'] : array(); $module = (string) trim($module); $unit_id = (string) trim($unit_id); if (@$params['single']) { $gallery_id = $class::moveImagesToGallery($uploaded_images, $gallery_id); if ($gallery_id) { $class::renameGallery($gallery_id, $module . " - " . $unit_id); } } else { ## Perform all actions for adding photos to the gallery & bind gallery to the unit_id of module $gallery_id = $class::imagesToUnit($uploaded_images, $module, $unit_id, $gallery_id); } #Helper::dd($gallery_id); return $gallery_id; }); ## ## EXTFORM IMAGE ## /* ################################################ ## Process image ################################################ if (Allow::action('admin_galleries', 'edit')) { $input['image_id'] = ExtForm::process('image', array( 'image' => Input::get('image'), 'return' => 'id', )); } ################################################ */ ExtForm::add("image", function ($name = 'image', $value = '', $params = null) use($mod_tpl, $class) { ## default template $tpl = "extform_image"; ## custom template if (@$params['tpl']) { $tpl = $params['tpl']; unset($params['tpl']); } #dd($value); #Helper::dd($params); if (!is_object($value)) { $photo = NULL; } if ($value === false || $value === null) { $val = Form::text($name); preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches); #Helper::d($matches); $val = (int) @$matches[1]; #Helper::tad($val); if ($val > 0) { #$photo = Photo::firstOrNew(array('id' => $val)); $photo = Photo::find($val); #Helper::tad($photo); } } elseif (is_numeric($value)) { $photo = Photo::find($value); } #Helper::tad($value); #Helper::tad($photo); ## return view with form element return View::make($mod_tpl . $tpl, compact('name', 'value', 'photo', 'params')); }, function ($params) use($mod_tpl, $class) { #Helper::dd($params); ## Array with POST-data $image = @$params['image'] ?: false; ## Return format $return = @$params['return'] ?: false; ## ID of uploaded image #$uploaded_image = isset($image['uploaded_image']) ? (int)$image['uploaded_image'] : false; $uploaded_image = $image; #Helper::dd($uploaded_image); if (!$uploaded_image) { return false; } ## Find photo by ID $photo = Photo::where('id', $uploaded_image)->first(); ## If photo don't exists - return false if (is_null($photo)) { return false; } ## Mark photo as "single used image" $photo->gallery_id = 0; $photo->save(); ## Return needable property or full object return $return ? @$photo->{$return} : $photo; }); }
public static function returnExtFormElements() { $mod_tpl = static::returnTpl(); $class = __CLASS__; /** * EXTFORM UPLOAD */ ExtForm::add("upload", function ($name = 'upload', $value = '', $params = null) use($mod_tpl, $class) { ## default template $tpl = "extform_upload"; ## custom template if (@$params['tpl']) { $tpl = $params['tpl']; unset($params['tpl']); } #Helper::dd($value); if ($value === false || $value === null) { $val = Form::text($name); preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches); #Helper::d($matches); $val = (int) @$matches[1]; if ($val > 0) { $value = Upload::firstOrNew(array('id' => $val)); } } elseif (is_numeric($value)) { $value = Upload::find($value); } #Helper::dd($params); ## return view with form element return View::make($mod_tpl . $tpl, compact('name', 'value', 'params')); }, function ($params) use($mod_tpl, $class) { #Helper::d($params); $file = isset($params['file']) ? $params['file'] : false; $upload_id = isset($params['upload_id']) ? $params['upload_id'] : false; $delete = isset($params['delete']) ? $params['delete'] : false; $return = isset($params['return']) ? $params['return'] : 'id'; $module = isset($params['module']) ? $params['module'] : NULL; $unit_id = isset($params['unit_id']) ? $params['unit_id'] : NULL; ## Find file $upload = false; if (is_numeric($upload_id)) { $upload = Upload::find($upload_id); } ## Delete if ($delete && is_object($upload)) { #Helper::dd($upload->fullpath()); @unlink($upload->fullpath()); $upload->delete(); if (!is_object($file)) { return NULL; } } ## If new file uploaded if (is_object($file)) { $mimetype = $file->getMimeType(); $mimes = explode('/', $mimetype); ## Move file $dir = Config::get('site.uploads_dir', public_path('uploads/files')); $file_name = time() . "_" . rand(1000, 1999) . '.' . $file->getClientOriginalExtension(); $file->move($dir, $file_name); $path = preg_replace("~^" . addslashes(public_path()) . "~is", '', $dir . '/' . $file_name); #Helper::dd(filesize($dir . '/' . $file_name)); $input = array('path' => $path, 'original_name' => $file->getClientOriginalName(), 'filesize' => filesize($dir . '/' . $file_name), 'mimetype' => $mimetype, 'mime1' => @$mimes[0], 'mime2' => @$mimes[1], 'module' => $module, 'unit_id' => $unit_id); ## Create new upload object if file not found if (!is_object($upload)) { $upload = new Upload(); $upload->save(); } ## Update upload record with new path $upload->update($input); ## Return return @$upload->{$return}; } ## Return exist upload_id, if no actions if (is_numeric($upload_id)) { return $upload_id; } }); /** * EXTFORM UPLOADS */ ExtForm::add("uploads", function ($name = 'uploads', $values = array(), $params = null) use($mod_tpl, $class) { ## default template $tpl = "extform_uploads"; ## custom template if (@$params['tpl']) { $tpl = $params['tpl']; unset($params['tpl']); } #Helper::dd($values); /* if ( $value === false || $value === null ) { $val = Form::text($name); preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches); #Helper::d($matches); $val = (int)@$matches[1]; if ( $val > 0 ) { $value = Upload::firstOrNew(array('id' => $val)); } } elseif (is_numeric($value)) { $value = Upload::find($value); } */ #Helper::dd($params); $params['multiple'] = 'multiple'; ## return view with form element return View::make($mod_tpl . $tpl, compact('name', 'values', 'params'))->render(); }, function ($params) use($mod_tpl, $class) { $files = isset($params['files']) ? $params['files'] : false; #$upload_id = isset($params['upload_id']) ? $params['upload_id'] : false; $module = isset($params['module']) ? $params['module'] : NULL; $unit_id = isset($params['unit_id']) ? $params['unit_id'] : NULL; #Helper::dd($files); ## If new file uploaded if (isset($files) && is_array($files) && count($files)) { $c = 0; foreach ($files as $f => $file) { if (!is_object($file)) { continue; } $mimetype = $file->getMimeType(); $mimes = explode('/', $mimetype); ## Move file $dir = Config::get('site.uploads_dir', public_path('uploads/files')); $file_name = time() . "_" . rand(1000000, 1999999) . '.' . $file->getClientOriginalExtension(); $file->move($dir, $file_name); #$path = preg_replace("~^" . addslashes(public_path()) . "~is", '', $dir . '/' . $file_name); $path = $dir . '/' . $file_name; #Helper::dd(filesize($dir . '/' . $file_name)); $input = array('path' => $path, 'original_name' => $file->getClientOriginalName(), 'filesize' => filesize($dir . '/' . $file_name), 'mimetype' => $mimetype, 'mime1' => @$mimes[0], 'mime2' => @$mimes[1], 'module' => $module, 'unit_id' => $unit_id); ## Create new upload object if file not found $upload = new Upload(); $upload->save(); ## Update upload record with new path $upload->update($input); ++$c; } return $c > 0; } return false; }); }