ryan

Hanna Code

335 posts in this topic

On 24/06/2016 at 1:08 PM, Robin S said:

I'd be keen to hear if there is a better way to get pages into a PageArray while maintaining a given order of page IDs.

Maybe $pages->getById() is the way to go.

$my_pages = $pages->getById([1086,1021,1053,1018]);

 

Share this post


Link to post
Share on other sites

It's occurred to me that adding to this existing thread might have been the better option for seeking a solution to my problem.

I've already created a new thread so I wonder if it's ok to post a link to it here in case anyone who might know the answer will be more likely to see it here...

 

 

Share this post


Link to post
Share on other sites
1 hour ago, spacemonkey95 said:

It's occurred to me that adding to this existing thread might have been the better option for seeking a solution to my problem.

I think there might be still better places to ask. :)

Table is a Pro field with it's own dedicated support sub-forum.

And the feature you are describing is not a feature of Hanna Code but rather a feature of the Hanna Code Helper module.

1 person likes this

Share this post


Link to post
Share on other sites

Hi all,

I'm struggling with a problem which is more a PHP issue than one of Hanna Code.

<?php
?>
<audio controls>
	<source src='<?= $audiofile?>' type='audio/mp3'> 
</audio>

This little HC  works fine when used in a textarea/CKEditor field like this:

[[audio file="/site/assets/files/1234/foo.mp3"]]

Now I wanted to make it flexible and enable the editor user to insert the path to any mp3 file (stored on some page in a field "mp3" of type File, allowed file extension mp3). 

In the HC Attributes I set a default value for $file, defining   file=LINK . Now the editor, inserting the HC using the HannaCodeHelper Module, gets

[[audio file="LINK"]]

The aimed workflow for the editor user was: Double click on LINK to mark it and using the Link button of the CKEditor to choose the wanted file from the wanted page. Obviously, the value created by CKE had to undergo some treatment.

Of course it's a link from which I had to extract the value of the href attribute (here  /site/assets/files/1122/bar.mp3) , but because of the double quotes from   [[audio file="LINK"]]  it would become

"<a href="/site/assets/files/1234/foo.mp3">"

where the second  "  would terminate the string. I tried string functions str_replace(), strstr() etc. but to no avail.
Perhaps I could have used Javascript, but I wanted to find a PHP solution.

Could anyone help on that?

 

Share this post


Link to post
Share on other sites

@ottogal

An easy solution would be to change...

[[audio file="LINK"]]

...to...

[[audio file='LINK']]

If you want Hanna Code Helper to insert single quotes around attributes I think you'll have to modify the module code. Change line 124 to:

$attrs .= " $attrName='$attrValue'";

You can use SimpleXML in your Hanna Code to get the href from the link:

$a = new SimpleXMLElement($file);
$path = $a['href']->__toString();

 

1 person likes this

Share this post


Link to post
Share on other sites

@Robin S

15 hours ago, Robin S said:

If you want Hanna Code Helper to insert single quotes around attributes I think you'll have to modify the module code. Change line 124 to:


$attrs .= " $attrName='$attrValue'";

Good find, thank you!

After this change even my simple use of the function strstr() works -  to crop the string on both ends, setting free the href attribute value:

<?php
$f = (string) $file;
$f = strstr($f,'/site');
$audiofile = strstr($f,'">',true);
?>
<audio controls>
	<source src='<?= $audiofile?>' type='audio/mp3'> 
</audio>

Your second hint to use SimpleXMLElement() of course is a cleaner way to do it:

<?php
$a = new SimpleXMLElement($file);
$audiofile = $a['href']->__toString();
?>
<audio controls>
	<source src='<?= $audiofile?>' type='audio/mp3'> 
</audio>

Didn't know this class before - so again I learnt something new. Thanks a lot again!

Share this post


Link to post
Share on other sites

Good day.
I really liked the Hana Code Insert plugin. But I was faced with the following problem. In WordPress platform there are 5 roles: Administrator, Editor, Author, Contributor, Subscriber.
I want only the Administrator could work with this plugin.
How to limit access to this plugin for role Contributor ?
Sorry, for my bad English.

Share this post


Link to post
Share on other sites
1 minute ago, Sergey Voronov said:

Good day.
I really liked the Hana Code Insert plugin. But I was faced with the following problem. In WordPress platform there are 5 roles: Administrator, Editor, Author, Contributor, Subscriber.
I want only the Administrator could work with this plugin.
How to limit access to this plugin for role Contributor ?
Sorry, for my bad English.

Check out the hanna specific permissions and only assign them to the contributor role.

Screen Shot 2016-11-03 at 2.36.16 PM.png

Share this post


Link to post
Share on other sites
4 minutes ago, Sergey Voronov said:

If I understand correctly, you need to edit the code in the plugin ?

No - just go to your PW Access > Roles menu and assign the relevant hanna permissions to the appropriate roles.

I just re-read your question and see that you actually only want the codes editable  by the administrator role. By this do you mean the PW superuser role? By default, only the superuser should be able to view/edit hanna codes.

1 person likes this

Share this post


Link to post
Share on other sites
Just now, Sergey Voronov said:

I have installed wordpress version 4.5.3.
Please tell me where I need to go and what to do?
Please explain the steps
Or show a screenshot

I think you're in the wrong place - this is the support forum for ProcessWire, not Wordpress!

ProcessWire also has a hanna code plugin - I think that is your confusion, but since you are here, maybe you should stay :)

 

2 people like this

Share this post


Link to post
Share on other sites
On 6/24/2016 at 3:08 AM, Robin S said:

I'd be keen to hear if there is a better way to get pages into a PageArray while maintaining a given order of page IDs.

Probably not:

 

Share this post


Link to post
Share on other sites
7 hours ago, szabesz said:
On 24/06/2016 at 1:08 PM, Robin S said:

I'd be keen to hear if there is a better way to get pages into a PageArray while maintaining a given order of page IDs.

Probably not:

I answered my own question in the next post:

On 26/06/2016 at 8:09 PM, Robin S said:

Maybe $pages->getById() is the way to go.


$my_pages = $pages->getById([1086,1021,1053,1018]);

The situation @Wanze replied to is a little different - not an order of page IDs but an order of values to match a field against.

1 person likes this

Share this post


Link to post
Share on other sites

I like this module, I used similar plugin in Wordpress before I switched to PW, so I was happy to find it.

Regarding the code editor, a helper module would be very useful which could save and reload the scrolling and cursor position when saving the code, so I could continue the editing where I left it.
I'm not sure where, but I found something similar, but I don!t remember exactly. I tried to search in Google again and in this forum also, but no success. Maybe it was a different editor ...

Can anyone suggest a solution?
Thanks!

Share this post


Link to post
Share on other sites
1 minute ago, Battman said:

Regarding the code editor, a helper module would be very useful which could save and reload the scrolling and cursor position when saving the code, so I could continue the editing where I left it.
I'm not sure where, but I found something similar, but I don!t remember exactly. I tried to search in Google again and in this forum also, but no success. Maybe it was a different editor ...

I use that technique in the Console Panel of the TracyDebugger module - it's pretty easy to implement by storing the current position in LocalStorage or cookie. Perhaps you could send Ryan a PR with the added functionality?

Share this post


Link to post
Share on other sites
3 hours ago, adrian said:

I use that technique in the Console Panel of the TracyDebugger module - it's pretty easy to implement by storing the current position in LocalStorage or cookie.

I checked TracyDebugger and I like it, thanks for the suggestion!
As I see, it uses Ace editor also, so your solution can be implemented in the Hanna code modul too. Can you give me more details, how you did that?

Share this post


Link to post
Share on other sites
5 minutes ago, Battman said:

I checked TracyDebugger and I like it, thanks for the suggestion!
As I see, it uses Ace editor also, so your solution can be implemented in the Hanna code modul too. Can you give me more details, how you did that?

Save position:

https://github.com/adrianbj/TracyDebugger/blob/865a669a3ddfc0e528413452235e8aefe50e332e/ConsolePanel.inc#L95-L107

Restore position:

https://github.com/adrianbj/TracyDebugger/blob/865a669a3ddfc0e528413452235e8aefe50e332e/ConsolePanel.inc#L540-L545

Share this post


Link to post
Share on other sites
44 minutes ago, adrian said:

Thanks! I dig into Hanna code modul to see, how difficult would be to implement this storage ...

1 person likes this

Share this post


Link to post
Share on other sites

Hi all,

distracted for a while by other (bigger) problems, I now came back to the situation discussed here in this thread in october:

On 27.10.2016 at 3:01 PM, ottogal said:

@Robin S

Good find, thank you!

After this change even my simple use of the function strstr() works -  to crop the string on both ends, setting free the href attribute value:


<?php
$f = (string) $file;
$f = strstr($f,'/site');
$audiofile = strstr($f,'">',true);
?>
<audio controls>
	<source src='<?= $audiofile?>' type='audio/mp3'> 
</audio>

Your second hint to use SimpleXMLElement() of course is a cleaner way to do it:


<?php
$a = new SimpleXMLElement($file);
$audiofile = $a['href']->__toString();
?>
<audio controls>
	<source src='<?= $audiofile?>' type='audio/mp3'> 
</audio>

 

For my Hanna Code call    [[mp3 audio='LINK']]    now I have this Hanna Code (mp3.php):  (and all works fine - :) )

<?php
$a = new SimpleXMLElement($audio);
$pagelink = $a['href']->__toString();
$pagename = basename($pagelink);
$ap = $pages->get("template=audio,parent=audiopool,name=$pagename");
$link = $ap->mp3->url;
?>
	<div class='block'>
		<audio  controls width='400'>
			<source src='<?= $link ?>' type='audio/mp3'> 
		</audio>
	</div>
	<p><?= $pagename ?></p>

But when I open the Hanna Code in the editor and click the button "Save & Test", I get the following messages:

Quote

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in ....../site/assets/cache/HannaCode/mp3.php on line 4

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: LINK in ....../site/assets/cache/HannaCode/mp3.php on line 4

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in ....../site/assets/cache/HannaCode/mp3.php on line 4


ProcessWire: ProcessHannaCode: String could not be parsed as XML
......

The line number refers to the file  ....../site/assets/cache/HannaCode/mp3.php where  the line

Quote

if(!defined("PROCESSWIRE")) die("no direct access");

and a blank line are prepended - so  the line in question is, of course: 

Quote

$a = new SimpleXMLElement($audio);

What is wrong with the code, and how can I get rid of these Warnings?

Thankful for some clarification:

ottogal

Share this post


Link to post
Share on other sites
1 hour ago, ottogal said:

But when I open the Hanna Code in the editor and click the button "Save & Test", I get the following messages:

I think that's because when you use your Hanna tag in CKEditor your audio attribute is (or should be) valid link markup, e.g. <a href="/some/url/">LINK</a>

But in the Hanna Code test tab the attribute is not a valid link but simply the string "LINK" which cannot be parsed by SimpleXML. So probably nothing to worry about, but if the error message is a concern you can do some simple check to see if the attribute looks like it will be a link. For example, at the top of your Hanna code:

if(substr($audio, 0, 2) !== '<a') return;

 

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By justb3a
      Displays countries and continents and their iso codes.
      The "value" for each country is the two-letter country code. 
      As an added bonus, the country names are displayed in the language of the user (sorted by name ASC) if the appropriate translation was added.
       
      read more ...
       
    • By Robin S
      I'd hate to know how much accumulated time I have spent and how much eye-strain I have experienced over the last couple of years, hunting through the 675 icons in the "all icons" view for the one I want. Today I finally got around to doing something about it.
      IconsFilter
      Allows the "all icons" view in InputfieldIcon to be filtered by name.
      Usage
      Install the IconsFilter module.
      When viewing "all icons" in InputfieldIcon (Advanced tab of field/template settings) you can filter the icons by name using the filter input at top right.
       

       
      https://github.com/Toutouwai/IconsFilter
       
      @tpr, something that could be merged into AdminOnSteroids?
    • By horst
      Croppable Image 3 (beta)
      for PW 3.0.20+
      Module Version 1.1.7
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
      Sticking with a PW legacy 2.8.20+ Version (none namespaced)? - I have created a CroppableImage2 snapshot, which you can get from the github repo branch: CroppableImage2 

      -------------------------------------------------------------------------
       
    • By kongondo
      Variations
      Released 29 May 2017
      Variations is a simple yet powerful commercial ProcessWire module that allows website editors to create attributes and their values and from those generate variations of any entity, most notably products.
      The module consists of  FieldtypeVariations and InputfieldVariations as well as a ProcessVariations for managing variations configurations and attributes.   Setting up the field is quite easy.   First, create a field of type Variations. Define some custom inputs that will need to be directly edited on the page containing the field, for instance a product price, SKU, etc.   Secondly, via the Inputfield, create a couple of attributes.   Thirdly, create a variations configuration and add the attributes and values you want in the configuration. Link that variations configuration to your page and the module will automatically generate all possible combinations (variations) of the attribute values in that configuration. These, together with the custom inputs you created when setting up the field will be displayed on the page (e.g. a product page), ready for editing. This makes this module quite unique; variations are defined at the page-level rather than at the field level. This presents lots of possibilities such as infinitely reusable attributes and variations configurations.    For those using Padloper, integration with the e-commerce platform is quite simple as demonstrated in this tutorial.  The module consists of 4 modules
      ProcessVariations FieldtypeVariations InputfieldVariations VariationsCustomTableManager (autoload module, working behind the scenes) Video Demo: https://youtu.be/T93nn96UL8o
      Documentation: https://variations.kongondo.com/
      Shop: https://processwireshop.pw/plugins/variations/
      Requires: ProcessWire 2.5 or newer
      Features
      Easily create variations of anything, including products for e-commerce websites, etc   Create an attribute once, use it everywhere, multiple times, picking and choosing all or only the attribute values you want Bulk editing of variations configurations and attributes Reusable variations configurations Works with Padloper out-of-the-box with minimal coding User-friendly, intuitive and easy to set up
    • By joshuag
      Introducing our newest [commercial] module:
      Recurme
      Processwire Recurring Dates Field & Custom Calendar Module.
      http://www.99lime.com/modules/recurme/
      One Field to Recur them ALL…
      A Recurring Dates InputField for your Processwire templates. The InputField you’ve been waiting for.
      Complex RRule date repeating in a simple and fast user interface.
      Use the super simple, & powerful API to output them into your templates.
      example:
      <? // easy to get recurring events $events = $recurme->find(); // events for this day $events = $recurme->day(); // events for this week $events = $recurme->week(); // events for this month $events = $recurme->month(); ?> <? // Loop through your events foreach($events as $event){ echo $event->title; echo $event->start_date; echo $event->rrule; echo $event->original->url; ... } ?> Unlimited Custom Calendars.
      Imagine you could create any calendar you wanted on your website. Use recurring events with the Recurme field, or use your own Processwire pages and date fields to render calendars… it’s up to you. Fully customizable. Make as many calendars as you like. Get events from anywhere. Recurme does all the hard date work for you.
      Unlimited Custom Admin Calendars too.
      Hope you like it  ,
       Joshua & Eduardo from 99Lime.
       





       
      ## [1.0.1] - 2017-05-29
      ### changed
      - Fixed $options[weekStartDay] offset in Calendar
      - Fixed ->renderCalendar() Blank Days
      - Fixed missing ->renderList() [renderMonth][xAfter]
      - Removed ->renderCalendar() <table> attributes border, border-spacing
      - Fixed ->renderCalendar() excluded dates
      - Fixed rrule-giu.js exclude dates
      - Fixed ->renderList missing space in attr ID
      (shout out to @Juergen for multiple suggestions & feedback).