예제 #1
0
 function copyCategory($cat_id, $dest, $copy_subcats, $copy_relcats, $copy_listings, $copy_reviews, $reset_hits, $reset_rating, $increment = null)
 {
     global $mtconf;
     static $copied_cat_ids;
     $database =& JFactory::getDBO();
     # Get original cat's info
     $this->_db->setQuery("SELECT * FROM {$this->_tbl} WHERE cat_id = '" . $cat_id . "' LIMIT 1");
     $org_cat = $this->_db->loadObject();
     # Get $dest (New cat parent)'s lft & rgt
     if (is_null($increment)) {
         $this->_db->setQuery("SELECT lft, rgt FROM {$this->_tbl} WHERE cat_id = '" . $dest . "' LIMIT 1");
         $new_cat = $this->_db->loadObject();
         $inc = $new_cat->rgt - $org_cat->lft;
         $copied_cat_ids = array();
     } else {
         $inc = $increment;
     }
     # Change cat_parent
     $org_cat->cat_parent = $dest;
     # Copy cat
     $this->_db->setQuery('INSERT INTO ' . $this->_tbl . ' (cat_name, cat_desc, cat_parent, cat_links, cat_cats, cat_featured, cat_published, cat_created, cat_approved, cat_template, metakey, metadesc, ordering, lft, rgt) ' . ' VALUES(' . $this->_db->quote($org_cat->cat_name) . ', ' . $this->_db->quote($org_cat->cat_desc) . ', ' . $this->_db->quote($org_cat->cat_parent) . ', ' . ($copy_listings ? $org_cat->cat_links : '0') . ', ' . $this->_db->quote($org_cat->cat_cats) . ', ' . $this->_db->quote($org_cat->cat_featured) . ', ' . $this->_db->quote($org_cat->cat_published) . ', ' . $this->_db->quote($org_cat->cat_created) . ', ' . $this->_db->quote($org_cat->cat_approved) . ', ' . $this->_db->quote($org_cat->cat_template) . ', ' . $this->_db->quote($org_cat->metakey) . ', ' . $this->_db->quote($org_cat->metadesc) . ', ' . $this->_db->quote($org_cat->ordering) . ', ' . $this->_db->quote($org_cat->lft + $inc) . ', ' . $this->_db->quote($org_cat->rgt + $inc) . ')');
     $this->_db->query();
     $new_cat_parent = $this->_db->insertid();
     $copied_cat_ids[] = $new_cat_parent;
     # Copy image
     $file_s = $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_small_image') . $org_cat->cat_image;
     $file_o = $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_original_image') . $org_cat->cat_image;
     if ($org_cat->cat_image && is_writable($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_small_image')) && is_writable($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_original_image'))) {
         if (copy($file_s, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_small_image') . $new_cat_parent . "_" . substr($org_cat->cat_image, strpos($org_cat->cat_image, "_") + 1)) && copy($file_o, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_original_image') . $new_cat_parent . "_" . substr($org_cat->cat_image, strpos($org_cat->cat_image, "_") + 1))) {
             $this->_db->setQuery('UPDATE #__mt_cats SET cat_image = ' . $this->_db->quote($new_cat_parent . "_" . substr($org_cat->cat_image, strpos($org_cat->cat_image, "_") + 1)) . ' WHERE cat_id = ' . $this->_db->quote($new_cat_parent));
             $this->_db->query();
         }
     }
     # Copy Related Categories
     $this->_db->setQuery("SELECT rel_id FROM #__mt_relcats WHERE cat_id = '" . $cat_id . "'");
     $rel_ids = $this->_db->loadResultArray();
     if (count($rel_ids) > 0 && $copy_relcats == 1) {
         foreach ($rel_ids as $rel_id) {
             $this->_db->setQuery("INSERT INTO #__mt_relcats ( cat_id, rel_id ) VALUES ( '{$new_cat_parent}', '{$rel_id}' )");
             $this->_db->query();
         }
     }
     # Copy listings
     if ($copy_listings == 1) {
         $this->_db->setQuery("SELECT l.link_id FROM #__mt_links AS l, #__mt_cl AS cl WHERE l.link_id = cl.link_id AND cl.cat_id ='" . $cat_id . "' AND cl.main = '1'");
         $listings = $this->_db->loadResultArray();
         if (count($listings) > 0) {
             foreach ($listings as $listing) {
                 $l = new mtLinks($database);
                 $l->copyLink($listing, $new_cat_parent, $reset_hits, $reset_rating, $copy_reviews, 1);
             }
         }
         # Copy soft listing / CL mapping
         /*
         $this->_db->setQuery( "INSERT INTO #__mt_cl( link_id, cat_id, main ) SELECT link_id, '".$new_cat_parent."', '0' FROM #__mt_cl WHERE cat_id = '".$cat_id."' AND main = '0'" );
         $this->_db->query();
         echo $this->_db->getQuery();
         */
     }
     # Copy Sub categories
     $this->_db->setQuery("SELECT cat_id FROM {$this->_tbl} WHERE cat_parent = '" . $cat_id . "'");
     $subcats = $this->_db->loadResultArray();
     if (count($subcats) > 0 && $copy_subcats == 1) {
         foreach ($subcats as $subcat) {
             $this->copyCategory($subcat, $new_cat_parent, $copy_subcats, $copy_relcats, $copy_listings, $copy_reviews, $reset_hits, $reset_rating, $inc);
         }
     }
     return $copied_cat_ids;
 }
예제 #2
0
function copyLinks2($link_id, $option)
{
    global $mainframe;
    $database =& JFactory::getDBO();
    $new_cat_parent = JRequest::getInt('new_cat_parent', '', 'post');
    $copy_reviews = JRequest::getInt('copy_reviews', 0, 'post');
    $copy_secondary_cats = JRequest::getInt('copy_secondary_cats', 0, 'post');
    $reset_hits = JRequest::getInt('reset_hits', 1, 'post');
    $reset_rating = JRequest::getInt('reset_rating', 1, 'post');
    $row = new mtLinks($database);
    if (count($link_id) > 0) {
        foreach ($link_id as $id) {
            $row->copyLink($id, $new_cat_parent, $reset_hits, $reset_rating, $copy_reviews, $copy_secondary_cats);
            $row->cat_id = $new_cat_parent;
            $row->updateLinkCount(1);
        }
    }
    $mainframe->redirect("index2.php?option={$option}&task=listcats&cat_id={$new_cat_parent}");
}