Example #1
0
 public static function paginate($page = 1, $perpage = 10)
 {
     $query = Query::table(static::table());
     $count = $query->count();
     $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('title')->get();
     return new Paginator($results, $count, $page, $perpage, Uri::to('admin/companies'));
 }
Example #2
0
 public static function __callStatic($method, $arguments)
 {
     $obj = Query::table(static::table())->apply(get_called_class());
     if (method_exists($obj, $method)) {
         return call_user_func_array(array($obj, $method), $arguments);
     }
 }
Example #3
0
 private static function account($settings)
 {
     $account = $settings['account'];
     $database = $settings['database'];
     $query = Query::table($database['prefix'] . 'users', static::$connection);
     $query->insert(array('username' => $account['username'], 'password' => Hash::make($account['password']), 'email' => $account['email'], 'real_name' => 'Administrator', 'bio' => 'The bouse', 'status' => 'active', 'role' => 'administrator'));
 }
 public static function paginate($page = 1, $perpage = 10)
 {
     $query = Query::table(static::table());
     $count = $query->count();
     $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('date', 'desc')->get();
     return new Paginator($results, $count, $page, $perpage, url('comments'));
 }
 public static function paginate($page = 1, $perpage = 10)
 {
     $query = Query::table(static::table());
     $count = $query->count();
     $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('real_name', 'desc')->get();
     return new Paginator($results, $count, $page, $perpage, Uri::to('users'));
 }
 public function up()
 {
     $table = Base::table('meta');
     if ($this->has_table($table)) {
         if (!Query::table($table)->where('key', '=', 'comment_notifications')->count()) {
             Query::table($table)->insert(array('key' => 'comment_notifications', 'value' => 0));
         }
     }
 }
 public function up()
 {
     $table = Base::table('categories');
     if ($this->has_table($table)) {
         if (!Query::table($table)->count()) {
             Query::table($table)->insert(array('title' => 'Uncategorised', 'slug' => 'uncategorised', 'description' => 'Ain\'t no category here.'));
         }
     }
 }
Example #8
0
 public static function search($term, $page = 1, $per_page = 10)
 {
     $query = Query::table(Base::table('posts'));
     $query->join(Base::table('wtfsearch'), Base::table('posts.id'), '=', Base::table('wtfsearch.post_id'));
     $query->left_join(Base::table('users'), Base::table('users.id'), '=', Base::table('posts.author'))->where(Base::table('posts.status'), '=', 'published')->where(Base::table('wtfsearch.meta_value'), 'like', '%' . $term . '%');
     $query->group(Base::table('posts.id'));
     $total = $query->count();
     $posts = $query->take($per_page)->skip(--$page * $per_page)->get(array(Base::table('posts.*'), Base::table('users.id as author_id'), Base::table('users.bio as author_bio'), Base::table('users.real_name as author_name')));
     return array($total, $posts);
 }
Example #9
0
/**
 * Returns an array of ids for posts that have the specified tag
 *
 * @param string
 * @return array
 */
function get_posts_with_tag($tag)
{
    $tag_ext = Extend::where('key', '=', 'post_tags')->get();
    $tag_id = $tag_ext[0]->id;
    $prefix = Config::db('prefix', '');
    $posts = array();
    foreach (Query::table($prefix . 'post_meta')->where('extend', '=', $tag_id)->where('data', 'LIKE', '%' . $tag . '%')->get() as $meta) {
        $posts[] = $meta->post;
    }
    return array_unique($posts);
}
 public function up()
 {
     $table = Base::table('meta');
     if ($this->has_table($table)) {
         if (!Query::table($table)->where('key', '=', 'dashboard_page')->count()) {
             Query::table($table)->insert(array('key' => 'dashboard_page', 'value' => 'panel'));
         } else {
             Query::table($table)->where('key', '=', 'dashboard_page')->update(array('value' => 'panel'));
         }
     }
 }
 public function up()
 {
     $table = Base::table('meta');
     if ($this->has_table($table)) {
         if (!Query::table($table)->where('key', '=', 'show_all_posts')->count()) {
             Query::table($table)->insert(array('key' => 'show_all_posts', 'value' => 0));
         } else {
             Query::table($table)->where('key', '=', 'show_all_posts')->update(array('value' => 0));
         }
     }
 }
Example #12
0
 public static function renew()
 {
     $version = static::touch();
     $today = date('Y-m-d H:i:s');
     $table = Base::table('meta');
     Query::table($table)->where('key', '=', 'last_update_check')->update(array('value' => $today));
     Query::table($table)->where('key', '=', 'update_version')->update(array('value' => $version));
     // reload database metadata
     foreach (Query::table($table)->get() as $item) {
         $meta[$item->key] = $item->value;
     }
     Config::set('meta', $meta);
 }
Example #13
0
 public static function migrations()
 {
     $current = Config::meta('current_migration');
     $migrate_to = Config::migrations('current');
     $migrations = new Migrations($current);
     $table = Base::table('meta');
     if (is_null($current)) {
         $number = $migrations->up($migrate_to);
         Query::table($table)->insert(array('key' => 'current_migration', 'value' => $number));
     } else {
         if ($current < $migrate_to) {
             $number = $migrations->up($migrate_to);
             Query::table($table)->where('key', '=', 'current_migration')->update(array('value' => $number));
         }
     }
 }
 public function up()
 {
     $table = Base::table('pagetypes');
     if (!$this->has_table($table)) {
         $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (\n\t\t\t\t`key` varchar(32) NOT NULL,\n\t\t\t\t`value` varchar(32) NOT NULL\n\t\t\t) ENGINE=InnoDB";
         DB::ask($sql);
         Query::table($table)->insert(array('key' => 'all', 'value' => 'All Pages'));
     }
     $table2 = Base::table('extend');
     if (!$this->has_table_column($table2, 'pagetype')) {
         $sql2 = "ALTER TABLE `" . $table2 . "` ADD `pagetype` VARCHAR(140) NOT NULL DEFAULT 'all' AFTER `type`";
         DB::ask($sql2);
     }
     $table3 = Base::table('pages');
     if (!$this->has_table_column($table3, 'pagetype')) {
         $sql2 = "ALTER TABLE `" . $table3 . "` ADD `pagetype` VARCHAR(140) NOT NULL DEFAULT 'all' AFTER `slug`";
         DB::ask($sql2);
     }
 }
Example #15
0
function company_count()
{
    return Query::table(Base::table('posts'))->where('company', '=', company_id())->where('status', '=', 'published')->count();
}
Example #16
0
			<?php 
}
?>
		</nav>
	</header>
	<?php 
if (site_meta('sidebar', 1) && page_title("") != "List") {
    ?>
	<aside>
		<p class="description">
			<?php 
    echo site_description();
    ?>
		</p>
		<?php 
    $items = Query::table(Base::table('posts'))->where('status', '=', 'published')->get();
    $previousMonth = "";
    $page = Registry::get('posts_page');
    ?>
		<div id="previousPosts">
		<?php 
    for ($i = count($items) - 1; $i >= 0; $i--) {
        $item = $items[$i];
        $currMonth = date('F Y', strtotime($item->created));
        if ($currMonth != $previousMonth) {
            if ($previousMonth != "") {
                echo "</ul>";
            }
            echo "<p class='month'>{$currMonth}</p>";
            echo "<ul>";
            $previousMonth = $currMonth;
/**
 * Returns an array of unique tags that exist on post given post,
 * empty array if no tags are found.
 *
 * @return array
 */
function get_tags_for_post($post_id)
{
    $tag_ext = Extend::where('key', '=', 'post_tags')->where('type', '=', 'post')->get();
    $tag_id = $tag_ext[0]->id;
    $prefix = Config::db('prefix', '');
    $tags = array();
    $index = 0;
    $meta = Query::table($prefix . 'post_meta')->left_join('posts', 'posts.id', '=', 'post_meta.post')->where('posts.status', '=', 'published')->where('extend', '=', $tag_id)->where('post', '=', $post_id)->get();
    $post_meta = json_decode($meta[0]->data);
    if (!trim($post_meta->text) == "") {
        foreach (explode(",", $post_meta->text) as $tag_text) {
            $tags[$index] = trim($tag_text);
            $index += 1;
        }
    }
    return array_unique($tags);
}
Example #18
0
        $input = Input::get(array('key', 'value'));
        $input['key'] = slug($input['key'], '_');
        $validator = new Validator($input);
        $validator->add('valid_key', function ($str) use($key) {
            // no change
            if ($str == $key) {
                return true;
            }
            // check the new key $str is available
            return Query::table(Base::table('pagetypes'))->where('key', '=', $str)->count() == 0;
        });
        $validator->check('key')->is_max(2, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
        $validator->check('value')->is_max(1, __('extend.name_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/extend/pagetypes/edit/' . $key);
        }
        Query::table(Base::table('pagetypes'))->where('key', '=', $key)->update($input);
        Notify::success(__('extend.pagetype_updated'));
        return Response::redirect('admin/extend/pagetypes');
    });
    /*
        Delete Var
    */
    Route::get('admin/extend/pagetypes/delete/(:any)', function ($key) {
        Query::table(Base::table('pagetypes'))->where('key', '=', $key)->delete();
        Notify::success(__('extend.pagetype_deleted'));
        return Response::redirect('admin/extend/pagetypes');
    });
});
Example #19
0
        $vars['themes'] = Themes::all();
        return View::create('extend/metadata/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    /*
        Update Metadata
    */
    Route::post('admin/extend/metadata', function () {
        $input = Input::get(array('sitename', 'description', 'home_page', 'posts_page', 'posts_per_page', 'auto_published_comments', 'theme', 'comment_notifications', 'comment_moderation_keys', 'show_all_posts', 'dashboard_page'));
        foreach ($input as $key => $value) {
            $input[$key] = eq($value);
        }
        $validator = new Validator($input);
        $validator->check('sitename')->is_max(3, __('metadata.sitename_missing'));
        $validator->check('description')->is_max(3, __('metadata.sitedescription_missing'));
        $validator->check('posts_per_page')->is_regex('#^[0-9]+$#', __('metadata.missing_posts_per_page', 'Please enter a number for posts per page'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/extend/metadata');
        }
        // convert double quotes so we dont break html
        $input['sitename'] = e($input['sitename'], ENT_COMPAT);
        $input['description'] = e($input['description'], ENT_COMPAT);
        foreach ($input as $key => $v) {
            $v = is_null($v) ? 0 : $v;
            Query::table(Base::table('meta'))->where('key', '=', $key)->update(array('value' => $v));
        }
        Notify::success(__('metadata.updated'));
        return Response::redirect('admin/extend/metadata');
    });
});
Example #20
0
 function table($name)
 {
     $instance = new Query($this);
     $instance->table($name);
     return $instance;
 }
Example #21
0
 public function testTruncateTable()
 {
     $this->markTestSkipped("Defect");
     $query = new Query("TRUNCATE TABLE `dates`");
     $query->table("aaa");
     $this->assertEquals("TRUNCATE TABLE `aaa`", (string) $query);
 }
Example #22
0
    Route::post('admin/extend/variables/edit/(:any)', function ($key) {
        $input = Input::get(array('key', 'value'));
        $input['key'] = 'custom_' . slug($input['key'], '_');
        $validator = new Validator($input);
        $validator->add('valid_key', function ($str) use($key) {
            // no change
            if ($str == $key) {
                return true;
            }
            // check the new key $str is available
            return Query::table(Base::table('meta'))->where('key', '=', $str)->count() == 0;
        });
        $validator->check('key')->is_max(8, __('extend.name_missing'))->is_valid_key(__('extend.name_exists'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/extend/variables/edit/' . $key);
        }
        Query::table(Base::table('meta'))->where('key', '=', $key)->update($input);
        Notify::success(__('extend.variable_updated'));
        return Response::redirect('admin/extend/variables');
    });
    /*
    	Delete Var
    */
    Route::get('admin/extend/variables/delete/(:any)', function ($key) {
        Query::table(Base::table('meta'))->where('key', '=', $key)->delete();
        Notify::success(__('extend.variable_deleted'));
        return Response::redirect('admin/extend/variables');
    });
});
Example #23
0
 */
 Route::get(array('admin/comments', 'admin/comments/(:num)'), function ($page = 1) {
     $query = Query::table(Base::table(Comment::$table));
     $perpage = Config::meta('posts_per_page');
     $count = $query->count();
     $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('date', 'desc')->get();
     $vars['comments'] = new Paginator($results, $count, $page, $perpage, Uri::to('admin/comments'));
     $vars['messages'] = Notify::read();
     $vars['statuses'] = array(array('url' => '', 'lang' => 'global.all', 'class' => 'active'), array('url' => 'pending', 'lang' => 'global.pending', 'class' => 'pending'), array('url' => 'approved', 'lang' => 'global.approved', 'class' => 'approved'), array('url' => 'spam', 'lang' => 'global.spam', 'class' => 'spam'));
     return View::create('comments/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 /*
 	List Comments by status
 */
 Route::get(array('admin/comments/(pending|approved|spam)', 'admin/comments/(pending|approved|spam)/(:num)'), function ($status = '', $page = 1) {
     $query = Query::table(Base::table(Comment::$table));
     $perpage = Config::meta('posts_per_page');
     if (in_array($status, array('pending', 'approved', 'spam'))) {
         $query->where('status', '=', $status);
     }
     $count = $query->count();
     $results = $query->take($perpage)->skip(($page - 1) * $perpage)->sort('date', 'desc')->get();
     $vars['comments'] = new Paginator($results, $count, $page, $perpage, Uri::to('admin/comments/' . $status));
     $vars['messages'] = Notify::read();
     $vars['status'] = $status;
     $vars['statuses'] = array(array('url' => '', 'lang' => 'global.all', 'class' => ''), array('url' => 'pending', 'lang' => 'global.pending', 'class' => 'pending'), array('url' => 'approved', 'lang' => 'global.approved', 'class' => 'approved'), array('url' => 'spam', 'lang' => 'global.spam', 'class' => 'spam'));
     return View::create('comments/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 /*
 	Edit Comment
 */
Example #24
0
            return Extend::where('key', '=', $str)->where('type', '=', $input['type'])->where('id', '<>', $id)->count() == 0;
        });
        $validator->check('key')->is_max(1, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
        $validator->check('label')->is_max(1, __('extend.label_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/extend/fields/edit/' . $id);
        }
        if ($input['field'] == 'image') {
            $attributes = Json::encode($input['attributes']);
        } elseif ($input['field'] == 'file') {
            $attributes = Json::encode(array('attributes' => array('type' => $input['attributes']['type'])));
        } else {
            $attributes = '';
        }
        Extend::update($id, array('type' => $input['type'], 'pagetype' => $input['pagetype'], 'field' => $input['field'], 'key' => $input['key'], 'label' => $input['label'], 'attributes' => $attributes));
        Notify::success(__('extend.field_updated'));
        return Response::redirect('admin/extend/fields/edit/' . $id);
    });
    /*
        Delete Field
    */
    Route::get('admin/extend/fields/delete/(:num)', function ($id) {
        $field = Extend::find($id);
        Query::table(Base::table($field->type . '_meta'))->where('extend', '=', $field->id)->delete();
        $field->delete();
        Notify::success(__('extend.field_deleted'));
        return Response::redirect('admin/extend/fields');
    });
});
Example #25
0
 public static function process($type, $item)
 {
     foreach (static::fields($type, $item) as $extend) {
         if ($extend->attributes) {
             $extend->attributes = Json::decode($extend->attributes);
         }
         $data = call_user_func_array(array('Extend', 'process_' . $extend->field), array($extend, $item));
         // save data
         if (!is_null($data)) {
             $table = static::table($extend->type . '_meta');
             $query = Query::table($table)->where('extend', '=', $extend->id)->where($extend->type, '=', $item);
             if ($query->count()) {
                 $query->update(array('data' => $data));
             } else {
                 $query->insert(array('extend' => $extend->id, $extend->type => $item, 'data' => $data));
             }
         }
         // remove data
         if (Input::get('extend_remove.' . $extend->key)) {
             if (isset($extend->value->filename) and strlen($extend->value->filename)) {
                 Query::table(static::table($extend->type . '_meta'))->where('extend', '=', $extend->id)->where($extend->type, '=', $item)->delete();
                 $resource = PATH . 'content' . DS . $extend->value->filename;
                 file_exists($resource) and unlink(PATH . 'content' . DS . $extend->value->filename);
             }
         }
     }
 }
Example #26
0
        $vars['categories'] = Category::dropdown();
        return View::create('accueil/editBio_en', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post(array('admin/accueil/editBio'), function () {
        $page = Page::slug('biographie');
        Extend::process('page', $page->id);
        Notify::success(__('accueil.updated_bio'));
        return Response::redirect('admin/accueil');
    });
    Route::post(array('admin/accueil/editBio_en'), function () {
        $page = Page::slug('biographie');
        Extend::process('page', $page->id);
        Notify::success(__('accueil.updated_bio'));
        return Response::redirect('admin/accueil');
    });
    /**
     * Person infos
     */
    Route::get('admin/accueil/editInfo/(:any)', function ($key) {
        $vars['messages'] = Notify::read();
        $vars['token'] = Csrf::token();
        $vars['variableInfo'] = Query::table(Base::table('meta'))->where('key', '=', $key)->fetch();
        return View::create('accueil/editInfo', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
    });
    Route::post('admin/accueil/editInfo/(:any)', function ($key) {
        $input = Input::get(array('value'));
        Query::table(Base::table('meta'))->where('key', '=', $key)->update($input);
        Notify::success(__('accueil.updated_info'));
        return Response::redirect('admin/accueil');
    });
});
Example #27
0
            $input['comments'] = 0;
        }
        if (empty($input['html'])) {
            $input['status'] = 'draft';
        }
        $post = Post::create($input);
        Extend::process('post', $post->id);
        Notify::success(__('posts.created'));
        return Response::redirect('admin/posts');
    });
    /*
    	Preview post
    */
    Route::post('admin/posts/preview', function () {
        $html = Input::get('html');
        // apply markdown processing
        $md = new Markdown();
        $output = Json::encode(array('html' => $md->transform($html)));
        return Response::create($output, 200, array('content-type' => 'application/json'));
    });
    /*
    	Delete post
    */
    Route::get('admin/posts/delete/(:num)', function ($id) {
        Post::find($id)->delete();
        Comment::where('post', '=', $id)->delete();
        Query::table(Base::table('post_meta'))->where('post', '=', $id)->delete();
        Notify::success(__('posts.deleted'));
        return Response::redirect('admin/posts');
    });
});
Example #28
0
function department_count()
{
    return Query::table(Base::table('posts'))->where('department', '=', department_id())->where('status', '=', 'published')->count();
}
Example #29
0
        $input = Input::get(array('username', 'email', 'real_name', 'password', 'bio', 'status', 'role'));
        $validator = new Validator($input);
        $validator->check('username')->is_max(3, __('users.username_missing', 2));
        $validator->check('email')->is_email(__('users.email_missing'));
        $validator->check('password')->is_max(6, __('users.password_too_short', 6));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/users/add');
        }
        $input['password'] = Hash::make($input['password']);
        $user = User::create($input);
        Extend::process('user', $user->id);
        Notify::success(__('users.created'));
        return Response::redirect('admin/users');
    });
    /*
    	Delete user
    */
    Route::get('admin/users/delete/(:num)', function ($id) {
        $self = Auth::user();
        if ($self->id == $id) {
            Notify::error(__('users.delete_error'));
            return Response::redirect('admin/users/edit/' . $id);
        }
        User::where('id', '=', $id)->delete();
        Query::table(Base::table('user_meta'))->where('user', '=', $id)->delete();
        Notify::success(__('users.deleted'));
        return Response::redirect('admin/users');
    });
});
            return Page::where('slug', '=', $str)->count() == 0;
        });
        $validator->check('title')->is_max(3, __('pages.title_missing'));
        $validator->check('slug')->is_max(3, __('pages.slug_missing'))->is_duplicate(__('pages.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('pages.slug_invalid'));
        if ($input['redirect']) {
            $validator->check('redirect')->is_url(__('pages.redirect_missing'));
        }
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/pages/add');
        }
        if (empty($input['name'])) {
            $input['name'] = $input['title'];
        }
        $input['show_in_menu'] = is_null($input['show_in_menu']) ? 0 : 1;
        $page = Page::create($input);
        Extend::process('page', $page->id);
        Notify::success(__('pages.created'));
        return Response::redirect('admin/pages');
    });
    /*
    	Delete Page
    */
    Route::get('admin/pages/delete/(:num)', function ($id) {
        Page::find($id)->delete();
        Query::table(Base::table('page_meta'))->where('page', '=', $id)->delete();
        Notify::success(__('pages.deleted'));
        return Response::redirect('admin/pages');
    });
});