<commit_before><?php

namespace ECE\Bundle\NetagoraBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use ECE\Bundle\NetagoraBundle\Entity\Publication;

/** 
 * @Route("/twitter")
 *
 */
class TwitterController extends Controller
{
    /**
     * @Route("/refresh", name="twitter_refresh")
     *
     */
    public function refreshAction()
    {
        $user = $this->get('security.context')->getToken()->getUser();
        
        $em = $this->getDoctrine()->getEntityManager();
        $repository = $em->getRepository('ECENetagoraBundle:Publication');
        
        $twitter = $this->get('fos_twitter.api');
        $twitter->setOAuthToken(
            $user->getTwitterOAuthToken(),
            $user->getTwitterOAuthSecret()
        );

        $timeline = $twitter->get('statuses/home_timeline', array(
            'screen_name' => $user->getTwitterID(),
            'count' => 10
        ));

        foreach ($timeline as $tweet) {
            $publication = $repository->findOneByReference($tweet->id_str);
            if (!$publication) {
                $text = $tweet->text;
                if (preg_match('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $text, $links)) {
                    $publication = new Publication();
                    $publication->setUser($user);
                    $publication->setSocialNetwork(Publication::TWITTER);
                    $publication->setAuthor($tweet->user->name);
                    $publication->setPublishedAt(new \DateTime($tweet->created_at));
                    $publication->setAuthorPicture($tweet->user->profile_image_url_https);
                    $publication->setReference($tweet->id_str);
                    $publication->setContent($tweet->text);
                    $publication->setLinkUrl($links[0]);
                    $em = $this->getDoctrine()->getEntityManager();
                    $em->persist($publication);
                    $em->flush();
                }
            }
        }

        return $this->redirect($this->generateUrl('home'));
    }

    /** 
     * @Route("/login", name="twitter_login")
     *
     */
    public function twitterLoginAction(Request $request)<commit_msg>comments to integrate code from algo<commit_after><?php

namespace ECE\Bundle\NetagoraBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use ECE\Bundle\NetagoraBundle\Entity\Publication;

/** 
 * @Route("/twitter")
 *
 */
class TwitterController extends Controller
{
    /**
     * @Route("/refresh", name="twitter_refresh")
     *
     */
    public function refreshAction()
    {
        $user = $this->get('security.context')->getToken()->getUser();
        
        $em = $this->getDoctrine()->getEntityManager();
        $repository = $em->getRepository('ECENetagoraBundle:Publication');
        
        $twitter = $this->get('fos_twitter.api');
        $twitter->setOAuthToken(
            $user->getTwitterOAuthToken(),
            $user->getTwitterOAuthSecret()
        );

        $timeline = $twitter->get('statuses/home_timeline', array(
            'screen_name' => $user->getTwitterID(),
            'count' => 10
        ));

        foreach ($timeline as $tweet) {
            $publication = $repository->findOneByReference($tweet->id_str);
            if (!$publication) {
                $text = $tweet->text;
                if (preg_match('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $text, $links)) {
                    $publication = new Publication();
                    $publication->setUser($user);
                    $publication->setSocialNetwork(Publication::TWITTER);
                    $publication->setAuthor($tweet->user->name);
                    $publication->setPublishedAt(new \DateTime($tweet->created_at));
                    $publication->setAuthorPicture($tweet->user->profile_image_url_https);
                    $publication->setReference($tweet->id_str);
                    $publication->setContent($tweet->text);
                    $publication->setLinkUrl($links[0]);
                    $em = $this->getDoctrine()->getEntityManager();
                    $em->persist($publication);
                    $em->flush();
                }
            }
        }

        //Find right Category
            //Appeler main(Publication $publication)
        
                //Check the $publication->LinkUrl isn't in DB (KnownLink)
                    //if in => attribuber le KnownLink correspondant à la publication
                    //Sinon faire la tambouille
        
        
        return $this->redirect($this->generateUrl('home'));
    }

    /** 
     * @Route("/login", name="twitter_login")
     *
     */
    public function twitterLoginAction(Request $request)
{'fraction_non_alphanumeric': 0.1552093476144109, 'fraction_numerical': 0.0011684518013631937, 'mean_word_length': 2.1684145589142503, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559818', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1389, 'n_words': 188}