コード例 #1
0
ファイル: UploadHandler.php プロジェクト: rmaiwald/MUBoard
 /**
  * Process a file upload.
  *
  * @param string $objectType Currently treated entity type.
  * @param string $fileData   Form data array.
  * @param string $fieldName  Name of upload field.
  *
  * @return array Resulting file name and collected meta data.
  */
 public function performFileUpload($objectType, $fileData, $fieldName)
 {
     $dom = ZLanguage::getModuleDomain('MUBoard');
     $result = array('fileName' => '', 'metaData' => array());
     // check whether uploads are allowed for the given object type
     if (!in_array($objectType, $this->allowedObjectTypes)) {
         return $result;
     }
     // perform validation
     if (!$this->validateFileUpload($objectType, $fileData[$fieldName], $fieldName)) {
         // skip this upload field
         return false;
         //$result;
     }
     // retrieve the final file name
     $fileName = $fileData[$fieldName]['name'];
     $fileNameParts = explode('.', $fileName);
     $extension = $fileNameParts[count($fileNameParts) - 1];
     $extension = str_replace('jpeg', 'jpg', strtolower($extension));
     $fileNameParts[count($fileNameParts) - 1] = $extension;
     $fileName = implode('.', $fileNameParts);
     // retrieve the final file name
     $basePath = MUBoard_Util_Controller::getFileBaseFolder($objectType, $fieldName);
     $fileName = $this->determineFileName($objectType, $fieldName, $basePath, $fileName, $extension);
     if (!move_uploaded_file($fileData[$fieldName]['tmp_name'], $basePath . $fileName)) {
         return LogUtil::registerError(__('Error! Could not move your file to the destination folder.', $dom));
     }
     // collect data to return
     $result['fileName'] = $fileName;
     $result['metaData'] = $this->readMetaDataForFile($fileName, $basePath . $fileName);
     return $result;
 }
コード例 #2
0
ファイル: Edit.php プロジェクト: rmaiwald/MUBoard
 /**
  * Initialize form handler.
  *
  * This method takes care of all necessary initialisation of our data and form states.
  *
  * @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->getGet()->filter('idp', '', FILTER_SANITIZE_STRING);
     // initialise redirect goal
     $this->returnTo = $this->request->getGet()->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);
     $objectTemp = new $entityClass();
     $this->idFields = $objectTemp->get_idFields();
     // retrieve identifier of the object we wish to view
     $this->idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, array(), $this->objectType, $this->idFields);
     $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($this->idValues);
     $entity = null;
     $this->mode = $hasIdentifier ? 'edit' : 'create';
     if ($this->mode == 'edit') {
         if (!SecurityUtil::checkPermission($this->permissionComponent, '::', ACCESS_EDIT)) {
             // set an error message and return false
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForEdit();
         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, $entity))); */
         }
     } else {
         if (!SecurityUtil::checkPermission($this->permissionComponent, '::', ACCESS_ADD)) {
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForCreation($entityClass);
     }
     $this->view->assign('mode', $this->mode)->assign('inlineUsage', $this->inlineUsage);
     // We set text field to empty if entity class is posting
     if ($this->request->query->filter('ot', 'category', FILTER_SANITIZE_STRING) == 'posting' && $this->request->query->filter('func', 'main', FILTER_SANITIZE_STRING) == 'display') {
         $entity['text'] = '';
     }
     $entityData = $entity->toArray();
     // assign data to template as array (makes translatable support easier)
     $this->view->assign($this->objectTypeLower, $entityData);
     // save entity reference for later reuse
     $this->entityRef = $entity;
     $this->initializeAdditions();
     // everything okay, no initialization errors occured
     return true;
 }
コード例 #3
0
ファイル: ItemList.php プロジェクト: rmaiwald/MUBoard
 public function loadData(&$data)
 {
     if (!isset($data['objectType']) || !in_array($data['objectType'], MUBoard_Util_Controller::getObjectTypes('contentType'))) {
         $data['objectType'] = MUBoard_Util_Controller::getDefaultObjectType('contentType');
     }
     $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_' . ucwords($this->objectType) . '_display.tpl';
     }
     if (!isset($data['filter'])) {
         $data['filter'] = '';
     }
     $this->sorting = $data['sorting'];
     $this->amount = $data['amount'];
     $this->template = $data['template'];
     $this->filter = $data['filter'];
 }
コード例 #4
0
ファイル: Edit.php プロジェクト: rmaiwald/MUBoard
 /**
  * Initialize form handler.
  *
  * This method takes care of all necessary initialisation of our data and form states.
  *
  * @return boolean False in case of initialization errors, otherwise true.
  */
 public function initialize(Zikula_Form_View $view)
 {
     // we get forumid for edit form to answer to an issue
     // we get func
     $func = $this->request->query->filter('func', 'main', FILTER_SANITIZE_STRING);
     // we get forum for edit form to create a new issue
     $forum = $this->request->query->filter('forum', 0, FILTER_SANITIZE_NUMBER_INT);
     // we get parentid for edit form to answer to an issue
     $parentid = $this->request->query->filter('id', 0, FILTER_SANITIZE_NUMBER_INT);
     if (!SecurityUtil::checkPermission('MUBoard:Forum:', 'ForumID::1', ACCESS_ADD)) {
         return $view->registerError(LogUtil::registerPermissionError());
     }
     parent::initialize($view);
     // build posting repository
     $repository = MUBoard_Util_Model::getPostingRepository();
     if ($func == 'display') {
         // we get forumid for edit form to answer to an issue
         if ($parentid > 0) {
             $entity = $repository->selectById($parentid);
             $forumOfEntity = $entity->getForum();
             $forumid = $forumOfEntity['id'];
         } else {
             $forumid = 0;
         }
     } else {
         $id = $this->request->query->filter('id', 0, FILTER_SANITIZE_NUMBER_INT);
         if ($id > 0) {
             $entity = $repository->selectById($id);
             $parent = $entity->getParent();
             if ($parent) {
                 $parentid = $parent->getId();
             } else {
                 $parentid = 0;
             }
         }
     }
     // set mode to create if we want to answer
     if ($func == 'display') {
         // set mode to create
         $this->mode = 'create';
     } else {
         // if we func is not display
         // if id > 0 set mode to edit
         if ($id > 0) {
             // set mode to edit
             $this->mode = 'edit';
         }
     }
     // rule of token TODO with this we get problems with the edit
     // because e get always an error messahe nor permissions
     /* if ($this->mode == 'edit') {
             $token = $this->request->query->filter('token');
     
             if (SecurityUtil::validateCsrfToken($token)){
             // nothing to do
                 } else {
             if($parentid > 0) {
             $url = ModUtil::url($this->name, 'user', 'display', array('ot' => 'posting', 'id' => $parentid));
             } else {
             $url = ModUtil::url($this->name, 'user', 'display', array('ot' => 'forum', 'id' => $forum));
             }
             return LogUtil::registerPermissionError($url);
             }
             }*/
     // get text for the picture upload fields
     $maxSize = MUBoard_Util_Controller::maxSize();
     // get modvars
     $uploadImages = ModUtil::getVar('MUBoard', 'uploadImages');
     $uploadFiles = ModUtil::getVar('MUBoard', 'uploadFiles');
     $numberImages = ModUtil::getVar('MUBoard', 'numberImages');
     $numberFiles = ModUtil::getVar('MUBoard', 'numberFiles');
     // we assign to template
     $this->view->assign('uploadImages', $uploadImages)->assign('maxSize', $maxSize)->assign('uploadFiles', $uploadFiles)->assign('numberImages', $numberImages)->assign('numberFiles', $numberFiles)->assign('mode', $this->mode)->assign('forum', $forum)->assign('forumid', $forumid)->assign('parentid', $parentid);
     // everything okay, no initialization errors occured
     return true;
 }
コード例 #5
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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($args)
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', 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', 'category', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'edit');
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     // create new Form reference
     $view = FormUtil::newForm($this->name, $this);
     // build form handler class name
     $handlerClass = 'MUBoard_Form_Handler_User_' . ucfirst($objectType) . '_Edit';
     // execute form using supplied template and page event handler
     return $view->execute('user/' . $objectType . '/edit.tpl', new $handlerClass());
 }
コード例 #6
0
ファイル: Admin.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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($args)
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_ADMIN));
     // 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', 'category', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'admin', 'action' => 'delete');
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to delete
     $idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, $args, $objectType, $idFields);
     $hasIdentifier = MUBoard_Util_Controller::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.'));
     $confirmation = (bool) (isset($args['confirmation']) && !empty($args['confirmation'])) ? $args['confirmation'] : $this->request->getPost()->filter('confirmation', false, FILTER_VALIDATE_BOOLEAN);
     if ($confirmation) {
         $this->checkCsrfToken();
         // TODO call pre delete validation hooks
         $this->entityManager->remove($entity);
         $this->entityManager->flush();
         $this->registerStatus($this->__('Done! Item deleted.'));
         // TODO call post delete process hooks
         // clear view cache to reflect our changes
         $this->view->clear_cache();
         // redirect to the list of the current object type
         $this->redirect(ModUtil::url($this->name, 'admin', 'view', array('ot' => $objectType)));
     }
     $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     // assign the object we loaded above
     $this->view->assign($objectType, $entity)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // fetch and return the appropriate template
     return MUBoard_Util_View::processTemplate($this->view, 'admin', $objectType, 'delete', $args);
 }
コード例 #7
0
ファイル: Rank.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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 MUBoard_Entity_Rank::postLoadCallback()
  * @return boolean true if completed successfully else false.
  */
 protected function performPostLoadCallback()
 {
     // echo 'loaded a record ...';
     $currentType = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
     $currentFunc = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING);
     // initialise the upload handler
     $uploadManager = new MUBoard_UploadHandler();
     $this['id'] = (int) (isset($this['id']) && !empty($this['id']) ? DataUtil::formatForDisplay($this['id']) : 0);
     if ($currentFunc != 'edit') {
         $this['name'] = isset($this['name']) && !empty($this['name']) ? DataUtil::formatForDisplayHTML($this['name']) : '';
     }
     $this['minPostings'] = (int) (isset($this['minPostings']) && !empty($this['minPostings']) ? DataUtil::formatForDisplay($this['minPostings']) : 0);
     $this['maxPostings'] = (int) (isset($this['maxPostings']) && !empty($this['maxPostings']) ? DataUtil::formatForDisplay($this['maxPostings']) : 0);
     $this['numberOfIcons'] = (int) (isset($this['numberOfIcons']) && !empty($this['numberOfIcons']) ? DataUtil::formatForDisplay($this['numberOfIcons']) : 0);
     if (!empty($this['uploadImage'])) {
         $basePath = MUBoard_Util_Controller::getFileBaseFolder('rank', 'uploadImage');
         $fullPath = $basePath . $this['uploadImage'];
         $this['uploadImageFullPath'] = $fullPath;
         $this['uploadImageFullPathURL'] = System::getBaseUrl() . $fullPath;
         // just some backwards compatibility stuff
         if (!isset($this['uploadImageMeta']) || !is_array($this['uploadImageMeta']) || !count($this['uploadImageMeta'])) {
             // assign new meta data
             $this['uploadImageMeta'] = $uploadManager->readMetaDataForFile($this['uploadImage'], $fullPath);
         }
     }
     $this['special'] = (bool) $this['special'];
     $this->prepareItemActions();
     return true;
 }
コード例 #8
0
ファイル: Selection.php プロジェクト: rmaiwald/MUBoard
 /**
  * Select tree of given object type.
  *
  * @param string $args['ot'] The object type to retrieve (optional)
  * @param string $methodName Name of calling method
  */
 protected function determineObjectType($args, $methodName = '')
 {
     $objectType = isset($args['ot']) ? $args['ot'] : '';
     $utilArgs = array('api' => 'selection', 'action' => $methodName);
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('api', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('api', $utilArgs);
     }
     return $objectType;
 }
コード例 #9
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * Form custom url string
  *
  * @return       string custom url string
  */
 public function encodeurl($args)
 {
     // check if we have the required input
     if (!is_array($args) || !isset($args['modname']) || !isset($args['func'])) {
         return LogUtil::registerArgsError();
     }
     // 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;
     }
     // reference to current language
     $lang = ZLanguage::getLanguageCode();
     // initialise url routing rules
     $routerFacade = new MUBoard_RouterFacade();
     // get router itself for convenience
     $router = $routerFacade->getRouter();
     // initialise object type
     $utilArgs = array('controller' => 'user', 'action' => 'encodeurl');
     $allowedObjectTypes = MUBoard_Util_Controller::getObjectTypes('api', $utilArgs);
     $objectType = isset($args['args']['ot']) && in_array($args['args']['ot'], $allowedObjectTypes) ? $args['args']['ot'] : MUBoard_Util_Controller::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 = '';
     $endingPrefix = $args['func'] == 'view' ? '.' : '';
     foreach (array('csv', 'rss', 'atom', 'xml', 'pdf', 'json') 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]);
             }
         }
         $slugTitle = '';
         if ($id > 0) {
             $slugTitle = $routerFacade->getFormattedSlug($objectType, $args['func'], $args['args'], $id);
         }
         if (!empty($slugTitle) && $slugTitle != $id) {
             // add slug expression
             $args['args']['title'] = $slugTitle;
         } else {
             // readd id
             $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('MUBoard');
     $result = preg_replace('/' . $modInfo['name'] . '/', $modInfo['url'], $result, 1);
     return $result;
 }
コード例 #10
0
ファイル: Installer.php プロジェクト: rmaiwald/MUBoard
 /**
  * Install the MUBoard application.
  *
  * @return boolean True on success, or false.
  */
 public function install()
 {
     $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'firstImage');
     if (!is_dir($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath)));
     }
     if (!is_writable($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath)));
     }
     $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'secondImage');
     if (!is_dir($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath)));
     }
     if (!is_writable($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath)));
     }
     $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'thirdImage');
     if (!is_dir($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath)));
     }
     if (!is_writable($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath)));
     }
     $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'firstFile');
     if (!is_dir($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath)));
     }
     if (!is_writable($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath)));
     }
     $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'secondFile');
     if (!is_dir($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath)));
     }
     if (!is_writable($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath)));
     }
     $basePath = MUBoard_Util_Controller::getFileBaseFolder('posting', 'thirdFile');
     if (!is_dir($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath)));
     }
     if (!is_writable($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath)));
     }
     $basePath = MUBoard_Util_Controller::getFileBaseFolder('rank', 'uploadImage');
     if (!is_dir($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" does not exist. Please create it before installing this application.', array($basePath)));
     }
     if (!is_writable($basePath)) {
         return LogUtil::registerError($this->__f('The upload folder "%s" is not writable. Please change permissions accordingly before installing this application.', array($basePath)));
     }
     // create all tables from according entity definitions
     try {
         DoctrineHelper::createSchema($this->entityManager, $this->listEntityClasses());
     } catch (Exception $e) {
         if (System::isDevelopmentMode()) {
             LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage());
         }
         return LogUtil::registerError($this->__f('An error was encountered while creating the tables for the %s module.', array($this->getName())));
     }
     // set up all our vars with initial values
     $this->setVar('uploadImages', false);
     $this->setVar('allowedSizeOfImages', 0);
     $this->setVar('numberImages', array('1'));
     $this->setVar('uploadFiles', false);
     $this->setVar('allowedSizeOfFiles', 0);
     $this->setVar('numberFiles', array('1'));
     $this->setVar('editPostings', false);
     $this->setVar('editTime', 6);
     $this->setVar('latestPostings', 1);
     $this->setVar('sortingPostings', array('descending'));
     $this->setVar('iconSet', array('1'));
     $this->setVar('template', array('normal'));
     $this->setVar('pagesize', 10);
     $this->setVar('standardIcon', 'images/icons/extrasmall/favorites.png');
     $this->setVar('specialIcon', 'images/icons/extrasmall/package_favorite.png');
     $this->setVar('showStatisticInDetails', true);
     $this->setVar('showStatisticOnBottom', false);
     // create the default data for MUBoard
     $this->createDefaultData();
     // register persistent event handlers
     $this->registerPersistentEventHandlers();
     // register hook subscriber bundles
     HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles());
     // initialisation successful
     return true;
 }
コード例 #11
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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($args)
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_READ));
     // 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', 'category', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'display');
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to view
     $idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, $args, $objectType, $idFields);
     $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($idValues);
     // check for unique permalinks (without id)
     $hasSlug = false;
     $slugTitle = '';
     if ($hasIdentifier === false) {
         $entityClass = 'MUBoard_Entity_' . ucfirst($objectType);
         $objectTemp = new $entityClass();
         $hasSlug = $objectTemp->get_hasUniqueSlug();
         if ($hasSlug) {
             $slugTitle = isset($args['title']) && !empty($args['title']) ? $args['title'] : $this->request->getGet()->filter('title', '', FILTER_SANITIZE_STRING);
             $hasSlug = !empty($slugTitle);
         }
     }
     $hasIdentifier |= $hasSlug;
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues, 'slug' => $slugTitle));
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     // we take the children postings of the parent issue
     if ($objectType == 'posting') {
         $postingid = $entity['id'];
         $postingsWhere = 'tbl.parent = \'' . DataUtil::formatForStore($postingid) . '\'';
         $order = ModUtil::getVar($this->name, 'sortingPostings');
         if ($order == 'descending') {
             $sdir = 'desc';
         } else {
             $sdir = 'asc';
         }
         $selectionArgs = array('ot' => 'posting', 'where' => $postingsWhere, 'orderBy' => 'createdDate' . ' ' . $sdir);
         // the current offset which is used to calculate the pagination
         $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT);
         // the number of items displayed on a page for pagination
         $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT);
         if ($resultsPerPage == 0) {
             $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT);
             $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10);
         }
         $selectionArgs['currentPage'] = $currentPage;
         $selectionArgs['resultsPerPage'] = $resultsPerPage;
         list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs);
         // we check if the user may see the form to answer to posting
         $mayEdit = MUBoard_Util_Controller::mayEdit($id);
         $this->view->assign('mayEdit', $mayEdit);
     }
     if ($objectType == 'forum') {
         $forumid = $entity['id'];
         $parentWhere = 'tbl.parent_id IS NULL';
         $parentWhere .= ' AND ';
         $parentWhere .= 'tbl.forum = \'' . DataUtil::formatForStore($forumid) . '\'';
         $order = ModUtil::getVar($this->name, 'sortingPostings');
         if ($order == 'descending') {
             $sdir = 'desc';
         } else {
             $sdir = 'asc';
         }
         $selectionArgs = array('ot' => 'posting', 'where' => $parentWhere, 'orderBy' => 'createdDate' . ' ' . $sdir);
         // the current offset which is used to calculate the pagination
         $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT);
         // the number of items displayed on a page for pagination
         $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT);
         if ($resultsPerPage == 0) {
             $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT);
             $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10);
         }
         $selectionArgs['currentPage'] = $currentPage;
         $selectionArgs['resultsPerPage'] = $resultsPerPage;
         list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs);
     }
     // build ModUrl instance for display hooks
     $currentUrlArgs = array('ot' => $objectType);
     foreach ($idFields as $idField) {
         $currentUrlArgs[$idField] = $idValues[$idField];
     }
     // add a call to the posting
     if ($objectType == 'posting') {
         MUBoard_Util_Model::addView($idValues);
     }
     // get actual time
     $nowtime = DateUtil::getDatetime();
     // set sessionvar with calling time
     SessionUtil::setVar('muboardonline', $nowtime);
     $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs);
     $type = $this->request->getGet()->filter('type', 'admin', FILTER_SANITIZE_STRING);
     $func = $this->request->getGet()->filter('func', 'view', FILTER_SANITIZE_STRING);
     $editPostings = ModUtil::getVar($this->name, 'editPostings');
     // assign output data to view object.
     $this->view->assign($objectType, $entity)->assign('postings', $entities)->assign('currentUrlObject', $currentUrlObject)->assign('func', $func)->assign('editPostings', $editPostings)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage));
     $dom = ZLanguage::getModuleDomain($this->name);
     // we set Pagetitle
     $sitename = ModUtil::getVar('ZConfig', 'sitename');
     if ($objectType == 'category') {
         $titletobject = __('Forum - Category: ', $dom);
     }
     if ($objectType == 'forum') {
         $titletobject = __('Forum - Category: ', $dom) . ' ' . $entity['category']['title'] . ' - ' . __('Forum: ', $dom);
     }
     if ($objectType == 'posting') {
         $titletobject = 'Forum: ' . ' ' . $entity['forum']['title'] . ' - ' . __('Issue: ', $dom);
     }
     PageUtil::setVar('title', $sitename . ' - ' . $titletobject . ' ' . $entity['title']);
     // we set description
     if ($objectType == 'category' || $objectType == 'forum') {
         $descriptionobject = $entity['description'];
     }
     if ($objectType == 'posting') {
         $descriptionobject = $entity['text'];
         $descriptionobject = substr($descriptionobject, 0, 160) . '...';
     }
     PageUtil::setVar('description', $descriptionobject);
     // fetch and return the appropriate template
     return MUBoard_Util_View::processTemplate($this->view, 'user', $objectType, 'display', $args);
 }
コード例 #12
0
ファイル: View.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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 static function processPdf(Zikula_View $view, $template)
 {
     // first the content, to set page vars
     $output = $view->fetch($template);
     // 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>';
     // create name of the pdf output file
     $fileTitle = MUBoard_Util_Controller::formatPermalink(System::getVar('sitename')) . '-' . MUBoard_Util_Controller::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;
 }
コード例 #13
0
ファイル: ItemList.php プロジェクト: rmaiwald/MUBoard
 /**
  * Update block settings
  *
  * @param        array       $blockinfo a blockinfo structure
  * @return       $blockinfo  the modified blockinfo structure
  */
 public function update($blockinfo)
 {
     // Get current content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $vars['objectType'] = $this->request->getPost()->filter('objecttype', 'category', FILTER_SANITIZE_STRING);
     $vars['sorting'] = $this->request->getPost()->filter('sorting', 'default', FILTER_SANITIZE_STRING);
     $vars['amount'] = (int) $this->request->getPost()->filter('amount', 5, FILTER_VALIDATE_INT);
     $vars['template'] = $this->request->getPost()->get('template', '');
     $vars['filter'] = $this->request->getPost()->get('filter', '');
     if (!in_array($vars['objectType'], MUBoard_Util_Controller::getObjectTypes('block'))) {
         $vars['objectType'] = MUBoard_Util_Controller::getDefaultObjectType('block');
     }
     // 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_' . ucwords($vars['objectType']) . '_display.tpl');
     $this->view->clear_cache('block/itemlist_display_description.tpl');
     $this->view->clear_cache('block/itemlist_' . ucwords($vars['objectType']) . '_display_description.tpl');
     return $blockinfo;
 }
コード例 #14
0
ファイル: ItemList.php プロジェクト: rmaiwald/MUBoard
 /**
  * Display the block
  *
  * @param        array       $blockinfo a blockinfo structure
  * @return       output      the rendered block
  */
 public function display($blockinfo)
 {
     // only show block content if the user has the required permissions
     if (!SecurityUtil::checkPermission('MUBoard:ItemListBlock:', "{$blockinfo['title']}::", ACCESS_OVERVIEW)) {
         return false;
     }
     // check if the module is available at all
     if (!ModUtil::available('MUBoard')) {
         return false;
     }
     // get current block content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $vars['bid'] = $blockinfo['bid'];
     // set default values for all params which are not properly set
     if (!isset($vars['objectType']) || empty($vars['objectType'])) {
         $vars['objectType'] = 'category';
     }
     if (!isset($vars['sorting']) || empty($vars['sorting'])) {
         $vars['sorting'] = 'default';
     }
     if (!isset($vars['amount']) || !is_numeric($vars['amount'])) {
         $vars['amount'] = 5;
     }
     if (!isset($vars['template'])) {
         $vars['template'] = 'itemlist_' . ucwords($vars['objectType']) . '_display.tpl';
     }
     if (!isset($vars['filter'])) {
         $vars['filter'] = '';
     }
     ModUtil::initOOModule('MUBoard');
     if (!isset($vars['objectType']) || !in_array($vars['objectType'], MUBoard_Util_Controller::getObjectTypes('block'))) {
         $vars['objectType'] = MUBoard_Util_Controller::getDefaultObjectType('block');
     }
     $objectType = $vars['objectType'];
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     $repository = $entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     $idFields = ModUtil::apiFunc('MUBoard', 'selection', 'getIdFields', array('ot' => $objectType));
     $sortParam = '';
     if ($vars['sorting'] == 'random') {
         $sortParam = 'RAND()';
     } elseif ($vars['sorting'] == 'newest') {
         if (count($idFields) == 1) {
             $sortParam = $idFields[0] . ' DESC';
         } else {
             foreach ($idFields as $idField) {
                 if (!empty($sortParam)) {
                     $sortParam .= ', ';
                 }
                 $sortParam .= $idField . ' ASC';
             }
         }
     } elseif ($vars['sorting'] == 'default') {
         $sortParam = $repository->getDefaultSortingField() . ' ASC';
     }
     // get objects from database
     $selectionArgs = array('ot' => $objectType, 'where' => $vars['filter'], 'orderBy' => $sortParam, 'currentPage' => 1, 'resultsPerPage' => $vars['amount']);
     list($entities, $objectCount) = ModUtil::apiFunc('MUBoard', 'selection', 'getEntitiesPaginated', $selectionArgs);
     $this->view->setCaching(false);
     // assign block vars and fetched data
     $this->view->assign('vars', $vars)->assign('objectType', $objectType)->assign('items', $entities)->assign($repository->getAdditionalTemplateParameters('block'));
     // set a block title
     if (empty($blockinfo['title'])) {
         $blockinfo['title'] = $this->__('MUBoard items');
     }
     $output = '';
     $templateForObjectType = str_replace('itemlist_', 'itemlist_' . ucwords($objectType) . '_', $vars['template']);
     if ($this->view->template_exists('contenttype/' . $templateForObjectType)) {
         $output = $this->view->fetch('contenttype/' . $templateForObjectType);
     } elseif ($this->view->template_exists('contenttype/' . $vars['template'])) {
         $output = $this->view->fetch('contenttype/' . $vars['template']);
     } elseif ($this->view->template_exists('block/' . $templateForObjectType)) {
         $output = $this->view->fetch('block/' . $templateForObjectType);
     } elseif ($this->view->template_exists('block/' . $vars['template'])) {
         $output = $this->view->fetch('block/' . $vars['template']);
     } else {
         $output = $this->view->fetch('block/itemlist.tpl');
     }
     $blockinfo['content'] = $output;
     // return the block to the theme
     return BlockUtil::themeBlock($blockinfo);
 }
コード例 #15
0
ファイル: Ajax.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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_Base
  */
 public function getItemList()
 {
     if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_EDIT)) {
         return true;
     }
     $objectType = 'category';
     if ($this->request->isPost() && $this->request->getPost()->has('ot')) {
         $objectType = $this->request->getPost()->filter('ot', 'category', FILTER_SANITIZE_STRING);
     } elseif ($this->request->isGet() && $this->request->getGet()->has('ot')) {
         $objectType = $this->request->getGet()->filter('ot', 'category', FILTER_SANITIZE_STRING);
     }
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', array('controller' => 'ajax', 'action' => 'getItemList')))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', array('controller' => 'ajax', 'action' => 'getItemList'));
     }
     $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     $fragment = '';
     $exclude = '';
     if ($this->request->isPost() && $this->request->getPost()->has('fragment')) {
         $fragment = $this->request->getPost()->get('fragment', '');
         $exclude = $this->request->getPost()->get('exclude', '');
     } elseif ($this->request->isGet() && $this->request->getGet()->has('fragment')) {
         $fragment = $this->request->getGet()->get('fragment', '');
         $exclude = $this->request->getGet()->get('exclude', '');
     }
     $exclude = !empty($exclude) ? array($exclude) : array();
     // parameter for used sorting field
     $sort = $this->request->getGet()->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) {
         $titleFieldName = $repository->getTitleFieldName();
         $descriptionFieldName = $repository->getDescriptionFieldName();
         $previewFieldName = $repository->getPreviewFieldName();
         $thumbWidth = 100;
         $thumbHeight = 80;
         foreach ($entities as $item) {
             // class="informal" --> show in dropdown, but do not copy in the input field after selection
             $itemTitle = !empty($titleFieldName) ? $item[$titleFieldName] : $this->__('Item');
             $itemTitleStripped = str_replace('"', '', $itemTitle);
             $itemDescription = isset($item[$descriptionFieldName]) && !empty($item[$descriptionFieldName]) ? $item[$descriptionFieldName] : '';
             //$this->__('No description yet.'));
             $itemId = '';
             foreach ($idFields as $idField) {
                 $itemId .= (!empty($itemId) ? '_' : '') . $item[$idField];
             }
             $out .= '<li id="' . $itemId . '" title="' . $itemTitleStripped . '">';
             $out .= '<div class="itemtitle">' . $itemTitle . '</div>';
             if (!empty($itemDescription)) {
                 $out .= '<div class="itemdesc informal">' . $itemDescription . '</div>';
             }
             // check for preview image
             if (!empty($previewFieldName) && !empty($item[$previewFieldName]) && isset($item[$previewFieldName . 'FullPath'])) {
                 $thumbImagePath = MUBoard_Util_Image::getThumb($item[$previewFieldName], $item[$previewFieldName . 'FullPath'], $thumbWidth, $thumbHeight);
                 $preview = '<img src="' . $thumbImagePath . '" width="' . $thumbWidth . '" height="' . $thumbHeight . '" alt="' . $itemTitleStripped . '" />';
                 $out .= '<div class="itempreview informal" id="itempreview' . $itemId . '">' . $preview . '</div>';
             }
             $out .= '</li>';
         }
     }
     $out .= '</ul>';
     return new Zikula_Response_Ajax_Plain($out);
 }
コード例 #16
0
ファイル: UploadHandler.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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.
  *
  * @return mixed Array with updated object data on success, else false.
  */
 public function deleteUploadFile($objectType, $objectData, $fieldName)
 {
     if (!in_array($objectType, $this->allowedObjectTypes)) {
         return false;
     }
     if (empty($objectData[$fieldName])) {
         return $objectData;
     }
     // determine file system information
     $basePath = MUBoard_Util_Controller::getFileBaseFolder($objectType, $fieldName);
     $fileName = $objectData[$fieldName];
     // remove original file
     if (!unlink($basePath . $fileName)) {
         return false;
     }
     $objectData[$fieldName] = '';
     $objectData[$fieldName . 'Meta'] = array();
     $fileExtension = FileUtil::getExtension($fileName, false);
     if (!in_array($fileExtension, $this->imageFileTypes)) {
         // we are done, so let's return
         return $objectData;
     }
     // get extension again, but including the dot
     $fileExtension = FileUtil::getExtension($fileName, true);
     $thumbFileNameBase = str_replace($fileExtension, '', $fileName) . '_tmb_';
     $thumbFileNameBaseLength = strlen($thumbFileNameBase);
     // remove image thumbnails
     $thumbPath = $basePath . 'tmb/';
     $thumbFiles = FileUtil::getFiles($thumbPath, false, true, null, 'f');
     // non-recursive, relative pathes
     foreach ($thumbFiles as $thumbFile) {
         $thumbFileBase = substr($thumbFile, 0, $thumbFileNameBaseLength);
         if ($thumbFileBase != $thumbFileNameBase) {
             // let other thumbnails untouched
             continue;
         }
         unlink($thumbPath . $thumbFile);
     }
     return $objectData;
 }