ryan

Hanna Code

328 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 VirtuallyCreative
      Hello PW Community,
      I'm trying to modify a small module I found to pull in Gravatars but I'm having a bit of an issue and was curious if someone has already done a Gravatar implementation, or could look over the module code? It installed no problem, but when I try to use it, nothing works.
      Here is the full module:
      <?php /** * Module for generating Gravatar URLs for ProcessWire users. * * Use it like this: * * Get URL only with all defaults: * $user->gravatar() * * Get image tag with different size: * $user->gravatar(array('img' => true, 's' => 200)); * */ class Gravatar extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Gravatar', 'version' => 1, 'summary' => 'Gravatar hook for users', 'singular' => true, 'autoload' => true, 'icon' => 'smile-o', ); } public function init() { $this->addHook('User::gravatar', $this, 'methodGravatar'); } public function methodGravatar($event) { $u = $event->object; if ( ! $u instanceof User) $event->return = false; return; if ( ! $u->email) $event->return = false; return; $params = ($event->arguments(0) ? $event->arguments(0) : array()); // Default options $defaults = array( 's' => 100, 'd' => 'retro', 'r' => 'g', 'img' => false, 'attrs' => array(), ); $opts = array_merge($defaults, $params); extract($opts); $url = '//www.gravatar.com/avatar/'; $url .= md5(strtolower(trim($u->email))); $url .= "?s=$s&d=$d&r=$r"; if ($img) { $url = '<img src="' . $url . '"'; foreach ($attrs as $key => $val ) { $url .= ' ' . $key . '="' . $val . '"'; } $url .= ' />'; } $event->return = $url; } } The issue is when I use $user->gravatar() I'm getting back "unknown". I know that the email being used by the current logged-in user (me) does have a Gravatar, but I'm unable to get the URL so I can place it into my template markup.
      Any insight or direction would be appreciated. I did a search for Gravatar modules / forum topics but it mostly appears to be linked to the Blog profile that uses Gravatar, not a stand-alone module / implementation.
      Regards,
      VirtuallyCreative
    • By cosmicsafari
      Hi All,
      Fairly new to ProcessWire so apologies if this is a daft question, but I am having a go creating my first module. I have set it up and enabled it as per the docs.
      However I have created another class within the same module directory, which was going to be used in the main module file but I can't get it to work for the life of me and I believe its due to me not fully understanding the namespace side of things.
      Example:
      MyModule.module.php
      <?php namespace ProcessWire; class MyModule extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Test Module', 'version' => 1, 'summary' => 'Test module', 'href' => '', 'singular' => true, 'autoload' => true, 'icon' => 'exchange', ); } public function newMethod( $testMessage ) { $foo = new Foo($testMessage); $foo->getFoo(); } } Foo.php
      <?php namespace ProcessWire; class Foo { protected $foo; public function __construct($foo) { $this->foo = $foo; } public function getFoo() { return $this->foo; } } Now as I understand it both these files should exist under the ProcessWire namespace, so in theory I should be able to use Foo within MyModule without any use statements as they both exist at the same level within the ProcessWire namespace?
      However when I try something like so:
      $myModule = $modules->getModule('MyModule'); $myModule->myMethod('Foo'); I would have thought this should return 'Foo', however I keep running into errors like:
      Any help would be appreciated.
    • By Max Allan Niklasson
      Hi, I think this is my first topic, even though I've been working with PW a few years. But now, I'm trying to restructure my way of coding, cause many templates (like activities for birding societies) are re appearing in multiple different websites. Since this, I've been working on redo this into a module, but as far as I have read I cannot store the templates (related to specific module) in the module's folder. It has to be in the templates folder?
       
    • By kongondo
      Menu Builder
       
      Modules Directory
      Project Page
      Read Me (How to install, use, etc..)

      If you want a navigation that mirrors your ProcessWire page tree, the system allows you to easily create recursive menus using either vanilla PHP or Soma's great MarkupSimpleNavigation. In some cases, however, you may wish to create menus that:
      1. Do not mirror you site's page tree (hirarchies and ancestry); and
      2. You can add custom links (external to your site) to.

      That is primarily where Menu Builder comes in. It is also helpful if you:
      3. Prefer creating menus via drag and drop
      4. Have a need for menus (or other listings) that will be changing regularly or that you want to allow your admin users to edit.

      The issue of custom menus is not new here in the forums. The difference is that this module allows you to easily create such menus via drag and drop in the Admin. Actually, you can even use it to just create some list if you wanted to. In the backend, the module uses the jQueryUI plugin nestedSortable by Manuele J Sarfatti for the drag and drop and is inspired in part by the WP Custom Menu feature.
       
      Please read the Read Me completely before using this module. 
      For Complex or highly-customised menus, it is recommended to use the getMenuItems() method as detailed in this post.
       
      Features
      Ability to create menus that do not mirror your ProcessWire Page Tree hierarchy/structure Menus can contain both ProcessWire pages and custom links Create menu hierarchies and nesting via drag and drop Easily add CSS IDs and Classes to each menu item on creating the menu items (both custom and from ProcessWire pages) or post creation. Optionally set custom links to open in a new tab Change menu item titles built from ProcessWire pages (without affecting the original page). E.g. if you have a page titled 'About Us' but you want the menu item title to be 'About' Readily view the structure and settings for each menu item Menus stored as pages (note: just the menu, not the items!) Menu items stored as JSON in a field in the menu pages (empty values not stored) Add menu items from ProcessWire pages using page fields (option to choose between PageAutocomplete and AsmSelect [default]) or a Selector (e.g. template=basic-page, limit=20, sort=title). For page fields, you can specify a selector to return only those specified pages for selection in the page field (i.e. asm and autocomplete) For superusers, optionally allow markup in your menu titles, e.g. <span>About</span> Menu settings for nestedSortable - e.g. maxLevels (limit nesting levels) Advanced features (e.g. add pages via selector, menu settings) currently permissible to superadmins only (may change to be permission-based) Delete single or all menu items without deleting the menu itself Lock down menus for editing Highly configurable MarkupMenuBuilder - e.g. can pass menu id, title, name or array to render(); Passing an array means you can conditionally manipulate it before rendering, e.g. make certain menu branches visible only to certain users [the code is up to you!]  Optionally grab menu items only (as a Menu object WireArray or a normal array) and use your own code to create custom highly complex menus to meet any need. More... In the backend, ProcessMenuBuilder does the menu creation. For the frontend, menus are displayed using MarkupMenuBuilder.

      Credits

      In this module's infancy (way back!), I wanted to know more about ProcessWire modules as well as improve my PHP skills. As they say, what better way to learn than to actually create something? So, I developed this module (instead of writing PW tutorials as promised, tsk, tsk, naughty, naughty!) in my own summer of code . Props to Wanze, Soma, Pete, Antti and Ryan whose modules I studied (read copied ) to help in my module development and to Teppo for his wonderful write-up on the "Anatomy of fields in ProcessWire" that vastly improved my knowledge and understanding of how PW works. Diogo and marcus for idea about using pages (rather than a custom db table), onjegolders for his helpful UI comments, Martijn Geerts, OrganizedFellow, dazzyweb and Mike Anthony for 'pushing me' to complete this module and netcarver for help with the code.
       
      Screens

    • By kongondo
      Introducing Variations, an Input- and Fieldtype for product variations and their attributes.
      Product variations is a topic that has been coming up now and then, especially in the recent past.  This module seeks to fill this gap. Though it's in its early stages of development, it is already functional and can be used as is. I decided to make an early announcement (modules development forum) in order to get early feedback from potential users. 
      The module is an alternative take on how variations can be built for a product. Imagine the ubiquitous T-Shirt. The product could vary by ...Size, Colour, Material, etc...These variations could in turn have internal variations, i.e. attributes....so, Size [Small, Large], Colour [Red, Blue]...etc; you get the drift.
      The usual approaches to building variations have been either to use Multiple pages, Repeaters, Page Table, Table or Matrix (limited to 1x1 variations). In this module, we do it a bit differently.
      First, the variations occur not at the Field level (meaning all product pages would have the same variations and attributes for each template) but at the page level. Secondly, there are no multiple pages for each variation and/or attributes; a product is a single page. The variations and their attributes are defined by site editors at the page level. Once a variations configuration has been defined, it is applied to the page and all possible combinations are generated (i.e. the Red,Small,Cotton; Red,Large,Cotton, etc) in the Inputfield. There is no limit to the number of variations and attributes that can be defined, although you will be amazed at how quickly the combinations grow! Prices are entered for each combination when editing the page. Combinations without prices are not saved to the database. Please note that prices cannot themselves vary at the page-level. Meaning, you cannot have ONE variation configuration that has different price inputs per product in the same FieldtypeVariations field.
      The module ships with an API for outputting variation combinations in the frontend. Search, database and in-memory work as normal in the frontend. In the backend, DataTables provides a nice paginated, filterable table. Prices can be entered on any pages (of the table) without loss of data (meaning you can enter prices on page 1, scroll to page 10, enter more prices, filter or search the products table, enter more prices and finally save; no data will be lost).
      I still have a couple of ideas and plans pending but would love to hear from you, thanks.
      Below is a short video demo of the module in its current state. Things may/will change, both UI and features. Btw, the Fieldtype, although primarily targeted at commerce applications, is by no means limited to this. Other uses requiring combinations of whatever number of variables are very much within the remit of the module.
      Planned/Hoped for features
      Import/Export product variations and attributes (Excel, etc) Full integration with Padloper (I will have to  discuss with @apeisa) SKU fields for each product variation Add/Remove extra subfields, e.g. multi-currency prices (currently there is only 1 input for each product variations' price) Product variation images? Etc... Please not this module is not related to this other planned module (but it may eventually).
      Sneak Peek Demo