×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Edgar/linktitle: Difference between revisions

    Content added Content deleted
    imported>mutante
    m (Created page with '# if somebody mentions a http link, return the <title> of the page # mutante and finn in screen session, idea by finn # advanced features by took function linktitle($link) { …')
     
    imported>mutante
    mNo edit summary
     
    Line 1: Line 1:
    <HighlightSyntax>
    # if somebody mentions a http link, return the <title> of the page
    # if somebody mentions a http link, return the <title> of the page
    # mutante and finn in screen session, idea by finn
    # mutante and finn in screen session, idea by finn
    Line 79: Line 80:
    return $output;
    return $output;
    }
    }
    </HighlightSyntax>

    Latest revision as of 22:50, 28 February 2011

    <HighlightSyntax>

    1. if somebody mentions a http link, return the <title> of the page
    2. mutante and finn in screen session, idea by finn
    3. advanced features by took

    function linktitle($link) {

           global $linktitle_db;
           if (isset ($linktitle_db['temp_blacklist'])) {
                   $largest_key = -2; //-2 for: we havent found any key yet
                   $largest_key_size = -1;
                   foreach ($linktitle_db['temp_blacklist'] as $key => $value) {
                           if ($value['url'] == $link && $value['expire'] > (time() - 23)) {
                                   return "I just told you about that url...";
                           }
                           if ($value['expire'] > time() && $largest_key != -1) {
                                   unset ($GLOBALS['linktitle_db']['temp_blacklist'][$key]);
                                   $largest_key = -1; //-1 for: we dont need to delete any more rows - even if mem just was full
                           } else {
                                   $size = time() - $value['expire'];
                                   if ($size > $largest_key_size) {
                                           $largest_key_size = $size;
                                           $largest_key = $key;
                                   }
                           }
                   }
                   if (count($linktitle_db['temp_blacklist']) > 100 && $largest_key >= 0) {
                           unset ($GLOBALS['linktitle_db']['temp_blacklist'][$largest_key]);
                   }
           }
           $linktitle_db['temp_blacklist'][] = array (
                   'url' => $link,
           'expire' => (time() + 115));
           # Add feature to detect and download image links --mutante 080223
           $image_extensions = array (
                   "jpg",
                   "gif",
                   "png",
                   "jpeg",
                   "bmp",
           );
    
           if (in_array(strtolower(substr($link, -3)), $image_extensions)) {
    
                   $directory = "public_html/images";
                   $imagename = explode("/", $link);
                   $imagename = end($imagename);
    
                   $output = "Looks like an image. Downloading.. ";
                   $image = `wget -q -P $directory $link`;
                   $file = `file $directory/$imagename`;
                   $size = `ls -hs $directory/$imagename | cut -d " " -f1`;
                   $output .= "Saved to " . trim($file) . " size: " . trim($size) . ".";
    
     } elseif (stristr($link,"/wiki/")){
      # < finn__> edgar k?nnte wiki seiten ignorieren, da der titel ja nach dem letzten / abzulesen ist
      $output="";
    } else {
    
                   $buffer = file_get_contents($link);
                   preg_match('@<title>(.*?)</title>@i', str_replace(array (
                           "\n",
                           "\r"
                   ), array (
                           "",
                           ""
                   ), $buffer), $pieces);
                   $title = $pieces[1];
    
                   if ($title != ) {
                           $output = "Title: '" . trim(html_entity_decode($title)) . "'";
                   } else {
                           if ($buffer != ) {
                                   $output = "Sorry, 200 but no title";
                           } else {
                                   $output = ""; // "Sorry, empty buffer"; -> (21:19:39) mutante: Edgar23: if empty buffer, just say nothing
                           }
                   }
    
           }
    
           return $output;
    

    } </HighlightSyntax>

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.