public function action_delete() { $role = ORM::factory('Role', arr::get($_POST, 'id')); if (!$role->loaded()) { ajax::error(__('Role not found. Has it been deleted already?')); } try { $role->delete(); ajax::info(__('Deleted')); } catch (exception $e) { ajax::error(__('An uncaught error occurred: :error', array(':error' => $e->getMessage()))); } }
public function action_delete() { $vacation = ORM::factory('Vacation', arr::get($_POST, 'id', '')); if (!$vacation->loaded()) { ajax::error('Ferien blev ikke fundet. Er den allerede blevet slettet?'); } try { $vacation->delete(); ajax::success(); } catch (exception $e) { ajax::error('Der opstod en fejl: ' . $e->getMessage()); } }
public function action_toggleread() { $message = ORM::factory('Message', arr::get($_POST, 'id')); if (!$message->loaded()) { ajax::error(__('The message wasn\'t found. Has it already been deleted?')); } $message->read = arr::get($_POST, 'read', '0'); try { $message->save(); ajax::success(); } catch (exception $e) { ajax::error(__('An uncaught error occurred: :error', array(':error' => $e->getMessage()))); } }
public function action_getautosave() { if (!user::logged()) { ajax::error('You must be logged in'); } $user = user::get(); $autosave = ORM::factory('Page')->where('user_id', '=', $user->id)->where('type', '=', 'autosave')->find(); $content = ''; if ($autosave->loaded() && $autosave->content != '') { $content = $autosave->decode($autosave->content); $autosave->delete(); } ajax::success('', array('content' => $content, 'md5' => md5($content))); }
public function action_get() { $contenttype = ORM::factory('Contenttype', arr::get($_GET, 'id', '')); if (!$contenttype->loaded()) { ajax::error(__('Contenttype not found. Has it been deleted?')); } $items = array(); $contents = $contenttype->contents->find_all(); if ((bool) $contents->count()) { foreach ($contents as $content) { $items[] = array('id' => $content->id, 'title' => $content->title()); } } ajax::success('', array('id' => $contenttype->id, 'type' => $contenttype->type, 'slug' => $contenttype->slug, 'icon' => $contenttype->icon, 'hierarchical' => $contenttype->hierarchical, 'has_categories' => $contenttype->has_categories, 'has_tags' => $contenttype->has_tags, 'has_timestamp' => $contenttype->has_timestamp, 'has_thumbnail' => $contenttype->has_thumbnail, 'has_author' => $contenttype->has_author, 'display' => $contenttype->display, 'items' => $items)); }
public function action_twitter() { $redirect = ''; try { $connection = new TwitterOAuth(arr::get($this->creds, 'key'), arr::get($this->creds, 'secret')); $tmp = $connection->getRequestToken('http://morningpages.net/auth/twittercallback'); Session::instance()->set('twitter_oauth_token', arr::get($tmp, 'oauth_token', '')); Session::instance()->set('twitter_oauth_token_secret', arr::get($tmp, 'oauth_token_secret', '')); $redirect = $connection->getAuthorizeURL($tmp); } catch (exception $e) { ajax::error('Oh no! Something went wrong and we couldn\'t get a hold of Twitter! They might be too busy right now. You can either wait a bit and see if Twitter wakes up or use another way of logging in.'); site::redirect(); } site::redirect($redirect); }
public function action_takechallenge() { if (!user::logged()) { ajax::error('You must be logged in to sign up for the challenge!'); } $user = user::get(); if ($user->doing_challenge()) { ajax::error('You are already doing the challenge! Complete it first, then sign up again.'); } $challenge = ORM::factory('User_Challenge'); $challenge->user_id = $user->id; $challenge->start = $user->timestamp(); $challenge->progress = 0; if ($user->wrote_today()) { $challenge->progress = 1; } $challenge->save(); $user->add_event('Signed up for the 30 day challenge!'); ajax::success('Awesome! You have signed up for the challenge! Good luck!', array('progress' => $challenge->progress)); }
public function action_create() { $content = ORM::factory('Content', arr::get($_POST, 'parent', '')); if (!$content->loaded()) { ajax::error('The content wasn\'t found. Has it been deleted?'); } $title = arr::get($_POST, 'title', false); if (!$title) { $title = $content->title; } $clone = $content->copy(); $clone->splittest = $content->id; $clone->splittest_title = $title; try { $clone->save(); ajax::success('Splittest created', array('splittest' => array('id' => $clone->id, 'title' => $clone->splittest_title))); } catch (exception $e) { ajax::error('An error occurred and the splittest couldn\'t be created. The site said: ' . $e->getMessage()); } }
public function action_add() { $title = arr::get($_POST, 'title', false); if (!$title || empty($title)) { ajax::error('A title is required'); } $option = ORM::factory('Option'); $option->optiongroup_id = arr::get($_POST, 'group'); $option->title = $title; $option->key = arr::get($_POST, 'key', ''); $option->type = arr::get($_POST, 'type', 'text'); $option->description = arr::get($_POST, 'description', ''); $option->editable = arr::get($_POST, 'editable', '1'); try { $option->save(); ajax::success('Option added', array('option' => $option->info())); } catch (exception $e) { ajax::error('Something went wrong: ' . $e->getMessage()); } }
public function action_delete() { if ($_POST) { $id = arr::get($_POST, 'id', false); if (!$id) { ajax: error(__('No data recieved')); } try { if (is_array($id)) { foreach ($id as $fid) { ORM::factory('File', $fid)->delete(); } } else { ORM::factory('File', arr::get($_POST, 'id', false))->delete(); } ajax::success('ok'); } catch (exception $e) { ajax::error(__('An uncaught error occurred and the file couldn\'t be deleted: :error', array(':error' => $e->getMessage()))); } } }
public function action_xml() { if (!user::logged()) { ajax::error('You must be logged in to use this feature'); } $user = user::get(); $pages = $user->pages->where('type', '=', 'page')->find_all(); $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<channel>'; $namelen = strlen($user->username); $possessive = $user->username . "'s"; if (substr($user->username, $namelen - 1, $namelen) == 's') { $possessive = $user->username . "'"; } $xml .= '<title>' . $possessive . ' morning pages</title>'; $xml .= '<language>en-US</language>'; $xml .= '<author>' . $user->username . '</author>'; $xml .= '<pages>'; if ((bool) $pages->count()) { foreach ($pages as $page) { $xml .= '<page>'; $xml .= '<published>'; $xml .= '<date>' . $page->daystamp() . '</date>'; $xml .= '<timestamp>' . $page->created . '</timestamp>'; $xml .= '</published>'; $xml .= '<content><![CDATA[' . $page->rawcontent() . ']]></content>'; $xml .= '<wordcount>' . $page->wordcount . '</wordcount>'; $xml .= '</page>'; } } $xml .= '</pages>'; $xml .= '</channel>'; $this->response->headers('Content-Type', 'text/xml'); $this->response->body($xml); $this->response->send_file(true, 'pages.xml'); }
public function action_delete() { $user = $this->post(); if (arr::get($_POST, 'action') == 'transfer') { $newowner = arr::get($_POST, 'newowner', 3); $content = $user->contents->find_all(); if ((bool) $content->count()) { foreach ($content as $cont) { $cont->user_id = $newowner; $cont->save(); } } } try { $user->delete(); ajax::info(__('User deleted')); } catch (exception $e) { ajax::error(__('An uncaught error occurred: :error', array(':error' => $e->getMessage()))); } }
public function action_updateWidgets() { $dashboard = ORM::factory('Dashboard', arr::get($_POST, 'id')); if (!$dashboard->loaded()) { ajax::error('he dashboard wasn\'t found. Has it been deleted in the meantime?'); } $widgets = arr::get($_POST, 'widgets', false); if ($widgets && (bool) count($widgets)) { foreach ($widgets as $w) { $widget = ORM::factory('Widget', arr::get($w, 'id')); if ($widget->loaded()) { $widget->sizex = arr::get($w, 'sizex'); $widget->sizey = arr::get($w, 'sizey'); $widget->col = arr::get($w, 'col'); $widget->row = arr::get($w, 'row'); $widget->save(); } } } ajax::success('ok'); }
public function action_delete() { $block = ORM::factory('Block', arr::get($_POST, 'block_id')); if (!$block->loaded()) { ajax::error('Blokken blev ikke fundet.'); } try { $block->delete(); ajax::success('ok'); } catch (exception $e) { ajax::error('Der opstod en fejl og blokken kunne ikke slettes. Siden sagde: ' . $e->getMessage()); } }
public function action_addinternal() { $menu = ORM::factory('Menu', arr::get($_POST, 'id', '')); if (!$menu->loaded()) { ajax::error(__('The menu wasn\'t found. Has it been deleted in the meantime?')); } $content = ORM::factory('Content', arr::get($_POST, 'content', '')); if (!$content->loaded()) { ajax::error(__('The content wasn\'t found. Has it been deleted in the meantime?')); } $item = ORM::factory('Menu_Item'); $item->menu_id = $menu->id; $item->content_id = $content->id; $item->linktext = $content->title(); $item->titletext = $content->title(); $item->order = $menu->items->count_all(); try { $item->save(); ajax::success('', array('item' => $item->info())); } catch (exception $e) { ajax::error(__('An error occurred and the menuitem couldn\'t be added: :error', array(':error' => $e->getMessage()))); } }
public function action_addmeta() { $meta = ORM::factory('Blocktype_Meta'); $meta->blocktype_id = arr::get($_POST, 'blocktype_id', ''); $meta->key = arr::get($_POST, 'key', ''); $meta->value = arr::get($_POST, 'value', ''); try { $meta->save(); ajax::success('', array('meta' => $meta->info())); } catch (exception $e) { ajax::error($e->getMessage()); } }
public function action_upload() { $block = ORM::factory('Block', arr::get($_POST, 'blockid')); if (!$block->loaded()) { ajax::error('Block not found'); } try { $files = arr::get($_FILES, 'files', false); $file = ORM::factory('File'); $file->upload($files); $file->save(); $block->add('files', $file->id); $img = '<img src="' . $file->get_thumb(75, 75) . '" class="img-polaroid" />'; $view = View::factory('Cms/Content/blocks/gallery/image'); $view->file = $file; ajax::success('OK', array('file' => $view->render())); } catch (exception $e) { ajax::error('Fejl! Kunne ikke uploade filen: ' . $e->getMessage()); } }
public function action_deletepost() { if (!user::logged()) { ajax::error('You must be logged in to do that.'); } $id = arr::get($_POST, 'id', false); $object = ORM::factory('Talkreply', $id); if (!$object->loaded()) { ajax::error('I couldn\'t find that post. Has it already been deleted? Please contact us if you think this is a mistake'); } if (!user::can_edit($object)) { ajax::error('That doesn\'t seem to be your post to delete. Please contact us if you think this is a mistake'); } $object->deleted = time(); $object->deleted_by = user::get()->id; try { $object->talk->deleted = 0; $object->talk->save(); $object->save(); if ($object->op == 1) { $talk = $object->talk; $talk->deleted = 1; $talk->save(); } ajax::info('Your post has been deleted.'); } catch (exception $e) { Kohana::$log->add(Log::CRITICAL, 'Couldn\'t delete Model_Talkreply: :message. User_id: :userid, postreply_id: :replyid', array(':message' => $e->getMessage(), ':userid' => user::get()->id, ':replyid' => $object->id)); ajax::error('Something went wrong and your post couln\'t be deleted. Please try again or contact us if you think this is a mistake.'); } }
public function action_getblocks() { $content = ORM::factory('Content', arr::get($_POST, 'id', false)); if (!$content->loaded()) { ajax::error(__('The content wasn\'t found. Has it been deleted in the meantime?')); } $blocks = $content->blocks->where('parent', '=', arr::get($_POST, 'parent', '0'))->find_all(); $json = array(); if ($blocks->count()) { foreach ($blocks as $block) { $json[] = $block->info(); } } ajax::success('ok', array('blocks' => $json)); }
public function action_savesetting() { if (!user::logged()) { ajax::error('You must be logged in'); } $user = user::get(); $option = $user->option; $setting = arr::get($_POST, 'setting', false); $value = arr::get($_POST, 'value', false); if (!$setting || $value === false) { ajax::error('Something wen\'t wrong and your setting couldn\'t be saved. I received no data!'); } $update_timestamp = false; switch ($setting) { case 'reminder': $option->reminder = $value; $update_timestamp = true; break; case 'reminder_hour': $option->reminder_hour = $value; $update_timestamp = true; break; case 'reminder_minute': $option->reminder_minute = $value; $update_timestamp = true; break; case 'reminder_meridiem': $option->reminder_meridiem = $value; $update_timestamp = true; break; case 'timezone_id': $option->timezone_id = $value; $update_timestamp = true; break; case 'privacymode': $option->privacymode = $value; break; case 'privacymode_minutes': $option->privacymode_minutes = $value; break; case 'hemingwaymode': $option->hemingwaymode = $value; break; case 'public': $option->public = $value; break; case 'rtl': $option->rtl = $value; break; case 'language': $option->language = (int) $value; break; default: ajax::error('Something wen\'t wrong and your setting couldn\'t be saved. I received no data!'); break; } try { if ($update_timestamp) { $option->next_reminder = $user->get_next_reminder($user); } $option->save(); ajax::success('Saved'); } catch (ORM_Validation_Exception $e) { ajax::error('An error occurred and your setting couldn\'t be saved.', array('errors' => $e->errors())); } }
<?php $file = ORM::factory('file', arr::get($_POST, 'fileid')); if (!$file->loaded()) { ajax::error('Fejl! Filen blev ikke fundet. Er den blevet slettet i mellemtiden?'); } $width = arr::get($_POST, 'width', false); if (!$width) { $width = $file->width; } $height = arr::get($_POST, 'height', false); if (!$height) { $height = $file->height; } $file = $file->get($width, $height); $class = ''; if (arr::get($_POST, 'float', '') == 'left') { $class = 'alignleft'; } if (arr::get($_POST, 'float', '') == 'right') { $class = 'alignright'; } $file = '<img src="' . $file . '" width="' . $width . '" height="' . $height . '" alt="' . arr::get($_POST, 'alt', '') . '" class="' . $class . '" />'; ajax::success('ok', array('file' => $file));
* You should have received a copy of the GNU General Public License * along with Jeedom. If not, see <http://www.gnu.org/licenses/>. */ try { require_once dirname(__FILE__) . '/../../core/php/core.inc.php'; include_file('core', 'authentification', 'php'); if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__), -1234); } if (init('action') == 'remove') { $connection = connection::byId(init('id')); if (!is_object($connection)) { throw new Exception(__('Connexion inconnue. Vérifiez l\'id', __FILE__)); } $connection->remove(); ajax::success(); } if (init('action') == 'ban') { $connection = connection::byId(init('id')); if (!is_object($connection)) { throw new Exception(__('Connexion inconnue. Vérifiez l\'id', __FILE__)); } $connection->setStatus('Ban'); $connection->save(); ajax::success(); } throw new Exception(__('Aucune méthode correspondante à : ', __FILE__) . init('action')); /* * *********Catch exeption*************** */ } catch (Exception $e) { ajax::error(displayExeption($e), $e->getCode()); }
public function action_filebrowser_upload() { try { $file = ORM::factory('File')->upload($_FILES['files']); ajax::success('OK', array('file' => $file->info())); } catch (exception $e) { ajax::error(__('An error occurred and the file :filename couldn\'t be uploaded: :error', array(':error' => $e->getMessage(), ':filename' => $file['name'][0]))); } }