I have website build in php .
I like the revision control system used in SO edited answers. like we can see al the old revisions.
Now i am new to that and have no idea how to implement it . i mean its a software plugin or its programmed like that.
If i want to do that on my all php files how to do that.
I know there are software for that but how link those with website like SO has done . i mean although in the software there may be all the old versions but how to link those with webiste php
It requires more work with the database. Your application will have to store old revisions itself (or use triggers/views). Commonly a separate archive table is created for everything you normally store in your database. The crucial part of that is a version field:
CREATE TABLE articles ( // always the current version
title VARCHAR,
content TEXT
)
CREATE TABLE articles_ARCHIVE (
version INT with AUTO_INCREMENT,
title VARCHAR,
content TEXT,
) // yes, that's not a correct CREATE TABLE, just figuratively
And whenever you regularily would just update the articles table, you will instead first store the current version into the _archive table. And only afterwards store the new current text into the regular table.
Now to replicate what SO provides, you will also need some more UI logic. But a diff view for comparing _archive texts against the current version is not difficult (see PEAR Text_Diff).
I think you could look into a common Wiki implementation to get an idea how it is done in practice.
Use GIT for your code control, and have a look at these existing PHP frontends to GIT to get you started.
SO's review system is custom-built I guess, so you'll have to build what you want on your own.
Related
I am developing a lyrics importing website using PHP in CodeIgniter framework. In that website I need to compare the old lyrics and new lyrics after using editing.
I need to show what user deleted from previous and inserted.
Is there any algorithm or library?
Similar question has been answered here, although a little bit older question: Highlight the difference between two strings in PHP
There are as well countless other "diff" packages/libraries available. They do not need to be CI specific in order for you to use it.
I've been struggling with this for a while now. One my CMS' is ready to be extended with a translation module. I've been thinking of different methods but haven't figured out what is the best way so far.
Basically I have a CMS which uses a template system to parse all data from a database to the screen. I've come so far to "split up" my templates in different folders to be able to translate things that are "static" like images with text, footer links, etc.
However, there are many modules (pages, news, products) that have multiple fields that require a database driven method to be translated. I started off with a "languages" table which describes languages (id, iso_code, name). That's as far as I've come.. since there were a couple of projects that had to be done I haven't spend any more time to this subject thus far.
My first thought ("the quick fix") was to add multiple fields inside the tables (such as "title_nl", "title_en"), but this actually makes the database more crowded than is needed in my opinion.
My second thought was to create a table, "news_translations" for example. Which contained the language iso code, a news_id, the fields that require translation. Obviously a news_id connects the translation to it's original and the language iso code is used to get the right language from the database. Then in my front-end code I would first check if the default language is selected (=> select from the "news" table) or a translation (=> check inside translations table). If the 2nd case does not return any results a message is display "Sorry, no translation available" and the default is shown (or an error message, what fits the client best..).
But then there's a 3rd option.. my websites all use search engine friendly links (www.domain.com/pagename/ or www.domain.com/news/1-news-item-here.html). It would be far better if I had the ability to also "override" the SEF URL in my translations table. But I guess in this case I would always need 1 extra query to the translations table (since we first want to check for a translated page)... guess it's not such a big deal, but it's worth considering I guess.
In the end I guess by describing my options number 3 is what I need. But I'd like to have some other opinions on the subject as well! This is what I am trying to achieve:
Create a CMS system with multi language support
No language files (obviously this is why I use templates)
Being able to translate an original page/newsitem/product
Optionally: to change the SEF URL according to the language
I think option 3 has all this.. so the steps to create this solution is:
Create a _translation table for each item (or perhaps even in the
original by adding 2 new fields 'translation_to' (containing the
PrimaryKey) and 'translation_is' (containing ISO code) - however..
in that case all fields would need to be edited (which is not always
necessary.. plus by creating a 2nd table I keep the originals
divided with their translations, right?)
If the default language is NOT chosen first query the translations table to find a translation, if one is found display the
translation. Otherwise notify/error the user and/or display the
original text (based on the SEF URL... if the SEF is not found
within the translations or original table, then obviously display an
error only).
Any suggestions? :-)
Thanks for thinking along!
I would like to see what your table structure looks like. Probably the best thing you can do is generate two seperate new tables named something like "CONTENT_MULTI_LANG" & "SITE_LOCALES".
Then in the code that prints out your content do an initial check for a language flag. I'd create two separate classes for loading static content, something like "Content_LoadStandard" and "Content_LoadMultiLang". So then your conditional will look like this.
if ($this->site_locale == 'standard'){
$contentLoader = new Content_LoadStandard();
} else {
$contentLoader = new Content_LoadMultiLang($this->site_locale);
}
$content->blah($cheese);
Your "CONTENT_MULTI_LANG" table should be a narrowed down version of your standard CMS object table, only containing the relevant content field(s) that need to be in alternative languages.
// PSEUDO SQL
CREATE TABLE `LOCALE` (
`id` int(11),
`locale` varchar(16), // name of locale (language)
... // any other fields
)
CREATE TABLE `CONTENT_MULTI_LANG` (
`id` int(11),
`pcid` int(11), // parent content id
`lid` medint(), // locale id
`content` {$type}, // whatever type you use (varchar, text, bin, etc)
... // any other fields
)
In your Content_LoadMultiLang class, create methods to query alternate content using a join.
TIP: Might be a good idea to establish relationships in your table to do cascading deletes on content rows, that way if you delete content in standard your multi lingual version(s) will also be deleted.
From what I've seen from Drupal, option three is how they handle it, with a couple of tweaks. They keep it all in one table and a field called language. Then there is a separate table that maps which items are connected.
This way is primary language agnostic, meaning the content can be created in any language without requiring a translation in any other.
i have set up Wiki:Family using the tutorial #2 specified here
http://www.mediawiki.org/wiki/Wiki_family
Specifically, i am using same code, same folder, same database and different tables (they differ by prefixes) to create a multilanguage mediaWiki.
for now i have created two languages,
french and english which can be access by fr.sitename.com/wiki/ and en.sitename.com/wiki/
now i need to add interlanguage links to the article, the syntax
[[:fr:Main Page]]
does not work it just redirects me to a new page saying that i need to create the page as it does not exists while i can access it at fr.sitename.com/wiki/Main_Page
can someone please help me solve this?
Probably need to update your interwiki table - what does it contain now for iw_prefix='fr' ?. For example, see maintenance/wikipedia-interwiki.sql. Also I think there is a MediaWiki extension to do this, if you prefer a Web-based interface.
I find Yii great framework, and the example website created with yiic shell is a good point to start... however it doesn't cover the topic of multi-language websites, unfortunately. The docs covers the topic of translating short messages, but not keeping the multi-lingual content ...
I'm about to start working on a website which needs to be in at least two languages, and I'm wondering what is the best way to keep content for that ...
The problem is that the content is mixed extensively with common elements (like embedded video files).
I need to avoid duplicating those commons ... so far I used to have an array of arrays containing texts (usually no more than 1-2 short paragraphs), then the view file was just rendering the text from an array.
Now I'd like to avoid keeping it in arrays (which requires some attention when putting double quotations " " and is inconvenient in general...).
So, what is the best way to keep those short paragraphs? Should I keep them in DB like (id | msg_id | language | content ) and then select them by msg_id & language? That still requires me to create some msg_id's and embed them into view file ...
Is there any recommended paradigm for which Yii has some solutions?
Thanks,
m.
Gettext is good for its ease of translation, but the default PHP implementation is not thread safe. Yii therefore uses its own unpacker, dramatically increasing processing time compared to php arrays.
Since I was setting up a high volume, high transaction site, the performance hit was not acceptable. Also, by using APC, we could cache the PHP translation further increasing performance.
My approach was therefore to use PHP arrays but to keep the translations in a DB for ease of translation, generating the needed files when translations are changed.
The DB is similar to this :
TABLE Message // stores source language, updated by script
id INT UNSIGNED
category VARCHAR(20) // first argument to Yii::t()
key TEXT // second argument to Yii::t()
occurences TINYINT UNSIGNED // number of times found in sources
TABLE MessageTranslation // stores target language, translated by human
id INT UNSIGNED
language VARCHAR(3) // ISO 639-1 or 639-3, as used by Yii
messageId INT UNSIGNED // foreign key on Message table
value TEXT
version VARCHAR(15)
creationTime TIMESTAMP DEFAULT NOW()
lastModifiedTime TIMESTAMP DEFAULT NULL
lastModifiedUserId INT UNSIGNED
I then modified the CLI tool yiic 'message' command to dump the collected strings into the DB.
http://www.yiiframework.com/wiki/41/how-to-extend-yiic-shell-commands/
Once in the DB, a simple CMS can be setup to provide translators an easy way to translate and at the same time providing versioning information, reverting to older versions, checking quality of translators, etc ...
Another script, also modified from yiic, then takes the DB info and compiles it into PHP arrays. Basically a JOIN of the two tables for each language, then build an array using 'Message'.'key' and 'MessageTranslation'.'value' as (what else?) key => value ... saving to file named from 'Message'.'category' in folder specified by language.
The generated files are loaded as normal by Yii CPhpMessageSource.
For images, this was as simple as placing them in folders with the proper language and getting the app language when linking.
<img src="/images/<?php echo Yii::app()->language; ?>/help_button.png">
Note that in real life, I wrote a little helper method to strip off the country from the language string, 'en_us' should be 'en'.
A Yii application by default uses yii::t() method for translating text messages and there are 3 different types for message sources:
CPhpMessageSource : Translations are stored as key-value pairs in a PHP array.
CGettextMessageSource : Translations are stored as GNU Gettext files. (PO Files)
CDbMessageSource : Message translations are stored in database tables.
If i don't misunderstand, you are using classic arrays for translations. I recommend to you using GetText and PO files with Yii for translation operations.
You can find lot of information about translation and i18n with yii in this official documentation page.
Well I think what is concerned here is how to translate static text/messages on the page and Yii solves it pretty well using Yii:t() and Edigu's answer is for it.
I check out the post on FlexicaCMS about translating dynamic content in database, well ultimately that will be the next after you solve static text/message problem, and that is a truly good approach using Yii's behavior. Not sure if FlexicaCMS authors are too ambitious in supporting translation that way as it would make content translation a worry-free thing - really great.
One thing they don't mention is the url of translated page. For example your.site.com/fr/translated_article_title.html. I mean the url must has /language_id/ part in it so it can help with SEO.
In Yii1 and Yii2 yii\i18n\GettextMessageSource doesn't use Yii perfect cache engine anyway (look at the source) to enhance the load of PO or MO files. It's not recommended to load these files by using php pure code (including yii\i18n\GettextMessageSource) (it's so slower than php array idx) :
http://mel.melaxis.com/devblog/2006/04/10/benchmarking-php-localization-is-gettext-fast-enough/
However php gettext ext for MO files is a few faster than translation php array because it uses cache but the negative point is : every change in MO requires server restart.
I think the best solution would be to extend yii\i18n\GettextMessageSource in your own code library and add the cache ability to GettextMessageSource to enhance its performance and use your extended version as the component.
protected function loadMessages($category, $language);
Just don't check MO modified date in every load to compare against the cache , instead clear the cache when the MO or PO files are changed (it can be a schedule).
I would like to design a web app that allows me to sort, browse, and display various attributes (e.g. title, tag, description) for a collection of man pages.
Specifically, these are R documentation files within an R package that houses a collection of data sets, maintained by several people in an SVN repository. The format of these files is .Rd, which is LaTeX-like, but different.
R has functions for converting these man pages to html or pdf, but I'd like to be able to have a web interface that allows users to click on a particular keyword, and bring up a list (and brief excerpts) for those man pages that have that keyword within the \keyword{} tag.
Also, the generated html is somewhat ugly and I'd like to be able to provide my own CSS.
One obvious option is to load all the metadata I desire into a database like MySQL and design my site to run queries and fetch the appropriate data.
I'd like to avoid that to minimize upkeep for future maintainers. The number of files is small (<500) and the amount of data is small (only a couple of hundred lines per file).
My current leaning is to have a script that pulls the desired metadata from each file into a summary JSON file and load this summary.json file in PHP, decode it, and loop through the array looking for those items that have attributes that match the current query (e.g. all docs with keyword1 AND keyword2).
I was starting in that direction with the following...
$contents=file_get_contents("summary.json");
$c=json_decode($contents,true);
foreach ($c as $ind=>$val ) { .... etc
Another idea was to write a script that would convert these .Rd files to xml. In that case, are there any lightweight frameworks that make it easy to sort and search a small collection of xml files?
I'm not sure if xQuery is overkill or if I have time to dig into it...
I think I'm suffering from too-many-options-syndrome with all the AJAX temptations. Any help is greatly appreciated.
I'm looking for a super simple solution. How might some of you out there approach this?
My approach would be parsing the keywords (from your description i assume they have a special notation to distinguish them from normal words/text) from the files and storing this data as searchindex somewhere. Does not have to be mySQL, sqlite would surely be enough for your project.
A search would then be very simple.
Parsing files could be automated as post-commit-hook to your subversion repository.
Why don't you create table SUMMARIES with column for each of summary's fields?
Then you could index that with full-text index, assigning different weight to each field.
You don't need MySQL, you can use SQLite which has the the Google's full-text indexing (FTS3) built in.