Changeset 2409


Ignore:
Timestamp:
Jul 1, 2008, 4:09:21 AM (16 years ago)
Author:
rvelices
Message:
  • remember me cookie security improvement (the time when the cookie was generated is saved and checked in range [now-remember_me_length; now]
  • tags improvements
    • pass to templates all fields in table #tags (handy for plugins such as type tags)
    • fix issue with tag letter when first letter is accentuated (utf-8)
    • tags are sorted on url_name instead of name (accentuated first letter chars are the same as without accent)
    • better use of columns in by letter display mode
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_global.php

    r2299 r2409  
    276276  // remove tags
    277277  $tags = get_common_tags($page['cat_elements_id'], -1);
    278   usort($tags, 'name_compare');
    279278
    280279  $template->assign(
  • trunk/include/functions_html.inc.php

    r2353 r2409  
    551551}
    552552
     553function tag_alpha_compare($a, $b)
     554{
     555  return strcmp(strtolower($a['url_name']), strtolower($b['url_name']));
     556}
     557
    553558/**
    554559 * exits the current script (either exit or redirect)
     
    733738}
    734739
    735 /** returns the argument_ids array with new sequenced keys based on related 
     740/** returns the argument_ids array with new sequenced keys based on related
    736741 * names. Sequence is not case sensitive.
    737742 * Warning: By definition, this function breaks original keys
  • trunk/include/functions_tag.inc.php

    r2308 r2409  
    6060
    6161  $query = '
    62 SELECT id, name, url_name
     62SELECT *
    6363  FROM '.TAGS_TABLE;
    6464  $result = pwg_query($query);
     
    8484{
    8585  $query = '
    86 SELECT id,
    87        name,
    88        url_name
     86SELECT *
    8987  FROM '.TAGS_TABLE.'
    9088;';
     
    9694  }
    9795
    98   usort($tags, 'name_compare');
     96  usort($tags, 'tag_alpha_compare');
    9997
    10098  return $tags;
     
    228226  }
    229227  $query = '
    230 SELECT id, name, url_name, count(*) counter
     228SELECT t.*, count(*) counter
    231229  FROM '.IMAGE_TAG_TABLE.'
    232     INNER JOIN '.TAGS_TABLE.' ON tag_id = id
     230    INNER JOIN '.TAGS_TABLE.' t ON tag_id = id
    233231  WHERE image_id IN ('.implode(',', $items).')';
    234232  if (!empty($excluded_tag_ids))
     
    257255    array_push($tags, $row);
    258256  }
    259   usort($tags, 'name_compare');
     257  usort($tags, 'tag_alpha_compare');
    260258  return $tags;
    261259}
     
    308306
    309307  $query = '
    310 SELECT id, url_name, name
     308SELECT *
    311309  FROM '.TAGS_TABLE.'
    312310  WHERE '. implode( '
  • trunk/include/functions_user.inc.php

    r2371 r2409  
    839839function get_default_language()
    840840{
    841   global $conf;
    842   if (isset($conf['browser_language']) and $conf['browser_language'])
    843   {
    844     return get_browser_language();
    845   }
    846   else
    847   {
    848     return get_default_user_value('language', PHPWG_DEFAULT_LANGUAGE);
    849   }
    850 }
    851 
    852 /*
    853  * Returns the browser language value
    854  *
    855  */
    856 function get_browser_language()
    857 {
    858   $browser_language = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2);
    859   foreach (get_languages() as $language_code => $language_name)
    860   {
    861     if (substr($language_code, 0, 2) == $browser_language)
    862     {
    863       return $language_code;
    864     }
    865   }
    866   return PHPWG_DEFAULT_LANGUAGE;
     841  return get_default_user_value('language', PHPWG_DEFAULT_LANGUAGE);
    867842}
    868843
     
    924899        $status = 'normal';
    925900      }
    926       $default_user['language'] = get_default_language();
    927901
    928902      $insert = array_merge(
     
    975949 * returns the auto login key or false on error
    976950 * @param int user_id
     951 * @param time_t time
    977952 * @param string [out] username
    978953*/
    979 function calculate_auto_login_key($user_id, &$username)
     954function calculate_auto_login_key($user_id, $time, &$username)
    980955{
    981956  global $conf;
     
    990965    $row = mysql_fetch_assoc($result);
    991966    $username = $row['username'];
    992     $data = $row['username'].$row['password'];
     967    $data = $time.$row['username'].$row['password'];
    993968    $key = base64_encode(
    994969      pack('H*', sha1($data))
     
    1012987  if ($remember_me and $conf['authorize_remembering'])
    1013988  {
    1014     $key = calculate_auto_login_key($user_id, $username);
     989    $now = time();
     990    $key = calculate_auto_login_key($user_id, $now, $username);
    1015991    if ($key!==false)
    1016992    {
    1017       $cookie = array('id' => (int)$user_id, 'key' => $key);
     993      $cookie = $user_id.'-'.$now.'-'.$key;
    1018994      setcookie($conf['remember_me_name'],
    1019             serialize($cookie),
     995            $cookie,
    1020996            time()+$conf['remember_me_length'],
    1021997            cookie_path()
     
    10501026  if ( isset( $_COOKIE[$conf['remember_me_name']] ) )
    10511027  {
    1052     $cookie = unserialize(stripslashes($_COOKIE[$conf['remember_me_name']]));
    1053     if ($cookie!==false and is_numeric(@$cookie['id']) )
    1054     {
    1055       $key = calculate_auto_login_key( $cookie['id'], $username );
    1056       if ($key!==false and $key===$cookie['key'])
    1057       {
    1058         log_user($cookie['id'], true);
     1028    $cookie = explode('-', stripslashes($_COOKIE[$conf['remember_me_name']]));
     1029    if ( count($cookie)===3
     1030        and is_numeric(@$cookie[0]) /*user id*/
     1031        and is_numeric(@$cookie[1]) /*time*/
     1032        and time()-$conf['remember_me_length']<=@$cookie[1]
     1033        and time()>=@$cookie[1] /*cookie generated in the past*/ )
     1034    {
     1035      $key = calculate_auto_login_key( $cookie[0], $cookie[1], $username );
     1036      if ($key!==false and $key===$cookie[2])
     1037      {
     1038        log_user($cookie[0], true);
    10591039        trigger_action('login_success', $username);
    10601040        return true;
  • trunk/include/menubar.inc.php

    r2325 r2409  
    112112    $template->append(
    113113      'related_tags',
    114       array(
    115         'U_TAG' => make_index_url(
    116           array(
    117             'tags' => array($tag)
    118             )
    119           ),
    120 
    121         'NAME' => $tag['name'],
    122 
    123         'CLASS' => 'tagLevel'.$tag['level'],
    124 
    125         'add' => array(
    126 
    127             'URL' => make_index_url(
    128               array(
    129                 'tags' => array_merge(
    130                   $page['tags'],
    131                   array($tag)
     114      array_merge( $tag,
     115        array(
     116          'URL' => make_index_url(
     117            array(
     118              'tags' => array($tag)
     119              )
     120            ),
     121
     122          'U_ADD' => make_index_url(
     123                array(
     124                  'tags' => array_merge(
     125                    $page['tags'],
     126                    array($tag)
     127                    )
    132128                  )
    133                 )
    134               ),
    135             'COUNTER' => $tag['counter'],
    136             )
     129                ),
     130          )
    137131        )
    138132      );
  • trunk/include/ws_functions.inc.php

    r2356 r2409  
    890890  else
    891891  {
    892     usort($tags, 'name_compare');
     892    usort($tags, 'tag_alpha_compare');
    893893  }
    894894  for ($i=0; $i<count($tags); $i++)
  • trunk/search.php

    r2324 r2409  
    187187if (count($available_tags) > 0)
    188188{
    189   usort( $available_tags, 'name_compare');
     189  usort( $available_tags, 'tag_alpha_compare');
    190190
    191191  $template->assign(
  • trunk/tags.php

    r2362 r2409  
    8585if ($page['display_mode'] == 'letters') {
    8686  // we want tags diplayed in alphabetic order
    87   usort($tags, 'name_compare');
     87  usort($tags, 'tag_alpha_compare');
    8888
    8989  $current_letter = null;
    90   $is_first_tag = true;
    9190  $nb_tags = count($tags);
    92   $current_column_tags = 0;
     91  $current_column = 1;
     92  $current_tag_idx = 0;
    9393
    9494  $letter = array(
     
    9898  foreach ($tags as $tag)
    9999  {
    100     $tag_letter = strtoupper(substr($tag['name'], 0, 1));
     100    $tag_letter = strtoupper(substr($tag['url_name'], 0, 1));
    101101
    102     if ($is_first_tag) {
     102    if ($current_tag_idx==0) {
    103103      $current_letter = $tag_letter;
    104104      $letter['TITLE'] = $tag_letter;
    105       $is_first_tag = false;
    106105    }
    107106
     
    109108    if ($tag_letter !== $current_letter)
    110109    {
    111       if ($current_column_tags > $nb_tags/$conf['tag_letters_column_number'])
     110      if ($current_column<$conf['tag_letters_column_number']
     111          and $current_tag_idx > $current_column*$nb_tags/$conf['tag_letters_column_number'] )
    112112      {
    113113        $letter['CHANGE_COLUMN'] = true;
    114         $current_column_tags = 0;
     114        $current_column++;
    115115      }
    116116
     
    121121        $letter
    122122        );
    123      
     123
    124124      $current_letter = $tag_letter;
    125125      $letter = array(
     
    130130    array_push(
    131131      $letter['tags'],
    132       array(
    133         'URL' => make_index_url(
    134           array(
    135             'tags' => array($tag),
    136             )
    137           ),
    138         'NAME' => $tag['name'],
    139         'COUNTER' => $tag['counter'],
     132      array_merge(
     133        $tag,
     134        array(
     135          'URL' => make_index_url(
     136            array(
     137              'tags' => array($tag),
     138              )
     139            ),
     140          )
    140141        )
    141142      );
    142    
    143     $current_column_tags++;
     143
     144    $current_tag_idx++;
    144145  }
    145146
     
    169170
    170171// we want tags diplayed in alphabetic order
    171 usort($tags, 'name_compare');
     172usort($tags, 'tag_alpha_compare');
    172173
    173174// display sorted tags
     
    176177  $template->append(
    177178    'tags',
    178     array(
    179       'URL' => make_index_url(
    180         array(
    181           'tags' => array($tag),
    182           )
    183         ),
    184 
    185       'NAME' => $tag['name'],
    186       'TITLE' => $tag['counter'],
    187       'CLASS' => 'tagLevel'.$tag['level'],
     179    array_merge(
     180      $tag,
     181      array(
     182        'URL' => make_index_url(
     183          array(
     184            'tags' => array($tag),
     185            )
     186          ),
     187        )
    188188      )
    189189    );
  • trunk/template/yoga/menubar.css

    r2356 r2409  
    11#menubar {
    2     float: left;
    3     margin: 0 0 10px 1em;
    4     padding: 0;
    5     /* Fix against the "double margin of a floated item" IE bug */
    6     /* Damned: that screws up top_navbar in opera 7.54/Linux! */
    7     display: inline;
    8     text-align: left; /* follow-up of the "be nice to IE5" rule */
     2        float: left;
     3        margin: 0 0 10px 1em;
     4        padding: 0;
     5        display: inline;
     6        text-align: left; /* follow-up of the "be nice to IE5" rule */
    97}
    108
    119#menubar DL, #menubar DT, #menubar DD {
    12     margin: 0; padding: 0; display: block;
     10        margin: 0; padding: 0; display: block;
    1311}
    1412
    1513#menubar .button {
    16   margin: 0 2px;
    17   width: auto;
    18   padding: 0;
    19   text-indent: 0;
    20   list-style: none;
    21   text-align: center;
    22   float: right;
     14        margin: 0 2px;
     15        width: auto;
     16        padding: 0;
     17        text-indent: 0;
     18        list-style: none;
     19        text-align: center;
     20        float: right;
    2321}
    2422
    2523/* H2 properties copied here */
    2624#menubar DT {
    27     font-weight: bold; /* default for h2 */
    28     margin: 0;
    29     padding: 5px 5px 5px 5px;
    30     font-size: 120%;
    31     text-align: center;
     25        font-weight: bold;
     26        margin: 0;
     27        padding: 5px 5px 5px 5px;
     28        font-size: 120%;
     29        text-align: center;
    3230}
    3331
     
    3735#menubar P, /* ooh, careful... */
    3836#menubar .totalImages {
    39     font-size: 92%;
    40     margin: 10px 0 10px 10px;
     37        font-size: 92%;
     38        margin: 10px 0 10px 10px;
    4139}
    4240#menubar UL {
    43     list-style-type: square;
    44     list-style-position: inside;
    45     padding: 0 0 0 2px;
     41        list-style-type: square;
     42        list-style-position: inside;
     43        padding: 0 0 0 2px;
    4644}
    4745#menubar UL UL {
    48     font-size: 100%;
    49     margin-top: 0;
    50     margin-bottom: 0;
     46        font-size: 100%;
     47        margin-top: 0;
     48        margin-bottom: 0;
    5149}
    5250
    5351#menubar LI.selected A {
    54   font-weight: bold;
     52        font-weight: bold;
    5553}
    5654
    5755#menubar LI.selected LI A {
    58   font-weight: normal;
     56        font-weight: normal;
    5957}
    6058
     
    6563
    6664#menubar HR {
    67     display: block;
    68     margin: 10px auto;
    69     width: 90%;
     65        display: block;
     66        margin: 10px auto;
     67        width: 90%;
    7068}
    7169#menubar INPUT {
    72     text-indent: 2px;
     70        text-indent: 2px;
    7371}
    7472
    7573/* quickconnect form */
    7674FORM#quickconnect {
    77   margin: 0;
    78   padding: 5px;
     75        margin: 0;
     76        padding: 5px;
    7977}
    8078
    8179FORM#quickconnect FIELDSET {
    82   margin: 0;
    83   padding: 0 0 0.5em 0;
     80        margin: 0;
     81        padding: 0 0 0.5em 0;
    8482}
    8583
    8684FORM#quickconnect P {
    87   margin-left: 0;
    88   font-size: 100%;
    89   float: left;
    90   clear: left;
     85        margin-left: 0;
     86        font-size: 100%;
     87        float: left;
     88        clear: left;
    9189}
    9290
    9391FORM#quickconnect P INPUT {
    94   margin: 0;
     92        margin: 0;
    9593}
    9694
    9795FORM#quickconnect UL.actions {
    98   display: inline;
    99   float: right;
    100   padding: 0;
    101   text-align: right;    /* Opera 7.5 */
     96        display: inline;
     97        float: right;
     98        padding: 0;
     99        text-align: right;      /* Opera 7.5 */
    102100}
    103101FORM#quickconnect FIELDSET>UL.actions {
    104   width: 40%;           /* Opera 7.5 cannot find why width:auto fails :-( */
     102        width: 40%;             /* Opera 7.5 cannot find why width:auto fails :-( */
    105103}
    106104
     
    108106FORM#quickconnect P,
    109107FORM#quickconnect LABEL {
    110   padding: 0 0.5em 0 0.5em;
     108        padding: 0 0.5em 0 0.5em;
    111109}
    112110
    113111FORM#quickconnect LABEL {
    114   margin:0;
    115   width: 100%;
    116   box-sizing: border-box; /* CSS3 */
     112        margin:0;
     113        width: 100%;
     114        box-sizing: border-box; /* CSS3 */
    117115}
    118116
    119117FORM#quickconnect INPUT[type=text],
    120118FORM#quickconnect INPUT[type=password] {
    121   width: 100%;  /* mozilla can handle 100% */
     119        width: 100%;    /* mozilla can handle 100% */
    122120}
    123 /* same as above for IE with inputfix.htc              */
    124 /* unfortunately IE doesn't handle that correctly      */
    125 /* so you should set a width in em in local_layout.css */
     121/* same as above for IE with inputfix.htc
     122unfortunately IE doesn't handle that correctly
     123 so you should set a width in em in local_layout.css */
    126124/*FORM#quickconnect INPUT.text,
    127125FORM#quickconnect INPUT.password {
     
    130128
    131129FORM#quicksearch {
    132   margin-top: 4px;
    133   margin-bottom: 1px;
     130        margin-top: 4px;
     131        margin-bottom: 1px;
    134132}
    135 input#qsearchInput {
    136   width: 90%;
     133INPUT#qsearchInput {
     134        width: 90%;
    137135}
    138136#menubar #mbMenu p { margin: 0px; padding: 0px; }
    139137
    140138#menubar #menuTagCloud {
    141   text-align: center;
    142   margin: 5px 0;
     139        text-align: center;
     140        margin: 5px 0;
    143141}
    144142
    145143#menubar #menuTagCloud LI
    146144{
    147   display: inline;
    148   white-space: nowrap;  /* No line break in the LI but Opera set nowrap to */
     145        display: inline;
     146        white-space: nowrap;    /* No line break in the LI but Opera set nowrap to */
    149147}
  • trunk/template/yoga/menubar.tpl

    r2325 r2409  
    2222
    2323  {if isset($U_START_FILTER)}
    24   <a href="{$U_START_FILTER}" title="{'start_filter_hint'|@translate}" rel="nofollow"><img src="{$ROOT_URL}{$themeconf.icon_dir}/start_filter.png" class="button" alt="{'start_filter_hint'|@translate}"></a>
     24  <a href="{$U_START_FILTER}" title="{'start_filter_hint'|@translate}" rel="nofollow"><img src="{$ROOT_URL}{$themeconf.icon_dir}/start_filter.png" class="button" alt="start filter"></a>
    2525  {/if}
    2626  {if isset($U_STOP_FILTER)}
    27   <a href="{$U_STOP_FILTER}" title="{'stop_filter_hint'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/stop_filter.png" class="button" alt="{'stop_filter_hint'|@translate}"></a>
     27  <a href="{$U_STOP_FILTER}" title="{'stop_filter_hint'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/stop_filter.png" class="button" alt="stop filter"></a>
    2828  {/if}
    2929
     
    4949    {foreach from=$related_tags item=tag}
    5050    <li>
    51     {if !empty($tag.add) }
    52       <a href="{$tag.add.URL}"
    53         title="{$pwg->l10n_dec('%d element are also linked to current tags', '%d elements are also linked to current tags', $tag.add.COUNTER)}"
     51    {if !empty($tag.U_ADD) }
     52      <a href="{$tag.U_ADD}"
     53        title="{$pwg->l10n_dec('%d element are also linked to current tags', '%d elements are also linked to current tags', $tag.counter)}"
    5454        rel="nofollow">
    5555        <img src="{$ROOT_URL}{$themeconf.icon_dir}/add_tag.png" alt="+" />
    5656      </a>
    5757    {/if}
    58     <a href="{$tag.U_TAG}" class="{$tag.CLASS}" title="{'See elements linked to this tag only'|@translate}">{$tag.NAME}</a>
     58    <a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{'See elements linked to this tag only'|@translate}">{$tag.name}</a>
    5959    </li>
    6060    {/foreach}
  • trunk/template/yoga/tags.tpl

    r2396 r2409  
    2121  <ul id="fullTagCloud">
    2222    {foreach from=$tags item=tag}
    23     <li><a href="{$tag.URL}" class="{$tag.CLASS}" title="{$tag.TITLE}">{$tag.NAME}</a></li>
     23    <li><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$tag.counter}">{$tag.name}</a></li>
    2424    {/foreach}
    2525  </ul>
     
    3636      {foreach from=$letter.tags item=tag}
    3737      <tr class="tagLine">
    38         <td><a href="{$tag.URL}">{$tag.NAME}</a></td>
    39         <td class="nbEntries">{$pwg->l10n_dec('%d element', '%d elements', $tag.COUNTER)}</td>
     38        <td><a href="{$tag.URL}">{$tag.name}</a></td>
     39        <td class="nbEntries">{$pwg->l10n_dec('%d element', '%d elements', $tag.counter)}</td>
    4040      </tr>
    4141      {/foreach}
Note: See TracChangeset for help on using the changeset viewer.