News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Where does the posting go on?

Started by MLM, February 27, 2011, 04:14:35 PM

Previous topic - Next topic

ascaland

So let me get this straight... Your adding a new field to the post template so when people post they have the option to set this field, which would then get sent to the database am I right?

MLM

post.php (right above this: // This is a new topic or an already existing one. Save it.)

// featured work stuff
$featured_work_image_url = $_POST['featured_work_image_url'];
$featured_work_image_title = $_POST['featured_work_image_title'];
$featured_work_image_creator = $context['username'];

if(!empty($featured_work_image_url))
{
$Regex = '/http://([\w-]+\.)+[\w-]+(/[\w- ./]*)+\.(?:gif|jpg|jpeg|png|bmp|GIF|JPEG|JPG|PNG|BMP|Gif|Jpg|Jpeg|Png|Bmp)$/';

// checking if this is even an image url
if(preg_match($Regex, $featured_work_image_url))
{

// figure out the dimensions...
list($image_width, $image_height, $image_type, $image_attr) = getimagesize($featured_work_image_url);

// making the proportions
if($image_width < 283 && $image_height < 143)
{
}
else
{

$image_ratio = $image_width/$image_height;

if($image_width > $image_height)
{

$image_ratio = $image_width/$image_height;

while ($image_width > 287)
{
$image_width = $image_width - $image_ratio;
$image_height--;
}

// is the image height still too big?
if($image_height > 143)
{
$image_ratio = $image_height/$image_width;

while ($image_height > 143)
{
$image_height = $image_height - $image_ratio;
$image_width--;
}
}
}
else
{

$image_ratio = $image_height/$image_width;

while ($image_height > 143)
{
$image_height = $image_height - $image_ratio;
$image_width--;
}

// is the image width still too big?
if($image_height > 287)
{
$image_ratio = $image_width/$image_height;

while ($image_width > 287)
{
$image_width = $image_width - $image_ratio;
$image_height--;
}
}
}
}

// rounding our values to the nearest pixel
$featured_image_width = round($image_width);
$featured_image_height = round($image_height);






$feature_text = "n";
$featured_work_topic_id = "UNKNOWN";

// insert everything into the db
            mysql_query("INSERT INTO  vp_featured_work_entries (topic_id, feature, title, creator, image, width, height) VALUES('$featured_work_topic_id', '$feature_text', '$featured_work_image_title', '$featured_work_image_creator', '$featured_work_image_url', '$featured_image_width', '$featured_image_height') ") or die(mysql_error());
       
}
else
{
$post_errors[] = 'featured_work_not_image_error';
}


}



post.template.php (right above: // Is visual verification enabled?)

// featured work Submission
echo '
<dl id="postAttachment2">
<dt>
Featured Work Submission:
</dt>
<dd class="smalltext">
<div class="featured_work_post_template_div">Title: <input name="featured_work_image_title"></input></div>
<div class="featured_work_post_template_div">Image URL: <input name="featured_work_image_url"></input></div>
</dd>

</dl>
';

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

ascaland

Ok, you have a couple of things mixed up. Lets start with Post.php.

Your creating the error way too late in the script. You should be creating the error above this snippet,
// Any mistakes?
if (!empty($post_errors))
{
loadLanguage('Errors');
// Previewing.
$_REQUEST['preview'] = true;

$context['post_error'] = array('messages' => array());
foreach ($post_errors as $post_error)
{
$context['post_error'][$post_error] = true;
if ($post_error == 'long_message')
$txt['error_' . $post_error] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);

$context['post_error']['messages'][] = $txt['error_' . $post_error];
}

return Post();
}

Because that is where each error is being checked and if so, returning back to the post template. This being said, your going to have to figure out which codes need to go where. So to do the error checking properly, you must move a part of the snippet higher up in the script.

Next, createPost() from Subs-Post.php is where you should be submitting the post data to the database. Maybe you should take a look at this modification here and see if you can figure it out,
http://custom.simplemachines.org/mods/index.php?mod=349

That should be more than enough to help you.
About your snippet in the Post.template.php file, your input tags should be fixed up a bit. Such as adding the type attribute, etc.

MLM

Thanks a bunch Project Evolution

My error seems to be still working without adding to that array thing up top.

I added my code to the subs-post above creatPost and now it is giving my error that it isn't a image url when i try to post. It is probably just my regex or coding though.

I am going to bed now so wont be able to reply until tomorrow afternoon.

Thanks for all the help so far and if you happen to find the proper regex for a image url, please post.

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

MLM

Is there a variable to use so i can get the member name of the person posting for example $context['username']

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

ascaland

Quote from: Project Evolution on February 27, 2011, 08:23:39 PMAnd since $user_id is accessible here you can easily just use $user_id['name'] (or $user_id['username'] if your looking for the username).

Arantor

There is no such variable in SMF, look in $context['user']['id'] instead

MLM

$user_id['username'] does not seem to be working. Perhaps i need to call a global although it isnt it a function (just above the creatPost())

Also if i want to make sure it doesn't submit to db if the message/ thread/ post has errors how do i check and get all possible errors before submitting it.

Could i put my code underneath the creatPost function and if($post_errors) around my code.

Also if below could i get the topic id that is being submitted?

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

ascaland

Oops, I meant to say $user_info. Ive been thinking $user_id exists lately. :P

MLM

$user_info['username'] worked great thanks Project Evolution and Arantor!

Any info on other problems/ questions?

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Arantor

QuoteAlso if i want to make sure it doesn't submit to db if the message/ thread/ post has errors how do i check and get all possible errors before submitting it.

Could i put my code underneath the creatPost function and if($post_errors) around my code.

Also if below could i get the topic id that is being submitted?

No, you can't do that, you HAVE to do it sooner than that like I already pointed out, putting all tests before return Post() in the case of errors.

-sigh- I would answer the rest of the questions then remember that all of the answers to all of those questions came from me earlier in this thread.

MLM

Well i put it under createpost() and seems to be working fine...

I am trying to do this to get the topic id but its not working.. There has got to be a way to find the topic id.
$featured_work_topic_id = createPost($topicOptions['id']);

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

MLM

Disregard all that info.

I dont know. I see what Arantor is saying now. I see all my answers in posts before. I have no idea how i could of missed them unless you edited afterwards.

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

MLM

ugh, I am sure this is bothering you because it is for me but the $topicOptions['id']; really isnt working. All my code is below the createpost even. It works completely awesome except i always get a 0 for topic id. I have tried globaling it by having it equal the global and then using it in the db insertion.

I need a variable that well give me the topic id of the topic that is being posted.

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

ascaland

Can you show me the code and EXACTLY where your putting it.

MLM

Right above createAttachment() on subs-post - Its there because i think i have a better chance of getting the topic id. It was above createPost() before today..


         // featured work stuff
$featured_work_image_url = $_POST['featured_work_image_url'];
$featured_work_image_title = $_POST['featured_work_image_title'];
$featured_work_image_creator = $user_info['username'];
$featured_work_topic_id = $topicOptions['id'];

if(!empty($featured_work_image_url) && !empty($featured_work_image_title))
{
$Regex = '/http:\/\/(.*?)png|jpg|gif/';

// checking if this is even an image url
if(preg_match($Regex, $featured_work_image_url))
{

// figure out the dimensions...
list($image_width, $image_height, $image_type, $image_attr) = getimagesize($featured_work_image_url);

// making the proportions
if($image_width < 283 && $image_height < 143)
{
}
else
{

$image_ratio = $image_width/$image_height;

if($image_width > $image_height)
{

$image_ratio = $image_width/$image_height;

while ($image_width > 287)
{
$image_width = $image_width - $image_ratio;
$image_height--;
}

// is the image height still too big?
if($image_height > 143)
{
$image_ratio = $image_height/$image_width;

while ($image_height > 143)
{
$image_height = $image_height - $image_ratio;
$image_width--;
}
}
}
else
{

$image_ratio = $image_height/$image_width;

while ($image_height > 143)
{
$image_height = $image_height - $image_ratio;
$image_width--;
}

// is the image width still too big?
if($image_height > 287)
{
$image_ratio = $image_width/$image_height;

while ($image_width > 287)
{
$image_width = $image_width - $image_ratio;
$image_height--;
}
}
}
}

// rounding our values to the nearest pixel
$featured_image_width = round($image_width);
$featured_image_height = round($image_height);






$feature_text = "n";

// insert everything into the db
mysql_query("INSERT INTO  vp_featured_work_entries (topic_id, feature, title, creator, image, width, height) VALUES('$featured_work_topic_id', '$feature_text', '$featured_work_image_title', '$featured_work_image_creator', '$featured_work_image_url', '$featured_image_width', '$featured_image_height') ") or die(mysql_error());

}
else
{
$post_errors[] = 'featured_work_not_image_error';
}


}
else
{
if(empty($featured_work_image_url) && empty($featured_work_image_title))
{
}
else
{
if(empty($featured_work_image_url))
{
$post_errors[] = 'featured_work_no_image_url_error';
}

if(empty($featured_work_image_title))
{
$post_errors[] = 'featured_work_no_title_error';
}
}
}

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

ascaland

I dont understand what you mean by above these functions you need to be more specific. And I see your still not taking Arantor's advice with handling the errors.

The majority of that code shouldnt even be in createPost() anyways. I suggest you take the time to look back at what we have been telling you to do because this obviously isnt working out.

MLM

Its not in createPost()...

It is below createPost() above createAttachment().

Errors work great the way they are set up now...

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

ascaland

Quote from: MLM on February 28, 2011, 09:24:03 PM
Its not in createPost()...

It is below createPost() above createAttachment().

Errors work great the way they are set up now...

So the code is outside of any function?

MLM


My Themes:

My Mods:

Unsolved Threads:
  • None atm...

Advertisement: