Наследование: extends AppController
Пример #1
1
 /**
  * Test controller when logged in but a non-numeric post ID
  */
 public function testControlLoggedInWithNonNumericPostID()
 {
     $this->simulateLogin('*****@*****.**');
     $_GET["t"] = 'notapostID45';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertTrue(strpos($results, "Post not found") > 0, "no post");
 }
Пример #2
1
 public function testControlWithNonExistentPluginActivated()
 {
     $data[] = FixtureBuilder::build('instances', array('network_user_id' => '10', 'network_username' => 'ev', 'is_public' => 1, 'network' => 'twitter'));
     $data[] = FixtureBuilder::build('posts', array('post_id' => '1001', 'author_user_id' => '10', 'author_username' => 'ev', 'post_text' => 'This is a test post', 'retweet_count_cache' => '5', 'network' => 'twitter', 'is_protected' => 0));
     $data[] = FixtureBuilder::build('users', array('user_id' => '10', 'username' => 'ev', 'is_protected' => '0', 'network' => 'twitter'));
     $data[] = FixtureBuilder::build('plugins', array('name' => "Nonexistent", 'folder_name' => 'idontexist', 'is_active' => 1));
     $_GET["t"] = '1001';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertPattern("/This is a test post/", $results);
     $this->assertNoPattern("/No plugin object defined for/", $results);
     //assert plugin has been deactivated
     $sql = "SELECT * FROM " . $this->table_prefix . "plugins WHERE folder_name='idontexist';";
     $stmt = PluginMySQLDAO::$PDO->query($sql);
     $data = $stmt->fetch(PDO::FETCH_ASSOC);
     $this->assertEqual(0, $data['is_active']);
 }
    function rbs_ajax_create_article()
    {
        if (isset($_POST['galleryid']) && (int) $_POST['galleryid'] && isset($_POST['categoryid']) && (int) $_POST['categoryid']) {
            $galleryid = intval($_POST['galleryid']);
            $categoryid = intval($_POST['categoryid']);
            $post_info = get_post($galleryid);
            if (gettype($post_info) != 'object') {
                echo '<p><strong>' . __('Post not created. Error: ', 'rbs_gallery') . '</strong><br><p>empty gallery id</p>';
                die;
            }
            $Poster = new PostController();
            $title = $post_info->post_title;
            if (isset($_POST['articletitle']) && $_POST['articletitle']) {
                $title = wp_kses_data($_POST['articletitle']);
            }
            $slug = 'post_' . $post_info->post_name;
            if (isset($_POST['articleslug']) && $_POST['articleslug']) {
                $slug = wp_kses_data($_POST['articleslug']);
            }
            $Poster->set_title($title);
            $Poster->add_category(array($categoryid));
            $Poster->set_type("post");
            $Poster->set_content('[robo-gallery id="' . $galleryid . '"]');
            $Poster->set_author_id(get_current_user_id());
            $Poster->set_post_slug($slug);
            $Poster->set_post_state("publish");
            $Poster->create();
            $posts_id = get_post_meta($galleryid, 'rbs_gallery_id', true);
            if (!$posts_id) {
                $posts_id = array();
            } else {
                $posts_id = json_decode($posts_id, true);
            }
            $postId = $Poster->PC_current_post_id;
            $posts_id[] = $postId;
            update_post_meta($galleryid, 'rbs_gallery_id', json_encode($posts_id, JSON_FORCE_OBJECT));
            if (isset($Poster->errors) && count($Poster->errors)) {
                echo '<p><strong>' . __('Post not created. Error: ', 'rbs_gallery') . '</strong><br>';
                for ($i = 0; $i < count($Poster->errors); $i++) {
                    $error = $Poster->errors[$i];
                    echo ' &nbsp;&nbsp; - ' . $error . '<br>';
                }
                echo '</p>';
            } else {
                echo '<h3>' . __('Post ', 'rbs_gallery') . '"' . $title . '"' . __(' created', 'rbs_gallery') . '</h3>';
                echo '<p>
					<a href="' . esc_url(get_edit_post_link($postId)) . '" class="button button-small" target="_blank">
						' . __('Edit', 'rbs_gallery') . '</a> 
					<a  href="' . esc_url(get_permalink($postId)) . '"  class="button button-small" target="_blank">
						' . __('Preview', 'rbs_gallery') . '</a> 
				</p>';
            }
        } else {
            echo '<p><strong>' . __('Error: input value', 'rbs_gallery') . '</strong></p>';
        }
        die;
    }
Пример #4
0
<?php

require 'models/' . changesingulare($resource) . '.php';
$cont = new PostController();
$modl = new Post();
//複数形を単数形に変換
function changesingulare($value)
{
    if ($value == 'posts') {
        return 'post';
    }
}
//$action = $_GET['action'];
//var_dump($_GET['action']);
switch ($action) {
    case 'index':
        //各条件
        $cont->index();
        break;
    case 'show':
        //各条件
        $cont->show(10);
        break;
    case 'edit':
        //各条件
        $cont->edit(20);
        break;
    case 'destroy':
        //各条件
        $cont->destroy(10);
        break;
Пример #5
0
 /**
  *
  * @param PostController $sender Sending controller instance.
  * @param array $args Event arguments.
  */
 public function postController_render_before($sender, $args)
 {
     $data = $sender->data('Comments');
     if (is_object($data)) {
         RoleModel::setUserRoles($data->result(), 'InsertUserID');
     }
 }
 public function testCleanXSS()
 {
     $with_xss = true;
     $builders = $this->buildPublicPostWithMixedAccessResponses($with_xss);
     $_GET["t"] = '1001';
     $_GET['n'] = 'twitter';
     //Log in and see private replies and retweets
     $this->simulateLogin('*****@*****.**');
     //default menu item
     $_GET["v"] = 'default';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertPattern("/This is a test post&#60;script&#62;alert\\(&#39;wa&#39;\\);&#60;\\/script&#62;/", $results);
 }
Пример #7
0
 /**
  *
  * @param PostController $Sender
  * @param type $RecordType
  * @param type $ID
  * @throws type
  */
 public function postController_facebook_create($Sender, $RecordType, $ID)
 {
     if (!$this->socialReactions()) {
         throw permissionException();
     }
     $Row = getRecord($RecordType, $ID, true);
     if ($Row) {
         $Message = sliceParagraph(Gdn_Format::plainText($Row['Body'], $Row['Format']), 160);
         if ($this->accessToken() && $Sender->Request->isPostBack()) {
             $R = $this->api('/me/feed', array('link' => $Row['ShareUrl'], 'message' => $Message));
             $Sender->setJson('R', $R);
             $Sender->informMessage(t('Thanks for sharing!'));
         } else {
             $Get = array('app_id' => c('Plugins.Facebook.ApplicationID'), 'link' => $Row['ShareUrl'], 'name' => Gdn_Format::plainText($Row['Name'], 'Text'), 'description' => $Message, 'redirect_uri' => url('/post/shared/facebook', true));
             $Url = 'http://www.facebook.com/dialog/feed?' . http_build_query($Get);
             redirect($Url);
         }
     }
     $Sender->render('Blank', 'Utility', 'Dashboard');
 }
Пример #8
0
<?php

require "helper/cabecalho.php";
$url = explode("/post/", $_SERVER['REQUEST_URI']);
$post = new PostController();
$postModel = $post->getPostBySeo($url[1]);
?>
	
	<div class="container">
		<div class="row">
			
			<div class="col-sm-9 post" id="conteudo-pagina">
				
				<input type="hidden" id="id-post" value="<?php 
echo $postModel->Id;
?>
">
				
				<h1 class="titulo"><?php 
echo $postModel->Titulo;
?>
</h1>
				<h2 class="categoria">
					<?php 
$i = 0;
foreach ($postModel->Categorias as $categoria) {
    if ($i > 0) {
        echo " / ";
    }
    echo "\t<a href='categoria/" . $categoria->Seo . "'>" . $categoria->Nome . "</a>";
    $i++;
Пример #9
0
<?php

/**
 * @author Harri Bell-Thomas <*****@*****.**>
 * @created January, 2014 
 * @version 1.0.0
 * @license Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
 * @license url : http://creativecommons.org/licenses/by-sa/3.0/
*/
/*  INCLUDE WRAPPER  */
require_once 'class.postcontroller.php';
/*  USAGE  */
$Poster = new PostController();
$Poster->set_title("My Post's Title");
$Poster->add_category(array(1, 2, 8));
$Poster->set_type("post");
$Poster->set_content("This my awesome content");
$Poster->set_author_id(1);
$Poster->set_post_slug('updated_post');
//$Poster->set_page_template( "login-infusion-page.php" );
$Poster->set_post_state("publish");
$Poster->search('title', 'Old Post');
$Poster->update();
//$Poster->create();
//$Poster->PrettyPrintAll();
$Poster->get_var('slug');
Пример #10
0
 /**
  * Test controller when logged in but a non-numeric post ID
  */
 function testControlLoggedInWithNonNumericPostID()
 {
     $_SESSION['user'] = '******';
     $_REQUEST["t"] = 'notapostID45';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertTrue(strpos($results, "Post not found") > 0, "no post");
 }
Пример #11
0
 /**
  *
  *
  * @param PostController $Sender
  * @param type $RecordType
  * @param type $ID
  * @throws type
  */
 public function postController_googlePlus_create($Sender, $RecordType, $ID)
 {
     $Row = GetRecord($RecordType, $ID);
     if ($Row) {
         $Message = SliceParagraph(Gdn_Format::plainText($Row['Body'], $Row['Format']), 160);
         $Get = array('url' => $Row['ShareUrl']);
         $Url = 'https://plus.google.com/share?' . http_build_query($Get);
         redirect($Url);
     }
     $Sender->render('Blank', 'Utility', 'Dashboard');
 }
Пример #12
0
 /**
  * Override the PostController->Discussion() method before render to use our view instead.
  *
  * @param PostController $sender Sending controller instance.
  */
 public function postController_beforeDiscussionRender_handler($sender)
 {
     // Override if we are looking at the question url.
     if ($sender->RequestMethod == 'question') {
         $sender->Form->addHidden('Type', 'Question');
         $sender->title(t('Ask a Question'));
         $sender->setData('Breadcrumbs', array(array('Name' => $sender->data('Title'), 'Url' => '/post/question')));
     }
 }
Пример #13
0
$base = $GLOBALS['base_url'];
$url = $_SERVER["REQUEST_URI"];
if ($part_count === 4) {
    $_GET['cat'] = $url_parts[1];
    $_GET['search'] = urldecode($url_parts[2]);
    $_GET['page'] = (int) $url_parts[$part_count - 1];
    //page is always last part of url or 1
    try {
        $cat = $_GET['cat'];
        $page = $_GET['page'];
        $search = $_GET['search'];
        $parsedown = new Parsedown();
        $post_views = new PostViews($parsedown);
        $db = MongoConnection();
        $db_getter = new MongoGetter($db);
        $post_controller = new PostController($db_getter, $post_views);
        $mongo_results = $post_controller->getSearchPagePosts($page, $cat, $search);
        //false if no result set
        $template = file_get_contents($GLOBALS['template_dir'] . "/base_page.txt");
        $title = $cat . " search '" . $search . "' page " . $page . " - " . $_SERVER['HTTP_HOST'];
        $desc = $_SERVER['HTTP_HOST'] . " - browse " . $cat . " search '" . $search . "' page " . $page;
        if ($mongo_results) {
            //need to special chars anything using $search param that gets inserted into HTML
            $tmplt_data = array();
            $tmplt_data["title"] = htmlspecialchars($title, ENT_QUOTES);
            $tmplt_data["description"] = htmlspecialchars($desc, ENT_QUOTES);
            $tmplt_data["styles"] = "";
            $tmplt_data["scripts"] = "";
            $tmplt_data["base"] = $base;
            $tmplt_data["category"] = $cat;
            $tmplt_data["search_placeholder"] = htmlspecialchars("search " . $cat, ENT_QUOTES);
Пример #14
0
 /**
  * Add needed resources to the page.
  *
  * @param PostController $sender Sending controller instance.
  * @param array $args Event's arguments.
  */
 public function postController_render_before($sender, $args)
 {
     if (!$this->isWelcomePostActive($sender->Request, $categoryID)) {
         return;
     }
     $sender->addDefinition('WelcomePostPopupMessage', t('Please introduce yourself to the community!'));
     $sender->addJsFile('welcomepost.js', 'plugins/welcomepost');
     $sender->addCssFile('welcomepost.css', 'plugins/welcomepost');
 }
Пример #15
0
 /**
  * Global function to call PostController::get_controllers
  * @see PostController::get_controllers
  */
 function get_post_controllers($args = null)
 {
     return PostController::get_controllers($args);
 }
Пример #16
0
 public function testPluginMenuGeneration()
 {
     $instance_builder = FixtureBuilder::build('instances', array('network_user_id' => '10', 'network_username' => 'ev', 'is_public' => 1, 'network' => 'facebook'));
     $post_builder = FixtureBuilder::build('posts', array('id' => 1, 'post_id' => '1001', 'author_user_id' => '10', 'author_username' => 'ev', 'post_text' => 'This is a test post', 'retweet_count_cache' => '5', 'network' => 'facebook', 'is_protected' => 0, 'location' => 'Clarence, NY 14031, USA'));
     $user_builder = FixtureBuilder::build('users', array('user_id' => '10', 'username' => 'ev', 'is_protected' => '0', 'network' => 'facebook'));
     $data[] = FixtureBuilder::build('plugins', array('name' => "Facebook", 'folder_name' => 'facebook', 'is_active' => 1));
     $data[] = FixtureBuilder::build('plugins', array('name' => "YouTube", 'folder_name' => 'youtube', 'is_active' => 1));
     // Disable debug (because then the controller sets reporting to E_STRICT) and enable warnings
     $this->config->setValue('debug', 0);
     $old_level = error_reporting();
     error_reporting(E_WARNING);
     $_GET['t'] = '1001';
     $_GET['n'] = 'facebook';
     $_GET['v'] = 'likes';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertNoPattern("/PHP error/", $results);
     $this->assertPattern("/n=facebook.*Replies/", $results);
     error_reporting($old_level);
 }
Пример #17
0
<?php

// Connect to the DB.
require_once 'app/db/doConnection.php';
// Include the PostController
require_once 'app/controllers/PostController.php';
if (isset($_POST['postAdd'])) {
    $post = new PostController();
    try {
        $result = $post->add();
        print $result;
    } catch (Exception $e) {
        print $e->getMessage();
    }
}
Пример #18
0
				<div class="col-lg-12">
					
					<a href="blog-posts-form" class="btn btn-primary pull-right"><i class="icon-plus icon-white"></i> Novo post</a>
					
					<table class="table table-hover">
						<thead>
							<tr>
								<th style="width: 160px">Data criação</th>
								<th>Título</th>
								<th style="width: 15%">Usuário</th>
								<th style="width: 20%"></th>
							</tr>
						</thead>
						<tbody>
							<?php 
foreach (PostController::getAll("", "DataCriacao DESC") as $post) {
    echo "\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<td>" . DefaultHelper::converterData($post->DataCriacao) . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $post->Titulo . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t<td>" . $post->Usuario_Nome . "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t<td class='align-right'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class='btn-group'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<!--i class='fa fa-fw fa-bars'></i--><span class='caret'></span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<ul class='dropdown-menu dropdown-menu-right'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href='blog-posts-form?id=" . $post->Id . "'>Editar</a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href='#' class='abrir-modal-avaliacoes' alt='" . $post->Id . "' data-toggle='modal' data-target='#modal-avaliacoes'>Avaliações</a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li role='separator' class='divider'></li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href='#' class='del' value='" . $post->Id . "' style='color: red;'>Excluir</button>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t</tr>";
}
?>
						</tbody>
					</table>
				</div>
			</div>
			
		</div>
		
	</div>
	
	<!-- Avaliações do post -->
	<div class="modal fade" id="modal-avaliacoes" tabindex="-1" role="dialog" aria-labelledby="modal-avaliacoes-label">
		<div class="modal-dialog">
Пример #19
0
 /**
  * 
  * @param PostController $Sender
  * @param type $RecordType
  * @param type $ID
  * @throws type
  */
 public function PostController_Facebook_Create($Sender, $RecordType, $ID)
 {
     if (!$this->SocialReactions()) {
         throw PermissionException();
     }
     //      if (!Gdn::Request()->IsPostBack())
     //         throw PermissionException('Javascript');
     $Row = GetRecord($RecordType, $ID);
     if ($Row) {
         $Message = SliceParagraph(Gdn_Format::PlainText($Row['Body'], $Row['Format']), 160);
         if ($this->AccessToken() && $Sender->Request->IsPostBack()) {
             $R = $this->API('/me/feed', array('link' => $Row['ShareUrl'], 'message' => $Message));
             $Sender->SetJson('R', $R);
             $Sender->InformMessage(T('Thanks for sharing!'));
         } else {
             //            http://www.facebook.com/dialog/feed?app_id=231546166870342&redirect_uri=http%3A%2F%2Fvanillicon.com%2Fredirect%2Ffacebook%3Fhash%3Daad66afb13105676dffa79bfe2b8595f&link=http%3A%2F%2Fvanillicon.com&picture=http%3A%2F%2Fvanillicon.com%2Faad66afb13105676dffa79bfe2b8595f.png&name=Vanillicon&caption=What%27s+Your+Vanillicon+Look+Like%3F&description=Vanillicons+are+unique+avatars+generated+by+your+name+or+email+that+are+free+to+make+%26+use+around+the+web.+Create+yours+now%21
             $Get = array('app_id' => C('Plugins.Facebook.ApplicationID'), 'link' => $Row['ShareUrl'], 'name' => Gdn_Format::PlainText($Row['Name'], 'Text'), 'description' => $Message, 'redirect_uri' => Url('/post/shared/facebook', TRUE));
             $Url = 'http://www.facebook.com/dialog/feed?' . http_build_query($Get);
             Redirect($Url);
         }
     }
     $Sender->Render('Blank', 'Utility', 'Dashboard');
 }
Пример #20
0
    }
    
    function GetTagsIds(){
    	var tags = [];
        $("#tagsList .Token").each(function() {
        	if ($.isNumeric($(this).attr("data-value")))
        	{
        		tags.push($(this).attr("data-value"));
        	}          
        });

        return tags;        		
    }

    function GetCategoriasIds(){
    	var categorias = [];
        $("#categoriasList .Token").each(function() {
        	categorias.push($(this).attr("data-value"));
        });
		
        return categorias;
    }
</script>

<?php 
//error_log("______".$post->Titulo);
if (isset($_GET['id'])) {
    $post = PostController::getPost($_GET['id']);
    echo "\t<script>\n\t\t\t\t\t\$('#id').val('" . $post->Id . "');\n                    \$('#titulo').val('" . addslashes($post->Titulo) . "');\n                    \$('#seo').val('" . $post->Seo . "');\n                    \$('#corpo').html('" . $post->Corpo . "');\n\t\t\t\t\t" . ($post->IdUsuario > 0 ? "\$('#criador').show().text('" . $post->Usuario_Nome . "'); " : "") . "\n\t\t\t\t\t\$('#subtitle').text('/ Editar post');\n\t\t\t\t</script>";
}
include "helper/rodape.php";
Пример #21
0
<?php

require "helper/cabecalho.php";
$url = explode("/categoria/", $_SERVER['REQUEST_URI']);
$categoria = new CategoriaController();
$categoriaModel = $categoria->getCategoriaBySeo($url[1]);
$posts = new PostController();
$totalPosts = $posts->getPostsCountByCategoria($categoriaModel->Id);
?>
	
	<div class="container">
		<div class="row">
			
			<div class="col-sm-9" id="conteudo-pagina">
				
				<div id="topo-home">
					
					<h2 class="titulo-bloco">
						<span>Categoria:</span> 
						<?php 
echo $categoriaModel->Nome;
?>
					</h2>
					
					<div class="row lista-posts">
					
						<?php 
foreach ($posts->getPostsByCategoria($categoriaModel->Id, 0, 5) as $post) {
    echo "\t<div class='col-sm-12'>\n\t\t\t\t\t\t\t\t\t\t\t<div class='post-thumb horizontal lista' url='" . $post->Seo . "'>\n\t\t\t\t\t\t\t\t\t\t\t\t<div class='imagem'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t" . (!empty($post->Capa) ? "<img src='" . $post->Capa . "'>" : "") . "\n\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t<div class='dados'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<h1 class='titulo'>" . $post->Titulo . "</h1>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class='data'>Publicado em " . DefaultHelper::converterData($post->DataCriacao, true) . "</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class='nota rateit' data-rateit-min='0' data-rateit-max='5' data-rateit-readonly='true' data-rateit-value='" . $post->NotaGeral . "'></div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class='resumo'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $post->Corpo . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class='acoes'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href='post/" . $post->Seo . "' class='btn btn-link link'>Continuar lendo</a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t</div>";
}
?>
Пример #22
0
<?php

chdir("..");
require_once 'init.php';
require_once 'controller/class.PostController.php';
$controller = new PostController();
echo $controller->go();
Пример #23
0
 /**
  * Add javascript to the post/edit discussion page so that tagging autocomplete works.
  *
  * @param PostController $Sender
  */
 public function postController_render_before($Sender)
 {
     $Sender->addJsFile('jquery.tokeninput.js');
     $Sender->addJsFile('tagging.js', 'plugins/Tagging');
     $Sender->addDefinition('PluginsTaggingAdd', Gdn::session()->checkPermission('Plugins.Tagging.Add'));
     $Sender->addDefinition('PluginsTaggingSearchUrl', Gdn::request()->Url('plugin/tagsearch'));
     // Make sure that detailed tag data is available to the form.
     $TagModel = TagModel::instance();
     $DiscussionID = val('DiscussionID', $Sender->Data['Discussion']);
     if ($DiscussionID) {
         $Tags = $TagModel->getDiscussionTags($DiscussionID, TagModel::IX_EXTENDED);
         $Sender->setData($Tags);
     } elseif (!$Sender->Request->isPostBack() && ($tagString = $Sender->Request->get('tags'))) {
         $tags = explodeTrim(',', $tagString);
         $types = array_column(TagModel::instance()->defaultTypes(), 'key');
         // Look up the tags by name.
         $tagData = Gdn::sql()->getWhere('Tag', array('Name' => $tags, 'Type' => $types))->resultArray();
         // Add any missing tags.
         $tagNames = array_change_key_case(array_column($tagData, 'Name', 'Name'));
         foreach ($tags as $tag) {
             $tagKey = strtolower($tag);
             if (!isset($tagNames[$tagKey])) {
                 $tagData[] = array('TagID' => $tag, 'Name' => $tagKey, 'FullName' => $tag, 'Type' => '');
             }
         }
         $Sender->setData('Tags', $tagData);
     }
 }
Пример #24
0
 /**
  *
  *
  * @param PostController $Sender
  * @param type $RecordType
  * @param type $ID
  * @throws type
  */
 public function postController_twitter_create($Sender, $RecordType, $ID)
 {
     if (!$this->socialReactions()) {
         throw permissionException();
     }
     //      if (!Gdn::request()->isPostBack())
     //         throw permissionException('Javascript');
     $Row = GetRecord($RecordType, $ID, true);
     if ($Row) {
         // Grab the tweet message.
         switch (strtolower($RecordType)) {
             case 'discussion':
                 $Message = Gdn_Format::plainText($Row['Name'], 'Text');
                 break;
             case 'comment':
             default:
                 $Message = Gdn_Format::plainText($Row['Body'], $Row['Format']);
         }
         $Elips = '...';
         $Message = preg_replace('`\\s+`', ' ', $Message);
         //         if (function_exists('normalizer_is_normalized')) {
         //            // Slice the string to 119 characters (21 reservered for the url.
         //            if (!normalizer_is_normalized($Message))
         //               $Message = Normalizer::normalize($Message, Normalizer::FORM_D);
         //            $Elips = Normalizer::normalize($Elips, Normalizer::FORM_D);
         //         }
         $Max = 140;
         $LinkLen = 22;
         $Max -= $LinkLen;
         $Message = SliceParagraph($Message, $Max);
         if (strlen($Message) > $Max) {
             $Message = substr($Message, 0, $Max - strlen($Elips)) . $Elips;
         }
         //         echo $Message.strlen($Message);
         if ($this->accessToken()) {
             Gdn::controller()->setData('Message', $Message);
             $Message .= ' ' . $Row['ShareUrl'];
             $R = $this->api('/statuses/update.json', array('status' => $Message), 'POST');
             $Sender->setJson('R', $R);
             $Sender->informMessage(t('Thanks for sharing!'));
         } else {
             $Get = array('text' => $Message, 'url' => $Row['ShareUrl']);
             $Url = "https://twitter.com/share?" . http_build_query($Get);
             redirect($Url);
         }
     }
     $Sender->render('Blank', 'Utility', 'Dashboard');
 }
Пример #25
0
 function testInstantiateHelpers()
 {
     $Controller = new PostController();
     var_dump($Controller->instantiateHelpers());
 }
Пример #26
0
            }
        } else {
            foreach ($categorias as $categoria) {
                $arr = array("idCategoria" => $categoria, "idPost" => $_POST['id']);
                PostController::insertPostCategoria($arr);
            }
        }
        if ($res) {
            header("Location: blog-posts");
            exit;
        } else {
            die("ERRO");
        }
    }
} elseif ($_POST['action'] == "del") {
    if (PostController::delete($_POST)) {
        die("OK");
    } else {
        die("ERRO");
    }
} elseif ($_POST['action'] == "listaAvaliacoes") {
    $html = "";
    $i = 0;
    $soma = 0;
    foreach (AvaliacaoController::getAllByPost($_POST['idPost'], "a.DataCriacao DESC") as $avaliacao) {
        if (!empty($avaliacao->Id)) {
            $i++;
            $soma += $avaliacao->Nota;
            $html .= "\t<tr>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t" . DefaultHelper::converterData($avaliacao->DataCriacao) . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t" . $avaliacao->IP . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<div class='nota rateit' data-rateit-min='0' data-rateit-max='5' data-rateit-readonly='true' data-rateit-value='" . $avaliacao->Nota . "'></div>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<a href='#' class='btn btn-danger del-avaliacao' onclick='delAvaliacao(" . $avaliacao->Id . ");'><i class='fa fa-fw fa-close'></i></button>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>";
        }
    }
Пример #27
0
        header('Location: index.php');
    }
}
// Format title accordingly
function format_title($title)
{
    // Remove all HTML tags (e.g. <br/>) that could cause problems
    return strip_tags($title);
}
// Format content accordingly
function format_content($content)
{
    // Convert all \n into <br/> for proper content display
    return str_replace("\n", '<br />', $content);
}
$post_controller = new PostController($db);
// Initialize Post Controller
// HTTP Requests
if (isset($_POST['add'])) {
    // Publish a post
    $post_controller->publish($_SESSION['userid'], format_title($_POST['title']), format_content($_POST['content']));
}
if (isset($_GET['delete'])) {
    // Delete a post
    $post = $post_controller->search_by_id($_GET['id']);
    // Ensure that only authors can delete their own posts
    if ($_SESSION['userid'] == $post['author_id']) {
        // Authorized
        $post_controller->delete($post['id']);
    } else {
        // Not Authorized
Пример #28
0
 /**
  * @param PostController $Sender
  * @param array $Args
  * @return mixed
  */
 public function PostController_Comment_Create($Sender, $Args = array())
 {
     if ($Sender->Form->AuthenticatedPostBack()) {
         $Sender->Form->SetModel($Sender->CommentModel);
         // Grab the discussion for use later.
         $DiscussionID = $Sender->Form->GetFormValue('DiscussionID');
         $DiscussionModel = new DiscussionModel();
         $Discussion = $DiscussionModel->GetID($DiscussionID);
         // Check to see if the discussion is supposed to be in private...
         $WhisperConversationID = GetValueR('Attributes.WhisperConversationID', $Discussion);
         if ($WhisperConversationID === TRUE) {
             // There isn't a conversation so we want to create one.
             $Sender->Form->SetFormValue('Whisper', TRUE);
             $WhisperUserIDs = GetValueR('Attributes.WhisperUserIDs', $Discussion);
             $Sender->Form->SetFormValue('RecipientUserID', $WhisperUserIDs);
         } elseif ($WhisperConversationID) {
             // There is already a conversation.
             $Sender->Form->SetFormValue('Whisper', TRUE);
             $Sender->Form->SetFormValue('ConversationID', $WhisperConversationID);
         }
         $Whisper = $Sender->Form->GetFormValue('Whisper') && GetIncomingValue('Type') != 'Draft';
         $WhisperTo = trim($Sender->Form->GetFormValue('To'));
         $ConversationID = $Sender->Form->GetFormValue('ConversationID');
         // If this isn't a whisper then post as normal.
         if (!$Whisper) {
             return call_user_func_array(array($Sender, 'Comment'), $Args);
         }
         $ConversationModel = new ConversationModel();
         $ConversationMessageModel = new ConversationMessageModel();
         if ($ConversationID > 0) {
             $Sender->Form->SetModel($ConversationMessageModel);
         } else {
             // We have to remove the blank conversation ID or else the model won't validate.
             $FormValues = $Sender->Form->FormValues();
             unset($FormValues['ConversationID']);
             $FormValues['Subject'] = GetValue('Name', $Discussion);
             $Sender->Form->FormValues($FormValues);
             $Sender->Form->SetModel($ConversationModel);
             $ConversationModel->Validation->ApplyRule('DiscussionID', 'Required');
         }
         $ID = $Sender->Form->Save($ConversationMessageModel);
         if ($Sender->Form->ErrorCount() > 0) {
             $Sender->ErrorMessage($Sender->Form->Errors());
         } else {
             if ($WhisperConversationID === TRUE) {
                 $Discussion->Attributes['WhisperConversationID'] = $ID;
                 $DiscussionModel->SetProperty($DiscussionID, 'Attributes', serialize($Discussion->Attributes));
             }
             $LastCommentID = GetValue('LastCommentID', $Discussion);
             $MessageID = GetValue('LastMessageID', $ConversationMessageModel, FALSE);
             // Randomize the querystring to force the browser to refresh.
             $Rand = mt_rand(10000, 99999);
             if ($LastCommentID) {
                 // Link to the last comment.
                 $HashID = $MessageID ? 'w' . $MessageID : $LastCommentID;
                 $Sender->RedirectUrl = Url("discussion/comment/{$LastCommentID}?rand={$Rand}#Comment_{$HashID}", TRUE);
             } else {
                 // Link to the discussion.
                 $Hash = $MessageID ? "Comment_w{$MessageID}" : 'Item_1';
                 $Name = rawurlencode(GetValue('Name', $Discussion, 'x'));
                 $Sender->RedirectUrl = Url("discussion/{$DiscussionID}/{$Name}?rand={$Rand}#{$Hash}", TRUE);
             }
         }
         $Sender->Render();
     } else {
         return call_user_func_array(array($Sender, 'Comment'), $Args);
     }
 }
Пример #29
0
 public function testLoggedInPostWithViewsSpecified()
 {
     $builders = $this->buildPublicPostWithMixedAccessResponses();
     $_GET["t"] = '1001';
     $_GET['n'] = 'twitter';
     //Log in and see private replies and retweets
     $this->simulateLogin('*****@*****.**');
     //default menu item
     $_GET["v"] = 'default';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertPattern("/This is a test post/", $results);
     $this->assertPattern("/This is a public reply to 1001/", $results);
     $this->assertPattern("/This is a private reply to 1001/", $results);
     //retweets menu item
     $this->simulateLogin('*****@*****.**');
     $_GET["v"] = 'fwds';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertPattern("/This is a test post/", $results);
     //shouldn't see replies, just retweets
     $this->assertNoPattern("/This is a public reply to 1001/", $results);
     $this->assertNoPattern("/This is a private reply to 1001/", $results);
     $this->assertPattern("/This is a public retweet of 1001/", $results);
     //logged in, should see private responses
     $this->assertPattern("/This is a private retweet of 1001/", $results);
     //non-existent menu item
     $_GET["v"] = 'idontexist';
     $controller = new PostController(true);
     $results = $controller->go();
     $this->assertPattern("/This is a test post/", $results);
 }
Пример #30
-1
 protected function __construct($post)
 {
     parent::__construct($post);
     // Set standard content
     $this->description =& $this->content;
     $this->caption =& $this->excerpt;
     // Retrieve post meta
     $this->alt = get_post_meta($this->id, '_wp_attachment_image_alt', true);
     $this->mime_type = get_post_mime_type($this->id);
     $this->link = wp_get_attachment_url($this->id);
 }