本文整理汇总了PHP中Sprig类的典型用法代码示例。如果您正苦于以下问题:PHP Sprig类的具体用法?PHP Sprig怎么用?PHP Sprig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sprig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Overload Sprig::delete() to update child articles
* to become children of the uncategorized subcategory
*/
public function delete(Database_Query_Builder_Delete $query = NULL) {
Kohana::$log->add(Kohana::DEBUG, 'Beginning subcategory deletion for subcategory_id='.$this->id);
if (Kohana::$profiling === TRUE)
{
$benchmark = Profiler::start('blog', 'delete subcategory');
}
$uncategorized = Sprig::factory('subcategory', array('name'=>'uncategorized'))->load();
// Modify category IDs for all child articles
try
{
DB::update('articles')->value('subcategory_id', $uncategorized->id)
->where('subcategory_id', '=', $this->id)->execute();
}
catch (Database_Exception $e)
{
Kohana::$log->add(Kohana::ERROR, 'Exception occured while modifying deleted subcategory\'s articles. '.$e->getMessage());
return $this;
}
if (isset($benchmark))
{
Profiler::stop($benchmark);
}
return parent::delete($query);
}
示例2: revoke
/**
* Revoke access to $role for resource
*
* @param mixed string role name or Model_Role object
* @param string resource identifier
* @param string action [optional]
* @param string condition [optional]
* @return void
*/
public static function revoke($role, $resource, $action = NULL, $condition = NULL)
{
// Normalise $role
if (!$role instanceof Model_Role) {
$role = Sprig::factory('role', array('name' => $role))->load();
}
// Check role exists
if (!$role->loaded()) {
// Just return without deleting anything
return;
}
$model = Sprig::factory('aacl_rule', array('role' => $role->id));
if ($resource !== '*') {
// Add normal reources, resource '*' will delete all rules for this role
$model->resource = $resource;
}
if ($resource !== '*' and !is_null($action)) {
$model->action = $action;
}
if ($resource !== '*' and !is_null($condition)) {
$model->condition = $condition;
}
// Delete rule
$model->delete();
}
示例3: __construct
public function __construct(array $options = NULL)
{
parent::__construct($options);
if ($this->choices === NULL) {
$this->choices = Sprig::factory($this->model)->select_list();
}
}
示例4: ajax_response
public function ajax_response()
{
session_start();
// Проверяем, что форма была разблокирована
if (isset($_SESSION['qaptcha_key']) and $_SESSION['qaptcha_key'] == 'iqaptcha' and isset($_POST['iqaptcha']) and empty($_POST['iqaptcha'])) {
// Проверяем заполненность всех обязательных полей
if (!empty($_POST['fio']) and !empty($_POST['phone']) and !empty($_POST['message'])) {
// Обезопасим входные данные
$this->set_safe($_POST, FALSE);
// Сохраняем в админке
// Создаем запрос
$feedback = Sprig::factory('feedback');
$feedback->values($_POST);
$feedback->create();
// Если в настройках задан email администратора - отправляем письмо
if (!empty($this->fos_email)) {
// Создаем объект PHPMailer и задаем начальные настройки
$mail = new PHPMailer();
$mail->CharSet = 'utf-8';
$mail->From = 'no-reply@' . $_SERVER['HTTP_HOST'];
$mail->FromName = $_SERVER['HTTP_HOST'];
$mail->AddAddress($this->fos_email, 'Получатель запросов');
$mail->Subject = 'Сообщение с сайта от: ' . $_POST['fio'];
$mail->Body = $this->email_tpl_render('feedbackadminmail', $_POST);
$mail->Send();
}
return 'true';
}
}
return 'false';
}
示例5: ajax_response
public function ajax_response()
{
session_start();
// Проверяем, что форма была разблокирована
if (isset($_SESSION['qaptcha_key']) and $_SESSION['qaptcha_key'] == 'iqaptcha' and isset($_POST['iqaptcha']) and empty($_POST['iqaptcha'])) {
// Проверяем заполненность всех обязательных полей
if (!empty($_POST['fio']) and !empty($_POST['phone']) and !empty($_POST['catalog_id']) and !empty($_POST['object_data'])) {
// Обезопасим входные данные
$this->set_safe($_POST, FALSE);
// Добавим переводы строк
$_POST['object_data'] = str_replace(';', "\r\n", $_POST['object_data']);
// Сохраняем в админке
// Создаем запрос
$reqbuy = Sprig::factory('reqbuy');
$reqbuy->values($_POST);
$reqbuy->create();
// Если в настройках задан email администратора - отправляем письмо
if (!empty($this->reqbuy_email)) {
// Создаем объект PHPMailer и задаем начальные настройки
$mail = new PHPMailer();
$mail->CharSet = 'utf-8';
$mail->From = 'no-reply@' . $_SERVER['HTTP_HOST'];
$mail->FromName = $_SERVER['HTTP_HOST'];
$mail->AddAddress($this->reqbuy_email, 'Получатель запросов');
$mail->Subject = 'Заявка на покупку объекта от: ' . $_POST['fio'];
$mail->Body = $this->email_tpl_render('reqbuyadminmail', $_POST);
$mail->Send();
}
return 'true';
}
}
return 'false';
}
示例6: action_new
/**
* Create a new article
*/
public function action_new()
{
Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Admin_Article::action_new');
$this->template->content = View::factory('blog/admin/article_form')->set('legend', __('Create Article'))->set('submit', __('Save'))->set('slug_editable', FALSE)->set('comment_needed', FALSE)->bind('article', $article)->bind('errors', $errors);
$article = Sprig::factory('article')->values($_POST);
$article->author = $this->a1->get_user();
if ($_POST) {
try {
$article->create();
//$article->load();
$statistic = Sprig::factory('statistic', array('article' => $article))->create();
Message::instance()->info('The article, :title, has been created.', array(':title' => $article->title));
if (!$this->_internal) {
$this->request->redirect($this->request->uri(array('action' => 'list')));
}
} catch (Validate_Exception $e) {
$errors = $e->array->errors('admin');
}
}
// Set template scripts and styles
$this->template->scripts[] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js';
$this->template->scripts[] = Route::get('media')->uri(array('file' => 'js/markitup/jquery.markitup.js'));
$this->template->scripts[] = Route::get('media')->uri(array('file' => 'js/markitup/sets/html/set.js'));
$this->template->styles[Route::get('media')->uri(array('file' => 'js/markitup/skins/markitup/style.css'))] = 'screen';
$this->template->styles[Route::get('media')->uri(array('file' => 'js/markitup/sets/html/style.css'))] = 'screen';
}
示例7: action_update
/**
* Update an existing post
*
*/
public function action_update()
{
$this->request->response = View::factory('shindig/admin/edit_post')->set('form_title', __('Update Post'))->bind('use_authors', $use_authors)->bind('site_url', $site_url)->bind('errors', $errors)->bind('post', $post);
$use_authors = Kohana::config('shindig.use_authors');
$site_url = URL::site('blog', TRUE) . '/';
$post = Sprig::factory('shindig_post')->values(array('id' => $this->request->param('id')))->load();
if (isset($_POST['shindig_post'])) {
try {
/*
if ($tags = Arr::get($_POST, 'tags'))
{
foreach ($tags as $tag)
{
// check to see if tag exsists.
// Get id if it does, create it if it doesn't
}
}
*/
$post->values($_POST)->update();
Request::instance()->redirect(Route::get(Kohana::config('shindig.post_create_redirect.route'))->uri(array('action' => Kohana::config('shindig.post_create_redirect.action'), 'id' => $post->id)));
} catch (Validate_Exception $e) {
$errors = $e->array->errors('shindig/crud');
}
}
}
示例8: factory
/**
* Loads the “Invite” model with the given primary key
*
* @param primary key to load
* @param dummy value to conform with Sprig
* @return Model_Invite
*/
public static function factory($token, array $dummy = array())
{
if (Model_Invite::valid($token)) {
$dummy['token'] = $token;
}
return parent::factory('invite', $dummy);
}
示例9: load
public function load(Database_Query_Builder_Select $query = NULL, $limit = NULL)
{
if (!$query) {
$query = DB::select()->order_by('id', 'DESC')->order_by('created_on', 'DESC');
}
return Sprig::factory('Shindig_Post')->load($query, $limit);
}
示例10: action_recent_comments
/**
* Show recent comments
*/
public function action_recent_comments()
{
Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Blog_Stats::action_recent_comments');
$this->template->content = View::factory('blog/stats/comments')->set('legend', __('Recent Comments'))->bind('comments', $comments);
$limit = $this->request->param('limit', NULL);
$search = Sprig::factory('blog_search');
$comments = $search->get_recent_comments($limit);
}
示例11: action_stats_reset
/**
* Reset daily statistics
*/
public function action_stats_reset()
{
$search = Sprig::factory('blog_search');
$articles = $search->search_by_state('published');
foreach ($articles as $article) {
$article->statistic->load()->reset()->update();
}
}
示例12: __construct
public function __construct($template = NULL, array $partials = NULL)
{
// Шаблон берем от метода Add
$template = 'admin/benefits/add';
parent::__construct($template, $partials);
// Создаем объект текущего преимущества
$this->cur_benefit = Sprig::factory('benefits', array('id' => $this->id))->load()->as_array();
}
示例13: __set
/**
* Overload Sprig::__set() to serialize comments
*
* @param string variable name
* @param string variable value
* @return void
*/
public function __set($key, $value)
{
if ($key == 'comments') {
$this->comment = serialize($value);
return;
}
parent::__set($key, $value);
}
示例14: action_details
public function action_details()
{
$plugin = Sprig::factory('plugin', array('id' => $this->request->param('id')))->load();
if (!$plugin->loaded()) {
notice::add(__('Invalid Plugin'), 'error');
Request::instance()->redirect(Request::instance('admin')->uri(array('action' => 'list')));
}
}
示例15: action_view
/**
* Attempt to find a page in the CMS, return the response
*
* @param string The url to load, will be autodetected if needed
* @return void
*/
public function action_view($url = NULL)
{
if (Kohana::$profiling === TRUE) {
// Start a new benchmark
$benchmark = Profiler::start('Kohanut', 'Kohanut Controller');
}
// If no $url is passed, default to the server request uri
if ($url === NULL) {
$url = $_SERVER['REQUEST_URI'];
}
// Trim off Kohana::$base_url
$url = preg_replace('#^' . Kohana::$base_url . '#', '', $url);
// Ensure no trailing slash
$url = preg_replace('/\\/$/', '', $url);
// Ensure no leading slash
$url = preg_replace('/^\\//', '', $url);
// Remove anything ofter a ? or #
$url = preg_replace('/[\\?#].+/', '', $url);
// Try to find what to do on this url
try {
// Make sure the url is clean. See http://www.faqs.org/rfcs/rfc2396.html see section 2.3
// TODO - this needs to be better
if (preg_match("/[^\\/A-Za-z0-9-_\\.!~\\*\\(\\)]/", $url)) {
Kohana::$log->add('INFO', "Kohanut - Request had unknown characters. '{$url}'");
throw new Kohanut_Exception("Url request had unknown characters '{$url}'", array(), 404);
}
// Check for a redirect on this url
Sprig::factory('kohanut_redirect', array('url', $url))->go();
// Find the page that matches this url, and isn't an external link
$query = DB::select()->where('url', '=', $url)->where('islink', '=', 0);
$page = Sprig::factory('kohanut_page')->load($query);
if (!$page->loaded()) {
// Could not find page in database, throw a 404
Kohana::$log->add('INFO', "Kohanut - Could not find '{$url}' (404)");
throw new Kohanut_Exception("Could not find '{$page->url}'", array(), 404);
}
// Set the status to 200, rather than 404, which was set by the router with the reflectionexception
Kohanut::status(200);
$out = $page->render();
} catch (Kohanut_Exception $e) {
// Find the error page
$error = Sprig::factory('kohanut_page', array('url' => 'error'))->load();
// If i couldn't find the error page, just give a generic message
if (!$error->loaded()) {
Kohanut::status(404);
$this->request->response = View::factory('kohanut/generic404');
return;
}
// Set the response
$out = $error->render();
}
if (isset($benchmark)) {
// Stop the benchmark
Profiler::stop($benchmark);
}
// Set the response
$this->request->response = $out;
}