Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#85 2013-11-13 15:54:13

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: smd_user_manager: keep large user bases under control

Bloke wrote:

admi wrote:

Thanks! I didn’t get into which file those code lines go?

Both hunks of code are separate plugins that do different things. Neither have been released as far as I know, they’re just examples of how to do it.

To try it:

  • Install ied_plugin_composer and visit its main panel.
  • Twist down the ‘installation’ sub-panel.
  • Name a plugin and hit Create New Plugin.
  • Paste one of the code blocks into the Code textarea.
  • Make sure you check the Enable checkbox from the Meta area at the top.
  • Save it.

Game on. Though as it says in the comment under the ‘for your eyes only’ code, you’ll probably want to add some code so that Publishers can see all articles / files / images / links. Shout (in a new thread, or on the one linked above) if you need a hand.

You know what I say? It works! But I had to copy and paste both codes. The first code did not change anything but when I added the second one it worked ok. Thanx.

And yes what about the publisher seeing all authors’ articles?

Offline

#86 2013-11-13 16:15:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,568
Website GitHub

Re: smd_user_manager: keep large user bases under control

admi wrote:

The first code did not change anything

It probably did, but it’s subtle. The first plugin is an example of how to remove an entire section’s articles from the Article panel. In that case it removed all articles from the ‘articles’ Section. If you don’t have a section named that, you may not have spotted it doing anything.

The second plugin is the one you want. At the risk of going off-topic, here’s a quick commented breakdown of a slightly modified version:

// Hook the plugin into the admin side in the right place
register_callback('mrd_for_your_eyes_only', 'admin_criteria');

function mrd_for_your_eyes_only($evt, $stp, $crit) {
	// Grab the logged-in user name and make sure it's 'safe' (no weird characters that would break MySQL)
	global $txp_user;
	$user = doSlash($txp_user);

	// Fetch the logged-in user's privilege level
	$privs = safe_field('privs', 'txp_users', "name='$user'");

	// Publishers get to see everything: drop out of the plugin without doing anything
	if ($privs === '1') {
		return;
	}

	// Anyone other than Publisher ends up here
	if ($stp === 'list_list') {
		// We are on the 'articles' page so alter the criteria to only include those articles
		// with AuthorID that matches the logged-in user 
		return " AND AuthorID = '$user'";
	} else if (in_array($stp, array('link_list', 'file_list', 'image_list'))) {
		// We are on the Links, Files or Images panel so only include those items where
		// the author matches the logged-in user
		return " AND author = '$user'";
	}
}

Untested but should do what you want. Also note that mrd_ is Dale’s prefix so if you want to release this or anything, you should probably reserve your own three-letter prefix and change the two places in the code that use mrd_ to your own.

Last edited by Bloke (2013-11-13 16:20:59)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#87 2013-11-13 20:10:04

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: smd_user_manager: keep large user bases under control

// Hook the plugin into the admin side in the right place
register_callback('mrd_for_your_eyes_only', 'admin_criteria');

function mrd_for_your_eyes_only($evt, $stp, $crit) {
	// Grab the logged-in user name and make sure it's 'safe' (no weird characters that would break MySQL)
	global $txp_user;
	$user = doSlash($txp_user);

	// Fetch the logged-in user's privilege level
	$privs = safe_field('privs', 'txp_users', "name='$user'");

	// Publishers get to see everything: drop out of the plugin without doing anything
	if ($privs === '1') {
		return;
	}

	// Anyone other than Publisher ends up here
	if ($stp === 'list_list') {
		// We are on the 'articles' page so alter the criteria to only include those articles
		// with AuthorID that matches the logged-in user 
		return " AND AuthorID = '$user'";
	} else if (in_array($stp, array('link_list', 'file_list', 'image_list'))) {
		// We are on the Links, Files or Images panel so only include those items where
		// the author matches the logged-in user
		return " AND author = '$user'";
	}
}

Untested but should do what you want. Also note that mrd_ is Dale’s prefix so if you want to release this or anything, you should probably reserve your own three-letter prefix and change the two places in the code that use mrd_ to your own.

Cool! Thanx! It works perfectly so far.

Offline

#88 2013-12-29 08:03:48

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,440
Website GitHub Twitter

Re: smd_user_manager: keep large user bases under control

Hi Stef

I use your plugin (0.11) for a website under 4.4.1 (can t upgrad it know because it uses many plugins that i am not sure they all works well under 4.5.x.).

I have got that message (it worked before without problem):


Warning: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay SELECT txu.user_id, txu.name, txu.RealName, txu.email, txu.privs, unix_timestamp(txu.last_access) as last_login, txp.total AS article_count, txi.total AS image_count, txf.total AS file_count, txl.total AS link_count FROM txp_users as txu LEFT JOIN (SELECT AuthorID, count(ID) AS total FROM textpattern GROUP BY AuthorID) AS txp ON txp.AuthorID = txu.name LEFT JOIN (SELECT author, count(id) AS total FROM txp_image GROUP BY author) AS txi ON txi.author = txu.name LEFT JOIN (SELECT author, count(id) AS total FROM txp_file GROUP BY author) AS txf ON txf.author = txu.name LEFT JOIN (SELECT author, count(id) AS total FROM txp_link GROUP BY author) AS txl ON txl.author = txu.name HAVING 1 in /htdocs/public/www/textpattern/lib/txplib_db.php on line 89
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /htdocs/public/www/textpattern/lib/txplib_db.php on line 295
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /htdocs/public/www/textpattern/lib/txplib_db.php on line 297

it seems that the query is too complex! i cant access the mysql conf to try to tweek mysql itself but is ther a qay i can simplify some queries inside the plugin to not look at links and files (line 327 in the plugin code) to try to solve the issue?

Happy new year!

FOUND A SOLUTION

at line 338 right before

$totrs = safe_query('SELECT '.$fields.$clause.' HAVING '.$criteria);

add this line:

$totrs = safe_query('SET SQL_BIG_SELECTS=1');

Last edited by Dragondz (2013-12-29 08:17:02)

Offline

#89 2013-12-29 13:03:00

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: smd_user_manager: keep large user bases under control

Dragondz wrote:

I have got that message (it worked before without problem) … it seems that the query is too complex

Its about number of examined rows when joining. You hit it and got the error seemingly suddenly because of the number of rows in your content tables has increased, causing that select-heavy query to go over the limit.

Offline

#90 2013-12-29 14:15:55

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,440
Website GitHub Twitter

Re: smd_user_manager: keep large user bases under control

Thanks Jukka

that s what i thinked, the right solution would be to increase the max join on mysql but i havent that possibility then i must stick on that query.

Offline

#91 2013-12-29 14:16:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,568
Website GitHub

Re: smd_user_manager: keep large user bases under control

Dragondz wrote #277622:

it seems that the query is too complex!

Yes, it’s a pretty hideous query. Since my current plugin version (0.21) is for 4.5.x only, I wonder if you could try this modified code in your version and report back if it fixes the problem. First of all, take out your SQL_BIG_SELECTS line. Then, delete lines 325 – 331 inclusive (the lines with $fields and $clause defined). In place of those removed lines, put this code instead:

// The fields that make up the real and computed columns
	$fields = 'txu.user_id,
		txu.name,
		txu.RealName,
		txu.email,
		txu.privs,
		unix_timestamp(txu.last_access) as last_login,
		(
			SELECT count(*)
			FROM textpattern
			WHERE AuthorID = txu.name
			GROUP BY AuthorID
		) AS article_count,
		(
			SELECT count(*)
			FROM txp_image
			WHERE author = txu.name
			GROUP BY author
		) AS image_count,
		(
			SELECT count(*)
			FROM txp_file
			WHERE author = txu.name
			GROUP BY author
		) AS file_count,
		(
			SELECT count(*)
			FROM txp_link
			WHERE author = txu.name
			GROUP BY author
		) AS link_count';
	$clause = ' FROM '.PFX.'txp_users as txu';

I’ve not profiled it, but that query will probably be less heavy on the ol’ server as it doesn’t do any JOINs, just a bunch of single-row SubSelects. If you could try that version and report back if it works, I’d be very grateful.

If it works fine, I can actually remove the GROUP BYs as well, but I’ve left them in for the moment because it affects the current searching feature. To put it bluntly I put some hacky crap in the code to detect if you were searching for ‘0’ to get round the fact that my awful SQL returned NULLs. If the above query works, I can remove the GROUP BY which will return true ‘0’ values for any people with no assets to their name and I can then remove the kludge code too, which will make me a much happier chappy.

Thanks in advance for any feedback.

Last edited by Bloke (2013-12-29 14:17:57)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#92 2013-12-31 11:41:59

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,440
Website GitHub Twitter

Re: smd_user_manager: keep large user bases under control

Hi stef thanks for the code correction, i havent seen it till i got your mail, i tryed it and it wotks without error.

Thanks stef and big hat and happy new year.

Offline

#93 2014-07-07 04:06:05

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,467

Re: smd_user_manager: keep large user bases under control

I propose this slightly modified version:

smd_user_manager_v0.21_es-es_textpack.txt

#@smd_um
#@language es-es
smd_um_active => Usuarios actualmente conectados:
smd_um_active_timeout => Desconectar a los usuarios después de (segundos)
smd_um_admin_group => Grupo protegido de administradores
smd_um_article_count => Artículos
smd_um_based_on => basado en
smd_um_chp_lbl => Cambiar contraseña
smd_um_file_count => Ficheros
smd_um_grp_affected => . Usuarios afectados: {num}
smd_um_grp_created => Grupo "{name}" creado
smd_um_grp_deleted => Grupo eliminado
smd_um_grp_exists => El grupo ya existe, su ID de privilegios es {id}
smd_um_grp_lbl => Grupos
smd_um_grp_new => Nuevo nombre de grupo
smd_um_grp_new_name => nombre
smd_um_grp_saved => Información de grupo actualizada
smd_um_heading_grp => Grupos de usuarios
smd_um_heading_prf => Preferencias del gestor de usuarios
smd_um_heading_prv => Privilegios de usuarios
smd_um_heading_usr => Gestión de usuarios
smd_um_hierarchical_groups => Asumir grupos jerárquicos (niveles)
smd_um_image_count => Imágenes
smd_um_link_count => Enlaces
smd_um_max_search_limit => Límite máximo de resultados en búsqueda de usuarios
smd_um_name_required => Se requiere un nombre
smd_um_new_user => Nuevo usuario
smd_um_pass_change_error => Contraseña NO guardada
smd_um_pass_length => Longitud de contraseña (caracteres)
smd_um_prf_lbl => Preferencias
smd_um_prv_created => Área de privilegios "{area}" creada
smd_um_prv_exists => Área de privilegios ya existe
smd_um_prv_lbl => Privilegios
smd_um_prv_new => Nuevo área de privilegios
smd_um_prv_saved => Privilegios actualizados
smd_um_prv_smd_um => Imposible crear privilegios para smd_user_manager
smd_um_reset => [R]
smd_um_self_alter => Permitir cambiar privilegios a smd_um
smd_um_sel_all => Selecciona esta área completa, luego marca (c), desmarca (u) o invierte (t) la selección
smd_um_sel_grp => Selecciona este grupo, luego marca (c), desmarca (u) o invierte (t) la selección
smd_um_sel_prv => Selecciona este área, luego marca (c), desmarca (u) o invierte (t) la selección
smd_um_sel_reset => Reajustar: todas las áreas marcadas volverán a sus valores por defecto después de guardar
smd_um_settings => Preferencias
smd_um_tab_name => Gestor de usuarios
smd_um_tbl_installed => Tablas instaladas
smd_um_tbl_not_installed => Tablas no instaladas
smd_um_tbl_not_removed => Tablas no eliminadas
smd_um_tbl_removed => Tablas eliminadas
smd_um_user_count => Usuarios en este grupo:
smd_um_usr_lbl => Usuarios

Offline

#94 2016-01-09 17:16:22

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,753
Website

Re: smd_user_manager: keep large user bases under control

Subscribed to thread. ;)

Offline

#95 2017-12-02 07:47:58

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,777
Website GitHub Twitter

Re: smd_user_manager: keep large user bases under control

I am trying to change the staff writer privileges by allowing them read/write/edit access to the articles images and files tabs. All works Ok except for files as the upload GUI is not showing. Does anyone have any ideas?


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#96 2017-12-02 08:47:59

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: smd_user_manager: keep large user bases under control

I have trouble mixing smd_user_manager and rah_change_passwords after updating a site to 4.6.2. Nothing appears at backend to change users password under smd_user_manager screen.

Does anybody has experience the same issue? I asked for help at rah_change_passwords thread (and also sent a private to Gocom) but nobody answered : -(

The plugins markup looks sort, so perhaps someone with knowledge can fix it easily for do it operative under 4.6.2


<txp:rocks/>

Offline

Board footer

Powered by FluxBB