I wonder if it's possible to view a PHP code source in a way that https://j11y.io/jquery/ shows a JQ code. Of course I mean reading code from a given file, not from websites code.
I'm not looking for programs like the PHPdocumentor.
Thank you in advance for any reasonable reply.
P.S. For perfectionists - I'm searching for a nice website or software (and I would prefer that option, so that I can be quite sure about the security), which will give me such a useful ability. I'm disturbed after using CTRL-F all the time ;)
Related
I know that \Phar and \PharData exist, but I'm having some trouble with the methods they supply so far. I'm still having to detect the mime-type / file type by whatever means, before determining which Phar*::method() to use in an attempt to extract the archive and do work on the files it contains.
Is there a go-to, "easy-button" class that I could include (maybe some package available via composer) that handles this at a very high level? Or am I failing to use the Phar and friends properly or in need of re-RTM so far?
Basically, I want to do the following (it's a CLI script that I control for now, so security, while important with this type of thing, is on the backburner for now):
Detect that a file might be an archive of some kind.
Validate that it seems to be one of the following: .tar, .gz, .tar.gz, or .zip.
If so, attempt to extract the archive and then parse the content of it's actual files.
Is there an "easy-button" for this that I'm unaware of, or do I need to build some logic that guesses as best it can as to what type of archive it might be, and then try to use the appropriate Phar* method to attempt to extract it's files and do whatever work I need to on them?
I hope that makes sense the way I wrote it. I'm trying to avoid re-inventing the wheel for a mini-project here if someone has already figured all of this out basically.
So, while continuing to research this I ended up seeing my own (this) SO question in google search results, which annoys me for some reason. So just in case someone stumbles upon this looking for a good solution, I've since found a couple by searching https://packagist.org/search/?q=archive (go figure):
Here's a few of them that seem promising.
wapmorgan/UnifiedArchive:
wapmorgan/UnifiedArchive (packagist)
wapmorgan/UnifiedArchive (github source)
Features (at first glance):
Only has one requirement of pear/archive_tar (which includes a few
more utility classes also from pear).
It attempts to detect the filetype for you, so it could eliminate the need to do that on your own.
alchemy/zippy:
alchemy/zippy (packagist)
alchemy-fr/Zippy (github source)
Features (at first glance):
Code looks to have been very well designed.
Seems to integrate with Laravel and guzzle\guzzle (the popular php http client) in some way so that might be an advantage for some.
zetacomponents/Archive
zetacomponents/Archive (packagist)
zetacomponents/Archive (github source)
Features (at first glance):
It seems to be a pure php implementation? If so that's just awesome.
Last updated 15 days ago, so it's the most active of the three I mentioned.
Seems to be maintained by an organization as opposed to a single person.
It has the most downloads by far on packagist (when searching for "archive"), and though I haven't played with it yet, that's usually a good sign.
Disclaimer: I have only actually tried wapmorgan/UnifiedArchive as of this writing, and so far it's exactly what I was looking for.
Anyway, I hope this helps anyone who might stumble upon this question.
If you don't need pure php and if your code is running on a linux machine, a
exec('uncompress [-cfv] [file...]');
or a
exec('unzip filename.zip -d destination');
will extract the file and make it usable for php.
Of course you need to check the extension (zip, tar, etc) in order to call the right command
Im looking for an prefferably automated tool that generates a diagram over the
structure of a laaaaaaaaaarge php project, files with 10 000 lines of code in them.
Mixed php with html with css and javascript here and there.
Need the ones in charge to realize that the project needs refactoring.
Theres not really any oop in this project so some kind of class diagram overview
would only show a small part of the project since its 99% functions.
Anyone that could point me in the right direction to sort out this mess? :)
I don't know if this will truly help but it's too big for a comment..
There is a program called Doxygen which can generate documentation from php source files, now bear with me..
There is an extension to this program that generates structographs(?) structograms based on the source too, it may be of some help.
Failing that this question and maybe this one can offer you some advice on how to get the message across.
I've looked through several Google searches now, and continue to keep coming up empty when it comes to finding some end-user documentation for the File_PDF package.
A lot of people have pointed to FPDF, which is a predecessor, and as far I know, no longer compatible. FPDF hasn't been updated (http://fpdf.org/) since 2008, either.
I've found a few small snippets of code for File_PDF here and there, but nothing over like 20 lines of code.
Then I came across this little "nugget" of wealth: http://dev.horde.org/pdf/
There's plenty of examples, none of which I've looked through yet, but I'm hoping it does the trick.
In the mean time, does anyone else have some recommendations for PDF generation with PHP?
Last time I needed to generate PDF files with PHP that is what I used (admittedly back in '07) with no major problems.
Things change though and if File_PDF is more intuitive to use or has a better feature-set then you should obviously use it instead.
I feel obliged to point out that there appears to be a later version of File_PDF available at http://pear.php.net/package/File_PDF than at http://dev.horde.org/pdf/
Have you evaluated any of the PDF related classes at http://www.phpclasses.org?
Ended up using tcpdf, as many examples were provided from their site.
I'm writing a WordPress plugin to create an eBook from a selected category in most major eBook formats. I would like to support MobiPocket since that's the format used by the Kindle but I'm not sure how to go about it. From what I've read .mobi files are actually Palm Resource Databases (PRC) but I haven't been able to find a PHP class to work with these.
I thought about using exec along with KindleGen but that would be undesirable as it would complicate initial setup. I've also thought about hosting a web service somewhere and using XML-RPC to accomplish this but that also complicates things.
My question is: is there a PHP class/library (PHP-only preferred) that can work with PRC or even better, a class that specialises in creating MobiPocket ebooks? (needs to be open source since I'm releasing under the GPL)
I've tried searching but haven't been able to find anything.
I don't know whether you're still looking for this PHP library, but just in case: https://github.com/raiju/phpMobi. This is a library that creates mobi files from html files.
It's should still be seen as an experimental version, but it should work without a problem for basic document with a few images.
Unfortunately not; however, the binary compiled format is an open specification available at:
http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen
The only direct way of transforming the uncompiled format is using the native XML functionality of PHP to create them and then invoking a compiler with exec, which I understand you don't want to do. If you go with this route, the link above also has details about this XML format.
You might want to try the mobiperl tools,
https://dev.mobileread.com/trac/mobiperl/wiki
Please note I haven't tested them yet. But they have been
around since at least 2007 so they should work well by now.
google "Mobiperl - Perl tools for handling MobiPocket files" to
find a thread on mobileread board discussing it. As a new
poster I can't put 2 hyperlinks into my reply.
Another tool I have recently found (but not yet tested), is: http://www.phpclasses.org/package/8173-PHP-Generate-Kindle-ebook-file-in-mobi-format.html#files
It is based upon KindleGen, and looks pretty straight forward to implement.
I am going to start working on a website that has already been built by someone else.
The main script was bought and then adjusted by the lead programmer. The lead has left and I am the only programmer.
Never met the lead and there are no papers, documentation or comments in the code to help me out, also there are many functions with single letter names. There are also parts of the code that are all compressed in one line (like where there should be 200 lines there is one).
There are a few hundred files.
My questions are:
Does anyone have any advice on how to understand this system?
Has anyone had any similar experiences?
Does anyone have a quick way of decompressing the lines?
Please help me out here. This is my first big break and I really want this to work out well.
Thanks
EDIT:
On regards to the question:
- Does anyone have a quick way of decompressing the lines?
I just used notepad++ (extended replace) and netbeans (the format option) to change a file from 1696 lines to 5584!!
This is going to be a loooonnngggg project
For reformatting the source, try this online pretty-printer: http://www.prettyprinter.de/
For understanding the HTML and CSS, use Firebug.
For understanding the PHP code, step through it in a debugger. (I can't personally recommend a PHP debugger, but I've heard good things about Komodo.)
Start by checking the whole thing into source control, if you haven't already, and then as you work out what the various functions and variables do, rename them to something sensible and check in your changes.
If you can cobble together some rough regression tests (eg. with Selenium) before you start then you can be reasonably sure you aren't breaking anything as you go.
Ouch! I feel your pain!
A few things to get started:
If you're not using source control, don't do anything else until you get that set up. As you hack away at the files, you need to be able to revert to previous, presumably-working versions. Which source-control system you use isn't as important as using one. Subversion is easy and widely used.
Get an editor with a good PHP syntax highlighter and code folder. Which one is largely down to platform and personal taste; I like JEdit and Notepad++. These will help you navigate the code within a page. JEdit's folder is the best around. Notepad++ has a cool feature that when you highlight a word it highlights the other occurrences in the same file, so you can easily see e.g. where a tag begins, or where a variable is used.
Unwind those long lines by search-and-replace ';' with ';\n' -- at least you'll get every statement on a line of its own. The pretty-printer mentioned above will do the same plus indent. But I find that going in and indenting the code manually is a nice way to start to get familiar with it.
Analyze the website's major use cases and trace each one. If you're a front-end guy, this might be easier if you start from the front-end and work your way back to the DB; if you're a back-end guy, start with the DB and see what talks to it, and then how that's used to render pages -- either way works. Use FireBug in Firefox to inspect e.g. forms to see what names the fields take and what page they post to. Look at the PHP page to see what happens next. Use some echo() statements to print out the values of variables at various places. Finally, crack open the DB and get familiar with its schema.
Lather, rinse, repeat.
Good luck!
Could you get a copy of the original script version which was bought? It might be that that is documented. You could then use a comparison tool like Beyond Compare in order to extract any modifications that have been made.
If the functions names are only one letter it could be that the code is encoded with some kind of tool (I think Zend had a tool like that - Zend Encoder?) so that people cannot copy it. You should try to find an unencoded version, if there is one because that would save a lot of time.