Пример #1
0
    /**
     * Add a notification for specific users
     *
     * @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
     * @param array $data Data specific for this type that will be inserted
     * @param array $notify_users User list to notify
     */
    public function add_notifications_for_users($notification_type_name, $data, $notify_users)
    {
        if (is_array($notification_type_name)) {
            foreach ($notification_type_name as $type) {
                $this->add_notifications_for_users($type, $data, $notify_users);
            }
            return;
        }
        $notification_type_id = $this->get_notification_type_id($notification_type_name);
        $item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);
        $user_ids = array();
        $notification_objects = $notification_methods = array();
        // Never send notifications to the anonymous user!
        unset($notify_users[ANONYMOUS]);
        // Make sure not to send new notifications to users who've already been notified about this item
        // This may happen when an item was added, but now new users are able to see the item
        $sql = 'SELECT n.user_id
			FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
			WHERE n.notification_type_id = ' . (int) $notification_type_id . '
				AND n.item_id = ' . (int) $item_id . '
				AND nt.notification_type_id = n.notification_type_id
				AND nt.notification_type_enabled = 1';
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            unset($notify_users[$row['user_id']]);
        }
        $this->db->sql_freeresult($result);
        if (!sizeof($notify_users)) {
            return;
        }
        // Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications)
        $notification = $this->get_item_type_class($notification_type_name);
        $pre_create_data = $notification->pre_create_insert_array($data, $notify_users);
        unset($notification);
        $insert_buffer = new \src\db\sql_insert_buffer($this->db, $this->notifications_table);
        // Go through each user so we can insert a row in the DB and then notify them by their desired means
        foreach ($notify_users as $user => $methods) {
            $notification = $this->get_item_type_class($notification_type_name);
            $notification->user_id = (int) $user;
            // Insert notification row using buffer.
            $insert_buffer->insert($notification->create_insert_array($data, $pre_create_data));
            // Users are needed to send notifications
            $user_ids = array_merge($user_ids, $notification->users_to_query());
            foreach ($methods as $method) {
                // setup the notification methods and add the notification to the queue
                if ($method) {
                    if (!isset($notification_methods[$method])) {
                        $notification_methods[$method] = $this->get_method_class($method);
                    }
                    $notification_methods[$method]->add_to_queue($notification);
                }
            }
        }
        $insert_buffer->flush();
        // We need to load all of the users to send notifications
        $this->user_loader->load_users($user_ids);
        // run the queue for each method to send notifications
        foreach ($notification_methods as $method) {
            $method->notify();
        }
    }
Пример #2
0
    /**
     * @param int			$start		Start of staggering step
     * @return		mixed		int start of the next step, null if the end was reached
     */
    public function convert_user_field_to_custom_field($start)
    {
        $insert_buffer = new \src\db\sql_insert_buffer($this->db, $this->table_prefix . 'profile_fields_data');
        $limit = 250;
        $converted_users = 0;
        $sql = 'SELECT user_id, ' . $this->user_column_name . '
			FROM ' . $this->table_prefix . 'users
			WHERE ' . $this->user_column_name . " <> ''\n\t\t\tORDER BY user_id";
        $result = $this->db->sql_query_limit($sql, $limit, $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $converted_users++;
            $cp_data = array('pf_' . $this->profilefield_name => $row[$this->user_column_name]);
            $sql = 'UPDATE ' . $this->table_prefix . 'profile_fields_data
				SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . '
				WHERE user_id = ' . (int) $row['user_id'];
            $this->db->sql_query($sql);
            if (!$this->db->sql_affectedrows()) {
                $cp_data['user_id'] = (int) $row['user_id'];
                $cp_data = array_merge($this->get_insert_sql_array(), $cp_data);
                $insert_buffer->insert($cp_data);
            }
        }
        $this->db->sql_freeresult($result);
        $insert_buffer->flush();
        if ($converted_users < $limit) {
            // No more users left, we are done...
            return;
        }
        return $start + $limit;
    }
Пример #3
0
    /**
     * Populate the language tables
     */
    function add_language($mode, $sub)
    {
        global $db, $lang, $src_root_path, $phpEx;
        $dir = @opendir($src_root_path . 'language');
        if (!$dir) {
            $this->error('Unable to access the language directory', __LINE__, __FILE__);
        }
        $installed_languages = array();
        while (($file = readdir($dir)) !== false) {
            $path = $src_root_path . 'language/' . $file;
            if ($file == '.' || $file == '..' || is_link($path) || is_file($path) || $file == 'CVS') {
                continue;
            }
            if (is_dir($path) && file_exists($path . '/iso.txt')) {
                $lang_file = file("{$path}/iso.txt");
                $lang_pack = array('lang_iso' => basename($path), 'lang_dir' => basename($path), 'lang_english_name' => trim(htmlspecialchars($lang_file[0])), 'lang_local_name' => trim(htmlspecialchars($lang_file[1], ENT_COMPAT, 'UTF-8')), 'lang_author' => trim(htmlspecialchars($lang_file[2], ENT_COMPAT, 'UTF-8')));
                $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $lang_pack));
                $installed_languages[] = (int) $db->sql_nextid();
                if ($db->get_sql_error_triggered()) {
                    $error = $db->sql_error($db->get_sql_error_sql());
                    $this->p_master->db_error($error['message'], $db->get_sql_error_sql(), __LINE__, __FILE__);
                }
            }
        }
        closedir($dir);
        $sql = 'SELECT *
			FROM ' . PROFILE_FIELDS_TABLE;
        $result = $db->sql_query($sql);
        $profile_fields = array();
        $insert_buffer = new \src\db\sql_insert_buffer($db, PROFILE_LANG_TABLE);
        while ($row = $db->sql_fetchrow($result)) {
            foreach ($installed_languages as $lang_id) {
                $insert_buffer->insert(array('field_id' => $row['field_id'], 'lang_id' => $lang_id, 'lang_name' => strtoupper(substr($row['field_name'], 6)), 'lang_explain' => '', 'lang_default_value' => ''));
            }
        }
        $db->sql_freeresult($result);
        $insert_buffer->flush();
    }