<commit_before><?php

namespace Borg\Controller;

use Borg\Controller\AppController;
use Cake\Network\Exception\NotFoundException;

/**
 * Social controller
 * Counter for social posts
 *
 * Usage:
 * -----------------------------------
 * Perform an ajax request to this controller (default route is yoursite/borg/social/counter)
 * The post must contain the key urls which has to be an serialized array that is then base64 encoded
 * containing one or more url to check
 *
 * @author Borg
 * @version 0.1
 */
class SocialController extends AppController
{
    public function initialize() {
        parent::initialize();

        // request handler for json detection
        $this->loadComponent('RequestHandler');
    }

    /**
     * Get total likes shares and plus ones
     * @throws NotFoundException
     */
    public function counter() {
        // not ajax?
        if(!$this->request->is('ajax'))
            throw new NotFoundException();

        // not post
        if(!$this->request->is('post'))
            throw new NotFoundException();

        // no urls?
        if(is_null($this->request->data('urls')))
            throw new NotFoundException();

        // start social
        $social = new Social();

        // default
        $facebook_count = 0;
        $google_count = 0;

        // process data
        foreach(array_unique(unserialize(base64_decode($this->request->data('urls')))) as $url) {
            if(strpos($url, env('HTTP_HOST')) !== false) { // same domain protection
                $facebook_count += $social->facebookCount($url);
                $google_count += $social->googleCount($url);
            }
        }

        // output
        $response = [
            'success' => true,
            'data' => [
                'f' => $facebook_count,
                'g' => $google_count
            ]
        ];

        // send to template
        $this->set(compact('response'));
        $this->set('_serialize', ['response']);
    }
}

/**
 * Social network counter
 *
 * @author Borg
 * @version 0.1
 */
class Social {
    /**
     * URL helper
     * @param string $url
     * @return boolean|string
     */
    private function _url($url = null) {
        if(is_null($url) || !strlen($url) > 0)
            return false;

        return $url;
    }

    /**
     * Get the facebook share and like count
     *<commit_msg>Corporate<commit_after><?php

namespace Unimatrix\Utility\Controller;

use Unimatrix\Utility\Controller\AppController;
use Cake\Network\Exception\NotFoundException;

/**
 * Social controller
 * Counter for social posts
 *
 * Usage:
 * -----------------------------------
 * Perform an ajax request to this controller (default route is yoursite/unimatrix/utility/social/counter)
 * The post must contain the key urls which has to be an serialized array that is then base64 encoded
 * containing one or more url to check
 *
 * @author Flavius
 * @version 0.1
 */
class SocialController extends AppController
{
    public function initialize() {
        parent::initialize();

        // request handler for json detection
        $this->loadComponent('RequestHandler');
    }

    /**
     * Get total likes shares and plus ones
     * @throws NotFoundException
     */
    public function counter() {
        // not ajax?
        if(!$this->request->is('ajax'))
            throw new NotFoundException();

        // not post
        if(!$this->request->is('post'))
            throw new NotFoundException();

        // no urls?
        if(is_null($this->request->data('urls')))
            throw new NotFoundException();

        // start social
        $social = new Social();

        // default
        $facebook_count = 0;
        $google_count = 0;

        // process data
        foreach(array_unique(unserialize(base64_decode($this->request->data('urls')))) as $url) {
            if(strpos($url, env('HTTP_HOST')) !== false) { // same domain protection
                $facebook_count += $social->facebookCount($url);
                $google_count += $social->googleCount($url);
            }
        }

        // output
        $response = [
            'success' => true,
            'data' => [
                'f' => $facebook_count,
                'g' => $google_count
            ]
        ];

        // send to template
        $this->set(compact('response'));
        $this->set('_serialize', ['response']);
    }
}

/**
 * Social network counter
 *
 * @author Flavius
 * @version 0.1
 */
class Social {
    /**
     * URL helper
     * @param string $url
     * @return boolean|string
     */
    private function _url($url = null) {
        if(is_null($url) || !strlen($url) > 0)
            return false;

        return $url;
    }

    /**
     * Get the facebook share and like count
     *
{'fraction_non_alphanumeric': 0.14249947840600877, 'fraction_numerical': 0.004590027122887545, 'mean_word_length': 1.923170731707317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '1669529', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1275, 'n_words': 346}