getInstance() публичный статический Метод

创建一个用来实例化对象的方法
public static getInstance ( )
Пример #1
0
function is_answered($task_id)
{
    $uid = (int) $_SESSION['uid'];
    $sql = "select * from moderators_history where task_id={$task_id} && to_usr!=from_usr order by id desc limit 0,1;";
    $from_usr = Mysql::getInstance()->query($sql)->first('from_usr');
    return $from_usr == $uid;
}
Пример #2
0
 public function __construct()
 {
     $this->mysqlInstance = \Mysql::getInstance();
     $this->reseller_id = NULL;
     $this->admin_id = NULL;
     $this->admin_login = NULL;
 }
 public function check($page, $action = 'view')
 {
     if ($this->admin->getLogin() == 'admin') {
         return true;
     }
     return (bool) Mysql::getInstance()->from('acl')->where(array('gid' => $this->admin->getGID(), 'page' => $page, 'acl.' . $action => 1))->get()->first();
 }
Пример #4
0
 public static function getInstance($id = false)
 {
     if (!$id) {
         foreach (self::$connectionData as $k => $v) {
             $idC = $k;
             break;
         }
     } else {
         $idC = $id;
     }
     $connection = Model::getConnectionData($idC);
     $database = NULL;
     // Debug::print_r("getInstance $id ", $connection);
     if (Run::MYSQL === true && $connection['type_db'] == "mysql") {
         $database = Mysql::getInstance($id);
         if ($id) {
             Mysql::setActive($id);
         }
         self::$query = new MysqlQuery($id);
         return $database;
     } else {
         if (Run::POSTGRE === true && $connection['type_db'] == "postgre") {
             $database = Postgre::getInstance($id);
             if ($id) {
                 Postgre::setActive($id);
             }
             self::$query = new PostgreQuery($id);
             return $database;
         } else {
             return false;
         }
     }
 }
 public function delete(RESTApiRequest $request, $parent_id)
 {
     $user = \Mysql::getInstance()->from('users')->where(array('id' => $parent_id))->get()->first();
     if (!empty($user['now_playing_link_id'])) {
         switch ($user['now_playing_type']) {
             case 1:
                 // tv
                 if (time() - strtotime($user['now_playing_start']) > 30 * 60) {
                     // more then 30 min
                     \Mysql::getInstance()->insert('played_itv', array('itv_id' => $user['now_playing_link_id'], 'uid' => $parent_id, 'playtime' => 'NOW()', 'user_locale' => $user['locale']));
                 }
                 break;
             case 2:
                 // video
                 if (time() - strtotime($user['now_playing_start']) > 60 * 60) {
                     // more then 1 hour (70% can't be counted)
                     \Mysql::getInstance()->insert('played_video', array('video_id' => $user['now_playing_link_id'], 'uid' => $parent_id, 'playtime' => 'NOW()'));
                 }
                 break;
             case 11:
                 // tvarchive
                 if (time() - strtotime($user['now_playing_start']) > 60) {
                     // more then 1 min
                     $program = \Mysql::getInstance()->from('epg')->where(array('id' => $user['now_playing_link_id']))->get()->first();
                     if (!empty($program)) {
                         \Mysql::getInstance()->insert('played_tv_archive', array('ch_id' => $program['ch_id'], 'uid' => $parent_id, 'playtime' => 'NOW()', 'length' => time() - strtotime($user['now_playing_start'])));
                     }
                 }
                 break;
         }
     }
     return \Mysql::getInstance()->update('users', array('now_playing_type' => '', 'now_playing_content' => '', 'last_active' => 'NOW()'), array('id' => $parent_id))->result();
 }
function set_karaoke_returned($id, $val, $txt)
{
    if (!$id) {
        return;
    }
    Mysql::getInstance()->update('karaoke', array('returned' => $val, 'reason' => $txt, 'done' => intval(!$val)), array('id' => $id));
}
Пример #7
0
function get_users_count_in_tariff($tariff)
{
    $tariff_ids = array($tariff['id']);
    if ($tariff['user_default'] == 1) {
        $tariff_ids[] = 0;
    }
    return Mysql::getInstance()->from('users')->count()->in('tariff_plan_id', $tariff_ids)->get()->counter();
}
Пример #8
0
 function MysqlQuery($id)
 {
     $this->query_string = "";
     $this->_line = __LINE__;
     $this->_function = __FUNCTION__;
     $this->_class = __CLASS__;
     $this->_file = __FILE__;
     $this->mysql = Mysql::getInstance($id);
 }
Пример #9
0
 public function executeSql($file)
 {
     $fileInfo = file_get_contents($file);
     $sql = $this->parseSql($fileInfo);
     unset($fileInfo);
     $mysql = Mysql::getInstance();
     foreach ($sql as $s) {
         $mysql->execute($s);
     }
 }
 private function filter($profile)
 {
     if (empty($profile)) {
         throw new RESTNotFound("User not found");
     }
     $profile = array_intersect_key($profile, $this->fields_map);
     $themes = \Middleware::getThemes();
     $profile['theme'] = empty($profile['theme']) || !array_key_exists($profile['theme'], $themes) ? \Mysql::getInstance()->from('settings')->get()->first('default_template') : $profile['theme'];
     $profile['themes'] = $themes;
     return $profile;
 }
Пример #11
0
 public function __construct()
 {
     $this->db = Mysql::getInstance();
     $this->xml_url = $this->xml_url . '?' . time();
     $this->weekday_arr = array('', _('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat'));
     $this->tod_arr = array(_('Night'), _('Morning'), _('Day'), _('Evening'));
     $this->month_arr = array('', _('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec'));
     $this->cloudiness_arr = array(_('clear'), _('partly cloudy'), _('cloudy'), _('overcast'));
     $this->precipitation_arr = array('', '', '', '', _('rain'), _('rainfall'), _('snow'), _('snow'), _('thunderstorm'), _('no data'), _('w/o precipitation'));
     $this->direction_arr = array('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW');
 }
 public function update(RESTRequest $request)
 {
     $stb_list = $request->getConvertedIdentifiers();
     if (empty($stb_list)) {
         throw new RESTCommandException('Empty stb list');
     }
     foreach ($stb_list as $uid) {
         Mysql::getInstance()->update('users', array('access_token' => strtoupper(md5(microtime(1) . uniqid()))), array('id' => $uid));
         Mysql::getInstance()->update('access_tokens', array('token' => 'invalid_' . md5(microtime(1) . uniqid()), 'refresh_token' => 'invalid_' . md5(microtime(1) . uniqid())), array('uid' => $uid));
     }
     return true;
 }
Пример #13
0
 public function setOff()
 {
     $this->checkIfInitialized();
     if ($this->storage['status'] == 0) {
         return true;
     }
     $result = Mysql::getInstance()->update('storages', array('status' => 0), array('id' => $this->storage['id']));
     if ($result) {
         Mysql::getInstance()->insert('master_log', array('log_txt' => "Storage " . $this->storage['storage_name'] . " has been disabled after " . $this->max_failures . " failures in " . $this->stat_period . "s", 'added' => 'NOW()'));
     }
     return $result;
 }
Пример #14
0
 public function getCollectionByAttribute($attribute, $like)
 {
     $bdd = Mysql::getInstance();
     $select = 'SELECT id FROM chauffeurs where ' . $attribute . ' LIKE "%' . $like . '%"';
     $req = $bdd->prepare($select);
     $req->execute();
     $chauffeurs = array();
     foreach ($req->fetchAll() as $row) {
         $chauffeur = new Chauffeurs();
         $chauffeur->load($row["id"]);
         $chauffeurs[] = $chauffeur;
     }
     return $chauffeurs;
 }
Пример #15
0
 public static function writePackageSubscribeLog($user_id, $package_id, $set_state)
 {
     $data = array('user_id' => $user_id, 'set_state' => $set_state, 'package_id' => $package_id);
     if (!empty(Stb::getInstance()->id) && (empty($_SERVER['TARGET']) || $_SERVER['TARGET'] !== 'API' && $_SERVER['TARGET'] !== 'ADM')) {
         $data['initiator_id'] = Stb::getInstance()->id;
         $data['initiator'] = 'user';
     } else {
         $data['initiator_id'] = Admin::getInstance()->getId();
         if (!empty($data['initiator_id'])) {
             $data['initiator'] = 'admin';
         }
     }
     Mysql::getInstance()->insert('package_subscribe_log', $data);
 }
 public function save()
 {
     $favorites = @$_REQUEST['favorites'];
     if (empty($favorites)) {
         $favorites = '""';
     }
     $favorites = System::base64_encode($favorites);
     $record = Mysql::getInstance()->from('media_favorites')->where(array('uid' => Stb::getInstance()->id))->get()->first();
     if (empty($record)) {
         return Mysql::getInstance()->insert('media_favorites', array('favorites' => $favorites, 'uid' => Stb::getInstance()->id))->insert_id();
     } else {
         return Mysql::getInstance()->update('media_favorites', array('favorites' => $favorites), array('uid' => Stb::getInstance()->id))->result();
     }
 }
Пример #17
0
 public function isAuthorized()
 {
     if (empty($_SESSION['login']) || empty($_SESSION['pass'])) {
         return false;
     }
     $admin = Mysql::getInstance()->from('administrators')->where(array('login' => $_SESSION['login']))->get()->first();
     if (empty($admin)) {
         return false;
     }
     $is_authorized = $admin['pass'] == $_SESSION['pass'];
     if ($is_authorized) {
         $this->profile = $admin;
     }
     return $is_authorized;
 }
Пример #18
0
 public function getById($id, $pretty_id = false)
 {
     if ($pretty_id) {
         $genres = $this->getAll($pretty_id, true);
         $genres = array_filter($genres, function ($genre) use($id) {
             return $id == $genre['id'];
         });
         if (empty($genres)) {
             return null;
         }
         $genres = array_values($genres);
         return Mysql::getInstance()->from('tv_genre')->where(array('id' => $genres[0]['_id']))->get()->first();
     } else {
         return Mysql::getInstance()->from('tv_genre')->where(array('id' => intval($id)))->get()->first();
     }
 }
Пример #19
0
 /**
  * 初始化
  * @access	public
  * @return 	void
  */
 public static function init()
 {
     require APP_ROOT . 'vendor/autoload.php';
     $model_path = APP_ROOT . 'config/model.php';
     if (file_exists($model_path)) {
         require $model_path;
     }
     require SKPHP_CORE . 'Mysql.php';
     require SKPHP_CORE . 'Fun.php';
     self::$_instance['mysql'] = Mysql::getInstance();
     // 加载应用配置和方法
     self::mergeConfig();
     if (empty(Config::$_config['charset'])) {
         trigger_error('IS Not Setting charset @ config.php');
     }
     header("Content-type:text/html;charset=" . Config::$_config['charset']);
 }
 public function update(RESTRequest $request)
 {
     $put = $request->getPut();
     if (empty($put)) {
         throw new RESTCommandException('HTTP PUT data is empty');
     }
     $allowed_to_update_fields = array_fill_keys(array('monitoring_status'), true);
     $data = array_intersect_key($put, $allowed_to_update_fields);
     if (empty($data)) {
         throw new RESTCommandException('Update data is empty');
     }
     $ids = $request->getIdentifiers();
     if (empty($ids)) {
         throw new RESTCommandException('Empty channel id');
     }
     $channel_id = intval($ids[0]);
     return Mysql::getInstance()->update('itv', $data, array('id' => $channel_id));
 }
Пример #21
0
 public static function getServicesForPackage($package_id)
 {
     $package = self::getPackageById($package_id);
     if ($package['all_services'] == 1) {
         return 'all';
     }
     $service_ids = Mysql::getInstance()->from('service_in_package')->where(array('package_id' => $package_id))->get()->all('service_id');
     $services = Mysql::getInstance();
     if ($package['type'] == 'tv') {
         $services = $services->select('id, name')->from('itv')->orderby('name')->get()->all();
     } elseif ($package['type'] == 'radio') {
         $services = $services->select('id, name')->from('radio')->orderby('name')->get()->all();
     } elseif ($package['type'] == 'video') {
         $services = $services->select('id, name')->from('video')->orderby('name')->get()->all();
     } else {
         $services = array_unique($service_ids);
     }
     return $services;
 }
 protected function postParse($weather)
 {
     if (!empty($weather['date'])) {
         if (strlen($weather['date']) == 10 && !empty($weather['hour'])) {
             $weather['date'] = $weather['date'] . ' ' . $weather['hour'] . ':00:00';
         }
         $target_timezone = Mysql::getInstance()->from('cities')->where(array('id' => Stb::getInstance()->city_id))->get()->first('timezone');
         if (!$target_timezone) {
             $target_timezone = Stb::getInstance()->getTimezone();
         }
         $date = new DateTime($weather['date'], new DateTimeZone('Europe/Kiev'));
         $date->setTimeZone(new DateTimeZone($target_timezone));
         $weather['date_orig'] = $weather['date'];
         $weather['date'] = $date->format('Y-m-d H:i:s');
         $weather['hour'] = $date->format('G');
         $weather['pict'] = $this->getPicture($weather);
     }
     return $weather;
 }
 public function getById($id, $pretty_id = false)
 {
     if ($pretty_id) {
         $categories = $this->getAll($pretty_id);
         $categories = array_filter($categories, function ($category) use($id) {
             return $id == $category['id'];
         });
         if (empty($categories)) {
             return null;
         }
         $categories = array_values($categories);
         $category = Mysql::getInstance()->from('media_category')->where(array('category_name' => $categories[0]['original_title']))->get()->first();
         if (!empty($category)) {
             $category['id'] = $id;
         }
         return $category;
     } else {
         return Mysql::getInstance()->from('media_category')->where(array('id' => intval($id)))->get()->first();
     }
 }
 public function __construct()
 {
     $this->db = Mysql::getInstance();
     $this->stb = Stb::getInstance();
     $this->response['max_page_items'] = self::max_page_items;
     /// TRANSLATORS: Letters of the alphabet. If the letter is missing - leave ".";
     $this->abc = array_filter(array('*', _('ABC_1l'), _('ABC_2l'), _('ABC_3l'), _('ABC_4l'), _('ABC_5l'), _('ABC_6l'), _('ABC_7l'), _('ABC_8l'), _('ABC_9l'), _('ABC_10l'), _('ABC_11l'), _('ABC_12l'), _('ABC_13l'), _('ABC_14l'), _('ABC_15l'), _('ABC_16l'), _('ABC_17l'), _('ABC_18l'), _('ABC_19l'), _('ABC_20l'), _('ABC_21l'), _('ABC_22l'), _('ABC_23l'), _('ABC_24l'), _('ABC_25l'), _('ABC_26l'), _('ABC_27l'), _('ABC_28l'), _('ABC_29l'), _('ABC_30l'), _('ABC_31l'), _('ABC_32l'), _('ABC_33l')), function ($e) {
         return $e != '.';
     });
     $this->months = array(_('january'), _('february'), _('march'), _('april'), _('may'), _('june'), _('july'), _('august'), _('september'), _('october'), _('november'), _('december'));
     $this->all_title = _('All');
     $this->no_ch_info = _('[No channel info]');
     $this->page = @intval($_REQUEST['p']);
     if ($this->page == 0) {
         $this->load_last_page = true;
     }
     if ($this->page > 0) {
         $this->page--;
     }
 }
 public function get(RESTApiRequest $request, $parent_id)
 {
     $events = \Mysql::getInstance()->from('events')->where(array('uid' => $parent_id))->orderby('addtime', 'DESC')->get()->all();
     if (empty($events)) {
         return null;
     }
     $allowed_events = array('send_msg');
     $user_events = array();
     foreach ($events as $event) {
         if (!in_array($event['event'], $allowed_events)) {
             continue;
         }
         $result = array();
         $result['id'] = $event['id'];
         $result['type'] = $event['event'];
         $result['msg'] = $event['msg'];
         $result['send_time'] = strtotime($event['addtime']);
         $user_events[] = $result;
     }
     return $user_events;
 }
Пример #26
0
set_time_limit(0);
session_start();
ob_start();
include "./common.php";
Admin::checkAuth();
Admin::checkAccess(AdminAccess::ACCESS_VIEW);
$updated_video = 0;
$updated_karaoke = 0;
$not_custom_video = Mysql::getInstance()->from('video')->where(array('protocol!=' => 'custom'))->get();
while ($item = $not_custom_video->next()) {
    $master = new VideoMaster();
    $master->getAllGoodStoragesForMediaFromNet($item['id'], true);
    unset($master);
    $updated_video++;
}
$not_custom_karaoke = Mysql::getInstance()->from('karaoke')->where(array('protocol!=' => 'custom'))->get();
while ($item = $not_custom_video->next()) {
    $master = new KaraokeMaster();
    $master->getAllGoodStoragesForMediaFromNet($item['id']);
    unset($master);
    $updated_karaoke++;
}
$error = sprintf(_('Updated %s videos and %s karaokes'), $updated_video, $updated_karaoke);
$debug = '<!--' . ob_get_contents() . '-->';
ob_clean();
echo $debug;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
Пример #27
0
if (@$_GET['edit'] && !empty($id)) {
    $action_name = 'edit';
    $action_value = _('Save');
    $edit = Mysql::getInstance()->from('epg_setting')->where(array('id' => $id))->get()->first();
}
if (isset($_GET['update_epg'])) {
    Admin::checkAccess(AdminAccess::ACCESS_PAGE_ACTION);
    $epg = new Epg();
    if (isset($_GET['force'])) {
        $force = true;
    } else {
        $force = false;
    }
    $error = $epg->updateEpg($force);
}
$settings = Mysql::getInstance()->from('epg_setting')->get()->all();
$debug = '<!--' . ob_get_contents() . '-->';
ob_clean();
echo $debug;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">

body {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
}
td {
    font-family: Arial, Helvetica, sans-serif;
Пример #28
0
 public function getLinksForMonitoring($status = FALSE)
 {
     $result = Mysql::getInstance()->select('ch_links.*, itv.name as ch_name')->from('ch_links')->join('itv', 'itv.id', 'ch_links.ch_id', 'INNER')->where(array('ch_links.enable_monitoring' => 1, 'ch_links.enable_balancer_monitoring' => 0));
     if ($status) {
         $result->where(array('ch_links.status' => (int) ($status == 'up')));
     }
     $monitoring_links = $result->orderby('ch_id')->get()->all();
     $result = Mysql::getInstance()->select('ch_links.*, streamer_id, ch_link_on_streamer.id as streamer_link_id, itv.name as ch_name')->from('ch_links')->join('ch_link_on_streamer', 'link_id', 'ch_links.id', 'INNER')->join('itv', 'itv.id', 'ch_links.ch_id', 'INNER')->where(array('ch_links.enable_monitoring' => 1, 'ch_links.enable_balancer_monitoring' => 1, 'ch_links.use_load_balancing' => 1));
     if ($status) {
         $result->where(array('ch_links.status' => (int) ($status == 'up')));
     }
     $balanser_monitoring_links_raw = $result->orderby('ch_id')->get()->all();
     $servers_map = StreamServer::getIdMap();
     $balanser_monitoring_links = array();
     foreach ($balanser_monitoring_links_raw as $link) {
         if (empty($servers_map[$link['streamer_id']])) {
             continue;
         }
         if ($link['use_http_tmp_link'] == 1 && $link['wowza_tmp_link'] == 0) {
             $colon_pos = strpos($servers_map[$link['streamer_id']]['address'], ":");
             if ($colon_pos === false) {
                 $address = $servers_map[$link['streamer_id']]['address'];
             } else {
                 $address = substr($servers_map[$link['streamer_id']]['address'], 0, $colon_pos);
             }
             $link['url'] = preg_replace('/:\\/\\/([^\\/:]*)/', '://' . $address, $link['url']);
             $link['monitoring_url'] = preg_replace('/:\\/\\/([^\\/:]*)/', '://' . $address, $link['monitoring_url']);
         } else {
             $link['url'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $servers_map[$link['streamer_id']]['address'], $link['url']);
             $link['monitoring_url'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $servers_map[$link['streamer_id']]['address'], $link['monitoring_url']);
         }
         $link['id'] = 's' . $link['streamer_link_id'];
         $balanser_monitoring_links[] = $link;
     }
     $monitoring_links = array_merge($monitoring_links, $balanser_monitoring_links);
     $monitoring_links = array_map(function ($cmd) {
         $cmd['monitoring_url'] = trim($cmd['monitoring_url']);
         if (!empty($cmd['monitoring_url']) && preg_match("/(\\S+:\\/\\/\\S+)/", $cmd['monitoring_url'], $match)) {
             $cmd['url'] = $match[1];
         } else {
             if (preg_match("/(\\S+:\\/\\/\\S+)/", $cmd['url'], $match)) {
                 $cmd['url'] = $match[1];
             }
         }
         if ($cmd['flussonic_tmp_link']) {
             $cmd['type'] = 'flussonic_health';
         } elseif ($cmd['nginx_secure_link']) {
             try {
                 $cmd['type'] = 'nginx_secure_link';
                 $cmd['url'] = Itv::getNginxSecureLink($cmd['url']);
             } catch (ItvLinkException $e) {
                 return false;
             }
         } else {
             $cmd['type'] = 'stream';
         }
         return $cmd;
     }, $monitoring_links);
     return array_values(array_filter($monitoring_links));
 }
Пример #29
0
 public function __construct()
 {
     $this->db = Mysql::getInstance();
     $this->cache_table = "course_cache";
 }
Пример #30
0
function get_categories(){

    $categories = Mysql::getInstance()->from('media_category')->orderby('num')->get()->all();

    $str = "var all_categories = [ ";

    foreach($categories as $arr){
        $str .= "{ id : ".$arr['id'].", name : '"._($arr['category_name'])."'},";
    }
    $str = substr($str, 0, strlen($str)-1);
    $str .= " ]";
    return $str;
}