/** * Validates if the block contains any contents * * @since 5.0 * @access public * @param string * @return */ public function validate($block) { $content = EB::blocks()->renderViewableBlock($block, true); // convert html entities back to it string. e.g. back to empty space $content = html_entity_decode($content); // strip html tags to precise length count. $content = strip_tags($content); // remove any blank space. $content = trim($content); // get content length $contentLength = JString::strlen($content); if ($contentLength > 0) { return true; } else { return false; } }
/** * Formats blocks in the blog post. * * @since 4.0 * @access public * @param string * @return */ public function format(EasyBlogPost &$blog, $blocks, $type = 'list') { static $_cache = array(); if (!$blocks) { return array(); } // Determines the total number of blocks $total = count($blocks); // Get the maximum number of blocks $max = $this->config->get('composer_truncation_blocks'); // Determines if content truncation should happen if ($type == 'list' && $this->config->get('composer_truncation_enabled') && $max) { // Get the total number of blocks $blocks = array_splice($blocks, 0, $max); } // Default read more to false $blog->readmore = false; // Default contents $contents = ''; foreach ($blocks as $item) { // If the read more is present at this point of time, we should skip processing the rest of the blocks if ($blog->readmore && $type == 'list') { continue; } // Load from cache if (!isset($_cache[$item->type])) { $tblElement = EB::table('Block'); $tblElement->load(array('element' => $item->type)); $_cache[$item->type] = $tblElement; } $table = $_cache[$item->type]; $block = EB::blocks()->get($table); $contents .= $block->formatDisplay($item, $blog); } // If the total is larger than the iterated blocks, we need to display the read more if ($total > count($blocks)) { $blog->readmore = true; } return $contents; }
/** * Retrieves the editable html codes for each blocks * * @since 5.0 * @access public * @param string * @return */ public function getEditableContent() { $output = ''; foreach ($this->blocks as $block) { $output .= EB::blocks()->renderEditableBlock($block); } return $output; }
/** * Retrieves a list of galleries associated with the post * * @since 5.0 * @access public * @param string * @return */ public function process($content, $userId = '') { $pattern = '/\\[embed=gallery\\](.*)\\[\\/embed\\]/i'; $galleries = array(); preg_match_all($pattern, $content, $matches, PREG_SET_ORDER); if (!$matches) { return $content; } // Get the image block so that we can construct it $block = EB::blocks()->getBlockByType('image'); foreach ($matches as $match) { $totalColumns = 4; $columns = array(); for ($i = 0; $i < $totalColumns; $i++) { $columns[$i] = array(); } // The full text of the matched content list($text, $json) = $match; // Ensure that the property is valid $json = str_ireplace('file:', '"file":', $json); $json = str_ireplace('place:', '"place":', $json); // Parse the raw json $gallery = json_decode($json); if ($gallery === null) { continue; } $images = $this->getImages($gallery); // We need to construct a block for each of these items for ($i = 0; $i < count($images); $i++) { $image = $block->getHtml($images[$i]); $column = $i - floor($i / $totalColumns) * $totalColumns; $columns[$column][] = $image; } $theme = EB::template(); $theme->set('columns', $columns); $output = $theme->output('site/blogs/latest/blog.gallery'); $content = str_ireplace($match, $output, $content); } return $content; }
<?php /** * @package EasyBlog * @copyright Copyright (C) 2010 - 2014 Stack Ideas Sdn Bhd. All rights reserved. * @license GNU/GPL, see LICENSE.php * EasyBlog is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ defined('_JEXEC') or die('Unauthorized Access'); ?> <ul class="nav nav-tabs" role="tablist"> <li class="active"><a href="#firsttab" role="tab" data-bp-toggle="tab" contenteditable="true"><?php echo JText::_('COM_EASYBLOG_BLOCK_TABS_DEFAULT_TITLE'); ?> </a></li> </ul> <div class="tab-content" data-tabs-content> <div class="tab-pane active" id="firsttab" contenteditable="false"> <div class="ebd-nest" data-type="block" data-tab-wrapper=""> <?php echo EB::blocks()->renderEditableBlock(EB::blocks()->createBlock('text', array(), array('nested' => true))); ?> </div> </div> </div>
/** * Retrieves the html codes for composer * * @since 4.0 * @access public * @param int The unique item id. * @param string The type of the post, whether this is a post or a draft * @return */ public function renderManager($uid = null) { // Get the current post library $post = EB::post($uid); // Check if user has permissions to write new entry if (!$post->canCreate()) { return JError::raiseError(500, JText::_('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG')); } // If the blog post is edited, ensure that the user has access to edit this entry if (!$post->canEdit()) { return JError::raiseError(500, JText::_('COM_EASYBLOG_NO_PERMISSION_TO_EDIT_BLOG')); } // Get the editor to use $editorSetting = $this->user->getEditor(); $editorSetting = $editorSetting == 'composer' ? JFactory::getConfig()->get('editor') : $editorSetting; $editor = JFactory::getEditor($editorSetting); // Get a list of parent categories $parentCategories = $this->getParentCategories(); // Get the default category. $defaultCategoryId = EB::model('Category')->getDefaultCategoryId(); $primaryCategory = $post->getPrimaryCategory(); // Get a list of categories // Prepare selected category $selectedCategories = array(); foreach ($post->getCategories() as $row) { $selectedCategories[] = (int) $row->id; } // if there is no category selected, or this is a new blog post, lets use the default category id. if (!$selectedCategories && $defaultCategoryId) { $selectedCategories[] = $defaultCategoryId; } // Prepare categories object $categories = array(); $cats = EB::model('Categories')->getCategoriesHierarchy(false); foreach ($cats as $row) { $category = new stdClass(); $category->id = (int) $row->id; $category->title = $row->title; $category->parent_id = (int) $row->parent_id; $params = new JRegistry($row->params); $category->tags = $params->get('tags'); if (!$category->tags) { $category->tags = array(); } else { $tags = explode(',', $category->tags); for ($i = 0; $i < count($tags); $i++) { $tags[$i] = JString::trim($tags[$i]); } $category->tags = implode(',', $tags); } // Cross check if this category is selected $category->selected = in_array($category->id, $selectedCategories); // check if this is a primary category or not $category->isprimary = $category->id == $primaryCategory->id; $categories[] = $category; } // Prepare tags $tags = array(); foreach ($post->getTags() as $row) { $tag = new stdClass(); $tag->id = (int) $row->id; $tag->title = $row->title; $tags[] = $tag; } // Render default post templates $postTemplatesModel = EB::model('Templates'); $postTemplates = $postTemplatesModel->getPostTemplates($this->my->id); // Get the post's author $author = $post->getAuthor(); // Get a list of revisions for this post $revisions = $post->getRevisions(); // Get the current revision for the post $workingRevision = $post->getWorkingRevision(); // Determines if the current page load should be loading from block templates $postTemplate = EB::table('PostTemplate'); $postTemplate->load($this->input->get('block_template', 0, 'int')); if (!$postTemplate->id || $postTemplate->id == 1) { $postTemplate = false; } // Get available blocks on the site $blocks = EB::blocks()->getAvailableBlocks(); // Determines if we should display the custom fields tab by default $displayFieldsTab = false; // Get a list of selected categories $selectedCategories = $post->getCategories(); // If there's no selected categories, we assume that the primary category if (!$selectedCategories) { $selectedCategories = array($primaryCategory); } // If explicitly configured to be hidden, skip the checks altogether if ($this->config->get('layout_composer_fields')) { foreach ($selectedCategories as $category) { if ($category->hasCustomFields()) { $displayFieldsTab = true; break; } } } $user = EB::table('Profile'); $user = $user->load($this->my->id); //available languages $languages = JLanguageHelper::getLanguages('lang_code'); //post association $associations = $post->getAssociation(); $theme = EB::template(); $theme->set('user', $user); $theme->set('displayFieldsTab', $displayFieldsTab); $theme->set('postTemplate', $postTemplate); $theme->set('postTemplates', $postTemplates); $theme->set('workingRevision', $workingRevision); $theme->set('revisions', $revisions); $theme->set('editor', $editor); $theme->set('primaryCategory', $primaryCategory); $theme->set('categories', $categories); $theme->set('tags', $tags); $theme->set('post', $post); $theme->set('author', $author); $theme->set('uuid', uniqid()); $theme->set('blocks', $blocks); $theme->set('languages', $languages); $theme->set('associations', $associations); // Determines if the source id and source type is provided $sourceId = $this->input->get('source_id', 0, 'int'); $sourceType = $this->input->get('source_type', '', 'default'); $contribution = ''; if ($sourceId && $sourceType) { $contribution = EB::contributor()->load($sourceId, $sourceType); $post->source_id = $sourceId; $post->source_type = $sourceType; } $theme->set('contribution', $contribution); $theme->set('sourceId', $sourceId); $theme->set('sourceType', $sourceType); $output = $theme->output('site/composer/manager'); return $output; }
/** * Standard meta data of a block object * * @since 5.0 * @access public * @param string * @return */ public function meta() { $meta = new stdClass(); // Standard descriptors $meta->type = $this->type; $meta->icon = $this->icon; $meta->title = $this->title; $meta->keywords = $this->keywords; $meta->data = $this->data(); // Nestable $meta->nestable = $this->nestable; // Dimensions $meta->dimensions = new stdClass(); $meta->dimensions->enabled = true; $meta->dimensions->respectMinContentSize = false; // Others $meta->properties = array('fonts' => true, 'textpanel' => true); $template = EB::template(); $template->set('block', $this); $template->set('data', $meta->data); // HTML & Block $meta->html = $template->output('site/composer/blocks/handlers/' . $this->type . '/html'); $meta->block = EB::blocks()->renderBlockContainer(EASYBLOG_BLOCK_MODE_EDITABLE, $this, $meta->html); // Fieldset & fieldgroup $meta->fieldset = $template->output('site/composer/blocks/handlers/' . $this->type . '/fieldset'); $meta->fieldgroup = $template->output('site/composer/blocks/fieldgroup', array('fieldset' => $meta->fieldset)); return $meta; }
/** * Used during post editing so we can render the necessary blocks * * @since 5.0 * @access public * @param string * @return */ public function renderEditorContent() { if ($this->doctype == 'ebd') { // If this is a empty document, // start with a text block. if (empty($this->document)) { $blocks = EB::blocks(); $block = $blocks->createBlock("text"); $content = $blocks->renderEditableBlock($block); // If this is an existing document, // get editable content. } else { $document = EB::document($this->document); $content = $document->getEditableContent(); } } else { // Format the post content now $content = $this->intro; // Append the readmore if necessary if (!empty($this->intro) && !empty($this->content)) { $content .= '<hr id="system-readmore" />'; } // Append the rest of the contents $content .= $this->content; } return $content; }
?> <?php foreach ($blocks as $block) { ?> <tr> <td> <?php echo $this->html('grid.id', $i, $block->id); ?> </td> <td align="left"> <div class="media"> <div class="media-object pull-left"> <i class="<?php echo EB::blocks()->get($block)->getIcon(); ?> " style="font-size:12px;"></i> </div> <div class="media-body"> <b><?php echo $block->title; ?> </b> <p class="small"><?php echo $block->description; ?> </p> </div> </div> </td>
/** * Retrieves a list of available blocks * * @since 4.0 * @access public * @param string * @return */ public function getAvailableBlocks() { $db = EB::db(); $query = $this->getQuery(array('filter_state' => 'all')); $query[] = 'AND('; $query[] = $db->qn('published') . '=' . $db->Quote(EASYBLOG_COMPOSER_BLOCKS_PUBLISHED); $query[] = 'OR'; $query[] = $db->qn('published') . '=' . $db->Quote(EASYBLOG_COMPOSER_BLOCKS_NOT_VISIBLE); $query[] = ')'; $query[] = "order by " . $db->qn('ordering'); $query = implode(' ', $query); $db->setQuery($query); $result = $db->loadObjectList(); if (!$result) { return $result; } $categories = array(); foreach ($result as $row) { $block = EB::table('Block'); $block->bind($row); if (!isset($categories[$block->group])) { $categories[$block->group] = array(); } $categories[$block->group][] = EB::blocks()->get($block); } return $categories; }