Changeset 534


Ignore:
Timestamp:
Sep 24, 2004, 1:41:23 AM (20 years ago)
Author:
z0rglub
Message:
  • (re)added feature : in remote site management, if a listing.xml file is found at PhpWebGallery root directory, it can be used to update a remote site
  • size and maxlength of prefix_thumbnail in admin/configuration are 10
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/remote_site.php

    r526 r534  
    160160
    161161/**
     162 * read $listing_file and update a remote site according to its id
     163 *
     164 * @param string listing_file
     165 * @param int site_id
     166 * @return void
     167 */
     168function update_remote_site($listing_file, $site_id)
     169{
     170  global $lang, $counts, $template, $removes, $errors;
     171 
     172  if (@fopen($listing_file, 'r'))
     173  {
     174    $counts = array(
     175      'new_elements' => 0,
     176      'new_categories' => 0,
     177      'del_elements' => 0,
     178      'del_categories' => 0
     179      );
     180    $removes = array();
     181       
     182    $xml_content = getXmlCode($listing_file);
     183    insert_remote_category($xml_content, $site_id, 'NULL', 0);
     184    update_category();
     185       
     186    $template->assign_block_vars(
     187      'update',
     188      array(
     189        'NB_NEW_CATEGORIES'=>$counts['new_categories'],
     190        'NB_DEL_CATEGORIES'=>$counts['del_categories'],
     191        'NB_NEW_ELEMENTS'=>$counts['new_elements'],
     192        'NB_DEL_ELEMENTS'=>$counts['del_elements']
     193        ));
     194       
     195    if (count($removes) > 0)
     196    {
     197      $template->assign_block_vars('update.removes', array());
     198    }
     199    foreach ($removes as $remove)
     200    {
     201      $template->assign_block_vars('update.removes.remote_remove',
     202                                   array('NAME'=>$remove));
     203    }
     204  }
     205  else
     206  {
     207    array_push($errors, $lang['remote_site_listing_not_found']);
     208  }
     209}
     210
     211/**
    162212 * searchs the "dir" node of the xml_dir given and insert the contained
    163213 * categories if the are not in the database yet. The function also deletes
     
    319369;';
    320370  $result = mysql_query($query);
     371  $to_delete = array();
    321372  while ($row = mysql_fetch_array($result))
    322373  {
    323374    if (!in_array($row['file'], $xml_files))
    324375    {
    325       array_push($removes, $row['file']);
    326       delete_element($row['id']);
    327     }
    328   }
     376      // local_dir is cached
     377      if (!isset($local_dir))
     378      {
     379        $local_dir = get_local_dir($category_id);
     380      }
     381      array_push($removes, $local_dir.$row['file']);
     382      array_push($to_delete, $row['id']);
     383    }
     384  }
     385  delete_elements($to_delete);
    329386
    330387  $database_elements = array();
     
    443500    'L_REMOTE_SITE_REMOVED_TITLE'=>$lang['remote_site_removed_title'],
    444501    'L_REMOTE_SITE_REMOVED'=>$lang['remote_site_removed'],
     502    'L_REMOTE_SITE_LOCAL_FOUND'=>$lang['remote_site_local_found'],
     503    'L_REMOTE_SITE_LOCAL_NEW'=>$lang['remote_site_local_new'],
     504    'L_REMOTE_SITE_LOCAL_UPDATE'=>$lang['remote_site_local_update'],
    445505   
    446506    'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=remote_site')
     
    524584if (isset($_GET['action']))
    525585{
    526   $query = '
     586  if (isset($page['site']))
     587  {
     588    $query = '
    527589SELECT galleries_url
    528590  FROM '.SITES_TABLE.'
    529591  WHERE id = '.$page['site'].'
    530592;';
    531   $row = mysql_fetch_array(mysql_query($query));
    532   $clf = $row['galleries_url'].'create_listing_file.php';
    533  
     593    list($galleries_url) = mysql_fetch_array(mysql_query($query));
     594  }
     595
    534596  switch($_GET['action'])
    535597  {
     
    537599    {
    538600      delete_site($page['site']);
    539      
     601
    540602      $template->assign_block_vars(
    541603        'confirmation',
    542604        array(
    543           'CONTENT'=>$row['galleries_url'].' '.$lang['remote_site_deleted']
     605          'CONTENT'=>$galleries_url.' '.$lang['remote_site_deleted']
    544606          ));
    545607     
     
    548610    case 'generate' :
    549611    {
    550       $title = $row['galleries_url'].' : '.$lang['remote_site_generate'];
     612      $title = $galleries_url.' : '.$lang['remote_site_generate'];
    551613      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
    552       remote_output($clf.'?action=generate');
     614      remote_output($galleries_url.'create_listing_file.php?action=generate');
    553615      break;
    554616    }
    555617    case 'update' :
    556618    {
    557       $title = $row['galleries_url'].' : '.$lang['remote_site_update'];
     619      $title = $galleries_url.' : '.$lang['remote_site_update'];
    558620      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
     621      update_remote_site($galleries_url.'listing.xml', $page['site']);
     622      break;
     623    }
     624    case 'clean' :
     625    {
     626      $title = $galleries_url.' : '.$lang['remote_site_clean'];
     627      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
     628      remote_output($galleries_url.'create_listing_file.php?action=clean');
     629      break;
     630    }
     631    case 'local_update' :
     632    {
     633      $local_listing = PHPWG_ROOT_PATH.'listing.xml';
     634      $xml_content = getXmlCode($local_listing);
     635      $url = getAttribute(getChild($xml_content, 'informations'), 'url');
     636
     637      // is the site already existing ?
     638      $query = '
     639SELECT id
     640  FROM '.SITES_TABLE.'
     641  WHERE galleries_url = \''.addslashes($url).'\'
     642;';
     643      $result = mysql_query($query);
     644      if (mysql_num_rows($result) == 0)
     645      {
     646        // we have to register this site in the database
     647        $query = '
     648INSERT INTO '.SITES_TABLE.'
     649  (galleries_url)
     650  VALUES
     651  (\''.$url.'\')
     652;';
     653        mysql_query($query);
     654        $site_id = mysql_insert_id();
     655      }
     656      else
     657      {
     658        // we get the already registered id
     659        $row = mysql_fetch_array($result);
     660        $site_id = $row['id'];
     661      }
    559662     
    560       if (@fopen($row['galleries_url'].'listing.xml', 'r'))
    561       {
    562         $counts = array(
    563           'new_elements' => 0,
    564           'new_categories' => 0,
    565           'del_elements' => 0,
    566           'del_categories' => 0
    567           );
    568         $removes = array();
    569        
    570         $xml_content = getXmlCode($row['galleries_url'].'listing.xml');
    571         insert_remote_category($xml_content, $page{'site'}, 'NULL', 0);
    572         update_category();
    573        
    574         $template->assign_block_vars(
    575           'update',
    576           array(
    577             'NB_NEW_CATEGORIES'=>$counts['new_categories'],
    578             'NB_DEL_CATEGORIES'=>$counts['del_categories'],
    579             'NB_NEW_ELEMENTS'=>$counts['new_elements'],
    580             'NB_DEL_ELEMENTS'=>$counts['del_elements']
    581             ));
    582        
    583         if (count($removes) > 0)
    584         {
    585           $template->assign_block_vars('update.removes', array());
    586         }
    587         foreach ($removes as $remove)
    588         {
    589           $template->assign_block_vars('update.removes.remote_remove',
    590                                        array('NAME'=>$remove));
    591         }
    592       }
    593       else
    594       {
    595         array_push($errors, $lang['remote_site_listing_not_found']);
    596       }
     663      $title = $url.' : '.$lang['remote_site_local_update'];
     664      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
     665      update_remote_site($local_listing, $site_id);
    597666      break;
    598667    }
    599     case 'clean' :
    600     {
    601       $title = $row['galleries_url'].' : '.$lang['remote_site_clean'];
    602       $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
    603       remote_output($clf.'?action=clean');
    604       break;
     668  }
     669}
     670else
     671{
     672  // we search a "local" listing.xml file
     673  $local_listing = PHPWG_ROOT_PATH.'listing.xml';
     674  if (is_file($local_listing))
     675  {
     676    $xml_content = getXmlCode($local_listing);
     677    $url = getAttribute(getChild($xml_content, 'informations'), 'url');
     678
     679    $base_url = PHPWG_ROOT_PATH.'admin.php?page=remote_site&action=';
     680   
     681    $template->assign_block_vars(
     682      'local',
     683      array(
     684        'URL' => $url,
     685        'U_UPDATE' => add_session_id($base_url.'local_update')
     686        )
     687      );
     688
     689    // is the site already existing ?
     690    $query = '
     691SELECT COUNT(*)
     692  FROM '.SITES_TABLE.'
     693  WHERE galleries_url = \''.addslashes($url).'\'
     694;';
     695    list($count) = mysql_fetch_array(mysql_query($query));
     696    if ($count == 0)
     697    {
     698      $template->assign_block_vars('local.new_site', array());
    605699    }
    606700  }
  • trunk/language/en_UK.iso-8859-1/admin.lang.php

    r532 r534  
    11<?php
    22// +-----------------------------------------------------------------------+
    3 // |                           en_UK/admin.lang.php                           |
     3// |                         en_UK/admin.lang.php                          |
    44// +-----------------------------------------------------------------------+
    55// | application   : PhpWebGallery <http://phpwebgallery.net>              |
    6 // | branch        : BSF (Best So Far)                                                   |
     6// | branch        : BSF (Best So Far)                                     |
    77// +-----------------------------------------------------------------------+
    88// | file          : $RCSfile$
     
    6767$lang['remote_site_file_not_found'] = 'file create_listing_file.php on remote site was not found';
    6868$lang['remote_site_error'] = 'an error happened';
    69 $lang['remote_site_listing_not_found'] = 'remote listing file was not found';
     69$lang['remote_site_listing_not_found'] = 'listing.xml file was not found';
    7070$lang['remote_site_removed'] = 'was removed on remote site';
    7171$lang['remote_site_removed_title'] = 'Removed elements';
    7272$lang['remote_site_created'] = 'created';
    7373$lang['remote_site_deleted'] = 'deleted';
     74$lang['remote_site_local_found'] = 'A local listing.xml file has been found for ';
     75$lang['remote_site_local_new'] = '(new site)';
     76$lang['remote_site_local_update'] = 'read local listing.xml and update';
    7477
    7578// Categorie words
  • trunk/template/default/admin/configuration.tpl

    r527 r534  
    2626  <tr>
    2727    <td><strong>{general.L_CONF_TN_PREFIX}&nbsp;:</strong><br /><span class="small">{general.L_CONF_TN_PREFIX_INFO}</span></td>
    28         <td class="row1"><input type="text" size="3" maxlength="4" name="prefix_thumbnail" value="{general.THUMBNAIL_PREFIX}" /></td>
     28        <td class="row1"><input type="text" size="10" maxlength="10" name="prefix_thumbnail" value="{general.THUMBNAIL_PREFIX}" /></td>
    2929  </tr>
    3030  <tr>
  • trunk/template/default/admin/remote_site.tpl

    r526 r534  
    4343<!-- END remote_output -->
    4444
     45<!-- BEGIN local -->
     46<div class="remoteLocal">
     47  {L_REMOTE_SITE_LOCAL_FOUND} {local.URL}
     48  <!-- BEGIN new_site -->
     49  {L_REMOTE_SITE_LOCAL_NEW}
     50  <!-- END new_site -->
     51  [<a href="{local.U_UPDATE}">{L_REMOTE_SITE_LOCAL_UPDATE}</a>]
     52</div>
     53<!-- END local -->
     54
    4555<form action="{F_ACTION}" method="post">
    4656  {L_REMOTE_SITE_CREATE}
  • trunk/template/default/default.css

    r531 r534  
    413413  color:#ffe1e1;
    414414}
     415
     416div.remoteOutput, div.remoteLocal {
     417  background-color:#444444;
     418  border:1px solid black;
     419  margin:10px;
     420  text-align:left;
     421  padding:5px;
     422}
     423
     424li.remoteInfo {
     425  color:gray;
     426}
     427
     428li.remoteWarning {
     429  color:#ffe1e1;
     430}
     431
     432li.remoteError {
     433  color:orange;
     434}
     435
     436div.remoteLocal {
     437  text-align:center;
     438}
Note: See TracChangeset for help on using the changeset viewer.