Exemple #1
0
 /**
  * Set a DB path
  *
  * @param string $type
  * @param int $item_id
  * @param string $path
  * @param bool $bool
  * @param bool $show_error
  * @return bool/string
  */
 public function setdbPath($type, $item_id, $path, $bool = true, $show_error = true)
 {
     if (in_array($type, array_merge($this->_dynamic_sections, $this->_static_sections))) {
         $custom = 1;
         // if path is empty or already taken generate one
         if (empty($path) || $GLOBALS['db']->count('CubeCart_seo_urls', 'id', "`path` = '{$path}' AND `type` = '{$type}' AND `item_id` <> {$item_id}") > 0) {
             // send warning if in use
             if (!empty($path)) {
                 if ($show_error) {
                     $GLOBALS['gui']->setError($GLOBALS['language']->settings['seo_path_taken'], true);
                 }
             }
             // try to generate
             $path = $this->generatePath($item_id, $type);
             $custom = 0;
         }
         $path = SEO::_safeUrl($path);
         if (empty($path)) {
             return $bool ? false : '';
         }
         if (($existing = $GLOBALS['db']->select('CubeCart_seo_urls', 'id', array('type' => $type, 'item_id' => $item_id))) !== false) {
             $GLOBALS['db']->update('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path, 'custom' => $custom), array('id' => $existing[0]['id']));
         } else {
             //Check for dup path
             if (!$GLOBALS['db']->select('CubeCart_seo_urls', false, array('path' => $path))) {
                 $GLOBALS['db']->insert('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path, 'custom' => $custom));
             } else {
                 // Force unique path is it's already taken
                 $unique_id = substr($type, 0, 1) . $item_id;
                 $GLOBALS['db']->insert('CubeCart_seo_urls', array('type' => $type, 'item_id' => $item_id, 'path' => $path . '-' . $unique_id, 'custom' => $custom));
                 $GLOBALS['gui']->setError($GLOBALS['language']->settings['seo_path_taken'], true);
             }
         }
         return $bool ? true : $path;
     } else {
         trigger_error('Invalid SEO path type ' . $type . '.', E_USER_NOTICE);
         return false;
     }
 }