diff --git a/README.md b/README.md index 6316eda..26d0364 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,123 @@ and [Project wiki](https://github.com/pkerspe/yii2-simple-cms/wiki) for more det Installation instructions are located in the [installation guide](https://github.com/pkerspe/yii2-simple-cms/wiki) -Prefered way is by using composer: +Prefered way is using composer by adding the reuquirement to your composer.json and running composer update afterwards: "require": { - "schallschlucker/yii2-simple-cms": ">=0.1", + "schallschlucker/yii2-simple-cms": ">=0.2.4", } -After installation run migration for database table creation: +After installation run migration for database table creation (it is assumed at this point, that the yii2 db module is configured properly in your configuration). Currently the scripts support only mysql databases, other databases might work as well but haven't been tested yet and thus are disabled in the migration script): - php yii migrate --migrationPath=@schallschlucker/simplecms/migrations + yii migrate --migrationPath=@schallschlucker/simplecms/migrations + +Finally create a folder where to store the uploaded images from the WYSIWYG editor. To do so, create a subfolder named "mediarepository" in the web folder of you application. If you use separated applications for backend and frontend, simply create a simlink to the sceond web folder to use the mediarepository there as well. +Then set the access rights to this folder accordingly so that php is allowed to write to this folder. + +It is also possible to place the mediarepository outside of the web folder to limit access to uploaded files, but then each file needs to be read by php and delivered to the client which certainly has an impact on the performance, so this should only be used if the media data is somewhat sensitive and should only be availbale to logged in users. +when the folder is not placed in the web folder, the module configuration needs to be changed (at the moment you need to edit the backend.php and frontend.php file in the vendor folder of simple-cms, in future versions we will document how to overwrite the path in the module configuration) + +#Usage + +the extension is split into two modules: the frontend and the backend module. + +Frontend provides the needed controllers to: - display page content - display documents - display a search form and a search result page Widgets to: - render a navigation menu (extending yii\bootstrap\Nav widget) - render the navigation structure in different formats like a html list (ol or ul and li nodes), xml, json - render the search bar - render extended search form - render the search results list + +The backend provides administrative functions for maintaining the page tree structure (including drag and drop functionality, keyboard shortcuts and context menus for easy creation of new pages). + +Both modules can be deployed in the same application, but it is recommended to follow the frontend/backend approach to clearly separate the frontend (user view) from the administrative backend interface. + +Content pages in simple cms can be created in multiple language, since simple cms uses internal language id's which might differ from your applications language codes (i.e. ISO 2 letter code or 5 letter code) you need ti initalize the LanguageManager in the components section with a valid mapping to map you applications language codes to the simple cms language codes. Here is an example (which also uses aliases to e.g. map the application language code "de-DE" to the simple cms language code "1" etc.). You can add support for additional languages in simple cms just by adding new mappings.: + + 'components' => [ + 'simplecmsLanguageManager' => [ + 'class' => 'schallschlucker\simplecms\LanguageManager', + 'languageIdMappings' => [ + '1' => [ + 'code' => 'de', + 'displaytext' => [ + 'de' => 'deutsch', + 'en' => 'german', + 'pl' => 'niemiecki', + 'tr' => 'alman', + ], + ], + 'de-DE' => [ + 'alias' => '1' + ], + '2' => [ + 'code' => 'en', + 'displaytext' => [ + 'de' => 'englisch', + 'en' => 'english', + 'pl' => 'angielski', + 'tr' => 'ingilizce', + ], + ], + 'en-US' => [ + 'alias' => '2', + ], + '3' => [ + 'code' => 'pl', + 'displaytext' => [ + 'de' => 'polnisch', + 'en' => 'polish', + 'pl' => 'polski', + 'tr' => 'lehçe', + ], + ], + '4' => [ + 'code' => 'tr', + 'displaytext' => [ + 'de' => 'türkisch', + 'en' => 'turkish', + 'pl' => 'turecki', + 'tr' => 'türk', + ], + ], + ], + ], + ], + 'modules' => [ + 'simplecms_backend' => [ + 'class' => 'schallschlucker\simplecms\Backend', + 'languageManager' => simplecmsLanguageManager + ], + 'simplecms_frontend' => [ + 'class' => 'schallschlucker\simplecms\Frontend', + 'languageManager' => simplecmsLanguageManager + ], + ], + +After the modules registered, you should be able to open the administration backend by calling the "simplecms_backend" route e.g. by calling: + +http://yourserver/index.php?r=simplecms_backend + +or if pretty URLs are activated: + +http://yourserver/simplecms_backend + +Then you should see CMS Administration Backend with a root node in the page-tree. +By right-clicking on the root node you can add new pages to the page tree. +Each page has multiple language versions, so you can create common page tree structure for all different language versions. +Via drag and drop you can rearange the positions and orders of the pages. +Each page (except for the root node) can be set to one of three states: +- visible: it will show up in the rendered navigation by the navigation widget +- hidden: the page won't be shown in the navigation, yet it can be linked of found in the search +- unpublished: the page will neither be shown in the navigation nor in the search results and cannot be linked + +Each page can have three different behavious/types: +- content page: the page is a normal content whose content can be edited via the embeded WYSIWYG editor +- linked document: the page is basically a link to a uploaded document (e.g. PDF) that will be rendered as a link in the navigation +- URL: the page will directly link to any given URL. This can be used to create an alias of a page in the navigation or to link to an external URL and embedding this link in the normal navigation + +You can select one of these page types when creating a new page language version. + + + +# Please note: +In order for the page administration to work you need to be logged in, otherwise an error will occur since the user id will be stored for auditing purposes upon page creation or modification. ## License diff --git a/controllers/backend/MediaController.php b/controllers/backend/MediaController.php index cd771fa..6eb4f8a 100644 --- a/controllers/backend/MediaController.php +++ b/controllers/backend/MediaController.php @@ -459,6 +459,90 @@ public function actionGetMedia($mediaItemId, $variationId = null) { } } + public function actionMediaVarationManager($mediaItemId){ + $mediaItemId = intval ( $mediaItemId ); + + $msg = ''; + /* @var $mediaItem CmsContentMedia */ + $mediaItem = CmsContentMedia::find()->where([ 'id' =>$mediaItemId ])->with('cmsContentMediaVariations')->one(); + if($mediaItem){ + $model = new MediaVariationManagerUpload(); + //check for upload + if($model->load ( Yii::$app->request->post () ) && $model->validate()){ + $model->file = UploadedFile::getInstances ( $model, 'file' ); + if ($model->file != null) { + foreach ( $model->file as $file ) { + /* @VAR $file UploadedFile */ + $targetPath = $this->getFullUploadPathForFile($file); + if($file->saveAs ( $targetPath )){ + $pathInfo = pathinfo($targetPath); + $content = new CmsContentMediaVariation(); + $content->init(); + $content->mime_type = BaseFileHelper::getMimeType($targetPath); + $content->file_name = $pathInfo['basename']; + $content->file_path = $pathInfo['dirname']; + $content->parent_content_media_id = $mediaItemId; + $content->filesize_bytes = $file->size; + if($mediaItem->media_type == MediaController::$MEDIA_TYPE_IMAGE){ + $dimensions = $this->getImageDimensions($targetPath); + if($dimensions != null){ + $content->dimension_width = $dimensions['width']; + $content->dimension_height = $dimensions['height']; + } else { + $msg .= 'Unable to detect image dimensions for image '.$content->file_name; + } + } + if(!$content->insert(true)){ + /** + $this->layout = 'modalLayout'; + return $this->render ( 'fileUpload', [ + 'model' => $model, + 'errors' => $content->errors, + 'mediaType' => $mediaType, + 'msg' => $msg + ] ); + */ + throw new Exception('The upload of one or more files failed. Most likely validation of properties failed'); + } + } else { + throw new Exception('The upload of one or more files failed.'); + } + } + } + } else { + $model->parentMediaId = $mediaItem->id; + switch($mediaItem->media_type){ + case MediaController::$MEDIA_TYPE_AUDIO: + $this->layout = 'modalLayout'; + return $this->render ( 'mediaVariationManager_audio', [ + 'mediaItem' => $mediaItem, + 'model' => $model + ] ); + break; + case MediaController::$MEDIA_TYPE_VIDEO: + $this->layout = 'modalLayout'; + return $this->render ( 'mediaVariationManager_video', [ + 'mediaItem' => $mediaItem, + 'model' => $model + ] ); + break; + case MediaController::$MEDIA_TYPE_IMAGE: + $this->layout = 'modalLayout'; + return $this->render ( 'mediaVariationManager_image', [ + 'mediaItem' => $mediaItem, + 'model' => $model + ] ); + break; + default: + throw new UserException('The media item to manage variations for has an unknown media type'); + break; + } + } + } else { + throw new UserException('The media item could not be found for the given id'); + } + } + /** * display the media variation manager screen. Used in the media browser to display multiple version (e.g. Image formats) of a media item) * @menuLabel __HIDDEN__