/** * constructor * This should be called */ public function __construct($id = null, $cached = true) { $sid = session_id(); if (is_null($id)) { $this->reset(); if ($cached) { $data = serialize($this->_state); $sql = 'INSERT INTO `tmp_browse` (`sid`, `data`) ' . 'VALUES(?, ?)'; Dba::write($sql, array($sid, $data)); $this->id = Dba::insert_id(); } else { $this->id = 'nocache'; } return true; } $this->id = $id; $sql = 'SELECT `data` FROM `tmp_browse` ' . 'WHERE `id` = ? AND `sid` = ?'; $db_results = Dba::read($sql, array($id, $sid)); if ($results = Dba::fetch_assoc($db_results)) { $this->_state = unserialize($results['data']); return true; } Error::add('browse', T_('Browse not found or expired, try reloading the page')); return false; }
/** * create * This takes a key'd array of data as input and inserts a new license entry, it returns the auto_inc id * @param array $data * @return int */ public static function create(array $data) { $sql = "INSERT INTO `license` (`name`,`description`,`external_link`) " . "VALUES (? , ?, ?)"; Dba::write($sql, array($data['name'], $data['description'], $data['external_link'])); $insert_id = Dba::insert_id(); return $insert_id; }
public static function create($name, $description = '') { if (!empty($name)) { $sql = "INSERT INTO `broadcast` (`user`, `name`, `description`, `is_private`) VALUES (?, ?, ?, '1')"; $params = array($GLOBALS['user']->id, $name, $description); Dba::write($sql, $params); return Dba::insert_id(); } return 0; }
/** * login */ public static function login($input) { self::check_auth('dmap.loginresponse'); // Create a new daap session $sql = "INSERT INTO `daap_session` (`creationdate`) VALUES (?)"; Dba::write($sql, array(time())); $sid = Dba::insert_id(); $o = self::tlv('dmap.status', 200); $o .= self::tlv('dmap.sessionid', $sid); $o = self::tlv('dmap.loginresponse', $o); self::apiOutput($o); }
/** * save * * Save this search to the database for use as a smart playlist */ public function save() { // Make sure we have a unique name if (!$this->name) { $this->name = $GLOBALS['user']->username . ' - ' . date('Y-m-d H:i:s', time()); } $sql = "SELECT `id` FROM `search` WHERE `name` = ?"; $db_results = Dba::read($sql, array($this->name)); if (Dba::num_rows($db_results)) { $this->name .= uniqid('', true); } $sql = "INSERT INTO `search` (`name`, `type`, `user`, `rules`, `logic_operator`, `random`, `limit`) VALUES (?, ?, ?, ?, ?, ?, ?)"; Dba::write($sql, array($this->name, $this->type, $GLOBALS['user']->id, serialize($this->rules), $this->logic_operator, $this->random, $this->limit)); $insert_id = Dba::insert_id(); $this->id = $insert_id; return $insert_id; }
/** * check * * Checks for an existing tv show; if none exists, insert one. */ public static function check($name, $year, $tvshow_summary, $readonly = false) { // null because we don't have any unique id like mbid for now if (isset(self::$_mapcache[$name]['null'])) { return self::$_mapcache[$name]['null']; } $id = 0; $exists = false; $trimmed = Catalog::trim_prefix(trim($name)); $name = $trimmed['string']; $prefix = $trimmed['prefix']; if (!$exists) { $sql = 'SELECT `id` FROM `tvshow` WHERE `name` LIKE ? AND `year` = ?'; $db_results = Dba::read($sql, array($name, $year)); $id_array = array(); while ($row = Dba::fetch_assoc($db_results)) { $key = 'null'; $id_array[$key] = $row['id']; } if (count($id_array)) { $id = array_shift($id_array); $exists = true; } } if ($exists) { self::$_mapcache[$name]['null'] = $id; return $id; } if ($readonly) { return null; } $sql = 'INSERT INTO `tvshow` (`name`, `prefix`, `year`, `summary`) VALUES(?, ?, ?, ?)'; $db_results = Dba::write($sql, array($name, $prefix, $year, $tvshow_summary)); if (!$db_results) { return null; } $id = Dba::insert_id(); self::$_mapcache[$name]['null'] = $id; return $id; }
protected function insertRecord($properties) { $sql = 'INSERT INTO ' . $this->getTableName() . ' (' . implode(',', array_keys($properties)) . ')' . ' VALUES(' . implode(',', array_fill(0, count($properties), '?')) . ')'; //print_r($properties); \Dba::write($sql, array_values($this->resolveObjects($properties))); return \Dba::insert_id(); }
/** * insert * * This inserts the song preview described by the passed array */ public static function insert($results) { $sql = 'INSERT INTO `song_preview` (`file`, `album_mbid`, `artist`, `artist_mbid`, `title`, `disk`, `track`, `mbid`, `session`) ' . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'; $db_results = Dba::write($sql, array($results['file'], $results['album_mbid'], $results['artist'], $results['artist_mbid'], $results['title'], $results['disk'], $results['track'], $results['mbid'], $results['session'])); if (!$db_results) { debug_event('song_preview', 'Unable to insert ' . $results[''], 2); return false; } return Dba::insert_id(); }
public static function create_share($object_type, $object_id, $allow_stream = true, $allow_download = true, $expire = 0, $secret = '', $max_counter = 0, $description = '') { $object_type = self::format_type($object_type); if (empty($object_type)) { return ''; } if (!$allow_stream && !$allow_download) { return ''; } $sql = "INSERT INTO `share` (`user`, `object_type`, `object_id`, `creation_date`, `allow_stream`, `allow_download`, `expire_days`, `secret`, `counter`, `max_counter`, `description`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $params = array($GLOBALS['user']->id, $object_type, $object_id, time(), $allow_stream ?: 0, $allow_download ?: 0, $expire, $secret, 0, $max_counter, $description); Dba::write($sql, $params); $id = Dba::insert_id(); $url = self::get_url($id, $secret); // Get a shortener url if any available foreach (Plugin::get_plugins('shortener') as $plugin_name) { try { $plugin = new Plugin($plugin_name); if ($plugin->load($GLOBALS['user'])) { $short_url = $plugin->_plugin->shortener($url); if (!empty($short_url)) { $url = $short_url; break; } } } catch (Exception $e) { debug_event('share', 'Share plugin error: ' . $e->getMessage(), '1'); } } $sql = "UPDATE `share` SET `public_url` = ? WHERE `id` = ?"; Dba::write($sql, array($url, $id)); return $id; }
/** * insert * This inserts a new preference into the preference table * it does NOT sync up the users, that should be done independently */ public static function insert($name, $description, $default, $level, $type, $catagory) { $sql = "INSERT INTO `preference` (`name`,`description`,`value`,`level`,`type`,`catagory`) " . "VALUES (?, ?, ?, ?, ?, ?)"; $db_results = Dba::write($sql, array($name, $description, $default, intval($level), $type, $catagory)); if (!$db_results) { return false; } $id = Dba::insert_id(); $params = array($id, $default); $sql = "INSERT INTO `user_preference` VALUES (-1,?,?)"; $db_results = Dba::write($sql, $params); if (!$db_results) { return false; } if ($catagory !== "system") { $sql = "INSERT INTO `user_preference` SELECT `user`.`id`, ?, ? FROM `user`"; $db_results = Dba::write($sql, $params); if (!$db_results) { return false; } } return true; }
/** * create * This function creates an empty playlist, gives it a name and type * Assumes $GLOBALS['user']->id as the user */ public static function create($name, $type) { $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) VALUES (?, ?, ?, ?)"; Dba::write($sql, array($name, $GLOBALS['user']->id, $type, time())); $insert_id = Dba::insert_id(); return $insert_id; }
/** * check * * Checks for an existing artist; if none exists, insert one. */ public static function check($name, $mbid = null, $readonly = false) { $trimmed = Catalog::trim_prefix(trim($name)); $name = $trimmed['string']; $prefix = $trimmed['prefix']; if ($mbid == '') { $mbid = null; } if (!$name) { $name = T_('Unknown (Orphaned)'); $prefix = null; } if (isset(self::$_mapcache[$name][$mbid])) { return self::$_mapcache[$name][$mbid]; } $id = 0; $exists = false; if ($mbid) { $sql = 'SELECT `id` FROM `artist` WHERE `mbid` = ?'; $db_results = Dba::read($sql, array($mbid)); if ($row = Dba::fetch_assoc($db_results)) { $id = $row['id']; $exists = true; } } if (!$exists) { $sql = 'SELECT `id`, `mbid` FROM `artist` WHERE `name` LIKE ?'; $db_results = Dba::read($sql, array($name)); $id_array = array(); while ($row = Dba::fetch_assoc($db_results)) { $key = $row['mbid'] ?: 'null'; $id_array[$key] = $row['id']; } if (count($id_array)) { if ($mbid) { if (isset($id_array['null']) && !$readonly) { $sql = 'UPDATE `artist` SET `mbid` = ? WHERE `id` = ?'; Dba::write($sql, array($mbid, $id_array['null'])); } if (isset($id_array['null'])) { $id = $id_array['null']; $exists = true; } } else { // Pick one at random $id = array_shift($id_array); $exists = true; } } } if ($exists) { self::$_mapcache[$name][$mbid] = $id; return $id; } if ($readonly) { return null; } $sql = 'INSERT INTO `artist` (`name`, `prefix`, `mbid`) ' . 'VALUES(?, ?, ?)'; $db_results = Dba::write($sql, array($name, $prefix, $mbid)); if (!$db_results) { return null; } $id = Dba::insert_id(); self::$_mapcache[$name][$mbid] = $id; return $id; }
/** * check * * Searches for an album; if none is found, insert a new one. */ public static function check($name, $year = 0, $disk = 0, $mbid = null, $readonly = false) { if ($mbid == '') { $mbid = null; } $trimmed = Catalog::trim_prefix(trim($name)); $name = $trimmed['string']; $prefix = $trimmed['prefix']; // Not even sure if these can be negative, but better safe than llama. $year = abs(intval($year)); $disk = abs(intval($disk)); if (!$name) { $name = T_('Unknown (Orphaned)'); $year = 0; $disk = 0; } if (isset(self::$_mapcache[$name][$year][$disk][$mbid])) { return self::$_mapcache[$name][$year][$disk][$mbid]; } $sql = 'SELECT `id` FROM `album` WHERE `name` = ? AND `disk` = ? AND `year` = ? AND `mbid` '; $params = array($name, $disk, $year); if ($mbid) { $sql .= '= ? '; $params[] = $mbid; } else { $sql .= 'IS NULL '; } $sql .= 'AND `prefix` '; if ($prefix) { $sql .= '= ?'; $params[] = $prefix; } else { $sql .= 'IS NULL'; } $db_results = Dba::read($sql, $params); if ($row = Dba::fetch_assoc($db_results)) { $id = $row['id']; self::$_mapcache[$name][$year][$disk][$mbid] = $id; return $id; } if ($readonly) { return null; } $sql = 'INSERT INTO `album` (`name`, `prefix`, `year`, `disk`, `mbid`) VALUES (?, ?, ?, ?, ?)'; $db_results = Dba::write($sql, array($name, $prefix, $year, $disk, $mbid)); if (!$db_results) { return null; } $id = Dba::insert_id(); // Remove from wanted album list if any request on it if (!empty($mbid) && AmpConfig::get('wanted')) { try { Wanted::delete_wanted_release($mbid); } catch (Exception $e) { debug_event('wanted', 'Cannot process wanted releases auto-removal check: ' . $e->getMessage(), '1'); } } self::$_mapcache[$name][$year][$disk][$mbid] = $id; return $id; }
public static function create(array $data) { $feed = $data['feed']; // Feed must be http/https if (strpos($feed, "http://") !== 0 && strpos($feed, "https://") !== 0) { AmpError::add('feed', T_('Wrong feed url')); } $catalog_id = intval($data['catalog']); if ($catalog_id <= 0) { AmpError::add('catalog', T_('Target catalog required')); } else { $catalog = Catalog::create_from_id($catalog_id); if ($catalog->gather_types !== "podcast") { AmpError::add('catalog', T_('Wrong target catalog type')); } } if (AmpError::occurred()) { return false; } $title = T_('Unknown'); $website = null; $description = null; $language = null; $copyright = null; $generator = null; $lastbuilddate = 0; $episodes = array(); $arturl = ''; $xmlstr = file_get_contents($feed); if ($xmlstr === false) { AmpError::add('feed', T_('Cannot access the feed.')); } else { $xml = simplexml_load_string($xmlstr); if ($xml === false) { AmpError::add('feed', T_('Cannot read the feed.')); } else { $title = html_entity_decode($xml->channel->title); $website = $xml->channel->link; $description = html_entity_decode($xml->channel->description); $language = $xml->channel->language; $copyright = html_entity_decode($xml->channel->copyright); $generator = html_entity_decode($xml->channel->generator); $lastbuilddatestr = $xml->channel->lastBuildDate; if ($lastbuilddatestr) { $lastbuilddate = strtotime($lastbuilddatestr); } if ($xml->channel->image) { $arturl = $xml->channel->image->url; } $episodes = $xml->channel->item; } } if (AmpError::occurred()) { return false; } $sql = "INSERT INTO `podcast` (`feed`, `catalog`, `title`, `website`, `description`, `language`, `copyright`, `generator`, `lastbuilddate`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; $db_results = Dba::write($sql, array($feed, $catalog_id, $title, $website, $description, $language, $copyright, $generator, $lastbuilddate)); if ($db_results) { $id = Dba::insert_id(); $podcast = new Podcast($id); $dirpath = $podcast->get_root_path(); if (!is_dir($dirpath)) { if (mkdir($dirpath) === false) { debug_event('podcast', 'Cannot create directory ' . $dirpath, 1); } } if (!empty($arturl)) { $art = new Art($id, 'podcast'); $art->insert_url($arturl); } if (count($episodes) > 0) { $podcast->add_episodes($episodes); } } return $db_results; }
protected static function update_recommendation_cache($type, $id, $recommendations) { self::delete_recommendation_cache($type, $id); $sql = "INSERT INTO `recommendation` (`object_type`, `object_id`, `last_update`) VALUES (?, ?, ?)"; Dba::write($sql, array($type, $id, time())); $insertid = Dba::insert_id(); foreach ($recommendations as $recommendation) { $sql = "INSERT INTO `recommendation_item` (`recommendation`, `recommendation_id`, `name`, `rel`, `mbid`) VALUES (?, ?, ?, ?, ?)"; Dba::write($sql, array($insertid, $recommendation['id'], $recommendation['name'], $recommendation['rel'], $recommendation['mbid'])); } }
/** * create * * This creates a new catalog entry and associate it to current instance */ public static function create($data) { $name = $data['name']; $type = $data['type']; $rename_pattern = $data['rename_pattern']; $sort_pattern = $data['sort_pattern']; $insert_id = 0; $filename = AmpConfig::get('prefix') . '/modules/catalog/' . $type . '.catalog.php'; $include = (require_once $filename); if ($include) { $sql = 'INSERT INTO `catalog` (`name`, `catalog_type`, ' . '`rename_pattern`, `sort_pattern`) VALUES (?, ?, ?, ?)'; Dba::write($sql, array($name, $type, $rename_pattern, $sort_pattern)); $insert_id = Dba::insert_id(); if (!$insert_id) { Error::add('general', T_('Catalog Insert Failed check debug logs')); debug_event('catalog', 'Insert failed: ' . json_encode($data), 2); return false; } $classname = 'Catalog_' . $type; if (!$classname::create_type($insert_id, $data)) { $sql = 'DELETE FROM `catalog` WHERE `id` = ?'; Dba::write($sql, array($insert_id)); $insert_id = 0; } } return $insert_id; }
/** * Add a new wanted release. * @param string $mbid * @param int $artist * @param string $artist_mbid * @param string $name * @param int $year */ public static function add_wanted($mbid, $artist, $artist_mbid, $name, $year) { $sql = "INSERT INTO `wanted` (`user`, `artist`, `artist_mbid`, `mbid`, `name`, `year`, `date`, `accepted`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; $accept = $GLOBALS['user']->has_access('75') ? true : AmpConfig::get('wanted_auto_accept'); $params = array($GLOBALS['user']->id, $artist, $artist_mbid, $mbid, $name, $year, time(), '0'); Dba::write($sql, $params); if ($accept) { $wantedid = Dba::insert_id(); $wanted = new Wanted($wantedid); $wanted->accept(); database_object::remove_from_cache('wanted', $wantedid); } }
/** * create * This is the democratic play create function it inserts this into the democratic table */ public static function create($data) { // Clean up the input $name = Dba::escape($data['name']); $base = Dba::escape($data['democratic']); $cool = Dba::escape($data['cooldown']); $level = Dba::escape($data['level']); $default = Dba::escape($data['make_default']); $user = Dba::escape($GLOBALS['user']->id); $sql = "INSERT INTO `democratic` (`name`,`base_playlist`,`cooldown`,`level`,`user`,`primary`) " . "VALUES ('{$name}','{$base}','{$cool}','{$level}','{$user}','{$default}')"; $db_results = Dba::write($sql); if ($db_results) { $insert_id = Dba::insert_id(); parent::create(array('session_id' => $insert_id, 'type' => 'vote', 'object_type' => 'song')); } return $db_results; }
/** * create * inserts a new user into ampache */ public static function create($username, $fullname, $email, $website, $password, $access, $state = '', $city = '', $disabled = false) { $website = rtrim($website, "/"); $password = hash('sha256', $password); $disabled = $disabled ? 1 : 0; /* Now Insert this new user */ $sql = "INSERT INTO `user` (`username`, `disabled`, " . "`fullname`, `email`, `password`, `access`, `create_date`"; $params = array($username, $disabled, $fullname, $email, $password, $access, time()); if (!empty($website)) { $sql .= ", `website`"; $params[] = $website; } if (!empty($state)) { $sql .= ", `state`"; $params[] = $state; } if (!empty($city)) { $sql .= ", `city`"; $params[] = $city; } $sql .= ") VALUES(?, ?, ?, ?, ?, ?, ?"; if (!empty($website)) { $sql .= ", ?"; } if (!empty($state)) { $sql .= ", ?"; } if (!empty($city)) { $sql .= ", ?"; } $sql .= ")"; $db_results = Dba::write($sql, $params); if (!$db_results) { return false; } // Get the insert_id $insert_id = Dba::insert_id(); /* Populates any missing preferences, in this case all of them */ self::fix_preferences($insert_id); return $insert_id; }
public static function create(array $data) { if (self::lookup($data) !== 0) { return false; } $name = $data['name']; $category = $data['category']; $summary = $data['summary']; $address = $data['address']; $email = $data['email']; $website = $data['website']; $user = $data['user'] ?: $GLOBALS['user']->id; $creation_date = $data['creation_date'] ?: time(); $sql = "INSERT INTO `label` (`name`, `category`, `summary`, `address`, `email`, `website`, `user`, `creation_date`) " . "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; Dba::write($sql, array($name, $category, $summary, $address, $email, $website, $user, $creation_date)); $id = Dba::insert_id(); return $id; }
/** * create * This function creates an empty playlist, gives it a name and type */ public static function create($name, $type, $user_id = null, $date = null) { if ($user_id == null) { $user_id = $GLOBALS['user']->id; } if ($date == null) { $date = time(); } $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) VALUES (?, ?, ?, ?)"; Dba::write($sql, array($name, $user_id, $type, $date)); $insert_id = Dba::insert_id(); return $insert_id; }
/** * update_370034 * * Add User messages and user follow tables. */ public static function update_370034() { $retval = true; $sql = "CREATE TABLE `user_pvmsg` (" . "`id` int(11) unsigned NOT NULL AUTO_INCREMENT," . "`subject` varchar(80) NOT NULL," . "`message` TEXT CHARACTER SET utf8 NULL," . "`from_user` int(11) unsigned NOT NULL," . "`to_user` int(11) unsigned NOT NULL," . "`is_read` tinyint(1) unsigned NOT NULL DEFAULT '0'," . "`creation_date` int(11) unsigned NULL," . "PRIMARY KEY (`id`)) ENGINE = MYISAM"; $retval = Dba::write($sql) ? $retval : false; $sql = "CREATE TABLE `user_follower` (" . "`id` int(11) unsigned NOT NULL AUTO_INCREMENT," . "`user` int(11) unsigned NOT NULL," . "`follow_user` int(11) unsigned NOT NULL," . "`follow_date` int(11) unsigned NULL," . "PRIMARY KEY (`id`)) ENGINE = MYISAM"; $retval = Dba::write($sql) ? $retval : false; $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES ('notify_email','0','Receive notifications by email (shouts, private messages, ...)',25,'boolean','options')"; $retval = Dba::write($sql) ? $retval : false; $id = Dba::insert_id(); $sql = "INSERT INTO `user_preference` VALUES (-1,?,'0')"; $retval = Dba::write($sql, array($id)) ? $retval : false; return $retval; }
/** * create * This takes a key'd array of data as input and inserts a new shoutbox entry, it returns the auto_inc id */ public static function create(array $data) { if (!Core::is_library_item($data['object_type'])) { return false; } $sticky = isset($data['sticky']) ? 1 : 0; $user = intval($data['user'] ?: $GLOBALS['user']->id); $date = intval($data['date'] ?: time()); $comment = strip_tags($data['comment']); $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`, `data`) " . "VALUES (? , ?, ?, ?, ?, ?, ?)"; Dba::write($sql, array($user, $date, $comment, $sticky, $data['object_id'], $data['object_type'], $data['data'])); $insert_id = Dba::insert_id(); // Never send email in case of user impersonation if (!isset($data['user']) && $insert_id) { $libitem = new $data['object_type']($data['object_id']); $item_owner_id = $libitem->get_user_owner(); if ($item_owner_id) { if (Preference::get_by_user($item_owner_id, 'notify_email')) { $item_owner = new User($item_owner_id); if (!empty($item_owner->email)) { $libitem->format(); $mailer = new Mailer(); $mailer->set_default_sender(); $mailer->recipient = $item_owner->email; $mailer->recipient_name = $item_owner->fullname; $mailer->subject = T_('New shout on your content'); $mailer->message = sprintf(T_("You just received a new shout from %s on your content `%s`.\n\n\n ----------------------\n %s\n ----------------------\n\n %s\n "), $GLOBALS['user']->fullname, $libitem->get_fullname(), $comment, AmpConfig::get('web_path') . "/shout.php?action=show_add_shout&type=" . $data['object_type'] . "&id=" . $data['object_id'] . "#shout" . $insert_id); $mailer->send(); } } } } return $insert_id; }
/** * add_tag_map * This adds a specific tag to the map for specified object */ public static function add_tag_map($type, $object_id, $tag_id, $user = '') { $uid = $user == '' ? intval($GLOBALS['user']->id) : intval($user); $tag_id = intval($tag_id); if (!self::validate_type($type)) { return false; } $id = intval($object_id); if (!$tag_id || !$id) { return false; } $sql = "INSERT INTO `tag_map` (`tag_id`,`user`,`object_type`,`object_id`) " . "VALUES ('{$tag_id}','{$uid}','{$type}','{$id}')"; Dba::write($sql); $insert_id = Dba::insert_id(); parent::add_to_cache('tag_map_' . $type, $insert_id, array('tag_id' => $tag_id, 'user' => $uid, 'object_type' => $type, 'object_id' => $id)); return $insert_id; }
/** * create * This function initializes a new Tmp_Playlist. It is associated with * the current session rather than a user, as you could have the same * user logged in from multiple locations. */ public static function create($data) { $sql = "INSERT INTO `tmp_playlist` " . "(`session`,`type`,`object_type`) " . " VALUES (?, ?, ?)"; Dba::write($sql, array($data['session_id'], $data['type'], $data['object_type'])); $id = Dba::insert_id(); /* Clean any other playlists associated with this session */ self::session_clean($data['session_id'], $id); return $id; }
/** * check * * Checks for an existing tv show season; if none exists, insert one. */ public static function check($tvshow, $season_number, $readonly = false) { $name = $tvshow . '_' . $season_number; // null because we don't have any unique id like mbid for now if (isset(self::$_mapcache[$name]['null'])) { return self::$_mapcache[$name]['null']; } $id = 0; $exists = false; if (!$exists) { $sql = 'SELECT `id` FROM `tvshow_season` WHERE `tvshow` = ? AND `season_number` = ?'; $db_results = Dba::read($sql, array($tvshow, $season_number)); $id_array = array(); while ($row = Dba::fetch_assoc($db_results)) { $key = 'null'; $id_array[$key] = $row['id']; } if (count($id_array)) { $id = array_shift($id_array); $exists = true; } } if ($exists) { self::$_mapcache[$name]['null'] = $id; return $id; } if ($readonly) { return null; } $sql = 'INSERT INTO `tvshow_season` (`tvshow`, `season_number`) ' . 'VALUES(?, ?)'; $db_results = Dba::write($sql, array($tvshow, $season_number)); if (!$db_results) { return null; } $id = Dba::insert_id(); self::$_mapcache[$name]['null'] = $id; return $id; }
/** * update_380001 * * Add podcasts */ public static function update_380001() { $retval = true; $sql = "CREATE TABLE `podcast` (`id` int( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , " . "`feed` varchar(4096) NOT NULL , " . "`catalog` int(11) NOT NULL , " . "`title` varchar(255) CHARACTER SET utf8 NOT NULL , " . "`website` varchar(255) NULL , " . "`description` varchar(4096) CHARACTER SET utf8 NULL , " . "`language` varchar(5) NULL , " . "`copyright` varchar(64) NULL , " . "`generator` varchar(64) NULL , " . "`lastbuilddate` int(11) UNSIGNED DEFAULT '0' NOT NULL , " . "`lastsync` int(11) UNSIGNED DEFAULT '0' NOT NULL" . ") ENGINE = MYISAM"; $retval &= Dba::write($sql); $sql = "CREATE TABLE `podcast_episode` (`id` int( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , " . "`title` varchar(255) CHARACTER SET utf8 NOT NULL , " . "`guid` varchar(255) NOT NULL , " . "`podcast` int(11) NOT NULL , " . "`state` varchar(32) NOT NULL , " . "`file` varchar(4096) CHARACTER SET utf8 NULL , " . "`source` varchar(4096) NULL , " . "`size` bigint(20) UNSIGNED DEFAULT '0' NOT NULL , " . "`time` smallint(5) UNSIGNED DEFAULT '0' NOT NULL , " . "`website` varchar(255) NULL , " . "`description` varchar(4096) CHARACTER SET utf8 NULL , " . "`author` varchar(64) NULL , " . "`category` varchar(64) NULL , " . "`played` tinyint(1) UNSIGNED DEFAULT '0' NOT NULL , " . "`pubdate` int(11) UNSIGNED NOT NULL , " . "`addition_time` int(11) UNSIGNED NOT NULL" . ") ENGINE = MYISAM"; $retval &= Dba::write($sql); $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES ('podcast_keep','10','Podcast: # latest episodes to keep',100,'integer','system')"; $retval &= Dba::write($sql); $id = Dba::insert_id(); $sql = "INSERT INTO `user_preference` VALUES (-1,?,'10')"; $retval &= Dba::write($sql, array($id)); $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES ('podcast_new_download','1','Podcast: # episodes to download when new episodes are available',100,'integer','system')"; $retval &= Dba::write($sql); $id = Dba::insert_id(); $sql = "INSERT INTO `user_preference` VALUES (-1,?,'1')"; $retval &= Dba::write($sql, array($id)); $sql = "ALTER TABLE `rating` CHANGE `object_type` `object_type` ENUM ('artist','album','song','stream','video','playlist','tvshow','tvshow_season','podcast','podcast_episode') NULL"; $retval &= Dba::write($sql); return $retval; }
public static function create(array $data) { $subject = trim(strip_tags($data['subject'])); $message = trim(strip_tags($data['message'])); if (empty($subject)) { AmpError::add('subject', T_('Error: Subject Required')); } $to_user = User::get_from_username($data['to_user']); if (!$to_user->id) { AmpError::add('to_user', T_('Error: Unknown user')); } if (!AmpError::occurred()) { $from_user = $data['from_user'] ?: $GLOBALS['user']->id; $creation_date = $data['creation_date'] ?: time(); $is_read = $data['is_read'] ?: 0; $sql = "INSERT INTO `user_pvmsg` (`subject`, `message`, `from_user`, `to_user`, `creation_date`, `is_read`) " . "VALUES (?, ?, ?, ?, ?, ?)"; if (Dba::write($sql, array($subject, $message, $from_user, $to_user->id, $creation_date, $is_read))) { $insert_id = Dba::insert_id(); // Never send email in case of user impersonation if (!isset($data['from_user']) && $insert_id) { if (Preference::get_by_user($to_user->id, 'notify_email')) { if (!empty($to_user->email)) { $mailer = new Mailer(); $mailer->set_default_sender(); $mailer->recipient = $to_user->email; $mailer->recipient_name = $to_user->fullname; $mailer->subject = "[" . T_('Private Message') . "] " . $subject; $mailer->message = sprintf(T_("You just received a new private message from %s.\n\n\n ----------------------\n %s\n ----------------------\n\n %s\n "), $GLOBALS['user']->fullname, $message, AmpConfig::get('web_path') . "/pvmsg.php?action=show&pvmsg_id=" . $insert_id); $mailer->send(); } } } return $insert_id; } } return false; }
/** * add_tag_map * This adds a specific tag to the map for specified object */ public static function add_tag_map($type, $object_id, $tag_id, $user = '') { $uid = $user == '' ? intval($GLOBALS['user']->id) : intval($user); $tag_id = intval($tag_id); if (!Core::is_library_item($type)) { return false; } $id = intval($object_id); if (!$tag_id || !$id) { return false; } // If tag merged to another one, add reference to the merge destination $parent = new Tag($tag_id); $merges = $parent->get_merged_tags(); if ($parent->is_hidden == false) { $merges[] = array('id' => $parent->id, 'name' => $parent->name); } foreach ($merges as $tag) { $sql = "INSERT INTO `tag_map` (`tag_id`,`user`,`object_type`,`object_id`) " . "VALUES (?, ?, ?, ?)"; Dba::write($sql, array($tag['id'], $uid, $type, $id)); } $insert_id = Dba::insert_id(); parent::add_to_cache('tag_map_' . $type, $insert_id, array('tag_id' => $tag_id, 'user' => $uid, 'object_type' => $type, 'object_id' => $id)); return $insert_id; }
/** * create * * This creates a new catalog entry and associate it to current instance * @param array $data * @return int */ public static function create($data) { $name = $data['name']; $type = $data['type']; $rename_pattern = $data['rename_pattern']; $sort_pattern = $data['sort_pattern']; $gather_types = $data['gather_media']; // Should it be an array? Not now. if (!in_array($gather_types, array('music', 'clip', 'tvshow', 'movie', 'personal_video', 'podcast'))) { return 0; } $insert_id = 0; $filename = AmpConfig::get('prefix') . '/modules/catalog/' . $type . '/' . $type . '.catalog.php'; $include = (require_once $filename); if ($include) { $sql = 'INSERT INTO `catalog` (`name`, `catalog_type`, ' . '`rename_pattern`, `sort_pattern`, `gather_types`) VALUES (?, ?, ?, ?, ?)'; Dba::write($sql, array($name, $type, $rename_pattern, $sort_pattern, $gather_types)); $insert_id = Dba::insert_id(); if (!$insert_id) { AmpError::add('general', T_('Catalog Insert Failed check debug logs')); debug_event('catalog', 'Insert failed: ' . json_encode($data), 2); return 0; } $classname = 'Catalog_' . $type; if (!$classname::create_type($insert_id, $data)) { $sql = 'DELETE FROM `catalog` WHERE `id` = ?'; Dba::write($sql, array($insert_id)); $insert_id = 0; } } return $insert_id; }