/** * The reviewsGetFileSize 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_reviewsGetFileSize($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 Reviews_Util_View($serviceManager); $result = $viewHelper->getReadableFileSize($size, $nodesc, $onlydesc); return $result; }
/** * This method provides a generic item detail view. * * @param string $ot Treated object type. * @param string $tpl Name of alternative template (for alternative display options, feeds and xml output) * @param boolean $raw Optional way to display a template instead of fetching it (needed for standalone output) * * @return mixed Output. */ public function display() { $controllerHelper = new Reviews_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = $this->request->query->filter('ot', 'review', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'display'); if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) { $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs); } $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', ACCESS_READ), 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); // check for unique permalinks (without id) $hasSlug = false; $slug = ''; if ($hasIdentifier === false) { $entityClass = $this->name . '_Entity_' . ucwords($objectType); $meta = $this->entityManager->getClassMetadata($entityClass); $hasSlug = $meta->hasField('slug') && $meta->isUniqueField('slug'); if ($hasSlug) { $slug = $this->request->query->filter('slug', '', FILTER_SANITIZE_STRING); $hasSlug = !empty($slug); } } $hasIdentifier |= $hasSlug; $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.')); $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues, 'slug' => $slug)); $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 = array('ot' => $objectType); $instanceId = ''; foreach ($idFields as $idField) { $currentUrlArgs[$idField] = $entity[$idField]; if (!empty($instanceId)) { $instanceId .= '_'; } $instanceId .= $entity[$idField]; } $currentUrlArgs['id'] = $instanceId; if (isset($entity['slug'])) { $currentUrlArgs['slug'] = $entity['slug']; } $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs); $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', $instanceId . '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $viewHelper = new Reviews_Util_View($this->serviceManager); $templateFile = $viewHelper->getViewTemplate($this->view, 'user', $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)); //$controllerHelper = new Reviews_Util_Controller($this->serviceManager); $controllerHelper->addView($entity['id']); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, 'user', $objectType, 'display', array(), $templateFile); }
/** * This method provides a generic handling of all edit requests. * * @param string $ot Treated object type. * @param string $tpl Name of alternative template (for alternative display options, feeds and xml output) * @param boolean $raw Optional way to display a template instead of fetching it (needed for standalone output) * * @return mixed Output. */ public function edit() { $controllerHelper = new Reviews_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = $this->request->query->filter('ot', 'review', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'edit'); if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) { $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs); } $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', ACCESS_EDIT), LogUtil::getErrorMsgPermission()); // create new Form reference $view = FormUtil::newForm($this->name, $this); // build form handler class name $handlerClass = $this->name . '_Form_Handler_User_' . ucfirst($objectType) . '_Edit'; // determine the output template $viewHelper = new Reviews_Util_View($this->serviceManager); $template = $viewHelper->getViewTemplate($this->view, 'user', $objectType, 'edit', array()); // execute form using supplied template and page event handler return $view->execute($template, new $handlerClass()); }
/** * This method provides a generic handling of simple delete requests. * * @param string $ot Treated object type. * @param int $id Identifier of entity to be deleted. * @param boolean $confirmation Confirm the deletion, else a confirmation page is displayed. * @param string $tpl Name of alternative template (for alternative display options, feeds and xml output) * @param boolean $raw Optional way to display a template instead of fetching it (needed for standalone output) * * @return mixed Output. */ public function delete() { $controllerHelper = new Reviews_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = $this->request->query->filter('ot', 'review', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'admin', 'action' => 'delete'); if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) { $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs); } $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', ACCESS_ADMIN), 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.')); $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues)); $this->throwNotFoundUnless($entity != null, $this->__('No such item.')); $entity->initWorkflow(); $workflowHelper = new Reviews_Util_Workflow($this->serviceManager); $deleteActionId = 'delete'; $deleteAllowed = false; $actions = $workflowHelper->getActionsForObject($entity); if ($actions === false || !is_array($actions)) { return LogUtil::registerError($this->__('Error! Could not determine workflow actions.')); } 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 entity.')); } $confirmation = (bool) $this->request->request->filter('confirmation', false, FILTER_VALIDATE_BOOLEAN); if ($confirmation) { $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 an item $hookType = 'process_delete'; $hook = new Zikula_ProcessHook($hookAreaPrefix . '.' . $hookType, $entity->createCompositeIdentifier()); $this->notifyHooks($hook); // An item was deleted, so we clear all cached pages this item. $cacheArgs = array('ot' => $objectType, 'item' => $entity); ModUtil::apiFunc($this->name, 'cache', 'clearItemCache', $cacheArgs); // redirect to the list of the current object type return $this->redirect(ModUtil::url($this->name, 'admin', 'view', array('ot' => $objectType))); } } $entityClass = $this->name . '_Entity_' . ucwords($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 Reviews_Util_View($this->serviceManager); return $viewHelper->processTemplate($this->view, 'admin', $objectType, 'delete', array()); }