Example #1
0
 /**
  * Loads the data.
  *
  * @param array $data Data array with parameters.
  */
 public function loadData(&$data)
 {
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     $utilArgs = array('name' => 'detail');
     if (!isset($data['objectType']) || !in_array($data['objectType'], $controllerHelper->getObjectTypes('contentType', $utilArgs))) {
         $data['objectType'] = $controllerHelper->getDefaultObjectType('contentType', $utilArgs);
     }
     $this->objectType = $data['objectType'];
     if (!isset($data['id'])) {
         $data['id'] = null;
     }
     if (!isset($data['moviewidth'])) {
         $data['moviewidth'] = 400;
     }
     $this->moviewidth = $data['moviewidth'];
     if (!isset($data['movieheight'])) {
         $data['movieheight'] = 300;
     }
     $this->movieheight = $data['movieheight'];
     if (!isset($data['displayMode'])) {
         $data['displayMode'] = 'embed';
     }
     $this->id = $data['id'];
     $this->displayMode = $data['displayMode'];
 }
Example #2
0
 /**
  * Determines whether there exist at least one instance of a certain object type in the database.
  *
  * @param string $objectType Name of treated entity type.
  *
  * @return boolean Whether at least one instance exists or not.
  */
 protected function hasExistingInstances($objectType)
 {
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     if (!in_array($objectType, $controllerHelper->getObjectTypes('util', array('util' => 'model', 'action' => 'hasExistingInstances')))) {
         throw new \Exception('Error! Invalid object type received.');
     }
     $entityClass = 'MUVideo_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     return $repository->selectCount() > 0;
 }
Example #3
0
 /**
  * This method provides a item detail view.
  *
  * @param string  $tpl          Name of alternative template (to be used instead of the default template).
  * @param boolean $raw          Optional way to display a template instead of fetching it (required for standalone output).
  *
  * @return mixed Output.
  */
 public function display()
 {
     $legacyControllerType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING);
     System::queryStringSetVar('type', $legacyControllerType);
     $this->request->query->set('type', $legacyControllerType);
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // parameter specifying which type of objects we are treating
     $objectType = 'movie';
     $utilArgs = array('controller' => 'movie', 'action' => 'display');
     $permLevel = $legacyControllerType == 'admin' ? ACCESS_ADMIN : ACCESS_READ;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission());
     $entityClass = $this->name . '_Entity_' . ucwords($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $repository->setControllerArguments(array());
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to view
     $idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $objectType, $idFields);
     $hasIdentifier = $controllerHelper->isValidIdentifier($idValues);
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $selectionArgs = array('ot' => $objectType, 'id' => $idValues);
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', $selectionArgs);
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     unset($idValues);
     $entity->initWorkflow();
     // build ModUrl instance for display hooks; also create identifier for permission check
     $currentUrlArgs = $entity->createUrlArgs();
     $instanceId = $entity->createCompositeIdentifier();
     $currentUrlArgs['id'] = $instanceId;
     // TODO remove this
     $currentUrlObject = new Zikula_ModUrl($this->name, 'movie', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs);
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', $instanceId . '::', $permLevel), LogUtil::getErrorMsgPermission());
     $viewHelper = new MUVideo_Util_View($this->serviceManager);
     $templateFile = $viewHelper->getViewTemplate($this->view, $objectType, 'display', array());
     // set cache id
     $component = $this->name . ':' . ucwords($objectType) . ':';
     $instance = $instanceId . '::';
     $accessLevel = ACCESS_READ;
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) {
         $accessLevel = ACCESS_COMMENT;
     }
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) {
         $accessLevel = ACCESS_EDIT;
     }
     $this->view->setCacheId($objectType . '|' . $instanceId . '|a' . $accessLevel);
     // assign output data to view object.
     $this->view->assign($objectType, $entity)->assign('currentUrlObject', $currentUrlObject)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // initialize
     $youtubeId = '';
     // we get the id from the url
     $youtubeId = explode('=', $entity['urlOfYoutube']);
     // assign to template
     $this->view->assign('youtubeId', $youtubeId[1]);
     // fetch and return the appropriate template
     return $viewHelper->processTemplate($this->view, $objectType, 'display', array(), $templateFile);
 }
Example #4
0
 /**
  * Command event handler.
  *
  * This event handler is called when a command is issued by the user.
  *
  * @param Zikula_Form_View $view The form view instance.
  * @param array            $args Additional arguments.
  *
  * @return mixed Redirect or false on errors.
  */
 public function handleCommand(Zikula_Form_View $view, &$args)
 {
     // get collection id
     $collectionId = $this->request->query->filter('collectionId', 0, FILTER_SANITIZE_NUMBER_INT);
     if ($collectionId == 0) {
         return LogUtil::registerError(__('Sorry. There is no valid collection id!'));
     }
     // get channel id from form
     $channelId = $this->request->request->filter('channelId', '', FILTER_SANITIZE_STRING);
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     return $controllerHelper->getYoutubeVideos($channelId[0], $collectionId);
     // return $this->view->redirect($this->getRedirectUrl($args));
 }
Example #5
0
 /**
  * This method provides a handling of edit requests.
  *
  * @param string  $ot           Treated object type.
  * @param string  $tpl          Name of alternative template (to be used instead of the default template).
  * @param boolean $raw          Optional way to display a template instead of fetching it (required for standalone output).
  *
  * @return mixed Output.
  */
 public function getVideos()
 {
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // parameter specifying which type of objects we are treating
     $objectType = $this->request->query->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'getVideos');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs);
     }
     $permLevel = ACCESS_EDIT;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission());
     // redirect to entity controller
     System::queryStringSetVar('lct', 'user');
     $this->request->query->set('lct', 'user');
     return ModUtil::func($this->name, $objectType, 'getVideos', array('lct' => 'user'));
 }
Example #6
0
 /**
  * Returns available admin panel links.
  *
  * @return array Array of admin links.
  */
 public function getLinks()
 {
     $links = array();
     if (SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_READ)) {
         $links[] = array('url' => ModUtil::url($this->name, 'user', 'main'), 'text' => $this->__('Frontend'), 'title' => $this->__('Switch to user area.'), 'class' => 'z-icon-es-home');
     }
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'admin', 'action' => 'getLinks');
     $allowedObjectTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $currentType = $this->request->query->filter('type', 'collection', FILTER_SANITIZE_STRING);
     $currentLegacyType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING);
     $permLevel = in_array('admin', array($currentType, $currentLegacyType)) ? ACCESS_ADMIN : ACCESS_READ;
     if (in_array('collection', $allowedObjectTypes) && SecurityUtil::checkPermission($this->name . ':Collection:', '::', $permLevel)) {
         $links[] = array('url' => ModUtil::url($this->name, 'admin', 'view', array('ot' => 'collection')), 'text' => $this->__('Collections'), 'title' => $this->__('Collection list'));
     }
     if (in_array('movie', $allowedObjectTypes) && SecurityUtil::checkPermission($this->name . ':Movie:', '::', $permLevel)) {
         $links[] = array('url' => ModUtil::url($this->name, 'admin', 'view', array('ot' => 'movie')), 'text' => $this->__('Movies'), 'title' => $this->__('Movie list'));
     }
     if (SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_ADMIN)) {
         $links[] = array('url' => ModUtil::url($this->name, 'admin', 'config'), 'text' => $this->__('Configuration'), 'title' => $this->__('Manage settings for this application'));
     }
     return $links;
 }
Example #7
0
 /**
  * This method takes care of the application configuration.
  *
  * @return string Output
  */
 public function getVideos()
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUVideo::', '::', ACCESS_EDIT));
     // DEBUG: permission check aspect ends
     // parameter specifying which type of objects we are treating
     $objectType = isset($args['ot']) && !empty($args['ot']) ? $args['ot'] : $this->request->getGet()->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'getVideos');
     if (!in_array($objectType, MUVideo_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUVideo_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     // create new Form reference
     $view = FormUtil::newForm($this->name, $this);
     // build form handler class name
     $handlerClass = 'MUVideo_Form_Handler_' . ucfirst($objectType) . '_GetVideos';
     // determine the output template
     $viewHelper = new MUVideo_Util_View($this->serviceManager);
     $template = $viewHelper->getViewTemplate($this->view, $objectType, 'getVideos', array());
     // execute form using supplied template and page event handler
     return $view->execute($template, new $handlerClass());
 }
Example #8
0
 /**
  * Deletes an existing upload file.
  * For images the thumbnails are removed, too.
  *
  * @param string  $objectType Currently treated entity type.
  * @param string  $objectData Object data array.
  * @param string  $fieldName  Name of upload field.
  * @param integer $objectId   Primary identifier of the given object.
  *
  * @return mixed Array with updated object data on success, else false.
  */
 public function deleteUploadFile($objectType, $objectData, $fieldName, $objectId)
 {
     if (!in_array($objectType, $this->allowedObjectTypes)) {
         return false;
     }
     if (empty($objectData[$fieldName])) {
         return $objectData;
     }
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     // determine file system information
     try {
         $basePath = $controllerHelper->getFileBaseFolder($objectType, $fieldName);
     } catch (\Exception $e) {
         LogUtil::registerError($e->getMessage());
     }
     $fileName = $objectData[$fieldName];
     // path to original file
     $filePath = $basePath . $fileName;
     // check whether we have to consider thumbnails, too
     $fileExtension = FileUtil::getExtension($fileName, false);
     if (in_array($fileExtension, $this->imageFileTypes) && $fileExtension != 'swf') {
         // remove thumbnail images as well
         $manager = ServiceUtil::getManager()->getService('systemplugin.imagine.manager');
         $manager->setModule('MUVideo');
         $fullObjectId = $objectType . '-' . $objectId;
         $manager->removeImageThumbs($filePath, $fullObjectId);
     }
     // remove original file
     if (!unlink($filePath)) {
         return false;
     }
     $objectData[$fieldName] = '';
     $objectData[$fieldName . 'Meta'] = array();
     return $objectData;
 }
Example #9
0
 /**
  * Install the MUVideo application.
  *
  * @return boolean True on success, or false.
  */
 public function install()
 {
     // Check if upload directories exist and if needed create them
     try {
         $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
         $controllerHelper->checkAndCreateAllUploadFolders();
     } catch (\Exception $e) {
         return LogUtil::registerError($e->getMessage());
     }
     // create all tables from according entity definitions
     try {
         DoctrineHelper::createSchema($this->entityManager, $this->listEntityClasses());
     } catch (\Exception $e) {
         if (System::isDevelopmentMode()) {
             return LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage());
         }
         $returnMessage = $this->__f('An error was encountered while creating the tables for the %s extension.', array($this->name));
         if (!System::isDevelopmentMode()) {
             $returnMessage .= ' ' . $this->__('Please enable the development mode by editing the /config/config.php file in order to reveal the error details.');
         }
         return LogUtil::registerError($returnMessage);
     }
     // set up all our vars with initial values
     $this->setVar('pageSize', 10);
     $this->setVar('maxSizeOfMovie', 1024000000);
     $this->setVar('maxSizeOfPoster', 102400);
     $this->setVar('standardPoster', '/images/poster.png');
     $categoryRegistryIdsPerEntity = array();
     // add default entry for category registry (property named Main)
     include_once 'modules/MUVideo/lib/MUVideo/Api/Base/Category.php';
     include_once 'modules/MUVideo/lib/MUVideo/Api/Category.php';
     $categoryApi = new MUVideo_Api_Category($this->serviceManager);
     $categoryGlobal = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Global');
     $registryData = array();
     $registryData['modname'] = $this->name;
     $registryData['table'] = 'Collection';
     $registryData['property'] = $categoryApi->getPrimaryProperty(array('ot' => 'Collection'));
     $registryData['category_id'] = $categoryGlobal['id'];
     $registryData['id'] = false;
     if (!DBUtil::insertObject($registryData, 'categories_registry')) {
         LogUtil::registerError($this->__f('Error! Could not create a category registry for the %s entity.', array('collection')));
     }
     $categoryRegistryIdsPerEntity['collection'] = $registryData['id'];
     $registryData = array();
     $registryData['modname'] = $this->name;
     $registryData['table'] = 'Movie';
     $registryData['property'] = $categoryApi->getPrimaryProperty(array('ot' => 'Movie'));
     $registryData['category_id'] = $categoryGlobal['id'];
     $registryData['id'] = false;
     if (!DBUtil::insertObject($registryData, 'categories_registry')) {
         LogUtil::registerError($this->__f('Error! Could not create a category registry for the %s entity.', array('movie')));
     }
     $categoryRegistryIdsPerEntity['movie'] = $registryData['id'];
     // create the default data
     $this->createDefaultData($categoryRegistryIdsPerEntity);
     // register persistent event handlers
     $this->registerPersistentEventHandlers();
     // register hook subscriber bundles
     HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles());
     // initialisation successful
     return true;
 }
Example #10
0
 /**
  * Searches for entities for auto completion usage.
  *
  * @param string $ot       Treated object type.
  * @param string $fragment The fragment of the entered item name.
  * @param string $exclude  Comma separated list with ids of other items (to be excluded from search).
  *
  * @return Zikula_Response_Ajax_Plain
  */
 public function getItemListAutoCompletion()
 {
     if (!SecurityUtil::checkPermission($this->name . '::Ajax', '::', ACCESS_EDIT)) {
         return true;
     }
     $objectType = 'collection';
     if ($this->request->isPost() && $this->request->request->has('ot')) {
         $objectType = $this->request->request->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     } elseif ($this->request->isGet() && $this->request->query->has('ot')) {
         $objectType = $this->request->query->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     }
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('controller' => 'ajax', 'action' => 'getItemListAutoCompletion');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs);
     }
     $entityClass = 'MUVideo_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     $fragment = '';
     $exclude = '';
     if ($this->request->isPost() && $this->request->request->has('fragment')) {
         $fragment = $this->request->request->get('fragment', '');
         $exclude = $this->request->request->get('exclude', '');
     } elseif ($this->request->isGet() && $this->request->query->has('fragment')) {
         $fragment = $this->request->query->get('fragment', '');
         $exclude = $this->request->query->get('exclude', '');
     }
     $exclude = !empty($exclude) ? array($exclude) : array();
     // parameter for used sorting field
     $sort = $this->request->query->get('sort', '');
     if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) {
         $sort = $repository->getDefaultSortingField();
     }
     $sortParam = $sort . ' asc';
     $currentPage = 1;
     $resultsPerPage = 20;
     // get objects from database
     list($entities, $objectCount) = $repository->selectSearch($fragment, $exclude, $sortParam, $currentPage, $resultsPerPage);
     $out = '<ul>';
     if ((is_array($entities) || is_object($entities)) && count($entities) > 0) {
         $descriptionFieldName = $repository->getDescriptionFieldName();
         $previewFieldName = $repository->getPreviewFieldName();
         if (!empty($previewFieldName)) {
             $imageHelper = new MUVideo_Util_Image($this->serviceManager);
             $imagineManager = $imageHelper->getManager($objectType, $previewFieldName, 'controllerAction', $utilArgs);
         }
         foreach ($entities as $item) {
             // class="informal" --> show in dropdown, but do nots copy in the input field after selection
             $itemTitle = $item->getTitleFromDisplayPattern();
             $itemTitleStripped = str_replace('"', '', $itemTitle);
             $itemDescription = isset($item[$descriptionFieldName]) && !empty($item[$descriptionFieldName]) ? $item[$descriptionFieldName] : '';
             //$this->__('No description yet.');
             $itemId = $item->createCompositeIdentifier();
             $out .= '<li id="' . $itemId . '" title="' . $itemTitleStripped . '">';
             $out .= '<div class="itemtitle">' . $itemTitle . '</div>';
             if (!empty($itemDescription)) {
                 $out .= '<div class="itemdesc informal">' . substr($itemDescription, 0, 50) . '&hellip;</div>';
             }
             // check for preview image
             if (!empty($previewFieldName) && !empty($item[$previewFieldName]) && isset($item[$previewFieldName . 'FullPath'])) {
                 $fullObjectId = $objectType . '-' . $itemId;
                 $thumbImagePath = $imagineManager->getThumb($item[$previewFieldName], $fullObjectId);
                 $preview = '<img src="' . $thumbImagePath . '" width="50" height="50" alt="' . $itemTitleStripped . '" />';
                 $out .= '<div id="itemPreview' . $itemId . '" class="itempreview informal">' . $preview . '</div>';
             }
             $out .= '</li>';
         }
     }
     $out .= '</ul>';
     // return response
     return new Zikula_Response_Ajax_Plain($out);
 }
Example #11
0
 /**
  * Post-Process the data after the entity has been constructed by the entity manager.
  * The event happens after the entity has been loaded from database or after a refresh call.
  *
  * Restrictions:
  *     - no access to entity manager or unit of work apis
  *     - no access to associations (not initialised yet)
  *
  * @see MUVideo_Entity_Movie::postLoadCallback()
  * @return boolean true if completed successfully else false.
  */
 protected function performPostLoadCallback()
 {
     // echo 'loaded a record ...';
     $currentFunc = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING);
     $usesCsvOutput = FormUtil::getPassedValue('usecsvext', false, 'GETPOST', FILTER_VALIDATE_BOOLEAN);
     // initialise the upload handler
     $uploadManager = new MUVideo_UploadHandler();
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     $this['id'] = (int) (isset($this['id']) && !empty($this['id']) ? DataUtil::formatForDisplay($this['id']) : 0);
     $this->formatTextualField('workflowState', $currentFunc, $usesCsvOutput, true);
     $this->formatTextualField('title', $currentFunc, $usesCsvOutput);
     $this->formatTextualField('description', $currentFunc, $usesCsvOutput);
     if (!empty($this['uploadOfMovie'])) {
         try {
             $basePath = $controllerHelper->getFileBaseFolder('movie', 'uploadOfMovie');
         } catch (\Exception $e) {
             return LogUtil::registerError($e->getMessage());
         }
         $fullPath = $basePath . $this['uploadOfMovie'];
         $this['uploadOfMovieFullPath'] = $fullPath;
         $this['uploadOfMovieFullPathURL'] = System::getBaseUrl() . $fullPath;
         // just some backwards compatibility stuff
         /*if (!isset($this['uploadOfMovieMeta']) || !is_array($this['uploadOfMovieMeta']) || !count($this['uploadOfMovieMeta'])) {
               // assign new meta data
               $this['uploadOfMovieMeta'] = $uploadManager->readMetaDataForFile($this['uploadOfMovie'], $fullPath);
           }*/
     }
     $this['urlOfYoutube'] = isset($this['urlOfYoutube']) && !empty($this['urlOfYoutube']) ? DataUtil::formatForDisplay($this['urlOfYoutube']) : '';
     if (!empty($this['poster'])) {
         try {
             $basePath = $controllerHelper->getFileBaseFolder('movie', 'poster');
         } catch (\Exception $e) {
             return LogUtil::registerError($e->getMessage());
         }
         $fullPath = $basePath . $this['poster'];
         $this['posterFullPath'] = $fullPath;
         $this['posterFullPathURL'] = System::getBaseUrl() . $fullPath;
         // just some backwards compatibility stuff
         /*if (!isset($this['posterMeta']) || !is_array($this['posterMeta']) || !count($this['posterMeta'])) {
               // assign new meta data
               $this['posterMeta'] = $uploadManager->readMetaDataForFile($this['poster'], $fullPath);
           }*/
     }
     $this['widthOfMovie'] = (int) (isset($this['widthOfMovie']) && !empty($this['widthOfMovie']) ? DataUtil::formatForDisplay($this['widthOfMovie']) : 0);
     $this['heightOfMovie'] = (int) (isset($this['heightOfMovie']) && !empty($this['heightOfMovie']) ? DataUtil::formatForDisplay($this['heightOfMovie']) : 0);
     $this->prepareItemActions();
     return true;
 }
Example #12
0
 /**
  * Popup selector for Scribite plugins.
  * Finds items of a certain object type.
  *
  * @param string $objectType The object type.
  * @param string $editor     Name of used Scribite editor.
  * @param string $sort       Sorting field.
  * @param string $sortdir    Sorting direction.
  * @param int    $pos        Current pager position.
  * @param int    $num        Amount of entries to display.
  *
  * @return output The external item finder page
  */
 public function finder()
 {
     PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet('MUVideo'));
     $getData = $this->request->query;
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $objectType = $getData->filter('objectType', 'collection', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'external', 'action' => 'finder');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controller', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerType', $utilArgs);
     }
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUVideo:' . ucfirst($objectType) . ':', '::', ACCESS_COMMENT), LogUtil::getErrorMsgPermission());
     $entityClass = 'MUVideo_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $repository->setControllerArguments(array());
     $editor = $getData->filter('editor', '', FILTER_SANITIZE_STRING);
     if (empty($editor) || !in_array($editor, array('xinha', 'tinymce', 'ckeditor'))) {
         return $this->__('Error: Invalid editor context given for external controller action.');
     }
     // fetch selected categories to reselect them in the output
     // the actual filtering is done inside the repository class
     $categoryIds = ModUtil::apiFunc('MUVideo', 'category', 'retrieveCategoriesFromRequest', array('ot' => $objectType, 'source' => 'GET'));
     $sort = $getData->filter('sort', '', FILTER_SANITIZE_STRING);
     if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) {
         $sort = $repository->getDefaultSortingField();
     }
     $sortdir = $getData->filter('sortdir', '', FILTER_SANITIZE_STRING);
     $sdir = strtolower($sortdir);
     if ($sdir != 'asc' && $sdir != 'desc') {
         $sdir = 'asc';
     }
     $sortParam = $sort . ' ' . $sdir;
     // the current offset which is used to calculate the pagination
     $currentPage = (int) $getData->filter('pos', 1, FILTER_VALIDATE_INT);
     // the number of items displayed on a page for pagination
     $resultsPerPage = (int) $getData->filter('num', 0, FILTER_VALIDATE_INT);
     if ($resultsPerPage == 0) {
         $resultsPerPage = $this->getVar('pageSize', 20);
     }
     $where = '';
     list($entities, $objectCount) = $repository->selectWherePaginated($where, $sortParam, $currentPage, $resultsPerPage);
     foreach ($entities as $k => $entity) {
         $entity->initWorkflow();
     }
     $view = Zikula_View::getInstance('MUVideo', false);
     $view->assign('editorName', $editor)->assign('objectType', $objectType)->assign('items', $entities)->assign('sort', $sort)->assign('sortdir', $sdir)->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage));
     // assign category properties
     $properties = null;
     if (in_array($objectType, $this->categorisableObjectTypes)) {
         $properties = ModUtil::apiFunc('MUVideo', 'category', 'getAllProperties', array('ot' => $objectType));
     }
     $view->assign('properties', $properties)->assign('catIds', $categoryIds);
     return $view->display('external/' . $objectType . '/find.tpl');
 }
Example #13
0
 /**
  * Initialize form handler.
  *
  * This method takes care of all necessary initialisation of our data and form states.
  *
  * @param Zikula_Form_View $view The form view instance.
  *
  * @return boolean False in case of initialization errors, otherwise true.
  */
 public function initialize(Zikula_Form_View $view)
 {
     $this->inlineUsage = UserUtil::getTheme() == 'Printer' ? true : false;
     $this->idPrefix = $this->request->query->filter('idp', '', FILTER_SANITIZE_STRING);
     // initialise redirect goal
     $this->returnTo = $this->request->query->filter('returnTo', null, FILTER_SANITIZE_STRING);
     // store current uri for repeated creations
     $this->repeatReturnUrl = System::getCurrentURI();
     $this->permissionComponent = $this->name . ':' . $this->objectTypeCapital . ':';
     $entityClass = $this->name . '_Entity_' . ucfirst($this->objectType);
     $this->idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $this->objectType));
     // retrieve identifier of the object we wish to view
     $controllerHelper = new MUVideo_Util_Controller($this->view->getServiceManager());
     $this->idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $this->objectType, $this->idFields);
     $hasIdentifier = $controllerHelper->isValidIdentifier($this->idValues);
     $entity = null;
     $this->mode = $hasIdentifier ? 'edit' : 'create';
     if ($this->mode == 'edit') {
         if (!SecurityUtil::checkPermission($this->permissionComponent, $this->createCompositeIdentifier() . '::', ACCESS_EDIT)) {
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForEdit();
         if (!is_object($entity)) {
             return false;
         }
         if ($this->hasPageLockSupport === true && ModUtil::available('PageLock')) {
             // try to guarantee that only one person at a time can be editing this entity
             ModUtil::apiFunc('PageLock', 'user', 'pageLock', array('lockName' => $this->name . $this->objectTypeCapital . $this->createCompositeIdentifier(), 'returnUrl' => $this->getRedirectUrl(null)));
         }
     } else {
         if (!SecurityUtil::checkPermission($this->permissionComponent, '::', ACCESS_EDIT)) {
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForCreation();
     }
     $this->view->assign('mode', $this->mode)->assign('inlineUsage', $this->inlineUsage);
     // save entity reference for later reuse
     $this->entityRef = $entity;
     if ($this->hasCategories === true) {
         $this->initCategoriesForEdit();
     }
     $workflowHelper = new MUVideo_Util_Workflow($this->view->getServiceManager());
     $actions = $workflowHelper->getActionsForObject($entity);
     if ($actions === false || !is_array($actions)) {
         return LogUtil::registerError($this->__('Error! Could not determine workflow actions.'));
     }
     // assign list of allowed actions to the view for further processing
     $this->view->assign('actions', $actions);
     // everything okay, no initialization errors occured
     return true;
 }
Example #14
0
 /**
  * Clear cache for given item. Can be called from other modules to clear an item cache.
  *
  * @param $args['ot']   the treated object type
  * @param $args['item'] the actual object
  */
 public function clearItemCache(array $args = array())
 {
     if (!isset($args['ot']) || !isset($args['item'])) {
         return;
     }
     $objectType = $args['ot'];
     $item = $args['item'];
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'cache', 'action' => 'clearItemCache');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) {
         return;
     }
     if ($item && !is_array($item) && !is_object($item)) {
         $item = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $item, 'useJoins' => false, 'slimMode' => true));
     }
     if (!$item) {
         return;
     }
     $instanceId = $item->createCompositeIdentifier();
     // Clear View_cache
     $cacheIds = array();
     $cacheIds[] = 'user_main';
     switch ($objectType) {
         case 'collection':
             $cacheIds[] = 'collection_main';
             $cacheIds[] = $objectType . '_view';
             $cacheIds[] = $objectType . '_display|' . $instanceId;
             break;
         case 'movie':
             $cacheIds[] = 'movie_main';
             $cacheIds[] = $objectType . '_view';
             $cacheIds[] = $objectType . '_display|' . $instanceId;
             break;
     }
     $view = Zikula_View::getInstance('MUVideo');
     foreach ($cacheIds as $cacheId) {
         $view->clear_cache(null, $cacheId);
     }
     // Clear Theme_cache
     $cacheIds = array();
     $cacheIds[] = 'homepage';
     // for homepage (can be assigned in the Settings module)
     $cacheIds[] = 'MUVideo/user/main';
     // main function
     switch ($objectType) {
         case 'collection':
             $cacheIdPrefix = 'MUVideo/' . $objectType . '/';
             $cacheIds[] = $cacheIdPrefix . 'main';
             // main function
             $cacheIds[] = $cacheIdPrefix . 'view/';
             // view function (list views)
             $cacheIds[] = $cacheIdPrefix . 'display/' . $instanceId;
             // display function (detail views)
             break;
         case 'movie':
             $cacheIdPrefix = 'MUVideo/' . $objectType . '/';
             $cacheIds[] = $cacheIdPrefix . 'main';
             // main function
             $cacheIds[] = $cacheIdPrefix . 'view/';
             // view function (list views)
             $cacheIds[] = $cacheIdPrefix . 'display/' . $instanceId;
             // display function (detail views)
             break;
     }
     $theme = Zikula_View_Theme::getInstance();
     $theme->clear_cacheid_allthemes($cacheIds);
 }
Example #15
0
 /**
  * Update block settings.
  *
  * @param array $blockinfo the blockinfo structure
  *
  * @return array the modified blockinfo structure.
  */
 public function update($blockinfo)
 {
     // Get current content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $vars['objectType'] = $this->request->request->filter('objecttype', 'collection', FILTER_SANITIZE_STRING);
     $vars['sorting'] = $this->request->request->filter('sorting', 'default', FILTER_SANITIZE_STRING);
     $vars['amount'] = (int) $this->request->request->filter('amount', 5, FILTER_VALIDATE_INT);
     $vars['template'] = $this->request->request->get('template', '');
     $vars['customTemplate'] = $this->request->request->get('customtemplate', '');
     $vars['filter'] = $this->request->request->get('filter', '');
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     if (!in_array($vars['objectType'], $controllerHelper->getObjectTypes('block'))) {
         $vars['objectType'] = $controllerHelper->getDefaultObjectType('block');
     }
     $primaryRegistry = ModUtil::apiFunc('MUVideo', 'category', 'getPrimaryProperty', array('ot' => $vars['objectType']));
     $vars['catIds'] = array($primaryRegistry => array());
     if (in_array($vars['objectType'], $this->categorisableObjectTypes)) {
         $vars['catIds'] = ModUtil::apiFunc('MUVideo', 'category', 'retrieveCategoriesFromRequest', array('ot' => $vars['objectType']));
     }
     // write back the new contents
     $blockinfo['content'] = BlockUtil::varsToContent($vars);
     // clear the block cache
     $this->view->clear_cache('block/itemlist_display.tpl');
     $this->view->clear_cache('block/itemlist_' . ucfirst($vars['objectType']) . '_display.tpl');
     $this->view->clear_cache('block/itemlist_display_description.tpl');
     $this->view->clear_cache('block/itemlist_' . ucfirst($vars['objectType']) . '_display_description.tpl');
     return $blockinfo;
 }
Example #16
0
 /**
  * Forms custom url string.
  *
  * @param array $args List of arguments.
  *
  * @return string custom url string
  */
 public function encodeurl(array $args = array())
 {
     // check if we have the required input
     if (!isset($args['modname']) || !isset($args['func'])) {
         throw new \InvalidArgumentException(__('Invalid arguments array received.'));
     }
     // set default values
     if (!isset($args['type'])) {
         $args['type'] = 'user';
     }
     if (!isset($args['args'])) {
         $args['args'] = array();
     }
     // return if function url scheme is not being customised
     $customFuncs = array('view', 'display');
     if (!in_array($args['func'], $customFuncs)) {
         return false;
     }
     // initialise url routing rules
     $routerFacade = new MUVideo_RouterFacade();
     // get router itself for convenience
     $router = $routerFacade->getRouter();
     // initialise object type
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('controller' => 'user', 'action' => 'encodeurl');
     $allowedObjectTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $objectType = isset($args['args']['ot']) && in_array($args['args']['ot'], $allowedObjectTypes) ? $args['args']['ot'] : $controllerHelper->getDefaultObjectType('api', $utilArgs);
     // initialise group folder
     $groupFolder = $routerFacade->getGroupingFolderFromObjectType($objectType, $args['func'], $args['args']);
     // start pre processing
     // convert object type to group folder
     $args['args']['ot'] = $groupFolder;
     // handle special templates
     $displayDefaultEnding = System::getVar('shorturlsext', 'html');
     $endingPrefix = $args['func'] == 'view' ? '.' : '';
     foreach (array('csv', 'rss', 'atom', 'xml', 'pdf', 'json', 'kml') as $ending) {
         if (!isset($args['args']['use' . $ending . 'ext'])) {
             continue;
         }
         if ($args['args']['use' . $ending . 'ext'] == '1') {
             $args['args'][$args['func'] . 'ending'] = $endingPrefix . $ending;
         }
         unset($args['args']['use' . $ending . 'ext']);
     }
     // fallback to default templates
     if (!isset($args['args'][$args['func'] . 'ending'])) {
         if ($args['func'] == 'view') {
             $args['args'][$args['func'] . 'ending'] = '';
             //'/';
         } else {
             if ($args['func'] == 'display') {
                 $args['args'][$args['func'] . 'ending'] = $displayDefaultEnding;
             }
         }
     }
     if ($args['func'] == 'view') {
         // TODO filter views (e.g. /orders/customer/mr-smith.csv)
         /**
         $filterEntities = array('customer', 'region', 'federalstate', 'country');
         foreach ($filterEntities as $filterEntity) {
             $filterField = $filterEntity . 'id';
             if (!isset($args['args'][$filterField]) || !$args['args'][$filterField]) {
                 continue;
             }
             $filterId = $args['args'][$filterField];
             unset($args['args'][$filterField]);
             
             $filterGroupFolder = $routerFacade->getGroupingFolderFromObjectType($filterEntity, 'display', $args['args']);
             $filterSlug = $routerFacade->getFormattedSlug($filterEntity, 'display', $args['args'], $filterId);
             $result .= $filterGroupFolder . '/' . $filterSlug .'/';
             break;
         }
         */
     } elseif ($args['func'] == 'display') {
         // determine given id
         $id = 0;
         foreach (array('id', strtolower($objectType) . 'id', 'objectid') as $idFieldName) {
             if (isset($args['args'][$idFieldName])) {
                 $id = $args['args'][$idFieldName];
                 unset($args['args'][$idFieldName]);
             }
         }
         // check if we have a valid slug given
         if (isset($args['args']['slug']) && (!$args['args']['slug'] || $args['args']['slug'] == $id)) {
             unset($args['args']['slug']);
         }
         // try to determine missing slug
         if (!isset($args['args']['slug'])) {
             $slug = '';
             if ($id > 0) {
                 $slug = $routerFacade->getFormattedSlug($objectType, $args['func'], $args['args'], $id);
             }
             if (!empty($slug) && $slug != $id) {
                 // add slug expression
                 $args['args']['slug'] = $slug;
             }
         }
         // check if we have one now
         if (!isset($args['args']['slug'])) {
             // readd id as fallback
             $args['args']['id'] = $id;
         }
     }
     // add func as first argument
     $routerArgs = array_merge(array('func' => $args['func']), $args['args']);
     // now create url based on params
     $result = $router->generate(null, $routerArgs);
     // post processing
     if ($args['func'] == 'view' && !empty($args['args']['viewending']) || $args['func'] == 'display') {
         // check if url ends with a trailing slash
         if (substr($result, -1) == '/') {
             // remove the trailing slash
             $result = substr($result, 0, strlen($result) - 1);
         }
     }
     // enforce url name of the module, but do only 1 replacement to avoid changing other params
     $modInfo = ModUtil::getInfoFromName('MUVideo');
     $result = preg_replace('/' . $modInfo['name'] . '/', $modInfo['url'], $result, 1);
     return $result;
 }
Example #17
0
 /**
  * Executes the actual search process.
  *
  * @param array $args List of arguments.
  *
  * @return boolean
  *
  * @throws RuntimeException Thrown if search results can not be saved
  */
 public function search(array $args = array())
 {
     if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_READ)) {
         return '';
     }
     // ensure that database information of Search module is loaded
     ModUtil::dbInfoLoad('Search');
     // save session id as it is used when inserting search results below
     $sessionId = session_id();
     // retrieve list of activated object types
     $searchTypes = isset($args['objectTypes']) ? (array) $args['objectTypes'] : (array) FormUtil::getPassedValue('mUVideoSearchTypes', array(), 'GETPOST');
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'search', 'action' => 'search');
     $allowedTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $entityManager = ServiceUtil::getService('doctrine.entitymanager');
     $currentPage = 1;
     $resultsPerPage = 50;
     foreach ($searchTypes as $objectType) {
         if (!in_array($objectType, $allowedTypes)) {
             continue;
         }
         $whereArray = array();
         $languageField = null;
         switch ($objectType) {
             case 'collection':
                 $whereArray[] = 'tbl.workflowState';
                 $whereArray[] = 'tbl.title';
                 $whereArray[] = 'tbl.description';
                 break;
             case 'movie':
                 $whereArray[] = 'tbl.workflowState';
                 $whereArray[] = 'tbl.title';
                 $whereArray[] = 'tbl.description';
                 $whereArray[] = 'tbl.uploadOfMovie';
                 $whereArray[] = 'tbl.urlOfYoutube';
                 $whereArray[] = 'tbl.poster';
                 break;
         }
         $where = Search_Api_User::construct_where($args, $whereArray, $languageField);
         $entityClass = $this->name . '_Entity_' . ucfirst($objectType);
         $repository = $entityManager->getRepository($entityClass);
         // get objects from database
         list($entities, $objectCount) = $repository->selectWherePaginated($where, '', $currentPage, $resultsPerPage, false);
         if ($objectCount == 0) {
             continue;
         }
         $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
         $descriptionField = $repository->getDescriptionFieldName();
         $entitiesWithDisplayAction = array('collection', 'movie');
         foreach ($entities as $entity) {
             $urlArgs = $entity->createUrlArgs();
             $hasDisplayAction = in_array($objectType, $entitiesWithDisplayAction);
             if ($hasDisplayAction) {
                 $urlArgs['type'] = $objectType;
                 // slug could exceed the maximum length of the 'extra' field, improved in 1.4.0
                 if (isset($urlArgs['slug'])) {
                     unset($urlArgs['slug']);
                 }
             }
             $instanceId = $entity->createCompositeIdentifier();
             // perform permission check
             if (!SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', $instanceId . '::', ACCESS_OVERVIEW)) {
                 continue;
             }
             $title = $entity->getTitleFromDisplayPattern();
             $description = !empty($descriptionField) ? $entity[$descriptionField] : '';
             $created = isset($entity['createdDate']) ? $entity['createdDate']->format('Y-m-d H:i:s') : '';
             $searchItemData = array('title' => $title, 'text' => $description, 'extra' => $hasDisplayAction ? serialize($urlArgs) : '', 'created' => $created, 'module' => $this->name, 'session' => $sessionId);
             if (!DBUtil::insertObject($searchItemData, 'search_result')) {
                 return LogUtil::registerError($this->__('Error! Could not save the search results.'));
             }
         }
     }
     return true;
 }
Example #18
0
 /**
  * This method provides a handling of simple delete requests.
  *
  * @param int     $id           Identifier of entity to be shown.
  * @param boolean $confirmation Confirm the deletion, else a confirmation page is displayed.
  * @param string  $tpl          Name of alternative template (to be used instead of the default template).
  * @param boolean $raw          Optional way to display a template instead of fetching it (required for standalone output).
  *
  * @return mixed Output.
  */
 public function delete()
 {
     $legacyControllerType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING);
     System::queryStringSetVar('type', $legacyControllerType);
     $this->request->query->set('type', $legacyControllerType);
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // parameter specifying which type of objects we are treating
     $objectType = 'movie';
     $utilArgs = array('controller' => 'movie', 'action' => 'delete');
     $permLevel = $legacyControllerType == 'admin' ? ACCESS_ADMIN : ACCESS_DELETE;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission());
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to delete
     $idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $objectType, $idFields);
     $hasIdentifier = $controllerHelper->isValidIdentifier($idValues);
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $selectionArgs = array('ot' => $objectType, 'id' => $idValues);
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', $selectionArgs);
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     $entity->initWorkflow();
     // determine available workflow actions
     $workflowHelper = new MUVideo_Util_Workflow($this->serviceManager);
     $actions = $workflowHelper->getActionsForObject($entity);
     if ($actions === false || !is_array($actions)) {
         return LogUtil::registerError($this->__('Error! Could not determine workflow actions.'));
     }
     // check whether deletion is allowed
     $deleteActionId = 'delete';
     $deleteAllowed = false;
     foreach ($actions as $actionId => $action) {
         if ($actionId != $deleteActionId) {
             continue;
         }
         $deleteAllowed = true;
         break;
     }
     if (!$deleteAllowed) {
         return LogUtil::registerError($this->__('Error! It is not allowed to delete this movie.'));
     }
     $confirmation = (bool) $this->request->request->filter('confirmation', false, FILTER_VALIDATE_BOOLEAN);
     if ($confirmation && $deleteAllowed) {
         $this->checkCsrfToken();
         $hookAreaPrefix = $entity->getHookAreaPrefix();
         $hookType = 'validate_delete';
         // Let any hooks perform additional validation actions
         $hook = new Zikula_ValidationHook($hookAreaPrefix . '.' . $hookType, new Zikula_Hook_ValidationProviders());
         $validators = $this->notifyHooks($hook)->getValidators();
         if (!$validators->hasErrors()) {
             // execute the workflow action
             $success = $workflowHelper->executeAction($entity, $deleteActionId);
             if ($success) {
                 $this->registerStatus($this->__('Done! Item deleted.'));
             }
             // Let any hooks know that we have created, updated or deleted the movie
             $hookType = 'process_delete';
             $hook = new Zikula_ProcessHook($hookAreaPrefix . '.' . $hookType, $entity->createCompositeIdentifier());
             $this->notifyHooks($hook);
             // The movie was deleted, so we clear all cached pages this item.
             $cacheArgs = array('ot' => $objectType, 'item' => $entity);
             ModUtil::apiFunc($this->name, 'cache', 'clearItemCache', $cacheArgs);
             if ($legacyControllerType == 'admin') {
                 // redirect to the list of movies
                 $redirectUrl = ModUtil::url($this->name, 'movie', 'view', array('lct' => $legacyControllerType));
             } else {
                 // redirect to the list of movies
                 $redirectUrl = ModUtil::url($this->name, 'movie', 'view', array('lct' => $legacyControllerType));
             }
             return $this->redirect($redirectUrl);
         }
     }
     $entityClass = $this->name . '_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     // set caching id
     $this->view->setCaching(Zikula_View::CACHE_DISABLED);
     // assign the object we loaded above
     $this->view->assign($objectType, $entity)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // fetch and return the appropriate template
     $viewHelper = new MUVideo_Util_View($this->serviceManager);
     return $viewHelper->processTemplate($this->view, $objectType, 'delete', array());
 }
Example #19
0
 /**
  * Displays one item of a certain object type using a separate template for external usages.
  *
  * @param string $ot          The currently treated object type.
  * @param int    $id          Identifier of the entity to be shown.
  * @param string $source      Source of this call (contentType or scribite).
  * @param string $displayMode Display mode (link or embed).
  *
  * @return string Desired data output.
  */
 public function display(array $args = array())
 {
     $getData = $this->request->query;
     $getPostData = $this->request->request;
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $objectType = isset($args['objectType']) ? $args['objectType'] : $getData->filter('ot', '', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'external', 'action' => 'display');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controller', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerType', $utilArgs);
     }
     $id = isset($args['id']) ? $args['id'] : $getData->filter('id', null, FILTER_SANITIZE_STRING);
     $component = $this->name . ':' . ucwords($objectType) . ':';
     /* if (!SecurityUtil::checkPermission($component, $id . '::', ACCESS_READ)) {
            return '';
        }*/
     if (!SecurityUtil::checkPermission('MUVideoContentPlugin::', '::', ACCESS_READ)) {
         return '';
     }
     $source = isset($args['source']) ? $args['source'] : $getData->filter('source', '', FILTER_SANITIZE_STRING);
     if (!in_array($source, array('contentType', 'scribite'))) {
         $source = 'contentType';
     }
     $moviewidth = isset($args['moviewidth']) ? $args['moviewidth'] : $getPostData->filter('moviewidth', '', FILTER_SANITIZE_STRING);
     $movieheight = isset($args['movieheight']) ? $args['movieheight'] : $getPostData->filter('movieheight', '', FILTER_SANITIZE_STRING);
     $displayMode = isset($args['displayMode']) ? $args['displayMode'] : $getData->filter('displayMode', 'embed', FILTER_SANITIZE_STRING);
     if (!in_array($displayMode, array('link', 'embed'))) {
         $displayMode = 'embed';
     }
     $entityClass = 'MUVideo_Entity_' . ucwords($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $repository->setControllerArguments(array());
     $idFields = ModUtil::apiFunc('MUVideo', 'selection', 'getIdFields', array('ot' => $objectType));
     $idValues = array('id' => $id);
     $hasIdentifier = $controllerHelper->isValidIdentifier($idValues);
     if (!$hasIdentifier) {
         return $this->__('Error! Invalid identifier received.');
     }
     // assign object data fetched from the database
     $entity = $repository->selectById($idValues);
     if (!is_array($entity) && !is_object($entity) || !isset($entity[$idFields[0]])) {
         return $this->__('No such item.');
     }
     $entity->initWorkflow();
     $instance = $entity->createCompositeIdentifier() . '::';
     $this->view->setCaching(Zikula_View::CACHE_ENABLED);
     // set cache id
     $accessLevel = ACCESS_READ;
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) {
         $accessLevel = ACCESS_COMMENT;
     }
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) {
         $accessLevel = ACCESS_EDIT;
     }
     $this->view->setCacheId($objectType . '|' . $id . '|a' . $accessLevel);
     $this->view->assign('objectType', $objectType)->assign('source', $source)->assign($objectType, $entity)->assign('moviewidth', $moviewidth)->assign('movieheight', $movieheight)->assign('displayMode', $displayMode);
     // initialize
     $youtubeId = '';
     // we get the id from the url
     $youtubeId = explode('=', $entity['urlOfYoutube']);
     // assign to template
     $this->view->assign('youtubeId', $youtubeId[1]);
     return $this->view->fetch('external/' . $objectType . '/display.tpl');
 }
Example #20
0
 /**
  * Determines object type using controller util methods.
  *
  * @param string $args['ot'] The object type to retrieve (optional).
  * @param string $methodName Name of calling method.
  *
  * @return string the object type.
  */
 protected function determineObjectType(array $args = array(), $methodName = '')
 {
     $objectType = isset($args['ot']) ? $args['ot'] : '';
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'selection', 'action' => $methodName);
     if (!in_array($objectType, $controllerHelper->getObjectTypes('api', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('api', $utilArgs);
     }
     return $objectType;
 }
Example #21
0
 /**
  * Processes a template file using dompdf (LGPL).
  *
  * @param Zikula_View $view     Reference to view object.
  * @param string      $template Name of template to use.
  *
  * @return mixed Output.
  */
 protected function processPdf(Zikula_View $view, $template)
 {
     // first the content, to set page vars
     $output = $view->fetch($template);
     // make local images absolute
     $output = str_replace('img src="/', 'img src="' . System::serverGetVar('DOCUMENT_ROOT') . '/', $output);
     // see http://codeigniter.com/forums/viewthread/69388/P15/#561214
     //$output = utf8_decode($output);
     // then the surrounding
     $output = $view->fetch('include_pdfheader.tpl') . $output . '</body></html>';
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // create name of the pdf output file
     $fileTitle = $controllerHelper->formatPermalink(System::getVar('sitename')) . '-' . $controllerHelper->formatPermalink(PageUtil::getVar('title')) . '-' . date('Ymd') . '.pdf';
     // if ($_GET['dbg'] == 1) die($output);
     // instantiate pdf object
     $pdf = new \DOMPDF();
     // define page properties
     $pdf->set_paper('A4');
     // load html input data
     $pdf->load_html($output);
     // create the actual pdf file
     $pdf->render();
     // stream output to browser
     $pdf->stream($fileTitle);
     // prevent additional output by shutting down the system
     System::shutDown();
     return true;
 }
Example #22
0
 /**
  * Loads the data.
  *
  * @param array $data Data array with parameters.
  */
 public function loadData(&$data)
 {
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     $utilArgs = array('name' => 'list');
     if (!isset($data['objectType']) || !in_array($data['objectType'], $controllerHelper->getObjectTypes('contentType', $utilArgs))) {
         $data['objectType'] = $controllerHelper->getDefaultObjectType('contentType', $utilArgs);
     }
     $this->objectType = $data['objectType'];
     if (!isset($data['sorting'])) {
         $data['sorting'] = 'default';
     }
     if (!isset($data['amount'])) {
         $data['amount'] = 1;
     }
     if (!isset($data['template'])) {
         $data['template'] = 'itemlist_' . $this->objectType . '_display.tpl';
     }
     if (!isset($data['customTemplate'])) {
         $data['customTemplate'] = '';
     }
     if (!isset($data['filter'])) {
         $data['filter'] = '';
     }
     $this->sorting = $data['sorting'];
     $this->amount = $data['amount'];
     $this->template = $data['template'];
     $this->customTemplate = $data['customTemplate'];
     $this->filter = $data['filter'];
     $this->categorisableObjectTypes = array('collection', 'movie');
     // fetch category properties
     $this->catRegistries = array();
     $this->catProperties = array();
     if (in_array($this->objectType, $this->categorisableObjectTypes)) {
         $idFields = ModUtil::apiFunc('MUVideo', 'selection', 'getIdFields', array('ot' => $this->objectType));
         $this->catRegistries = ModUtil::apiFunc('MUVideo', 'category', 'getAllPropertiesWithMainCat', array('ot' => $this->objectType, 'arraykey' => $idFields[0]));
         $this->catProperties = ModUtil::apiFunc('MUVideo', 'category', 'getAllProperties', array('ot' => $this->objectType));
     }
     if (!isset($data['catIds'])) {
         $primaryRegistry = ModUtil::apiFunc('MUVideo', 'category', 'getPrimaryProperty', array('ot' => $this->objectType));
         $data['catIds'] = array($primaryRegistry => array());
         // backwards compatibility
         if (isset($data['catId'])) {
             $data['catIds'][$primaryRegistry][] = $data['catId'];
             unset($data['catId']);
         }
     } elseif (!is_array($data['catIds'])) {
         $data['catIds'] = explode(',', $data['catIds']);
     }
     foreach ($this->catRegistries as $registryId => $registryCid) {
         $propName = '';
         foreach ($this->catProperties as $propertyName => $propertyId) {
             if ($propertyId == $registryId) {
                 $propName = $propertyName;
                 break;
             }
         }
         if (isset($data['catids' . $propName])) {
             $data['catIds'][$propName] = $data['catids' . $propName];
         }
         if (!is_array($data['catIds'][$propName])) {
             if ($data['catIds'][$propName]) {
                 $data['catIds'][$propName] = array($data['catIds'][$propName]);
             } else {
                 $data['catIds'][$propName] = array();
             }
         }
     }
     $this->catIds = $data['catIds'];
 }