Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ---------------------------------------------------------------
- // ----------------- file: getmata_curl.php ----------------------
- // ---------------------------------------------------------------
- header("Content-Type: text/html; charset=utf-8");
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
- ## $myscript = 'getmata_curl.php';
- $myscript = $_SERVER['PHP_SELF'];
- // ------------------------------------------------------------
- print "<br />\n";
- print "<br /> --- <a href=\"".$myscript."\">HOME</a> (RESET) --- \n";
- print "<br />\n";
- // ----------------------------------------------------
- if (!empty($_REQUEST['url'])) {
- $go_url = trim(chop($_REQUEST['url']));
- $go_url = str_replace('http://http://','http://',$go_url);
- if (strpos($go_url,'http://') === FALSE && strpos($go_url,'https://') === FALSE) { $go_url = 'http://'.$go_url; }
- // ----- to-do: filters and/or escape url string -----
- }
- else {
- $go_url = 'http://';
- }
- // ----------------------------------------------------
- function pingSite($url, $length=4096) {
- $fp = curl_init($url);
- curl_setopt($fp, CURLOPT_TIMEOUT, 10);
- curl_setopt($fp, CURLOPT_FAILONERROR, 1);
- curl_setopt($fp, CURLOPT_RANGE, '0-4096');
- curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($fp, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
- $result = curl_exec($fp);
- ## if (curl_errno($fp) != 0) { $status = false; }
- if (curl_errno($fp) != 0) { $status = curl_error($fp); }
- else { $status = true; }
- curl_close($fp);
- return array('status' => $status, 'html' => $result);
- }
- // ----------------------------------------------------
- $online = pingSite($go_url);
- if ( $online['status'] !== true && !empty($go_url) && $go_url != 'http://' ) {
- print "<br />\n";
- print "<br /> ........ Die URL <span style=\"margin:8px; padding:4px; background:#DDEEDD;\">".$go_url."</span> ist <strong style=\"color:red;\">nicht</strong> online !!! ... <a href=\"".$myscript."\">zurück</a>\n";
- print "<br />\n";
- print "<br />ERROR: <span style=\"margin:8px; padding:4px; background:#DEDEDE\">".$online['status']."</span>\n";
- print "<br />\n";
- exit;
- }
- else {
- $hsize = strlen($online['html']);
- print "<br />\n";
- print "<br />Size: ".$hsize."\n";
- print "<br />\n";
- // ------------------------------------------------------------
- if ( !empty($_REQUEST['save']) && !empty($go_url) && $go_url != 'http://' ) {
- print "<br />\n";
- print "<br /> To-Do ........ Speichern \n";
- print "<br />\n";
- print "<br /> ###### DEBUG ###### _POST ###### \n";
- print "<br />\n";
- print "<br />\n";
- print "<pre style=\"margin:4px; padding:4px; background:#DEDEDE; text-align:left;\">\n";
- print_r($_POST);
- print "</pre>\n";
- print "<br />\n";
- print "<br />\n";
- print "<br />\n";
- }
- else {
- // ------------------------------------------------------------
- $formular1 = '
- <form name="form1" method="post" action="">
- <br /> URL: <input type="text" name="url" size="48" maxlength="180" value="'.$go_url.'" />
- <br />
- <br /> RUN: <input type="submit" name="meta" value="Get MetaTags" /> INFO: <span id="minfo" style="margin:12px; padding:4px; background:#DDEEDD;">Bitte eine URL eingeben.</span>
- <br />
- <br /> Titel: <input type="text" name="title" size="48" maxlength="90" />
- <br />
- <br /> Beschreibung:
- <br /> <textarea name="description" cols="48" rows="4" wrap="VIRTUAL"></textarea>
- <br />
- <br /> Keywords:
- <br /> <textarea name="keywords" cols="48" rows="4" wrap="VIRTUAL"></textarea>
- <br />
- <br /> OK: <input type="submit" name="save" value="Speichern" />
- <br />
- </form>
- ';
- // ----------------------------------------------------
- print "<br />\n";
- print "<br />\n";
- print $formular1;
- print "<br />\n";
- print "<br />\n";
- }
- // ----------------------------------------------------
- function str_utf8_encode($str) {
- if (mb_detect_encoding($str, 'UTF-8', true) === FALSE) {
- $str = utf8_encode($str);
- }
- return $str;
- }
- // ----------------------------------------------------------------
- // ----------------------------------------------------------------
- ## function get_meta_from_url($url) {
- function get_meta_from_url($html) {
- /* ---------------
- $html = '';
- if($fh = @fopen($url,"r")){
- while (!feof($fh)){
- $buffer = fgets($fh, 4096);
- if (strpos($buffer,'/head') !== FALSE) { break; }
- $html .= $buffer;
- }
- fclose($fh);
- }
- else {
- print "<br />ERROR ... fopen\n";
- print "<br /> ........ Die URL <span style=\"margin:8px; padding:4px; background:#DDEEDD;\">".$go_url."</span> ist <strong style=\"color:red;\">nicht</strong> online !!! ... <a href=\"".$myscript."\">zurück</a>\n";
- exit;
- }
- --------------- */
- // --------------------------------------------
- $pattern1 = '/<title>(.*)<\/title>/iU';
- preg_match_all ($pattern1, $html, $matches_title);
- ## print "<pre>\n";
- ## print_r($matches_title);
- ## print "</pre>\n";
- // --------------------------------------------
- $pattern2 = '/<meta name=(["\']?)(description|keywords)\\1\\s+content=(["\']?)(.+?)\\3[ \/>]/i';
- preg_match_all ($pattern2, $html, $matches_meta, PREG_SET_ORDER);
- ## print "<pre>\n";
- ## print_r($matches_meta);
- ## print "</pre>\n";
- // --------------------------------------------
- $matchdata = array();
- $matchdata['title'] = (isset($matches_title[1][0])) ? str_utf8_encode($matches_title[1][0]) : '';
- foreach($matches_meta as $matchitem) {
- $mkey = strtolower($matchitem[2]);
- $matchdata[$mkey] = (isset($matchitem[4])) ? str_utf8_encode($matchitem[4]) : '';
- }
- // --------------------------------------------
- return $matchdata;
- }
- // ----------------------------------------------------------------
- // ----------------------------------------------------------------
- // ----------------------------------------------------
- if ( !empty($_REQUEST['meta']) ) {
- // ---------------------------------
- if ( !empty($go_url) && $go_url != 'http://' ) {
- ## $data = get_meta_from_url($go_url);
- $data = get_meta_from_url($online['html']);
- print "<p>###### DEBUG ######</p>\n";
- print "<br />URL: ".$go_url."\n";
- print "<br />\n";
- print "<pre style=\"margin:4px; padding:4px; background:#DEDEDE; text-align:left;\">\n";
- print_r($data);
- print "</pre>\n";
- print "<br />\n";
- print "<br />\n";
- $jscode = '';
- $jscode .= '
- <script type="text/javascript">
- ';
- $jscode .= '
- document.form1.title.value = "'.$data['title'].'";
- document.form1.description.value = "'.$data['description'].'";
- document.form1.keywords.value = "'.$data['keywords'].'";
- ';
- $jscode .= '
- document.getElementById("minfo").innerHTML = "OK ... MetaTags wurden gelesen.";
- ';
- $jscode .= '
- </script>
- ';
- print $jscode;
- }
- else {
- // ---------------------------------
- print '
- <script type="text/javascript">
- document.getElementById("minfo").innerHTML = "Kannst Du nicht Lesen? ... zuerst eine URL eintragen !!!";
- </script>
- ';
- }
- // ---------------------------------
- }
- // ----------------------------------------------------
- }
- // ------------------------------------------------------------
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement