Exemplo n.º 1
0
 /**
  * This function increment the page view if the user is not the creator
  */
 public static function addView($id)
 {
     $serviceManager = ServiceUtil::getManager();
     $modelHelper = new Reviews_Util_Model($serviceManager);
     // build review repository
     $repository = $modelHelper->getReviewRepository();
     $entity = $repository->selectById($id);
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     if ($entity->getCreatedUserId() != UserUtil::getVar('uid')) {
         $hits = $entity->getHits();
         $entity->setHits($hits + 1);
         $email = $entity->getEmail();
         $email = html_entity_decode($email);
         $entity->setEmail($email);
         $entityManager->flush();
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * form custom url string
  *
  * @author Mark West
  * @return string custom url string
  */
 public function encodeurl($args)
 {
     // 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 Reviews_RouterFacade();
     // get router itself for convenience
     $router = $routerFacade->getRouter();
     // initialise object type
     $controllerHelper = new Reviews_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', '');
     $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') {
             // category list
             /* if (isset($args['args']['prop'])) {
                 $vars = $args['args']['prop'];
                if (isset($args['args']['cat'])) {
                $vars .= '/'.$args['args']['cat'];
                }
                // letter list
                } elseif (isset($args['args']['letter'])) {
                $vars = 'letter/'.$args['args']['letter'];
                }
                if (isset($args['args']['page']) && $args['args']['page'] != 1) {
                $vars .= (empty($vars) ? '' : '/').'page/'.$args['args']['page'];
                }*/
             $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]);
             }
         }
         if (ModUtil::getVar('Reviews', 'addcategorytitletopermalink') == 1 && ModUtil::getVar('Reviews', 'enablecategorization') == 1) {
             if ($id > 0) {
                 $modelHelper = new Reviews_Util_Model($this->serviceManager);
                 $repository = $modelHelper->getReviewRepository();
                 $thisreview = $repository->selectById($id);
                 $categories = $thisreview->getCategories();
                 $name = $categories[0]->getCategory()->getName();
                 $displayname = $categories[0]->getCategory()->getDisplayName();
             }
             $lang = ZLanguage::getLanguageCode();
             $cat = '';
             if ($name != '') {
                 $cat = $name;
             }
             if ($displayname != '') {
                 $cat = $displayname[$lang];
             }
             $args['args']['cat'] = $cat;
         }
         // 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('Reviews');
     $result = preg_replace('/' . $modInfo['name'] . '/', $modInfo['url'], $result, 1);
     $result = preg_replace('#' . 'review/' . '#', '', $result, 1);
     $result = preg_replace('=' . '\\+' . '=', ' ', $result);
     return $result;
 }