protected function trim_explode($delimiter, $string, $trim = 'trim', $limit = NULL) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return (array) self::parameters(['delimiters' => DT::TYPE_ARRAY, 'string' => DT::STRING, 'trim' => DT::STRING, 'limit' => DT::MIXED])->call(__FUNCTION__)->with($delimiter, $string, $trim, $limit)->returning(DT::TYPE_ARRAY); } else { return (array) trim_explode($delimiter, $string, $trim, $limit); } }
function queryItem($search_attributes_r, $s_item_type) { $hometheaterinfo_r = fetch_hometheaterinfo_r($search_attributes_r['hmi_id']); if ($hometheaterinfo_r !== FALSE) { // Format slash correctly. $hometheaterinfo_r['title'] = str_replace("/ ", " / ", $hometheaterinfo_r['title']); // Lets get anything in brackets out into DVD_EXTRAS field. $indexStart = strpos($hometheaterinfo_r['title'], "("); if ($indexStart !== FALSE && $indexStart > 0) { // In case bracket is first character!!! $indexEnd = strpos($hometheaterinfo_r['title'], ")", $indexStart); if ($indexEnd !== FALSE) { $this->addItemAttribute('dvd_extras', substr($hometheaterinfo_r['title'], $indexStart + 1, $indexEnd - ($indexStart + 1))); $this->addItemAttribute('title', substr($hometheaterinfo_r['title'], 0, $indexStart)); } else { $this->addItemAttribute('title', $hometheaterinfo_r['title']); } } else { $this->addItemAttribute('title', $hometheaterinfo_r['title']); } if (strlen($hometheaterinfo_r['studio']) > 0) { $this->addItemAttribute('studio', $hometheaterinfo_r['studio']); } if (strlen($hometheaterinfo_r['rel_status']) > 0) { $this->addItemAttribute('rel_status', $hometheaterinfo_r['rel_status']); } $this->addItemAttribute('dvd_region', '1'); // This is only option! // All Region 1 (US) items should be NTSC! $this->addItemAttribute('vid_format', 'NTSC'); //------------------ // AUDIO_LANG Processing. //------------------ //1.0, 2.0, 4.0, 5.0, 5.1, DTS, 6.1 ES, 6.1 EX, SUR, PCM,DUB, SUB, SIL, VAR $this->addItemAttribute('audio_lang', $hometheaterinfo_r['audio_lang']); //------------------ // DVD_FORMAT Processing. //------------------ if (strlen($hometheaterinfo_r['dvd_format']) > 0) { $dvd_format_r = trim_explode(',', $hometheaterinfo_r['dvd_format']); while (list(, $dvd_format) = each($dvd_format_r)) { switch ($dvd_format) { case 'LBX': $this->addItemAttribute('dvd_format', 'LBX'); break; case '4:3': $this->addItemAttribute('dvd_format', '4:3'); break; case '16:9': $this->addItemAttribute('dvd_format', '16:9'); $this->addItemAttribute('anamorphic', 'Y'); break; case 'P&S': $this->addItemAttribute('dvd_format', 'P&S'); break; //case 'VAR': // break; //case 'VAR': // break; default: // serves as UNK as well. break; } // switch$record['dvd_format'] } } //------------------ // RATIO Processing. //------------------ if (strlen($hometheaterinfo_r['ratio']) > 0) { if ($hometheaterinfo_r['ratio'] != "VAR") { $indexOfColon = strpos($hometheaterinfo_r['ratio'], ":"); // Remove everything after the colon. if ($indexOfColon !== FALSE) { $this->addItemAttribute('ratio', substr($hometheaterinfo_r['ratio'], 0, $indexOfColon)); } } } //------------------ // PRICE Processing. //------------------ if (strlen($hometheaterinfo_r['listprice']) > 0) { if (substr($hometheaterinfo_r['listprice'], 0, 1) == "\$") { $this->addItemAttribute('listprice', substr($hometheaterinfo_r['listprice'], 1)); } } //------------------ // YEAR Processing. //------------------ if (is_numeric($hometheaterinfo_r['year'])) { $this->addItemAttribute('year', $hometheaterinfo_r['year']); } //------------------ // GENRE Processing. //------------------ if (strlen($hometheaterinfo_r['genre']) > 0) { if ($hometheaterinfo_r['genre'] != "VAR") { // Remove spaces and explode on / $genre_r = explode("/", str_replace(" ", "", $hometheaterinfo_r['genre'])); $this->addItemAttribute('genre', $genre_r); } } //------------------ // DATE Processing. // Note: Ignores any hours/minutes/seconds //------------------ $date_format_cfg = $this->getConfigValue('datetime_mask'); // We will change the date format to use later on! if (strlen($hometheaterinfo_r['dvd_rel_dt']) > 0) { //YYYY-MM-DD list($year, $month, $day) = sscanf($hometheaterinfo_r['dvd_rel_dt'], "%d-%d-%d"); $this->addItemAttribute('dvd_rel_dt', get_localised_timestamp($date_format_cfg, mktime(0, 0, 0, $month, $day, $year))); } // We will change the date format to use later on! if (strlen($hometheaterinfo_r['orig_rel_dt']) > 0) { //YYYY-MM-DD list($year, $month, $day) = sscanf($hometheaterinfo_r['orig_rel_dt'], "%d-%d-%d"); $this->addItemAttribute('orig_rel_dt', get_localised_timestamp($date_format_cfg, mktime(0, 0, 0, $month, $day, $year))); } if (strlen($hometheaterinfo_r['age_rating']) > 0) { $this->addItemAttribute('age_rating', $hometheaterinfo_r['age_rating']); } if (strlen($hometheaterinfo_r['upc_id']) > 0) { $this->addItemAttribute('upc_id', $hometheaterinfo_r['upc_id']); } return TRUE; } else { //if($hometheaterinfo_r!==FALSE) return FALSE; } }
function parse_dvdempire_video_data($search_attributes_r, $s_item_type, $buffer) { //<title>DVD Empire - Item - Rambo III: Ultimate Edition / DVD-Video</title> if (preg_match("!<title>DVD Empire - Item - (.*)/[\\s]*DVD-Video<\\/title>!m", $buffer, $regs)) { $this->addItemAttribute('title', str_replace("\"", "", html_entity_decode(strip_tags($regs[1]), ENT_COMPAT, get_opendb_config_var('themes', 'charset') == 'utf-8' ? 'UTF-8' : 'ISO-8859-1'))); } //<title>Buy Just Friends DVD @ DVD Empire </title> if (preg_match("!<title>Buy (.*) DVD @ DVD Empire <\\/title>!", $buffer, $matches)) { $this->addItemAttribute('title', $matches[1]); } if (preg_match("/Region ([0-9]+)/i", $buffer, $regs)) { $this->addItemAttribute('dvd_region', $regs[1]); } else { $this->addItemAttribute('dvd_region', '1'); // otherwise assume US region } $product_info = get_page_block('Product Information', $buffer); $this->addItemAttribute('dvd_extras', preg_replace(array("'[\n|\r]+'", "'[\t ]+'"), array("\n", " "), html_entity_decode(strip_tags(str_replace("<br>", "\n", parse_page_block('Features', $product_info))), ENT_COMPAT, get_opendb_config_var('themes', 'charset') == 'utf-8' ? 'UTF-8' : 'ISO-8859-1'))); $this->addItemAttribute('vid_format', 'NTSC'); // An American site, so most likely NTSC $video = parse_page_block('Video', $product_info); if (strlen($video) > 0) { if (strpos($video, 'Anamorphic') !== FALSE) { $this->addItemAttribute('anamorphic', 'Y'); } $ratio_list_r = array('1.33', '1.66', '1.78', '1.85', '2.35', '2.78'); while (list(, $ratio) = @each($ratio_list_r)) { if (preg_match('/' . $ratio . ':1/', $video)) { $this->addItemAttribute('ratio', $ratio); } } } $audio = parse_page_block('Audio', $product_info); if (strlen($audio) > 0) { $audio_r = explode_lines(strip_tags(preg_replace("/<br>/i", "\n", $audio))); if (is_not_empty_array($audio_r)) { //ENGLISH: Dolby Digital 5.1 [CC] for ($i = 0; $i < count($audio_r); $i++) { if (preg_match("/([A-Z]+): ([^\$]+)\$/Ui", $audio_r[$i], $matches)) { if (ends_with($matches[2], "[CC]")) { $audio_format = trim(substr($matches[2], 0, -5)); } else { $audio_format = trim($matches[2]); } $this->addItemAttribute('audiotrk', $matches[0]); $this->addItemAttribute('audio_lang', $matches[1]); $this->addItemAttribute('audio_format', $audio_format); } } } } $subtitles = parse_page_block('Subtitles', $product_info); if (strpos($subtitles, 'None') === FALSE) { $this->addItemAttribute('subtitles', trim_explode(",", $subtitles)); } if (preg_match("/<b>Packaging:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('dvd_packge', $regs[1]); } if (preg_match("/<b>Disc:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('dvd_disc', $regs[1]); } if (preg_match("/<b>Number of Discs:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $no_discs = trim($regs[1]); // fixed if (strlen($no_discs) > 0) { $this->addItemAttribute('no_discs', $no_discs); } } if (preg_match("/<b>Item Code:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('item_code', $regs[1]); } if (preg_match("/<b>Chapters:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('dvd_chptrs', $regs[1]); } if (preg_match("/<b>UPC Code:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('upc_id', $regs[1]); } if (preg_match("/<b>Studio:<\\/b> <a href=\\'.*?\\'>(.*?)<\\/a><br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('studio', $regs[1]); } if (preg_match("/<b>Production Year:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('year', $regs[1]); } if (preg_match("/<b>Release Date:<\\/b> (.*?)<br \\/>/i", $product_info, $regs)) { $this->addItemAttribute('rel_date', $regs[1]); } if (preg_match("/<b>DVD Year:<\\/b>(.*?)<br>/i", $product_info, $regs)) { $this->addItemAttribute('dvd_rel_dt', $regs[1]); } if (preg_match("/<b>Length:<\\/b>[\\s]([0-9]*)/i", $product_info, $regs)) { $this->addItemAttribute('run_time', $regs[1]); } if (preg_match("/<b>Rating:<\\/b>(.*?)<br \\/>/i", $product_info, $regs)) { $age_rating = trim($regs[1]); if (strlen($age_rating) > 0) { $this->addItemAttribute('age_rating', $age_rating); } } //<b>Cast & Crew</b> $film_info = get_page_block('Cast & Crew', $buffer); if (strlen($film_info) > 0) { $this->addItemAttribute('actors', parse_film_info_block('Actors', $film_info)); $this->addItemAttribute('director', parse_film_info_block('Directors', $film_info)); $this->addItemAttribute('producers', parse_film_info_block('Producers', $film_info)); $this->addItemAttribute('writers', parse_film_info_block('Writers', $film_info)); $this->addItemAttribute('creators', parse_film_info_block('Creators', $film_info)); } $index = strpos($buffer, "<b>Reviews</b>"); if ($index !== FALSE) { $index += strlen("<b>Reviews</b>"); $reviews = get_page_block('Reviews', substr($buffer, $index)); if (strlen($reviews) > 0) { // <b>Overall Rating:</b> <img src="/Graphics/Running/v4_rating0.gif" border='0' vspace='0' hspace='1'><img src="/Graphics/Running/v4_rating0.gif" border='0' vspace='0' hspace='1'><img src="/Graphics/Running/v4_rating0.gif" border='0' vspace='0' hspace='1'><img src="/Graphics/Running/v4_rating0.gif" border='0' vspace='0' hspace='1'><img src="/Graphics/Running/v4_rating1.gif" border='0' vspace='0' hspace='1'><span class='fontsmall'> <b>4.45</b> out of <b>5</b>, including <b>41</b> reviews<br> } } // ---------------------------- // Now the Cover images // ---------------------------- //http://images2.dvdempire.com/gen/movies/3073.jpg if (preg_match('!<img src=[\'|"](http://\\w*?\\.dvdempire\\.org/products/[0-9]*/' . $search_attributes_r['dvdempr_id'] . '\\.jpg)[\'|"]!', $buffer, $regs)) { $this->addItemAttribute('thumbimg', $regs[1]); } // Now we need to get the cover images $buffer = $this->fetchURI('http://www.dvdempire.com/Exec/v4_item.asp?item_id=' . $search_attributes_r['dvdempr_id'] . '&tab=5'); if (strlen($buffer) > 0) { //<img src="http://images2.dvdempire.com/gen/movies/3073h.jpg" valign="top" align="middle" border="0" hspace="0" vspace="0"> if (preg_match('!<img src=[\'|"](http://\\w*?\\.dvdempire\\.org/products/[0-9]*/' . $search_attributes_r['dvdempr_id'] . 'h\\.jpg)[\'|"]!', $buffer, $regs)) { $this->addItemAttribute('imageurl', $regs[1]); $this->addItemAttribute('imageurlf', $regs[1]); } } $buffer = $this->fetchURI('http://www.dvdempire.com/Exec/v4_item.asp?item_id=' . $search_attributes_r['dvdempr_id'] . '&tab=5&back=1'); if (strlen($buffer) > 0) { if (preg_match('!<img src=[\'|"](http://\\w*?\\.dvdempire\\.org/products/[0-9]*/' . $search_attributes_r['dvdempr_id'] . 'bh\\.jpg)[\'|"]!', $buffer, $regs)) { $this->addItemAttribute('imageurlb', $regs[1]); } } }
} } } else { if ($HTTP_VARS['op'] == 'update') { if (is_not_empty_array($HTTP_VARS['content_type'])) { for ($i = 0; $i < count($HTTP_VARS['content_type']); $i++) { if ($HTTP_VARS['exists_ind'][$i] == 'Y') { if (is_exists_file_type($HTTP_VARS['content_type'][$i])) { if (!update_s_file_type($HTTP_VARS['content_type'][$i], $HTTP_VARS['content_group'][$i], $HTTP_VARS['extension'][$i], trim_explode(',', $HTTP_VARS['alt_extensions'][$i]), $HTTP_VARS['description'][$i], $HTTP_VARS['image'][$i], $HTTP_VARS['thumbnail_support_ind'][$i])) { $errors[] = array('error' => 'File Type "' . $HTTP_VARS['content_type'][$i] . '" not updated.', 'detail' => db_error()); } } } else { if (strlen($HTTP_VARS['content_type'][$i]) > 0) { if (!is_exists_file_type($HTTP_VARS['content_type'][$i])) { if (!insert_s_file_type($HTTP_VARS['content_type'][$i], $HTTP_VARS['content_group'][$i], $HTTP_VARS['extension'][$i], trim_explode(',', $HTTP_VARS['alt_extensions'][$i]), $HTTP_VARS['description'][$i], $HTTP_VARS['image'][$i], $HTTP_VARS['thumbnail_support_ind'][$i])) { $errors[] = array('error' => 'File Type "' . $HTTP_VARS['content_type'][$i] . '" not inserted.', 'detail' => db_error()); } } } } } } $HTTP_VARS['op'] = ''; } } if (strlen($HTTP_VARS['op']) == 0) { if (is_not_empty_array($errors)) { echo format_error_block($errors); } echo "\n<form name=\"s_file_type\" action=\"{$PHP_SELF}\" method=\"POST\">";
function execute($query, $isMultiple = false) { if (!$this->isConnected) { $this->connect(); } $this->queries[] = $query; if (DEBUG_SQL) { //$sqlLogger = new logger(LOGS . "mysql-calls", false); //$sqlLogger->log($this->queries[count($this->queries)-1]); } if ($isMultiple) { if ($this->type == 'mysql') { $qs = trim_explode(';', $query); // need to figure out a good way to check multiple statements... with possibility to include ; mysql_query("START TRANSACTION", $this->connection); mysql_query("BEGIN", $this->connection); foreach ($qs as $q) { if (!empty($q) && !($resource = mysql_query($q, $this->connection))) { $this->error("error=>Unable to complete SQL call.", "function=>" . __FUNCTION__, "line=>" . __LINE__, "connection=>" . $this->connection, "resource=>" . $resource, "query=>" . $q); break; } } if (!$resource) { mysql_query("ROLLBACK", $this->connection); } else { mysql_query("COMMIT", $this->connection); } } } else { switch ($this->type) { case "mysql": default: $resource = mysql_query($query, $this->connection); } if (substr(strtolower($query), 0, 11) == strtolower('INSERT INTO')) { $this->getInsertId(); } } return $resource; }
function handleImport($include_header_row, $s_item_type) { // skip the header row if appropriate. if ($this->importPlugin->is_header_row() !== TRUE || $include_header_row !== TRUE) { $this->importPlugin->read_header($this->fileHandler, $this->_error); } while (!$this->fileHandler->isEof() && $this->itemImportHandler->isError() != TRUE && ($read_row_r = $this->importPlugin->read_row($this->fileHandler, $this->_error)) !== FALSE) { // ensure we have a array that is not empty, or empty except for first element, which is empty. // Either no s_item_type restriction applies, or the s_item_type column is the same as // the current s_item_type we are processing. if (is_not_empty_array($read_row_r) && (count($read_row_r) > 1 || strlen($read_row_r[0]) > 0) && (!is_numeric($this->field_column_r['s_item_type']) || strlen($read_row_r[$this->field_column_r['s_item_type']]) == 0 || strcasecmp($read_row_r[$this->field_column_r['s_item_type']], $s_item_type) === 0)) { $this->itemImportHandler->startItem($s_item_type); // Now do the title. $title_attr_type_r = fetch_sfieldtype_item_attribute_type_r($s_item_type, 'TITLE'); $title = $this->get_field_value(get_field_name($title_attr_type_r['s_attribute_type'], $title_attr_type_r['order_no']), NULL, $read_row_r); $this->itemImportHandler->setTitle($title); $results = fetch_item_attribute_type_rs($s_item_type, NULL, FALSE); if ($results) { while ($item_attribute_type_r = db_fetch_assoc($results)) { // these field types are references to item_instance values, and not true attribute types. if ($item_attribute_type_r['s_field_type'] != 'TITLE' && $item_attribute_type_r['s_field_type'] != 'STATUSTYPE' && $item_attribute_type_r['s_field_type'] != 'STATUSCMNT' && $item_attribute_type_r['s_field_type'] != 'DURATION' && $item_attribute_type_r['s_field_type'] != 'ITEM_ID') { $value = $this->get_field_value(get_field_name($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no']), $item_attribute_type_r['s_attribute_type'], $read_row_r); if (strlen($value) > 0) { if ($item_attribute_type_r['lookup_attribute_ind'] == 'Y' || $item_attribute_type_r['multi_attribute_ind'] == 'Y') { // row based are comma delimited. $values_r = trim_explode(',', $value); } else { $values_r = $value; } $this->itemImportHandler->addAttribute($item_attribute_type_r['s_attribute_type'], $item_attribute_type_r['order_no'], $values_r); } //if(strlen($value)>0) } } db_free_result($results); } //if($results) $status_attr_type_r = fetch_sfieldtype_item_attribute_type_r($s_item_type, 'STATUSTYPE'); $s_status_type = $this->get_field_value(get_field_name($status_attr_type_r['s_attribute_type'], $status_attr_type_r['order_no']), $status_attr_type_r['s_attribute_type'], $read_row_r); $status_cmnt_attr_type_r = fetch_sfieldtype_item_attribute_type_r($s_item_type, 'STATUSCMNT'); $status_comment = $this->get_field_value(get_field_name($status_cmnt_attr_type_r['s_attribute_type'], $status_cmnt_attr_type_r['order_no']), $status_cmnt_attr_type_r['s_attribute_type'], $read_row_r); $duration_attr_type_r = fetch_sfieldtype_item_attribute_type_r($s_item_type, 'DURATION'); $borrow_duration = $this->get_field_value(get_field_name($duration_attr_type_r['s_attribute_type'], $duration_attr_type_r['order_no']), $duration_attr_type_r['s_attribute_type'], $read_row_r); $this->itemImportHandler->startItemInstance(); $this->itemImportHandler->setInstanceStatusType($s_status_type); $this->itemImportHandler->setInstanceStatusComment($status_comment); $this->itemImportHandler->setInstanceBorrowDuration($borrow_duration); $this->itemImportHandler->endItemInstance(); $this->itemImportHandler->endItem(); } } if ($this->itemImportHandler->isError()) { // copy the first error in $itemImportHandlerErrors =& $this->itemImportHandler->getRawErrors(); if (is_array($itemImportHandlerErrors)) { $this->_error = $itemImportHandlerErrors[0]['error']; } return FALSE; } else { return TRUE; } }