Soundclound BBcode for Kunena forum - soundcloud

I use Kunena Forum 3.0.6 with Joomla 3 for a :usical website.
I need to add BBcode in Kunena editor, so users can share their Soundcloud tracks directly on the forum with something like [soundcloud]my-track[soundcloud].
SO I have this code for now in bbcode.php
'soundcloud' => array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => 'DoSoundcloud',
'allow_in' => array('listitem', 'block', 'columns'),
'class' => 'block',
'allow_in' => array('listitem', 'block', 'columns'),
'content' => BBCODE_PROHIBIT,
'plain_start' => "[soundcloud]",
'plain_end' => "\n",
),
and
function DoSoundcloud($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK)
return true;
return '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://soundcloud.com/'.$content.'&auto_play=false&visual=true"></iframe>';
}
This way it works but not with the complete url. For example, if a user wants to share "http://soundcloud/track/1234" , he must post [soundcloud]track/1234[/soundcloud].
I would prefer with the complete url between the [soundcloud] because that would be far more easier for users.
Waiting for your suggestions !
Regards

Try:
function DoSoundcloud($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK) {
return true;
}
$content = preg_replace('%^http://(?:www\\.)?soundcloud\\.com/?%i', '', $content);
return '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://soundcloud.com/'.$content.'&auto_play=false&visual=true"></iframe>';
}

I tried with the code you give but it seems to have no effect.
With the code below,it works but not if there are dashes in the url (and maybe other characters ?).
I guess I have to add something like '%^http://(?:www\.)?soundcloud\.com/?%i' but I've no idea how to do.
function DoSoundcloud($bbcode, $action, $name, $default, $params, $content) { if ($action == BBCODE_CHECK) return true;
$content = strip_tags($content);
return '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url='.$content.'&auto_play=false&visual=true"></iframe>';
}
Thanks for your help !

Wouldn't it of been easyer to add this to Kunena's Core ? Soundcloud download mp3 soundcloudmp3downloader.com/en/
case 'soundcloud' :
if ($between) {
$task->autolink_disable --;
$tag_new = "";
$tag_new = '<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=' . $between . '&g=bb"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=' . $between . '&g=bb" type="application/x-shockwave-flash" width="100%"></embed></object> ' . $between . '';
return TAGPARSER_RET_REPLACED;
}
return TAGPARSER_RET_NOTHING;
break;

Related

Paragraph breaks missing from shortcode output

I created a shortcode in Wordpress to perform a query and display the content, but the content line breaks are being removed.
add_shortcode( 'resource' , 'Resource' );
function Resource($atts) {
$atts = shortcode_atts( array(
'category' => ''
), $atts );
$categories = explode(',' , $atts['category']);
$args = array(
'post_type' => 'resource',
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page'=> -1,
'tax_query' => array( array(
'taxonomy' => 'category',
'field' => 'term_id',
'operator' => 'AND',
'terms' => $categories
) )
);
$string = '';
$query = new WP_Query( $args );
if( ! $query->have_posts() ) {
$string .= '<p>no listings at this time...</p>';
}
while( $query->have_posts() ){
$query->the_post();
$string .= '<div id="links"><div id="linksImage">' . get_the_post_thumbnail() . '</div>
<div id="linksDetails"><h1>'. get_the_title() .'</h1><p>' . get_the_content() . '</p>
<p>for more information CLICK HERE</div></div>';
}
wp_reset_postdata();
$output = '<div id="linksWrapper">' . $string . '</div>';
return $output;
}
Any suggestion on why this is happening and what to do to fix it. This is only happening on the shortcode output. On regular pages - the content displays correctly.
found a solution through more searches:
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
works perfect, so I thought I would share..

register View-Helper understanding issue

I tried to register a View Helper for navigation, it is an example from olegkrivtsov,I chose this to learn more about the topic. I also read the posts about it. I thought it must be really easy, but it doesn't work, probably some more experienced Zend-developer will see the problem immediately.
First the folder I use, is this the right folder, what is the diffenrence to the folder helpers in the module Import for example?
Here is the content of menu.php
<?php
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
// This view helper class displays a menu bar.
class Menu extends AbstractHelper
{
// Menu items array.
protected $items = [];
// Active item's ID.
protected $activeItemId = '';
// Constructor.
public function __construct($items=[])
{
$this->items = $items;
}
// Sets menu items.
public function setItems($items)
{
$this->items = $items;
}
// Sets ID of the active items.
public function setActiveItemId($activeItemId)
{
$this->activeItemId = $activeItemId;
}
// Renders the menu.
public function render()
{
if (count($this->items)==0)
return ''; // Do nothing if there are no items.
$result = '<nav class="navbar navbar-default" role="navigation">';
$result .= '<div class="navbar-header">';
$result .= '<button type="button" class="navbar-toggle" ';
$result .= 'data-toggle="collapse" data-target=".navbar-ex1-collapse">';
$result .= '<span class="sr-only">Toggle navigation</span>';
$result .= '<span class="icon-bar"></span>';
$result .= '<span class="icon-bar"></span>';
$result .= '<span class="icon-bar"></span>';
$result .= '</button>';
$result .= '</div>';
$result .= '<div class="collapse navbar-collapse navbar-ex1-collapse">';
$result .= '<ul class="nav navbar-nav">';
// Render items
foreach ($this->items as $item) {
$result .= $this->renderItem($item);
}
$result .= '</ul>';
$result .= '</div>';
$result .= '</nav>';
return $result;
}
// Renders an item.
protected function renderItem($item)
{
$id = isset($item['id']) ? $item['id'] : '';
$isActive = ($id==$this->activeItemId);
$label = isset($item['label']) ? $item['label'] : '';
$result = '';
if(isset($item['dropdown'])) {
$dropdownItems = $item['dropdown'];
$result .= '<li class="dropdown ' . ($isActive?'active':'') . '">';
$result .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">';
$result .= $label . ' <b class="caret"></b>';
$result .= '</a>';
$result .= '<ul class="dropdown-menu">';
foreach ($dropdownItems as $item) {
$link = isset($item['link']) ? $item['link'] : '#';
$label = isset($item['label']) ? $item['label'] : '';
$result .= '<li>';
$result .= ''.$label.'';
$result .= '</li>';
}
$result .= '</ul>';
$result .= '</a>';
$result .= '</li>';
} else {
$link = isset($item['link']) ? $item['link'] : '#';
$result .= $isActive?'<li class="active">':'<li>';
$result .= ''.$label.'';
$result .= '</li>';
}
return $result;
}
}
I posted the hole example for somebody who also wants to use it.
Here how I tried to register in my module.config.php
'view_helpers' => [
'factories' => [
View\Helper\Menu::class => InvokableFactory::class,
],
'aliases' => [
'mainMenu' => View\Helper\Menu::class
]
],
I placed it in the layout.phtml
<div class="collapse navbar-collapse">
<?php
$this->mainMenu()->setItems([
[
'id' => 'home',
'label' => 'Dashboard',
'link' => $this->url('home')
],
[
'id' => 'project',
'label' => 'Project',
'link' => $this->url("project", ['action'=>'index'])
],
[
'id' => 'unit',
'label' => 'Unit',
'dropdown' => [
[
'id' => 'add',
'label' => 'add Unit',
// 'link' => $this->url('unit', ['page'=>'contents'])
'link' => $this->url('unit', ['action'=>'add'])
],
[
'id' => 'help',
'label' => 'Help',
'link' => $this->url('home')
]
]
],
]);
echo $this->mainMenu()->render();
?>
</div>
With this code I replaced the former part, which came from the skeleton:
<div class="collapse navbar-collapse">
<?= $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav navbar-nav') ?>
I get this error message via browser:
Fatal error: Uncaught Error: Class 'Application\view\helper\Menu' not found in C:\wamp64\www\xyz\vendor\zendframework\zend-servicemanager\src\Factory\InvokableFactory.php
I'd really love to understand this because it might be really helpful in future, so any suggestion is appreciated.
Move file Menu.php to the folder Application/src/Application/View/Helper

How to get List for Contact Form 7

I have 2 contact forms created by Contact Form 7.
How to list all contact forms created through shortcode?
Please check images, tks.
Updated:
this is my code, this working!
$args = array('post_type' => 'wpcf7_contact_form', 'posts_per_page' => -1);
$rs = array();
if( $data = get_posts($args)){
foreach($data as $key){
$rs[$key->ID] = $key->post_title;
}
}else{
$rs['0'] = esc_html__('No Contact Form found', 'text-domanin');
}
Below is a dropdown list:
<select name="field-name" id="field-id">
<option value="">--Select--</option><?php
$dbValue = get_option('field-name'); //example!
$posts = get_posts(array(
'post_type' => 'wpcf7_contact_form',
'numberposts' => -1
));
foreach ( $posts as $p ) {
echo '<option value="'.$p->ID.'"'.selected($p->ID,$dbValue,false).'>'.$p->post_title.' ('.$p->ID.')</option>';
} ?>
</select>

facebook-php-sdk how to upload photo to wall or album?

Hi Guys i'm e newbie in php programin and facebook app, i found this code and it works very well for TEXT posts, but my requirements are that I have to UPLOAD a picture too, i tried by addin ['source' => '$image_source'] on the arrey but does not work...
How can I upload a PHOTO ?
<?php
include_once("config.php");
if($_POST)
{
//Post variables we received from user
$userPageId = $_POST["userpages"];
$userMessage = $_POST["message"];
$image_source = "http://www.example.com/image.jpg"
if(strlen($userMessage)<1)
{
//message is empty
$userMessage = 'No message was entered!';
}
//HTTP POST request to PAGE_ID/feed with the publish_stream
$post_url = '/'.$userPageId.'/feed';
//posts message on page statues
$msg_body = array(
'message' => $userMessage,
'source' => '$image_source'
);
if ($fbuser) {
try {
$postResult = $facebook->api($post_url, 'post', $msg_body );
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}else{
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
header('Location: ' . $loginUrl);
}
//Show sucess message
if($postResult)
{
echo '<html><head><title>Message Posted</title><link href="style.css" rel="stylesheet" type="text/css" /></head><body>';
echo '<div id="fbpageform" class="pageform" align="center">';
echo '<h1>Your message is posted on your facebook wall.</h1>';
echo '<a class="button" href="'.$homeurl.'">Back to Main Page</a> <a target="_blank" class="button" href="http://www.facebook.com/'.$userPageId.'">Visit Your Page</a>';
echo '</div>';
echo '</body></html>';
}
}
?>
You cannot use the feed endpoint to post photos. You should be using /me/photos with the publish_stream permission. To post to an album you need the /ALBUM_ID/photos endpoint
$msg_body = array(
'message' => $userMessage,
'source' => '#'.'$image_source'
);
$postResult = $facebook->api('/me/photos/','post', $msg_body);
For using urls not associated with your site you need to use url
$msg_body = array(
'message' => $userMessage,
'url' => 'http://somepage.com/img.png'
);

zend-form select optgroup, how to specify id

Hello i am using Zend Framework Form and have tried to get this example to work http://framework.zend.com/issues/browse/ZF-8252, but it fails xD
this is my code
$options = Array
(
[] => Qualsiasi Agente
[agenti_attivi] => Array
(
[4] => Giovanni Abc
[10] => Luigi Abc
[13] => Michela Abc
)
);
$agenti->addMultiOptions($options);
and the generated code is :
<select name="agente_id" id="agente_id" tabindex="6">
<option value="" label="Qualsiasi Agente" selected="selected">Qualsiasi Agente</option>
<optgroup id="agente_id-optgroup-Agenti attivi: " label="Agenti attivi: ">
<option value="4" label="Giovanni Abc">Giovanni Abc</option>
<option value="10" label="Luigi Capoarea">Luigi Abc</option>
<option value="13" label="Michela Abc">Michela Abc</option>
</optgroup>
</select>
where id="agente_id-optgroup-Agenti attivi: " is not xhtml valid Line 724, Column 44: value of attribute "id" must be a single token
i am using zend 1.11.10
thanks
Create a custom view helper FormSelect that extends the core FormSelect and then modify the code.
Include the path to your view helpers in the bootstrap file
protected function _initHelpers()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath('My/View/Helper', 'My_View_Helper');
}
The custom view helper. It's a copy of Zend_View_Helper_FormSelect but with small modification.
class My_View_Helper_FormSelect extends Zend_View_Helper_FormSelect
{
public function formSelect($name, $value = null, $attribs = null,
$options = null, $listsep = "<br />\n")
{
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
extract($info); // name, id, value, attribs, options, listsep, disable
// force $value to array so we can compare multiple values to multiple
// options; also ensure it's a string for comparison purposes.
$value = array_map('strval', (array) $value);
// check if element may have multiple values
$multiple = '';
if (substr($name, -2) == '[]') {
// multiple implied by the name
$multiple = ' multiple="multiple"';
}
if (isset($attribs['multiple'])) {
// Attribute set
if ($attribs['multiple']) {
// True attribute; set multiple attribute
$multiple = ' multiple="multiple"';
// Make sure name indicates multiple values are allowed
if (!empty($multiple) && (substr($name, -2) != '[]')) {
$name .= '[]';
}
} else {
// False attribute; ensure attribute not set
$multiple = '';
}
unset($attribs['multiple']);
}
// now start building the XHTML.
$disabled = '';
if (true === $disable) {
$disabled = ' disabled="disabled"';
}
// Build the surrounding select element first.
$xhtml = '<select'
. ' name="' . $this->view->escape($name) . '"'
. ' id="' . $this->view->escape($id) . '"'
. $multiple
. $disabled
. $this->_htmlAttribs($attribs)
. ">\n ";
// build the list of options
$list = array();
$translator = $this->getTranslator();
foreach ((array) $options as $opt_value => $opt_label) {
if (is_array($opt_label)) {
$opt_disable = '';
if (is_array($disable) && in_array($opt_value, $disable)) {
$opt_disable = ' disabled="disabled"';
}
if (null !== $translator) {
$opt_value = $translator->translate($opt_value);
}
$opt_id = ' id="' . $this->formatElementId($id . '-optgroup-' . $opt_value) . '"';
$list[] = '<optgroup'
. $opt_disable
. $opt_id
. ' label="' . $this->view->escape($opt_value) .'">';
foreach ($opt_label as $val => $lab) {
$list[] = $this->_build($val, $lab, $value, $disable);
}
$list[] = '</optgroup>';
} else {
$list[] = $this->_build($opt_value, $opt_label, $value, $disable);
}
}
// add the options to the xhtml and close the select
$xhtml .= implode("\n ", $list) . "\n</select>";
return $xhtml;
}
private function formatElementId($id)
{
// in here put whatever filter you want for the id value
$id = trim(strtr($id, array('[' => '-', ']' => '', ' ' => '', ':' => '')), '-');
$id = strtolower($id);
return $id;
}
}
Done. Create multi select element with a valid id.
<?php
$this->addElement('multiSelect', 'agente_id', array(
'label' => 'Label Name:',
'multiOptions' => array(
'' => 'Qualsiasi Agente',
'Agenti attivi: ' => array(
4 => 'Giovanni Verdi',
10 => 'Luigi Capoarea',
13 => 'Michela Passarin',
)
)
));
try this, it's works for me:
$select = new Zend_Form_Element_Select('select');
$options = Array(
'' => 'Qualsiasi Agente',
'agenti_attivi' => Array(
4 => 'Giovanni Verdi',
10 => 'Luigi Capoarea',
13 => 'Michela Passarin'
)
);
$this->addElements(array($xxxx,$select,$yyyy)); // $this : the form instance
and the result is:
<select id="select" name="select">
<option label="Qualsiasi Agente" value="">Qualsiasi Agente</option>
<optgroup label="agenti_attivi">
<option label="Giovanni Verdi" value="4">Giovanni Verdi</option>
<option label="Luigi Capoarea" value="10">Luigi Capoarea</option>
<option label="Michela Passarin" value="13">Michela Passarin</option>
</optgroup>
</select>
the problem is that the id attribute does not accept spaces and special special characters:
id="agente_id-optgroup-Agenti attivi: "
Zend is usually pretty good about rendering the proper html, given a doctype.
Try setting your doctype like this if you aren't already.
<?php
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->initView();
$viewRenderer->view->doctype('XHTML1_STRICT');
AND
<?php echo $this->doctype(); ?>
at the top of your layout
I don't have a install of ZF i can mess with easy, if this doesn't work ill setup a test environment.