Beispiel #1
0
 /**
  * create
  * This is a static function that takes a key'd array for input
  * and if everything is good creates the object.
  */
 public static function create(array $data)
 {
     // Make sure we've got a name
     if (!strlen($data['name'])) {
         AmpError::add('name', T_('Name Required'));
     }
     $allowed_array = array('https', 'http', 'mms', 'mmsh', 'mmsu', 'mmst', 'rtsp', 'rtmp');
     $elements = explode(":", $data['url']);
     if (!in_array($elements['0'], $allowed_array)) {
         AmpError::add('url', T_('Invalid URL must be http:// or https://'));
     }
     if (!empty($data['site_url'])) {
         $elements = explode(":", $data['site_url']);
         if (!in_array($elements['0'], $allowed_array)) {
             AmpError::add('site_url', T_('Invalid URL must be http:// or https://'));
         }
     }
     // Make sure it's a real catalog
     $catalog = Catalog::create_from_id($data['catalog']);
     if (!$catalog->name) {
         AmpError::add('catalog', T_('Invalid Catalog'));
     }
     if (AmpError::occurred()) {
         return false;
     }
     // If we've made it this far everything must be ok... I hope
     $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`codec`) " . "VALUES (?, ?, ?, ?, ?)";
     $db_results = Dba::write($sql, array($data['name'], $data['site_url'], $data['url'], $catalog->id, $data['codec']));
     return $db_results;
 }
Beispiel #2
0
 /**
  * update
  * This function is an all encompasing update function that
  * calls the mini ones does all the error checking and all that
  * good stuff
  */
 public function update(array $data)
 {
     if (empty($data['username'])) {
         AmpError::add('username', T_('Error Username Required'));
     }
     if ($data['password1'] != $data['password2'] and !empty($data['password1'])) {
         AmpError::add('password', T_("Error Passwords don't match"));
     }
     if (AmpError::occurred()) {
         return false;
     }
     if (!isset($data['fullname_public'])) {
         $data['fullname_public'] = false;
     }
     foreach ($data as $name => $value) {
         if ($name == 'password1') {
             $name = 'password';
         } else {
             $value = scrub_in($value);
         }
         switch ($name) {
             case 'password':
             case 'access':
             case 'email':
             case 'username':
             case 'fullname':
             case 'fullname_public':
             case 'website':
             case 'state':
             case 'city':
                 if ($this->{$name} != $value) {
                     $function = 'update_' . $name;
                     $this->{$function}($value);
                 }
                 break;
             case 'clear_stats':
                 Stats::clear($this->id);
                 break;
             default:
                 // Rien a faire
                 break;
         }
     }
     return $this->id;
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 if ($pass1 !== $pass2 || !strlen($pass1)) {
     AmpError::add('password', T_("Error Passwords don't match"));
 }
 if (empty($username)) {
     AmpError::add('username', T_('Error Username Required'));
 }
 /* make sure the username doesn't already exist */
 if (!User::check_username($username)) {
     AmpError::add('username', T_('Error Username already exists'));
 }
 // Check the mail for correct address formation.
 if (!Mailer::validate_address($email)) {
     AmpError::add('email', T_('Invalid email address'));
 }
 /* If we've got an error then show add form! */
 if (AmpError::occurred()) {
     require_once AmpConfig::get('prefix') . UI::find_template('show_add_user.inc.php');
     break;
 }
 /* Attempt to create the user */
 $user_id = User::create($username, $fullname, $email, $website, $pass1, $access, $state, $city);
 if (!$user_id) {
     AmpError::add('general', T_("Error: Insert Failed"));
 }
 $user = new User($user_id);
 $user->upload_avatar();
 if ($access == 5) {
     $access = T_('Guest');
 } elseif ($access == 25) {
     $access = T_('User');
 } elseif ($access == 100) {