Jump to content

Hanna Code


ryan

Recommended Posts

After a whiIe of not using the module I recently ran into an issue when I reinstalled the hanna code module. I tried uninstalling the module and reinstalling it, but then I run into the issue of:

SQLSTATE[HY000]: General error: 1813 Tablespace '`revamp`.`hanna_code`' exists.

I checked the database with adminer and searched for "hanna_code", but I am not seeing any tablespace in the database. Is there a way of clearing this out so I can do a fresh install?

Also, I was going to use this module to allow people to define the form fields they would like to use in a setup I am currently developing (one per line). For example, they could type in [[form-firstname]] and the output would be:

<input type="text" name="firstname" id="firstname" required>
<label for="firstname" class="is-required">First Name</label>

In my infinite wisdom, I thought I could explode by the line and wrap each input into a column/row. Obviously this doesnt work as the output is actually two lines (and some of my hanna codes would output up to 6 lines). Is there a good way to go about adding in rows/columns to the actual inputs?

Link to comment
Share on other sites

  • 1 month later...

Is it possible to pass session vars immediately in Hanna Code?

Let’s say, I include two PHP files file_1.php and file_2.php via Hanna Code input in a textarea. When I set $session->foo = "bar" in file_1.php and try to get the value in file_2.php it is not there before page reload. Obviously it has to do with the rendering/formatting order. Is there a more or less dirty trick to intrude the session vars into Hanna Code in the first run?

Link to comment
Share on other sites

Hi,

I know this module have not changed since many years, but could I suggest to add a description for each Hanna code? I come back to my setup page and have some codes that I didn't update since years and I don't know why/where they used through my website. I would like to have written a small description. Yes, you could tell me I should have written comments in the code itself, and it's what I would do starting from now... 🙄 But something on the setup page will be faster to read.
Thanks!

  • Like 3
Link to comment
Share on other sites

  • 2 months later...

I am using an custom attribute. But it gets rendered with a tag. When I

bd($vid)

the output is

</code>508075620<code>

The value 508075620 is correct. I had to strip the tags manually. But would like to know whats going on.

Link to comment
Share on other sites

  • 2 months later...
13 minutes ago, JFn said:

Although the issue is closed, I commented on it, since it's the same error but not the same resolution or offending module installed.

The old version of @Robin S's HannaCodeDialog module also called that method: https://github.com/Toutouwai/HannaCodeDialog/blob/7ea31c31f151fbe3ea1982c83ac94dfa209e763e/HannaCodeDialog.module#L175

Update to the latest version of that and you should be fine.

Link to comment
Share on other sites

After a second look, apparently the offending HannaCodeHelper module was installed, although I don't recall installing it, was it part of the previous version by default?

Anyway, disabling it, no more errors, problem solved.

  • Like 1
Link to comment
Share on other sites

Just now, adrian said:

Nope 🙂

Oh my, I must be getting old ☺️. That's the thing with processwire, you set it and forget it, it just keeps on running 😉

Link to comment
Share on other sites

  • 2 weeks later...

I have trouble with latest update v0.3.0 – my hanna code stops working.

In v0.2.0 I could use 
#1: wire("pages")->get($someid) – in v0.3.0 it throws error "Call to undefined function wire()".
It's easily fixed by calling $pages->get($someid) instead - but I wonder why it's now the opposite as it was in v0.2.0 where I couldn't use $pages?

#2: Inside the hanna code I call custom functions defined in _func.php (included @ready.php – I once moved the include from site/_init.php to ready.php to be able to use the shared functions in hanna code). That worked with v0.2.0, now in v0.3.0 I receive the same error as above "Call to undefined function myFunction()"s

I guess I've got something basically wrong here… I have no clue how to get my custom functions work inside hanna code. Anybody can shed a light … ?

ProcessWire: 3.0.165
PHP: 7.4.11

Link to comment
Share on other sites

2 hours ago, Ivan Gretsky said:

I guess it is namespace related. Try adding ProcessWire namespace in you Hanna codes.

Ah, I forgot to mention it, I tried already – adding <?php Namespace Processwire; doesn't change anything…

Link to comment
Share on other sites

On 4/29/2021 at 3:40 PM, adrian said:

Try calling the function like:

\ProcessWire\myFunction()

…ah… thank you adrian! I rember seeing that before. The whole change from v0.2.0 to v0.3.0 is kind of nebulous for me… I should read about namespacing I guess.
And it works! I namespaced all my hanna codes now, changed all wire('…') to $…-> and prefixed my custom function calls as you mentioned. 

Link to comment
Share on other sites

  • 4 months later...
On 4/29/2021 at 9:34 AM, Ivan Gretsky said:

Try adding ProcessWire namespace in you Hanna codes.

 

On 4/29/2021 at 2:40 PM, adrian said:

Try calling the function like:

\ProcessWire\myFunction()

I am confused by this. Surely it should not be necessary to both add the namespace in the Hanna code AND call the function \ProcessWire\myFunction()?

So I looked at the TextFormatterHannaCode.module - getPHP() method and found this:


		$php = '<' . '?php';
		$openPHP = $php;
		$openPHPNS = "$php namespace ProcessWire;";
		$firstLine = 'if(!defined("PROCESSWIRE")) die("no direct access");';

		if(strpos($code, 'namespace') && preg_match('/(namespace\s+ProcessWire(?:;|\s*;))/', $code, $matches)) {
			$openPHP = $openPHPNS;
			$code = str_replace($matches[1], '', $code);
		}

		if(strpos($code, $openPHP) !== 0 && strpos($code, $php) !== 0) {
			// prepend open PHP tag to code if not already present
			$code = "$openPHP\n$firstLine\n$code"; 
		} else {
			// otherwise insert our $firstLine security check
			$code = str_replace($openPHP, "$openPHP\n$firstLine\n", $code); 
		}

It seems that the method is removing "namespace ProcessWire;" from the Hanna code. Looking at the cached files shows this to be the case. In other words, adding  "namespace ProcessWire;" to the Hanna code is pointless as \ProcessWire\myfunction() is still going to be needed.

I really don't know why the above code has been added or what it is trying to achieve?

  • Like 1
Link to comment
Share on other sites

On 9/6/2021 at 9:12 AM, MarkE said:

I really don't know why the above code has been added or what it is trying to achieve?

The more I look at this, the more it seems to me to be a bug. The current method has the effect of not only removing the namespace, but also failing to add:

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

to the Hanna code.

In my case, I have dozens of Hanna codes all just calling one hannaCode() function, so that I can maintain the codes in my IDE rather than the PW UI (much less time-consuming!). The upgrade seems to require me to edit every single Hanna code, which surely ought not to be the intention. I have therefore hacked my TextFormatterHannaCode.module to include the following in getPHP():
 


		$php = '<' . '?php';
		$openPHP = $php;
		$openPHPNS = "$php namespace ProcessWire;";
		$firstLine = 'if(!defined("PROCESSWIRE")) die("no direct access");';
		
		if(strpos($code, 'namespace') && preg_match('/(namespace\s+ProcessWire(?:;|\s*;))/', $code, $matches)) {
			$openPHP = $openPHPNS;
			$code = str_replace($matches[1], '', $code);
		}

		if(strpos($code, $openPHP) !== 0 && strpos($code, $php) !== 0) {
			// prepend open PHP tag to code if not already present
			$code = "$openPHPNS\n$firstLine\n$code"; 
		} else {
			// otherwise insert our $firstLine security check
			$code = str_replace($php, "$openPHPNS\n$firstLine\n", $code);
		}

This automatically adds the namespace and the 'die' to all Hanna codes and works (so far) for me. Perhaps others ( @adrian, @ryan?) might suggest a better fix or tell me that I've got it all wrong 😉 

EDIT: I have raised an issue on GitHub for this

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

       
×
×
  • Create New...