Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ---------------------------------------------------------------
- // ---------------- file: getmata_fopen.php ----------------------
- // ---------------------------------------------------------------
- header("Content-Type: text/html; charset=utf-8");
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
- ## $myscript = 'getmata_fopen.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://';
- }
- // ----------------------------------------------------
- $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>
- ';
- // ----------------------------------------------------------------
- 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) {
- $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";
- $online = false;
- return $online;
- ## exit;
- }
- $hsize = strlen($html);
- print "<br />\n";
- print "<br />Size: ".$hsize."\n";
- print "<br />\n";
- // --------------------------------------------
- $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['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 {
- // ------------------------------------------------------------
- print "<br />\n";
- print "<br />\n";
- print $formular1;
- print "<br />\n";
- print "<br />\n";
- }
- // ------------------------------------------------------------
- $jscode = '';
- // ----------------------------------------------------
- if ( !empty($_REQUEST['meta']) ) {
- // ---------------------------------
- if ( !empty($go_url) && $go_url != 'http://' ) {
- $data = get_meta_from_url($go_url);
- // -----------------------------
- if ($data === false) {
- 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";
- }
- else {
- // -----------------------------
- 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 .= '
- <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>
- ';
- }
- // -----------------------------
- }
- else {
- // ---------------------------------
- $jscode .= '
- <script type="text/javascript">
- document.getElementById("minfo").innerHTML = "Kannst Du nicht Lesen? ... zuerst eine URL eintragen !!!";
- </script>
- ';
- }
- // ---------------------------------
- }
- // ----------------------------------------------------
- print $jscode;
- print '<p> </p>'."\n";
- // ------------------------------------------------------------
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement