Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2017, 04:32 PM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vBulletin 4 Request - Little help wrapping some PHP with my page style.

I need your help.

Ive been trying to wrap the below code with my sites header, footer, style but I keep getting errors. The code below works on the forum root. The page is called cpg_index.php. Any help would be great.

Thanks.

Code:
<?php
$delta = 24;
$reduce_brightness = true;
$reduce_gradients = true;
$num_results = 20;

include_once("colors.inc.php");
$ex=new GetMostCommonColors();
$colors=$ex->Get_Color("test.jpg", $num_results, $reduce_brightness, $reduce_gradients, $delta);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<title>Image Color Extraction</title>
	<style type="text/css">
		* {margin: 0; padding: 0}
		body {text-align: center;}
		form, div#wrap {margin: 10px auto; text-align: left; position: relative; width: 500px;}
		fieldset {padding: 20px; border: solid #999 2px;}
		img {width: 200px;}
		table {border: solid #000 1px; border-collapse: collapse;}
		td {border: solid #000 1px; padding: 2px 5px; white-space: nowrap;}
		br {width: 100%; height: 1px; clear: both; }
	</style>
</head>
<body>
<div id="wrap">
<form action="#" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Upload Your Own Image</legend>
<input type="file" name="imgFile" />
<input type="submit" name="action" value="Process" />
</fieldset>
</form>
<?php
// was any file uploaded?
if ( isset( $_FILES['imgFile']['tmp_name'] ) && strlen( $_FILES['imgFile']['tmp_name'] ) > 0 )
{
	// move image to a writable directory
	if (! move_uploaded_file($_FILES['imgFile']['tmp_name'], 'images/'.$_FILES['imgFile']['name']))
	{
		die("Error moving uploaded file to images directory");
	}
	$colors=$ex->Get_Color( 'images/'.$_FILES['imgFile']['name'], $num_results, $reduce_brightness, $reduce_gradients, $delta);
?>
<table>
<tr><td>Color</td><td>Color Code</td><td>Percentage</td><td rowspan="<?php echo (($num_results > 0)?($num_results+1):22500);?>"><img src="<?='images/'.$_FILES['imgFile']['name']?>" alt="test image" /></td></tr>
<?php
foreach ( $colors as $hex => $count )
{
	if ( $count > 0 )
	{
		echo "<tr><td style=\"background-color:#".$hex.";\"></td><td>".$hex."</td><td>$count</td></tr>";
	}
}
?>
</table>
<br />
<?php
}
?>

</div>
</body>
</html>
Reply With Quote
  #2  
Old 07-22-2017, 04:35 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What error are you receiving?

P.S. Just a heads up that the script you posted is vulnerable to arbitrary file upload, anyone can upload any kind of file to your server, including backdoors which can take over your server and interact with your database in any kind of way you can imagine.
Reply With Quote
  #3  
Old 07-22-2017, 04:53 PM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That sucks. Any way to limit the file types to just images?

--------------- Added [DATE]1500750280[/DATE] at [TIME]1500750280[/TIME] ---------------

Well I just tried to upload other file types and all I got was ton of errors. I checked the upload folder and nothing but images. Still Im sure your right and there is a way but maybe if the form was wrapped in a condition to only show to members that would cut down some of the risk. Maybe a captia also...

--------------- Added [DATE]1500750798[/DATE] at [TIME]1500750798[/TIME] ---------------

And just a thought.

Can the code above be tweaked to use on a CMS PSP Page? Ive never tried to use PHP that way I always use it on an external page.

Again thanks for the help.
Reply With Quote
  #4  
Old 07-22-2017, 05:56 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You will find this article useful:

[HOW TO - vB4] Create your own vBulletin page
Reply With Quote
  #5  
Old 07-22-2017, 06:07 PM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
You will find this article useful:

[HOW TO - vB4] Create your own vBulletin page

Thanks Mark thats actually what Ive been trying to do. Still getting errors.
Reply With Quote
  #6  
Old 07-22-2017, 06:21 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've used the method described in that article many times to create custom pages which include the header/footer and it has always worked very well for me.
Reply With Quote
  #7  
Old 07-22-2017, 07:22 PM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ive used that method just fine if Im only adding simply html but the trick is getting the PHP to work. Still stuck. Anyone?
Reply With Quote
  #8  
Old 07-22-2017, 09:18 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I generally put the php in the external script, and then have the HTML rendered using a custom template. For example, in my "Profile Reporter" product, I use the following external script to render the custom page:

PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

$vbulletin->options['mypage'] = $_SERVER['HTTP_REFERER'];

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''reportprofile');
define('CSRF_PROTECTION'true);  

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('markfl_reportprofile_form');

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

// ###### YOUR CUSTOM CODE GOES HERE #####
$navbits construct_navbits(array('' => $vbphrase['markfl_rp_pagetitle']));
$navbar render_navbar_template($navbits);
$pagetitle $vbphrase['markfl_rp_pagetitle'];
$reporteduserid $_REQUEST['userid'];
$reporteruserid $vbulletin->userinfo['userid'];

if (
$reporteruserid AND $reporteduserid)
{
    
$user_data $vbulletin->db->query_read_slave("
        SELECT user.*
        FROM " 
TABLE_PREFIX "user AS user
        WHERE userid = " 
intval($reporteduserid)
    );


    
$user_stats $db->fetch_array($user_data);

    
$reportedusername $user_stats['username'];

    
$all_reasons $vbphrase['markfl_rp_reasons'] . ',' $vbphrase['markfl_rp_reasonsother'];

    
$reasons array_filter(explode(','$all_reasons));
    
$text_height count($reasons) * 16;
    
$rp_checkboxes '';
    
$rp_conditional = array();

    foreach (
$reasons as $reason)
    {
        
$elname strtolower(str_replace(' '''$reason));
        
$rp_checkboxes .= '<div>' $reason '</div><input type="checkbox" name="' $elname '" /><br>';
        
$rp_conditional[] = 'document.getElementsByName("' $elname '")[0].checked';
    }

    
$rp_condition implode(' || '$rp_conditional);

    
// ###### NOW THE TEMPLATES ARE BEING RENDERED ######

    
$templater vB_Template::create('markfl_reportprofile_form');
    
$templater->register_page_templates();
    
$templater->register('navbar'$navbar);
    
$templater->register('pagetitle'$pagetitle);
    
$templater->register('reporteduserid'$reporteduserid);
    
$templater->register('reporteruserid'$reporteruserid);
    
$templater->register('reportedusername'$reportedusername);
    
$templater->register('rp_checkboxes'$rp_checkboxes);
    
$templater->register('text_height'$text_height);
    
$templater->register('rp_condition'$rp_condition);

    
print_output($templater->render());
}
else
{
    
print_no_permission();
}

?>
And this script renders the custom template:

HTML Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
	<head>
		<title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
		<vb:if condition="$vboptions['storecssasfile']">
			{vb:cssfile forumhome-rollup.css}
		<vb:else />
			{vb:cssfile forumbits.css,forumhome.css,options.css}
	        </vb:if>
		{vb:raw headinclude}
		{vb:raw headinclude_bottom}
		<style type="text/css">
#report_profile form {
	margin-bottom: 2.5em;
}

.wgo_block {
	border: {vb:stylevar formrow_border};
}

#rpform {
	padding: 5px;
	margin-bottom: 1em;
}

#rpform fieldset {
	border: {vb:stylevar formrow_border};
	padding: 5px;
}

#rpform fieldset:first-of-type {
	display: inline-block;
	width: 25%;
}

#rpform fieldset:last-of-type {
	float: right;
	width: 70%;
}

#rpform fieldset div {
	display: inline-block;
	min-height: 16px;
}

#rpform fieldset div::after {
	content: ":";
}

#rpform fieldset input {
	float: right;
	margin-top: 2px;
}

legend::before {
	content: "\00a0";
}

legend::after {
	content: ":\00a0";
}

textarea {
	resize: none;
	height: {vb:raw text_height}px;
	width: 100%;
	font-size: 14px;
	font-family: Arial;
}

#fbuttons {
	float: right;
	margin-top: 10px;
}

#fbuttons input {
	cursor: pointer;
}

#explain {
	padding: 5px;
	text-align: justify;
}
		</style>
		<script>
function checkEmpty() {
	if (!({vb:raw rp_condition}))
	{
		return 0;
	}
	else if (document.getElementsByName("other")[0].checked && !document.getElementsByName("comment")[0].value)
	{
		return 1;
	}
	else
	{
		return 2;
	}
}
		</script>
	</head>
	<body>
		{vb:raw header}
		{vb:raw navbar}

		<div id="report_profile" class="wgo_block">
			<h2 class="blockhead">
				{vb:rawphrase markfl_rp_header, {vb:raw reportedusername}}
			</h2>
			<form name="reportprofile_form" method="post" action="reportprofilethread.php">
				<input type="hidden" name="url" value="{vb:raw $_SERVER['HTTP_REFERER']}" />
				<input type="hidden" name="reporteduser" value="{vb:raw reportedusername}" />
				<input type="hidden" name="reporteruserid" value="{vb:raw reporteruserid}" />
				<input type="hidden" name="reporteduserid" value="{vb:raw reporteduserid}" />
				<div id="rpform">
					<fieldset>
						<legend>{vb:rawphrase markl_rp_legendreasons}</legend>
						{vb:raw rp_checkboxes}
 					</fieldset>
					<fieldset>
						<legend>{vb:rawphrase markl_rp_legendcomments}</legend>
							<textarea name="comment"></textarea>
					</fieldset>
					<div id="fbuttons">
						<input title="{vb:rawphrase markfl_rp_formresettitle}" class="button" type="reset" name="rpreset" value="{vb:rawphrase markfl_rp_formreset}" />
						<input title="{vb:rawphrase markfl_rp_form_submittitle}" class="button" type="submit" name="rpsubmit" value="{vb:rawphrase markfl_rp_form_submit}" onclick="var state = checkEmpty(); if (state == 0){alert('{vb:rawphrase markfl_rp_form_submitemptyalert}'); return false;} else if (state == 1) {alert('{vb:rawphrase markfl_rp_form_submitotheralert}'); return false;}" />
					</div>
				</div>
			</form>
			<div id="explain">
				{vb:rawphrase markfl_rp_formexplain}
			</div>
		</div>

		{vb:raw footer}
	</body>
</html>
Reply With Quote
  #9  
Old 07-24-2017, 05:20 PM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ive been trying that but the multiple instances of opened and closed PHP are screwing me up. I either get Global.php errors or just the form shows up with no formatting.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:14 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04089 seconds
  • Memory Usage 2,299KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete