示例#1
0
function init_display_template($template_var, $replacement, $filename = 'viewtopic_attach_body.tpl')
{
    global $template;
    //
    // This function is adapted from the old template class
    // I wish i had the functions from the 2.2 one. :D (This class rocks, can't await to use it in Mods)
    //
    //
    // Handle Attachment Informations
    //
    if (!isset($template->uncompiled_code[$template_var]) && empty($template->uncompiled_code[$template_var])) {
        // If we don't have a file assigned to this handle, die.
        if (!isset($template->files[$template_var])) {
            die("Template->loadfile(): No file specified for handle {$template_var}");
        }
        $filename_2 = $template->files[$template_var];
        $str = implode("", @file($filename_2));
        if (empty($str)) {
            die("Template->loadfile(): File {$filename_2} for handle {$template_var} is empty");
        }
        $template->uncompiled_code[$template_var] = $str;
    }
    $complete_filename = $filename;
    if (substr($complete_filename, 0, 1) != '/') {
        $complete_filename = $template->root . '/' . $complete_filename;
    }
    if (!file_exists($complete_filename)) {
        die("Template->make_filename(): Error - file {$complete_filename} does not exist");
    }
    $content = implode('', file($complete_filename));
    if (empty($content)) {
        die('Template->loadfile(): File ' . $complete_filename . ' is empty');
    }
    // replace $replacement with uncompiled code in $filename
    $template->uncompiled_code[$template_var] = str_replace($replacement, $content, $template->uncompiled_code[$template_var]);
    //
    // Force Reload on cached version
    //
    display_compile_cache_clear($template->files[$template_var], $template_var);
}
示例#2
0
 /**
  * Display the Attach Limit Box (move it to displaying.php ?)
  */
 function display_attach_box_limits()
 {
     global $folder, $attach_config, $board_config, $template, $lang, $userdata, $db;
     // Begin PNphpBB2 Module
     global $phpbb_theme;
     // End PNphpBB2 Module
     if (!$attach_config['allow_pm_attach'] && $userdata['user_level'] != ADMIN) {
         return;
     }
     $this->get_quota_limits($userdata);
     $pm_filesize_limit = !$attach_config['pm_filesize_limit'] ? $attach_config['attachment_quota'] : $attach_config['pm_filesize_limit'];
     $pm_filesize_total = get_total_attach_pm_filesize('to_user', (int) $userdata['user_id']);
     $attach_limit_pct = $pm_filesize_limit > 0 ? round($pm_filesize_total / $pm_filesize_limit * 100) : 0;
     $attach_limit_img_length = $pm_filesize_limit > 0 ? round($pm_filesize_total / $pm_filesize_limit * $board_config['privmsg_graphic_length']) : 0;
     if ($attach_limit_pct > 100) {
         $attach_limit_img_length = $board_config['privmsg_graphic_length'];
     }
     $attach_limit_remain = $pm_filesize_limit > 0 ? $pm_filesize_limit - $pm_filesize_total : 100;
     $l_box_size_status = sprintf($lang['Attachbox_limit'], $attach_limit_pct);
     // Begin PNphpBB2 Module
     $template->set_filenames(array('attachsize' => 'privmsgs_attach_size_box.tpl'));
     display_compile_cache_clear($template->files['attachsize'], 'attachsize');
     // End PNphpBB2 Module
     $template->assign_vars(array('ATTACHBOX_LIMIT_IMG_WIDTH' => $attach_limit_img_length, 'ATTACHBOX_LIMIT_PERCENT' => $attach_limit_pct, 'ATTACH_BOX_SIZE_STATUS' => $l_box_size_status, 'T_TD_COLOR2' => '#' . $phpbb_theme['td_color2']));
     // Begin PNphpBB2 Module
     $template->assign_var_from_handle('PM_ATTACH_LIMIT', 'attachsize');
     // End PNphpBB2 Module
 }
 /**
  * Attachment Mod entry switch/output (intern)
  * @private
  */
 function display_attachment_bodies()
 {
     global $attach_config, $db, $is_auth, $lang, $mode, $phpEx, $template, $upload_dir, $userdata, $HTTP_POST_VARS, $forum_id;
     global $phpbb_root_path;
     // Choose what to display
     $value_add = $value_posted = 0;
     if (intval($attach_config['show_apcp'])) {
         if (!empty($HTTP_POST_VARS['add_attachment_box'])) {
             $value_add = $this->add_attachment_body == 0 ? 1 : 0;
             $this->add_attachment_body = $value_add;
         } else {
             $value_add = $this->add_attachment_body == 0 ? 0 : 1;
         }
         if (!empty($HTTP_POST_VARS['posted_attachments_box'])) {
             $value_posted = $this->posted_attachments_body == 0 ? 1 : 0;
             $this->posted_attachments_body = $value_posted;
         } else {
             $value_posted = $this->posted_attachments_body == 0 ? 0 : 1;
         }
         $template->assign_block_vars('show_apcp', array());
     } else {
         $this->add_attachment_body = 1;
         $this->posted_attachments_body = 1;
     }
     $template->set_filenames(array('attachbody' => 'posting_attach_body.tpl'));
     display_compile_cache_clear($template->files['attachbody'], 'attachbody');
     $s_hidden = '<input type="hidden" name="add_attachment_body" value="' . $value_add . '" />';
     $s_hidden .= '<input type="hidden" name="posted_attachments_body" value="' . $value_posted . '" />';
     if ($this->page == PAGE_PRIVMSGS) {
         $u_rules_id = 0;
     } else {
         $u_rules_id = $forum_id;
     }
     $template->assign_vars(array('L_ATTACH_POSTING_CP' => $lang['Attach_posting_cp'], 'L_ATTACH_POSTING_CP_EXPLAIN' => $lang['Attach_posting_cp_explain'], 'L_OPTIONS' => $lang['Options'], 'L_ADD_ATTACHMENT_TITLE' => $lang['Add_attachment_title'], 'L_POSTED_ATTACHMENTS' => $lang['Posted_attachments'], 'L_FILE_NAME' => $lang['File_name'], 'L_FILE_COMMENT' => $lang['File_comment'], 'RULES' => '<a href="' . append_sid($phpbb_root_path . "attach_rules.{$phpEx}?f={$u_rules_id}") . '" target="_blank">' . $lang['Allowed_extensions_and_sizes'] . '</a>', 'S_HIDDEN' => $s_hidden));
     $attachments = array();
     if (sizeof($this->attachment_list) > 0) {
         if (intval($attach_config['show_apcp'])) {
             $template->assign_block_vars('switch_posted_attachments', array());
         }
         for ($i = 0; $i < sizeof($this->attachment_list); $i++) {
             $hidden = '<input type="hidden" name="attachment_list[]" value="' . $this->attachment_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="filename_list[]" value="' . $this->attachment_filename_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="extension_list[]" value="' . $this->attachment_extension_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="mimetype_list[]" value="' . $this->attachment_mimetype_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="filesize_list[]" value="' . $this->attachment_filesize_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="filetime_list[]" value="' . $this->attachment_filetime_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="attach_id_list[]" value="' . $this->attachment_id_list[$i] . '" />';
             $hidden .= '<input type="hidden" name="attach_thumbnail_list[]" value="' . $this->attachment_thumbnail_list[$i] . '" />';
             if (!$this->posted_attachments_body || sizeof($this->attachment_list) == 0) {
                 $hidden .= '<input type="hidden" name="comment_list[]" value="' . $this->attachment_comment_list[$i] . '" />';
             }
             $template->assign_block_vars('hidden_row', array('S_HIDDEN' => $hidden));
         }
     }
     if ($this->add_attachment_body) {
         init_display_template('attachbody', '{ADD_ATTACHMENT_BODY}', 'add_attachment_body.tpl');
         $form_enctype = 'enctype="multipart/form-data"';
         $template->assign_vars(array('L_ADD_ATTACH_TITLE' => $lang['Add_attachment_title'], 'L_ADD_ATTACH_EXPLAIN' => $lang['Add_attachment_explain'], 'L_ADD_ATTACHMENT' => $lang['Add_attachment'], 'FILE_COMMENT' => $this->file_comment, 'FILESIZE' => $attach_config['max_filesize'], 'FILENAME' => $this->filename, 'S_FORM_ENCTYPE' => $form_enctype));
     }
     if ($this->posted_attachments_body && sizeof($this->attachment_list) > 0) {
         init_display_template('attachbody', '{POSTED_ATTACHMENTS_BODY}', 'posted_attachments_body.tpl');
         $template->assign_vars(array('L_POSTED_ATTACHMENTS' => $lang['Posted_attachments'], 'L_UPDATE_COMMENT' => $lang['Update_comment'], 'L_UPLOAD_NEW_VERSION' => $lang['Upload_new_version'], 'L_DELETE_ATTACHMENT' => $lang['Delete_attachment'], 'L_DELETE_THUMBNAIL' => $lang['Delete_thumbnail'], 'L_OPTIONS' => $lang['Options']));
         for ($i = 0; $i < sizeof($this->attachment_list); $i++) {
             if ($this->attachment_id_list[$i] == 0) {
                 $download_link = $upload_dir . '/' . basename($this->attachment_list[$i]);
             } else {
                 $download_link = append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $this->attachment_id_list[$i]);
             }
             $template->assign_block_vars('attach_row', array('FILE_NAME' => $this->attachment_filename_list[$i], 'ATTACH_FILENAME' => $this->attachment_list[$i], 'FILE_COMMENT' => $this->attachment_comment_list[$i], 'ATTACH_ID' => $this->attachment_id_list[$i], 'U_VIEW_ATTACHMENT' => $download_link));
             // Thumbnail there ? And is the User Admin or Mod ? Then present the 'Delete Thumbnail' Button
             if (intval($this->attachment_thumbnail_list[$i]) == 1 && (isset($is_auth['auth_mod']) && $is_auth['auth_mod'] || $userdata['user_level'] == ADMIN)) {
                 $template->assign_block_vars('attach_row.switch_thumbnail', array());
             }
             if ($this->attachment_id_list[$i]) {
                 $template->assign_block_vars('attach_row.switch_update_attachment', array());
             }
         }
     }
     $template->assign_var_from_handle('ATTACHBOX', 'attachbody');
 }
示例#4
0
function init_display_template($template_var, $replacement, $filename = 'forums/viewtopic_attach_body.html')
{
    global $template;
    //
    // Handle Attachment Informations
    //
    if (!isset($template->uncompiled_code[$template_var])) {
        // If we don't have a file assigned to this handle, die.
        if (!isset($template->files[$template_var])) {
            die("Template->loadfile(): No file specified for attachment handle {$template_var}");
        }
        $filename_2 = $template->files[$template_var];
        //		  die("Filename: $filename_2");
        $str = implode("", file($filename_2));
        if (empty($str)) {
            die("Template->loadfile(): File {$filename_2} for attachment handle {$template_var} is empty");
        }
        $template->uncompiled_code[$template_var] = $str;
    }
    $complete_filename = $filename;
    if (substr($complete_filename, 0, 1) != '/') {
        $complete_filename = $template->root . '/' . $complete_filename;
    }
    if (!file_exists(amod_realpath($complete_filename))) {
        die("Template->make_filename(): Error - file {$complete_filename} does not exist for displaying");
    }
    $content = implode('', file($complete_filename));
    if (empty($content)) {
        die('Template->loadfile(): File ' . $complete_filename . ' is empty');
    }
    // replace $replacement with uncompiled code in $filename
    $template->uncompiled_code[$template_var] = str_replace($replacement, $content, $template->uncompiled_code[$template_var]);
    //
    // Force Reload on cached version
    //
    display_compile_cache_clear($template->files[$template_var], $template_var);
}