I ran into a small problem what i cant really solve.
I created a delete function for videos in fuel php with orm, and maybe its a but stupid but i cant really figure out how to redirext the user if and id doest not exsits.
here is my code
public function action_delete($id)
{
$deletevideo = Model_Video::find($id);
if($deletevideo->user_id != Session::get('sentry_user')):
Session::set_flash('fail', 'The video you want to remove is not yours, we logged this activity');
Response::redirect(Uri::base() . "myvideos");
else:
unlink(realpath("users/video/" . $deletevideo->video_preview));
unlink(realpath("users/video/" . $deletevideo->video_file));
$deletevideo->delete();
Response::redirect(Uri::base() . "myvideos");
endif;
}
html
Delete
I saw in a forum people talked about DB::expr to achive this but can find any example about it.
Could please someone give me a hint?
Here is some code that should get you going:
$video = Model_Video::find($id);
if ( ! $video instanceof Model_Video)
{
Session::set_flash('fail', 'The video ID is not valid!');
Response::redirect('go/somewhere/else');
}
You should always check if the result is in fact a valid Model_Video before using it.
Related
I'm trying to get some PHP to check if a specific value is pulled out of an array, but I'm having trouble getting it to work. It actually causes the site to go black.
<?php
$message_array = file("http://www.example.com/wp-content/themes/mytheme/Subtitles.css");
$message = array_rand($message_array);
echo "$message_array[$message]";
$GfCheck = "<audio id='audio' src='example.com/wp-content/uploads/2016/01/example.wav'; preload='auto' ></audio><a onclick='GFFUNC()'><img src='example.com/wp-content/uploads/2016/01/Gf.png'; height='90px' alt='gf' title='gf'/></a>";
if ($message_array[$message] == $GfCheck) { $Gf = "1" } else { }
?>
the $Gf would then in turn add a secret section to a menu later on.
Can anyone help me figure out what's going wrong?
Thanks in advance for your help!
Answer largely came from Rizier123's comments on the main post.
While the file tag did not work, the code did in the end. I am left with an issue of global variables now, but the hard part is done!
I'm trying to get a list of all my subscriptions in Woocommerce. I have read about WC_Subscriptions_Manager::get_subscription(), but I don't know how to use it. Please keep in mind that I have almost zero knowledge concerning PHP.
Someone asked a similar question on the forum. I finally used the following code:
<?php if(isset($_REQUEST['Action']))
{
$Action = $_REQUEST['Action'];
switch($Action)
{
case "ValidateSubscription":
include('../../wp-load.php'); //Guessing this path based on your code sample... should be wp root
$Subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions();
print_r($Subscriptions);
break;
default:
echo "invalid action";
}
}else
{
echo "no action specified";
}
?>
How can I use it?
Thanks for your help!
You can use wcs_get_users_subscriptions(). If you don't pass a user_id argument, the default is to get the current user. The function returns all subscriptions.
i wan to change the text in a DIV based on the page they redirected from..
is there any if condition for this... or any code which helps me to do this... searched all the internet.. but didn't find it :(
if users reducers from google.com i want to show hello googler! if he came from my friends site, hello xxx reader. (Xxx = my friends blog name). if he is a direct visitor, hello visitor. like this....
hope you guys can help me! Thanks!!
UPDATE
in other question in stackoverflow, i found this ode (ASP.NET) i need a similar one in php.
in this ASP code he writes ENDS WITH(" ") but i want to write the FULL url there.
protected void Page_Load(object sender, EventArgs e)
{
string requestUrl = "";
. . .
if (requestUrl.ToString().EndsWith("Page1.aspx"))
label.Text = "foo";
else
label.Text = "bar";
}
Thank you!
$_SERVER['HTTP_REFERER'] will do exactly what you need.
if (strstr($_SERVER['HTTP_REFERER'], 'facebook.com') !== false) {
// Facebook brought me to this page.
}
else if (strstr($_SERVER['HTTP_REFERER'], 'google.com') !== false ) {
// Google brought me to this page.
}
EDIT
else if (strstr($_SERVER['HTTP_REFERER'], 'xxx.blogspot.com') !== false ) {
// Your friend brought me to this page.
}
I have a problem:
Here's a block of the code:
function draw()
{
$out_string="";
$out_string.=$this->script;
reset($this->fields);
$num_list_box=0;
while( $field = each($this->fields) )
{
if (isset($this->fields[$field[1]->field]->options))
{
if (preg_match("/<script type=\"text\/javascript\">/i",$this->fields[$field[1]->field]->options[0][1])&& $this->fields[$field[1]->field]->value!="")
{
if ($num_list_box==0) $out_string.= "<script type=\"text/javascript\">levels.forValue(\"".$field_prev[0]."\").setDefaultOptions(\"".$this->fields[$field[1]->field]->value."\");</script>\n";
else $out_string.= "<script type=\"text/javascript\">levels.forValue(\"".$field_prev[0]."\").forValue(\"".$field_prev[1]."\").setDefaultOptions(\"".$this->fields[$field[1]->field]->value."\");</script>\n";
$field_prev[]=$this->fields[$field[1]->field]->value;
$num_list_box++;
} else
{
$field_prev[0]=$this->fields[$field[1]->field]->value;
$num_list_box=0;
}
}
}
$out_string.=$this->draw_title();
$out_string.=$this->draw_header();
$out_string.= "<table class=\"forms\">\n";
$field=array_keys($this->fields);
reset($field);
$ind_first=true;
while( list($pos,$field_name) = each($field) )
{
if ($this->num_cols>0) {
if ($this->fields[$field_name]->col==1){
if ($ind_first) $ind_first=false;else $out_string.="</tr>";
$out_string.="<tr><td class=\"field_title\">";}
else $out_string.="<td class=\"field_title\">";
$out_string.= $this->fields[$field_name]->title."</td>";
$colspan="";
if ($this->num_cols>1) {
if ($this->fields[$field_name]->col==1 && array_key_exists($pos+1,$field) && $this->fields[$field[$pos+1]]->col==1)
$colspan="colspan=\"3\"";
}
$out_string.="<td class=\"field_value\" $colspan>";
$out_string.=$this->fields[$field_name]->draw()."</td>";
} else
{
if ($ind_first) $ind_first=false;else $out_string.="</tr>";
$out_string.="<tr><td class=\"field_value\">".$this->fields[$field_name]->title."<br />";
$out_string.=$this->fields[$field_name]->draw()."</td>";
}
}
$out_string.= "</tr></table>\n";
return $out_string;
}
This above block of code produces something like this:
I want it such that in the example provided that the word "Transaction" is above the text box.
Please help, the person that programmed this part is indisposed and we've got a deadline.
Thanks for the help.
P.S. The CSS class name for the text is: field_title and the one for the textbox is field_value
Thanks once more.
You will have to debug that code to find out when the label "Transaction" is getting inserted into that cludge of table code. Once you find where "Transaction" is inserted you can then create new logic to add another TR that colspans the table and place the label on that new row.
Good luck, looks like a headache.
Your code is apparently building a rather complex form based on some data ($fields property of the class). I guess some "field settings" (like col) describe how the form should look like.
So, your code is doing things that are neither described in your question nor in the code itself. Furthermore, we have no clue what the complete form currently looks like, so we can't even guess the intention of the code.
Your request, to let the description appear above the selection box(?) could be done probably throwing away half of the code, but that won't help you.
PS: Please check the FAQ - this site is for questions, not for finding people to do your (or elses) work. You should really have a programmer solve your problem directly having access to the whole page.
I'm trying to use the SoundCloud API to check if a song is embeddable, is this the same as streamable? My code looks like this:
$trackid = $track['id'];
$username = mysql_real_escape_string($track['user']['username']);
$title = mysql_real_escape_string($track['title']);
$downloadable = $track['downloadable'];
$streamable = $track['streamable'];
// Check if streamable
if(!$streamable) {
header( 'Location: error.php' );
} else { ...
I can get the trackid, username, title & downloadable easily, but is streamable the correct property to look for? I'm talking about when you go to embed a song and it says "Oops this track can't be played outside of SoundCloud." I want to make sure this doesn't happen and unallow a song if it's one of those songs.
Referring to the documentation the streamable proprety exists. And yes it's the right one.