Пример #1
0
 public function index()
 {
     $CRs = new CR($this->db);
     $Actus = new Actu($this->db);
     $Streams = new Stream($this->db);
     $this->f3->set('actus', $Actus->all(10));
     $this->f3->set('streams', $Streams->find(NULL, array('order' => 'twitch_username ASC')));
     $this->f3->set('crs', $CRs->all(10));
     $this->f3->set('site_title', 'Un torrent d\'informations — thetartuffebay.org');
     $this->f3->set('page_head', 'Le premier site d\'information des tartuffes :o');
     $this->f3->set('view', 'home.htm');
 }
Пример #2
0
 public function page()
 {
     $pageNum = $this->f3->get('PARAMS.page');
     $pageNum--;
     if ($pageNum == 0 || !is_numeric($pageNum)) {
         //On vérifie que le numéro de page soit valide
         $this->f3->reroute('@actus_list');
     }
     $actus = new Actu($this->db);
     $page = $actus->paginate($pageNum, $this->nbPage, array('active = 1'), array('order' => 'date_posted DESC, id DESC'));
     if ($pageNum > $page['count']) {
         //On vérifie que le numéro de page existe
         $this->f3->reroute('@actus_list');
     }
     $this->f3->set('page', $page);
     $this->f3->set('page_type', 'gibbactu');
     $this->f3->set('view', 'actu/list.htm');
 }
Пример #3
0
 public function gibbactuPostProcess()
 {
     $Actu = new Actu($this->db);
     $NotProcessedActus = $Actu->find(array('processed = ?', 0));
     //print_r($NotProcessedActus);
     libxml_use_internal_errors(true);
     ob_start();
     foreach ($NotProcessedActus as $NPA) {
         $processActu = array();
         //echo $NPA->id."<br>";
         //Raw HTML to DOM/XPATH
         $dom = new DOMDocument();
         $searchPage = mb_convert_encoding($NPA->content_raw, 'HTML-ENTITIES', "UTF-8");
         @$dom->loadHTML($searchPage);
         @($xpath = new DomXpath($dom));
         //userID :
         $processActu['hfr_user_id'] = $xpath->query('//td[@class = "messCase2"]//a[contains(@href, "profil-")]')->item(0)->getAttribute('href');
         $processActu['hfr_user_id'] = preg_replace("/[^0-9]+/", "", $processActu['hfr_user_id']);
         //echo $processActu['hfr_user_id']."<br>";
         //pseudo :
         $processActu['username'] = $xpath->query('//td[@class = "messCase1"]//b[@class = "s2"]')->item(0)->textContent;
         $processActu['username'] = preg_replace('/[^(\\x20-\\x7F)]*/', '', htmlentities($processActu['username']));
         //echo $processActu['username']."<br>";
         //if ($processActu['username'] <> 'roswellent​ongues') {
         //continue;
         //}
         //Check si le smiley est bien directement dans le message
         $checkSmileyGAParent = $xpath->query('//img[contains(@title, "[:gibbactu]")]//..//..//..//div[starts-with(@id, "para")]');
         if (!$checkSmileyGAParent->length) {
             //pas de smiley, on skip
             //echo "smiley pas à la racine<br/><br/><br/>";
             $NPA->active = 0;
             $NPA->save();
             continue;
         }
         //post ID
         $processActu["hfr_post_id"] = $xpath->query('//a[contains(@href, "#t")]')->item(0)->getAttribute('href');
         $processActu['hfr_post_id'] = str_replace("#t", "", $processActu["hfr_post_id"]);
         //echo $processActu['hfr_post_id'];
         //if ($processActu['hfr_post_id'] <> '10764130') {
         //	continue;
         //}
         //date posted
         $divDate = $xpath->query('//div[@class="toolbar"]/div[@class="left"]');
         $oldate = preg_replace("/[^0-9:-]+/", "", $divDate->item(0)->nodeValue);
         $processActu['date_posted'] = date('Y-m-d H:i', strtotime($oldate));
         //echo $crDatePosted.' ';
         //echo $processActu['username']."\n";
         //le contenu au même niveau que le smiley
         $actuNodesZero = $xpath->query('//img[contains(@title, "[:gibbactu]")]/../node()');
         $processHTMLstep0 = '';
         $startInsert = false;
         foreach ($actuNodesZero as $actuNodeZ) {
             if ($actuNodeZ->nodeType == XML_ELEMENT_NODE && $actuNodeZ->getAttribute('title') == '[:gibbactu]') {
                 $startInsert = true;
                 continue;
             }
             if ($actuNodeZ->nodeType == XML_ELEMENT_NODE && !strcasecmp(trim($actuNodeZ->nodeValue), 'gibbactu')) {
                 continue;
             }
             if (!$startInsert) {
                 continue;
             }
             //echo "len    =".strlen(trim($actuNodeZ->nodeValue))."\n";
             //echo "htmlen =".strlen(trim($processHTMLstep0))."\n";
             //echo "html   =".($dom->saveHTML($actuNodeZ))."\n";
             if ($actuNodeZ->nodeType == XML_ELEMENT_NODE) {
                 //echo "tag    =".$actuNodeZ->tagName."\n";
             } else {
                 //echo "tag    =pasnoded\n";
                 if (!strcasecmp(trim(htmlentities($dom->saveHTML($actuNodeZ))), 'gibbactu')) {
                     //echo "== gibbactu\n";
                     continue;
                 }
             }
             if (trim(htmlentities($dom->saveHTML($actuNodeZ))) == '&nbsp;') {
                 //echo ">> on skip\n";
                 continue;
             }
             if (!strlen(trim($processHTMLstep0)) && $actuNodeZ->nodeType == XML_ELEMENT_NODE && $actuNodeZ->tagName == 'br') {
                 //echo ">> on skip\n";
                 continue;
             }
             //echo "==\nNew HTML:\n".htmlentities($processHTMLstep0)."\n============\n";
             //var_dump($actuNodeZ);
             $processHTMLstep0 .= htmlentities($dom->saveHTML($actuNodeZ));
             //echo htmlentities($dom->saveHTML($actuNodeZ))."\n".$actuNodeZ->nodeValue."\n\n";
         }
         //On va chercher tout le contenu APRES le smiley gibbactu
         $actuNodes = $xpath->query('//img[contains(@title, "[:gibbactu]")]/../following-sibling::*');
         //var_dump($actuNodes);
         $processHTMLstep1 = $processHTMLstep0;
         foreach ($actuNodes as $actuNode) {
             //echo $dom->saveHTML($actuNode)."\n";
             //echo "===\n".$actuNode->tagName." = ".$actuNode->getAttribute('class')."\n\n";
             //var_dump($actuNode);
             if ($actuNode->getAttribute('class') == 'edited' || $actuNode->getAttribute('class') == 'signature' || $actuNode->getAttribute('style') == 'clear: both;') {
                 continue;
             }
             if ($actuNode->nodeValue || $actuNode->childNodes) {
                 $processHTMLstep1 .= htmlentities($dom->saveHTML($actuNode));
             } else {
                 var_dump($actuNode->childNodes);
                 echo "noNodeValue=" . $dom->saveHTML($actuNode) . "\n\n";
             }
         }
         $processHTMLfinal = $processHTMLstep1;
         $processHTMLfinal = str_replace("\n", '', $processHTMLfinal);
         $processHTMLfinal = str_replace("\r", '', $processHTMLfinal);
         $processHTMLfinal = htmlentities(str_replace("<p><br></p>", '', html_entity_decode($processHTMLfinal)));
         $processHTMLfinal = htmlentities(str_replace('href="/hfr/', 'target="_blank" href="http://forum.hardware.fr/hfr/', html_entity_decode($processHTMLfinal)));
         $processHTMLfinal = htmlentities(preg_replace('/style="[a-zA-Z0-9:;\\.\\s\\(\\)\\-\\,]*"/i', '', html_entity_decode($processHTMLfinal)));
         $processHTMLfinal = htmlentities(preg_replace('/onload="[^\\"]+"/i', 'onload="return;"', html_entity_decode($processHTMLfinal)));
         $processHTMLfinal = htmlentities(preg_replace('/title="[^\\"]+"/i', '', html_entity_decode($processHTMLfinal)));
         if (!$processHTMLfinal) {
             echo "aucun contenu<br/><br/><br/>";
             $NPA->active = 0;
             $NPA->save();
             continue;
         }
         $NPA->hfr_cat_id = 5;
         $NPA->hfr_subcat_id = 249;
         $NPA->hfr_topic_id = 177180;
         //$NPA->hfr_page_id
         $NPA->hfr_post_id = $processActu['hfr_post_id'];
         $NPA->hfr_user_id = $processActu['hfr_user_id'];
         $NPA->username = $processActu['username'];
         $NPA->date_modified = date('Y-m-d H:i:s');
         $NPA->date_posted = $processActu['date_posted'];
         $NPA->content = $processHTMLfinal;
         $NPA->active = 1;
         $NPA->processed = 1;
         $NPA->save();
         echo "\n\n\n\n\n";
     }
     $myStr = ob_get_contents();
     ob_end_clean();
     libxml_use_internal_errors(false);
     echo $myStr;
     //$this->f3->set('report',$myStr);
     //echo Template::instance()->render('cron.htm');
 }