e107help.org Q&A
0 like 0 dislike
Hi everyone!

Could you help me with my modification?
I've been fighting this for several days.
Please, do not be mad at my code. I have recently used e107.
I did not have time to get to know its structure.
I will develop my code. I just need to add this function very urgently.

My code works. But now I have a problem how to pass the result to the code responsible for adding the news.

I tried to replace the lines responsible for this, but to no avail.
I've really tried many options.
My head is cracking from it.

My code snippet is a picture generator.

The code is too long, that's why it gives you a link

https://codeshare.io/alyWjD
e107 version 2.1.9
in Other by (22 points) 4

1 Answer

0 like 0 dislike
Hi!

I solved my problem.
The code is still weak, but it works.
I provide the code. Maybe someone will want to use it.
You just need to add a few lines, which determines what will be saved in the database.

Many thanks for any suggestions for modifying the code.

 

Mem generator v 0.1

[code]

 

 

<?php

 

require_once("class2.php");

e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_'.e_PAGE);

 

require_once(HEADERF);

 

 

 

?>

 

 

<?php

 

if (!isset($pref['subnews_class']))

{

$pref['subnews_class'] = e_UC_MEMBER;

}

 

 

if (!check_class($pref['subnews_class']))

{

e107::getRender()->tablerender(NWSLAN_12, NWSLAN_11);

require_once(FOOTERF);

exit;

}

/////////////////////////////

?>

 

<ul class="nav nav-tabs">

  <li><a href="submitnews.php?category=janusz">Janusz</a></li>

  <li><a href="submitnews.php?category=krowa">krowa</a></li>

  <li><a data-toggle="tab" href="#menu2">Menu 2</a></li>

</ul>

 

 

 

 

 

<?php

 

if(isset($_REQUEST['category']) and $_REQUEST['category']!=''){

 

if(isset($_REQUEST['category']) and $_REQUEST['category']=='janusz') {

 

define('dir', 'Generator/janusz/');

if ( !$katalog = opendir(dir) ) {

  die('<center>Podany katalog nie istnieje!</center>');

}

 

while ( $plik=readdir($katalog) ) {

   if(eregi('[.]jpg|[.]bmp|[.]gif|[.]png|[.]jpeg', $plik)) {

    echo '

<div class="col-md-3">

            <a><a href="submitnews.php?big_image='.dir.$plik.'"><img src="'.dir.$plik.'" alt="'.dir.$plik.'" class="img-responsive"/></a></a>

          </div>';

   }

}

}

 

if(isset($_REQUEST['category']) and $_REQUEST['category']=='krowa') {

define('dir', 'Generator/');

if ( !$katalog = opendir(dir) ) {

  die('<center>Podany katalog nie istnieje!</center>');

}

 

while ( $plik=readdir($katalog) ) {

   if(eregi('[.]jpg|[.]bmp|[.]gif|[.]png|[.]jpeg', $plik)) {

    echo '

<div class="col-md-3">

            <a><a href="submitnews.php?big_image='.dir.$plik.'"><img src="'.dir.$plik.'" alt="'.dir.$plik.'" class="img-responsive"/></a></a>

          </div>';

   }

}

}

}

 ?>

 

<?php if(isset($error)){

foreach($error as $errors){

echo '<li>'.$errors.'</li>';

}

}?>

 

 

 <?php

 

if(isset($_REQUEST['big_image']) and $_REQUEST['big_image'] !=''){

 

 

$image_title = strtolower($_REQUEST['big_image']);

$image_title = str_replace('_','',$image_title);

$image_title = str_replace('.jpg','',$image_title);

 

 

$fontname = 'font/Capriola-Regular.ttf';

// controls the spacing between text

$i=30;

//JPG image quality 0-100

$quality = 90;

$user = strtolower($_REQUEST['big_image']);

function create_image($user){

 

global $fontname;

global $quality;

global $file;

$file = "covers/".md5($user[0]['name'].$user[1]['name'].$user[2]['name']).".jpg";

// if the file already exists dont create it again just serve up the original

//if (!file_exists($file)) {

 

// define the base image that we lay our text on

$szablon =strtolower($_REQUEST['big_image']);

$im = imagecreatefromjpeg($szablon);

// setup the text colours

$color['grey'] = imagecolorallocate($im, 255,255,255);

$color['green'] = imagecolorallocate($im, 0, 0, 0);

// this defines the starting height for the text block

$y = imagesy($im) - $height - 625;

$y2 = imagesy($im) - $height - 135;

 

// loop through the array and write the text

foreach ($user as $value){

// center the text in our image - returns the x value

$x = center_text($value['name'], $value['font-size']);

$x2 = center_text($value['name2'], $value['font-size']);

$x3 = center_text($value['name3'], $value['font-size']);

$x4 = center_text($value['name4'], $value['font-size']);

imagettftext($im, $value['font-size'], 0, $x, $y+$i, $color[$value['color']], $fontname,$value['name']);

imagettftext($im, $value['font-size'], 0, $x2, $y+$i, $color[$value['color']], $fontname,$value['name2']);

imagettftext($im, $value['font-size'], 0, $x3, $y2+$i, $color[$value['color']], $fontname,$value['name3']);

imagettftext($im, $value['font-size'], 0, $x4, $y2+$i, $color[$value['color']], $fontname,$value['name4']);

// add 32px to the line height for the next text block

$i = $i+40;

}

// create the image

imagejpeg($im, $file, $quality);

//}

return $file;

}

 

function center_text($string, $font_size){

 

 

 

global $fontname;

 

$image_width = 900;

$dimensions = imagettfbbox($font_size, 0, $fontname, $string);

return ceil(($image_width - $dimensions[4]) / 2);

}

 

 

 

$user = array(

array(

'name'=> 'To jest pierwsza linijka twojego tekstu',

'font-size'=>'28',

'color'=>'grey'),

array(

'name2'=> 'To jest twoja druga linijak twojego tekst',

'font-size'=>'28',

'color'=>'grey'),

array(

'name3'=> 'To jest trzecia linijka tekstu',

'font-size'=>'28',

'color'=>'grey'

),

array(

'name4'=> '@lololo',

'font-size'=>'28',

'color'=>'grey'

)

);

if(isset($_POST['submit']) || isset($_POST['save_image'])) {

//$error = array();

//if(strlen($_POST['name'])==0){

// $error[] = 'Please enter a name';

//}

// if(strlen($_POST['job'])==0){

// $error[] = 'Please enter a job title';

// }

 

// if(strlen($_POST['email'])==0){

// $error[] = 'Please enter an email address';

// }

if(count($error)==0){

$user = array(

array(

'name'=> $_POST['name'],

'font-size'=>'28',

'color'=>'grey'),

array(

'name2'=> $_POST['job'],

'font-size'=>'28',

'color'=>'grey'),

array(

'name3'=> $_POST['email'],

'font-size'=>'28',

'color'=>'grey'

),

array(

'name4'=> $_POST['www'],

'font-size'=>'28',

'color'=>'grey'

)

);

 

 

 

 

}

 

 

 

 

 

}

 

 

 

 

 

 

 

 

 

}

$filename = create_image($user);

 

$filename

?>

 

<div class="col-md-9">

            <img src="<?=$filename;?>" alt="'.dir.$plik.'" class="img-responsive"/>

          </div>

 

 

<?php

if(isset($error)){

foreach($error as $errors){

echo '<li>'.$errors.'</li>';

}

}

?>

</ul>

 

<p>Wpisz swój tekst w wybranym polu.</p>

 

<div class="dynamic-form">

<form action="" method="post">

<label>Text 1:</label>

<input type="text" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}?>" name="name" maxlength="40" placeholder="Pierwsza linia"><br/>

<label>Text 2:</label>

<input type="text" value="<?php if(isset($_POST['job'])){echo $_POST['job'];}?>" name="job" maxlength="40" placeholder="Druga linia"><br/>

<label>Text 3:</label>

<input type="text" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" name="email" maxlength="40" placeholder="Trzecia linia"><br/>

<label>Text 4:</label>

<input type="text" value="<?php if(isset($_POST['www'])){echo $_POST['www'];}?>" name="www" maxlength="40" placeholder="Czwarta linia"><br/>

 

<input name="submit" type="submit" class="btn btn-primary btn-xs" value="Generuj" />

 

</div>

<?php

 

if(isset($_POST['submit'])) {

echo '

<div class="dynamic-form">

<form action="submit" method="post">

<label>Text 1:</label>

<input type="text" value="" name="submitnews_title" maxlength="40" placeholder="Tytul obrazka"><br/>

 

 

<input name="save_image" type="submit" class="btn btn-primary btn-xs" value="Zapisz" />

 

</div>';

 

}

?>

 

 

 

 

 

 

 

 

 

 

</body>

<?php

 

 if (isset($_POST['save_image'])) {

 

//global $filename;

$insertQry = array(

'submitnews_id'             => "",

'submitnews_name'           => "test",

'submitnews_email'          => "test",

'submitnews_user'           => USERID,

'submitnews_title'          => $_POST['submitnews_title'],

'submitnews_category'       => "memy",

'submitnews_item'           => "test",

'submitnews_datestamp'      => time(),

'submitnews_ip'             => "test",

'submitnews_auth'           => '0',

'submitnews_file'           => $filename,

'submitnews_keywords'       => "test",

                'submitnews_description'    => "test",

                'submitnews_summary'        => "test",

                'submitnews_media'          => "test"

);

 

if(!$sql->insert("submitnews", $insertQry))

{

$mes->addError(LAN_134);

return false;

}

 

 

$sql->insert("submitnews", "0, '$submitnews_user', '$submitnews_email', '$submitnews_title', '".intval($_POST['cat_id'])."', '$submitnews_item', '".time()."', '$ip', '0', '".implode(',',$submitnews_filearray)."' ");

 

$edata_sn = array("user" => $submitnews_user, "email" => $submitnews_email, "itemtitle" => $submitnews_title, "catid" => intval($_POST['cat_id']), "item" => $submitnews_item, "image" => $submitnews_file, "ip" => $ip);

 

e107::getEvent()->trigger("subnews", $edata_sn); // bc

e107::getEvent()->trigger("user_news_submit", $edata_sn);

 

 

}

?>

 

<?php

if(!vartrue($pref['subnews_htmlarea'])) // check after bbarea is called.

{

e107::wysiwyg(false);

}

 

require_once(FOOTERF);

 

 

 

?>

[/code]

 

I invite you to visit my website. Link in profile.
by (22 points) 4
Welcome to e107 Q&A, where you can ask questions and receive answers from other members of the e107 community.
859 questions
1,255 answers
2,177 comments
5,896 users