Example #1
0
File: Post.php Project: R-J/elefant
	public static function _publish_queued ($posts) {
		foreach (array_keys ($posts) as $k) {
			if ($posts[$k]->published === 'que') {
				$posts[$k]->published = 'yes';
				$posts[$k]->put ();
				\Versions::add ($posts[$k]);
			}
		}
		return $posts;
	}
Example #2
0
    $res->error = __('Authorization required.');
    echo json_encode($res);
    return;
}
$error = false;
$o = new Block($_GET['id']);
if ($o->error) {
    $error = $o->error;
} else {
    foreach ($_POST as $k => $v) {
        if ($k != $o->key && isset($o->data[$k])) {
            $o->{$k} = $v;
        }
    }
    if (!$o->put()) {
        $error = $o->error;
    } else {
        Versions::add($o);
        $_POST['id'] = $_GET['id'];
        $this->hook('blocks/edit', $_POST);
    }
}
$res = new StdClass();
if ($error) {
    $res->success = false;
    $res->error = $error;
} else {
    $res->success = true;
    $res->data = $_GET['id'];
}
echo json_encode($res);
Example #3
0
$wp = new Webpage($_GET['page']);
$f = new Form('post', 'admin/edit');
$f->verify_csrf = false;
if ($f->submit()) {
    $wp->id = $_POST['id'];
    $wp->title = $_POST['title'];
    $wp->menu_title = $_POST['menu_title'];
    $wp->window_title = $_POST['window_title'];
    $wp->access = $_POST['access'];
    $wp->layout = $_POST['layout'];
    $wp->description = $_POST['description'];
    $wp->keywords = $_POST['keywords'];
    $wp->body = $_POST['body'];
    $wp->put();
    if (!$wp->error) {
        Versions::add($wp);
        $memcache->delete('_admin_page_' . $_GET['page']);
        $this->add_notification(i18n_get('Page saved.'));
        $_POST['page'] = $_GET['page'];
        $lock->remove();
        $this->hook('admin/edit', $_POST);
        $this->redirect('/' . $_POST['id']);
    }
    $page->title = i18n_get('An Error Occurred');
    echo i18n_get('Error Message') . ': ' . $wp->error;
} else {
    $wp->layouts = admin_get_layouts();
    $wp->failed = $f->failed;
    $wp = $f->merge_values($wp);
    $page->title = i18n_get('Edit Page') . ': ' . $wp->title;
    $page->head = $tpl->render('admin/edit/head', $wp) . $tpl->render('admin/wysiwyg');
Example #4
0
        $file = 'cache/blog_' . $_FILES['import_file']['name'];
        $imported = 0;
        try {
            $posts = new SimpleXMLElement(file_get_contents($file));
            foreach ($posts->channel->item as $entry) {
                $dc = $entry->children('http://purl.org/dc/elements/1.1/');
                $content = $entry->children('http://purl.org/rss/1.0/modules/content/');
                $post = array('title' => (string) $entry->title, 'author' => (string) $dc->creator, 'ts' => gmdate('Y-m-d H:i:s', strtotime($entry->pubDate)), 'published' => $_POST['published'], 'body' => str_replace("\n", "<br />\n", (string) $content->encoded), 'tags' => '');
                $sep = '';
                for ($i = 0; $i < count($entry->category); $i++) {
                    $post['tags'] .= $sep . $entry->category[$i]->attributes()->nicename;
                    $sep = ', ';
                }
                $p = new blog\Post($post);
                if ($p->put()) {
                    Versions::add($p);
                    $imported++;
                }
            }
            echo '<p>' . i18n_getf('Imported %d posts.', $imported) . '</p>';
            echo '<p><a href="/blog/admin">' . i18n_get('Continue') . '</a></p>';
        } catch (Exception $e) {
            echo '<p><strong>' . i18n_get('Error importing file') . ': ' . $e->getMessage() . '</strong></p>';
            echo '<p><a href="/blog/admin">' . i18n_get('Back') . '</a></p>';
        }
        return;
    } else {
        echo '<p><strong>' . i18n_get('Error uploading file.') . '</strong></p>';
    }
}
$o = new StdClass();
Example #5
0
 /**
  * @depends test_get_classes
  */
 function test_restore_deleted()
 {
     // test restore on deleted item
     $foo = new Foobar(array('id' => 5, 'name' => 'Deleted'));
     $v = Versions::add($foo);
     $foo->remove();
     $foo2 = $v->restore();
     $this->assertEquals($foo, $foo2);
 }
Example #6
0
File: add.php Project: Alm001/form
<?php

/**
 * Creates a new untitled form and forwards to /form/edit, the form builder.
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
$f = new form\Form(array('title' => 'Untitled', 'message' => 'Please fill in the following information.', 'ts' => gmdate('Y-m-d H:i:s'), 'fields' => '[]', 'actions' => '[]', 'response_title' => 'Thank you', 'response_body' => 'Your information has been saved.'));
$f->put();
\Versions::add($f);
if (!$f->error) {
    $this->redirect('/form/edit?id=' . $f->id);
}
$page->title = i18n_get('An Error Occurred');
echo '<p>' . i18n_get('Unable to create a new form.') . '</p>';
Example #7
0
File: API.php Project: Alm001/form
 /**
  * Update the form actions. Usage:
  *
  *     /form/api/actions/form-id
  *
  * Expects a single POST item named `actions` containing
  * the data structure of the form actions.
  */
 public function post_actions($id)
 {
     $f = new Form($id);
     if ($f->error) {
         return $this->error(i18n_get('Form not found'));
     }
     if (!isset($_POST['actions'])) {
         $_POST['actions'] = array();
     }
     if (!is_array($_POST['actions'])) {
         return $this->error(i18n_get('Invalid actions parameter'));
     }
     $f->actions = $_POST['actions'];
     $f->put();
     if ($f->error) {
         return $this->error(i18n_get('Failed to save changes'));
     }
     \Versions::add($f);
     return i18n_get('Form updated');
 }
Example #8
0
if (!$appconf['Custom Handlers']['user/signup']) {
    echo $this->error(404, __('Not found'), __('The page you requested could not be found.'));
    return;
}
// Check for a custom handler override
$res = $this->override('user/login/newuser');
if ($res) {
    echo $res;
    return;
}
$f = new Form('post', 'user/login/newuser');
if ($f->submit()) {
    $date = gmdate('Y-m-d H:i:s');
    $u = new User(array('name' => $_POST['name'], 'email' => $_POST['email'], 'password' => User::encrypt_pass($_POST['password']), 'expires' => $date, 'type' => Appconf::user('User', 'default_role'), 'signed_up' => $date, 'updated' => $date, 'userdata' => json_encode(array()), 'about' => ''));
    $u->put();
    Versions::add($u);
    if (!$u->error) {
        $oid = new User_OpenID(array('token' => $_POST['token'], 'user_id' => $u->id));
        $oid->put();
        $_POST['username'] = $_POST['email'];
        User::require_login();
        $this->redirect($_POST['redirect']);
    }
    // TODO: already have an account
    @error_log('Error creating profile: ' . $u->error);
    $page->title = 'An Error Occurred';
    echo '<p>Please try again later.</p>';
    echo '<p><a href="/">' . __('Back') . '</a></p>';
} else {
    $u = new User();
    $u = $f->merge_values($u);
Example #9
0
 * Restores a previous version of a Model object, replacing the
 * current version, and adding a new version to the history
 * as well.
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
$ver = new Versions($_GET['id']);
$lock = new Lock($ver->class, $ver->pkey);
if ($lock->exists()) {
    $page->title = __('Editing Locked');
    echo $tpl->render('admin/locked', $lock->info());
    return;
} else {
    $lock->add();
}
$obj = $ver->restore();
$obj->put();
if ($obj->error) {
    $page->title = __('An Error Occurred');
    echo __('Error Message') . ': ' . $obj->error;
    return;
}
Versions::add($obj);
$this->add_notification(__('Item restored.'));
if ($ver->class == 'Webpage') {
    $cache->delete('_admin_page_' . $obj->id);
    $this->redirect('/' . $obj->id);
}
$this->redirect('/');
Example #10
0
				$data['error'] = false;

				// create the database
				$sqldata = sql_split (file_get_contents ('../conf/install_' . $_POST['driver'] . '.sql'));
				foreach ($sqldata as $sql) {
					if (! DB::execute ($sql)) {
						$data['error'] = DB::error ();
						DB::execute ('rollback');
						break;
					}
				}
				
				$wp = new Webpage ('index');
				Versions::add ($wp);
				$b = new Block ('members');
				Versions::add ($b);

				// write the settings
				if (! $data['error']) {
					$config = file_get_contents ('../conf/config.php');
					// good to replace database settings
					$_POST['pass'] = str_replace ('"', '\"', $_POST['pass']);
					$dbinfo = $tpl->render ('dbinfo', $_POST);
					$config = preg_replace ('/\[Database\].*\[Mongo\]/s', $dbinfo, $config);
					if (! file_put_contents ('../conf/config.php', $config)) {
						$data['error'] = __ ('Failed to write to conf/config.php');
					} else {
						$data['ready'] = true;
					}
				}
			}
Example #11
0
<?php

/**
 * Publish scheduled blog posts. Use via cron like this:
 *
 *     0,15,30,45 * * * * /var/www/elefant blog/publish-queue
 */
if (!$this->cli) {
    die('Must be run from the command line.');
}
$page->layout = false;
// fetch queued posts
$posts = blog\Post::query()->where('published', 'que')->where('ts <= ?', gmdate('Y-m-d H:i:s'))->fetch();
// publish posts
foreach ($posts as $post) {
    $post->published = 'yes';
    $post->put();
    Versions::add($post);
}