Example #1
0
 /**
  * Display hook for view.
  *
  * Subject is the object being viewed that we're attaching to.
  * args[id] Is the id of the object.
  * args[caller] the module who notified of this event.
  *
  * @param Zikula_Hook $hook The hook.
  *
  * @return void
  */
 public function uiView(Zikula_DisplayHook $hook)
 {
     // work out the input from the hook
     $mod = $hook->getCaller();
     $areaId = $hook->getAreaId();
     $objectid = $hook->getId();
     // first check if the user is allowed to do any comments for this module/objectid
     if (!SecurityUtil::checkPermission('EZComments::', "{$mod}:{$objectid}:", ACCESS_OVERVIEW)) {
         return;
     }
     $subject = array();
     //$hook->getSubject();
     $owneruid = isset($subject['cr_uid']) ? (int) $subject['cr_uid'] : 0;
     $useurl = isset($subject['useurl']) ? $subject['useurl'] : null;
     $ownerUidSession = SessionUtil::delVar('commentOwner', 0);
     if ($ownerUidSession > 0) {
         $owneruid = $ownerUidSession;
     }
     // we may have a comment incoming
     $ezcomment = unserialize(SessionUtil::getVar('ezcomment', 'a:0:{}'));
     $ezcomment = isset($ezcomment[$mod][$objectid]) ? $ezcomment[$mod][$objectid] : null;
     // we may get some input in from the navigation bar
     $order = FormUtil::getPassedValue('order');
     $sortorder = $order == 1 ? 'DESC' : 'ASC';
     $status = 0;
     // check if we're using the pager
     $enablepager = ModUtil::getVar('EZComments', 'enablepager');
     if ($enablepager) {
         $numitems = ModUtil::getVar('EZComments', 'commentsperpage');
         $startnum = FormUtil::getPassedValue('comments_startnum');
         if (!isset($startnum) && !is_numeric($startnum)) {
             $startnum = -1;
         }
     } else {
         $startnum = -1;
         $numitems = -1;
     }
     $params = compact('mod', 'areaId', 'objectid', 'sortorder', 'status', 'numitems', 'startnum');
     $items = ModUtil::apiFunc('EZComments', 'user', 'getall', $params);
     if ($items === false) {
         return LogUtil::registerError($this->__('Internal Error.'), null, 'index.php');
     }
     $items = ModUtil::apiFunc('EZComments', 'user', 'prepareCommentsForDisplay', $items);
     if ($enablepager) {
         $commentcount = ModUtil::apiFunc('EZComments', 'user', 'countitems', compact('mod', 'objectid', 'status'));
     } else {
         $commentcount = count($items);
     }
     // create the output object
     $view = Zikula_View::getInstance('EZComments', false, null, true);
     $view->assign('areaid', $areaId)->assign('comments', $items)->assign('commentcount', $commentcount)->assign('ezcomment', $ezcomment)->assign('ezc_info', compact('mod', 'objectid', 'sortorder', 'status'))->assign('modinfo', ModUtil::getInfo(ModUtil::getIdFromName($mod)))->assign('msgmodule', System::getVar('messagemodule', ''))->assign('prfmodule', System::getVar('profilemodule', ''))->assign('allowadd', SecurityUtil::checkPermission('EZComments::', "{$mod}:{$objectid}:", ACCESS_COMMENT))->assign('loggedin', UserUtil::isLoggedIn());
     $modUrl = $hook->getUrl();
     $redirect = !is_null($modUrl) ? $modUrl->getUrl() : '';
     $view->assign('returnurl', $redirect);
     // encode the url - otherwise we can get some problems out there....
     $redirect = base64_encode($redirect);
     $view->assign('redirect', $redirect);
     $view->assign('objectid', $objectid);
     // assign the user is of the content owner
     $view->assign('owneruid', $owneruid);
     // assign url that should be stored in db and sent in email if it
     // differs from the redirect url
     $view->assign('useurl', $useurl);
     // flag to recognize the main call
     static $mainScreen = true;
     $view->assign('mainscreen', $mainScreen);
     $mainScreen = false;
     // assign the values for the pager
     $view->assign('ezc_pager', array('numitems' => $commentcount, 'itemsperpage' => $numitems));
     // find out which template and stylesheet to use
     $templateset = isset($args['template']) ? $args['template'] : FormUtil::getPassedValue('eztpl');
     $css = isset($args['ezccss']) ? $args['ezccss'] : FormUtil::getPassedValue('ezccss');
     $defaultcss = ModUtil::getVar('EZComments', 'css', 'style.css');
     if (!$view->template_exists(DataUtil::formatForOS($templateset) . '/ezcomments_user_view.tpl')) {
         $templateset = ModUtil::getVar('EZComments', 'template', 'Standard');
     }
     $view->assign('template', $templateset);
     // include stylesheet if there is a style sheet
     $css = $css ? "{$css}.css" : $defaultcss;
     if ($css = ModUtil::apiFunc('EZComments', 'user', 'getStylesheet', array('path' => "{$templateset}/{$css}"))) {
         PageUtil::addVar('stylesheet', $css);
     }
     $template = DataUtil::formatForOS($templateset) . '/ezcomments_user_view.tpl';
     $response = new Zikula_Response_DisplayHook('provider_area.ui_hooks.ezcomments.comments', $view, $template);
     $hook->setResponse($response);
 }