How to automate "remove comments" from public Website - html

Is there a way of getting ride of comments on a published webpage?
I tend to over-comment my HTML code when I am working on it so I can refer back to previous code, or some test changes I made. When I publish the Website publicly, if someone uses something like Chrome-inspect to see the code, they can see all the comments there.
I want those comments hidden when Its public, but stay while I'm editing it.
So my question is, does anyone have a good way to tag/mark comments for removal once published? or some script to strip the comments clean? (And is there a risk to stripping all the comments)

you can change .html on the end of the file to .php all of the html will work the same but put the comments in something like this and they'll be hidden.
<?php
//hidden comment
//you can't see this
?>
start each line with //
i'm not sure what text editor you are using but in sublime text you can select large areas of text and hit ctrl+/ to make them all into a comment while they are in the php tag
<?php //comments ?>

Related

Prefix a URL with CSS

I am pulling the content of a bunch of customer reviews from a website using a tiny piece of PHP, though the title of each review contains the URL to the original review on the website that it comes from, which is great, except that the URL that is pulled does not contain to originating websites full address.
So on my website, the link does not work. You can see it in action here:
http://www.clearpandb.co.uk/new2016/feedback.php try clicking one of the review titles.
Is there any way to fix this with CSS? I think all it needs is a prefix to the original site. What is pulled from the originating site is just e.g. "/job/view/1971050", which when clicked tries to find this on my site (obviously won't find it). So I need to prefix it with "www.mybuilder.com" so that it works.
If the above isn't possible, a last resort might be to just disable the URL (without removing the title text itself) just so that there isn't a bunch of broken links.
PHP being used:
<?php
include_once('simple_html_dom.php');
$target_url = "https://www.mybuilder.com/profile/view/clear_plumbing_and_building_ltd/feedback";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('li[class=job-view-feedback]') as $jobviewfeedback){
echo $jobviewfeedback;
}
?>
I'm using a modified version of this tutorial for this:
http://www.makeuseof.com/tag/build-webcrawler-part-2
Which makes use of the a "helper" called "Simple HTML DOM".
Any help or pointers in the right direction are much appreciated, thanks in advance!
Can you edit that PHP? If so, do a PHP string replace on $jobviewfeedback... search for href="/ and replace with href="http://www.mybuilder.com/
so instead of
echo $jobviewfeedback;
you'd have
echo str_replace('href="/', 'href="http://www.mybuilder.com/', $jobviewfeedback);

WP removing all br tags from my pages when I try to edit them

WordPress 3.7.1, one of the pages contains a lot of code looking like this:
...
<td>
<strong>Text</strong><br/>
Text<br/>
Text
</td>
I know, not the best HTML, however, changes of the HTML structure are not possible due to various reasons. I can save the page and it works fine, however, when I try to edit the page again (no TinyMCE or similar installed) WP stripped all the br tags without even asking (no, I've not even switched to the visual editor, HTML edit only).
I've searched the WWW, but couldn't find a working solution yet. Most fixes are TinyMCE-related.
Also the very high voted Removing <p> and <br/> tags in WordPress posts didn't change a thing.
Anyone knows a solution or on which part of WP I have to look to find the problem? I'm unfortunately far away from being a WP expert.
Edit: Installing the Text Control plugin and setting everything to "No Formatting" didn't help either,.
It seems that we destroyed it by using the Visual Editor in a previous version of the document which generated some invalid HTML which in turn confused the HTML editor thus removing all br tags completely.
After making the HTML valid again it does not strip the br tags anymore, still, weird behavior.
Try disabling the 'visual' tab from the editor via your user profile. That would stop it defaulting to 'visual' and overwriting the changes made on the text tab during those subsequent edits, and the text tab accepts html just fine!
Actually, I was also very frustrated trying to find a solution to this problem.
Realised that the solution was a simple one.
The editor.js and editor.js.min files have preg_match and replace functions to replace <p> tags with "".
Separate <div> containing <p>
//content = content.replace( /<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n' );
comment the above line
Similarly
// Remove <p> and <br />
//content = content.replace( /\s*<p>/gi, '' );
//content = content.replace( /\s*<\/p>\s*/gi, '\n\n' );
The explaination given in the documentation is that it is for Prettying up the source editor, so doesnt look harmful to remove it.
Thanks

How to hide or remove comments in browser view page source?

I'm working on a site. It contains a lot of comments. When a user click the view page source in any browser, I want to hide or remove the comments from the HTML.
Is this possible? If possible, could someone say a way to achieve it.
Easiest way to hide code from browser and page source, use php comments:
For quick one liner notes:
<?php //Hide this ?>
For blocks of code:
<?php /*
(html code to comment out here)
*/ ?>
Another advantage to using ?php as comments, is they're ...secret... you won't expose comments you want only for your team. Seeeee-cret
At the moment I decided to use php to create html and jquery comments to hide them in view source
like
<input type="submit" value="Submit">
<?php //this is comment regarding input ?>
Possibly it affects performance... but found no other way
Regarding jquery one note.
//$('#upper_level_id0').css('color', 'red');<?php //works ?>
$('#upper_level_id'+index).remove();
In this example $('#upper_level_id'+index).remove(); does not work.
$('#upper_level_id0').css('color', 'red');<?php //works ?>
//$('#upper_level_id0').css('color', 'red');
<?php //works ?>
$('#upper_level_id'+index).remove();
But in this example all works. So conclusion that <?php comment better tos start in new line
Well you cant do that. But before you upload the html files to your server you can minify the source and upload them. But before uploading check if everything is working as expected or not. Try this website.
http://www.willpeavy.com/minifier/
The source view shows the source. You have no control over how the browser will render it.
If you don't want comments to show up when the user of the browser views the source, then don't put them in the source that your server delivers to the browser.
If you have your own webserver, you can use Google's plugin called PageSpeed that is available both for Apache and Nginx, one of it's many features is to remove your comments from the code both html and css.
I think the only workaround would be to open a new browser window and copy the html contents there using javascript - it will be the rendered code already so there you won't have any comments.
But it's rather unlikely that you need this. The simple way is not to output your comments on server side. Now there are a lot of options (output buffering plus minification seems to be the most reasonable).
Jsource view shows the source. You have no control over how the browser will render it.
If you don't want comments to show up when the user of the browser views the source, then don't put them in the source

Headings created inside of a template

I have a number of templates that create headings based on a formula. I am wondering if there is anyway to create an "edit" link that will take you directly to that section? The way that it currently works, the edit link takes you to editing the template itself. Could I possibly create a customized link that would keep you on the page and take you to right part?
Here is some sample code to help clear things up...
Template:Head:
==={{{1}}}===
This is a heading titled "{{{1}}}"
Test Page:
=Section 1=
{{head|1.1}}
{{head|1.2}}
{{head|1.3}}
=Section 2=
{{head|2.1}}
{{head|2.2}}
{{head|2.3}}
At the moment, if I want to edit the information for template "2.3", I have to edit all of section 2. (Note that for this example, that isn't a big deal. For the actual templates I am working with on my site, the templates have dozens of parameters and there are sometimes 10 or more in a section.)
Bottom line, is there way to create a custom edit link inside of the {{head}} template that would take you directly to editing the templates call on the page "Test Page"? Hope that makes sense.
Edit: Is there perhaps a way to make use of "anchor" tags? Can anchors be passed in to the URL?
To restate your problem, when you transclude a section heading the header isn't treated as being part of the destination page, so the edit link takes you back to the source. So you need a separate container for the template in order to edit it individually, and a complete section is the smallest editable container.
The only way I can think of doing this is using subpages (or virtual subpages if you don't have that ennabled in this namespace, doesn't change anything). So instead of placing {{head|1.1}} on MyPage, put it on MyPage/Subpage1 and then transclude that into MyPage in the usual way ({{:MyPage/Subpage1}}).
{{head}} can then include a custom edit link to the template input by using HTML heading tags (<h2> is equal to ==, etc.) to suppress the standard edit link and then use one of these templates (probably {{ed right}}) to create a custom edit link pointing to MyPage/Subpage1.
The way to create anchors in Mediawiki, by the way, is to use a <span id="name"/> tag, but that doesn't create a container that can be edited (or at least, not that I've been able to work out through URL tinkering).
I'm pretty sure there's no way to do that. As far as MediaWiki's section editing feature is concerned, the only thing that begins a new section is a line of the form:
=== Some text here ===
with the number of = signs determining the level of the heading. There's no way to get MediaWiki to let you edit any segment of the document that doesn't begin and end with such a line (or the beginning or end of the page).
Well, OK, I'm sure you technically could do it with an extension, in the sense that you can do anything with a MediaWiki extension. All you'd need to do is provide some way (e.g. a special parameter in an edit URL) for to user to indicate "I want to edit this template", then extract the template from the wikitext, present it to the user for editing, and write the result back into the page text over the original.
The tricky part will be extracting the template from the page source. (Finding and replacing templates on a page is a fairly common task for MediaWiki bot writers, so you might want to look for ideas there.) Whatever method you end up using for that, there will probably be edge cases where you need to give up and tell the user "Sorry, but I can't figure out how that template is transcluded here."

MediaWiki : is it possible to add an edit link in a template?

I have a template on my wiki, kind of a box template.
Then, there is this page where I use it several times.
Can I add an edit link to each of the boxes so I don't have to edit the whole page in order to modify one of the boxes?
The boxes contain only text, not other templates.
Thanks!
Edit: Actually there's an easier way to ask my question:
Let's say I have a page without sections defined (namely without == titles ==):
content A
content B
content C
Is there a way to open an edit form only for content B?
"Is there a way to open an edit form only for content B?" - in standard mediawiki - no, but you can do sth like this
Main page will look like this:
{{/subpageA}}
{{/subpageB}}
{{/subpageC}}
subpageA will contain link to edit subpageA etc
But it is worse than sections in every possible way.
If I understand your question, and I'm not sure I do, I'm assuming your box is a div or table of some sort? If so, you could add id="{{{1|Some identifying parameter}}} to it.. Now, similar to if you had used == header 2 == you will be able to link to that section of the page with [[{{PAGENAMEE}}#{{{1|Some identifying parameter}}}]]. The only trick is to edit that section. You would likely have to set up a <span class=plainlinks>[http://somewiki.com/edit/{{PAGENAMEE}}&section={{{1|Some identifying parameter}}}]</span> Although, I'm not sure using the section name will work on your wiki, it works on only one of four that I edit. The other three require the section number, which may be harder to figure out, or at very least is beyond my pay-grade atm..
Not sure what you're asking here. Do you want to edit the template from the referring page?
Update:
One: The ugly but simple solution:
Add the following code above the text you want to edit:
=== ===
This will create a section with no name, but with an edit link. If you make four or more of these links, you will create a TOC in the page. You can suppress this with:
__NOTOC__
Two: The neat but extensive solution:
Make your wiki semantic and use Semantic_Forms to edit the page using a form.
Not with the standard installation.
But, I'm sure you could write an extension to do this. Eg. Right click on the page and it will start editing there.
It is possible to add link to edit template, so you can make ugly hack and create separate templates/subpages for every single box.