Using plugin in PHPfox - plugins

Can anyone tell me why this call {plugin call='video.template_block_entry_1'} is made in phpfox\module\video\template\default\block\entry.html.php file?

That is a hook, it allow other module can insert their code to this file.
Example, in other module, we can create a new file name: video.template_block_entry_1.php in module/[module_name]/include/plugin/
with contain:
<?php echo "Hello world";
More text hello world will include to entry.html.php

Related

Trying to return a static file in web.py but getting "not found" error message

I have a web.py server hosted on pythonanywhere.com doing some handy things with python.
Now I'd like to just serve a straightforward html file from the same server i.e. just return the contents of a static html file to the client
The comments/answers below state that it should be possible, out of the box, to serve static files in the static directory, located in the same directory as the main python file which contains the following :
import web
urls = (
'/', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self):
return 'Hello, Joe'
if __name__ == "__main__":
app.run()
The server above works fine, when I go to http://myhost/ it displays "Hello , Joe".
The directory static exists and contains a file small.jpg but when I try the url http://myhost/static/small.jpg it gives me "not found"
Previous text of question up to Nov 9th 2022 is below :
original question title : Trying to return a html file in web.py but getting "No template named ....." error message
So I've looked at the web.py documentation on serving static files and templating and I think the following code should work :
import web
render = web.template.render('static/')
# have also tried render = web.template.render('/full/path/to/static/')
urls = (
'/getlatlongEIRCODE', 'getlatlongEIRCODE', #other stuff
'/getlatlongGOOGLE', 'getlatlongGOOGLE', #other stuff
'/getmonthlyPV', 'getmonthlyPV', #other stuff
'/Tomas', 'Tomas',
)
class Tomas:
def GET(self):
return render.Tomas()
I have created a folder static at the same level as my file above (which works fine for the other scripts) and i have created a file Tomas.html in the static folder containing
<h1>Help me</h1>
However I get an error message when I go to https://example.com/Tomas
<class 'AttributeError'> at /Tomas
No template named Tomas
P.S. From the static files page it seems to say I should just be able to put the Tomas.html file in a folder called "static" and then access is via https://example.com/static/Tomas.html but that is not working (it returns "not found")
You're using a relative path to your template directory without paying attention to the working directory. See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/
You're working too hard. 'static' is built in.
As the documentation says, http://localhost/static/logo.png will return the file logo.png from the existing directory static, which is relative to your webserver root.
Do not use render() for this (not needed). Also, do not list your desired file ('/Tomas') in the urls list (not needed).
Anything under the static directory can be accessed with the url https://localhost/static/...
"static" is hardcoded in the web.py server, so you cannot (easily) change this to some other folder. The suggestion in the web.py documents is to have nginx or apache host your application and use an Alias there to go to web.py static. (I think you can also add StaticMiddleware to your web.py application, but you'd need to investigate that yourself -- look at web.application.run()
The case of the disappearing /static/ directory was related to the fact that I'm hosting on pythonanywhere.com
Even though the web.py documentation says that the /static/ folder is plugged in by default, that's not the case in pythonanywhere and you need to expressly make the link between the url http://yourhost/static/ and /path/to/static in the Web part of the dashboard.

integrate FPDF in codeIgniter 4: library and controllers

I want use fpdf in my project CI4..
how i can do this step by step?
How include it as thirdparty?!
<?php namespace App\Controllers\Purchase;
namespace App\ThirdParty\fpdf;
use CodeIgniter\Controller;
use FPDF;
?>
and how build the controller to call fpdf methods?!
$pdf = new PDF();
$pdf->AddPage();
thanks
I found a solution to this today.
Assuming your fpdf.php file is in the directory app\ThirdParty
1- make the first line of the file fpdf.php look like this
<?php namespace App\ThirdParty;
2- In your controller add the line
use App\ThirdParty\FPDF;
3- Now you can create your pdf file
$pdf = new FPDF();
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(1,13);
$pdf->AddPage('P','A4');
$this->response->setHeader('Content-Type', 'application/pdf');
$pdf->Output('test.pdf','F');
The file will be stored in the public directory of ci4.
I hope I've helped you.
I resolved this by using the old way (i.e adding fpdf directly in app/Controllers/);
Firstly, make sure you have the latest version of fpdf installed. Mine is 1.82 then unzip in app/Controllers.
require('fpdf.php');//to be done in your controller
$pdf = new \FPDF();
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(1,13);
$pdf->AddPage('P','A4');
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$this->response->setHeader('Content-Type', 'application/pdf');
$pdf->Output('test.pdf','F');
In case you are using XAMPP for linux kindly update fpdf in /opt/lampp/lib/php.
First include font folder, fpdf.php file and fpdf.css file in the ThirdParty folder.
Open fpdf.php file and include following 2 lines after <?php
namespace App\ThirdParty;
use Exception;
Then rename the fpdf.php file in ThirdParty folder to FPDF.php
Now you can import fpdf using:
use App\ThirdParty\FPDF;

Convert CloudFormation template (YAML) to Troposphere code

I have a large sized CloudFormation template written in Yaml, I want to start using Troposphere instead. Is there any easy way to convert the CF template to Troposphere code?
I have noticed this script here https://github.com/cloudtools/troposphere/blob/master/troposphere/template_generator.py
This creates a Troposphere python object, but I am not sure if its possible to output it Troposphere code.
You can do it by converting the CF YAML to JSON and running the https://github.com/cloudtools/troposphere/blob/master/scripts/cfn2py passing the JSON file in as an argument.
Adding to the good tip from #OllieB
Install dependencies using pip or poetry:
https://python-poetry.org/docs/#installation
https://github.com/cloudtools/troposphere
https://github.com/awslabs/aws-cfn-template-flip
pip install 'troposphere[policy]'
pip install cfn-flip
poetry add -D 'troposphere[policy]'
poetry add -D cfn-flip
The command line conversion is something like:
cfn-flip -c -j template-vpc.yaml template-vpc.json
cfn2py template-vpc.json > template_vpc.py
WARNING: it appears that the cfn2py script might not be fully unit tested or something, because it can generate some code that does not pass troposphere validations. I recommend adding a simple round-trip test to the end of the output python script, e.g.
if __name__ == "__main__":
template_py = json.loads(t.to_json())
with open("template-vpc.json", "r") as json_fd:
template_cfn = json.load(json_fd)
assert template_py == template_cfn
See also https://github.com/cloudtools/troposphere/issues/1879 for an example of auto-generation of pydantic models from CFN json schemas.
from troposphere.template_generator import TemplateGenerator
import yaml
with open("aws/cloudformation/template.yaml") as f:
source_content = yaml.load(f, Loader=yaml.BaseLoader)
template = TemplateGenerator(source_content)
This snippet shall give you a template object from Troposphere library. You can then make modifications using Troposphere api.

phpexcel save file to server ubuntu

I'm with a problem I would like to share to see if I can provide help.
PHP Excel use Ubuntu and want guaradar the file generated in a specific folder of my project directory. I understand that looking information is made as follows, but it is not working properly.
My code is as follows:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//header('Content-Disposition: attachment;filename="ReporteSuscriptores.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save('nameoffile.xls');
$filename = (__DIR__);
$objWriter->save($filename . '/report.xlsx');
Try other alternatives without success as the next block
$objWriter->save('nameoffile.xls');
And I can not save the file generated excel in a specific directory

Why do i use custom Variable Environment in a hosting website?

I am new to hosting world (cloudcontrol), an i got some problem with application credentials, like database administration (mongohq), or google authentification.
So, will i put those variable with some kind of syntaxte (something like $variable) in the code, and then make a commandline with key-value as variable-value ?
If you are using Tornado, it makes it even simpler. Use tornado.options and pass environment variables while running the code.
Use following in your Tornado code:
define("mysql_host", default="127.0.0.1:3306", help="Main user DB")
define("google_oauth_key", help="Client key for Google Oauth")
Then you can access the these values in your rest of your code as:
options.mysql_host
options.google_oauth_key
When you are running your Tornado script, pass the environment variables:
python main.py --mysql_host=$MYSQL_HOST --google_oauth_key=$OAUTH_KEY
assuming both $MYSQL_HOST and $OAUTH_KEY are environment variables. Let me know if you need a full working example or any further help.
example:
First set a environment variable:
$export mongo_uri_env=mongodb://alien:12345#kahana.mongohq.com:10067/essog
and make changes in your Tornado code:
define("mongo_uri", default="127.0.0.1:28017", help="MongoDB URI")
...
...
uri = options.mongo_uri
and you would run your code as
python main.py --mongo_uri=$mongo_uri_env
If you don't want to pass it while running, then you have to read that environment variable directly in your script. For that
import os
...
...
uri = os.environ['mongo_uri_env']