Permalink
Browse files

Import from Ning

  • Loading branch information...
0 parents commit 304b22791ab5d4c2ad7eb5a455e8ff830c5fe100 @singpolyma committed Apr 22, 2009
Showing with 2,065 additions and 0 deletions.
  1. +21 −0 README
  2. +83 −0 addORedit.php
  3. +78 −0 api.php
  4. +42 −0 commentRSS.php
  5. +12 −0 contentManager.php
  6. +21 −0 delete.php
  7. +28 −0 editor.php
  8. +112 −0 get.php
  9. +21 −0 getSweeties.php
  10. +114 −0 index.php
  11. +931 −0 minify.php
  12. BIN ning_logo.gif
  13. +16 −0 removeEvils.php
  14. +61 −0 setup.php
  15. +63 −0 tagFunctions.php
  16. +144 −0 view.php
  17. +15 −0 xn/ningbar.css
  18. +1 −0 xn/ningbar.php
  19. +222 −0 xn_default.css
  20. +66 −0 xn_header.view
  21. +7 −0 xn_pivot.Comment.view
  22. +7 −0 xn_pivot.File.view
@@ -0,0 +1,21 @@
+This is the code from filess.ning.com
+
+This is also the exact same code that powers jscripts.ning.com
+
+I can no longer update the Ning site.
+
+This code in under the following license unless otherwise noted:
+
+Copyright (c) 2009, Stephen Paul Weber
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,83 @@
+<?php
+
+if(!XN_Profile::current()->isLoggedIn())//Check if user is logged in and fail if they are not
+ die('<b>Please log in</b>');
+
+$setup = XN_Query::create('Content')//Get the setup data (so we know what object types we're working with)
+ ->filter('owner','=')
+ ->filter('type','eic','Setup');
+$setup = $setup->execute();
+$setup = $setup[0];
+
+$file = false;//we have no file
+if($_REQUEST['id']) {//if editing object id
+ $file = XN_Content::load(intval($_REQUEST['id']));//load file by id from Content Store
+ if(XN_Profile::current()->screenName != $file->contributorName)//if this user is not the object owner, die
+ die('You do not have permission to edit this item');
+ $file->focus();//focus sidebar -- probably deprecated
+}//end if id
+
+if(isset($_REQUEST['submit'])) {//if processing form
+ if($_POST['data']) {//if files was uploaded
+ $data = XN_Request::uploadedFileContents($_POST['data']);//get uploaded file
+ } else
+ $data = false;//no uploaded file == no data (or do not change data)
+
+ if(!$file && !$data)//if no data and no original, die
+ die('<b>You must upload a '.$setup->my->single.'!</b>');
+ if(!$file)//if no existing file, create new object
+ $file = XN_Content::create($setup->my->single);
+
+ $file->title = $_REQUEST['title'];//set title
+ $file->description = $_REQUEST['description'];//set description
+ if($data)//if editing data
+ $file->my->set('data',base64_encode($data));//set data
+ if($_POST['data'])//if uploading file
+ $file->my->set('filename',$_POST['data']);//set filename
+ foreach(unserialize($setup->my->fields) as $field) {//set other fields
+ $file->my->set($field,$_REQUEST[$field]);
+ }//end foreach fields
+ $file->save();//save object to Content Store
+ if($_REQUEST['tags']) {//if there are tags
+ XN_Tag::checkTags($_REQUEST['tags']);//make sure the tags are valid
+ XN_Tag::addTags($file,$_REQUEST['tags']);//add tags to object (object must be saved at least once before this)
+ }//end if tags
+ $file->focus();//focus sidebar -- probably deprecated
+
+ echo '<p><b>'.$setup->my->single.' Saved</b></p>';//Print 'saved' message
+}//end if isset submit
+
+if($file) {//If there's an existing object, we're editing
+ echo '<h2>Edit '.$setup->my->single.'</h2>';
+ echo '<xn:head><title>'.XN_Application::load()->name.' - Edit '.$setup->my->single.'</title></xn:head>';
+} else {//otherwise we're creating/adding
+ echo '<h2>Add '.$setup->my->single.'</h2>';
+ echo '<xn:head><title>'.XN_Application::load()->name.' - Add '.$setup->my->single.'</title></xn:head>';
+}//end if-else file
+
+?>
+<!-- File upload/object edit form -->
+<fieldset>
+<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"><dl>
+ <dt>Title</dt><dd><input type="text" name="title" value="<?php if($file) echo $file->h('title'); ?>" /></dd>
+ <dt>Description</dt><dd><textarea name="description"><?php if($file) echo $file->h('description'); ?></textarea></dd>
+
+<?php
+
+//do arbitrary fields
+foreach(unserialize($setup->my->fields) as $field) {
+ echo '<dt>'.$field.'</dt><dd><input type="text" name="'.$field.'" value="'.($file ? $file->my->$field : '').'" /></dd>';
+}//end foreach fields
+
+?>
+
+ <dt><?php echo ($file ? 'Update' : 'Upload'); ?> File</dt><dd><input name="data" type="file" /></dd>
+
+ <dd><a href="editor.php?id=<?php echo $file->id; ?>">Edit Online</a> (text-based files only)</dd>
+
+<?php if(!$file) { ?>
+ <dt>Tags</dt><dd><input type="text" name="tags" value="" /></dd>
+<?php } ?>
+ <dt></dt><dd><?php if($file) echo '<input type="hidden" name="id" value="'.$file->id.'" />'; ?><input type="submit" name="submit" value="Save" /></dd>
+</dl></form>
+</fieldset>
@@ -0,0 +1,78 @@
+<?php
+
+$setup = XN_Query::create('Content')
+ ->filter('owner','=')
+ ->filter('type','eic','Setup');
+$setup = $setup->execute();
+if(count($setup)) {
+ $setup = $setup[0];
+} else {
+ header('Content-Type: text/plain;');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].'/setup.php',true,303);
+ exit;
+}//end if-else setup
+
+$_SERVER['HTTP_X_NING_REQUEST_URI'] = explode('?',$_SERVER['HTTP_X_NING_REQUEST_URI']);
+$_SERVER['HTTP_X_NING_REQUEST_URI'] = $_SERVER['HTTP_X_NING_REQUEST_URI'][0];
+$pathvars = explode('/',$_SERVER['HTTP_X_NING_REQUEST_URI']);
+unset($pathvars[0]);unset($pathvars[1]);
+$pathvars = array_values($pathvars);
+
+if(!count($pathvars) || !$pathvars[0]) {
+ $query = XN_Query::create('Content_Count')
+ ->filter('owner')
+ ->rollup('contributor');
+ $users = array_keys($query->execute());
+ header('Content-type: application/xml;');
+ header('X-Moz-Is-Feed: 1');
+ echo '<?xml version="1.0" ?>'."\n";
+ echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
+ echo ' <channel/> <!-- may be removed, just forces firefox to render as feed -->'."\n";
+ foreach($users as $user) {
+ echo ' <item>'."\n";
+ echo ' <dc:identifier>'.htmlspecialchars($user).'</dc:identifier>'."\n";
+ echo ' <link>'.htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].'/user/'.urlencode($user)).'</link>'."\n";
+ echo ' <title>'.htmlspecialchars($user).'</title>'."\n";
+ echo ' <dc:created>2007-04-19T16:47:11+00:00</dc:created>'."\n";
+ echo ' <mime>inode/directory</mime>'."\n";
+ echo ' <permissions>444</permissions>'."\n";
+ echo ' </item>'."\n";
+ }//end foreach inode
+ echo '</rdf:RDF>';
+ exit;
+}//end if ! count pathvars
+
+if(!is_numeric($pathvars[0])) {
+ $query = XN_Query::create('Content')
+ ->filter('owner')
+ ->filter('type','eic',$setup->my->single)
+ ->filter('contributorName','eic',$pathvars[0]);
+ $items = $query->execute();
+ header('Content-type: application/xml;');
+ header('X-Moz-Is-Feed: 1');
+ echo '<?xml version="1.0" ?>'."\n";
+ echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
+ echo ' <channel/> <!-- may be removed, just forces firefox to render as feed -->'."\n";
+ foreach($items as $item) {
+ echo ' <item>'."\n";
+ echo ' <dc:identifier>'.$item->id.'</dc:identifier>'."\n";
+ echo ' <link>'.htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].'/id/'.$item->id).'</link>'."\n";
+ echo ' <title>'.htmlspecialchars($item->title).'</title>'."\n";
+ echo ' <dc:created>'.$item->createdDate.'</dc:created>'."\n";
+ echo ' <dc:modified>'.$item->updatedDate.'</dc:modified>'."\n";
+ echo ' <mime>'.htmlspecialchars($setup->my->mime).'</mime>'."\n";
+ echo ' <size>'.strlen(base64_decode($item->my->data)).'</size>'."\n";
+ echo ' <permissions>644</permissions>'."\n";
+ echo ' </item>'."\n";
+ }//end foreach inode
+ echo '</rdf:RDF>';
+ exit;
+}//end if is_numeric
+
+if(is_numeric($pathvars[0])) {
+ header('Content-Type: text/plain;');
+ header('Location: http://'.$_SERVER['HTTP_HOST'].'/id/'.$pathvars[0],true,303);
+ exit;
+}//end if is_numeric
+
+?>
@@ -0,0 +1,42 @@
+<?php
+
+if(!$_REQUEST['id'])
+ die('<b>No ID specified!</b>');
+
+require_once 'XNC/Comment.php';
+require_once 'removeEvils.php';
+
+$file = XN_Content::load(intval($_REQUEST['id']));
+$newComment = new XNC_Comment($file);
+$comments = $file->my->content($newComment->referenceAttribute,true);
+$firstcomment = new XNC_Comment($comments[0]);
+
+header('Content-Type: application/xml;charset=utf-8');
+echo '<?xml version="1.0"?>'."\n";
+
+?>
+<rss version="2.0">
+<channel>
+ <title>Comments on <?php echo $file->title ?></title>
+ <description>On App <?php echo XN_Application::load()->name; ?></description>
+ <link>http://<?php echo $_SERVER['HTTP_HOST']; ?>/view.php?id=<?php echo $file->id; ?></link>
+ <docs>http://blogs.law.harvard.edu/tech/rss</docs>
+ <generator><?php echo XN_Application::load()->name; ?> (PHP Script)</generator>
+ <pubDate><?php echo date('r',strtotime($firstcomment->createdDate)); ?></pubDate>
+ <lastBuildDate><?php echo date('r',strtotime($firstcomment->createdDate)); ?></lastBuildDate>
+
+<?php
+ foreach($comments as $comment) {
+ $data = new XNC_Comment($comment);
+?>
+ <item>
+ <title><?php echo 'Comment by '.$data->contributorName; ?></title>
+ <description><?php echo htmlspecialchars(removeEvilTags(nl2br($data->description))); ?></description>
+ <pubDate><?php echo date('r',strtotime($data->createdDate)); ?></pubDate>
+ <link>http://<?php echo $_SERVER['HTTP_HOST']; ?>/view.php?id=<?php echo $file->id.'#c'.$data->id; ?></link>
+ <guid>http://<?php echo $_SERVER['HTTP_HOST']; ?>/view.php?id=<?php echo $file->id.'#c'.$data->id; ?></guid>
+ </item>
+<?php } ?>
+
+</channel>
+</rss>
@@ -0,0 +1,12 @@
+<?php
+require_once 'XNC/ContentManager.php';
+
+if (XN_Profile::current()->isOwner()) {
+ $mgr = new XNC_ContentManager();
+ $mgr->go();
+} else {
+ echo '<h1>Whoops!</h1>';
+ echo '<p>We\'re sorry, only the owner of this application can access the Content Manager. If that\'s
+ you, please sign in.</p>';
+}
+?>
@@ -0,0 +1,21 @@
+<?php
+
+if(!$_REQUEST['id'])
+ die('<b>No ID Specified</b>');
+
+$content = XN_Content::load($_REQUEST['id']);
+
+if(XN_Profile::current()->screenName != $content->contributorName)
+ die('You do not have permission to delete this item');
+
+XN_Content::delete($content);
+
+$setup = XN_Query::create('Content')
+ ->filter('owner','=')
+ ->filter('type','eic','Setup');
+$setup = $setup->execute();
+$setup = $setup[0];
+
+echo '<p>'.$setup->my->single.' #'.$_REQUEST['id'].' Deleted</p>';
+
+?>
@@ -0,0 +1,28 @@
+<?php
+
+if(!XN_Profile::current()->isLoggedIn())//Check if user is logged in and fail if they are not
+ die('<b>Please log in</b>');
+
+if(!$_REQUEST['id'])
+ die('<b>No ID Specified</b>');
+
+$file = XN_Content::load(intval($_REQUEST['id']));//load file by id from Content Store
+if(XN_Profile::current()->screenName != $file->contributorName)//if this user is not the object owner, die
+ die('You do not have permission to edit this item');
+
+if($_REQUEST['_content']) {//save
+ $file->my->set('data',base64_encode($_REQUEST['_content']));
+ $file->save();
+ echo '<h2>Saved</h2>';
+}//end if _content
+
+?>
+<h2>Edit File</h2>
+<fieldset>
+<form method="post" action="?id=<?php echo $_REQUEST['id']; ?>" style="width:auto;"><dl>
+ <dt style="float:none;clear:both;text-align:left;width:auto;">File Contents</dt>
+ <dd style="clear:both;padding:0px;float:none;margin:0px;"><textarea name="_content" cols="100" rows="25"><?php echo xnhtmlentities(base64_decode($file->my->data)); ?></textarea></dd>
+
+ <dd style="display:block;width:auto;text-align:right;"><input type="submit" value="Save" /></dd>
+</dl></form>
+</fieldset>
Oops, something went wrong.

0 comments on commit 304b227

Please sign in to comment.