⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 general.php

📁 PHP 建站工具,CMS系统,类似与oscommerce
💻 PHP
📖 第 1 页 / 共 5 页
字号:
  // Cant be used in safe mode.
  function twe_set_time_limit($limit) {
    if (!get_cfg_var('safe_mode')) {
      @set_time_limit($limit);
    }
  }

  ////
  // Alias function for Store configuration values in the Administration Tool
  function twe_cfg_select_option($select_array, $key_value, $key = '') {
    for ($i = 0, $n = sizeof($select_array); $i < $n; $i++) {
      $name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
      $string .= '<br><input type="radio" name="' . $name . '" value="' . $select_array[$i] . '"';
      if ($key_value == $select_array[$i]) $string .= ' CHECKED';
      $string .= '> ' . $select_array[$i];
    }

    return $string;
  }

  ////
  // Alias function for module configuration keys
  function twe_mod_select_option($select_array, $key_name, $key_value) {
    reset($select_array);
    while (list($key, $value) = each($select_array)) {
      if (is_int($key)) $key = $value;
      $string .= '<br><input type="radio" name="configuration[' . $key_name . ']" value="' . $key . '"';
      if ($key_value == $key) $string .= ' CHECKED';
      $string .= '> ' . $value;
    }

    return $string;
  }

  ////
  // Retreive server information
  function twe_get_system_information() {

    $db_query = twe_db_query("select now() as datetime");
    $db = twe_db_fetch_array($db_query);

    list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);

    return array('date' => twe_datetime_short(date('Y-m-d H:i:s')),
                 'system' => $system,
                 'kernel' => $kernel,
                 'host' => $host,
                 'ip' => gethostbyname($host),
                 'uptime' => @exec('uptime'),
                 'http_server' => $_SERVER['SERVER_SOFTWARE'],
                 'php' => PHP_VERSION,
                 'zend' => (function_exists('zend_version') ? zend_version() : ''),
                 'db_server' => DB_SERVER,
                 'db_ip' => gethostbyname(DB_SERVER),
                 'db_version' => 'MySQL ' . (function_exists('mysql_get_server_info') ? mysql_get_server_info() : ''),
                 'db_date' => twe_datetime_short($db['datetime']));
  }

  function twe_array_shift(&$array) {
    if (function_exists('array_shift')) {
      return array_shift($array);
    } else {
      $i = 0;
      $shifted_array = array();
      reset($array);
      while (list($key, $value) = each($array)) {
        if ($i > 0) {
          $shifted_array[$key] = $value;
        } else {
          $return = $array[$key];
        }
        $i++;
      }
      $array = $shifted_array;

      return $return;
    }
  }

  function twe_array_reverse($array) {
    if (function_exists('array_reverse')) {
      return array_reverse($array);
    } else {
      $reversed_array = array();
      for ($i=sizeof($array)-1; $i>=0; $i--) {
        $reversed_array[] = $array[$i];
      }
      return $reversed_array;
    }
  }

  function twe_generate_category_path($id, $from = 'category', $categories_array = '', $index = 0) {

    if (!is_array($categories_array)) $categories_array = array();

    if ($from == 'product') {
      $categories_query = twe_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $id . "'");
      while ($categories = twe_db_fetch_array($categories_query)) {
        if ($categories['categories_id'] == '0') {
          $categories_array[$index][] = array('id' => '0', 'text' => TEXT_TOP);
        } else {
          $category_query = twe_db_query("select cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . $categories['categories_id'] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . $_SESSION['languages_id'] . "'");
          $category = twe_db_fetch_array($category_query);
          $categories_array[$index][] = array('id' => $categories['categories_id'], 'text' => $category['categories_name']);
          if ( (twe_not_null($category['parent_id'])) && ($category['parent_id'] != '0') ) $categories_array = twe_generate_category_path($category['parent_id'], 'category', $categories_array, $index);
          $categories_array[$index] = twe_array_reverse($categories_array[$index]);
        }
        $index++;
      }
    } elseif ($from == 'category') {
      $category_query = twe_db_query("select cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . $id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . $_SESSION['languages_id'] . "'");
      $category = twe_db_fetch_array($category_query);
      $categories_array[$index][] = array('id' => $id, 'text' => $category['categories_name']);
      if ( (twe_not_null($category['parent_id'])) && ($category['parent_id'] != '0') ) $categories_array = twe_generate_category_path($category['parent_id'], 'category', $categories_array, $index);
    }

    return $categories_array;
  }

  function twe_output_generated_category_path($id, $from = 'category') {
    $calculated_category_path_string = '';
    $calculated_category_path = twe_generate_category_path($id, $from);
    for ($i = 0, $n = sizeof($calculated_category_path); $i < $n; $i++) {
      for ($j = 0, $k = sizeof($calculated_category_path[$i]); $j < $k; $j++) {
        $calculated_category_path_string .= $calculated_category_path[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
      }
      $calculated_category_path_string = substr($calculated_category_path_string, 0, -16) . '<br>';
    }
    $calculated_category_path_string = substr($calculated_category_path_string, 0, -4);

    if (strlen($calculated_category_path_string) < 1) $calculated_category_path_string = TEXT_TOP;

    return $calculated_category_path_string;
  }

  function twe_remove_category($category_id) {
    $category_image_query = twe_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id = '" . twe_db_input($category_id) . "'");
    $category_image = twe_db_fetch_array($category_image_query);

    $duplicate_image_query = twe_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where categories_image = '" . twe_db_input($category_image['categories_image']) . "'");
    $duplicate_image = twe_db_fetch_array($duplicate_image_query);

    if ($duplicate_image['total'] < 2) {
      if (file_exists(DIR_FS_CATALOG_IMAGES . $category_image['categories_image'])) {
        @unlink(DIR_FS_CATALOG_IMAGES . $category_image['categories_image']);
      }
    }

    twe_db_query("delete from " . TABLE_CATEGORIES . " where categories_id = '" . twe_db_input($category_id) . "'");
    twe_db_query("delete from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . twe_db_input($category_id) . "'");
    twe_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . twe_db_input($category_id) . "'");

    if (USE_CACHE == 'true') {
      twe_reset_cache_block('categories');
      twe_reset_cache_block('also_purchased');
    }
  }

  function twe_remove_product($product_id) {
    $product_image_query = twe_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . twe_db_input($product_id) . "'");
    $product_image = twe_db_fetch_array($product_image_query);

    $duplicate_image_query = twe_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_image = '" . twe_db_input($product_image['products_image']) . "'");
    $duplicate_image = twe_db_fetch_array($duplicate_image_query);

    if ($duplicate_image['total'] < 2) {
      if (file_exists(DIR_FS_CATALOG_POPUP_IMAGES . $product_image['products_image'])) {
        @unlink(DIR_FS_CATALOG_POPUP_IMAGES . $product_image['products_image']);
      }
// START CHANGES
	  $image_subdir = BIG_IMAGE_SUBDIR;
	  if (substr($image_subdir, -1) != '/') $image_subdir .= '/';
      if (file_exists(DIR_FS_CATALOG_IMAGES . $image_subdir . $product_image['products_image'])) {
        @unlink(DIR_FS_CATALOG_IMAGES . $image_subdir . $product_image['products_image']);
      }
// END CHANGES
    }

    twe_db_query("delete from " . TABLE_SPECIALS . " where products_id = '" . twe_db_input($product_id) . "'");
    twe_db_query("delete from " . TABLE_PRODUCTS . " where products_id = '" . twe_db_input($product_id) . "'");
    twe_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . twe_db_input($product_id) . "'");
    twe_db_query("delete from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . twe_db_input($product_id) . "'");
    twe_db_query("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . twe_db_input($product_id) . "'");
    twe_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where products_id = '" . twe_db_input($product_id) . "'");
    twe_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where products_id = '" . twe_db_input($product_id) . "'");

    $customers_status_array=twe_get_customers_statuses();
    for ($i=0,$n=sizeof($customers_status_array);$i<$n;$i++) {
     twe_db_query("delete from personal_offers_by_customers_status_" . $i . " where products_id = '" . twe_db_input($product_id) . "'");

    }

    $product_reviews_query = twe_db_query("select reviews_id from " . TABLE_REVIEWS . " where products_id = '" . twe_db_input($product_id) . "'");
    while ($product_reviews = twe_db_fetch_array($product_reviews_query)) {
      twe_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . $product_reviews['reviews_id'] . "'");
    }
    twe_db_query("delete from " . TABLE_REVIEWS . " where products_id = '" . twe_db_input($product_id) . "'");

    if (USE_CACHE == 'true') {
      twe_reset_cache_block('categories');
      twe_reset_cache_block('also_purchased');
    }
  }

  function twe_remove_order($order_id, $restock = false) {
    if ($restock == 'on') {
      $order_query = twe_db_query("select products_id, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . twe_db_input($order_id) . "'");
      while ($order = twe_db_fetch_array($order_query)) {
        twe_db_query("update " . TABLE_PRODUCTS . " set products_quantity = products_quantity + " . $order['products_quantity'] . ", products_ordered = products_ordered - " . $order['products_quantity'] . " where products_id = '" . $order['products_id'] . "'");
      }
    }

    twe_db_query("delete from " . TABLE_ORDERS . " where orders_id = '" . twe_db_input($order_id) . "'");
    twe_db_query("delete from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . twe_db_input($order_id) . "'");
    twe_db_query("delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . twe_db_input($order_id) . "'");
    twe_db_query("delete from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . twe_db_input($order_id) . "'");
    twe_db_query("delete from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . twe_db_input($order_id) . "'");
  }

  function twe_reset_cache_block($cache_block) {
    global $cache_blocks;

    for ($i = 0, $n = sizeof($cache_blocks); $i < $n; $i++) {
      if ($cache_blocks[$i]['code'] == $cache_block) {
        if ($cache_blocks[$i]['multiple']) {
          if ($dir = @opendir(DIR_FS_CACHE)) {
            while ($cache_file = readdir($dir)) {
              $cached_file = $cache_blocks[$i]['file'];
              $languages = twe_get_languages();
              for ($j = 0, $k = sizeof($languages); $j < $k; $j++) {
                $cached_file_unlink = ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file);
                if (ereg('^' . $cached_file_unlink, $cache_file)) {
                  @unlink(DIR_FS_CACHE . $cache_file);
                }
              }
            }
            closedir($dir);
          }
        } else {
          $cached_file = $cache_blocks[$i]['file'];
          $languages = twe_get_languages();
          for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
            $cached_file = ereg_replace('-language', '-' . $languages[$i]['directory'], $cached_file);
            @unlink(DIR_FS_CACHE . $cached_file);
          }
        }
        break;
      }
    }
  }

  function twe_get_file_permissions($mode) {
    // determine type
    if ( ($mode & 0xC000) == 0xC000) { // unix domain socket
      $type = 's';
    } elseif ( ($mode & 0x4000) == 0x4000) { // directory
      $type = 'd';
    } elseif ( ($mode & 0xA000) == 0xA000) { // symbolic link
      $type = 'l';
    } elseif ( ($mode & 0x8000) == 0x8000) { // regular file
      $type = '-';
    } elseif ( ($mode & 0x6000) == 0x6000) { //bBlock special file
      $type = 'b';
    } elseif ( ($mode & 0x2000) == 0x2000) { // character special file
      $type = 'c';
    } elseif ( ($mode & 0x1000) == 0x1000) { // named pipe
      $type = 'p';
    } else { // unknown
      $type = '?';
    }

    // determine permissions
    $owner['read']    = ($mode & 00400) ? 'r' : '-';
    $owner['write']   = ($mode & 00200) ? 'w' : '-';
    $owner['execute'] = ($mode & 00100) ? 'x' : '-';
    $group['read']    = ($mode & 00040) ? 'r' : '-';
    $group['write']   = ($mode & 00020) ? 'w' : '-';
    $group['execute'] = ($mode & 00010) ? 'x' : '-';
    $world['read']    = ($mode & 00004) ? 'r' : '-';
    $world['write']   = ($mode & 00002) ? 'w' : '-';
    $world['execute'] = ($mode & 00001) ? 'x' : '-';

    // adjust for SUID, SGID and sticky bit
    if ($mode & 0x800 ) $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S';
    if ($mode & 0x400 ) $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S';
    if ($mode & 0x200 ) $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T';

    return $type .
           $owner['read'] . $owner['write'] . $owner['execute'] .
           $group['read'] . $group['write'] . $group['execute'] .
           $world['read'] . $world['write'] . $world['execute'];
  }

  function twe_array_slice($array, $offset, $length = '0') {
    if (function_exists('array_slice')) {
      return array_slice($array, $offset, $length);
    } else {
      $length = abs($length);
      if ($length == 0) {
        $high = sizeof($array);
      } else {
        $high = $offset+$length;
      }

      for ($i=$offset; $i<$high; $i++) {
        $new_array[$i-$offset] = $array[$i];
      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -