Add PHPWord to Joomla - joomla

I need to add the quite excellent PHPWord - https://github.com/PHPOffice/PHPWord to a Joomla 2.5 project.
I have added the PHPWord files to the plugins folder (might not be the correct choice) and have the following code
$phpWord = new \libraries\PhpOffice\PhpWord\PhpWord();
The class is not found as it is not autoloading. How would I load these classes in Joomla and it there a better folder than plugins that will will autoload?
I have added these lines
JLoader::discover('PhpWord', JPATH_LIBRARIES . '/PhpOffice/PhpWord/');
$phpWord = new PhpWord;
Inside the PhpWord folder is Phpword.php and autoloader.php, as well as several other scripts.

As said in the comment above in Using_own_library_in_your_extensions they explain how to import a library for Joomla 2.5 and Joomla 3.
Now assuming that the tutorial is correct and JLoader::discover is working I would say that the issue is that you have PHPWord in the plugin folder and with JLoader::discover you are searching in /libraries/PhpOffice/PhpWord/.
So
copy /PhpOffice/PhpWord/ in libraries
try to use again JLoader::discover('PhpWord', JPATH_LIBRARIES . '/PhpOffice/PhpWord/');
Reading the documentation of PhpWord I found that you can also directly require the library and use it in this way:
// be sure that the path match in your joomla
require_once 'libraries/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();

Related

Is there any way to change the creator PDF generation in spipu/html2pdf

I've been using spipu/Html2Pdf version 5.2 in laravel 5.8 to generating PDF, and trying to set my own creator name on the PDF (by default the creator is Html2Pdf - TCPDF)
Is that any way to change it via Html2Pdf class (without modifying the vendor)? or am I allowed to do that?
The creator name comes from TCPDF package (A package Html2Pdf uses) and I think it can be changed with the following:
$html2pdf = new \Spipu\Html2Pdf\Html2Pdf('P', 'A4', 'en');
$html2pdf->pdf->setCreator('CREATOR NAME');

Why are no embedded files found in EmbeddedFileProvider in asp.net core mvc?

I'm currently trying to load embedded ViewComponents from external assemblies.
I've included this in my project file:
<EmbeddedResource Include="Views\**\*.cshtml" />
so when I inspect the actual assembly and run GetManifestResourceNames() I see that the file is embedded.
I'm then calling this method in ConfigureService() in Startup.cs:
public static IMvcBuilder GetModules(this IMvcBuilder mvcBuilder)
{
var embeddedFileProviders = new List<EmbeddedFileProvider>
{
new EmbeddedFileProvider(Assembly.GetCallingAssembly())
};
mvcBuilder.ConfigureApplicationPartManager(apm =>
{
foreach (string modulePath in Directory.GetFiles(Configuration.Settings.Path, "*.Module.dll"))
{
var assembly = Assembly.LoadFrom(modulePath);
var startUpType = (from t in assembly.GetTypes()
where t.GetInterfaces().Contains(typeof(IModuleStartup))
select t).FirstOrDefault();
RegisterModuleServices(mvcBuilder, startUpType);
apm.ApplicationParts.Add(new AssemblyPart(assembly));
embeddedFileProviders.Add(new EmbeddedFileProvider(assembly));
Modules.Assemblies.Add(assembly);
}
var compositeFileProvider = new CompositeFileProvider(embeddedFileProviders);
mvcBuilder.Services.AddSingleton<IFileProvider>(compositeFileProvider);
});
return mvcBuilder;
}
I'm also not using
mvcBuilder.Services.Configure<RazorViewEngineOptions>(o =>
{
o.FileProviders.Add(compositeFileProvider);
});
as this doesn't work at all and the action o.FileProviders.Add(compositeFileProvider) is not even called.
All the embedded file providers are found when I inject IFileProvider but none of the files are found when I run _fileProvider.GetDirectoryContents("");
Does anybody have any idea why?
So i figured out why it wasn't returning anything...
It seems that I didn't set the baseNameSpace parameter when created the new EmbeddedFileProvider. stupid huh.
But there were quite a few examples that didn't set this and it worked.
Hopefully this helps some other people out there if they experience this issue.
Watch also your project root namespace setting. My case was the reverse - I copy-n-pasted a project file and it did not retain the namespace setting from the previous project. This was because I did not explicitly set <RootNamespace>YourNameSpaceNameHere</RootNamespace> in the .csproj settings
(nested under the <PropertyGroup> block at the top), so it took my file name as the namespace! It was quite a "gotcha" moment, and much time lost, to find out my code correctly sets the baseNameSpace parameter, but the whole time the project was storing the files under a different namespace! (you can open the DLL in any text editor, scroll to the bottom, and you should easily be able to make out the embedded text to verify). It was there, just not found. In case someone has this correct, you can also dump ALL files using {Assembly}.GetManifestResourceNames() and make sure your names are correct.
In my case I had '.' (period) in the resource filename.
I had this error in an ASPNET Core 3.0 project, where my external class library had the file correctly embedded, but the web application was not locating them at runtime. It turns out the example I copied from the internet had a namespace provided and I copied that example namespace without considering the implications...
After a bit of research, I was able to fix it by simply using the proper root namespace defined my own Class Library:
var embeddedFileProvider =
new Microsoft.Extensions.FileProviders
.EmbeddedFileProvider(assembly, "ViewComponentLibrary");
changed to
var embeddedFileProvider =
new Microsoft.Extensions.FileProviders
.EmbeddedFileProvider(assembly, "MyProjectLibrary");
We had another root cause leading to this problem. We had migrate our build agents from windows to linux, and FS case-sensitivity of the latter did the trick - it didn't found embedded resources:
<EmbeddedResource Include="swagger\ui\*" />
because on file system we have Swagger\ui\
So the #(EmbeddedResource) path must be the same as the File System path:
<EmbeddedResource Include="Swagger\ui\*" />
(or rename files/directories, to match the #(EmbeddedResource).

How To Deploy: Installing Mezzanine Theme

How to install Mezzanine Theme exactly, step-by-step?
E.g., Moderna free theme.
Preconditions:
0) Versioning
Python 2.7.6.
Django 1.6.10
Mezzanine 3.1.10
Moderna v.? (static content)
1) I used PythonAnywhere for hosting
2) I followed this way to install Mezzanine: here, at the bottom there are links to PythonAnywhere specific guides
3) So, initial state is: Mezzanine is deployed, empty, with default theme.
4) [optional] Basic templates are collected (~80 of them it was)
5) Static is collected via python manage.py collectstatic
1. Add moderna to project
That's a simple step.
You should go to site with theme (for moderna it's here ) and download it. It will be a Django App, probably zipped into archive.
If app is zipped, unzip it.
Move it to your Mezzanine project folder (the one, which got created by command mezzanine-project myproject)
Folder structure should become:
myproject/
+-deploy/
+-static/
+-templates/ [in case you chose to collect them]
+-moderna/ [our new theme]
|
+-__init__.py
+-settings.py
+-urls.py
+-manage.py
+-wsgi.py
|
+-[some other things]
2. Change settings.py
open settings.py of your Mezzanine project
add moderna/templates to TEMPLATE_DIRS in settings.py 1st recor. The point is to give new directions to template loaders - now they 1st look for templates in moderna. Should now look like this:
TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, "moderna/templates"),
os.path.join(PROJECT_ROOT, "templates"),
)
add moderna app to INSTALLED_APPS in settings.py above all (I presume, that's for Moderna's views, models etc. - backend for templates)
3. New Static Files
collectstatic again - now it will grab moderna's static
4. URLConf
in urls.py, use DIRECT_TO_TEMPLATE selected for / (root url), it should look like this:
urlpatterns += patterns('',
url("^$", direct_to_template, {"template": "index.html"}, name="home"),
("^", include("mezzanine.urls")),
...
5. Reload
I guess some servers would pick up new settings and urls automatically. Those which don't should be reloaded manually to catch up and start showing your beautiful new theme.
6. Customization begins
Now you can start customizing Moderna theme via base.html and index.html files in myproject/moderna/templates/ folder.
Postscriptum
I welcome any corrections and extensions, I'm not an expert in Mezzanine customization and the topic has many of slippery slopes.

Google Fonts and JQuery not working when hosted by Google Drive

I've uploaded them to a public folder. Everything works apart from these two.
Is there some extra "Google Drive Hosting" script I need to put in?
Or should it be working without any extra and I need re-check my code?
Many thanks!
me also faced same problem while uploading my custom Jquery Plugin, bt i can able upload js file to an existing folder which is already using for my previous project , me faced this problem while creating new folder only
but
In my new folder me just deleted that js file and uploaded it again ,its working fr me nw
save file as .js
content of that file
(function ( $ ) {
$.fn.doValidation = function(options) {
//ur code goes here
}( jQuery ));

magento create own package or use default

The main reason I like creating a fresh package is that it allows you to keep a clean separation between your store themes and the default bundled Magento themes. On the other hand most extensions install layout and template files to app/design/frontend/default/default/ and if your theme is installed under the default package magento will find the extensions frontend files or else you'll have to copy extension files to app/design/frontend/package/default/ always. So it's a little more work using your own package.
I'm curious to see if I'm missing anything else so what are some of the benefits of creating your own theme package in Magento as opposed to using the default package?
First of all, creating a new package is something that Magento Official user guide is required to do.
http://info.magento.com/rs/magentocommerce/images/MagentoDesignGuide.pdf
Here is what it says:
"Please ignore legacy Magento instructions and tutorials that instruct you to create your custom theme inside of the default design package, or to edit files in the default/default directory directly. Rather, the method that affords the best upgrade path for your theme and the most protection from accidental changes is to create a new design package and to create your custom theme inside of there."
My personal logic for creating a new package is if Magento requires few store views and they have differences, I need to have my own 'default' theme and that's exactly what I get by creating my own package (Magento will look for files in the my_theme theme in custom design package, then in the default theme and then fallback to the base package)
If you use default/default, and third-party extensions you use place their files in default/default, then you can't override those files - you have to edit them directly.
So, by
fixing the third-party extension in a vendor/upstream branch
using your own package
you can override only the templates/layouts you need in your package.
The two folder /app/design and /skin are identical(Mirror image we can say).Keep all the css,image files under /skin/your_theme directory and .phtml for layouts in /app/design/your_theme folder.
the default/default package is bad designed from my point of view.
If you use your own package the extensions cannot use your default-directory (?Right?).
I would suggest to add a field default-package.
I use this work-around now - config.xml:
<core>
<rewrite>
<design_package>Your_Extension_Model_Design_Package</design_package>
</rewrite>
</core>
Model/Design/Package.php
class Your_Extension_Model_Design_Package extends Mage_Core_Model_Design_Package
{
/**
* Use this one to get existing file name with fallback to default
*
* $params['_type'] is required
*
* #param string $file
* #param array $params
* #return string
*/
public function getFilename($file, array $params)
{
Varien_Profiler::start(__METHOD__);
$this->updateParamDefaults($params);
$result = $this->_fallback($file, $params, array(
array(),
//'_package' is new. Uses this package when looking for default theme
array('_theme' => $this->getFallbackTheme()),
array('_theme' => self::DEFAULT_THEME, '_package' => 'default'),
));
Varien_Profiler::stop(__METHOD__);
return $result;
}
}

Resources