/** * * @todo fix this function so that it always returns one data type - Chris (??) * @author unknown, Chris * @param unknown_type $type * @param unknown_type $days * @return multitype:unknown */ public function last_crawl($type = 'all', $days = 2) { $date = date('Y-m-d', strtotime("-{$days} days")); // from midnight so we can cache result $ret = array(); switch ($type) { // warning: returns array case 'all-deprecated': $types = array_to_lower(getMarketArray(TRUE)); foreach ($types as $t) { $res = $this->last_crawl($t); if (!empty($res)) { $ret[$t] = $res; } } break; // make this more performant, using IN() statement and RAM cache // make this more performant, using IN() statement and RAM cache case 'all': if ($this->last_crawl_cache_all_flag) { $ret = $this->last_crawl_cache; } else { if (!empty($this->store_id)) { $types = get_marketplaces_by_storeid_using_categories($this->store_id); $api_list = "'" . implode("','", $types) . "'"; } else { $api_list = "SELECT distinct name FROM marketplaces where is_active='1'"; } // SQL_CACHE and SQL_NO_CACHE in subquery are no longer permitted in MySQL 5.5.3 // http://stackoverflow.com/questions/24320137/mysql-syntax-error-after-upgrade $sql = "select SQL_CACHE x.* \n\t\t\t\t\t\tfrom (\n\t\t\t\t\t\t SELECT c.id, c.api_type, c.start_datetime, c.end_datetime\n\t\t\t\t\t\t\tFROM cron_log c\n\t\t\t\t\t\t\tWHERE c.api_type is not null\n\t\t\t\t\t\t\tAND\tc.start_datetime > '{$date}'\n\t\t\t\t\t\t\tAND c.api_type IN ({$api_list})\n\t\t\t\t\t\t\tAND c.tasks = ''\n\t\t\t\t\t\t\tORDER BY c.end_datetime desc, c.api_type\n\t\t\t\t\t\t) x\n\t\t\t\t\t\tGROUP BY x.api_type \n\t\t\t\t\t"; $cron_logs = $this->db->query($sql)->result_object(); foreach ($cron_logs as $t) { $ret[$t->api_type] = $t; } $this->last_crawl_cache = $ret; $this->last_crawl_cache_flag = TRUE; } break; // warning: returns object // warning: returns object default: if (isset($this->last_crawl_cache[$type])) { $ret = $this->last_crawl_cache[$type]; } else { $sql = "SELECT SQL_CACHE\n\t\t\t\t\t\t\t\tid, start_datetime, end_datetime, api_type\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t{$this->_table_cron_log}\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tapi_type=?\n\t\t\t\t\t\t AND tasks = ''\n\t\t\t\t\t\t AND start_datetime > '{$date}'\n\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\tdatetime desc\n\t\t\t\t\t\t\tLIMIT 1"; $variables = array($type); $ret = $this->db->query($sql, $variables)->row(); $this->last_crawl_cache[$type] = $ret; } } return $ret; }
private function _prep_whois_report() { $this->data->my = 'whois'; $this->data->report_chart = 'na'; // Separate marketplaces from retailers and // group marketplace_products by marketplace $this->data->marketplaces = array(); $this->data->retailers = array(); $markets = $this->report_info->whoisSwitch === 'marketplace' ? getMarketplaceArray($this->report_info->store_id) : getRetailerArray(false, $this->report_info->store_id); $markets = array_to_lower($markets); foreach ($markets as $market) { $crawl_info = $this->crawl_data_m->last_crawl($market); if ($crawl_info) { $from = $crawl_info->start_datetime; $to = $crawl_info->end_datetime; $marketplace_products = $this->merchant_products_m->getCountByMarketplace($this->report_info->store_id, $market, $from, $to); if (!empty($marketplace_products)) { $this->data->marketplace_products[] = $marketplace_products[0]; } } } if (isset($this->data->marketplace_products)) { for ($i = 0, $n = count($this->data->marketplace_products); $i < $n; $i++) { $marketplace = $this->data->marketplace_products[$i]['marketplace']; if ($this->data->marketplace_products[$i]['is_retailer'] === '1') { $merchant = $this->merchant_products_m->getMerchantDetailsByMarketplace($marketplace); if (isset($merchant[0]['id'])) { $this->data->marketplace_products[$i] = array_merge($this->data->marketplace_products[$i], $merchant[0]); $this->data->retailers[] = $this->data->marketplace_products[$i]; } } else { $this->data->marketplaces[] = $this->data->marketplace_products[$i]; } $this->data->marketplace_products[$marketplace] = $this->data->marketplace_products[$i]; unset($this->data->marketplace_products[$i]); } } // sort by keys $this->data->marketplace_keys = array(); if (!empty($this->data->marketplace_products)) { ksort($this->data->marketplace_products); $this->data->marketplace_keys = array_keys($this->data->marketplace_products); // graph data $this->data->gData = mvFormat::whoIsSellingMyProductDefault($this->data->marketplace_products); } $this->data->Data->retailers = $this->data->retailers; $this->data->Data->marketplaces = $this->data->marketplaces; }
function format_title($str) { error_debug("<b>format_title</b> starting with " . $str); $return = array(); $lower = array("a", "an", "and", "but", "for", "from", "if", "in", "nor", "of", "on", "or", "so", "the", "to", "via", "with"); $mixed = array("iPhone", "iPhones", "IPs", "SSNs", "TinyMCE", "URLs", "WordPress"); $upper = array("ADA", "ASAP", "BIF", "CCT", "CSS", "DB", "EBO", "FSS", "FTP", "HTML", "IP", "NHP", "NVN", "OMG", "ONYC", "OS", "PC", "PHP", "PLC", "RSS", "SF", "SFS", "SQL", "SSN", "URL", "WTF", "XML"); $words = explode(" ", ucwords(strtolower(trim($str)))); $counter = 1; $max = count($words); foreach ($words as $word) { if (in_array(strtolower($word), $lower) && $counter != 1 && $counter != $max) { $return[] = strtolower($word); } elseif (in_array(strToUpper($word), $upper)) { $return[] = strToUpper($word); } elseif (!empty($word)) { $index = array_search(strtolower($word), array_to_lower($mixed)); if ($index !== false) { //could return 0, which would be valid $return[] = $mixed[$index]; } else { $return[] = $word; } } $counter++; } return implode(" ", $return); }
/** * Check if a user has a specific addon * * @param type $addon * @return type */ function check_addon($addon) { $addons = array_lookup(array_to_lower($this->subscriber_addons)); return isset($addons[strtolower($addon)]); }