Jump to content

Hanna Code


ryan

Recommended Posts

  • 1 month later...

In /site/init.php...

$config->css_files = new \ProcessWire\FilenameArray();
$config->js_files = new \ProcessWire\FilenameArray();

In your Hanna Code PHP...

$config->css_files->add('/site/templates/path/to/file.css');
$config->js_files->add('/site/templates/path/to/file.js');

Wherever you output your <head>...

foreach($config->css_files as $css_file) {
    echo "<link rel='stylesheet' href='$css_file'>";
}
foreach($config->js_files as $js_file) {
    echo "<script src='$js_file'></script>";
}

See the code for the FilenameArray methods available: prepend(), remove(), removeAll(), etc.

P.S. you can use the existing core $config->styles and $config->scripts FilenameArrays but other files might be added to these by certain modules so cleaner to create your own FilenameArrays I think.

  • Like 6
Link to comment
Share on other sites

  • 1 month later...
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.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

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?

 

Link to comment
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();

 

  • Like 1
Link to comment
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!

Link to comment
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.

Link to comment
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

Link to comment
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.

  • Like 1
Link to comment
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 :)

 

  • Like 2
Link to comment
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.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

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!

Link to comment
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?

Link to comment
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?

Link to comment
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

Link to comment
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
×
×
  • Create New...