array( 'enabled' => '1', ), 'AOL' => array( 'enabled' => '1', ), 'Facebook' => array( 'keys' => array( 'id' => 'a', 'secret' => 'b', ), 'scope' => 'c', 'enabled' => '1', ), 'Foursquare' => array( 'keys' => array( 'id' => 'a', 'secret' => 'b', ), 'enabled' => '1', ), 'Github' => array( 'keys' => array( 'id' => 'a', 'secret' => 'b', ), 'scope' => 'c', 'enabled' => '1', ), 'Google' => array( 'keys' => array( 'id' => 'a', 'secret' => 'b', ), 'scope' => 'c', 'enabled' => '1', ), 'LinkedIn' => array( 'keys' => array( 'id' => 'a', 'secret' => 'b', ), 'enabled' => '1', ), 'Live' => array( 'keys' => array( 'id' => 'a', 'secret' => 'b', ), 'enabled' => '1', ), 'OpenID' => array( 'enabled' => '1', ), 'Steam' => array( 'keys' => array( 'key' => 'a', ), 'enabled' => '1', ), 'Twitter' => array( 'keys' => array( 'key' => 'a', 'secret' => 'b', ), 'enabled' => '1', ), 'Yahoo' => array( 'keys' => array( 'id' => 'a', 'secret' => 'b', ), 'enabled' => '1', ), ); e107::getConfig()->setPref('social_login', $legacy); */ class social_adminarea extends e_admin_dispatcher { protected $modes = array( 'main' => array( 'controller' => 'social_ui', 'path' => null, 'ui' => 'social_form_ui', 'uipath' => null ), ); protected $adminMenu = array( // 'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'), // 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), 'main/pages' => array('caption'=>LAN_SOCIAL_ADMIN_01, 'perm'=>'P'), 'main/configure' => array('caption'=> LAN_SOCIAL_ADMIN_02, 'perm' => 'P'), 'main/add' => array('caption'=> LAN_SOCIAL_ADMIN_44, 'perm' => 'P'), 'main/unsupported' => array('caption'=> LAN_SOCIAL_ADMIN_47, 'perm' => 'P'), 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'), ); protected $adminMenuAliases = array( 'main/modify' => 'main/add' ); protected $menuTitle = LAN_PLUGIN_SOCIAL_NAME; public function init() { $slcm = new social_login_config(e107::getConfig()); $supported_providers = $slcm->getSupportedProviders(); $configured_providers = $slcm->getConfiguredProviders(); $unsupported_providers = array_diff($configured_providers, $supported_providers); if(empty($unsupported_providers) && !deftrue('e_DEBUG')) { unset($this->adminMenu['main/unsupported']); } else { $this->adminMenu['main/unsupported']['badge'] = array('value' => count($unsupported_providers), 'type'=>'warning'); } } } require_once("includes/social_login_config.php"); class social_ui extends e_admin_ui { protected $pluginTitle = LAN_PLUGIN_SOCIAL_NAME; protected $pluginName = 'social'; // protected $eventName = 'social-social'; // remove comment to enable event triggers in admin. // protected $table = 'social'; protected $pid = 'social_id'; protected $perPage = 10; protected $batchDelete = true; // protected $batchCopy = true; // protected $sortField = 'somefield_order'; // protected $orderStep = 10; // protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable. // protected $listQry = "SELECT * FROM `#tableName` WHERE field != '' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. protected $listOrder = ''; protected $fields = array( ); protected $fieldpref = array(); protected $preftabs = array(LAN_LOGIN, LAN_SOCIAL_ADMIN_14, LAN_SOCIAL_ADMIN_15, LAN_SOCIAL_ADMIN_16, LAN_SOCIAL_ADMIN_17, LAN_SOCIAL_ADMIN_37); protected $prefs = array( 'facebook_comments_limit' => array('title'=> LAN_SOCIAL_ADMIN_18, 'type'=>'number', 'tab'=>2, 'data' => 'int','help'=>LAN_SOCIAL_ADMIN_29), 'facebook_comments_theme' => array('title'=> LAN_SOCIAL_ADMIN_19, 'type'=>'dropdown', 'tab'=>2, 'writeParms'=>array('optArray'=>array('light'=>LAN_SOCIAL_ADMIN_35,'dark'=>LAN_SOCIAL_ADMIN_36)), 'data' => 'str','help'=>''), 'facebook_comments_loadingtext' => array('title'=> LAN_SOCIAL_ADMIN_21, 'type'=>'text', 'tab'=>2, 'data' => 'str', 'writeParms'=>array('placeholder'=>LAN_SOCIAL_ADMIN_30), 'help'=>''), 'facebook_like_menu_theme' => array('title'=> LAN_SOCIAL_ADMIN_19, 'type'=>'dropdown', 'tab'=>3, 'writeParms'=>array('optArray'=>array('light'=>LAN_SOCIAL_ADMIN_35,'dark'=>LAN_SOCIAL_ADMIN_36)), 'data' => 'str'), 'facebook_like_menu_action' => array('title'=> LAN_SOCIAL_ADMIN_20, 'type'=>'dropdown', 'tab'=>3, 'writeParms'=>array('optArray'=>array('like'=>'Like','recommend'=>LAN_SOCIAL_ADMIN_32)), 'data' => 'str'), 'facebook_like_menu_width' => array('title'=> LAN_SOCIAL_ADMIN_22, 'type'=>'number', 'tab'=>3, 'data' => 'int','help'=>LAN_SOCIAL_ADMIN_31), // 'facebook_like_menu_ref' => array('title'=> "Referrer", 'type'=>'text', 'tab'=>2, 'data' => 'str', 'writeParms'=>'size=xxlarge', 'help'=>'Leave blank to use Site Url'), 'twitter_menu_theme' => array('title'=> LAN_SOCIAL_ADMIN_19, 'type'=>'dropdown', 'tab'=>4, 'writeParms'=>array('optArray'=>array('light'=>LAN_SOCIAL_ADMIN_35,'dark'=>LAN_SOCIAL_ADMIN_36)), 'data' => 'str'), 'twitter_menu_height' => array('title'=> LAN_SOCIAL_ADMIN_23, 'type'=>'number', 'tab'=>4, 'data' => 'int','help'=>LAN_SOCIAL_ADMIN_33), 'twitter_menu_limit' => array('title'=> LAN_SOCIAL_ADMIN_18, 'type'=>'number', 'tab'=>4, 'data' => 'int','help'=>LAN_SOCIAL_ADMIN_34), 'sharing_mode' => array('title'=> LAN_SOCIAL_ADMIN_24, 'type'=>'dropdown', 'tab'=>1, 'writeParms'=>array('optArray'=>array('normal'=>LAN_SOCIAL_ADMIN_25,'dropdown'=>LAN_SOCIAL_ADMIN_26,'off'=>LAN_SOCIAL_ADMIN_27)), 'data' => 'str','help'=>''), 'sharing_hashtags' => array('title'=> 'Hashtags', 'type'=>'tags', 'tab'=>1, 'data' => 'str','help'=>LAN_SOCIAL_ADMIN_28), 'sharing_providers' => array('title'=> LAN_SOCIAL_ADMIN_39, 'type'=>'checkboxes', 'tab'=>1, 'writeParms'=>array(), 'data' => 'str','help'=>''), 'xup_login_update_username' => array('title'=> LAN_SOCIAL_ADMIN_40, 'type'=>'bool', 'tab'=>0, 'writeParms'=>array(), 'data' => 'str','help'=>''), 'xup_login_update_avatar' => array('title'=> LAN_SOCIAL_ADMIN_41, 'type'=>'bool', 'tab'=>0, 'writeParms'=>array(), 'data' => 'str','help'=>''), 'og_image' => array('title'=> LAN_SOCIAL_ADMIN_42, 'type'=>'image', 'tab'=>5, 'data' => 'str','help'=>'og:image'), ); protected $social_logins = array(); /** * @var social_login_config */ protected $social_login_config_manager; protected $social_external = array(); const TEST_URL = SITEURL."?route=system/xup/test"; public function init() { $this->social_login_config_manager = new social_login_config(e107::getConfig()); if(!empty($_POST['save_social_logins']) ) { $cfg = e107::getConfig(); foreach ($_POST['social_login'] as $provider_name => $raw_updated_social_login) { $this->social_login_config_manager->setProviderConfig($provider_name, $raw_updated_social_login); } if(isset($_POST['social_login_active'])) { $social_login_flags = !!$_POST['social_login_active'] << social_login_config::ENABLE_BIT_GLOBAL | !!$_POST['social_login_test_page'] << social_login_config::ENABLE_BIT_TEST_PAGE; $cfg->setPref(social_login_config::SOCIAL_LOGIN_FLAGS, $social_login_flags); } $cfg->save(true, true, true); } if(!empty($_POST['save_social_pages']) && isset($_POST['xurl'])) { $cfg = e107::getConfig(); $cfg->setPref('xurl', $_POST['xurl']); $cfg->save(true, true, true); } $tp = e107::getParser(); require_once(e_PLUGIN."social/e_shortcode.php"); $obj = new social_shortcodes; $providers = $obj->getProviders(); foreach($providers as $k=>$v) { $this->prefs['sharing_providers']['writeParms']['optArray'][$k] = $k; } } // ------- Customize Create -------- public function beforeCreate($new_data, $old_data) { return $new_data; } public function afterCreate($new_data, $old_data, $id) { // do something } public function onCreateError($new_data, $old_data) { // do something } // ------- Customize Update -------- public function beforeUpdate($new_data, $old_data, $id) { return $new_data; } public function afterUpdate($new_data, $old_data, $id) { // do something } public function onUpdateError($new_data, $old_data, $id) { // do something } function renderHelp() { $action = $this->getAction(); switch($action) { case "configure": $notice = LAN_SOCIAL_ADMIN_45; break; case "unsupported": $notice = LAN_SOCIAL_ADMIN_48; break; case "prefs": return null; // todo? break; default: case "add": $notice = LAN_SOCIAL_ADMIN_46; break; } if($action == 'configure' || $action == 'add') { $notice .= "

".LAN_SOCIAL_ADMIN_08."

".self::TEST_URL.""; $callBack = SITEURL; $notice .= "

".LAN_SOCIAL_ADMIN_09."
".$callBack.""; } $tp = e107::getParser(); return array("caption"=>LAN_HELP,'text'=> $tp->toHTML($notice,true)); } public function unsupportedPage() { $slcm = $this->social_login_config_manager; $supported_providers = $slcm->getSupportedProviders(); $configured_providers = $slcm->getConfiguredProviders(); $unsupported_providers = array_diff($configured_providers, $supported_providers); // $configured_providers = array_diff($configured_providers, $unsupported_providers); return $this->generateSocialLoginSection($unsupported_providers, true ); } public function pagesPage() { $frm = $this->getUI(); $pref = e107::pref('core'); $text2 = " "; //XXX XURL Definitions. $xurls = array( 'facebook' => array('label'=>"Facebook", "placeholder"=>"eg. https://www.facebook.com/e107CMS"), 'twitter' => array('label'=>"Twitter", "placeholder"=>"eg. https://twitter.com/e107"), 'youtube' => array('label'=>"Youtube", "placeholder"=>"eg.https://youtube.com/e107Inc"), 'linkedin' => array('label'=>"LinkedIn", "placeholder"=>"eg. https://www.linkedin.com/groups?home=&gid=1782682"), 'github' => array('label'=>"GitHub", "placeholder"=>"eg. https://github.com/e107inc"), 'flickr' => array('label'=>"Flickr", "placeholder"=>""), 'instagram' => array('label'=>"Instagram", "placeholder"=>""), 'pinterest' => array('label'=>"Pinterest", "placeholder"=>""), 'steam' => array('label'=>"Steam", "placeholder"=>"eg. https://steamcommunity.com"), 'vimeo' => array('label'=>"Vimeo", "placeholder"=>""), 'twitch' => array('label'=>"Twitch", "placeholder"=>""), 'vk' => array('label'=>"VK (Vkontakte)", "placeholder"=>""), ); foreach($xurls as $k=>$var) { $keypref = "xurl[".$k."]"; $text_label = "xurl-".$k.""; $def = "XURL_". strtoupper($k); $help = LAN_SOCIAL_ADMIN_13." ".$var['label']." ".LAN_SOCIAL_ADMIN_12." (".$def.")"; $opts = array('size'=>'xxlarge','placeholder'=> $var['placeholder']); $text2 .= " "; } $text2 .= "
". $frm->help($help)." ".$frm->text($keypref, varset($pref['xurl'][$k]), false, $opts). "
"; $ret = $frm->open('social','post',null, 'class=form-horizontal'); $ret .= $text2; $ret .= "
".$frm->button('save_social_pages',1,'submit',LAN_SAVE)."
"; $ret .= $frm->token(); $ret .= $frm->close(); return $ret; } public function modifyPage() { $frm= $this->getUI(); $var = $this->getId(); $this->addTitle($var); $text = $frm->open('add-social', 'post', e_SELF."?mode=main&action=add"); $text .= $this->generateSocialLoginForm($var); $text .= "
".$frm->button('save_social_logins',1,'submit',LAN_ADD)."
"; $text .= $frm->token(); $text .= $frm->close(); return $text; } public function addPage() { $slcm = $this->social_login_config_manager; $supported_providers = $slcm->getSupportedProviders(); $configured_providers = $slcm->getConfiguredProviders(); $unconfigured_providers = array_diff($supported_providers, $configured_providers); // $text = ""; $text = ''; foreach($unconfigured_providers as $value) { $link = e_SELF."?mode=main&action=modify&id=".$value; $text .= "".$value.""; } return $text; } // optional - a custom page. public function configurePage() { $ns = e107::getRender(); $frm = e107::getForm(); $pref = e107::pref('core'); $slcm = $this->social_login_config_manager; require_once("social_setup.php"); $social_setup = new social_setup(); if ($social_setup->upgrade_required()) { $srch = array('[',']'); $repl = array("", ""); e107::getMessage()->addInfo(str_replace($srch,$repl, LAN_SOCIAL_ADMIN_43)); return null; } $text = $this->generateAdminFormJs(); $text .= "
"; $supported_providers = $slcm->getSupportedProviders(); $configured_providers = $slcm->getConfiguredProviders(); // $unconfigured_providers = array_diff($supported_providers, $configured_providers); $unsupported_providers = array_diff($configured_providers, $supported_providers); $configured_providers = array_diff($configured_providers, $unsupported_providers); $text .= $this->generateSocialLoginSection($configured_providers); $text .= "
".$frm->radio_switch('social_login_active', $slcm->isFlagActive($slcm::ENABLE_BIT_GLOBAL))."
".LAN_SOCIAL_ADMIN_07."
".$frm->radio_switch('social_login_test_page', $slcm->isFlagActive($slcm::ENABLE_BIT_TEST_PAGE))."
".LAN_SOCIAL_ADMIN_50."
"; $ret = $frm->open('social','post',null, 'class=form-horizontal').$text; $ret .= "
".$frm->button('save_social_logins',1,'submit',LAN_SAVE)."
"; $ret .= $frm->token(); $ret .= $frm->close(); return $ret; } /** * @param $text * @param array $provider_names * @return string */ private function generateSocialLoginSection($provider_names, $readonly=false) { if(empty($provider_names)) { return ""; } $text = " "; foreach ($provider_names as $provider_name) { // Check if the current configuration for the provider is valid try { new e_user_provider($provider_name, [], false); } catch (\Hybridauth\Exception\InvalidArgumentException $e) { e107::getMessage()->addError("[{$e->getCode()}] {$e->getMessage()}"); } catch (\Hybridauth\Exception\UnexpectedValueException $ignored) { } $text .= $this->generateSocialLoginRow($provider_name, $readonly); } $text .= "
" . LAN_SOCIAL_ADMIN_04 . " " . LAN_TYPE . " " . LAN_CONFIGURE . " " . LAN_SOCIAL_ADMIN_03 . "
"; return $text; } private function getLabel($fieldSlash) { $labels = array( 'keys/key' => LAN_SOCIAL_ADMIN_05, 'keys/id' => LAN_SOCIAL_ADMIN_05, 'keys/secret' => LAN_SOCIAL_ADMIN_06, 'scope' => LAN_SOCIAL_ADMIN_38 ); return varset($labels[$fieldSlash], ucfirst($fieldSlash)); } /** * @param $provider_name * @return string Text to append */ private function generateSocialLoginForm($provider_name) { $slcm = $this->social_login_config_manager; $provider_type = $slcm->getTypeOfProvider($provider_name); if (empty($provider_type)) $provider_type = "" . LAN_UNKNOWN . ""; $normalized_provider_name = $slcm->normalizeProviderName($provider_name); list($pretty_provider_name,) = array_pad(explode("-", $normalized_provider_name), 2, ""); $frm = e107::getForm(); $textKeys = ''; $textScope = ''; $label = !empty(self::getApiDocumentationUrlFor($provider_name)) ? "" . $pretty_provider_name . "" : $pretty_provider_name; $radio_label = strtolower($provider_name); $text = ""; $textEnabled = $frm->radio_switch("social_login[$provider_name][enabled]", $slcm->isProviderEnabled($provider_name), '', '', ['class' => 'e-expandit']); $text .= $textKeys . $textScope . ""; $text .= " "; $fieldInfo = e107::getParser()->toFlatArray($slcm->getFieldsOf($provider_name)); foreach ($fieldInfo as $fieldSlash => $description) { $field = str_replace("/", "][", $fieldSlash); $placeholder = self::getPlaceholderFor($provider_name, $fieldSlash); $frm_options = [ 'size' => 'xxlarge', 'placeholder' => $placeholder, ]; $text .= ""; } $text .= "
".LAN_ACTIVE."" . $textEnabled . "
".LAN_NAME."
".LAN_TYPE."$provider_type
".$this->getLabel($fieldSlash).""; $text .= $frm->text("social_login[$provider_name][$field]", $placeholder, 256, $frm_options); $text .= "
$description
"; $text .= "
"; return $text; } /** * @param $provider_name * @param bool $readonly * @return string Text to append */ private function generateSocialLoginRow($provider_name, $readonly = false) { $slcm = $this->social_login_config_manager; $provider_type = $slcm->getTypeOfProvider($provider_name); if (empty($provider_type)) $provider_type = "" . LAN_UNKNOWN . ""; $normalized_provider_name = $slcm->normalizeProviderName($provider_name); list($pretty_provider_name,) = array_pad(explode("-", $normalized_provider_name), 2, ""); $frm = e107::getForm(); $textKeys = ''; $textScope = ''; $label = !empty(self::getApiDocumentationUrlFor($provider_name)) ? "" . $pretty_provider_name . "" : $pretty_provider_name; $radio_label = strtolower($provider_name); $text = " $provider_type "; $text .= ""; $fieldInfo = e107::getParser()->toFlatArray($slcm->getFieldsOf($provider_name)); foreach ($fieldInfo as $fieldSlash => $description) { $field = str_replace("/", "][", $fieldSlash); $frm_options = [ 'size' => 'block-level', 'placeholder' => self::getPlaceholderFor($provider_name, $fieldSlash), ]; if($readonly) { $frm_options['readonly'] = 1; ; } $text .= ""; $text .= ""; } $text .= "
".$this->getLabel($fieldSlash)."".$frm->text("social_login[$provider_name][$field]", $slcm->getProviderConfig($provider_name, $fieldSlash), 256, $frm_options). "
$description
"; $text .= "
"; if($readonly) { $textEnabled = ($slcm->isProviderEnabled($provider_name)) ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON; } else { $enabledOpts = ['class' => 'e-expandit']; $textEnabled = $frm->radio_switch("social_login[$provider_name][enabled]", $slcm->isProviderEnabled($provider_name), '', '', $enabledOpts); } $text .= $textKeys . $textScope . "" . $textEnabled . ""; $text .= " "; return $text; } private static function getPlaceholderFor($providerName, $fieldSlash) { switch ($fieldSlash) { case "scope": $propertyName = "scope"; break; case "openid_identifier": $propertyName = "openidIdentifier"; break; default: $propertyName = ""; } try { $class = "\Hybridauth\Provider\\$providerName"; $reflection = new ReflectionClass($class); $properties = $reflection->getDefaultProperties(); return isset($properties[$propertyName]) ? $properties[$propertyName] : null; } catch (ReflectionException $e) { return null; } } private static function getApiDocumentationUrlFor($providerName) { try { $class = "\Hybridauth\Provider\\$providerName"; $reflection = new ReflectionClass($class); $properties = $reflection->getDefaultProperties(); return isset($properties['apiDocumentation']) ? $properties['apiDocumentation'] : null; } catch (ReflectionException $e) { return null; } } private function generateAdminFormJs() { return << var e107 = e107 || {'settings': {}, 'behaviors': {}}; let socialLoginSwitches = { 'social-login-test-page__switch': null, }; function socialLoginSwitchesHighstate(element) { if (element === undefined) return; let isActive = element.checked; if (isActive) { for (let key in socialLoginSwitches) { let toggle = $('[name='+key+']'); toggle.bootstrapSwitch('disabled', false); if (socialLoginSwitches[key] !== null) toggle.bootstrapSwitch('state', socialLoginSwitches[key]); } } else { for (let key in socialLoginSwitches) { let toggle = $('[name='+key+']'); socialLoginSwitches[key] = toggle.bootstrapSwitch('state'); toggle.bootstrapSwitch('state', false); toggle.bootstrapSwitch('disabled', true); } } } (function ($) { e107.behaviors.manageSocialLoginSwitches = { attach: function (context, settings) { let globalSwitch = $('[name=social-login-active__switch]'); socialLoginSwitchesHighstate(globalSwitch.get(0)); globalSwitch.on('switchChange.bootstrapSwitch', function(event) { socialLoginSwitchesHighstate(event.target); }); }, }; })(jQuery); EOD; } } class social_form_ui extends e_admin_form_ui { } class social_admin_tree_model extends e_tree_model { /** * Load data from theme meta file. * @param bool $force */ function loadBatch($force=false) { $themeList = e107::getTheme()->getList(); $newArray = array(); $parms = $this->getParams(); $siteTheme = e107::getPref('sitetheme'); if($parms['limitFrom'] == 0 && empty($parms['searchqry'])) // place the sitetheme first. { $newArray[] = $themeList[$siteTheme]; } foreach($themeList as $k=>$v) { if(!empty($parms['searchqry']) && stripos($v['description'],$parms['searchqry']) === false && stripos($v['folder'],$parms['searchqry']) === false && stripos($v['name'],$parms['searchqry']) === false) { continue; } if($v['path'] == $siteTheme) { continue; } $newArray[] = $v; } if(!empty($parms['limitTo']) && empty($parms['searchqry'])) { $arr = array_slice($newArray, $parms['limitFrom'], $parms['limitTo']); } else { $arr = $newArray; } foreach($arr as $k=>$v) { $v['social_id'] = $k; $v['social_thumbnail'] = !empty($v['thumbnail']) ? '{e_THEME}'.$v['path'].'/'.$v['thumbnail'] : null; $tmp = new e_model($v); $this->setNode($k,$tmp); } $this->setTotal(count($newArray)); } } new social_adminarea(); require_once(e_ADMIN."auth.php"); e107::getAdminUI()->runPage(); require_once(e_ADMIN."footer.php");