Example #1
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);
 }
/**
 * The muvideoGetFileSize modifier displays the size of a given file in a readable way.
 *
 * @param integer $size     File size in bytes.
 * @param string  $filepath The input file path including file name (if file size is not known).
 * @param boolean $nodesc   If set to true the description will not be appended.
 * @param boolean $onlydesc If set to true only the description will be returned.
 *
 * @return string File size in a readable form.
 */
function smarty_modifier_muvideoGetFileSize($size = 0, $filepath = '', $nodesc = false, $onlydesc = false)
{
    if (!is_numeric($size)) {
        $size = (int) $size;
    }
    if (!$size) {
        if (empty($filepath) || !file_exists($filepath)) {
            return '';
        }
        $size = filesize($filepath);
    }
    if (!$size) {
        return '';
    }
    $serviceManager = ServiceUtil::getManager();
    $viewHelper = new MUVideo_Util_View($serviceManager);
    $result = $viewHelper->getReadableFileSize($size, $nodesc, $onlydesc);
    return $result;
}
Example #3
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 #4
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());
 }