Standard method to find and edit front-end files in CakePHP - cakephp

I have recently been asked to take over the administration of a website that is built on CakePHP 3.x.
I have never worked with CakePHP before. Everything I have read talks about using a command line interface, but I haven't done this since I was in Uni.
I discovered a Dashboard on the website where I can enter or edit the products, but I was wondering about the pages on the site.
I had to change some phone numbers in the footer of each page and it was only hunting through the files that I found src/Template/Element/footer.ctp and edited this.
Is there some way of editing the pages without finding the individual files?

No. What you're referring to (the command-line stuff) is for when you're baking files, running shell tasks, doing database migrations, installing things via composer, or using the built-in local server...etc. There are other uses too, but editing front-end files is not usually one of them.
Though there are methods for altering local files via command line, for the things you're talking about, like editing a footer, or other pages (.ctp "Template files" in Cake 3), it's standard practice to just do that manually.
See the standard path for template files in these examples:
src/Template/Users/profile.ctp
src/Template/Pages/contact.ctp
src/Template/Layout/default.ctp
A "layout" file usually fetches the header, content, and footer.
As you've found, there are also Elements, which are smaller chunks of code that are reusable across one or more Template files.

Related

Generate static websites dynamically using Hugo

I'm building a static website hosting and would like to generate default web pages for my users and would like to use Hugo for this. Question is, what would be the best way to dynamically generate web pages for multiple users? This is my thought so far:
User fills up form for their website content e.g., photos, title, product descriptions, etc.
Pass to backend (I'm using Perl's Mojolicious) and create markdown files based on the provided information and save them in a designated folder created for this user
Run Hugo to build using those md files and move the public folder to user's root directory
This doesn't look right to me as there will be contention of multiple users to run Hugo and I'm thinking that it is much easier if I can just create the html files directly from backend instead of creating md files and then run Hugo to create the html files. Is there any better and smarter way?
If I am not mistaken, it seems you want to make a WordPress portal alike or something similar, going from Markdown plus theme down to HTMl/CSS/JavaScript content. The end-users edit the content in Markdown, choose the theme and the rest will be taken care of.
IMHO, there might be two ways:
(1) Using Hugo at the back-end and taking care of the destination folders and generated artifacts as well as mapping generated links to the front-end corresponding to your particular end-user's hosting. You can create a Hugo wrapper in which the input will be fed to Hugo and the generated pages will be in the public folder. In this way, you have to rely on an external tool (read Hugo) and wish for a long-term support version like many other systems (e.g. Ubuntu, Java, Windows).
(2) Creating a similar generator like Hugo or another (c.f. StaticGen for more generators on different languages). You may need the core of a Markdown based static site generator, for instance, a Markdown parser, link translators and generators, etc. With extra effort, you might have more control of every smaller component/library that you use, can configure the generated artifacts, their destinations, etc.
A side note: Markdown is a not-so-bad choice for content. Even WordPress have offered support for Markdown. Nonetheless, Markdown itself is not standardized but rather de facto. There are so many flavours. You might want to look up to or stick with a good one, for example, CommonMark.

Hiding the word "joomla" from a script in contact form

Whenever i create a contact form in my Joomla! 3.3.6, some script appears in the the page's HTML code that contains many words Joomla in it. I'd like to change those Joomla words and replace them with another words (i.e. Foo) for some security issue. I'd like to know whether or not i'm able to do so and how.
That script is:
<script>(function(){var strings={"JLIB_FORM_FIELD_INVALID":"\u0641\u06cc\u0644\u062f \u0646\u0627\u0645\u0639\u062a\u0628\u0631:&#160"};if(typeof Joomla=='undefined'){Joomla={};Joomla.JText=strings;}
else{Joomla.JText.load(strings);}})();</script>
I have no idea whether a plugin or an extension creates it or not.
Thank you
Regards
This script seems to be translating some text required for the form to use in its javascript, eg validation messages. It does this using a javascript version of JText, which is part of core Joomla. There is some info on how that works here. Weirdly, there seems to be little information in the official Joomla documentation about it.
The main JText function it is calling appears here: media/system/js/core.js
I'm sure it would be possible to write a plug-in to remove this script before the page is rendered and then to translate any untranslated text with your own scripts. However, I'm not sure I see any security benefit in doing this so it seems a waste of time.
Ultimately, someone sniffing a site for what it is built in is far more likely to see if core files exist by going direct to places like media/system/js/core.js, rather than to scan the code for the word "Joomla" - which would trigger a lot of false-positives (any site which just mentions Joomla) and negatives (any page which doesn't have a form on it). It also does not reveal the version of Joomla, which is the info a hacker would more likely be after.
I think you have to search for the script (i.e via Notepad++) in the whole directory. It must be a plugin for the contact form that has some inline script in it.
also do you use any special third party plugin or so? that might be the source of it.
PS: also i had some similar experience, i don't know exactly how i got rid of those words, but like you, i wanted to do that to hide the fact that i'm using joomla for security.
Its actually Joomla who add this, from the file: Joomlainstall/libraries/joomla/document/html/renderer/head.php
And load it globaly from:
Joomlainstall/libraries/cms/html/formbehavior.php
The developer ad that code by using the function, JText, for an example:
JText::_( 'COM_CONTACT_EMAIL_FORM' )
In my case it was the plugin ContactUs Form who add the javascript. If JText is not used, it is not loaded. If I disabled the plugin, the javascript was then not loaded. If you have that plugin enabled, my be try an other contact form?
For security reson it is bad programming by the developer off Joomla, for sure.

Database vs static html files for storage solution (Site Builder)

Project Description:
As a learning exercise for asp mvc 4, I'm creating a site builder / multitenancy site. It's nothing too fancy just wysiwyg editing on templates with custom routing to direct users to the correct template based on subdomain. So usr1.mysite.com is directed to the template edited by usr1. My main concern at the moment is my method of storing the edited templates.
Storage Dilemma:
At first I was simply going to make the templates into views and store the changes made by the user in the database. When usr1's template was displayed the system would pull up the view and populate it with usr1's data.
Instead I've implemented a system that takes the user's modified template and saves the whole thing as static html files in the file system. Only the path to the usr1's site (and some other details) are saved in the database. When usr1.mysite.com is called I just have a "content" controller to retrieve the correct html file.
Question:
Is there any reason to choose the database/view method over the static html file method?
Also I'm not concerned with having dynamic content in the end user pages. This is one reason I even tried the file method.
Decision (EDIT):
I'm implementing the file method. After more research (verifying my previous research), I have few doubts the file system will have trouble with even a few hundred sites. I will structure it in a way to group user data directories into group directories based on a naming convention I've yet to dream up, probably something like 000usr1, 000usr2 in 000 group directory. With a goal of less than 100 files/folders in any given directory and less than 4 levels deep. Which should give me the capability of holding 10000 sites. I have no plans of having any activity near that level with this software, but I do want to get up and running and torture it for awhile and see what it's capable of handling. If anyone expresses any interest I'll post back some results.

language specific pages are confused while creating a new portal from "Portal template" in bilingual portals

While creating a new Portal (dnn 5.6.1) from "portal template" which is created from a bilingual portal(en and tr), all pages(both en and tr) are created in one language. if I activated the second language creates another set of pages for both en and tr pages.
I tried creating a portal template while the second language is disabled but result is same.
do you have any idea to overcome this issue?
My hunch is that, at time of writing, this is an outstanding issue that can't be resolved directly through the UI (I say that because it sounds like you tried every reasonable measure).
If that is the case, your best bet would probably be to edit the generated portal template XML file and remove the elements that represent the second languages pages prior to importing to your target dnn instance. Then you could enable the second language and it would replicate the first language's pages and you could re-localize them. (Hopefully you don't have a ton of pages!).
Alternatively, you could potentially export page level templates for the second language and import them after you've done the import of the portal in the first language. If you take this path, and you have a lot of pages, you may export individually but "bulk import" them by placing them in the /Install/Template folder and hitting the /Install/Install.aspx?mode=installresources URL.
DNN 5.6.1 and i believe also DNN6 has serious issues with exporting/importing multilingual portals. From what i read, the multilingual issue is overcome in DNN 7 which is a major update.
One way to work with legacy multilingual DNN sites is this (far from ideal):
The template which is going to be exported must be in only one language. You may not press the "enable content localization". This is the moment after which export/import becomes very messy.
You export the single language template (this you must keep as the backup point)
Now you import your template.
Then you enable other languages & content localization button (wait till pages are created)
Now you enter the content into the second language pages.
No backups can be created, so you can only backup the content you have entered in the second language, manually..
In any case i recommend you start fresh with DNN7 or a different CMS altogether (WP, Drupal, Joomla...).

What are your recommendations for reducing the number of resources (JavaScript and CSS) that DotNetNuke loads?

The home page for DotNetNuke 5.2 is around 252.6KB. It uses 15 JavaScripts and 8 CSS files. The number of resources DotNetNuke uses seems excessive to me. I am looking for best practices creating DotNetNuke skins that limit the JavaScript and CSS resources.
You can use the Unload CSS Skin Object to remove links to some of the CSS files loaded by the framework (like Default.css, portal.css & any module-specific CSS files). You can then move all of those styles into the skin (or portal stylesheet, whichever is your preference), so that there's only one stylesheet that gets loaded.
I don't know of any solutions for combining JavaScript resources or reducing the number of scripts that DNN requires.
From 6.1 onward, the Client Resource Management component is the solution for this. It automatically combines all your files, cleaning them up, removing comments, and minifying if desired.
http://www.dotnetnuke.com/Resources/Wiki/Page/Client-Resource-Management-API.aspx
It takes a little getting used to, but the control is quite nice. You can decide which order they'll go in, you can group the files in bunches if you don't want one big single file - maybe you want certain bunches of scripts together but not all.
One thing to remember is that when you're doing development (as noted by the comment below, which I've since edited this post), you should always use debug=true in the web.config, otherwise if you are using Resource Mgmt and change your source files, you'll constantly need to regenerate the combined files by going into Site Settings, Client Resource Management, and increment the version. It's kind of a protection to keep anything from altering your clients' browser caches without intent (that's the message box that pops up to let you know when you do it). I'm sure if you have a zillion users this might make a difference.
Part of that is just the dynamic nature of DNN - there are some good resources that R2i has published about combining javascript and CSS
One concrete suggestion is to combine all your skin and contianer css in one file and if you have full control of the site to combine the css from the modules you use into that same file.
I know with the addition of the Telerik controls there is some abilities to combine resource files
Another thing that helps is to combine graphics into a single file and use CSS (the sprite technique) to cut down number of files loaded and calls to the sever
Like it was stated above, it's the nature of the beast. Each module will have at least 1 css file included. You can check out PageBlaster from snapsis.com, I believe it will do what you are looking for.

Resources