Changeset 20301


Ignore:
Timestamp:
Jan 20, 2013, 9:41:55 PM (11 years ago)
Author:
mistic100
Message:

clean code

Location:
extensions/oAuth
Files:
4 added
1 deleted
11 edited
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • extensions/oAuth/admin/config.php

    r20293 r20301  
    3030    }
    3131   
    32     if ($id == 'Wordpress' and $data['enabled'] and !@$providers['OpenID']['enabled'])
     32    if ( ($id=='Wordpress' or $id=='Flickr') and $data['enabled'] and !@$providers['OpenID']['enabled'] )
    3333    {
    34       array_push($page['errors'], sprintf(l10n('OpenID must be enabled in order to use %s authentification'), $id));
     34      array_push($page['errors'], sprintf(l10n('OpenID must be enabled in order to use %s authentication'), $id));
    3535      $error = true;
    3636    }
     
    5555    $content.= ";\n?>";
    5656    file_put_contents(OAUTH_CONFIG, $content);
     57 
     58    // plugin config
     59    $conf['oauth'] = array(
     60      'display_register' => isset($_POST['display_register']),
     61      'display_menubar' => isset($_POST['display_menubar']),
     62      );
     63     
     64    conf_update_param('oauth', serialize($conf['oauth']));
     65    array_push($page['infos'], l10n('Information data registered in database'));
    5766  }
    58  
    59   // plugin config
    60   $conf['oauth'] = array(
    61     'display_register' => isset($_POST['display_register']),
    62     'display_menubar' => isset($_POST['display_menubar']),
    63     );
    64    
    65   conf_update_param('oauth', serialize($conf['oauth']));
    66   array_push($page['infos'], l10n('Information data registered in database'));
    6767}
    6868
  • extensions/oAuth/admin/template/config.tpl

    r20293 r20301  
    3636
    3737<div class="titrePage">
    38         <h2>oAuth</h2>
     38        <h2>OAuth</h2>
    3939</div>
    4040
     
    125125      <li>{'Put your website domain in the %s fields. It should match with the current hostname: <em>%s</em>'|@translate|sprintf:'<b>Redirect Domain</b>':$SERVERNAME}</li>
    126126    {elseif $p=='Facebook'}
    127       <li>{'Select <em>Website with facebook authentification</em> as application type'|@translate}</li>
     127      <li>{'Select <em>Website with facebook authentication</em> as application type'|@translate}</li>
    128128      <li>{'Put your website domain in the %s fields. It should match with the current hostname: <em>%s</em>'|@translate|sprintf:'<b>Site Url</b>, <b>App Domains</b>':$SERVERNAME}</li>
    129129    {elseif $p=='LinkedIn'}
  • extensions/oAuth/auth.php

    r20293 r20301  
    99
    1010try {
     11  // inputs
    1112  if ( $provider == 'OpenID' and !isset($_GET['openid_identifier']) )
    1213  {
    13     throw new Exception('Invalid OpenID!');
     14    throw new Exception('Invalid OpenID!', 1003);
    1415  }
    1516 
    16   // inputs
    1717  if (
    1818    !array_key_exists($provider, $hybridauth_conf['providers'])
    1919    or !$hybridauth_conf['providers'][$provider]['enabled']
    2020  ) {
    21     throw new Exception('Hacking attempt!');
     21    throw new Exception('Hacking attempt!', 1002);
    2222  }
    23  
    24  
    2523 
    2624  $hybridauth = new Hybrid_Auth($hybridauth_conf);
     
    2927  if ($hybridauth->isConnectedWith($provider))
    3028  {
    31     $template->assign('AUTH_DONE', true);
    32    
    3329    $adapter = $hybridauth->getAdapter($provider);
    3430    $remote_user = $adapter->getUserProfile();
     
    6965  else if (isset($_GET['init_auth']))
    7066  {
    71     $params = array('hauth_return_to', get_absolute_root_url().OAUTH_PATH.'auth.php?provider='.$provider.'&amp;auth_done=1');
     67    $params = array('hauth_return_to', get_absolute_root_url() . OAUTH_PATH . 'auth.php?provider='.$provider.'&amp;auth_done=1');
    7268    if ($provider == 'OpenID')
    7369    {
     
    8379    $template->assign('LOADING', '&openid_identifier='.@$_GET['openid_identifier'].'&init_auth=1');
    8480  }
    85 }
    86 catch( Exception $e ){
    87   $template->assign('ERROR', $e->getMessage());
     81}
     82/*
     83 library errors :
     84     0 : Unspecified error
     85     1 : Hybriauth configuration error
     86     2 : Provider not properly configured
     87     3 : Unknown or disabled provider
     88     4 : Missing provider application credentials
     89     5 : Authentication aborded
     90 other errors :
     91  1002 : Invalid provider
     92  1003 : Missing openid_identifier
     93*/
     94catch (Exception $e) {
     95  switch ($e->getCode()) {
     96    case 5:
     97      $template->assign('ERROR', l10n('Authentication canceled')); break;
     98    default:
     99      $template->assign('ERROR', sprintf(l10n('An error occured, please contact the gallery owner. <i>Error code : %s</i>'), $e->getCode()));
     100  }
    88101}
    89102
     
    96109  'OAUTH_PATH' => OAUTH_PATH,
    97110  'PROVIDER' => $provider,
    98   'SELF_URL' => OAUTH_PATH.'auth.php?provider='.$provider,
     111  'SELF_URL' => OAUTH_PATH . 'auth.php?provider='.$provider,
    99112  ));
    100113
    101 $template->set_filename('index', realpath(OAUTH_PATH.'template/auth.tpl'));
     114$template->set_filename('index', realpath(OAUTH_PATH . 'template/auth.tpl'));
    102115$template->pparse('index');
    103116?>
  • extensions/oAuth/include/providers_stats.inc.php

    r20293 r20301  
    1010    'scope'             => 'email',
    1111  ),
     12 
    1213  'Google' => array(
    1314    'label'             => 'Google',
     
    3031    'new_app_link'      => 'https://www.linkedin.com/secure/developer',
    3132    'userguide_section' => 'http://hybridauth.sourceforge.net/userguide/IDProvider_info_LinkedIn.html',
    32   ),
    33   'OpenID' => array(
    34     'label'             => 'OpenID',
    35     'provider_name'     => 'OpenID',
    36     'new_app_link'      => null,
    37     'userguide_section' => 'http://hybridauth.sourceforge.net/userguide/IDProvider_info_OpenID.html',
    3833  ),
    3934  'Tumblr' => array(
     
    6257    'userguide_section' => 'http://hybridauth.sourceforge.net/userguide/IDProvider_info_Yahoo.html',
    6358  ),
     59  'OpenID' => array(
     60    'label'             => 'OpenID',
     61    'provider_name'     => 'OpenID',
     62    'new_app_link'      => null,
     63    'userguide_section' => 'http://hybridauth.sourceforge.net/userguide/IDProvider_info_OpenID.html',
     64  ),
     65  'Flickr' => array(
     66    'label'             => 'Flickr',
     67    'provider_name'     => 'Flickr',
     68    'new_app_link'      => null,
     69    'userguide_section' => 'http://hybridauth.sourceforge.net/userguide/IDProvider_info_OpenID.html',
     70  ),
    6471  'Wordpress' => array(
    6572    'label'             => 'Wordpress',
  • extensions/oAuth/include/public_events.inc.php

    r20293 r20301  
    77function oauth_begin_identification()
    88{
    9   global $template, $conf, $page, $hybridauth_conf;
    10  
    11   if (isset($_GET['redirect']))
    12   {
    13     pwg_set_session_var('oauth_redirect', $_GET['redirect']);
    14   }
    15   else
    16   {
    17     pwg_unset_session_var('oauth_redirect');
    18   }
     9  global $template;
    1910 
    2011  // template icons
     
    2213  {
    2314    $template->assign(array(
    24       'OAUTH_URL' => get_root_url().OAUTH_PATH.'auth.php?provider=',
     15      'OAUTH_URL' => get_root_url() . OAUTH_PATH . 'auth.php?provider=',
    2516      'OAUTH_PATH' => OAUTH_PATH,
    26       'OAUTH_ABS_PATH' => realpath(OAUTH_PATH).'/',
     17      'OAUTH_ABS_PATH' => realpath(OAUTH_PATH) . '/',
    2718      'PROVIDERS' => get_activated_providers(),
    2819    ));
     
    5243    list($oauth_id) = pwg_db_fetch_row($result);
    5344    list($provider) = explode('---', $oauth_id);
    54     $_SESSION['page_errors'][] = 'You registered with a '.ucfirst($provider).' account, please login with the same account.';
     45    $_SESSION['page_errors'][] = sprintf(l10n('You registered with a %s account, please sign in with the same account.'), $provider);
    5546   
    5647    $redirect_to = get_root_url().'identification.php';
     
    6859{
    6960  global $conf, $template, $hybridauth_conf;
    70  
    71   if (!$conf['oauth']['display_register'])
    72   {
    73     return;
    74   }
    7561 
    7662  // comming from identification page
     
    135121      $template->set_prefilter('register', 'oauth_remove_password_fields_prefilter');
    136122    }
    137     catch( Exception $e ){
    138       die($e->getMessage());
     123    catch (Exception $e) {
     124      array_push($page['errors'], sprintf(l10n('An error occured, please contact the gallery owner. <i>Error code : %s</i>'), $e->getCode()));
    139125    }
    140126  }
    141   else
     127  // display login buttons
     128  else if ($conf['oauth']['display_register'])
    142129  {
    143130    // template icons
     
    145132    {
    146133      $template->assign(array(
    147         'OAUTH_URL' => get_root_url().OAUTH_PATH.'auth.php?provider=',
     134        'OAUTH_URL' => get_root_url() . OAUTH_PATH . 'auth.php?provider=',
    148135        'OAUTH_PATH' => OAUTH_PATH,
    149         'OAUTH_ABS_PATH' => realpath(OAUTH_PATH).'/',
     136        'OAUTH_ABS_PATH' => realpath(OAUTH_PATH) . '/',
    150137        'PROVIDERS' => get_activated_providers(),
    151138        ));
     
    189176   
    190177    $template->assign(array(
    191       'OAUTH_PROVIDER' => ucfirst($provider),
     178      'OAUTH_PROVIDER' => $provider,
    192179      'OAUTH_USERNAME' => $remote_user->displayName,
    193180      'OAUTH_URL' => $remote_user->profileURL,
     
    197184   
    198185    $template->set_prefilter('profile_content', 'oauth_add_profile_prefilter');
    199   }
    200   catch( Exception $e ){
    201     die($e->getMessage());
    202   }
    203  
    204  
    205   $template->set_prefilter('profile_content', 'oauth_remove_password_fields_prefilter');
     186    $template->set_prefilter('profile_content', 'oauth_remove_password_fields_prefilter');
     187  }
     188  catch (Exception $e) {
     189    array_push($page['errors'], sprintf(l10n('An error occured, please contact the gallery owner. <i>Error code : %s</i>'), $e->getCode()));
     190  }
    206191}
    207192
     
    236221    $adapter->logout();
    237222  }
    238   catch( Exception $e ){
    239     die($e->getMessage());
     223  catch (Exception $e) {
     224    $_SESSION['page_errors'][] = sprintf(l10n('An error occured, please contact the gallery owner. <i>Error code : %s</i>'), $e->getCode());
    240225  }
    241226}
     
    249234  global $template, $conf;
    250235 
    251   if (!$conf['oauth']['display_menubar'])
     236  $menu = &$menu_ref_arr[0]; 
     237 
     238  if ( !$conf['oauth']['display_menubar'] or $menu->get_block('mbIdentification') == null )
    252239  {
    253240    return;
    254241  }
    255242 
    256   $menu = &$menu_ref_arr[0]; 
    257  
    258   if ($menu->get_block('mbIdentification') == null)
    259   {
    260     return;
    261   }
    262  
    263243  if ($template->get_template_vars('OAUTH_URL') == null)
    264244  {
    265245    $template->assign(array(
    266       'OAUTH_URL' => get_root_url().OAUTH_PATH.'auth.php?provider=',
     246      'OAUTH_URL' => get_root_url() . OAUTH_PATH . 'auth.php?provider=',
    267247      'OAUTH_PATH' => OAUTH_PATH,
    268       'OAUTH_ABS_PATH' => realpath(OAUTH_PATH).'/',
     248      'OAUTH_ABS_PATH' => realpath(OAUTH_PATH) . '/',
    269249      'PROVIDERS' => get_activated_providers(),
    270250      ));
     
    283263{
    284264  $search = '</form>';
    285   $add = file_get_contents(OAUTH_PATH.'template/identification_page.tpl');
     265  $add = file_get_contents(OAUTH_PATH . 'template/identification_page.tpl');
    286266  return str_replace($search, $search.$add, $content);
    287267}
     
    310290{
    311291  $search = '{include file=$block->template|@get_extent:$id }';
    312   $add = file_get_contents(OAUTH_PATH.'template/identification_menubar.tpl');
     292  $add = file_get_contents(OAUTH_PATH . 'template/identification_menubar.tpl');
    313293  return str_replace($search, $search.$add, $content);
    314294}
  • extensions/oAuth/language/en_UK/description.txt

    r20293 r20301  
     1Provides various ways to sign in your gallery (Twitter, Facebook, Google, etc.)
  • extensions/oAuth/language/fr_FR/description.txt

    r20293 r20301  
     1Fournit diverses manières de se connecter à la galerie (Twitter, Facebook, Google, etc.)
  • extensions/oAuth/main.inc.php

    r20293 r20301  
    11<?php
    22/*
    3 Plugin Name: oauth
     3Plugin Name: OAuth
    44Version: auto
    5 Description: This is not a plugin. It's a oauth for future plugins.
     5Description: Provides various ways to sign in your gallery (Twitter, Facebook, Google, etc.)
    66Plugin URI: auto
    77Author: Mistic
     
    4141  add_event_handler('get_admin_plugin_menu_links', 'oauth_admin_plugin_menu_links');
    4242 
    43   include_once(OAUTH_PATH . 'include/admin_events.inc.php');
     43  function oauth_admin_plugin_menu_links($menu)
     44  {
     45    array_push($menu, array(
     46      'NAME' => l10n('OAuth'),
     47      'URL' => OAUTH_ADMIN,
     48    ));
     49    return $menu;
     50  }
    4451}
    4552else if (!empty($hybridauth_conf) and function_exists('curl_init'))
     
    8794      if (defined('IN_ADMIN'))
    8895      {
    89         $_SESSION['page_infos'][] = 'oAuth updated to version '. OAUTH_VERSION;
     96        $_SESSION['page_infos'][] = 'OAuth updated to version '. OAUTH_VERSION;
    9097      }
    9198    }
     
    101108    if (empty($hybridauth_conf))
    102109    {
    103       array_push($page['errors'], l10n('oAuth: You need to configure the credentials'));
     110      array_push($page['errors'], l10n('OAuth: You need to configure the credentials'));
    104111    }
    105112    if (!function_exists('curl_init'))
    106113    {
    107       array_push($page['errors'], l10n('oAuth: cURL extension is needed'));
     114      array_push($page['errors'], l10n('OAuth: cURL extension is needed'));
    108115    }
    109116  }
  • extensions/oAuth/template/auth.tpl

    r20293 r20301  
    44  <meta http-equiv="Content-Type" content="text/html; charset={$CONTENT_ENCODING}">
    55  <title>{'Sign in with %s'|@translate|sprintf:$PROVIDER} | {$GALLERY_TITLE}</title>
    6  
    7   {combine_script id="jquery" load="footer"}
    8  
    9   {get_combined_css}
    10   {get_combined_scripts load='header'}
    11   {if not empty($head_elements)}
    12     {foreach from=$head_elements item=elt}{$elt}
    13     {/foreach}
    14   {/if}
    156</head>
    167
    178<body>
     9
     10<div style="text-align:center;margin-top:20px;">
     11{if $ERROR}
     12  <img id="loader" src="{$OAUTH_PATH}template/images/alert.png">
     13  <h3>{'Error...'|@translate}</h3>
     14  {$ERROR}<br>
     15  <a href="#" id="close">{'Close'|@translate}</a>
    1816 
    19 {if $LOADING}
    20   <img src="{$OAUTH_PATH}template/ajax-loader-big.gif">
    21   <script type="text/javascript">
    22     setTimeout('window.location.href = "{$SELF_URL}{$LOADING}";', 500);
     17  <script type="text/javascript">
     18    document.getElementById('close').onclick = function() {ldelim} window.self.close(); };
    2319  </script>
    2420 
    25 {elseif $AUTH_DONE}
    26   <script language="javascript">
    27     if (window.opener) {ldelim}
    28       window.opener.parent.redirect('{$REDIRECT_TO}');
    29     }
     21{elseif $LOADING}
     22  <img id="loader" src="{$OAUTH_PATH}template/images/ajax-loader-big.gif">
     23  <h3>{'Loading...'|@translate}</h3>
     24  {'Contacting <b>%s</b>. Please wait.'|@translate|sprintf:$PROVIDER}
     25 
     26  <script type="text/javascript">
     27    setTimeout('window.location.href = "{$SELF_URL}{$LOADING}";', 200);
     28  </script>
     29 
     30{elseif $REDIRECT_TO}
     31  <script type="text/javascript">
     32    if (window.opener) window.opener.parent.redirect('{$REDIRECT_TO}');
    3033    window.self.close();
    3134  </script>
    32 {elseif $ERROR}
    33   {$ERROR}<br>
    34   <a href="#" id="close">{'Close'|@translate}</a>
    3535{/if}
     36</div>
    3637
    37 
    38 {footer_script}{literal}
    39 $("a#close").click(function() {
    40   window.self.close();
    41 });
    42 {/literal}{/footer_script}
    43 
    44 
    45 
    46 {get_combined_scripts load='footer'}
    47 {if isset($footer_elements)}
    48   {foreach from=$footer_elements item=v}{$v}
    49   {/foreach}
    50 {/if}
    5138</body>
    5239</html>
  • extensions/oAuth/template/identification_common.tpl

    r20293 r20301  
    2929}
    3030
    31 // open authentification popup
     31// open authentication popup
    3232function open_auth(url) {ldelim}
    3333  window.open(
     
    4343 
    4444  switch(idp) {ldelim}
    45     case 'OpenID': case 'Wordpress':
     45    case 'OpenID': case 'Wordpress': case 'Flickr':
    4646      switch(idp) {ldelim}
    47         case 'OpenID': $("#openid_label").html('{'Please enter your OpenID URL'|@translate}'); break;
    48         case 'Wordpress': $("#openid_label").html('{'Please enter your Wordpress username'|@translate}'); break;
     47        case 'OpenID':
     48          $("#openid_label").html('{'Please enter your OpenID URL'|@translate}'); break;
     49        case 'Wordpress': case 'Flickr':
     50          $("#openid_label").html('{'Please enter your username'|@translate}'); break;
    4951      }
    5052 
     
    8284  switch(idp) {ldelim}
    8385    case 'Wordpress': oi = "http://" + oi + ".wordpress.com"; break;
     86    case 'Flickr': oi = "http://www.flickr.com/photos/" + oi + "/"; break;
    8487  }
    8588 
  • extensions/oAuth/template/profile.tpl

    r20293 r20301  
    2424  <img src="{$OAUTH_AVATAR}" class="avatar">
    2525{else}
    26   <img src="{$ROOT_URL}{$OAUTH_PATH}template/avatar-default.png" class="avatar">
     26  <img src="{$ROOT_URL}{$OAUTH_PATH}template/images/avatar-default.png" class="avatar">
    2727{/if}
    2828
Note: See TracChangeset for help on using the changeset viewer.