Example #1
0
 public function backup($cron = null)
 {
     function extract_numbers($string)
     {
         preg_match_all('/([\\d]+)/', $string, $match);
         return $match[0];
     }
     try {
         define('SAVE_FEED_LOCATION', Mage::getBaseDir() . '/export/scarab.csv');
         $handle = fopen(SAVE_FEED_LOCATION, 'w');
         $heading = array('item', 'link', 'title', 'image', 'category', 'price', 'available', 'brand');
         $feed_line = implode(",", $heading) . "\r\n";
         fwrite($handle, $feed_line);
         //Loop through and print each products info
         $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name')->addAttributeToSelect('is_in_stock')->addAttributeToFilter('visibility', 4)->addAttributeToFilter('status', 1)->addAttributeToSelect('is_saleable')->addAttributeToSelect('manufacturer', $joinType = false)->addAttributeToSelect('price');
         foreach ($collection as $product) {
             $id = $product->getId();
             $product = Mage::getModel('catalog/product')->load($id);
             $categ = "";
             # Get product's category collection object
             $catCollection = $product->getCategoryCollection();
             # export this collection to array so we could iterate on it's elements
             $categs = $catCollection->exportToArray();
             $categsToLinks = array();
             # Get categories names
             foreach ($categs as $cat) {
                 $categ .= $cat['path'] . "|";
             }
             $categ = substr($categ, 0, -1);
             $string = $categ;
             $numbers_array = extract_numbers($string);
             $array = array_unique($numbers_array);
             arsort($array);
             foreach ($array as $categoryId) {
                 $category = Mage::getModel('catalog/category')->load($categoryId);
                 if ($categoryId < 3) {
                     $categ = str_replace($categoryId . "/", "", $categ);
                     $categ = str_replace($categoryId, "", $categ);
                 } else {
                     $catname = $category->getName();
                     $categ = str_replace($categoryId, $catname, $categ);
                 }
             }
             // get price
             $finalprice = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), 2);
             $stock = "false";
             if ($product['is_in_stock'] == 1) {
                 $stock = "true";
             }
             $product_data = array();
             $product_data['item'] = $product->getId();
             $product_data['product_url'] = str_replace("/scarab.php/", "/", $product->getProductUrl());
             $product_data['name'] = $product->getName();
             $rconf = Mage::getStoreConfig('scarab_research/resize');
             $renabled = $rconf['resizeenabled'];
             $width = $rconf['resizewidth'];
             if ($renabled) {
                 $product_data['image'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . "timthumb.php?src=" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "catalog/product" . $product->getImage() . "&amp;w=" . $width . "&amp;zc=1";
             } else {
                 $product_data['image'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "catalog/product" . $product->getImage();
             }
             $product_data['kat'] = str_replace("/", " > ", $categ);
             $product_data['price'] = $finalprice;
             $product_data['status'] = $stock;
             $product_data['manufacturer'] = $product->getAttributeText('manufacturer');
             foreach ($product_data as $k => $val) {
                 $bad = array('"', "\r\n", "\n", "\r", "\t");
                 $good = array("", " ", " ", " ", "");
                 $product_data[$k] = '"' . str_replace($bad, $good, $val) . '"';
             }
             $feed_line = implode(",", $product_data) . "\r\n";
             fwrite($handle, $feed_line);
             fflush($handle);
             $product->clearInstance();
         }
         //---------------------- WRITE THE FEED
         fclose($handle);
     } catch (Exception $e) {
         Mage::logException($e);
     }
     return $this;
 }
Example #2
0
function expand_trigger_description_constants($description, $row)
{
    if ($row && isset($row['expression'])) {
        $numbers = extract_numbers(ereg_replace('(\\{[0-9]+\\})', 'function', $row['expression']));
        $description = $row["description"];
        for ($i = 0; $i < 9; $i++) {
            $description = str_replace('$' . ($i + 1), isset($numbers[$i]) ? $numbers[$i] : '', $description);
        }
    }
    return $description;
}
Example #3
0
$cards=$cards+$_POST[$i];
for ($l = 1; $l <= $_POST[$i]; $l++)
$cardid=$i . ',' . $cardid;
}
}
if($cards!=5 && $random==0){
print "<b>You must select exactly 5 cards!</b>";
}
elseif($hascards==1){
print "<b>You selected more cards than you have</b>";
}else{
if($random>0){
//todo random deck//
	
}else{
$numbers_array = extract_numbers($cardid);
$card1=$numbers_array[0];
$card2=$numbers_array[1];
$card3=$numbers_array[2];
$card4=$numbers_array[3];
$card5=$numbers_array[4];

$query = "INSERT INTO tt_matches (char1,gain,rules,special,card1,card2,card3,card4,card5,status) VALUES ('$charid','$mode','$rules','$special','$card1','$card2','$card3','$card4','$card5','1')" or die("Error in the consult.." . mysqli_error($db1));
$result = $db1->query($query) or die("Error " . mysqli_error($db1));
}
}

}
}

print "<br><a href='?d=lobby'>Home</a> -- <a href='?d=create'>Create Match</a> -- <a href='?d=active'>Active Matches</a> -- <a href='?d=finished'>Finished Matches</a>";