Dotclear


Ignore:
Timestamp:
11/17/13 20:25:53 (12 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
2.6
Children:
2567:6c11245cbf04, 2568:61c67a7d17fa
Message:

Add some people in CREDITS, remove trailing spaces and tabs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.trackback.php

    r1689 r2566  
    2222     public $core;       ///< <b>dcCore</b> dcCore instance 
    2323     public $table;      ///< <b>string</b> done pings table name 
    24       
     24 
    2525     /** 
    2626     Object constructor 
    27       
     27 
    2828     @param    core      <b>dcCore</b>       dcCore instance 
    2929     */ 
     
    3434          $this->table = $this->core->prefix.'ping'; 
    3535     } 
    36       
     36 
    3737     /// @name Send trackbacks 
    3838     //@{ 
    3939     /** 
    4040     Get all pings sent for a given post. 
    41       
     41 
    4242     @param    post_id   <b>integer</b>      Post ID 
    4343     @return   <b>record</b> 
     
    4848                    'FROM '.$this->table.' '. 
    4949                    'WHERE post_id = '.(integer) $post_id; 
    50            
     50 
    5151          return $this->con->select($strReq); 
    5252     } 
    53       
     53 
    5454     /** 
    5555     Sends a ping to given <var>$url</var>. 
    56       
     56 
    5757     @param    url            <b>string</b>       URL to ping 
    5858     @param    post_id        <b>integer</b>      Post ID 
     
    6666               return false; 
    6767          } 
    68            
     68 
    6969          $post_id = (integer) $post_id; 
    70            
     70 
    7171          # Check for previously done trackback 
    7272          $strReq = 'SELECT post_id, ping_url FROM '.$this->table.' '. 
    7373                    'WHERE post_id = '.$post_id.' '. 
    7474                    "AND ping_url = '".$this->con->escape($url)."' "; 
    75            
     75 
    7676          $rs = $this->con->select($strReq); 
    77            
     77 
    7878          if (!$rs->isEmpty()) { 
    7979               throw new Exception(sprintf(__('%s has still been pinged'),$url)); 
    8080          } 
    81            
     81 
    8282          $ping_parts = explode('|',$url); 
    83            
     83 
    8484          # Let's walk by the trackback way 
    8585          if (count($ping_parts) < 2) { 
     
    9191                    //,'__debug' => false 
    9292               ); 
    93                 
     93 
    9494               # Ping 
    9595               try 
     
    103103                    throw new Exception(__('Unable to ping URL')); 
    104104               } 
    105                 
     105 
    106106               $pattern = 
    107107               '|<response>.*<error>(.*)</error>(.*)'. 
    108108               '(<message>(.*)</message>(.*))?'. 
    109109               '</response>|msU'; 
    110                 
     110 
    111111               if (!preg_match($pattern,$res,$match)) 
    112112               { 
    113113                    throw new Exception(sprintf(__('%s is not a ping URL'),$url)); 
    114114               } 
    115                 
     115 
    116116               $ping_error = trim($match[1]); 
    117117               $ping_msg = (!empty($match[4])) ? $match[4] : ''; 
     
    126126               catch (xmlrpcException $e) { 
    127127                    $ping_error = $e->getCode(); 
    128                     $ping_msg = $e->getMessage();  
     128                    $ping_msg = $e->getMessage(); 
    129129               } 
    130130               catch (Exception $e) { 
     
    132132               } 
    133133          } 
    134            
     134 
    135135          if ($ping_error != '0') { 
    136136               throw new Exception(sprintf(__('%s, ping error:'),$url).' '.$ping_msg); 
     
    141141               $cur->ping_url = $url; 
    142142               $cur->ping_dt = date('Y-m-d H:i:s'); 
    143                 
     143 
    144144               $cur->insert(); 
    145145          } 
    146146     } 
    147147     //@} 
    148       
     148 
    149149     private function pingAlreadyDone($post_id, $from_url) 
    150150     { 
     
    154154               'comment_trackback' => 1, 
    155155          ); 
    156            
     156 
    157157          $rs = $this->core->blog->getComments($params, true); 
    158158          if ($rs && !$rs->isEmpty()) { 
    159159               return ($rs->f(0)); 
    160160          } 
    161            
     161 
    162162          return false; 
    163163     } 
    164       
     164 
    165165     private function addBacklink($post_id, $url, $blog_name, $title, $excerpt, &$comment) 
    166166     { 
     
    168168               $blog_name = 'Anonymous blog'; 
    169169          } 
    170            
     170 
    171171          $comment = 
    172172          "<!-- TB -->\n". 
    173173          '<p><strong>'.($title ? $title : $blog_name)."</strong></p>\n". 
    174174          '<p>'.$excerpt.'</p>'; 
    175            
     175 
    176176          $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 
    177177          $cur->comment_author = (string) $blog_name; 
     
    182182          $cur->comment_status = $this->core->blog->settings->system->trackbacks_pub ? 1 : -1; 
    183183          $cur->comment_ip = http::realIP(); 
    184            
     184 
    185185          # --BEHAVIOR-- publicBeforeTrackbackCreate 
    186186          $this->core->callBehavior('publicBeforeTrackbackCreate',$cur); 
    187187          if ($cur->post_id) { 
    188188               $comment_id = $this->core->blog->addComment($cur); 
    189                 
     189 
    190190               # --BEHAVIOR-- publicAfterTrackbackCreate 
    191191               $this->core->callBehavior('publicAfterTrackbackCreate',$cur,$comment_id); 
    192192          } 
    193193     } 
    194       
     194 
    195195     /// @name Receive trackbacks 
    196196     //@{ 
    197197     /** 
    198198     Receives a trackback and insert it as a comment of given post. 
    199       
     199 
    200200     @param    post_id        <b>integer</b>      Post ID 
    201201     */ 
     
    213213               return; 
    214214          } 
    215            
     215 
    216216          $post_id = (integer) $post_id; 
    217            
     217 
    218218          $title = !empty($_POST['title']) ? $_POST['title'] : ''; 
    219219          $excerpt = !empty($_POST['excerpt']) ? $_POST['excerpt'] : ''; 
     
    222222          $charset = ''; 
    223223          $comment = ''; 
    224                      
     224 
    225225          $err = false; 
    226226          $msg = ''; 
    227            
     227 
    228228          if ($this->core->blog === null) 
    229229          { 
     
    240240               $msg = 'Blog name is required.'; 
    241241          } 
    242            
     242 
    243243          if (!$err) 
    244244          { 
    245245               $post = $this->core->blog->getPosts(array('post_id'=>$post_id,'post_type'=>'')); 
    246                 
     246 
    247247               if ($post->isEmpty()) 
    248248               { 
     
    262262               } 
    263263          } 
    264            
     264 
    265265          if (!$err) 
    266266          { 
    267267               $charset = self::getCharsetFromRequest(); 
    268                 
     268 
    269269               if (!$charset) { 
    270270                    $charset = self::detectCharset($title.' '.$excerpt.' '.$blog_name); 
    271271               } 
    272                 
     272 
    273273               if (strtolower($charset) != 'utf-8') { 
    274274                    $title = iconv($charset,'UTF-8',$title); 
     
    276276                    $blog_name = iconv($charset,'UTF-8',$blog_name); 
    277277               } 
    278                 
     278 
    279279               $title = trim(html::clean($title)); 
    280280               $title = html::decodeEntities($title); 
    281281               $title = html::escapeHTML($title); 
    282282               $title = text::cutString($title,60); 
    283                 
     283 
    284284               $excerpt = trim(html::clean($excerpt)); 
    285285               $excerpt = html::decodeEntities($excerpt); 
    286286               $excerpt = preg_replace('/\s+/ms',' ',$excerpt); 
    287                $excerpt = text::cutString($excerpt,252);  
     287               $excerpt = text::cutString($excerpt,252); 
    288288               $excerpt = html::escapeHTML($excerpt).'...'; 
    289                 
     289 
    290290               $blog_name = trim(html::clean($blog_name)); 
    291291               $blog_name = html::decodeEntities($blog_name); 
    292292               $blog_name = html::escapeHTML($blog_name); 
    293293               $blog_name = text::cutString($blog_name,60); 
    294                 
     294 
    295295               try 
    296296               { 
     
    303303               } 
    304304          } 
    305            
     305 
    306306          $resp = 
    307307          '<?xml version="1.0" encoding="utf-8"?>'."\n". 
    308308          "<response>\n". 
    309309          '  <error>'.(integer) $err."</error>\n"; 
    310            
     310 
    311311          if ($msg) { 
    312312               $resp .= '  <message>'.$msg."</message>\n"; 
    313313          } 
    314            
     314 
    315315          if (!empty($_POST['__debug'])) { 
    316                $resp .=  
     316               $resp .= 
    317317               "  <debug>\n". 
    318318               '    <title>'.$title."</title>\n". 
     
    324324               "  </debug>\n"; 
    325325          } 
    326            
     326 
    327327          echo $resp."</response>"; 
    328328     } 
     
    333333     /** 
    334334     Receives a pingback and insert it as a comment of given post. 
    335       
     335 
    336336     @param    from_url       <b>string</b>       Source URL 
    337337     @param    to_url              <b>string</b>       Target URL 
     
    341341          $reg = '!^'.preg_quote($this->core->blog->url).'(.*)!'; 
    342342          $type = $args = $next = ''; 
    343            
     343 
    344344          # Are you dumb? 
    345345          if (!preg_match($reg, $to_url, $m)) { 
    346346               throw new Exception(__('Any chance you ping one of my contents? No? Really?'), 0); 
    347347          } 
    348            
    349           # Does the targeted URL look like a registered post type?  
     348 
     349          # Does the targeted URL look like a registered post type? 
    350350          $url_part = $m[1]; 
    351351          $p_type = ''; 
     
    359359               } 
    360360          } 
    361            
     361 
    362362          if (empty($p_type)) { 
    363363               throw new Exception(__('Sorry but you can not ping this type of content.'), 33); 
     
    370370          ); 
    371371          $posts = $this->core->blog->getPosts($params); 
    372            
    373           # Missed!  
     372 
     373          # Missed! 
    374374          if ($posts->isEmpty()) { 
    375375               throw new Exception(__('Oops. Kinda "not found" stuff. Please check the target URL twice.'), 33); 
    376376          } 
    377            
     377 
    378378          # Nice try. But, sorry, no. 
    379379          if (!$posts->trackbacksActive()) { 
     
    384384               throw new Exception(__('Don\'t repeat yourself, please.'), 48); 
    385385          } 
    386            
     386 
    387387          # OK. We've found our champion. Time to check the remote part. 
    388388          try { 
    389389               $http = self::initHttp($from_url, $from_path); 
    390                 
     390 
    391391               # First round : just to be sure the ping comes from an acceptable resource type. 
    392392               $http->setHeadersOnly(true); 
     
    398398                    throw new Exception(__('Your source URL does not look like a supported content type. Sorry. Bye, bye!'), 0); 
    399399               } 
    400                 
     400 
    401401               # Second round : let's go fetch and parse the remote content 
    402402               $http->setHeadersOnly(false); 
     
    409409                    $charset = self::detectCharset($remote_content); 
    410410               } 
    411                 
     411 
    412412               if (strtolower($charset) != 'utf-8') { 
    413413                    $remote_content = iconv($charset,'UTF-8',$remote_content); 
    414414               } 
    415                 
     415 
    416416               # We want a title... 
    417417               if (!preg_match('!<title>([^<].*?)</title>!mis', $remote_content, $m)) { 
     
    422422               $title = html::escapeHTML($title); 
    423423               $title = text::cutString($title,60); 
    424                 
     424 
    425425               preg_match('!<body[^>]*?>(.*)?</body>!msi', $remote_content, $m); 
    426426               $source = $m[1]; 
     
    429429               $source = strip_tags($source, '<a>'); 
    430430               $source = explode("\n\n",$source); 
    431                 
     431 
    432432               $excerpt = ''; 
    433433               foreach ($source as $line) { 
     
    451451               throw new Exception(__('Sorry, an internal problem has occured.'), 0); 
    452452          } 
    453            
     453 
    454454          return __('Thanks, mate. It was a pleasure.'); 
    455455     } 
    456456     //@} 
    457       
     457 
    458458     private static function initHttp($url,&$path) 
    459459     { 
     
    463463          $client->useGzip(false); 
    464464          $client->setPersistReferers(false); 
    465            
     465 
    466466          return $client; 
    467467     } 
    468       
     468 
    469469     private static function getCharsetFromRequest($header = '') 
    470470     { 
     
    472472               $header = $_SERVER['CONTENT_TYPE']; 
    473473          } 
    474            
     474 
    475475          if ($header) { 
    476476               if (preg_match('|charset=([a-zA-Z0-9-]+)|',$header,$m)) { 
     
    478478               } 
    479479          } 
    480            
     480 
    481481          return null; 
    482482     } 
     
    489489                    'ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15'); 
    490490     } 
    491            
     491 
    492492     /// @name Trackbacks auto discovery 
    493493     //@{ 
     
    495495     Returns an array containing all discovered trackbacks URLs in 
    496496     <var>$text</var>. 
    497       
     497 
    498498     @param    text      <b>string</b>       Input text 
    499499     @return   <b>array</b> 
     
    502502     { 
    503503          $res = array(); 
    504            
     504 
    505505          foreach ($this->getTextLinks($text) as $link) 
    506506          { 
     
    509509               } 
    510510          } 
    511            
     511 
    512512          return $res; 
    513513     } 
    514514     //@} 
    515       
     515 
    516516     private function getTextLinks($text) 
    517517     { 
    518518          $res = array(); 
    519            
     519 
    520520          # href attribute on "a" tags 
    521521          if (preg_match_all('/<a ([^>]+)>/ms', $text, $match, PREG_SET_ORDER)) 
     
    529529          } 
    530530          unset($match); 
    531            
     531 
    532532          # cite attributes on "blockquote" and "q" tags 
    533533          if (preg_match_all('/<(blockquote|q) ([^>]+)>/ms', $text, $match, PREG_SET_ORDER)) 
     
    540540               } 
    541541          } 
    542            
     542 
    543543          return array_keys($res); 
    544544     } 
    545       
     545 
    546546     private function getPingURL($url) 
    547547     { 
     
    549549               $url = http::getHost().$url; 
    550550          } 
    551            
     551 
    552552          try 
    553553          { 
     
    561561               return false; 
    562562          } 
    563            
     563 
    564564          # If we've got a X-Pingback header and it's a valid URL, it will be enough 
    565565          if ($pb_url && filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) { 
    566566               return $pb_url.'|'.$url; 
    567567          } 
    568            
     568 
    569569          # No X-Pingback header. A link rel=pingback, maybe ? 
    570570          $pattern_pingback = '!<link rel="pingback" href="(.*?)"( /)?>!msi'; 
    571            
     571 
    572572          if (preg_match($pattern_pingback,$page_content,$m)) { 
    573573               $pb_url = $m[1]; 
     
    583583          '.*?<\/rdf:RDF>'. 
    584584          '/msi'; 
    585            
     585 
    586586          preg_match_all($pattern_rdf,$page_content,$rdf_all,PREG_SET_ORDER); 
    587            
     587 
    588588          $url_path = parse_url($url, PHP_URL_PATH); 
    589589          $sanitized_url = str_replace($url_path, html::sanitizeURL($url_path), $url); 
    590            
     590 
    591591          for ($i=0; $i<count($rdf_all); $i++) 
    592592          { 
     
    599599               } 
    600600          } 
    601            
     601 
    602602          return null; 
    603603     } 
    604604} 
    605 ?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map