diff options
Diffstat (limited to 'mod/sitepages')
-rw-r--r-- | mod/sitepages/actions/addfront.php | 9 | ||||
-rw-r--r-- | mod/sitepages/actions/addmeta.php | 4 | ||||
-rw-r--r-- | mod/sitepages/languages/en.php | 34 | ||||
-rw-r--r-- | mod/sitepages/sitepages_functions.php | 107 | ||||
-rw-r--r-- | mod/sitepages/start.php | 37 | ||||
-rw-r--r-- | mod/sitepages/views/default/settings/sitepages/edit.php | 12 | ||||
-rw-r--r-- | mod/sitepages/views/default/sitepages/custom_frontpage.php | 10 | ||||
-rw-r--r-- | mod/sitepages/views/default/sitepages/footer_menu.php | 10 | ||||
-rw-r--r-- | mod/sitepages/views/default/sitepages/forms/editfront.php | 25 | ||||
-rw-r--r-- | mod/sitepages/views/default/sitepages/forms/editmeta.php | 2 | ||||
-rw-r--r-- | mod/sitepages/views/default/sitepages/keywords.php | 3 | ||||
-rw-r--r-- | mod/sitepages/views/default/sitepages/metatags.php | 12 |
12 files changed, 230 insertions, 35 deletions
diff --git a/mod/sitepages/actions/addfront.php b/mod/sitepages/actions/addfront.php index 6b8782da7..fd2154cc3 100644 --- a/mod/sitepages/actions/addfront.php +++ b/mod/sitepages/actions/addfront.php @@ -12,7 +12,9 @@ admin_gatekeeper(); -$content = get_input('sitepages_content', '', FALSE); +$logged_in_content = get_input('logged_in_content', '', FALSE); +$logged_out_content = get_input('logged_out_content', '', FALSE); + $css = get_input('css', '', FALSE); $loggedin_user_guid = get_loggedin_userid(); @@ -25,8 +27,9 @@ if (!$sitepage = sitepages_get_sitepage_object('front')) { $sitepage = sitepages_create_sitepage_object('front'); } -$sitepage->title = $css; -$sitepage->description = $content; +$sitepage->css = $css; +$sitepage->logged_in_content = $logged_in_content; +$sitepage->logged_out_content = $logged_out_content; if ($sitepage->save()) { system_message(elgg_echo("sitepages:posted")); diff --git a/mod/sitepages/actions/addmeta.php b/mod/sitepages/actions/addmeta.php index e9f40cdb4..e5c947776 100644 --- a/mod/sitepages/actions/addmeta.php +++ b/mod/sitepages/actions/addmeta.php @@ -19,8 +19,8 @@ $metatags = get_input('metatags', '', FALSE); $_SESSION['description'] = $description;
$_SESSION['metatags'] = $metatags;
-if (!$sitepage = sitepages_get_sitepage_object('front')) {
- $sitepage = sitepages_create_sitepage_object('front');
+if (!$sitepage = sitepages_get_sitepage_object('seo')) {
+ $sitepage = sitepages_create_sitepage_object('seo');
}
$sitepage->title = $metatags;
diff --git a/mod/sitepages/languages/en.php b/mod/sitepages/languages/en.php index ec08493c9..92cddb949 100644 --- a/mod/sitepages/languages/en.php +++ b/mod/sitepages/languages/en.php @@ -29,7 +29,8 @@ $english = array( 'sitepages:metadescription' => "Meta description for search engines", 'sitepages:metatags' => "Meta tags for search engines (use a comma)", 'sitepages:seocreated' => "Your search engine information has been added", - 'sitepages:front_content' => "Frontpage content", + 'sitepages:logged_in_front_content' => "Logged in front page content", + 'sitepages:logged_out_front_content' => "Logged out front page content", 'sitepages:ownfront' => "Construct your own frontpage for this network. (Note:you will need to know html and css)", 'sitepages:addcontent' => "You can add content here via your admin tools. Look for the external pages link under admin.", 'item:object:front' => 'Front page items', @@ -45,6 +46,37 @@ $english = array( */ 'sitepages:deleteerror' => "There was a problem deleting the old page", 'sitepages:error' => "There has been an error, please try again and if the problem persists, contact the administrator", + + /** + * Key words + */ + 'sitepages:keywords_title' => 'Keywords', + 'sitepages:keywords_instructions' => + 'Keywords are replaced with content when viewed. They must be surrounded by + two square brackets ([[ and ]]). You can build your own or use the ones listed below. + Hover over a keyword to read its description.', + + 'sitepages:keywords_instructions_more' => + ' + You can build your own keywords for views and entities.<br /><br /> + + [[entity: type=type, subtype=subtype, owner=username, limit=number]]<br /> + + EX: To show 5 blog posts by admin:<br /> + [[entity: type=object, subtype=blog, owner=admin, limit=5]] + + <br /><br /> + + You can also specify a valid Elgg view:<br /> + [[view: elgg_view, name=value]]<br /> + + Ex: To show a text input with a default value:<br /> + [[view: input/text, value=This is a default value]] + + <br /><br />', + + 'sitepages:keywords:login_box' => 'A standard login box. Useful for the logged out content area.', + 'sitepages:keywords:site_stats' => 'This does not exist yet.', ); add_translation('en', $english);
\ No newline at end of file diff --git a/mod/sitepages/sitepages_functions.php b/mod/sitepages/sitepages_functions.php index 7ffe8df63..0341b590b 100644 --- a/mod/sitepages/sitepages_functions.php +++ b/mod/sitepages/sitepages_functions.php @@ -10,10 +10,6 @@ */
-function sitepages_parse_frontpage($contents){
- echo htmlspecialchars_decode($contents, ENT_NOQUOTES);
-}
-
/**
* Returns a single object that holds information about
* customizations for the $section site page. The object guid
@@ -115,6 +111,109 @@ function sitepages_get_page_content($page_type) { return $content;
}
+
+/**
+ * Used to determine how to handle special non-static keywords.
+ *
+ * @param unknown_type $matches
+ * @return html
+ */
+function sitepages_parse_view_match($matches) {
+ $keyword = $matches[0];
+ $type = trim($matches[1]);
+ $params_string = trim($matches[2]);
+
+ switch ($type) {
+ case 'entity':
+ $options = sitepages_keywords_parse_entity_params($params_string);
+ // must use this lower-level function because I missed refactoring
+ // the list entity functions for relationships.
+ // (which, since you're here, is the only function that runs through all
+ // possible options for elgg_get_entities*() functions...)
+ $entities = elgg_get_entities_from_relationship($options);
+ $content = elgg_view_entity_list($entities, count($entities), $options['offset'],
+ $options['limit'], $options['full_view'], $options['view_type_toggle'], $options['pagination']);
+ break;
+
+ case 'view':
+ // parses this into an acceptable array for $vars.
+ $info = sitepages_keywords_parse_view_params($params_string);
+ $content = elgg_view($info['view'], $info['vars']);
+
+ break;
+
+ }
+
+ return $content;
+}
+
+/**
+ * Creates an array from a "name=value, name1=value2" string.
+ *
+ * @param $string
+ * @return array
+ */
+function sitepages_keywords_tokenize_params($string) {
+ $pairs = array_map('trim', explode(',', $string));
+
+ $params = array();
+
+ foreach ($pairs as $pair) {
+ list($name, $value) = explode('=', $pair);
+
+ $name = trim($name);
+ $value = trim($value);
+ $params[$name] = $value;
+ }
+
+ return $params;
+}
+
+/**
+ *
+ * @param $string
+ * @return unknown_type
+ */
+function sitepages_keywords_parse_view_params($string) {
+ $vars = sitepages_keywords_tokenize_params($string);
+
+ // the first element key is the view
+ $var_keys = array_keys($vars);
+ $view = $var_keys[0];
+
+ $info = array(
+ 'view' => $view,
+ 'vars' => $vars
+ );
+
+ return $info;
+
+}
+
+/**
+ * Returns an options array suitable for using in elgg_get_entities()
+ *
+ * @param string $string "name=value, name2=value2"
+ * @return array
+ */
+function sitepages_keywords_parse_entity_params($string) {
+ $params = sitepages_keywords_tokenize_params($string);
+
+ // handle some special cases
+ if (isset($params['owner'])) {
+ if ($user = get_user_by_username($params['owner'])) {
+ $options['owner_guid'] = $user->getGUID();
+ }
+ }
+
+ // @todo probably need to add more for
+ // group -> container_guid, etc
+
+ return $params;
+}
+
+
+
/**
* Utility object to store site page information.
*/
diff --git a/mod/sitepages/start.php b/mod/sitepages/start.php index 186738bab..5be36842a 100644 --- a/mod/sitepages/start.php +++ b/mod/sitepages/start.php @@ -11,8 +11,16 @@ * @copyright Curverider Ltd 2008-2010 * @link http://elgg.org/ * - * @todo Implement sticky pages - * @todo DRY up actions and views + * @todo + * Check for SQL injection problems. + * Make sure this stuff doesn't show up in search. + * Check entity keyword views against fullview. Force to FALSE? + * DRY up actions and views + * Implement sticky forms + * Use $entity->view to redirect to url of page. + * The tool settings view is probably not needed as it can be added to the front page edit tab. + * You can say pg/sitepages/edit|read/any_page_i_want and it will let you. + * Clean up and probably move the docs for keywords. */ /** @@ -93,6 +101,8 @@ function sitepages_custom_index() { } set_context($context); + + // return NULL to pass this to next in chain, or back to standard index.php. return NULL; } @@ -161,12 +171,24 @@ function sitepages_page_handler($page) { page_draw($title, $content); } - +/** + * Parses a registered view for supported keywords. + * + * @param unknown_type $hook + * @param unknown_type $entity_type + * @param unknown_type $return_value + * @param unknown_type $params + * @return string + */ function sitepages_parse_view($hook, $entity_type, $return_value, $params) { global $CONFIG; + // give me everything that is (string):(any thing that's not a ]) surrounded by [[ ]]s + $keyword_regex = '/\[\[([a-z]+):([^\]]+)\]\]/'; + if (in_array($params['view'], $CONFIG->sitepages_parse_views)) { $keywords = $CONFIG->sitepages_keywords; + $view_options = array( 'view' => $params['view'] ); @@ -176,11 +198,17 @@ function sitepages_parse_view($hook, $entity_type, $return_value, $params) { $return_value = str_replace("[[$keyword]]", $content, $return_value); } } + + // parse for specialized tags: + // [[entity: key=value, key=value,etc]] + // [[view:viewname, vars_key=value,...]] + $return_value = preg_replace_callback($keyword_regex, 'sitepages_parse_view_match', $return_value); } return $return_value; } + /** * Register some default keywords. * @@ -191,7 +219,6 @@ function sitepages_parse_view($hook, $entity_type, $return_value, $params) { * @return unknown_type */ function sitepages_keyword_hook($hook, $entity_type, $return_value, $params) { - $return_value['login_box'] = array( 'view' => 'account/forms/login', 'description' => elgg_echo('sitepages:keywords:login_box') @@ -205,7 +232,5 @@ function sitepages_keyword_hook($hook, $entity_type, $return_value, $params) { return $return_value; } - - register_elgg_event_handler('init', 'system', 'sitepages_init'); register_elgg_event_handler('pagesetup', 'system', 'sitepages_pagesetup');
\ No newline at end of file diff --git a/mod/sitepages/views/default/settings/sitepages/edit.php b/mod/sitepages/views/default/settings/sitepages/edit.php index 22f03abaf..9705aaae5 100644 --- a/mod/sitepages/views/default/settings/sitepages/edit.php +++ b/mod/sitepages/views/default/settings/sitepages/edit.php @@ -1,3 +1,15 @@ +<?php
+/**
+ * Settings Site Pages
+ *
+ * @package SitePages
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2010
+ * @link http://elgg.org/
+ */
+?>
+
<p>
<?php echo elgg_echo('sitepages:ownfront'); ?>
<select name="params[ownfrontpage]">
diff --git a/mod/sitepages/views/default/sitepages/custom_frontpage.php b/mod/sitepages/views/default/sitepages/custom_frontpage.php index fb0b673cc..429478280 100644 --- a/mod/sitepages/views/default/sitepages/custom_frontpage.php +++ b/mod/sitepages/views/default/sitepages/custom_frontpage.php @@ -10,8 +10,12 @@ * @link http://elgg.org/ */ -$object = sitepages_get_sitepage_object('front'); +$sitepage = sitepages_get_sitepage_object('front'); -if ($object) { - echo $object->description; +if ($sitepage) { + if (get_loggedin_userid()) { + echo $sitepage->logged_in_content; + } else { + echo $sitepage->logged_out_content; + } }
\ No newline at end of file diff --git a/mod/sitepages/views/default/sitepages/footer_menu.php b/mod/sitepages/views/default/sitepages/footer_menu.php index 5137e0f21..d0addd3e1 100644 --- a/mod/sitepages/views/default/sitepages/footer_menu.php +++ b/mod/sitepages/views/default/sitepages/footer_menu.php @@ -1,10 +1,16 @@ <?php /** - * Elgg External pages footer menu + * Footer view to add links to the semi-static pages. + * + * @package SitePages + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.org/ */ ?> -<div class="footer_toolbar_links">| +<div class="footer_toolbar_links">| <a href="<?php echo $vars['url']; ?>pg/sitepages/read/About/"><?php echo elgg_echo('sitepages:about'); ?></a> | <a href="<?php echo $vars['url']; ?>pg/sitepages/read/Terms/"><?php echo elgg_echo('sitepages:terms'); ?></a> | <a href="<?php echo $vars['url']; ?>pg/sitepages/read/Privacy/"><?php echo elgg_echo('sitepages:privacy'); ?></a> | diff --git a/mod/sitepages/views/default/sitepages/forms/editfront.php b/mod/sitepages/views/default/sitepages/forms/editfront.php index cc09b8cc8..e13f16f6e 100644 --- a/mod/sitepages/views/default/sitepages/forms/editfront.php +++ b/mod/sitepages/views/default/sitepages/forms/editfront.php @@ -12,21 +12,23 @@ $action = 'sitepages/addfront'; if ($sitepages_object = sitepages_get_sitepage_object('front')) { - $css = $sitepages_object->title; - $sitepages_content = $sitepages_object->description; - $guid = $sitepages_object->guid; + $css = $sitepages_object->css; + $logged_in_content = $sitepages_object->logged_in_content; + $logged_out_content = $sitepages_object->logged_out_content; } else { $css = ''; - $sitepages_content = ''; - $guid = ''; + $logged_in_content = ''; + $logged_out_content = ''; } // set the required form variables $input_css = elgg_view('input/plaintext', array('internalname' => 'css', 'value' => $css)); -$input_sitepages_content = elgg_view('input/plaintext', array('internalname' => 'sitepages_content', 'value' => $sitepages_content)); +$input_logged_in_content = elgg_view('input/plaintext', array('internalname' => 'logged_in_content', 'value' => $logged_in_content )); +$input_logged_out_content = elgg_view('input/plaintext', array('internalname' => 'logged_out_content', 'value' => $logged_out_content )); $submit_input = elgg_view('input/submit', array('internalname' => 'submit', 'value' => elgg_echo('save'))); -$pageshell_title = elgg_echo("sitepages:front_content"); +$logged_in_content_title = elgg_echo("sitepages:logged_in_front_content"); +$logged_out_content_title = elgg_echo("sitepages:logged_out_front_content"); $css_title = elgg_echo("sitepages:css"); //preview link @@ -38,8 +40,13 @@ $form_body = <<<___EOT <h3 class='settings'>$css_title</h3> <p class='longtext_editarea'>$input_css</p><br /> - <h3 class='settings'>$pageshell_title</h3> - <p class='longtext_editarea'>$input_sitepages_content</p> + + + <h3 class='settings'>$logged_in_content_title</h3> + <p class='longtext_editarea'>$input_logged_in_content</p><br /> + + <h3 class='settings'>$logged_out_content_title</h3> + <p class='longtext_editarea'>$input_logged_out_content</p> $hidden_guid <br /> diff --git a/mod/sitepages/views/default/sitepages/forms/editmeta.php b/mod/sitepages/views/default/sitepages/forms/editmeta.php index d94f32114..84a8297fc 100644 --- a/mod/sitepages/views/default/sitepages/forms/editmeta.php +++ b/mod/sitepages/views/default/sitepages/forms/editmeta.php @@ -19,7 +19,7 @@ if ($sitepages_object = sitepages_get_sitepage_object('front')) { $meta_description = '';
}
-$input_keywords = elgg_view('input/plaintext', array('internalname' => 'metatags', 'value' => $meta_tags));
+$input_keywords = elgg_view('input/text', array('internalname' => 'metatags', 'value' => $meta_tags));
$input_description = elgg_view('input/plaintext', array('internalname' => 'description', 'value' => $meta_description));
$submit_input = elgg_view('input/submit', array('internalname' => 'submit', 'value' => elgg_echo('save')));
diff --git a/mod/sitepages/views/default/sitepages/keywords.php b/mod/sitepages/views/default/sitepages/keywords.php index e5348678a..d46efb5bc 100644 --- a/mod/sitepages/views/default/sitepages/keywords.php +++ b/mod/sitepages/views/default/sitepages/keywords.php @@ -12,6 +12,7 @@ $keywords = $vars['config']->sitepages_keywords;
$title = elgg_echo('sitepages:keywords_title');
$instructions = elgg_echo('sitepages:keywords_instructions');
+$more_info = elgg_echo('sitepages:keywords_instructions_more');
$keywords_html = '';
foreach ($keywords as $keyword => $info) {
@@ -22,6 +23,8 @@ foreach ($keywords as $keyword => $info) { echo "
<h3>$title</h3>
<p>$instructions</p>
+<span id=\"sitepagesKeywordMoreInfo\" class=\"xhidden\">$more_info</span>
+
<ul>
$keywords_html
</ul>
diff --git a/mod/sitepages/views/default/sitepages/metatags.php b/mod/sitepages/views/default/sitepages/metatags.php index c536dbe29..107a5871a 100644 --- a/mod/sitepages/views/default/sitepages/metatags.php +++ b/mod/sitepages/views/default/sitepages/metatags.php @@ -16,8 +16,10 @@ if ($meta_details) { $description = $meta_details->description;
echo <<<___END
+
<meta name="description" content="$description" />
<meta name="keywords" content="$metatags" />
+
___END;
}
@@ -25,11 +27,13 @@ ___END; if (get_context() == 'sitepages:front') {
$custom_css = sitepages_get_sitepage_object('front');
- if ($custom_css && $custom_css->title) {
- echo "
+ if ($custom_css && $custom_css->css) {
+ echo <<<___END
+
<style>
- {$custom_css->title}
+ {$custom_css->css}
</style>
- ";
+
+___END;
}
}
\ No newline at end of file |