diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-19 20:18:40 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-19 20:18:40 +0000 |
commit | c25dcd4533ec98c7e58c647e4b2c08169c6b7dc4 (patch) | |
tree | a8569b30b979a78f0fa052023a2d1dffe03daadf | |
parent | 5681f47424f7c4b17acb56656135efff420fa09a (diff) | |
download | elgg-c25dcd4533ec98c7e58c647e4b2c08169c6b7dc4.tar.gz elgg-c25dcd4533ec98c7e58c647e4b2c08169c6b7dc4.tar.bz2 |
Automatic RSS feeds!
git-svn-id: https://code.elgg.org/elgg/trunk@1011 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/elgglib.php | 81 | ||||
-rw-r--r-- | views/default/canvas/default.php | 21 | ||||
-rw-r--r-- | views/default/page_elements/header.php | 24 | ||||
-rw-r--r-- | views/foaf/pageshells/pageshell.php | 2 | ||||
-rw-r--r-- | views/rss/canvas/default.php | 21 | ||||
-rw-r--r-- | views/rss/object/default.php | 29 | ||||
-rw-r--r-- | views/rss/pageshells/pageshell.php | 51 | ||||
-rw-r--r-- | views/rss/user/default.php | 22 |
8 files changed, 244 insertions, 7 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index d559e5131..261dc60cc 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -187,6 +187,50 @@ }
/**
+ * Returns whether the specified view exists
+ *
+ * @param string $view The view name
+ * @param string $viewtype The type of view
+ * @return true|false Depending on success
+ */
+ function elgg_view_exists($view, $viewtype = "") {
+
+ global $CONFIG;
+
+ // If we haven't been asked for a specific view, assume default
+ if (empty($_SESSION['view'])) {
+ $_SESSION['view'] = "default";
+
+ // If we have a config default view for this site then use that instead of 'default'
+ if (/*(is_installed()) && */(!empty($CONFIG->view)) && (trim($CONFIG->view)!=""))
+ $_SESSION['view'] = $CONFIG->view;
+ }
+ if (empty($viewtype) && is_callable('get_input'))
+ $viewtype = get_input('view');
+ if (empty($viewtype)) {
+ $viewtype = $_SESSION['view'];
+ }
+
+
+ if (!isset($CONFIG->views->locations[$view])) {
+ if (!isset($CONFIG->viewpath)) {
+ $location = dirname(dirname(dirname(__FILE__))) . "/views/";
+ } else {
+ $location = $CONFIG->viewpath;
+ }
+ } else {
+ $location = $CONFIG->views->locations[$view];
+ }
+
+ if (file_exists($location . "{$viewtype}/{$view}.php")) {
+ return true;
+ }
+
+ return false;
+
+ }
+
+ /**
* When given an entity, views it intelligently.
*
* Expects a view to exist called entity-type/subtype, or for the entity to have a parameter
@@ -203,6 +247,9 @@ */
function elgg_view_entity(ElggEntity $entity, $viewtype = "", $full = false, $bypass = true, $debug = false) {
+ global $autofeed;
+ $autofeed = true;
+
$view = $entity->view;
if (is_string($view)) {
return elgg_view($view,array('entity' => $entity), $viewtype, $bypass, $debug);
@@ -231,11 +278,17 @@ $subtype = $entity->getSubtype();
if (empty($subtype)) { $subtype = $entity_type; }
- return elgg_view("{$entity_type}/{$subtype}",array(
+ if (elgg_view_exists("{$entity_type}/{$subtype}")) {
+ return elgg_view("{$entity_type}/{$subtype}",array(
+ 'entity' => $entity,
+ 'full' => $full
+ ), $viewtype, $bypass, $debug);
+ } else {
+ return elgg_view("{$entity_type}/default",array(
'entity' => $entity,
'full' => $full
), $viewtype, $bypass, $debug);
-
+ }
}
/**
@@ -303,9 +356,14 @@ $param_array['area' . $arg] = func_get_arg($arg);
$arg++;
}
- return elgg_view("canvas/layouts/{$layout}",$param_array);
+ if (elgg_view_exists("canvas/layouts/{$layout}")) {
+ return elgg_view("canvas/layouts/{$layout}",$param_array);
+ } else {
+ return elgg_view("canvas/default",$param_array);
+ }
}
+
/**
* Sets an alternative function to handle templates, which will be passed to by elgg_view.
@@ -1300,7 +1358,20 @@ return false; } - - +
+ /**
+ * Get the full URL of the current page.
+ *
+ * @return string The URL
+ */ + function full_url()
+ {
+ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
+ $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")) . $s;
+ $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
+ return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
+ }
+
+ ?>
\ No newline at end of file diff --git a/views/default/canvas/default.php b/views/default/canvas/default.php new file mode 100644 index 000000000..2d2707918 --- /dev/null +++ b/views/default/canvas/default.php @@ -0,0 +1,21 @@ +<?php
+
+ /**
+ * Elgg default 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/
+ */
+
+ for ($i = 1; $i < 8; $i++) {
+
+ if (isset($vars["area{$i}"]))
+ echo $vars["area{$i}"];
+
+ }
+
+?>
\ No newline at end of file diff --git a/views/default/page_elements/header.php b/views/default/page_elements/header.php index fdcfe71df..75ef6f746 100644 --- a/views/default/page_elements/header.php +++ b/views/default/page_elements/header.php @@ -24,6 +24,23 @@ $title = $vars['title']; } else { $title = $vars['config']->sitename . ": " . $vars['title']; + }
+
+ global $autofeed;
+ if (isset($autofeed) && $autofeed == true) {
+ $url = full_url();
+ if (substr_count($url,'?')) {
+ $url .= "&view=rss";
+ } else {
+ $url .= "?view=rss";
+ }
+ $feedref = <<<END
+
+ <link rel="alternate" type="application/rss+xml" title="RSS" href="{$url}" />
+
+END;
+ } else {
+ $feedref = "";
} ?> @@ -38,7 +55,12 @@ <script type="text/javascript" src="<?php echo $vars['url']; ?>javascript/initialise_elgg.js"></script> <!-- include the default css file --> <link rel="stylesheet" href="<?php echo $vars['url']; ?>_css/css.css" type="text/css" /> - <?php echo elgg_view('metatags',$vars); ?> + <?php
+
+ echo $feedref;
+ echo elgg_view('metatags',$vars);
+
+ ?> </head> <body> diff --git a/views/foaf/pageshells/pageshell.php b/views/foaf/pageshells/pageshell.php index a5f73db2d..534cfac2c 100644 --- a/views/foaf/pageshells/pageshell.php +++ b/views/foaf/pageshells/pageshell.php @@ -38,7 +38,7 @@ <foaf:name><?php echo $owner->name; ?></foaf:name>
<foaf:homepage rdf:resource="<?php echo $owner->getURL(); ?>" />
<foaf:mbox_sha1sum><?php echo sha1("mailto:" . $owner->email); ?></foaf:mbox_sha1sum>
- <!-- TODO <foaf:img rdf:resource="http://p-userpic.livejournal.com/74250113/9186" /> -->
+ <foaf:img rdf:resource="<?php echo $vars['url']; ?>pg/icon/<?php echo $owner->username; ?>/large/icon.jpg" />
<?php
echo $vars['body'];
diff --git a/views/rss/canvas/default.php b/views/rss/canvas/default.php new file mode 100644 index 000000000..2d2707918 --- /dev/null +++ b/views/rss/canvas/default.php @@ -0,0 +1,21 @@ +<?php
+
+ /**
+ * Elgg default 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/
+ */
+
+ for ($i = 1; $i < 8; $i++) {
+
+ if (isset($vars["area{$i}"]))
+ echo $vars["area{$i}"];
+
+ }
+
+?>
\ No newline at end of file diff --git a/views/rss/object/default.php b/views/rss/object/default.php new file mode 100644 index 000000000..7c5fc11d8 --- /dev/null +++ b/views/rss/object/default.php @@ -0,0 +1,29 @@ +<?php
+
+ /**
+ * Elgg default object view
+ *
+ * @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/
+ */
+
+ $title = $vars['entity']->title;
+ if (empty($title)) {
+ $title = substr($vars['entity']->description,0,32);
+ if (strlen($vars['entity']->description) > 32)
+ $title .= " ...";
+ }
+
+?>
+
+ <item>
+ <guid isPermaLink='true'><?php echo $vars['entity']->getURL(); ?></guid>
+ <pubDate><?php echo date("r",$vars['entity']->time_created) ?></pubDate>
+ <link><?php echo $vars['entity']->getURL(); ?></link>
+ <title><![CDATA[<?php echo $title; ?>]]></title>
+ <description><![CDATA[<?php echo (nl2br($vars['entity']->description)); ?>]]></description>
+ </item>
diff --git a/views/rss/pageshells/pageshell.php b/views/rss/pageshells/pageshell.php new file mode 100644 index 000000000..8a34752bc --- /dev/null +++ b/views/rss/pageshells/pageshell.php @@ -0,0 +1,51 @@ +<?php
+
+ /**
+ * Elgg RSS output pageshell
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ header("Content-Type: text/xml");
+
+ echo "<?xml version='1.0'?>\n";
+
+ if (!$owner = page_owner_entity()) {
+ if (!isloggedin()) {
+ exit;
+ } else {
+ $owner = $vars['user'];
+ }
+ }
+
+ // Set title
+ if (empty($vars['title'])) {
+ $title = $vars['config']->sitename;
+ } else if (empty($vars['config']->sitename)) {
+ $title = $vars['title'];
+ } else {
+ $title = $vars['config']->sitename . ": " . $vars['title'];
+ }
+
+ // Remove RSS from URL
+ $url = str_replace('?view=rss','',full_url());
+ $url = str_replace('&view=rss','',full_url());
+
+?>
+
+<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'>
+ <channel xml:base=''>
+ <title><![CDATA[<?php echo $title; ?>]]></title>
+ <link><?php echo $url; ?></link>
+ <?php
+
+ echo $vars['body'];
+
+ ?>
+ </channel>
+</rss>
\ No newline at end of file diff --git a/views/rss/user/default.php b/views/rss/user/default.php new file mode 100644 index 000000000..5d72b30df --- /dev/null +++ b/views/rss/user/default.php @@ -0,0 +1,22 @@ +<?php
+
+ /**
+ * Elgg default user view
+ *
+ * @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/
+ */
+
+?>
+
+ <item>
+ <guid isPermaLink='true'><?php echo $vars['entity']->getURL(); ?></guid>
+ <pubDate><?php echo date("r",$vars['entity']->time_created) ?></pubDate>
+ <link><?php echo $vars['entity']->getURL(); ?></link>
+ <title><![CDATA[<?php echo (nl2br($vars['entity']->name)); ?>]]></title>
+ <description><![CDATA[<?php echo (nl2br($vars['entity']->description)); ?>]]></description>
+ </item>
|