diff --git a/plugins/defaultwidgets/actions/update.php b/plugins/defaultwidgets/actions/update.php new file mode 100644 index 0000000000000000000000000000000000000000..53b62f5d1ad5efd762222cd4528e395faf9a2dce --- /dev/null +++ b/plugins/defaultwidgets/actions/update.php @@ -0,0 +1,69 @@ +<?php +/** + + * Elgg default_widgets plugin. + * + * @package DefaultWidgets + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU + * @author Milan Magudia + * @copyright HedgeHogs.net + * @link http://www.hedgehogs.net + * + **/ + + +// validate user is an admin +admin_gatekeeper (); + +// validate action +action_gatekeeper (); + +// get parameters +$context = get_input ( 'context' ); +$leftbar = str_replace('::0', '', get_input ( 'debugField1' )); +$middlebar = str_replace('::0', '', get_input ( 'debugField2' )); +$rightbar = str_replace('::0', '', get_input ( 'debugField3' )); + +// make sure enough parameters are set +if ($context && isset($leftbar) && isset($middlebar) && isset($rightbar)) { + + // join widgets into a single string + $widgets = $leftbar.'%%'.$middlebar.'%%'.$rightbar; + + // get the elgg object that contains our settings + $entities = get_entities ( "object", "moddefaultwidgets", 0, "", 9999 ); + + // create new object unless one already exists + if (! isset ( $entities [0] )) { + $entity = new ElggObject ( ); + $entity->subtype = 'moddefaultwidgets'; + $entity->owner_guid = $_SESSION ['user']->getGUID (); + } else { + $entity = $entities [0]; + } + + // store the default widgets for each context + $entity->$context = $widgets; + + // make sure this object is public. + $entity->access_id = 2; + + // save the object or report error + if ($entity->save ()) { + system_message ( elgg_echo ( 'defaultwidgets:update:success' ) ); + $entity->state = "active"; + forward ( 'pg/admin'); + } else { + register_error ( elgg_echo ( 'defaultwidgets:update:failed' ) ); + forward ( 'pg/defaultwidgets/'.$context ); + } + +} else { + + // report incorrect parameters error + register_error ( elgg_echo ( 'defaultwidgets:update:noparams' ) ); + forward ( 'pg/defaultwidgets/'.$context ); + +} + +?> \ No newline at end of file diff --git a/plugins/defaultwidgets/dashboard.php b/plugins/defaultwidgets/dashboard.php new file mode 100644 index 0000000000000000000000000000000000000000..1fe119257ef56211d663e42e95a98d9b1bc51f54 --- /dev/null +++ b/plugins/defaultwidgets/dashboard.php @@ -0,0 +1,33 @@ +<?php +/** + + * Elgg default_widgets plugin. + * + * @package DefaultWidgets + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU + * @author Milan Magudia + * @copyright HedgeHogs.net + * @link http://www.hedgehogs.net + * + **/ + +require_once (dirname ( dirname ( dirname ( __FILE__ ) ) ) . "/engine/start.php"); + +// make sure only admins can view this +admin_gatekeeper (); +set_context ( 'admin' ); + +// Set admin user for user block +set_page_owner ( $_SESSION ['guid'] ); + +// vars required for action gatekeeper +$ts = time (); +$token = generate_action_token ( $ts ); +$context = 'dashboard'; + +// create the view +$content = elgg_view ( "defaultwidgets/editor", array ('token' => $token, 'ts' => $ts, 'context' => $context) ); + +// Display main admin menu +page_draw ( 'Default dashboard widgets for new users', $content ); +?> \ No newline at end of file diff --git a/plugins/defaultwidgets/editor.php b/plugins/defaultwidgets/editor.php deleted file mode 100644 index 3e4b3184b0e9a339fe448e5b1d29ea54fa4fee70..0000000000000000000000000000000000000000 --- a/plugins/defaultwidgets/editor.php +++ /dev/null @@ -1,276 +0,0 @@ -<?php - - /** - * Elgg default widget layout - * - * @package Elgg - * @subpackage Core - * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 - * @author Curverider Ltd - * @copyright Curverider Ltd 2008 - * @link http://elgg.org/ - * - * Edited version of the widget editor to be used to set default widgets - * @author Milan Magudia - * @copyright HedgeHogs.net - * @link http://www.hedgehogs.net - * - **/ - - // set some defaults - $owner = page_owner_entity(); - $context = $vars['context']; - $area1widgets = false; - $area2widgets = false; - $area3widgets = false; - - // get available widget types - set_context ( $context ); - $widgettypes = get_widget_types(); - set_context ( 'admin' ); - - // get the entities for the module - $entities = get_entities("object", "moddefaultwidgets", 0, "", 9999); - - // check if the entity exists - if(isset($entities[0])) { - - // get the widgets for the context - $entity = $entities[0]; - $current_widgets = $entity->$context; - list($left, $middle, $right) = split('%%',$current_widgets); - - // split columns into seperate widgets - $area1widgets = split('::',$left); - $area2widgets = split('::',$middle); - $area3widgets = split('::',$right); - - // clear out variables if no widgets are available - if ($area1widgets[0] == "") $area1widgets = false; - if ($area2widgets[0] == "") $area2widgets = false; - if ($area3widgets[0] == "") $area3widgets = false; - } - -?> -<script type="text/javascript"> -$(document).ready(function () { - $('div#customise_editpanel').slideToggle("fast"); -}); -</script> - -<div id="customise_editpanel" style="visibility:visible;"> - -<div id="customise_editpanel_rhs"> -<h2><?php echo elgg_echo("widgets:gallery"); ?></h2> -<div id="widget_picker_gallery"> - - -<?php - - foreach($widgettypes as $handler => $widget) { - -?> - -<table class="draggable_widget" cellspacing="0"><tr><td> - <h3> - <?php echo $widget->name; ?> - <input type="hidden" name="multiple" value="<?php if ((isset($widget->handler)) && (isset($widgettypes[$widget->handler]->multiple))) echo $widgettypes[$widget->handler]->multiple; ?>" /> - <input type="hidden" name="side" value="<?php if ((isset($widget->handler)) && (isset($widgettypes[$widget->handler])) && (is_array($widgettypes[$widget->handler]->positions))) echo in_array('side',$widgettypes[$widget->handler]->positions); ?>" /> - <input type="hidden" name="main" value="<?php if ((isset($widget->handler)) && (isset($widgettypes[$widget->handler])) && (is_array($widgettypes[$widget->handler]->positions))) echo in_array('main',$widgettypes[$widget->handler]->positions); ?>" /> - <input type="hidden" name="handler" value="<?php echo htmlentities($handler); ?>" /> - <input type="hidden" name="description" value="<?php echo htmlentities($widget->description, null, 'UTF-8'); ?>" /> - <input type="hidden" name="guid" value="0" /> - </h3> -</td> -<td width="17px" align="right"></td> -<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="14px" height="14px" class="more_info" /></a></td> -<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="15px" height="15px" class="drag_handle" /></a></td> -</tr></table> - -<?php - } -?> - -<br /><!-- bit of space at the bottom of the widget gallery --> - -</div><!-- /#customise_editpanel_rhs --> -</div><!-- /#widget_picker_gallery --> - - -<div class="customise_editpanel_instructions"> -<h2><?php echo elgg_echo('defaultwidgets:'.$context.':title'); ?></h2> -<?php echo autop(elgg_echo('widgets:add:description')); ?> -</div> - - -<div id="customise_page_view"> - -<table cellspacing="0"> - <tr> - <td colspan="2" align="left" valign="top"> - - <?php - if(get_context() == "profile"){ - ?> - <h2 class="profile_box"><?php echo elgg_echo("widgets:profilebox"); ?></h2> - <div id="profile_box_widgets"> - <p><small><?php echo elgg_echo('widgets:position:fixed'); ?></small></p> - </div> - <?php - } - ?> - - </td> - - - <td rowspan="2" align="left" valign="top"> - <h2><?php echo elgg_echo("widgets:rightcolumn"); ?></h2> - <div id="rightcolumn_widgets" <?php if(get_context() == "profile")echo "class=\"long\""; ?>> - <?php - $rightcolumn_widgets = ""; - if (is_array($area3widgets) && sizeof($area3widgets) > 0) { - foreach($area3widgets as $widget) { - if (!empty($rightcolumn_widgets)) { - $rightcolumn_widgets .= "::"; - } - $rightcolumn_widgets .= "{$widget}::0"; - ?> - - <table class="draggable_widget" cellspacing="0"><tr><td width="149px"> - <h3> - <?php echo $widgettypes[$widget]->name; ?> - <input type="hidden" name="handler" value="<?php - echo $widget; - ?>" /> - <input type="hidden" name="multiple" value="<?php echo $widgettypes[$widget]->multiple; ?>" /> - <input type="hidden" name="side" value="<?php echo in_array('side',$widgettypes[$widget]->positions); ?>" /> - <input type="hidden" name="main" value="<?php echo in_array('main',$widgettypes[$widget]->positions); ?>" /> - <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget]->description); ?>" /> - <input type="hidden" name="guid" value="0" /> - </h3> - </td> - <td width="17px" align="right"></td> - <td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="14px" height="14px" class="more_info" /></a></td> - <td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="15px" height="15px" class="drag_handle" /></a></td> - </tr></table> - - <?php - - } - } - ?> - - </div> - </td><!-- /rightcolumn td --> - - </tr> - - <tr> - -<td> -<h2><?php echo elgg_echo("widgets:leftcolumn"); ?></h2> -<div id="leftcolumn_widgets"> - -<?php - $leftcolumn_widgets = ""; - if (is_array($area1widgets) && sizeof($area1widgets) > 0) { - foreach($area1widgets as $widget) { - if (!empty($leftcolumn_widgets)) { - $leftcolumn_widgets .= "::"; - } - $leftcolumn_widgets .= "{$widget}::0"; -?> - -<table class="draggable_widget" cellspacing="0"><tr><td width="149px"> - <h3> - <?php echo $widgettypes[$widget]->name; ?> - <input type="hidden" name="handler" value="<?php - echo $widget; - ?>" /> - <input type="hidden" name="multiple" value="<?php echo $widgettypes[$widget]->multiple; ?>" /> - <input type="hidden" name="side" value="<?php echo in_array('side',$widgettypes[$widget]->positions); ?>" /> - <input type="hidden" name="main" value="<?php echo in_array('main',$widgettypes[$widget]->positions); ?>" /> - <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget]->description); ?>" /> - <input type="hidden" name="guid" value="0" /> - </h3> -</td> -<td width="17px" align="right"></td> -<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="14px" height="14px" class="more_info" /></a></td> -<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="15px" height="15px" class="drag_handle" /></a></td> -</tr></table> - -<?php - - } - } -?> -</div> -</td> - -<td> - -<h2><?php echo elgg_echo("widgets:middlecolumn"); ?></h2> -<div id="middlecolumn_widgets"> - -<?php - $middlecolumn_widgets = ""; - if (is_array($area2widgets) && sizeof($area2widgets) > 0) { - foreach($area2widgets as $widget) { - if (!empty($middlecolumn_widgets)) { - $middlecolumn_widgets .= "::"; - } - $middlecolumn_widgets .= "{$widget}::0"; -?> - -<table class="draggable_widget" cellspacing="0"><tr><td width="149px"> - <h3> - <?php echo $widgettypes[$widget]->name; ?> - <input type="hidden" name="handler" value="<?php - echo $widget; - ?>" /> - <input type="hidden" name="multiple" value="<?php echo $widgettypes[$widget]->multiple; ?>" /> - <input type="hidden" name="side" value="<?php echo in_array('side',$widgettypes[$widget]->positions); ?>" /> - <input type="hidden" name="main" value="<?php echo in_array('main',$widgettypes[$widget]->positions); ?>" /> - <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget]->description); ?>" /> - <input type="hidden" name="guid" value="0" /> - </h3> -</td> -<td width="17px" align="right"></td> -<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="14px" height="14px" class="more_info" /></a></td> -<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/spacer.gif" width="15px" height="15px" class="drag_handle" /></a></td> -</tr></table> - -<?php - - } - } -?> - -</div> -</td> - - - - - - -</tr> -</table> - -</div><!-- /#customise_page_view --> - -<form action="<?php echo $vars['url']; ?>action/defaultwidgets/update" method="post"> -<textarea type="textarea" value="Left widgets" style="display:none" name="debugField1" id="debugField1" /><?php echo $leftcolumn_widgets; ?></textarea> -<textarea type="textarea" value="Middle widgets" style="display:none" name="debugField2" id="debugField2" /><?php echo $middlecolumn_widgets; ?></textarea> -<textarea type="textarea" value="Right widgets" style="display:none" name="debugField3" id="debugField3" /><?php echo $rightcolumn_widgets; ?></textarea> -<?php - echo elgg_view('input/hidden',array('internalname' => '__elgg_token', 'value' => $vars['token'])); - echo elgg_view('input/hidden',array('internalname' => '__elgg_ts', 'value' => $vars['ts'])); -?> -<input type="hidden" name="context" value="<?php echo $context; ?>" /> -<input type="hidden" name="owner" value="<?php echo page_owner(); ?>" /> -<input type="submit" value="<?php echo elgg_echo('save'); ?>" class="submit_button" /> - -</form> -</div><!-- /customise_editpanel --> - diff --git a/plugins/defaultwidgets/languages/en.php b/plugins/defaultwidgets/languages/en.php new file mode 100644 index 0000000000000000000000000000000000000000..cd66cc452034e7d56c7bb57f85ef96e101c71d81 --- /dev/null +++ b/plugins/defaultwidgets/languages/en.php @@ -0,0 +1,27 @@ +<?php + +$english = array ( + + 'item:object:moddefaultwidgets' => 'DefaultWidgets settings', + + /** + * Menu items + */ + 'defaultwidgets:menu:profile' => 'Default profile widgets', + 'defaultwidgets:menu:dashboard' => 'Default dashboard widgets', + + 'defaultwidgets:admin:error' => 'Error: You are not logged in as an administrator', + 'defaultwidgets:admin:notfound' => 'Error: Page not found', + 'defaultwidgets:admin:loginfailure' => 'Warning: You are not currently logged is as an administrator', + + 'defaultwidgets:update:success' => 'Your widget settings have been saved', + 'defaultwidgets:update:failed' => 'Error: settings have not been saved', + 'defaultwidgets:update:noparams' => 'Error: incorrect form parameters', + + 'defaultwidgets:profile:title' => 'Set default widgets for new user profile pages', + 'defaultwidgets:dashboard:title' => 'Set default widgets for new user dashboard pages', +); + +add_translation ( "en", $english ); + +?> \ No newline at end of file diff --git a/plugins/defaultwidgets/manifest.xml b/plugins/defaultwidgets/manifest.xml new file mode 100644 index 0000000000000000000000000000000000000000..93114345c08ee964b0d500a8e04a13e6164b5d98 --- /dev/null +++ b/plugins/defaultwidgets/manifest.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest> + <field key="author" value="Milan Magudia" /> + <field key="version" value="2.02" /> + <field key="description" value="This plugin enables an administrator to define a default set of widgets for new users" /> + <field key="website" value="http://www.hedgehogs.net" /> + <field key="copyright" value="HedgeHogs" /> +</plugin_manifest> diff --git a/plugins/defaultwidgets/profile.php b/plugins/defaultwidgets/profile.php new file mode 100644 index 0000000000000000000000000000000000000000..2eb2c25762f03867578b41da58da7d4238c48247 --- /dev/null +++ b/plugins/defaultwidgets/profile.php @@ -0,0 +1,33 @@ +<?php +/** + + * Elgg default_widgets plugin. + * + * @package DefaultWidgets + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU + * @author Milan Magudia + * @copyright HedgeHogs.net + * @link http://www.hedgehogs.net + * + **/ + +require_once (dirname ( dirname ( dirname ( __FILE__ ) ) ) . "/engine/start.php"); + +// make sure only admins can view this +admin_gatekeeper (); +set_context ( 'admin' ); + +// Set admin user for user block +set_page_owner ( $_SESSION ['guid'] ); + +// vars required for action gatekeeper +$ts = time (); +$token = generate_action_token ( $ts ); +$context = 'profile'; + +// create the view +$content = elgg_view ( "defaultwidgets/editor", array ('token' => $token, 'ts' => $ts, 'context' => $context) ); + +// Display main admin menu +page_draw ( 'Default profile widgets for new users', $content ); +?> \ No newline at end of file diff --git a/plugins/defaultwidgets/start.php b/plugins/defaultwidgets/start.php new file mode 100644 index 0000000000000000000000000000000000000000..eda32208d47d9e1adaa5aecbb0173ae91e61f216 --- /dev/null +++ b/plugins/defaultwidgets/start.php @@ -0,0 +1,152 @@ +<?php +/** + + * Elgg default_widgets plugin. + * + * @package DefaultWidgets + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU + * @author Milan Magudia + * @copyright HedgeHogs.net + * @link http://www.hedgehogs.net + * + * Code based on the work of: + * @author Jade Dominguez, Chad Sowald + * @copyright tastyseed, 2008 + * @copyright Chad Sowald, 2008 + * @link http://www.tastyseed.com + * @link http://www.chadsowald.com + * @author Diego Ramirez + * @links http://www.somosmas.org + * + */ + +global $CONFIG; + +function defaultwidgets_init() { + + // Load system configuration + register_page_handler ( 'defaultwidgets', 'defaultwidgets_page_handler' ); + + // register create user event hook + register_elgg_event_handler ( 'create', 'user', 'defaultwidgets_newusers' ); + +} + +function defaultwidgets_newusers($event, $object_type, $object) { + + $guid = $object->guid; + + // if an admin creates a user we need to store their credentials so they so they can be logged back + if (isadminloggedin ()) { + $user_orig = $_SESSION ['user']; + } else { + $user_orig = false; + } + + /* + the add_widgets function only executes if the user has permissions to add widgets to his profile/dashboard. + Since there is no user yet logged in, we need to artificially login the new user + */ + $log_user_in = login ( $object ); + + if ($log_user_in) { + + if (! empty ( $guid )) { + if ($user = get_entity ( $guid )) { + if ($user->canEdit ()) { + $contexts = array ('profile', 'dashboard' ); + + // get the entities for the module + $entities = get_entities ( "object", "moddefaultwidgets", 0, "", 9999 ); + + // check if the entity exists + if (isset ( $entities [0] )) { + + // get the widgets for the context + $entity = $entities [0]; + + foreach ( $contexts as $context ) { + $current_widgets = $entity->$context; + list ( $left, $middle, $right ) = split ( '%%', $current_widgets ); + + // split columns into seperate widgets + $area1widgets = split ( '::', $left ); + $area2widgets = split ( '::', $middle ); + $area3widgets = split ( '::', $right ); + + // clear out variables if no widgets are available + if ($area1widgets [0] == "") $area1widgets = false; + if ($area2widgets [0] == "") $area2widgets = false; + if ($area3widgets [0] == "") $area3widgets = false; + + // generate left column widgets for a new user + foreach ( $area1widgets as $i => $widget ) { + //if (is_plugin_enabled($widget)) { + add_widget ( $guid, $widget, $context, ($i + 1), 1 ); + //} + } + + // generate middle column widgets for a new user + foreach ( $area2widgets as $i => $widget ) { + //if (is_plugin_enabled($widget)) { + add_widget ( $guid, $widget, $context, ($i + 1), 2 ); + //} + } + + // generate right column widgets for a new user + foreach ( $area3widgets as $i => $widget ) { + //if (is_plugin_enabled($widget)) { + add_widget ( $guid, $widget, $context, ($i + 1), 3 ); + //} + } + } + } + } + } + } + } + + // if an admin created this user, log the new user out, log the admin back in + if (! empty ( $user_orig )) { + if(! login ( $user_orig )) { + // if there something goes wrong with logging back in then warn the administrator + register_error(elgg_echo('defaultwidgets:admin:loginfailure')); + } + } +} + +// simple page handler +function defaultwidgets_page_handler($page) { + global $CONFIG; + + if (isset ( $page [0] )) { + + switch ($page [0]) { + case "profile" : + @include (dirname ( __FILE__ ) . "/profile.php"); + break; + case "dashboard" : + @include (dirname ( __FILE__ ) . "/dashboard.php"); + break; + } + } else { + register_error ( elgg_echo ( "defaultwidgets:admin:notfound" ) ); + forward ( $CONFIG->wwwroot ); + } + return true; +} + +// function to add a submenu to the admin panel. +function defaultwidgets_pagesetup() { + if (get_context () == 'admin' && isadminloggedin ()) { + global $CONFIG; + add_submenu_item ( elgg_echo ( 'defaultwidgets:menu:profile' ), $CONFIG->wwwroot . 'pg/defaultwidgets/profile' ); + add_submenu_item ( elgg_echo ( 'defaultwidgets:menu:dashboard' ), $CONFIG->wwwroot . 'pg/defaultwidgets/dashboard' ); + } +} + +// Make sure the status initialisation function is called on initialisation +register_elgg_event_handler ( 'init', 'system', 'defaultwidgets_init' ); +register_elgg_event_handler ( 'pagesetup', 'system', 'defaultwidgets_pagesetup' ); +register_action ( "defaultwidgets/update", false, $CONFIG->pluginspath . "defaultwidgets/actions/update.php" ); +?>