function init($params, &$smarty)
 {
     $this->mydirname = $smarty->_tpl_vars['mydirname'];
     $this->mod_url = $smarty->_tpl_vars['mod_url'];
     $this->content4disp = $smarty->_tpl_vars['content'];
     $this->content_uri = pico_common_unhtmlspecialchars(XOOPS_URL . '/modules/' . $this->mydirname . '/' . $this->content4disp['link']);
     $this->session_index = $this->mydirname . '_' . $this->content4disp['id'] . '_' . $this->mypluginname;
 }
 function execute($request)
 {
     // Ticket Check
     if (!$GLOBALS['xoopsGTicket']->check(true, 'pico')) {
         redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsGTicket']->getErrors());
     }
     parent::execute($request);
     // initialize
     $cat_data = $this->currentCategoryObj->getData();
     $picoPermission =& PicoPermission::getInstance();
     // permission check
     if (empty($cat_data['can_post'])) {
         redirect_header(XOOPS_URL . '/', 2, _MD_PICO_ERR_MAKECONTENT);
     }
     // insert a content
     $content_id = pico_makecontent($this->mydirname);
     $content_uri4html = XOOPS_URL . "/modules/{$this->mydirname}/" . pico_common_make_content_link4html($this->mod_config, $content_id, $this->mydirname);
     // get contentObj
     $this->contentObj =& new PicoContent($this->mydirname, $content_id, $this->currentCategoryObj);
     $content_data = $this->contentObj->getData();
     // return uri
     if (!empty($_GET['ret']) && ($ret_uri = pico_main_parse_ret2uri($this->mydirname, $_GET['ret']))) {
         $ret_uri4html = htmlspecialchars($ret_uri, ENT_QUOTES);
     } else {
         $ret_uri4html = $content_uri4html;
     }
     // calling a delegate
     if (class_exists('XCube_DelegateUtils')) {
         XCube_DelegateUtils::raiseEvent('ModuleClass.Pico.Contentman.InsertSuccess', $this->mydirname, $content_id, $cat_data, $ret_uri4html);
     }
     // create extra_tags for notifications
     $extra_tags = array('CONTENT_URL' => pico_common_unhtmlspecialchars($content_uri4html), 'APPROVAL_URL' => XOOPS_URL . "/modules/{$this->mydirname}/index.php?page=contentmanager&content_id={$content_id}", 'CAT_TITLE' => $cat_data['cat_title'], 'CONTENT_SUBJECT' => $content_data['subject_raw']);
     // users2notify (can_readfull only)
     $users2notify = $picoPermission->getUidsFromCatid($this->mydirname, $cat_data['id'], 'can_readfull');
     if ($cat_data['post_auto_approved']) {
         // Notify for new content 'global'
         pico_main_trigger_event($this->mydirname, 'global', 0, 'newcontent', $extra_tags, $users2notify, 0);
         // Notify for new content 'category' of all parental categories
         foreach (array_keys($cat_data['paths_raw']) as $cat_id) {
             pico_main_trigger_event($this->mydirname, 'category', $cat_id, 'newcontent', $extra_tags, $users2notify, 0);
         }
         // message "registered"
         redirect_header($ret_uri4html, 2, _MD_PICO_MSG_CONTENTMADE);
     } else {
         // Notify for new waiting content (only for admin or mod)
         $users2notify = pico_main_get_moderators($this->mydirname, $cat_data['id']);
         if (empty($users2notify)) {
             $users2notify = array(0);
         }
         pico_main_trigger_event($this->mydirname, 'global', 0, 'waitingcontent', $extra_tags, $users2notify);
         // message "waiting approval"
         redirect_header($ret_uri4html, 2, _MD_PICO_MSG_CONTENTWAITINGREGISTER);
     }
     // view
     $this->is_need_header_footer = false;
 }
 function readWrappedFile($request)
 {
     $wrap_full_path = XOOPS_TRUST_PATH . _MD_PICO_WRAPBASE . '/' . $this->mydirname . $request['path_info'];
     ob_start();
     include $wrap_full_path;
     $full_content = pico_convert_encoding_to_ie(ob_get_contents());
     ob_end_clean();
     // parse full_content (get subject, body etc.)
     $file = substr(strrchr($wrap_full_path, '/'), 1);
     $mtime = intval(@filemtime($wrap_full_path));
     if (preg_match('/\\<title\\>([^<>]+)\\<\\/title\\>/is', $full_content, $regs)) {
         $subject = $regs[1];
     } else {
         $subject = $file;
     }
     if (preg_match('/\\<body[^<>]*\\>(.*)\\<\\/body\\>/is', $full_content, $regs)) {
         $body = $regs[1];
     } else {
         $body = $full_content;
     }
     $cat_data = $this->currentCategoryObj->getData();
     $link = empty($this->mod_config['use_rewrite']) ? 'index.php' . $request['path_info'] : substr($request['path_info'], 1);
     return array('id' => 0, 'link' => $link, 'created_time' => $mtime, 'created_time_formatted' => formatTimestamp($mtime), 'subject_raw' => pico_common_unhtmlspecialchars($subject), 'subject' => $subject, 'body' => $body, 'can_read' => $cat_data['isadminormod'] || $cat_data['can_read'], 'can_readfull' => $cat_data['isadminormod'] || $cat_data['can_readfull'], 'can_edit' => false, 'can_vote' => false);
 }
 function execute($request)
 {
     parent::execute($request);
     // $contentObj
     $contentObj =& new PicoContent($this->mydirname, $request['content_id'], $this->currentCategoryObj);
     // check existence
     if ($contentObj->isError()) {
         redirect_header(XOOPS_URL . "/modules/{$this->mydirname}/index.php", 2, _MD_PICO_ERR_READCONTENT);
         exit;
     }
     $cat_data = $this->currentCategoryObj->getData();
     $this->assign['category'] = $this->currentCategoryObj->getData4html();
     $content_data = $contentObj->getData();
     $this->assign['content'] = $contentObj->getData4html(true);
     $this->contentObjs['content'] =& $contentObj;
     // permission check
     if (empty($content_data['can_read']) || empty($content_data['can_readfull'])) {
         if ($this->uid > 0) {
             redirect_header(XOOPS_URL . '/', 2, _MD_PICO_ERR_PERMREADFULL);
         } else {
             redirect_header(XOOPS_URL . '/user.php', 2, _MD_PICO_ERR_LOGINTOREADFULL);
         }
         exit;
     }
     // auto-register
     if (!empty($this->mod_config['wraps_auto_register']) && @$cat_data['cat_vpath'][0] == '/' && $content_data['poster_uid'] == 0 && $content_data['vpath'] != '') {
         $register_class = empty($this->mod_config['auto_register_class']) ? 'PicoAutoRegisterWraps' : $this->mod_config['auto_register_class'];
         require_once dirname(dirname(__FILE__)) . '/class/' . $register_class . '.class.php';
         $register_obj =& new $register_class($this->mydirname, $this->mod_config);
         $is_updated = $register_obj->updateContent($content_data['content_id'], $content_data['vpath']);
         if ($is_updated > 0) {
             // reload if the content is updated
             header('Location: ' . pico_common_unhtmlspecialchars($this->assign['mod_url']) . '/' . pico_common_unhtmlspecialchars($this->assign['content']['link']));
             exit;
         }
     }
     // prev/next content
     $prevContentObj =& $contentObj->getPrevContent();
     $this->assign['prev_content'] = is_object($prevContentObj) ? $prevContentObj->getData4html() : array();
     $this->contentObjs['prev_content'] =& $prevContentObj;
     $nextContentObj =& $contentObj->getNextContent();
     $this->assign['next_content'] = is_object($nextContentObj) ? $nextContentObj->getData4html() : array();
     $this->contentObjs['next_content'] =& $nextContentObj;
     // link for "tell to friends"
     if ($this->mod_config['use_taf_module']) {
         $this->assign['content']['tellafriend_uri'] = XOOPS_URL . '/modules/tellafriend/index.php?target_uri=' . rawurlencode(XOOPS_URL . "/modules/{$this->mydirname}/" . pico_common_make_content_link4html($this->mod_config, $content_data)) . '&amp;subject=' . rawurlencode(sprintf(_MD_PICO_FMT_TELLAFRIENDSUBJECT, @$GLOBALS['xoopsConfig']['sitename']));
     } else {
         $this->assign['content']['tellafriend_uri'] = 'mailto:?subject=' . pico_main_escape4mailto(sprintf(_MD_PICO_FMT_TELLAFRIENDSUBJECT, @$GLOBALS['xoopsConfig']['sitename'])) . '&amp;body=' . pico_main_escape4mailto(sprintf(_MD_PICO_FMT_TELLAFRIENDBODY, $content_data['subject'])) . '%0A' . XOOPS_URL . "/modules/{$this->mydirname}/" . rawurlencode(pico_common_make_content_link4html($this->mod_config, $content_data));
     }
     // category list can be read for category jumpbox etc.
     $categoryHandler =& new PicoCategoryHandler($this->mydirname, $this->permissions);
     $categories = $categoryHandler->getAllCategories();
     $this->assign['categories_can_read'] = array();
     foreach ($categories as $tmpObj) {
         $tmp_data = $tmpObj->getData();
         $this->assign['categories_can_read'][$tmp_data['id']] = str_repeat('--', $tmp_data['cat_depth_in_tree']) . $tmp_data['cat_title'];
     }
     // count up 'viewed'
     if ($content_data['modifier_ip'] != @$_SERVER['REMOTE_ADDR']) {
         $contentObj->incrementViewed();
     }
     // breadcrumbs
     $breadcrumbsObj =& AltsysBreadcrumbs::getInstance();
     $breadcrumbsObj->appendPath('', $this->assign['content']['subject']);
     $this->assign['xoops_breadcrumbs'] = $breadcrumbsObj->getXoopsbreadcrumbs();
     $this->assign['xoops_pagetitle'] = $this->assign['content']['subject'];
     // views
     switch ($request['view']) {
         case 'singlecontent':
             $this->template_name = 'db:' . $this->mydirname . '_independent_singlecontent.html';
             $this->is_need_header_footer = false;
             break;
         case 'print':
             $this->template_name = 'db:' . $this->mydirname . '_independent_print.html';
             $this->is_need_header_footer = false;
             break;
         default:
             $this->template_name = empty($this->mod_config['tpl_viewcontent']) ? $this->mydirname . '_main_viewcontent.html' : $this->mod_config['tpl_viewcontent'];
             $this->is_need_header_footer = true;
             break;
     }
     // htmlheader
     if (!empty($this->mod_config['allow_each_htmlheader'])) {
         $this->html_header .= $content_data['htmlheader'];
     }
 }
 function getFileInfo($vpath)
 {
     $wrap_full_path = $this->wrap_base . $vpath;
     ob_start();
     include $wrap_full_path;
     $full_content = pico_convert_encoding_to_ie(ob_get_contents());
     ob_end_clean();
     // file name
     $filename = substr(strrchr($wrap_full_path, '/'), 1);
     // parse full_content (get subject, body etc.)
     if (preg_match('/\\<title\\>([^<>]+)\\<\\/title\\>/is', $full_content, $regs)) {
         $subject = pico_common_unhtmlspecialchars($regs[1]);
     } else {
         $subject = false;
     }
     if (preg_match('/\\<body[^<>]*\\>(.*)\\<\\/body\\>/is', $full_content, $regs)) {
         $body = $regs[1];
     } else {
         $body = $full_content;
     }
     return array('mtime' => intval(@filemtime($wrap_full_path)), 'subject' => $subject, 'subject_alt' => $subject ? $subject : $filename, 'filename' => $filename, 'body' => $body);
 }