Recent Topics

1 Feb 22, 2009 23:55    

The "quick publish" and "quick deprecate" features (v2.4.6) do not talk to plugins prior to publishing or deprecating a post. So two new hooks would be really nice.

In /inc/items/items.ctrl.php modify the 'publish' case for the $action switch:

		$post_date = date('Y-m-d H:i:s', $localtimenow);
		$edited_Item->set( 'datestart', $post_date );
		$edited_Item->set( 'datemodified', $post_date );

		$Plugins->trigger_event( 'AdminBeforeItemPublishNow', array( 'Item' => & $edited_Item ) );

		if( $Messages->count('error') )
		{	// There have been some validation errors:
			// Params we need for tab switching:
			$tab_switch_params = 'p='.$post_ID;
			break;
		}

		// UPDATE POST IN DB:
		$edited_Item->dbupdate();


In the same file modify the 'deprecate' case:

		$edited_Item->set( 'status', $post_status );
		$edited_Item->set( 'datemodified', date('Y-m-d H:i:s',$localtimenow) );

		$Plugins->trigger_event( 'AdminBeforeItemDeprecateNow', array( 'Item' => & $edited_Item ) );

		if( $Messages->count('error') )
		{	// There have been some validation errors:
			// Params we need for tab switching:
			$tab_switch_params = 'p='.$post_ID;
			break;
		}

		// UPDATE POST IN DB:
		$edited_Item->dbupdate();

In /inc/plugins/_plugin.class.php after

	function AdminBeforeItemEditUpdate( & $params )
	{
	}

Add two new functions:

	/**
	 * Event handler: This gets called before an existing item gets published using the quick-publish feature.
	 *
	 * You could {@link Plugin::msg() add a message} of
	 * category "error" here, to prevent the post from being published.
	 *
	 * @param array Associative array of parameters
	 *              'Item': the Item which gets updated (by reference)
	 */
	function AdminBeforeItemPublishNow( & $params )
	{
	}


	/**
	 * Event handler: This gets called before an existing item gets deprecated using the quick-deprecate feature.
	 *
	 * You could {@link Plugin::msg() add a message} of
	 * category "error" here, to prevent the post from being deprecated.
	 *
	 * @param array Associative array of parameters
	 *              'Item': the Item which gets updated (by reference)
	 */
	function AdminBeforeItemDeprecateNow( & $params )
	{
	}

In /inc/plugins/model/_plugins_admin.class.php add two lines to feed the back office text:

				'AdminBeforeItemPublishNow' => 'This gets called before an existing item gets published using the quick-publish feature.',
				'AdminBeforeItemDeprecateNow' => 'This gets called before an existing item gets deprecated using the quick-deprecate feature.',

Untested but I'm pretty sure it'll work. I'll be testing eventually but I gotta go do that thing I do even though I don't want to but they give me money and I like living indoors and eating food someone else didn't throw out. Oh yeah: work. They call it "work".


Form is loading...