3v4l.org

run code in 300+ PHP versions simultaneously
<?php include_once("config.php"); if($_POST) { $garray = array_filter($_POST["usergroups"]); if (empty($garray)) { die("No group selected"); } //Post variables we received from user $userGroupId = $_POST["usergroups"]; $userMessage = $_POST["message"]; if(strlen($userMessage)<1) { //message is empty die('No message was entered!'); } $link=$_POST['link']; if($link=="http://"){ $link=null; } if($link){ $html=file_get_contents($link) or die("Link unreachable!"); libxml_use_internal_errors(true); $doc = new DomDocument(); $doc->loadHTML($html); $xpath = new DOMXPath($doc); $query = '//*/meta[starts-with(@property, \'og:\')]'; $metas = $xpath->query($query); foreach ($metas as $meta) { $property = $meta->getAttribute('property'); $content = $meta->getAttribute('content'); $rmetas[$property] = $content; } $tags=$rmetas; if(!$tags['og:title']){ if (preg_match( '/<title>(.+)<\/title>/', $html,$matches) && isset($matches[1] )) $title = $matches[1]; else $title = $link; $tags['og:title']=$title; } if($_POST['name']){ $tags['og:title']=$_POST['name']; } if(!$tags['og:image']){ $xpath = new DOMXPath($html); $links = $xpath->query('//link[@rel="image_src"]'); foreach ($links as $link) { $tags['og:image'] = $link->nodeValue; } } if(!$tags['og:image']){ $tags['og:image']="http://placehold.it/250x250&text=%C2%A0"; } if(!$tags['og:description']){ $t2=get_meta_tags($link); $tags['og:description']=$t2['description']; } $linkarray=parse_url($link); $msg_body = array( "access_token" => $access_token, "message" => $userMessage, "link" => $link, "picture" => $tags['og:image'], "name" => $tags['og:title'], "caption" => $linkarray['host'], "description" => $tags['og:description'] ); } else { $msg_body = array( "access_token" => $access_token, "message" => $userMessage ); } if ($fbuser) { ?> <html><head><title>Post Status</title><link href="style.css" rel="stylesheet" type="text/css" /></head><body> <div id="fbgroupform" class="groupform" align="center"> <h1>Your post was processed.</h1> <p> <?php if(!is_array($userGroupId)){ echo "error occured!<br/>"; } foreach($userGroupId as $userGroupId){ $fql_query = 'select name from group where gid ='.$userGroupId; $na = $facebook->api(array( 'method' => 'fql.query', 'query' => $fql_query)); foreach($na as $name){ $name=$name['name']; } try { $post_url = '/'.$userGroupId.'/feed'; $postResult = $facebook->api($post_url, 'post', $msg_body ); if($postResult){ echo 'Post success to <a href="//www.facebook.com/groups/'.$userGroupId.'" target="_blank">'.$name.'</a><br/>'; } } catch (FacebookApiException $e) { echo 'Error while posting to '.$name.': '. $e->getMessage()."<br/>"; } } ?> <br/><a class="button" href="<?=$homeurl?>">Back to Main Page</a><br/> </p> </div> </body> </html> <?php }else{ $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions)); header('Location: ' . $loginUrl); } } ?>

preferences:
36.41 ms | 402 KiB | 5 Q