primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,162 @@
<?php
/**
* Copyright 2011 Facebook, Inc.
* @copyright Copyright 2011 Facebook, Inc.
* @license
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
//require_once "base_facebook.php";
/**
* Extends the BaseFacebook class with the intent of using
* PHP sessions to store user ids and access tokens.
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
class Facebook extends BaseFacebook
{
const FBSS_COOKIE_NAME = 'fbss';
// We can set this to a high number because the main session
// expiration will trump this.
const FBSS_COOKIE_EXPIRE = 31556926; // 1 year
// Stores the shared session ID if one is set.
protected $sharedSessionID;
/**
* Identical to the parent constructor, except that
* we start a PHP session to store the user ID and
* access token if during the course of execution
* we discover them.
*
* @param Array $config the application configuration. Additionally
* accepts "sharedSession" as a boolean to turn on a secondary
* cookie for environments with a shared session (that is, your app
* shares the domain with other apps).
* @see BaseFacebook::__construct in facebook.php
*/
public function __construct($config) {
if (!session_id()) {
session_start();
}
parent::__construct($config);
if (!empty($config['sharedSession'])) {
$this->initSharedSession();
}
}
protected static $kSupportedKeys =
array('state', 'code', 'access_token', 'user_id');
protected function initSharedSession() {
$cookie_name = $this->getSharedSessionCookieName();
if (isset($_COOKIE[$cookie_name])) {
$data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
if ($data && !empty($data['domain']) &&
self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
// good case
$this->sharedSessionID = $data['id'];
return;
}
// ignoring potentially unreachable data
}
// evil/corrupt/missing case
$base_domain = $this->getBaseDomain();
$this->sharedSessionID = md5(uniqid(mt_rand(), true));
$cookie_value = $this->makeSignedRequest(
array(
'domain' => $base_domain,
'id' => $this->sharedSessionID,
)
);
$_COOKIE[$cookie_name] = $cookie_value;
if (!headers_sent()) {
$expire = time() + self::FBSS_COOKIE_EXPIRE;
setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
} else {
// @codeCoverageIgnoreStart
self::errorLog(
'Shared session ID cookie could not be set! You must ensure you '.
'create the Facebook instance before headers have been sent. This '.
'will cause authentication issues after the first request.'
);
// @codeCoverageIgnoreEnd
}
}
/**
* Provides the implementations of the inherited abstract
* methods. The implementation uses PHP sessions to maintain
* a store for authorization codes, user ids, CSRF states, and
* access tokens.
*/
protected function setPersistentData($key, $value) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to setPersistentData.');
return;
}
$session_var_name = $this->constructSessionVariableName($key);
$_SESSION[$session_var_name] = $value;
}
protected function getPersistentData($key, $default = false) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to getPersistentData.');
return $default;
}
$session_var_name = $this->constructSessionVariableName($key);
return isset($_SESSION[$session_var_name]) ?
$_SESSION[$session_var_name] : $default;
}
protected function clearPersistentData($key) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to clearPersistentData.');
return;
}
$session_var_name = $this->constructSessionVariableName($key);
unset($_SESSION[$session_var_name]);
}
protected function clearAllPersistentData() {
foreach (self::$kSupportedKeys as $key) {
$this->clearPersistentData($key);
}
if ($this->sharedSessionID) {
$this->deleteSharedSessionCookie();
}
}
protected function deleteSharedSessionCookie() {
$cookie_name = $this->getSharedSessionCookieName();
unset($_COOKIE[$cookie_name]);
$base_domain = $this->getBaseDomain();
setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
}
protected function getSharedSessionCookieName() {
return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
}
protected function constructSessionVariableName($key) {
$parts = array('fb', $this->getAppId(), $key);
if ($this->sharedSessionID) {
array_unshift($parts, $this->sharedSessionID);
}
return implode('_', $parts);
}
}

View File

@ -0,0 +1,350 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
if (is_file( JPATH_ADMINISTRATOR.'/components/com_phocagallery/libraries/phocagallery/facebook/base_facebook.php') &&
is_file( JPATH_ADMINISTRATOR.'/components/com_phocagallery/libraries/phocagallery/facebook/facebook.php')) {
if (class_exists('FacebookApiException') && class_exists('Facebook')) {
} else {
require_once( JPATH_ADMINISTRATOR.'/components/com_phocagallery/libraries/phocagallery/facebook/base_facebook.php');
require_once( JPATH_ADMINISTRATOR.'/components/com_phocagallery/libraries/phocagallery/facebook/facebook.php');
}
}
class PhocaGalleryFb
{
private static $fb = array();
private function __construct(){}
public static function getAppInstance($appid, $appsid) {
if( !array_key_exists( $appid, self::$fb ) ) {
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsid,
'cookie' => false,
));
self::$fb[$appid] = $facebook;
}
return self::$fb[$appid];
}
public static function getSession() {
}
public static function getFbStatus($appid, $appsid) {
$facebook = self::getAppInstance($appid, $appsid);
$fbLogout = JFactory::getApplication()->input->get('fblogout', 0, '', 'int');
if($fbLogout == 1) {
$facebook->destroySession();
}
$fbuser = $facebook->getUser();
$session = array();
$session['uid'] = $facebook->getUser();
$session['secret'] = $facebook->getApiSecret();
$session['access_token']= $facebook->getAccessToken();
$output = array();
$u = null;
// Session based API call.
if ($fbuser) {
try {
$u = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
$uri = JURI::getInstance();
// login or logout url will be needed depending on current user state.
if ($u) {
$uid = $facebook->getUser();
$params = array('next' => $uri->toString() . '&fblogout=1' );
$logoutUrl = $facebook->getLogoutUrl($params);
$output['log'] = 1;
$output['html'] = '<div><img src="https://graph.facebook.com/'. $uid .'/picture" /></div>';
$output['html'] .= '<div>'. $u['name'].'</div>';
//$output['html'] .= '<div><a href="'. $logoutUrl .'"><img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif" /></a></div>';
$output['html'] .= '<div><a href="'. $logoutUrl .'"><span class="btn btn-primary">'.JText::_('COM_PHOCAGALLERY_FB_LOGOUT').'</span></a></div><p>&nbsp;</p>';
/*
$script = array();
$fields = array('name', 'uid', 'base_domain', 'secret', 'session_key', 'access_token', 'sig');
$script[] = 'function clearFbFields() {';
foreach ($fields as $field) {
$script[] = ' document.getElementById(\'jform_'.$field.'\').value = \'\';';
}
$script[] = '}';
// Add the script to the document head.
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
$uri = JURI::getInstance();
$loginUrl = $facebook->getLoginUrl(array('req_perms' => 'user_photos,user_groups,offline_access,publish_stream', 'cancel_url' => $uri->toString(), 'next' => $uri->toString()));
$output['log'] = 0;
$output['html'] .= '<div><a onclick="clearFbFields()" href="'. $loginUrl .'">Clear and Fill data bu</a></div>';*/
} else {
/*$loginUrl = $facebook->getLoginUrl(array('req_perms' => 'user_photos,user_groups,offline_access,publish_stream,photo_upload,manage_pages', 'scope' => 'user_photos,user_groups,offline_access,publish_stream,photo_upload,manage_pages', 'cancel_url' => $uri->toString(), 'next' => $uri->toString()));
*/
// v2.3
/*
$loginUrl = $facebook->getLoginUrl(array('req_perms' => 'user_photos,user_groups,manage_pages', 'scope' => 'user_photos,user_groups,manage_pages', 'cancel_url' => $uri->toString(), 'next' => $uri->toString()));
*/
// v2.5
$loginUrl = $facebook->getLoginUrl(array('req_perms' => 'user_photos,manage_pages,publish_actions', 'scope' => 'user_photos,manage_pages,publish_actions', 'cancel_url' => $uri->toString(), 'next' => $uri->toString()));
$output['log'] = 0;
$output['html'] = '<div><a href="'. $loginUrl .'"><span class="btn btn-primary">'.JText::_('COM_PHOCAGALLERY_FB_LOGIN').'</span></a></div><p>&nbsp;</p>';
//$output['html'] = '<div><a href="'. $loginUrl .'"><img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif" /></a></div>';
}
$output['u'] = $u;
$output['session'] = $session;
return $output;
}
public static function getFbAlbums ($appid, $appidfanpage, $appsid, $session, $aid = 0, $albumN = array(), $next = '') {
$facebook = self::getAppInstance($appid, $appsid);
$facebook->setAccessToken($session['access_token']);
$albums['data'] = array();
// Change the uid to fan page id => Fan PAGE has other UID
$userID = $newUID = $session['uid'];
$nextS = '';
if ($next != '') {
$next = parse_url($next, PHP_URL_QUERY);
$nextS = '?'.strip_tags($next);
}
if (isset($appidfanpage) && $appidfanpage != '') {
$newUID = $appidfanpage;
$albums = $facebook->api("/".$newUID."/albums".$nextS);
} else {
$albums = $facebook->api("/me/albums".$nextS);
}
/* $loginUrl = $facebook->getLoginUrl(array('scope' => 'user_photos'));
if ($aid > 0) {
// TO DO - if used
$albums = $facebook->api(array('method' => 'photos.getAlbums', 'aids' => $aid));
} else {
//$albums = $facebook->api(array('method' => 'photos.getAlbums', 'uid' => $newUID));
//$albums = $facebook->api(array('method' => 'photos.getAlbums'));
$albums = $facebook->api("/me/albums");
} */
if (!empty($albums['data'])) {
$albumN[] = $albums['data'];
}
if (isset($albums['paging']['next']) && $albums['paging']['next'] != '') {
$albumN = self::getFbAlbums($appid, $appidfanpage, $appsid, $session, $aid, $albumN, $albums['paging']['next']);
}
return $albumN;
}
/* BY ID
public function getFbAlbumsFan ($appid, $appsid, $session, $id = 0) {
$facebook = self::getAppInstance($appid, $appsid, $session);
$facebook->setSession($session);
$albums = false;
$userID = $session['uid'];
if ($aid > 0) {
$albums = $facebook->api('/' . $userID . '/albums');
} else {
$albums = $facebook->api('/' . $userID . '/albums');
}
return $albums['data'];
}*/
public static function getFbAlbumName ($appid, $appsid, $session, $aid) {
$facebook = self::getAppInstance($appid, $appsid);
$facebook->setAccessToken($session['access_token']);
//$album = $facebook->api(array('method' => 'photos.getAlbums', 'aids' => $aid));
$album = $facebook->api("/".$aid);
$albumName = '';
if (isset($album['name']) && $album['name'] != '') {
$albumName = $album['name'];
}
return $albumName;
}
public static function getFbImages ($appid, $appsid, $session, &$fbAfter, $aid = 0, $limit = 0 ) {
$facebook = self::getAppInstance($appid, $appsid);
$facebook->setAccessToken($session['access_token']);
$images['data'] = array();
$fields = 'id,name,source,picture,created,created_time,images';
if ($aid > 0) {
//$images = $facebook->api(array('method' => 'photos.get', 'aid' => $aid));
if ((int)$limit > 0 && $fbAfter != '') {
$images = $facebook->api("/".$aid."/photos", 'GET', array('limit' => $limit,'after' => $fbAfter, 'fields' => $fields));
} else if ((int)$limit > 0 && $fbAfter == '') {
$images = $facebook->api("/".$aid."/photos", 'GET', array('limit' => $limit, 'fields' => $fields));
} else {
$images = $facebook->api("/".$aid."/photos", 'GET', array('fields' => $fields));
}
}
/*
$images = $facebook->api("/".$aid."/photos");
id (String
created_time (String
from (Array
height (Integer
icon (String
images (Array
link (String
name (String
picture (String
source (String
updated_time (String
width (Integer */
$fbAfter = '';// Unset this variable and check again if there is still new after value (if there are more images to pagination)
if (isset($images['paging'])) {
$paging = $images['paging'];
if (isset($paging['next']) && $paging['next'] != '') {
$query = parse_url($paging['next'], PHP_URL_QUERY);
parse_str($query, $parse);
if (isset($parse['after'])) {
$fbAfter = $parse['after']; // we return $fbAfter value in reference - new after value is set
}
}
}
return $images['data'];
}
/*
public static function getFbImages ($appid, $appsid, $session, $aid = 0) {
$facebook = self::getAppInstance($appid, $appsid);
$facebook->setAccessToken($session['access_token']);
$images['data'] = array();
if ($aid > 0) {
//$images = $facebook->api(array('method' => 'photos.get', 'aid' => $aid));
$images = $facebook->api("/".$aid."/photos");
}
return $images['data'];
}
*/
/*
public static function getFbImages ($appid, $appsid, $session, $aid = 0) {
$facebook = self::getAppInstance($appid, $appsid);
$facebook->setAccessToken($session['access_token']);
$images['data'] = array();
if ($aid > 0) {
//$images = $facebook->api(array('method' => 'photos.get', 'aid' => $aid));
//$images = $facebook->api("/".$aid."/photos");
$limit = 25;
$completeI = array();
$partI = $facebook->api("/".$aid."/photos", 'GET', array('limit' => $limit) );
$completeI[0] = $partI['data'];
$i = 1;
while ($partI['data']) {
$completeI[1] = $partI['data'];
$paging = $partI['paging'];
if (isset($paging['next']) && $paging['next'] != '') {
$query = parse_url($paging['next'], PHP_URL_QUERY);
parse_str($query, $par);
if (isset($parse['limit']) && isset($parse['after'])) {
$partI = $facebook->api("/".$aid."/photos", 'GET', array('limit' => $parse['limit'],'after' => $parse['after']));
$i++;
}
}
}
}
return $images['data'];
} */
/* BY ID
public static function getFbImagesFan ($appid, $appsid, $session, $id = 0) {
$facebook = self::getAppInstance($appid, $appsid, $session);
$facebook->setSession($session);
$images = false;
if ($id > 0) {
$imagesFolder = $facebook->api('/' . $id . '/photos?limit=0');
$images = $imagesFolder['data'];
}
return $images;
}*/
public static function exportFbImage ($appid, $appidfanpage, $appsid, $session, $image, $aid = 0) {
$facebook = self::getAppInstance($appid, $appsid);
$facebook->setAccessToken($session['access_token']);
$facebook->setFileUploadSupport(true);
// Change the uid to fan page id => Fan PAGE has other UID
$userID = $newUID = $session['uid'];
$newToken = $session['access_token'];//Will be changed if needed (for fan page)
if (isset($appidfanpage) && $appidfanpage != '') {
$newUID = $appidfanpage;
$params = array('access_token' => $session['access_token']);
$accounts = $facebook->api('/'.$session['uid'].'/accounts', 'GET', $params);
foreach($accounts['data'] as $account) {
if( $account['id'] == $appidfanpage || $account['name'] == $appidfanpage ){
$newToken = $account['access_token'];
}
}
}
if ($aid > 0) {
//$export = $facebook->api(array('method' => 'photos.upload', 'aid' => $aid, 'uid' => $newUID, 'caption' => $image['caption'], $image['filename'] => '@'.$image['fileorigabs']));
$args = array('caption' => $image['caption'], 'aid' => $aid, 'uid' => $newUID, 'access_token' => $newToken);
$args['image'] = '@'.$image['fileorigabs'];
$export = $facebook->api('/'. $aid . '/photos', 'post', $args);
return $export;
}
return false;
}
public final function __clone() {
throw new Exception('Function Error: Cannot clone instance of Singleton pattern', 500);
return false;
}
}

View File

@ -0,0 +1,151 @@
<?php
/**
* @package Phoca Gallery
* @author Jan Pavelka - https://www.phoca.cz
* @copyright Copyright (C) Jan Pavelka https://www.phoca.cz
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 and later
* @cms Joomla
* @copyright Copyright (C) Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Registry\Registry;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
class PhocaGalleryFbSystem
{
public static function setSessionData($data) {
$session = array();
// Don't set the session, in other way the SIG will be not the same
//$session['uid'] = $session['base_domain'] = $session['secret'] = '';
//$session['access_token'] = $session['session_key'] = $session['sig'] = '';
$session['expires'] = 0;
if (isset($data->uid) && $data->uid != '') {$session['uid'] = $data->uid;}
if (isset($data->base_domain) && $data->base_domain != '') {$session['base_domain'] = $data->base_domain;}
if (isset($data->secret) && $data->secret != '') {$session['secret'] = $data->secret;}
if (isset($data->session_key) && $data->session_key != '') {$session['session_key'] = $data->session_key;}
if (isset($data->access_token) && $data->access_token != ''){$session['access_token'] = $data->access_token;}
if (isset($data->sig) && $data->sig != '') {$session['sig'] = $data->sig;}
ksort($session);
return $session;
}
public static function getFbUserInfo ($id) {
$db = Factory::getDBO();
//build the list of categories
$query = 'SELECT a.*'
. ' FROM #__phocagallery_fb_users AS a'
. ' WHERE a.id ='.(int)$id;
$db->setQuery( $query );
$item = $db->loadObject();
return $item;
}
public static function getCommentsParams($id) {
$o = array();
$item = self::getFbUserInfo($id);
if(isset($item->appid)) {
$o['fb_comment_app_id'] = $item->appid;
}
if(isset($item->comments) && $item->comments != '') {
$registry = new Registry;
$registry->loadString($item->comments);
$item->comments = $registry->toArray();
foreach($item->comments as $key => $value) {
$o[$key] = $value;
}
}
return $o;
}
public static function getImageFromCat($idCat, $idImg = 0) {
$db = Factory::getDBO();
$nextImg = '';
if ($idImg > 0) {
$nextImg = ' AND a.id > '.(int)$idImg;
}
$query = 'SELECT a.*'
.' FROM #__phocagallery AS a'
.' WHERE a.catid = '.(int) $idCat
.' AND a.published = 1'
.' AND a.approved = 1'
. $nextImg
.' ORDER BY a.id ASC LIMIT 1';
$db->setQuery( $query );
$item = $db->loadObject();
if(!isset($item->id) || (isset($item->id) && $item->id < 1)) {
$img['end'] = 1;
return $img;
}
if (isset($item->description) && $item->description != '') {
$img['caption'] = $item->title . ' - ' .$item->description;
} else {
$img['caption'] = $item->title;
}
//TO DO TEST EXT IMAGE
if (isset($item->extid) && $item->extid != '') {
$img['extid'] = $item->extid;
}
$img['id'] = $item->id;
$img['title'] = $item->title;
$img['filename'] = PhocaGalleryFile::getTitleFromFile($item->filename, 1);
$img['fileorigabs'] = PhocaGalleryFile::getFileOriginal($item->filename);
return $img;
}
/*
* Used while pagination
*/
public static function renderProcessPage($id, $refreshUrl, $countInfo = '', $import = 0) {
if ($import == 0) {
$stopText = Text::_( 'COM_PHOCAGALLERY_STOP_UPLOADING_FACEBOOK_IMAGES' );
$dataText = Text::_('COM_PHOCAGALLERY_FB_UPLOADING_DATA');
} else {
$stopText = Text::_( 'COM_PHOCAGALLERY_STOP_IMPORTING_FACEBOOK_IMAGES' );
$dataText = Text::_('COM_PHOCAGALLERY_FB_IMPORTING_DATA');
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-en" lang="en-en" dir="ltr" >'. "\n";
echo '<head>'. "\n";
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'. "\n\n";
echo '<title>'.$dataText.'</title>'. "\n";
echo '<link rel="stylesheet" href="'.Uri::root(true).'/media/com_phocagallery/css/administrator/phocagallery.css" type="text/css" />';
echo '</head>'. "\n";
echo '<body>'. "\n";
echo '<div style="text-align:right;padding:10px"><a style="font-family: sans-serif, Arial;font-weight:bold;color:#fc0000;font-size:14px;" href="index.php?option=com_phocagallery&task=phocagalleryc.edit&id='.(int)$id.'">' .$stopText.'</a></div>';
echo '<div id="loading-ext-img-processp" style="font-family: sans-serif, Arial;font-weight:normal;color:#666;font-size:14px;padding:10px"><div class="loading"><div class="ph-lds-ellipsis"><div></div><div></div><div></div><div></div></div><div>&nbsp;</div><div><center>'.$dataText.'</center></div>';
echo $countInfo;
echo '</div></div>';
echo '<meta http-equiv="refresh" content="2;url='.$refreshUrl.'" />';
echo '</body></html>';
exit;
}
}

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>