예제 #1
0
 public function handleCreate()
 {
     $user_id = Auth::id();
     $snippet = new Snippet();
     $snippet->title = Input::get('title');
     $snippet->content = Input::get('content');
     $snippet->created_by_id = $user_id;
     $snippet->updated_by_id = $user_id;
     if (Input::get('save')) {
         $snippet->save();
         return Redirect::action('AdminSnippetController@index')->with('flash_edit_success', 'Hurray!You have created a Page Snippet');
     } elseif (Input::get('continue')) {
         $snippet->save();
         return Redirect::action('AdminSnippetController@edit', $snippet->id)->with('flash_edit_success', 'Hurray!Your updated information are saved,You can continue work...');
     } else {
         return Redirect::action('AdminSnippetController@index')->with('flash_dlt_success', 'OH!Sorry! I can not make a Page in this time');
     }
 }
예제 #2
0
 public function install($id)
 {
     $dir = FROG_ROOT . '/public/themes/' . $id . '/';
     $files = $this->scan_directory_recursively($dir, 'php');
     $data = array();
     $data['name'] = $id;
     // Layouts
     $layouts = array();
     $l = array();
     // Snippets
     $snippets = array();
     $s = array();
     foreach ($files as $file) {
         switch ($file['name']) {
             case 'layouts':
                 foreach ($file['content'] as $layout) {
                     $layouts[] = $layout['name'];
                     $l['name'] = Themr::theme_name($layout['name']);
                     $l['content_type'] = 'text/html';
                     $l['content'] = file_get_contents($layout['path']);
                     $layout = new Layout($l);
                     if (!$layout->save()) {
                         Flash::set('error', __('Layout has not been added. Name must be unique!'));
                     }
                 }
                 break;
             case 'snippets':
                 foreach ($file['content'] as $snippet) {
                     $snippets[] = $snippet['name'];
                     $s['name'] = $snippet['name'];
                     $s['filter_id'] = '';
                     $s['content'] = file_get_contents($snippet['path']);
                     $snippet = new Snippet($s);
                     if (!$snippet->save()) {
                         Flash::set('error', __('Snippet has not been added. Name must be unique!'));
                     }
                 }
                 break;
         }
     }
     // Serialize Layout and Snippet names
     $data['layout'] = serialize($layouts);
     $data['snippet'] = serialize($snippets);
     // Get Current Theme Info
     $theme_info = Themr::findTheme($id);
     // Save into Themr database table
     $theme = new Themr($data);
     if (!$theme->save()) {
         Flash::set('error', __('Theme has not been added. Name must be unique!'));
         redirect(get_url('plugin/themr'));
     } else {
         Flash::set('success', __('Theme <b>:name</b> has been added!', array(':name' => $theme_info['name'])));
         redirect(get_url('plugin/themr'));
     }
 }
 public function actionAdd()
 {
     $model = new Snippet();
     $data = Yii::app()->request->getPost('Snippet');
     if ($data) {
         $model->setAttributes($data);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('add', array('model' => $model));
 }
예제 #4
0
 function _edit($id)
 {
     $data = $_POST['snippet'];
     $data['id'] = $id;
     $snippet = new Snippet($data);
     if (!$snippet->save()) {
         Flash::set('error', __('Snippet :name has not been saved. Name must be unique!', array(':name' => $snippet->name)));
         redirect(get_url('snippet/edit/' . $id));
     } else {
         Flash::set('success', __('Snippet :name has been saved!', array(':name' => $snippet->name)));
         Observer::notify('snippet_after_edit', $snippet);
     }
     // save and quit or save and continue editing?
     if (isset($_POST['commit'])) {
         redirect(get_url('snippet'));
     } else {
         redirect(get_url('snippet/edit/' . $id));
     }
 }
예제 #5
0
 /**
  * Saves the edited Snippet.
  *
  * @todo Merge _edit() and edit()
  *
  * @param string $id Snippet id.
  */
 private function _edit($id)
 {
     $data = $_POST['snippet'];
     $data['id'] = $id;
     // CSRF checks
     if (isset($_POST['csrf_token'])) {
         $csrf_token = $_POST['csrf_token'];
         if (!SecureToken::validateToken($csrf_token, BASE_URL . 'snippet/edit')) {
             Flash::set('post_data', (object) $data);
             Flash::set('error', __('Invalid CSRF token found!'));
             Observer::notify('csrf_token_invalid', AuthUser::getUserName());
             redirect(get_url('snippet/edit/' . $id));
         }
     } else {
         Flash::set('post_data', (object) $data);
         Flash::set('error', __('No CSRF token found!'));
         Observer::notify('csrf_token_not_found', AuthUser::getUserName());
         redirect(get_url('snippet/edit/' . $id));
     }
     $snippet = new Snippet($data);
     if (!$snippet->save()) {
         Flash::set('post_data', (object) $data);
         Flash::set('error', __('Snippet :name has not been saved. Name must be unique!', array(':name' => $snippet->name)));
         redirect(get_url('snippet/edit/' . $id));
     } else {
         Flash::set('success', __('Snippet :name has been saved!', array(':name' => $snippet->name)));
         Observer::notify('snippet_after_edit', $snippet);
     }
     // save and quit or save and continue editing?
     if (isset($_POST['commit'])) {
         redirect(get_url('snippet'));
     } else {
         redirect(get_url('snippet/edit/' . $id));
     }
 }