/** * 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']; }
/** * 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')); }
/** * 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()); }
/** * 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'); }
/** * 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'); }
/** * 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; }
/** * 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']; }
/** * 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; }
/** * 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; }
/** * 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) . '…</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); }