YaWK  24.1
Yet another WebKit
YAWK\template Class Reference

The template controller - get and set template settings. More...

Public Member Functions

 checkIfTemplateAlreadyExists (object $db, string $name)
 Check if a template with given name already exists, return true or false. More...
 
 deleteSettingsCSSFile ($db, $filename)
 
 downloadTemplate ($db, $templateFolder, $templateID, $user)
 Create a zip file from template and force direct download. More...
 
 drawFontFamilySelectField ($db, $lang, $selectName, $defaultValue)
 return a select option list with all fonts: More...
 
 emptyTmpFolder ()
 
 getCustomCSSFile (object $db, int $templateID)
 return the content of custom.css More...
 
 getCustomJSFile (object $db, int $templateID)
 return the content of custom.js More...
 
 getFontRow ($db, $lang, $fontRow, $previewClass, $templateSettings)
 return font edit row including preview More...
 
 getFormElements ($db, $settings, $type, $lang, $user)
 return html form field, depending on fieldClass More...
 
 loadActiveAssets ($db, $templateID, $host)
 Load Active Assets. More...
 
 loadActiveAssetsIntoArray ($db, $templateID)
 
 loadAllSettingsIntoArray (object $db, int $id)
 load template settings of ID and return as array More...
 
 loadProperties ($db, $id)
 load properties into template object More...
 
 loadPropertiesIntoArray (object $db, int $id)
 load template properties and return as array More...
 
 loadSettingsTypesIntoArray (object $db)
 load template_settings_types and return as array More...
 
 saveAs (object $db)
 save a template as new. It copies the tpl folder and all settings into a new one. More...
 
 saveProperties (object $db, int $id, array $data, array $oldTplSettings)
 save new template properties into database More...
 
 switchPositionIndicators (object $db, int $templateID, int $status)
 switch all positions indicators on or off More...
 
 uploadTemplate ($db, $postData, $postFiles, $lang)
 Upload a template (install / update) More...
 

Static Public Member Functions

static checkWrapper ($lang, $title, $subtitle)
 check if an admin LTE wrapper should be loaded around the backend content. This function must be called at the top of every backend page (admin/includes/xyz.php) More...
 
static drawAssetsSelectFields ($db, $type, $templateID, $lang)
 Draw asset select fields. More...
 
static drawAssetsTitles ($db, $templateID, $lang)
 Draw a list with all assets that are used in this template. More...
 
static getActiveBodyFont ($db, $user, $template)
 Get and return current active google font. More...
 
static getActivegfont ($db, $status, $property)
 return currently active google font More...
 
static getAllSettingsIntoArray ($db, $user)
 Returns an array with all template settings. More...
 
static getAssetsByType ($db, $type)
 Return a multidimensional array with all assets by requested type. More...
 
static getCurrentTemplateId (object $db)
 return ID of current (active) template More...
 
static getFontsFromFolder ($folder)
 get fonts from folder and return as array More...
 
static getGoogleFontsArray ($db)
 get all google fonts into an array and return array More...
 
static getMaxId ($db)
 return biggest ID from template database More...
 
static getPositionDivBox ($db, $lang, $position, $row, $bootstrapGrid, $positions, $indicators, $user, $template)
 return div box with postition settings More...
 
static getPositionIndicatorStatusArray ($db, $templateID)
 get the position indicators. This is used on index.php to mark indicated positions More...
 
static getPositionStatesArray ($db, $templateID)
 get the position states of all templates. This is used on index.php to render only templates that are enabled (1) More...
 
static getTemplateIds (object $db)
 return array with all template id's + names. More...
 
static getTemplateSettingsArray ($db, $templateID)
 get all template settings into an array and return it More...
 
static getValidTemplateID ($db, $user, $template)
 check the current template ID, considering if user is logged in, allowed to override template and so on More...
 
static includeHeader ($db)
 include header for html page *outdated? *moved to sys? More...
 
static loadGoogleFonts ($db)
 get settings for heading, menu and text font and output html to load font More...
 
static returnCurrentBootstrapVersion ($db, $templateID)
 Return which Bootstrap version is currently loaded in given template. More...
 
static setCssBodyFontFace ($cssTagName, $tplSettings)
 set css code for custom fonts (ttf / otf / woff) More...
 
static setCssBodyFontSettings ($cssTagName, $tplSettings)
 set body font settings css code More...
 
static setCssBodyLinkTags ($cssTagName, $tplSettings)
 set css code for body link styling More...
 
static setCssBodySmallFontSettings ($cssTagName, $tplSettings)
 set small font settings css code More...
 
static setCssFontSettings ($cssTagName, $tplSettings)
 set font settings css code More...
 
static setPosition ($db, $lang, $position, $currentpage, $user, $template)
 set template position and output the correct data depending on position More...
 

Public Attributes

 $active
 
 $author
 
 $authorUrl
 
 $bootstrapVersion
 
 $config
 
 $description
 
 $folder = '../system/templates/'
 
 $framework = 'bootstrap4'
 
 $id
 
 $license
 
 $modifyDate
 
 $name
 
 $newId
 
 $newTplName
 
 $positions
 
 $releaseDate
 
int $selectedTemplate
 
 $subAuthor = ''
 
 $subAuthorUrl = ''
 
 $subFolder
 
 $tmpFolder = '../system/templates/tmp/'
 
string $ttfPath = '../system/fonts/'
 
 $uploadFile = ''
 
 $version
 
 $weblink
 

Detailed Description

The template controller - get and set template settings.

Template controller - get and set template settings.

Templates itself are located in /system/templates/ - if you want to modify them, start there.

Class covers both, backend & frontend functionality. See Methods Summary for Details!

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com

Definition at line 15 of file template.php.

Member Function Documentation

◆ checkIfTemplateAlreadyExists()

YAWK\template::checkIfTemplateAlreadyExists ( object  $db,
string  $name 
)

Check if a template with given name already exists, return true or false.

Parameters
object$db
string$name
Returns
bool true|false

Definition at line 95 of file template.php.

95  : bool
96  {
97  // check if name is set, not empty and valid type
98  if (isset($name) && (!empty($name) && (is_string($name))))
99  {
100  // strip unwanted code
101  $name = strip_tags($name);
102 
103  // check if template is already in database
104  $result = $db->query("SELECT name FROM {templates} WHERE name = '".$name."'");
105  // if there are no rows
106  if($result->num_rows == 0)
107  { // template not found in database...
108  sys::setSyslog($db, 45, 0, "template $name not found in database", 0, 0, 0, 0);
109  return false;
110  }
111  else
112  { // template exists in database
113  sys::setSyslog($db, 45, 0, "template $name updated", 0, 0, 0, 0);
114  return true;
115  }
116  }
117  else
118  { // template param not set, empty or wrong type
119  sys::setSyslog($db, 45, 0, "template param $name not set or wrong type", 0, 0, 0, 0);
120  return false;
121  }
122  }
$result
Definition: email-send.php:137

References $db, YAWK\template\$name, and $result.

Referenced by YAWK\template\uploadTemplate().

◆ checkWrapper()

static YAWK\template::checkWrapper (   $lang,
  $title,
  $subtitle 
)
static

check if an admin LTE wrapper should be loaded around the backend content. This function must be called at the top of every backend page (admin/includes/xyz.php)

Parameters
array$langlanguage array
Returns
null

Definition at line 2819 of file template.php.

2820  {
2821  /* @var \YAWK\db $db */
2822  if (!isset($_GET['hideWrapper'])) {
2823  // draw the admin lte wrapper around content to include breadcrumbs and start content section
2824  // TEMPLATE WRAPPER - HEADER & breadcrumbs
2825  echo "
2826  <!-- Content Wrapper. Contains page content -->
2827  <div class=\"content-wrapper\" id=\"content-FX\">
2828  <!-- Content Header (Page header) -->
2829  <section class=\"content-header\">";
2830  /* draw Title on top */
2831  echo \YAWK\backend::getTitle($lang[$title], $lang[$subtitle]);
2832  echo "<ol class=\"breadcrumb\">
2833  <li><a href=\"index.php\" title=\"$lang[DASHBOARD]\"><i class=\"fa fa-dashboard\"></i> $lang[DASHBOARD]</a></li>
2834  <li><a href=\"index.php?page=users\" class=\"active\" title=\"$lang[USERS]\"> $lang[USERS]</a></li>
2835  </ol>
2836  </section>
2837  <!-- Main content -->
2838  <section class=\"content\">";
2839  /* page content start here */
2840  return null;
2841  } else // if wrapper is set
2842  { // check if hide status is 1
2843  if ($_GET['hideWrapper'] === 1) {
2844  // no wrapper needed - do nothing
2845  }
2846  }
2847  return null;
2848  }
print $lang['FILEMAN_UPLOAD']
print $_GET['id']
Definition: page-edit.php:357

References $_GET, and $lang.

◆ deleteSettingsCSSFile()

YAWK\template::deleteSettingsCSSFile (   $db,
  $filename 
)

delete template settings css file

Parameters
object$dbdatabase
string$filenamethe filename (including path) you wish to delete
Returns
bool

Definition at line 799 of file template.php.

800  { // if no filename is given
801  if (!isset($filename) || (empty($filename))) { // set default filename
802  $filename = self::getSettingsCSSFilename($db, '', '');
803  }
804  // we want the settings.css file to be overridden, so check if file exists and delete it if needed.
805  if (file_exists($filename)) { // if there is a file, delete it.
806  if (!unlink($filename)) { // delete failed, throw error
807  sys::setSyslog($db, 47, 1, "failed to delete file <b>$filename</b>", 0, 0, 0, 0);
808  alert::draw("danger", "Error!", "Failed to unlink $filename<br>Please delete this file and check file / folder / owner or group permissions!", "", 6200);
809  return false;
810  } else { // delete worked
811  return true;
812  }
813  } else { // file does not exist
814  sys::setSyslog($db, 47, 1, "failed to delete settings css file because it does not exist.", 0, 0, 0, 0);
815  return true;
816  }
817  }
$filename
Definition: actions.php:10
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30

References $db, $filename, and YAWK\alert\draw().

◆ downloadTemplate()

YAWK\template::downloadTemplate (   $db,
  $templateFolder,
  $templateID,
  $user 
)

Create a zip file from template and force direct download.

Parameters
object$dbdatabase
string$templateFolderthe template folder to zip + download
int$templateIDID of the template to process
object$useruser object
Returns
bool true|false

dump database settings into .json files, write template.ini and license file, zip the whole template folder and serve .zip for direct download

Definition at line 3714 of file template.php.

3715  {
3716  // check if template folder is set and valid
3717  if (!isset($templateFolder) || (empty($templateFolder) || (!is_string($templateFolder))))
3718  { // required param not set
3719  return false;
3720  }
3721  else
3722  { // set template folder property
3723  $this->subFolder = $templateFolder;
3724  $this->name = $templateFolder;
3725  }
3726  // check if template ID is set and valid
3727  if (!isset($templateID) || (empty($templateID) || (!is_numeric($templateID))))
3728  { // required param not set
3729  return false;
3730  }
3731  else
3732  { // set template ID property
3733  $this->id = $templateID;
3734  }
3735 
3736  if (!is_dir(dirname($this->tmpFolder)))
3737  {
3738  // check if tmp directory exists...
3739  if (!mkdir(dirname($this->tmpFolder)))
3740  { // failed to create tmp folder
3741  // todo: add syslog entry
3742  return false;
3743  }
3744  }
3745 
3746  // params are set, next step:
3747  // check if tmp directory exists and is empty
3748  if (is_writeable(dirname($this->tmpFolder)))
3749  {
3750  // check if subfolder exists...
3751  if (!is_dir(dirname($this->tmpFolder.$this->subFolder)))
3752  {
3753  // check if tmp directory exists...
3754  if (!mkdir(dirname($this->tmpFolder.$this->subFolder)))
3755  { // failed to create tmp sub folder
3756  sys::setSyslog($db, 47, 0, "failed to create ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3757  return false;
3758  }
3759  }
3760 
3761  // next step is to copy the whole template folder into tmp folder
3762  if (sys::xcopy($this->folder.$this->subFolder."/", $this->tmpFolder.$this->subFolder) === false)
3763  { // failed to copy template into tmp folder
3764  sys::setSyslog($db, 47, 0, "failed to copy template into tmp folder: ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3765  return false;
3766  }
3767 
3768  // check if template folder is writeable
3769  if (is_writeable($this->tmpFolder.$this->subFolder))
3770  {
3771  // GET TEMPLATE DEPENDING DATABASE DATA
3772  // get current template data
3773  $templateData = self::loadPropertiesIntoArray($db, $this->id);
3774  $templateAssets = self::loadActiveAssetsIntoArray($db, $this->id);
3776  $templateSettingsTypes = self::loadSettingsTypesIntoArray($db);
3777 
3778  // encode arrays to JSON format
3779  $templateData = json_encode($templateData);
3780  $templateAssets = json_encode($templateAssets);
3781  $templateSettings = json_encode($templateSettings);
3782  $templateSettingsTypes = json_encode($templateSettingsTypes);
3783 
3784  // write json arrays into files
3785  // write templates.json
3786  if (!file_put_contents($this->tmpFolder.$this->subFolder."/"."templates.json", $templateData))
3787  { // error writing templates.json
3788  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."templates.json", 0, 0, 0, 0);
3789  }
3790  // write assets.json
3791  if (!file_put_contents($this->tmpFolder.$this->name."/"."assets.json", $templateAssets))
3792  { // error writing assets.json
3793  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."assets.json", 0, 0, 0, 0);
3794  }
3795  // write template_settings.json
3796  if (!file_put_contents($this->tmpFolder.$this->name."/"."template_settings.json", $templateSettings))
3797  { // error writing template_settings.json
3798  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."template_settings.json", 0, 0, 0, 0);
3799  }
3800  // write template_settings_types.json
3801  if (!file_put_contents($this->tmpFolder.$this->name."/"."template_settings_types.json", $templateSettingsTypes))
3802  { // error writing template_settings_types.json
3803  sys::setSyslog($db, 48, 0, "failed to write ".$this->tmpFolder.$this->subFolder."template_settings_types.json", 0, 0, 0, 0);
3804  }
3805 
3806  // get template properties
3807  $this->loadProperties($db, $this->id);
3808  // get year only from release date
3809  $year = (substr($this->releaseDate, 0, 4));
3810  // include class
3811  require_once('../system/classes/licenses.php');
3812  // create license object
3813  $license = new \YAWK\licenses($this->license, $this->description, $year, $this->author, $this->tmpFolder.$this->name."/");
3814  // write license file
3815  if ($license->writeLicenseFile() === false)
3816  { // failed to write license file
3817  sys::setSyslog($db, 47, 0, "failed to write license file ($this->license license) to ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3818  }
3819  }
3820 
3821  // check if .json files have been written...
3822  if (is_file($this->tmpFolder.$this->subFolder.'/assets.json')
3823  && (is_file($this->tmpFolder.$this->subFolder.'/templates.json')
3824  && (is_file($this->tmpFolder.$this->subFolder.'/template_settings.json')
3825  && (is_file($this->tmpFolder.$this->subFolder.'/template_settings_types.json')))))
3826  {
3827  // ok, all files seem to be processed successfully
3828 
3829  // set source (path to the affected template)
3830  $source = $this->tmpFolder;
3831  // set target (path to the zip file that will be generated)
3832  $destination = $this->tmpFolder.$this->name.'.zip';
3833 
3834  // set data for ini file
3835  $iniData['DATE'] = sys::now();
3836  $iniData['NAME'] = $this->name;
3837  $iniData['FOLDER'] = $this->folder;
3838  $iniData['SUBFOLDER'] = $this->subFolder;
3839  $iniData['TARGET_PATH'] = $this->folder.$this->subFolder."/";
3840  $iniData['ID'] = $this->id;
3841  $iniData['FRAMEWORK'] = $this->framework;
3842  $iniData['DESCRIPTION'] = $this->description;
3843  $iniData['AUTHOR'] = $this->author;
3844  $iniData['AUTHOR_URL'] = $this->authorUrl;
3845  $iniData['SUB_AUTHOR'] = $this->subAuthor;
3846  $iniData['SUB_AUTHOR_URL'] = $this->subAuthorUrl;
3847  $iniData['WEBLINK'] = $this->weblink;
3848  $iniData['VERSION'] = $this->version;
3849  $iniData['LICENSE'] = $this->license;
3850 
3851  // write ini file
3852  if (sys::writeIniFile($iniData, $this->tmpFolder."template.ini") === false)
3853  {
3854  // failed to write ini file:
3855  sys::setSyslog($db, 47, 0, "failed to write ".$this->tmpFolder."template.ini ", 0, 0, 0, 0);
3856  return false;
3857  }
3858 
3859  // next step is to zip the whole template folder, containing all files
3860 
3861  // check if zip extension is loaded
3862  if (extension_loaded('zip'))
3863  {
3864  // make sure $source (template folder) exists
3865  if (!is_dir(dirname($source)))
3866  { // if folder does not exist
3867  return false;
3868  }
3869 
3870  // create new zip object
3871  $zip = new \ZipArchive();
3872 
3873  // make sure to create and open new zip archive
3874  if (!$zip->open($destination, \ZIPARCHIVE::CREATE))
3875  { // if not
3876  return false;
3877  }
3878 
3879  // set path slashes correctly
3880  $source = str_replace('\\', '/', realpath($source));
3881 
3882  // check if $source is a directoy
3883  if (is_dir($source) === true)
3884  {
3885  // run recursive iterators to store files in array
3886  $elements = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
3887 
3888  // walk through folder
3889  foreach ($elements as $file)
3890  {
3891  // set path slashes correctly
3892  $file = str_replace('\\', '/', $file);
3893 
3894  // ignore dot folders (. and ..)
3895  if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
3896  continue;
3897 
3898  // set file including path
3899  $file = realpath($file);
3900 
3901  // check if current element is a directory
3902  if (is_dir($file) === true)
3903  { // add folder to zip file
3904  $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
3905  }
3906  // check if current element is a file
3907  else if (is_file($file) === true)
3908  { // add file to zip archive
3909  $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
3910  }
3911  }
3912  }
3913  // if $source is a file
3914  else if (is_file($source) === true)
3915  { // add file to zip archive
3916  $zip->addFromString(basename($source), file_get_contents($source));
3917  }
3918 
3919  // all done, close (and write) zip archive
3920  $zip->close();
3921 
3922  if (is_file($destination))
3923  { // destination zip file is there.
3924 
3925  // delete all files from tmp folder - except the created zipfile
3926  if (\YAWK\filemanager::recursiveRemoveDirectory($this->tmpFolder.$this->subFolder) === false)
3927  { // warning: failed to delete tmp files
3928  sys::setSyslog($db, 47, 0, "failed to delete tmp folder ".$this->tmpFolder.$this->subFolder."", 0, 0, 0, 0);
3929  // return false;
3930  }
3931 
3932  // check if template ID is set
3933  if (isset($_GET['id']) && (!empty($_GET['id'])))
3934  { // set var for JS: downloadArchiveLink (selector)
3935  $downloadTemplateLink = "#downloadTemplateLink-".$_GET['id'];
3936  // set var for JS: link to the file to download
3937  $downloadFile = $destination;
3938  // dirty lil piece of JS code to emulate the user's click
3939  // (this avoids that he have to click twice - 1st click to generate + 2nd click to download)
3940  echo "
3941  <script type='text/javascript'>
3942  $(document).ready(function()
3943  { // change href attribute for this archive to direct donwload file
3944  var oldLink = $('$downloadTemplateLink').attr('href');
3945  $('$downloadTemplateLink').attr('href', '$downloadFile')
3946  // emulate a users click to force direct download
3947  $('$downloadTemplateLink')[0].click();
3948  // if this is not working, the user have to click on that link.
3949  });
3950  </script>";
3951  }
3952  // download file generated, direct download forced...
3953  return true;
3954  }
3955  else
3956  { // zip not generated
3957  sys::setSyslog($db, 52, 2, "failed to create template $this->name.zip package - zip file not there", 0, 0, 0, 0);
3958  return false;
3959  }
3960  }
3961  else
3962  { // zip extension is not loaded
3963  sys::setSyslog($db, 52, 2, "failed to create template .zip package: PHP zip extension not loaded.", 0, 0, 0, 0);
3964  return false;
3965  }
3966  }
3967  else
3968  { // .sql files not written
3969  sys::setSyslog($db, 52, 2, ".json files missing: $this->folder$this->subFolder/*.json not found", 0, 0, 0, 0);
3970  return false;
3971  }
3972  }
3973  else
3974  { // unable to include class
3975  sys::setSyslog($db, 52, 2, "create template .zip package failed: folder $this->folder is not writeable. Please check folder group permissions", 0, 0, 0, 0);
3976  return false;
3977  }
3978  }
$blog description
Definition: blog-setup.php:49
$templateID
Definition: blog.php:9
static recursiveRemoveDirectory($directory)
Delete a directory recursive.
static xcopy($source, $dest, $permissions=0755)
Copy a file, or recursively copy a folder and its contents.
Definition: sys.php:473
static writeIniFile($array, $file)
write ini file
Definition: sys.php:2085
static now()
returns the current datetime
Definition: sys.php:1492
loadAllSettingsIntoArray(object $db, int $id)
load template settings of ID and return as array
Definition: template.php:328
loadSettingsTypesIntoArray(object $db)
load template_settings_types and return as array
Definition: template.php:401
loadProperties($db, $id)
load properties into template object
Definition: template.php:264
loadPropertiesIntoArray(object $db, int $id)
load template properties and return as array
Definition: template.php:300
loadActiveAssetsIntoArray($db, $templateID)
Definition: template.php:3088
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
$template name
if(isset($_GET['positionIndicatorStatus'])) $templateSettings

References $_GET, YAWK\template\$author, YAWK\template\$authorUrl, $db, YAWK\template\$description, YAWK\template\$folder, YAWK\template\$framework, YAWK\template\$id, YAWK\template\$license, YAWK\template\$name, YAWK\template\$subAuthor, YAWK\template\$subAuthorUrl, YAWK\template\$subFolder, $templateID, $templateSettings, YAWK\template\$tmpFolder, YAWK\template\$version, YAWK\template\$weblink, description, YAWK\template\loadActiveAssetsIntoArray(), YAWK\template\loadAllSettingsIntoArray(), YAWK\template\loadProperties(), YAWK\template\loadPropertiesIntoArray(), YAWK\template\loadSettingsTypesIntoArray(), name, YAWK\sys\now(), YAWK\filemanager\recursiveRemoveDirectory(), YAWK\sys\writeIniFile(), and YAWK\sys\xcopy().

◆ drawAssetsSelectFields()

static YAWK\template::drawAssetsSelectFields (   $db,
  $type,
  $templateID,
  $lang 
)
static

Draw asset select fields.

This method is used in the backend to generate asset select fields in template-assets view

Parameters
object$dbdatabase object
int$type0 = all, 1 = required, 2 = optional, 3 = additional
int$templateIDid of the affected template
array$langlanguage array
Returns
null

Definition at line 2947 of file template.php.

2948  {
2949  /* @var \YAWK\db $db */
2950 
2951  // check type and load assets data
2952  // if type is not set
2953  if (!isset($type) || (empty($type))) { // set to zero -this will get all assets in array
2954  $type = 0;
2955  }
2956 
2957  // check if templateID is set
2958  if (!isset($templateID) || (empty($templateID))) {
2959  // get current template ID
2960  $templateID = settings::getSetting($db, "selectedTemplate");
2961  }
2962 
2963  // get assets, depending on type from database
2964  $assets = template::getAssetsByType($db, $type);
2965 
2966  foreach ($assets as $asset => $property) {
2967  $resInternal = $db->query("SELECT link from {assets}
2968  WHERE templateID = '" . $templateID . "'
2969  AND link = '" . $property['internal'] . "'");
2970 
2971  $resUrl1 = $db->query("SELECT link from {assets}
2972  WHERE templateID = '" . $templateID . "'
2973  AND link = '" . $property['url1'] . "'");
2974 
2975  $resUrl2 = $db->query("SELECT link from {assets}
2976  WHERE templateID = '" . $templateID . "'
2977  AND link = '" . $property['url2'] . "'");
2978 
2979  $resUrl3 = $db->query("SELECT link from {assets}
2980  WHERE templateID = '" . $templateID . "'
2981  AND link = '" . $property['url3'] . "'");
2982 
2983  $row = mysqli_fetch_assoc($resInternal);
2984  if (isset($property['internal']) && isset($row['link']) && $row['link'] === $property['internal']) {
2985  $selectedInternal = " selected";
2986  } else {
2987  $selectedInternal = '';
2988  }
2989 
2990  $row = mysqli_fetch_assoc($resUrl1);
2991  if (isset($property['url1']) && isset($row['link']) && $row['link'] === $property['url1']) {
2992  $selectedUrl1 = " selected";
2993  } else {
2994  $selectedUrl1 = '';
2995  }
2996 
2997  $row = mysqli_fetch_assoc($resUrl2);
2998  // echo "<br>VAR : "; // print_r($property);
2999  if (isset($property['url2']) && isset($row['link']) && $row['link'] === $property['url2']) {
3000  $selectedUrl2 = " selected";
3001  } else {
3002  $selectedUrl2 = '';
3003  }
3004 
3005  $row = mysqli_fetch_assoc($resUrl3);
3006  if (isset($property['url3']) && isset($row['link']) && $row['link'] === $property['url3']) {
3007  $selectedUrl3 = " selected";
3008  } else {
3009  $selectedUrl3 = '';
3010  }
3011 
3012  echo "<label for=\"include-$property[property]\">$property[asset]</label>
3013  <input name=\"title-$property[property]\" value=\"$property[asset]\" type=\"hidden\">
3014  <input name=\"sortation-$property[property]\" value=\"$property[sortation]\" type=\"hidden\">
3015 
3016  <select id=\"include-$property[property]\" name=\"include-$property[property]\" class=\"form-control\">
3017  <option name=\"null\" value=\"\">inactive</option>
3018  <optgroup label=\"internal\">internal</optgroup>
3019  <option name=\"value\"$selectedInternal>$property[internal]</option>
3020  <optgroup label=\"external\">external</optgroup>
3021  <option name=\"value\"$selectedUrl1>$property[url1]</option>";
3022  if (!empty($property['url2'])) { // display 2nd external asset link
3023  echo "
3024  <option name=\"value\"$selectedUrl2>$property[url2]</option>";
3025  }
3026  if (!empty($property['url3'])) {
3027  echo "
3028  <option name=\"value\"$selectedUrl3>$property[url3]</option>";
3029  }
3030  echo "
3031  </select>";
3032  }
3033  return null;
3034  }
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static getAssetsByType($db, $type)
Return a multidimensional array with all assets by requested type.
Definition: template.php:2857
$type

References $db, $templateID, $type, YAWK\template\getAssetsByType(), and YAWK\settings\getSetting().

◆ drawAssetsTitles()

static YAWK\template::drawAssetsTitles (   $db,
  $templateID,
  $lang 
)
static

Draw a list with all assets that are used in this template.

Parameters
object$dbdatabase object
int$templateIDID of the affectd template
array$langlanguage array
Returns
null

Definition at line 2909 of file template.php.

2910  {
2911  /* @var \YAWK\db $db */
2912  // if no template ID is set
2913  if (!isset($templateID) || (empty($templateID))) { // get current ID from database
2914  $templateID = settings::getSetting($db, "selectedTemplate");
2915  }
2916  if ($res = $db->query("SELECT asset, link FROM {assets}
2917  WHERE templateID = '" . $templateID . "'
2918  ORDER BY asset")
2919  ) {
2920  while ($row = mysqli_fetch_assoc($res)) {
2921  // check, if link is external
2922  if (strpos($row['link'], 'http://') !== false || (strpos($row['link'], 'https://') !== false)) {
2923  $icon = "fa fa-cloud";
2924  $title = "$lang[EXTERNAL]";
2925  } else {
2926  $icon = "fa fa-server";
2927  $title = "$lang[INTERNAL]";
2928  }
2929  $qString = rawurlencode($row['asset']);
2930 
2931  echo "<small><a href=\"index.php?page=template-assets\" data-toggle=\"tooltip\" title=\"$title\"><i class=\"$icon text-info\"></i></a></small> &nbsp;$row[asset] &nbsp;<small><a href=\"https://www.google.at/search?q=$qString\" target=\"_blank\" data-toggle=\"tooltip\" title=\"$row[asset] $lang[GOOGLE_THIS]\"><i class=\"fa fa-question-circle-o\"></i></a></small><br>";
2932  }
2933  }
2934  return null;
2935  }

References $db, $res, $templateID, and YAWK\settings\getSetting().

◆ drawFontFamilySelectField()

YAWK\template::drawFontFamilySelectField (   $db,
  $lang,
  $selectName,
  $defaultValue 
)

return a select option list with all fonts:

  • system default fonts
  • own true type fonts from system/fonts
  • google fonts from database: gfonts
Parameters
object$dbdatabase
string$selectNameselectName
array$langlanguage array

Definition at line 1841 of file template.php.

1842  {
1843  if (isset($defaultValue) && (!empty($defaultValue))) {
1844  $defaultValueOption = "<option value=\"$defaultValue\" selected aria-selected=\"true\">$defaultValue</option>";
1845  } else {
1846  $defaultValueOption = '';
1847  }
1848  $selectField = ''; // init var to hold select field html code
1849  $selectField =
1850  "
1851  <select style=\"margin-bottom:10px;\" id=\"$selectName\" name=\"$selectName\" class=\"form-control\">
1852  $defaultValueOption;
1853  <optgroup label=\"System Sans-Serif Fonts\"></optgroup>
1854  <option value=\"Arial, Helvetica, sans-serif\">&nbsp;&nbsp;Arial, Helvetica, sans-serif</option>
1855  <option value=\"Arial Black\">&nbsp;&nbsp;Arial Black</option>
1856  <option value=\"Comic Sans MS, cursive, sans-serif\">&nbsp;&nbsp;Comic Sans</option>
1857  <option value=\"Impact, Charcoal, sans-serif\">&nbsp;&nbsp;Impact, Charcoal, sans-serif</option>
1858  <option value=\"Lucida Sans Unicode, Lucida Grande, sans-serif\">&nbsp;&nbsp;Lucida Sans Unicode, Lucida Grande, sans-serif</option>
1859  <option value=\"Tahoma, Geneva, sans-serif\">&nbsp;&nbsp;Tahoma, Geneva, sans-serif</option>
1860  <option value=\"Trebuchet MS, Helvetica, sans-serif\">&nbsp;&nbsp;Trebuchet MS, Helvetica, sans-serif</option>
1861  <option value=\"Verdana, Geneava, sans-serif\">&nbsp;&nbsp;Verdana, Geneava, sans-serif</option>
1862  <optgroup label=\"System Serif Fonts\"></optgroup>
1863  <option value=\"Georgia, serif\">&nbsp;&nbsp;Georgia, serif</option>
1864  <option value=\"Palatino Linotype, Book Antiqua, Palatino, serif\">&nbsp;&nbsp;Palatino Linotype, Book Antiqua, Palatino, serif</option>
1865  <option value=\"Times New Roman, Times, serif\">&nbsp;&nbsp;Times New Roman, Times, serif</option>
1866  <optgroup label=\"System Monospace Fonts\"></optgroup>
1867  <option value=\"Courier New, Courier, monospace\">&nbsp;&nbsp;Courier New, Courier, monospace</option>
1868  <option value=\"Lucida Console, Monaco, monospace\">&nbsp;&nbsp;Lucida Console, Monaco, monospace</option>";
1869 
1870  // directory iterator walks trough system/fonts
1871  // and build up 3 arrays: ttf fonts, otf fonts and woff fonts
1872  // afterwards they get processed and drawn
1873  if (is_dir($this->ttfPath)) // only if directory exists, otherwise skip
1874  {
1875  $dir = new \DirectoryIterator($this->ttfPath);
1876  $ttfFonts = array(); // all .ttf files
1877  $otfFonts = array(); // all .otf files
1878  $woffFonts = array(); // all .woff files
1879 
1880  foreach ($dir as $item) {
1881  if (!$item->isDot()
1882  && (!$item->isDir())
1883  ) {
1884  // workaround: todo what about filenames with spaces?
1885  // check if it is a true type file
1886  if (strtolower(substr($item, -3)) === "ttf") {
1887  // workaround: if dots are in there, the form does not work.
1888  // so lets change the dots to '-' and let option pass trough
1889  $item = str_replace(".", "-", $item);
1890  // add ttf font to array
1891  $ttfFonts[] = "<option value=\"$item\">&nbsp;&nbsp;$item</option>";
1892  }
1893  // check if it is a otf file
1894  if (strtolower(substr($item, -3)) === "otf") {
1895  $item = str_replace(".", "-", $item);
1896  // add option to select field
1897  $otfFonts[] = "<option value=\"$item\">&nbsp;&nbsp;$item</option>";
1898  }
1899  // check if it is a woff file
1900  if (strtolower(substr($item, -4)) === "woff") {
1901  // workaround: change dots to '-' to let option pass trough
1902  $item = str_replace(".", "-", $item);
1903  // add option to select field
1904  $woffFonts[] = "<option value=\"$item\">&nbsp;&nbsp;$item</option>";
1905  }
1906  }
1907  } // end if is_dir
1908 
1909  // add .ttf fonts to select option
1910  $selectField .= "<optgroup label=\"True Type Fonts (system/fonts/*.ttf)\"></optgroup>";
1911  foreach ($ttfFonts as $ttfFont) { // add ttf option to select field
1912  $selectField .= $ttfFont;
1913  }
1914  // add .otf fonts to select option
1915  $selectField .= "<optgroup label=\"Open Type Fonts (system/fonts/*.otf)\"></optgroup>";
1916  foreach ($otfFonts as $otfFont) { // add ttf option to select field
1917  $selectField .= $otfFont;
1918  }
1919  // add .woff fonts to select option
1920  $selectField .= "<optgroup label=\"Web Open Font Format (system/fonts/*.woff)\"></optgroup>";
1921  foreach ($woffFonts as $woffFont) { // add ttf option to select field
1922  $selectField .= $woffFont;
1923  }
1924  }
1925 
1926 
1927  // fill google fonts array
1929  // add google fonts to select option
1930  $selectField .= "<optgroup label=\"Google Fonts\"></optgroup>";
1931  foreach ($googleFonts as $gFont) {
1932  // add google font option to select field
1933  // add option to select field
1934  $selectField .= "<option value=\"$gFont-gfont\">&nbsp;&nbsp;$gFont (Google Font)</option>";
1935  }
1936  // close select option
1937  $selectField .= "</select>";
1938 
1939  // finally: output the html code of this select field
1940  return $selectField;
1941  }
if(!isset($language)||(!isset($lang))) $item
static getGoogleFontsArray($db)
get all google fonts into an array and return array
Definition: template.php:1949
if(isset($_GET) &&(!empty($_GET))) $googleFonts

References $googleFonts, $item, and YAWK\template\getGoogleFontsArray().

Referenced by YAWK\template\getFontRow().

◆ emptyTmpFolder()

YAWK\template::emptyTmpFolder ( )

Definition at line 3245 of file template.php.

3246  {
3247  foreach(glob($this->tmpFolder."*") as $file)
3248  {
3249  if(!is_dir($file))
3250  {
3251  unlink($file);
3252  }
3253  else
3254  {
3256  }
3257  }
3258  }

References YAWK\filemanager\recursiveRemoveDirectory().

Referenced by YAWK\template\uploadTemplate().

◆ getActiveBodyFont()

static YAWK\template::getActiveBodyFont (   $db,
  $user,
  $template 
)
static

Get and return current active google font.

Parameters
$db
Returns
string

Definition at line 2481 of file template.php.

2482  {
2483  /* @var \YAWK\db $db */
2484  $bodyFont = template::getTemplateSetting($db, "value", "globaltext-fontfamily", $user, $template);
2485  $bodyFontFamily = "font-family: $bodyFont";
2486  return $bodyFontFamily;
2487  }

References $db.

◆ getActivegfont()

static YAWK\template::getActivegfont (   $db,
  $status,
  $property 
)
static

return currently active google font

Parameters
object$dbdatabase
string$statusthe url or font name
string$propertyaffected settings property
Returns
null|string

Definition at line 2496 of file template.php.

2497  {
2498  /* @var \YAWK\db $db */
2499  if ($res = $db->query("SELECT id, font, setting
2500  FROM {gfonts}
2501  WHERE activated = 1
2502  AND id = (SELECT ts.value
2503  FROM {template_settings} ts
2504  JOIN {settings} s on s.value = ts.templateID
2505  WHERE ts.activated = 1 && s.property = 'selectedTemplate' && ts.property = '$property')")
2506  ) {
2507  while ($row = mysqli_fetch_array($res)) {
2508  // if no google font is selected
2509  if ($row[1] === "0") {
2510  return "font-family: Arial";
2511  }
2512  // css include output for index.php
2513  if ($status == "url") {//
2514  if (isset($row[2]) || (!empty($row[2]))) {
2515  return "
2516 <link rel=\"stylesheet\" href=\"http://fonts.googleapis.com/css?family=$row[1]:$row[2]\" type=\"text/css\" media=\"all\">";
2517  } else {
2518  return "
2519 <link rel=\"stylesheet\" href=\"http://fonts.googleapis.com/css?family=$row[1]\" type=\"text/css\" media=\"all\">";
2520  }
2521  } else {
2522  return "font-family: $row[1];";
2523  }
2524  }
2525  } else { // could not get active google font
2526  return "could not get active google font";
2527  }
2528  return null;
2529  }

References $db, and $res.

◆ getAllSettingsIntoArray()

static YAWK\template::getAllSettingsIntoArray (   $db,
  $user 
)
static

Returns an array with all template settings.

Parameters
object$dbDatabase Object
object$userUser Object
Returns
array|bool

Definition at line 1061 of file template.php.

1062  {
1063  if (!isset($user) || empty($user))
1064  {
1065  $user = new user($db);
1066  }
1067  // get template settings
1068  if (isset($user))
1069  { // get template settings for this user
1070  if ($user->overrideTemplate == 1) {
1071  $sql = "SELECT ts.property, ts.value, ts.longValue, ts.valueDefault, ts.type, ts.label, ts.sort, ts.fieldClass, ts.fieldType, ts.placeholder, ts.description, ts.options, ts.activated, ts.icon, ts.heading, ts.subtext
1072  FROM {template_settings} ts
1073  JOIN {users} u on u.templateID = ts.templateID
1074  WHERE ts.activated = 1 && u.id = $user->id
1075  ORDER BY ts.sort";
1076  } else {
1077  $sql = "SELECT ts.property, ts.value, ts.longValue, ts.valueDefault, ts.type, ts.label, ts.sort, ts.fieldClass, ts.fieldType, ts.placeholder, ts.description, ts.options, ts.activated, ts.icon, ts.heading, ts.subtext
1078  FROM {template_settings} ts
1079  JOIN {settings} s on s.value = ts.templateID
1080  WHERE ts.activated = 1 && s.property = 'selectedTemplate'
1081  ORDER BY ts.sort";
1082  }
1083  } else {
1084  sys::setSyslog($db, 47, 1, "failed to get template settings array - user is not set or empty", 0, 0, 0, 0);
1085  return false;
1086  }
1087 
1088  /* @param $db \YAWK\db */
1089  // if ($res= $db->query("SELECT * FROM {template_settings} ORDER by property"))
1090  if ($res = $db->query($sql)) {
1091  $settingsArray = array();
1092  while ($row = $res->fetch_assoc()) { // fill array
1093  $settingsArray[$row['property']] = $row;
1094  }
1095  } else { // q failed, throw error
1096  sys::setSyslog($db, 5, 1, "failed to query template settings", 0, 0, 0, 0);
1097  // \YAWK\alert::draw("warning", "Warning!", "Fetch database error: getSettingsArray failed.","","4800");
1098  return false;
1099  }
1100 
1101  // check if array has been generated
1102  if (is_array($settingsArray) && (!empty($settingsArray))) { // all good -
1103  return $settingsArray;
1104  } else { // error generating settings array -
1105  return false;
1106  }
1107  }
$sql
Definition: message-new.php:32

References $db, $res, and $sql.

◆ getAssetsByType()

static YAWK\template::getAssetsByType (   $db,
  $type 
)
static

Return a multidimensional array with all assets by requested type.

If no type is set, or type == 0, all assets will be returned.

Parameters
object$dbdatabase object
int$type0 = all, 1 = required, 2 = optional, 3 = additional
Returns
array

Definition at line 2857 of file template.php.

2858  {
2859  /* @var \YAWK\db $db */
2860  // check if type is set
2861  if (!isset($type) || (empty($type))) { // if its not set, get all assets from db, no matter which type they are
2862  $typeSQLCode = ''; // terminate db query
2863  } else { // check if type is a number
2864  if (is_numeric($type) || (is_int($type))) { // and build additional sql string
2865  $typeSQLCode = "AND type = '$type'";
2866 
2867  // if type is zero, fetch all data
2868  if ($type === 0) { // terminate db query
2869  $typeSQLCode = '';
2870  }
2871  } else { // type is not a number, get all data
2872  $typeSQLCode = ''; // terminate db query
2873  }
2874  }
2875 
2876  // init a new empty array
2877  $assets = array();
2878  // get assets from database
2879  $res = $db->query("SELECT *
2880  FROM {assets_types}
2881  WHERE published = '1'
2882  $typeSQLCode ORDER by sortation, asset");
2883  // fetch data in loop
2884  while ($row = mysqli_fetch_assoc($res)) { // build assets array
2885  $prop = $row['asset'];
2886  $assets[$prop]["asset"] = $prop;
2887  $assets[$prop]["property"] = $row['property'];
2888  $assets[$prop]["internal"] = $row['internal'];
2889  $assets[$prop]["url1"] = $row['url1'];
2890  $assets[$prop]["url2"] = $row['url2'];
2891  $assets[$prop]["url3"] = $row['url3'];
2892  $assets[$prop]["sortation"] = $row['sortation'];
2893  }
2894  // check if assets is an array
2895  if (is_array($assets)) { // all good
2896  return $assets;
2897  } else { // error: exit with msg
2898  die ('unable to return assets array - maybe database is corrupt or missing.');
2899  }
2900  }
die
Definition: block-user.php:27

References $db, $res, $type, and die.

Referenced by YAWK\template\drawAssetsSelectFields().

◆ getCurrentTemplateId()

static YAWK\template::getCurrentTemplateId ( object  $db)
static

return ID of current (active) template

Parameters
object$dbdatabase object
Returns
int the ID of the currently selected template

Definition at line 73 of file template.php.

73  : int
74  { // return value of property selectedTemplate from settings db
75  // outdated: return \YAWK\settings::getSetting($db, "selectedTemplate");
76 
77  if (!isset($user)){
78  $user = new user($db);
79  }
80  if (!isset($template)){
81  $template = new template();
82  }
83 
84  // since user can override his template, there are more specific checks needed,
85  // which template is currently active and which ID we will return. To do that:
86  return template::getValidTemplateID($db, $user, $template);
87  }
static getValidTemplateID($db, $user, $template)
check the current template ID, considering if user is logged in, allowed to override template and so ...
Definition: template.php:2603

References $db, and YAWK\template\getValidTemplateID().

Referenced by YAWK\sys\checkIfAssetsAreLoaded(), YAWK\menu\display(), YAWK\WIDGETS\BLOG\WIDGET\blogWidget\drawBlogWidget(), and YAWK\template\switchPositionIndicators().

◆ getCustomCSSFile()

YAWK\template::getCustomCSSFile ( object  $db,
int  $templateID 
)

return the content of custom.css

Parameters
object$dbdatabase
int$templateIDaffected template ID
Returns
string the content of custom.css

Definition at line 698 of file template.php.

698  : string
699  { // get the content from custom.css
700  $filename = self::getCustomCSSFilename($db, "backend", $templateID);
701  return file_get_contents($filename);
702  }

References $db, $filename, and $templateID.

◆ getCustomJSFile()

YAWK\template::getCustomJSFile ( object  $db,
int  $templateID 
)

return the content of custom.js

Parameters
object$dbdatabase
int$templateIDaffected template ID
Returns
string the content of custom.css

Definition at line 710 of file template.php.

710  : string
711  { // get the content from custom.css
712  $filename = self::getCustomJSFilename($db, "backend", $templateID);
713  return file_get_contents($filename);
714  }

References $db, $filename, and $templateID.

◆ getFontRow()

YAWK\template::getFontRow (   $db,
  $lang,
  $fontRow,
  $previewClass,
  $templateSettings 
)

return font edit row including preview

Parameters
object$dbdatabase
array$langlanguage array
string$fontRowthe prefix of the font group to edit (eg. h1, h2, h3, globaltext...)
string$previewClasscss class you want to use on the preview
array$templateSettingsall template settings as an array

Definition at line 1460 of file template.php.

1461  {
1462  // prepare vars
1463  $fontRowSize = "$fontRow-size";
1464  $fontRowColor = "$fontRow-fontcolor";
1465  $fontRowFontfamily = "$fontRow-fontfamily";
1466  $fontRowFontShadowSize = "$fontRow-fontshadowsize";
1467  $fontRowFontShadowColor = "$fontRow-fontshadowcolor";
1468  $fontRowFontWeight = "$fontRow-fontweight";
1469  $fontRowFontStyle = "$fontRow-fontstyle";
1470  $fontRowTextdecoration = "$fontRow-textdecoration";
1471  $fontRowALinkColor = "$fontRow-alink";
1472  $fontRowAHoverColor = "$fontRow-ahover";
1473  $fontRowAVisitedColor = "$fontRow-avisited";
1474  $fontRowLinkFontWeight = "$fontRow-linkfontweight";
1475  $fontRowLinkFontStyle = "$fontRow-linkfontstyle";
1476  $fontRowLinkTextDecoration = "$fontRow-linktextdecoration";
1477  $fontRowHoverTextDecoration = "$fontRow-hovertextdecoration";
1478  $fontRowSmallColor = "$fontRow-smallcolor";
1479  $fontRowSmallShadowSize = "$fontRow-smallshadowsize";
1480  $fontRowSmallShadowColor = "$fontRow-smallshadowcolor";
1481 
1482  if ($fontRow === "globaltext" xor ($fontRow === "menufont")) {
1483  $col = 4;
1484  } else {
1485  $col = 2;
1486  }
1487 
1488  $FONT_ROW = strtoupper($fontRow);
1489  $labelFontSize = "TPL_" . $FONT_ROW . "_SIZE";
1490  $labelFontColor = "TPL_" . $FONT_ROW . "_COLOR";
1491  $labelSmallColor = "TPL_" . $FONT_ROW . "_SMALLCOLOR";
1492 
1493 
1494  // check if description is set
1495  // the description will be shown right beside the label as small info icon
1496  if (isset($templateSettings[$fontRowFontfamily]['description']) && (!empty($templateSettings[$fontRowFontfamily]['description']))) { // L11n
1497  $fontRowFamilyDesc = $lang[$templateSettings[$fontRowFontfamily]['description']];
1498  $fontRowFamilyInfoBtn = "&nbsp;<small><i class=\"fa fa-question-circle-o text-info\" data-placement=\"auto right\" data-toggle=\"tooltip\" title=\"$fontRowFamilyDesc\"></i></small>";
1499  } else {
1500  $fontRowFamilyInfoBtn = '';
1501  }
1502  // check if font family default value is set
1503  if (isset($templateSettings[$fontRowFontfamily]['valueDefault']) && (!empty($templateSettings[$fontRowFontfamily]['valueDefault']))) { // default values:
1504  $fontRowFamilyDefault = "<i class=\"h6 small\">default: " . $templateSettings[$fontRowFontfamily]['valueDefault'] . "</i>";
1505  } else {
1506  $fontRowFamilyDefault = '';
1507  }
1508 
1509  // check if font size is set
1510  if (isset($templateSettings[$fontRowSize]['valueDefault']) && (!empty($templateSettings[$fontRowSize]['valueDefault']))) { // default values:
1511  $fontRowSizeDefault = "<i class=\"h6 small\">(" . $templateSettings[$fontRowSize]['valueDefault'] . ")</i>";
1512  } else {
1513  $fontRowSizeDefault = '';
1514  }
1515 
1516  $html = "
1517  <div class=\"col-md-$col\">
1518  <div class=\"$previewClass\" id=\"$fontRow-preview\" style=\"height: auto; overflow:hidden; font-size: " . $templateSettings[$fontRowSize]['value'] . "; color: #" . $templateSettings[$fontRowColor]['value'] . ";\">$fontRow Heading</div>
1519 
1520  <label for=\"$fontRowFontfamily\">$FONT_ROW $lang[TPL_FONTFAMILY] $fontRowFamilyInfoBtn</label>";
1521  $html .= $this->drawFontFamilySelectField($db, $lang, "$fontRowFontfamily", $templateSettings[$fontRowFontfamily]['value']);
1522  $html .= "
1523 
1524  <label for=\"$fontRowSize\">$lang[$labelFontSize] $fontRowSizeDefault</label>
1525  <input style=\"margin-bottom:10px;\" id=\"$fontRowSize\" name=\"$fontRowSize\" value=\"" . $templateSettings[$fontRowSize]['value'] . "\" class=\"form-control\">
1526 
1527  <label for=\"$fontRowColor\">$lang[$labelFontColor]</label>
1528  <input style=\"margin-bottom:10px;\" id=\"$fontRowColor\" name=\"$fontRowColor\" class=\"form-control color\" value=\"" . $templateSettings[$fontRowColor]['value'] . "\">
1529 
1530  <label for=\"$fontRowFontShadowSize\">$lang[TPL_FONTSHADOWSIZE]</label>
1531  <input style=\"margin-bottom:10px;\" id=\"$fontRowFontShadowSize\" name=\"$fontRowFontShadowSize\" class=\"form-control\" value=\"" . $templateSettings[$fontRowFontShadowSize]['value'] . "\" placeholder=\"2px 2px\">
1532 
1533  <label for=\"$fontRowFontShadowColor\">$lang[TPL_FONTSHADOWCOLOR]</label>
1534  <input style=\"margin-bottom:10px;\" id=\"$fontRowFontShadowColor\" name=\"$fontRowFontShadowColor\" value=\"" . $templateSettings[$fontRowFontShadowColor]['value'] . "\" class=\"form-control color\">
1535 
1536  <label for=\"$fontRowFontWeight\">$lang[TPL_FONTWEIGHT]</label>
1537  <select style=\"margin-bottom:10px;\" id=\"$fontRowFontWeight\" name=\"$fontRowFontWeight\" class=\"form-control\">";
1538 
1539  $fontweightStyles = array("normal", "bold", "bolder", "lighter", "100", "200", "300", "400 [normal]", "500", "600", "700 [bold]", "800", "900", "initial", "inherit");
1540  foreach ($fontweightStyles as $weight) {
1541  $currentFontWeight = "$fontRow-fontweight";
1542  if ($weight === $templateSettings[$currentFontWeight]['value']) {
1543  $selected = "selected aria-selected=\"true\"";
1544  } else {
1545  $selected = '';
1546  }
1547  $html .= "<option value=\"$weight\" $selected>$weight</option>";
1548  }
1549  $html .= "</select>
1550 
1551  <label for=\"$fontRowFontStyle\">$lang[TPL_FONTSTYLE]</label>
1552  <select style=\"margin-bottom:10px;\" id=\"$fontRowFontStyle\" name=\"$fontRowFontStyle\" class=\"form-control\">";
1553 
1554  $fontStyles = array("normal", "italic", "oblique", "initial", "inherit");
1555  foreach ($fontStyles as $style) {
1556  $currentFontStyle = "$fontRow-fontstyle";
1557  if ($style === $templateSettings[$currentFontStyle]['value']) {
1558  $selected = "selected aria-selected=\"true\"";
1559  } else {
1560  $selected = '';
1561  }
1562  $html .= "<option value=\"$style\" $selected>$style</option>";
1563  }
1564 
1565  $html .= "</select>
1566 
1567  <label for=\"$fontRowTextdecoration\">$lang[TPL_TEXTDECORATION]</label>
1568  <select style=\"margin-bottom:10px;\" id=\"$fontRowTextdecoration\" name=\"$fontRowTextdecoration\" class=\"form-control\">";
1569 
1570  $textdecorationTypes = array("none", "underline", "overline", "line-through", "intial", "inherit");
1571  foreach ($textdecorationTypes as $decoration) {
1572  $currentFontDecoration = "$fontRow-textdecoration";
1573  if ($decoration === $templateSettings[$currentFontDecoration]['value']) {
1574  $selected = "selected aria-selected=\"true\"";
1575  } else {
1576  $selected = '';
1577  }
1578  $html .= "<option value=\"$decoration\" $selected>$decoration</option>";
1579  }
1580  $html .= "</select>";
1581 
1582  // LINK SETTINGS START HERE
1583  $html .= "
1584 
1585  <label for=\"$fontRowLinkTextDecoration\">$lang[TPL_LINK_TEXTDECORATION]</label>
1586  <select style=\"margin-bottom:10px;\" id=\"$fontRowLinkTextDecoration\" name=\"$fontRowLinkTextDecoration\" class=\"form-control\">";
1587 
1588  foreach ($textdecorationTypes as $decoration) {
1589  $currentLinkTextDecoration = "$fontRow-linktextdecoration";
1590  if ($decoration === $templateSettings[$currentLinkTextDecoration]['value']) {
1591  $selected = "selected aria-selected=\"true\"";
1592  } else {
1593  $selected = '';
1594  }
1595  $html .= "<option value=\"$decoration\" $selected>$decoration</option>";
1596  }
1597  $html .= "</select>
1598  <label for=\"$fontRow-alink\">$lang[TPL_LINK_COLOR]</label>
1599  <input style=\"margin-bottom:10px;\" id=\"$fontRow-alink\" name=\"$fontRow-alink\" value=\"" . $templateSettings[$fontRowALinkColor]['value'] . "\" class=\"form-control color\">
1600 
1601  <label for=\"$fontRow-avisited\">$lang[TPL_LINK_VISITED_COLOR]</label>
1602  <input style=\"margin-bottom:10px;\" id=\"$fontRow-avisited\" name=\"$fontRow-avisited\" value=\"" . $templateSettings[$fontRowAVisitedColor]['value'] . "\" class=\"form-control color\">
1603 
1604  <label for=\"$fontRow-ahover\">$lang[TPL_LINK_HOVER_COLOR]</label>
1605  <input style=\"margin-bottom:10px;\" id=\"$fontRow-ahover\" name=\"$fontRow-ahover\" value=\"" . $templateSettings[$fontRowAHoverColor]['value'] . "\" class=\"form-control color\">
1606 
1607  <label for=\"$fontRowLinkFontWeight\">$lang[TPL_LINK_TEXTDECORATION]</label>
1608  <select style=\"margin-bottom:10px;\" id=\"$fontRowLinkFontWeight\" name=\"$fontRowLinkFontWeight\" class=\"form-control\">";
1609 
1610  foreach ($fontweightStyles as $weight) {
1611  $currentLinkFontWeight = "$fontRow-linkfontweight";
1612  if ($weight === $templateSettings[$currentLinkFontWeight]['value']) {
1613  $selected = "selected aria-selected=\"true\"";
1614  } else {
1615  $selected = '';
1616  }
1617  $html .= "<option value=\"$weight\" $selected>$weight</option>";
1618  }
1619  $html .= "</select>
1620 
1621  <label for=\"$fontRowLinkFontStyle\">$lang[TPL_LINK_FONTSTYLE]</label>
1622  <select style=\"margin-bottom:10px;\" id=\"$fontRowLinkFontStyle\" name=\"$fontRowLinkFontStyle\" class=\"form-control\">";
1623 
1624  foreach ($fontStyles as $style) {
1625  $currentLinkFontStyle = "$fontRow-linkfontstyle";
1626  if ($style === $templateSettings[$currentLinkFontStyle]['value']) {
1627  $selected = "selected aria-selected=\"true\"";
1628  } else {
1629  $selected = '';
1630  }
1631  $html .= "<option value=\"$style\" $selected>$style</option>";
1632  }
1633 
1634  $html .= "</select>
1635  <label for=\"$fontRowHoverTextDecoration\">$lang[TPL_HOVER_TEXTDECORATION]</label>
1636  <select style=\"margin-bottom:10px;\" id=\"$fontRowHoverTextDecoration\" name=\"$fontRowHoverTextDecoration\" class=\"form-control\">";
1637 
1638  foreach ($textdecorationTypes as $decoration) {
1639  $currentFontDecoration = "$fontRow-hovertextdecoration";
1640  if ($decoration === $templateSettings[$currentFontDecoration]['value']) {
1641  $selected = "selected aria-selected=\"true\"";
1642  } else {
1643  $selected = '';
1644  }
1645  $html .= "<option value=\"$decoration\" $selected>$decoration</option>";
1646  }
1647  $html .= "</select>";
1648 
1649 
1650  // SMALL TAG COLOR
1651  $html .= "<label for=\"$fontRowSmallColor\">$lang[TPL_SMALLCOLOR]</label>
1652  <input style=\"margin-bottom:10px;\" id=\"$fontRowSmallColor\" name=\"$fontRowSmallColor\" class=\"form-control color\" value=\"" . $templateSettings[$fontRowSmallColor]['value'] . "\">";
1653 
1654  // SMALL TAG SHADOW SIZE
1655  $html .= "<label for=\"$fontRowSmallShadowSize\">$lang[TPL_SMALLSHADOWSIZE]</label>
1656  <input style=\"margin-bottom:10px;\" id=\"$fontRowSmallShadowSize\" name=\"$fontRowSmallShadowSize\" class=\"form-control\" value=\"" . $templateSettings[$fontRowSmallShadowSize]['value'] . "\" placeholder=\"2px 2px\">";
1657  // SMALL TAG SHADOW COLOR
1658  $html .= "<label for=\"$fontRowSmallShadowColor\">$lang[TPL_SMALLSHADOWCOLOR]</label>
1659  <input style=\"margin-bottom:10px;\" id=\"$fontRowSmallShadowColor\" name=\"$fontRowSmallShadowColor\" value=\"" . $templateSettings[$fontRowSmallShadowColor]['value'] . "\" class=\"form-control color\">";
1660 
1661  // end font div box
1662  $html .= "
1663  </div>";
1664 
1665  echo $html;
1666 
1667  }
drawFontFamilySelectField($db, $lang, $selectName, $defaultValue)
return a select option list with all fonts:
Definition: template.php:1841
$col
Definition: index.php:79

References $col, $lang, $templateSettings, and YAWK\template\drawFontFamilySelectField().

◆ getFontsFromFolder()

static YAWK\template::getFontsFromFolder (   $folder)
static

get fonts from folder and return as array

Parameters
string$folderfolder that helds all fonts (usually ../system/fonts/)
Returns
string | array

Definition at line 1674 of file template.php.

1675  {
1676  // if no folder is given
1677  if (!isset($folder) || (empty($folder))) { // set default folder
1678  $folder = '../system/fonts/';
1679  } else {
1680  // make sure that there is a slash at the end
1681  $folder = rtrim($folder, '/') . '/';
1682  // check if folder is a directory
1683  if (!is_dir($folder)) { // if not, abort
1684  return "Folder <b>$folder</b> is not a valid folder";
1685  }
1686  }
1687 
1688  // create new font array
1689  $fontArray = array();
1690  // create new directory iterator
1691  $iterator = new \DirectoryIterator($folder);
1692  // walk through folder
1693  foreach ($iterator as $file) {
1694  // exclude dots
1695  if (!$file->isDot()) { // check filetype
1696  if ($file->getExtension() === "ttf") { // add ttf fonts to array
1697  $fontArray['ttf'][] = $file->getFilename();
1698  }
1699  // check filetype
1700  if ($file->getExtension() === "otf") { // add otf fonts to array
1701  $fontArray['otf'][] = $file->getFilename();
1702  }
1703  // check filetype
1704  if ($file->getExtension() === "woff") { // add woff fonts to array
1705  $fontArray['woff'][] = $file->getFilename();
1706  }
1707  // check filetype
1708  if ($file->getExtension() === "WOFF") { // add woff fonts to array
1709  $fontArray['woff'][] = $file->getFilename();
1710  }
1711  }
1712  }
1713  // check if font array is set and not empty
1714  if (is_array($fontArray) && (!empty($fontArray))) { // all good
1715  return $fontArray;
1716  } else { // array not set or empty, throw message
1717  return "No fonts found in $folder";
1718  }
1719  }
$fontArray

References YAWK\template\$folder, and $fontArray.

◆ getFormElements()

YAWK\template::getFormElements (   $db,
  $settings,
  $type,
  $lang,
  $user 
)

return html form field, depending on fieldClass

Parameters
object$dbDatabase Object

Definition at line 1163 of file template.php.

1164  { // loop trough array
1165  // removed not needed checkup
1166  if (!isset($type) && (empty($type)))
1167  { // if param 'type' is missing, set type 1 as default
1168  $type = 1;
1169  }
1170  if (!isset($settings) || (is_array($settings) === false))
1171  {
1172  echo 'Template settings are missing. Please re-install template.';
1173  }
1174  else
1175  {
1176  // loop trough settings array
1177  foreach ($settings as $setting)
1178  {
1179  // field type not set or empty
1180  if (!isset($setting['fieldType']) && (empty($fieldType)))
1181  { // set input field as common default
1182  $setting['fieldType'] = "input";
1183  }
1184  else
1185  { // settings type must be equal to param $type
1186  // equals settings category
1187  if ($setting['type'] === "$type" && ($setting['activated'] === "1"))
1188  {
1189  // check if ICON is set
1190  // if an icon is set, it will be drawn before the heading, to the left.
1191  if (isset($setting['icon']) && (!empty($setting['icon'])))
1192  { // fill it w icon
1193  $setting['icon'] = "<i class=\"$setting[icon]\"></i>";
1194  }
1195  else
1196  { // leave empty - no icon available
1197  $setting['icon'] = '';
1198  }
1199 
1200  // check if LABEL is set
1201  // The label sits directly above, relative to the setting form element
1202  if (isset($setting['label']) && (!empty($setting['label'])))
1203  { // if its set, put it into $lang array for L11n
1204  $setting['label'] = $lang[$setting['label']];
1205  }
1206  else
1207  { // otherwise throw error
1208  $setting['label'] = 'sorry, there is not label set. meh!';
1209  }
1210 
1211  // check if HEADING is set
1212  // if set, a <H3>Heading</H3> will be shown above the setting
1213  if (isset($setting['heading']) && (!empty($setting['heading'])))
1214  { // L11n
1215  $setting['heading'] = $lang[$setting['heading']];
1216  }
1217  else
1218  { // leave empty - no heading for that setting
1219  $setting['heading'] = '';
1220  }
1221 
1222  // check if SUBTEXT is set
1223  // this is shown in <small>tags</small> beneath the heading
1224  if (isset($setting['subtext']) && (!empty($setting['subtext'])))
1225  { // L11n
1226  $setting['subtext'] = $lang[$setting['subtext']];
1227  }
1228  else
1229  { // leave empty - no subtext beneath the heading
1230  $setting['subtext'] = '';
1231  }
1232 
1233  // check if description is set
1234  // the description will be shown right beside the label
1235  if (isset($setting['description']) && (!empty($setting['description'])))
1236  { // L11n
1237  $setting['description'] = $lang[$setting['description']];
1238  $setting['description'] = "&nbsp;<small><i class=\"fa fa-question-circle-o text-info\" data-placement=\"auto right\" data-toggle=\"tooltip\" title=\"$setting[description]\"></i></small>";
1239  }
1240 
1241  /* SELECT FIELD */
1242  if ($setting['fieldType'] === "select")
1243  { // display icon, heading and subtext, if its set
1244  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1245  {
1246  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1247  }
1248  // begin draw select
1249  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1250  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1251  <select style=\"margin-bottom:10px;\" class=\"form-control\" id=\"$setting[property]\" name=\"$setting[property]\">";
1252  echo "<option value=\"$setting[value]\">$lang[SETTING_CURRENT] $setting[value]</option>";
1253  // explode option string into array
1254  $optionValues = explode(":", $setting['options']);
1255  foreach ($optionValues as $value)
1256  {
1257  // extract value from option setting string
1258  // $optionValue = preg_replace("/,[a-zA-Z0-9]*/", "", $value);
1259  // extract description from option setting
1260  $optionDesc = preg_replace('/.*,(.*)/', '$1', $value);
1261  $optionValue = preg_split("/,[a-zA-Z0-9]*/", $value);
1262 
1263  echo "<option value=\"$optionValue[0]\">$optionDesc</option>";
1264  }
1265  echo "</select>";
1266  }
1267 
1268  /* RADIO BUTTTONS */
1269  else if ($setting['fieldType'] === "radio")
1270  {
1271  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1272  {
1273  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1274  }
1275  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;</label>
1276  <input style=\"margin-bottom:10px;\" type=\"radio\" id=\"$setting[property]\" name=\"$setting[property]\">";
1277  echo "<input type=\"radio\" value=\"$setting[value]\">$lang[SETTING_CURRENT] $setting[value]</option>";
1278 
1279  // explode option string into array
1280  $optionValues = explode(":", $setting['options']);
1281  foreach ($optionValues as $value)
1282  {
1283  // extract value from option setting string
1284  $optionValue = preg_replace("/,[a-zA-Z0-9]*/", "", $value);
1285  // extract description from option setting
1286  $optionDesc = preg_replace('/.*,(.*)/', '$1', $value);
1287 
1288  echo "<option value=\"$optionValue\">$optionDesc</option>";
1289  }
1290  echo "</select>";
1291  }
1292 
1293  // CHECKBOX
1294  else if ($setting['fieldType'] === "checkbox")
1295  { // build a checkbox
1296  if ($setting['value'] === "1")
1297  { // set checkbox to checked
1298  $checked = "checked";
1299  }
1300  else
1301  { // checkbox not checked
1302  $checked = "";
1303  }
1304  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1305  {
1306  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1307  }
1308  echo "<input type=\"hidden\" name=\"$setting[property]\" value=\"0\">
1309  <input type=\"checkbox\" id=\"$setting[property]\" name=\"$setting[property]\" value=\"1\" $checked>
1310  <label style=\"margin-bottom:10px;\" for=\"$setting[property]\">&nbsp; $setting[label]&nbsp;$setting[description]&nbsp;</label>";
1311  }
1312 
1313  // CHECKBOX as toggle switch
1314  else if ($setting['fieldType'] === "checkbox toggle")
1315  {
1316  // build a checkbox
1317  if ($setting['value'] === "1")
1318  { // set checkbox to checked
1319  $checked = "checked";
1320  }
1321  else
1322  { // checkbox not checked
1323  $checked = "";
1324  }
1325 
1326  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1327  {
1328  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1329  }
1330  echo "<input type=\"hidden\" name=\"$setting[property]\" value=\"0\">
1331  <input type=\"checkbox\" data-on=\"$lang[ON_]\" data-off=\"$lang[OFF_]\" data-toggle=\"toggle\" data-onstyle=\"success\" data-offstyle=\"danger\" id=\"$setting[property]\" name=\"$setting[property]\" value=\"1\" $checked>
1332  <label for=\"$setting[property]\">&nbsp; $setting[label]&nbsp;$setting[description]&nbsp;</label><hr>";
1333  }
1334 
1335  /* TEXTAREA */
1336  else if ($setting['fieldType'] === "textarea")
1337  { // if a long value is set
1338  $placeholder = $setting['placeholder'];
1339  // store placeholder from array in var to use it at language array
1340  if (isset($setting['longValue']) && (!empty($setting['longValue'])))
1341  { // build a longValue tagged textarea and fill with longValue
1342  $setting['longValue'] = nl2br($setting['longValue']);
1343  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1344  {
1345  echo "<h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1346  }
1347  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;</label>
1348  <textarea style=\"margin-bottom:10px;\" cols=\"64\" rows=\"4\" class=\"$setting[fieldClass]\" placeholder=\"$lang[$placeholder]\" id=\"$setting[property]\" name=\"$setting[property]\">$setting[longValue]</textarea>";
1349  }
1350  else
1351  { // draw default textarea
1352  $setting['value'] = nl2br($setting['value']);
1353  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1354  {
1355  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1356  }
1357  echo "<label for=\"$setting[property]-long\">$setting[label]&nbsp;$setting[description]&nbsp;</label>
1358  <textarea style=\"margin-bottom:10px;\" cols=\"64\" rows=\"4\" class=\"$setting[fieldClass]\" placeholder=\"$lang[$placeholder]\" id=\"$setting[property]\" name=\"$setting[property]\">$setting[value]</textarea>";
1359  }
1360  }
1361 
1362  /* INPUT PASSWORD FIELD */
1363  else if ($setting['fieldType'] === "password")
1364  { // draw an input field
1365  $placeholder = $setting['placeholder'];
1366  // store placeholder from array in var to use it at language array
1367  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1368  {
1369  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1370  }
1371  echo "<label for=\"$setting[property]\">$setting[label]</label>&nbsp;$setting[description]&nbsp;
1372  <input style=\"margin-bottom:10px;\" type=\"password\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1373  value=\"$setting[value]\" placeholder=\"$lang[$placeholder]\">";
1374  }
1375  /* INPUT TEXT FIELD */
1376  else if ($setting['fieldType'] === "input")
1377  { // draw an input field
1378  $placeholder = $setting['placeholder'];
1379  // store placeholder from array in var to use it at language array
1380  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1381  {
1382  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1383  }
1384  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1385  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1386  <input style=\"margin-bottom:10px;\" type=\"text\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1387  value=\"$setting[value]\" placeholder=\"$lang[$placeholder]\">";
1388  }
1389 
1390  /* COLOR TEXT FIELD */
1391  else if ($setting['fieldType'] === "color")
1392  { // draw a color input field
1393  $placeholder = $setting['placeholder']; // store placeholder from array in var to use it at language array
1394  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1395  {
1396  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1397  }
1398  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1399  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1400  <input style=\"margin-bottom:10px;\" type=\"text\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1401  value=\"$setting[value]\" placeholder=\"$lang[$placeholder]\">";
1402  }
1403 
1404  /* TEMPLATE SELECT FIELD */
1405  else if ($setting['fieldType'] === "select template")
1406  { // display icon, heading and subtext, if its set
1407 
1408  $templateArray = \YAWK\template::getTemplateIds($db);
1409  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1410  {
1411  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1412  }
1413  // begin draw select
1414  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1415  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1416  <select style=\"margin-bottom:10px;\" class=\"form-control\" id=\"$setting[property]\" name=\"$setting[property]\">";
1417  $activeTemplateName = \YAWK\template::getTemplateNameById($db, (int)$setting['value']);
1418  echo "<option value=\"$setting[value]\">$lang[SETTING_CURRENT] $activeTemplateName</option>";
1419  // explode option string into array
1420  $optionValues = explode(":", $setting['options']);
1421  foreach ($templateArray as $template)
1422  {
1423  if ($setting['value'] != $template['id']) {
1424  echo "<option value=\"".$template['id']."\"".$markup.">".$template['name']."</option>";
1425  }
1426  }
1427  echo "</select>";
1428  }
1429  else
1430  {
1431  // draw an input field
1432  $placeholder = $setting['placeholder'];
1433  // store placeholder from array in var to use it at language array
1434  if (!empty($setting['icon']) || (!empty($setting['heading']) || (!empty($setting['subtext']))))
1435  {
1436  echo "<br><h4 class=\"box-title\">$setting[icon]&nbsp;$setting[heading]&nbsp;<small>$setting[subtext]</small></h4>";
1437  }
1438  if (!isset($lang[$placeholder]) ||(empty($lang[$placeholder]))){ $phMarkup = ""; } else { $phMarkup = " placeholder=\"$lang[$placeholder]\""; }
1439  echo "<label for=\"$setting[property]\">$setting[label]&nbsp;$setting[description]&nbsp;
1440  <small><i class=\"small\" style=\"font-weight:normal\">$lang[DEFAULT]: $setting[valueDefault]</i></small></label>
1441  <input style=\"margin-bottom:10px;\" type=\"text\" class=\"$setting[fieldClass]\" id=\"$setting[property]\" name=\"$setting[property]\"
1442  value=\"$setting[value]\"$phMarkup\">";
1443  }
1444  }
1445  }
1446  }
1447  }
1448  }
static getTemplateIds(object $db)
return array with all template id's + names.
Definition: template.php:426
if(isset($_POST['save'])) $settings
$value

References $db, $lang, $settings, $type, $value, and YAWK\template\getTemplateIds().

◆ getGoogleFontsArray()

static YAWK\template::getGoogleFontsArray (   $db)
static

get all google fonts into an array and return array

Parameters
object$dbdatabase
Returns
array | null

Definition at line 1949 of file template.php.

1950  {
1951  // array that holds the data
1952  $googleFonts = array();
1953  // select google fonts from database
1954  if ($sql = $db->query("SELECT font FROM {gfonts} ORDER BY font")) { // for every single row...
1955  while ($row = mysqli_fetch_array($sql)) { // add font to array
1956  $googleFonts[] = $row['0'];
1957  }
1958  }
1959  // check if googleFont is set and an array and not empty
1960  if (isset($googleFonts) && (is_array($googleFonts) && (!empty($googleFonts)))) { // return array containing all google fonts
1961  return $googleFonts;
1962  } else { // no google font in database...
1963  return null;
1964  }
1965  }

References $db, $googleFonts, and $sql.

Referenced by YAWK\template\drawFontFamilySelectField().

◆ getMaxId()

static YAWK\template::getMaxId (   $db)
static

return biggest ID from template database

Parameters
object$dbdatabase
Returns
int|bool

Definition at line 779 of file template.php.

780  {
781  /* @param $db \YAWK\db */
782  if ($res = $db->query("SELECT MAX(id) from {templates}")) { // fetch id
783  if ($row = mysqli_fetch_row($res)) {
784  return $row[0];
785  } else {
786  sys::setSyslog($db, 47, 1, "failed to get MAX(id) from template db", 0, 0, 0, 0);
787  return false;
788  }
789  } else {
790  return false;
791  }
792  }

References $db, and $res.

◆ getPositionDivBox()

static YAWK\template::getPositionDivBox (   $db,
  $lang,
  $position,
  $row,
  $bootstrapGrid,
  $positions,
  $indicators,
  $user,
  $template 
)
static

return div box with postition settings

Parameters
object$dbDatabase object
string$positionThe position to load
array$positionsPositions [enabled] status array
array$indicatorsPositions [indicator] status array
object$userthe current user object
object$templateTemplate object

Definition at line 1118 of file template.php.

1119  {
1120  global $currentpage;
1121  if (isset($row) && (!empty($row))) {
1122  if ($row === "1") {
1123  $startRow = "<div class=\"row\">";
1124  $endRow = "</div>";
1125  } else {
1126  $startRow = '';
1127  $endRow = '';
1128  }
1129  } else {
1130  $startRow = '';
1131  $endRow = '';
1132  }
1133 
1134  // check if position indicator is enabled
1135  if ($positions["pos-$position-enabled"] === "1")
1136  { // check if position indicator is enabled
1137  if ($indicators["pos-$position-indicator"] === "1")
1138  { // display position indicator
1139  $indicatorStyle = "style=\"border: 1px solid red;\"";
1140  $indicatorText = "<i><b>$position</b></i>";
1141  }
1142  else
1143  { // no position indicator set
1144  $indicatorStyle = '';
1145  $indicatorText = '';
1146  }
1147 
1148  // output position div box
1149  echo "$startRow";
1150  echo "<div class=\"$bootstrapGrid pos-$position\" id=\"$position\" $indicatorStyle>$indicatorText";
1151  template::setPosition($db, $lang, "$position-pos", $currentpage, $user, $template);
1152  echo "
1153  </div>";
1154  echo "$endRow";
1155  }
1156  }
static setPosition($db, $lang, $position, $currentpage, $user, $template)
set template position and output the correct data depending on position
Definition: template.php:2736
$indicators
Definition: index.php:57

References $db, $indicators, $lang, YAWK\template\$positions, and YAWK\template\setPosition().

◆ getPositionIndicatorStatusArray()

static YAWK\template::getPositionIndicatorStatusArray (   $db,
  $templateID 
)
static

get the position indicators. This is used on index.php to mark indicated positions

Parameters
object$dbdatabase
int$templateIDID of the current template
Returns
array|bool $array position indicator 0|1

Definition at line 2710 of file template.php.

2711  {
2712  $markedPositions = array();
2713  $sql = $db->query("SELECT property, value
2714  FROM {template_settings}
2715  WHERE property
2716  LIKE 'pos-%-indicator'
2717  AND templateID = '" . $templateID . "'");
2718  while ($row = mysqli_fetch_assoc($sql)) {
2719  $prop = $row['property'];
2720  $markedPositions[$prop] = $row['value'];
2721  }
2722  if (!empty($markedPositions)) {
2723  return $markedPositions;
2724  } else {
2725  return false;
2726  }
2727  }

References $db, $sql, and $templateID.

◆ getPositionStatesArray()

static YAWK\template::getPositionStatesArray (   $db,
  $templateID 
)
static

get the position states of all templates. This is used on index.php to render only templates that are enabled (1)

Parameters
object$dbdatabase
int$templateIDID of the current selected template
Returns
array|bool $array template positions 0|1

Definition at line 2686 of file template.php.

2687  {
2688  $array = array();
2689  $sql = $db->query("SELECT property, value
2690  FROM {template_settings}
2691  WHERE property LIKE 'pos-%-enabled' AND
2692  templateID = '" . $templateID . "'");
2693  while ($row = mysqli_fetch_assoc($sql)) {
2694  $prop = $row['property'];
2695  $array[$prop] = $row['value'];
2696  }
2697  if (is_array($array) && (!empty($array))) {
2698  return $array;
2699  } else {
2700  die("Positions array not set");
2701  }
2702  }

References $db, $sql, $templateID, and die.

◆ getTemplateIds()

static YAWK\template::getTemplateIds ( object  $db)
static

return array with all template id's + names.

Parameters
object$dbdatabase
Returns
array|bool
Parameters
\YAWK\db$db

Definition at line 426 of file template.php.

427  {
428  /** @param \YAWK\db $db */
429  // returns an array with all template IDs
430  $mysqlRes = $db->query("SELECT id, name
431  FROM {templates}
432  ORDER by name ASC");
433  while ($row = mysqli_fetch_assoc($mysqlRes)) {
434  $res[] = $row;
435  }
436  if (!empty($res)) { // yey, return array
437  return $res;
438  } else { // could not fetch array
439  sys::setSyslog($db, 47, 1, "failed get template id and name ", 0, 0, 0, 0);
440  return false;
441  }
442  }

References $db, and $res.

Referenced by YAWK\backend\drawTemplateSelectField(), and YAWK\template\getFormElements().

◆ getTemplateSettingsArray()

static YAWK\template::getTemplateSettingsArray (   $db,
  $templateID 
)
static

get all template settings into an array and return it

Parameters
object$dbdatabase
int$templateIDaffected template ID
Returns
array

Definition at line 2794 of file template.php.

2795  {
2796  /* @var \YAWK\db $db */
2797  if (!isset($templateID) || (empty($templateID))) { // if no templateID is set, take current template ID from settings db
2798  $templateID = settings::getSetting($db, "selectedTemplate");
2799  }
2800  $array = array();
2801  $res = $db->query("SELECT property, value, longValue
2802  FROM {template_settings}
2803  WHERE templateID = $templateID");
2804 
2805  while ($row = mysqli_fetch_assoc($res)) {
2806  $prop = $row['property'];
2807  $array[$prop] = $row['value'];
2808  $array[$prop] .= $row['longValue'];
2809  }
2810  return $array;
2811  }

References $db, $res, $templateID, and YAWK\settings\getSetting().

◆ getValidTemplateID()

static YAWK\template::getValidTemplateID (   $db,
  $user,
  $template 
)
static

check the current template ID, considering if user is logged in, allowed to override template and so on

Parameters
object$dbdatabase
object$userthe current user object
object$templatethe current page object
Returns
int

Definition at line 2603 of file template.php.

2604  {
2605  // it is important to do some checks to determine the correct template id
2606  // to do that, we need data from 2 objects;
2607 
2608  // check if template and user obj are there and not empty
2609  if (isset($user) && (isset($template)))
2610  { // check, if user is allowed to override template
2611 
2612  if ($user->overrideTemplate == 1)
2613  { // ok, get user templateID
2614  if (!empty($user->templateID))
2615  { // set templateID for following query
2616  $validTemplateID = $user->templateID;
2617  }
2618  else
2619  { // user->TemplateID not set, instead use default template
2620  if (!empty($template->selectedTemplate))
2621  { // set global defined (current active), default template ID
2622  $validTemplateID = $template->selectedTemplate;
2623  }
2624  }
2625  }
2626  else
2627  { // user is not allowed to override template, use default template
2628  if (!empty($template->selectedTemplate))
2629  { // set global defined (current active), default template ID
2630  $validTemplateID = $template->selectedTemplate;
2631  }
2632  }
2633  }
2634  else
2635  { // unable to determine template from objects, load active (global) template instead
2636  $validTemplateID = settings::getSetting($db, "selectedTemplate");
2637  }
2638  // for any reasons, that valid template ID could not be set
2639  if (!isset($validTemplateID) || (empty($validTemplateID)))
2640  { // set current (active / selected) template as templateID
2641  $validTemplateID = settings::getSetting($db, "selectedTemplate");
2642  }
2643  // must be set
2644  return $validTemplateID;
2645  }

References $db, and YAWK\settings\getSetting().

Referenced by YAWK\template\getCurrentTemplateId().

◆ includeHeader()

static YAWK\template::includeHeader (   $db)
static

include header for html page *outdated? *moved to sys?

Parameters
object$dbdatabase
Parameters
\YAWK\db$db

Definition at line 2651 of file template.php.

2652  {
2653  /** @param \YAWK\db $db */
2654  global $currentpage;
2655  $i = 1;
2656  $host = settings::getSetting($db, "host");
2657  echo "<title>" . $currentpage->title . "</title>
2658  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=\"utf-8\">
2659  <link rel=\"shortcut icon\" href=\"favicon.ico\" type=\"image/x-icon\">
2660  <base href=\"" . $host . "/\">";
2661  $get_localtags = $db->query("SELECT name, content
2662  FROM {meta_local}
2663  WHERE page = '" . $currentpage->id . "'");
2664  while ($row = mysqli_fetch_row($get_localtags)) {
2665  if (isset($row['1']) && !empty($row['1'])) {
2666  echo "<meta name=\"" . $row[0] . "\" content=\"" . $row[1] . "\" />";
2667  } else {
2668  $get_globaltags = $db->query("SELECT content
2669  FROM {meta_global}
2670  WHERE name = 'description'");
2671  $row = mysqli_fetch_row($get_globaltags);
2672  while ($i > 0) {
2673  echo "<meta name=\"description\" content=\"" . $row[0] . "\" />";
2674  $i--;
2675  }
2676  }
2677  }
2678  }
$host
Definition: page-edit.php:65
$i

References $db, $host, $i, and YAWK\settings\getSetting().

◆ loadActiveAssets()

YAWK\template::loadActiveAssets (   $db,
  $templateID,
  $host 
)

Load Active Assets.

Load HTML markup for each active asset of current template

Parameters
$dbobject db connection
$templateIDint the current template ID
$hoststring host URL will be used by internal assets to avoid relative paths
$typestring css|js to detect which assets to load
Returns
null

Definition at line 3045 of file template.php.

3046  {
3047  /* @var \YAWK\db $db */
3048 
3049  // check if templateID is set
3050  if (isset($templateID) && (!empty($templateID)))
3051  {
3052  echo "
3053 <!-- ASSETS -->";
3054  // get assets from database for this template
3055  if ($res = $db->query("SELECT type, asset, link FROM {assets} WHERE templateID = '" . $templateID . "' ORDER BY sortation ASC"))
3056  {
3057  // loop through assets
3058  while ($row = mysqli_fetch_assoc($res))
3059  {
3060  // make sure, host will only be added for relative url assets
3061  if (stristr($row['link'], 'http://') || (stristr($row['link'], 'https://')) === FALSE) {
3062  // echo "".$row['link']." internal:";
3063  $url = $host . $row['link'];
3064  // do nothing
3065  } else { // external URL, do not prepend host string to link
3066  // echo "".$row['link']." ext:";
3067  $url = $row['link'];
3068  }
3069 
3070  if ($row['type'] === "js")
3071  { // load js asset
3072  echo "
3073 <!--load JS: $row[asset] -->
3074 <script src = \"" . $url . "\"></script>";
3075  }
3076  else if ($row['type'] === "css")
3077  { // load css asset
3078  echo "
3079 <!-- load CSS: $row[asset] -->
3080 <link rel=\"stylesheet\" href=\"" . $url . "\" type=\"text/css\" media=\"all\">";
3081  }
3082  }
3083  }
3084  }
3085  return null;
3086  }
$url
Definition: user-new.php:101

References $db, $host, $res, $templateID, and $url.

◆ loadActiveAssetsIntoArray()

YAWK\template::loadActiveAssetsIntoArray (   $db,
  $templateID 
)

Definition at line 3088 of file template.php.

3089  {
3090  /* @var \YAWK\db $db */
3091 
3092  if (isset($templateID) && (!empty($templateID)))
3093  {
3094  if ($sql = $db->query("SELECT * FROM {assets} WHERE templateID = '" . $templateID . "'"))
3095  { // fetch data
3096  while ($row = mysqli_fetch_assoc($sql)) { // store data as array
3097  $assets[] = $row;
3098  }
3099  }
3100  if (isset($assets) && (is_array($assets) && (!empty($assets))))
3101  {
3102  return $assets;
3103  }
3104  else
3105  {
3106  return false;
3107  }
3108  }
3109  else
3110  { // template ID is not set
3111  return false;
3112  }
3113  }

References $db, $sql, and $templateID.

Referenced by YAWK\template\downloadTemplate().

◆ loadAllSettingsIntoArray()

YAWK\template::loadAllSettingsIntoArray ( object  $db,
int  $id 
)

load template settings of ID and return as array

Parameters
object$dbdatabase object
int$idtemplate id to load
Returns
array|false
Parameters
$db\YAWK\db $res

Definition at line 328 of file template.php.

329  {
330  /** @param $db \YAWK\db $res */
331  $res = $db->query("SELECT * FROM {template_settings} WHERE templateID = '" . $id . "'");
332  while ($row = mysqli_fetch_assoc($res))
333  {
334  $templateSettings[] = $row;
335  }
336 
337  if (isset($templateSettings) && (is_array($templateSettings) && (!empty($templateSettings))))
338  { // not an array or empty...
339  return $templateSettings;
340  }
341  else
342  { // could not fetch tpl properties, throw error...
343  sys::setSyslog($db, 47, 1, "failed to load template_settings of template id <b>$id</b> into array", 0, 0, 0, 0);
344  return false;
345  }
346  }

References $db, YAWK\template\$id, $res, and $templateSettings.

Referenced by YAWK\template\downloadTemplate().

◆ loadGoogleFonts()

static YAWK\template::loadGoogleFonts (   $db)
static

get settings for heading, menu and text font and output html to load font

Parameters
object$dbdatabase

Definition at line 2536 of file template.php.

2537  {
2538  $fonts = array(); // hold all fonts
2539  $googleFontFamilyString = ''; // the string the contains all google font families to minimize requests
2540  if ($sql = $db->query("SELECT value FROM {template_settings} WHERE property LIKE '%-fontfamily'")) {
2541  while ($row = mysqli_fetch_row($sql)) {
2542  $fonts[] = $row[0];
2543  }
2544  }
2545  foreach ($fonts as $googleFont) {
2546  if (substr($googleFont, -6) === "-gfont") {
2547  // remove font indicator
2548  $googleFont = rtrim($googleFont, "gfont");
2549  $googleFont = rtrim($googleFont, "-");
2550  // build google font loading string
2551  $googleFontFamilyString .= $googleFont;
2552  // add | to allow loading more than one font
2553  $googleFontFamilyString .= "|";
2554  }
2555  }
2556  if (!empty($googleFontFamilyString)) {
2557  // remove last | because its not needed
2558  $googleFontFamilyString = rtrim($googleFontFamilyString, "|");
2559  echo "<link rel=\"dns-prefetch\" href=\"//fonts.googleapis.com\">";
2560  echo "<link href=\"https://fonts.googleapis.com/css?family=$googleFontFamilyString\" rel=\"stylesheet\">";
2561  }
2562 
2563  }

References $db, and $sql.

◆ loadProperties()

YAWK\template::loadProperties (   $db,
  $id 
)

load properties into template object

Parameters
object$dbdatabase object
int$idtemplate id to load
Returns
bool true or false
Parameters
$db\YAWK\db $res

Definition at line 264 of file template.php.

265  {
266  /** @param $db \YAWK\db $res */
267  $res = $db->query("SELECT * FROM {templates} WHERE id = '" . $id . "'");
268  if ($row = mysqli_fetch_assoc($res)) {
269  $this->id = $row['id'];
270  $this->active = $row['active'];
271  $this->name = $row['name'];
272  $this->positions = $row['positions'];
273  $this->description = $row['description'];
274  $this->releaseDate = $row['releaseDate'];
275  $this->author = $row['author'];
276  $this->authorUrl = $row['authorUrl'];
277  $this->weblink = $row['weblink'];
278  $this->subAuthor = $row['subAuthor'];
279  $this->subAuthorUrl = $row['subAuthorUrl'];
280  $this->modifyDate = $row['modifyDate'];
281  $this->version = $row['version'];
282  $this->framework = $row['framework'];
283  $this->license = $row['license'];
284  $this->selectedTemplate = settings::getSetting($db, "selectedTemplate");
285  return true;
286  } else { // could not fetch tpl properties, throw error...
287  sys::setSyslog($db, 47, 1, "failed to load properties of template <b>$this->name</b> (id: <b>$id</b>)", 0, 0, 0, 0);
288  // \YAWK\alert::draw("danger", "Warning!", "Could not fetch template properties. Expect a buggy view.", "", 3000);
289  return false;
290  }
291  }
$template selectedTemplate
Definition: index.php:170

References $db, YAWK\template\$id, $res, description, YAWK\settings\getSetting(), name, and selectedTemplate.

Referenced by YAWK\template\downloadTemplate().

◆ loadPropertiesIntoArray()

YAWK\template::loadPropertiesIntoArray ( object  $db,
int  $id 
)

load template properties and return as array

Parameters
object$dbdatabase object
int$idtemplate id to load
Returns
bool|array true or false
Parameters
$db\YAWK\db $res

Definition at line 300 of file template.php.

301  {
302  /** @param $db \YAWK\db $res */
303  $res = $db->query("SELECT * FROM {templates} WHERE id = '" . $id . "'");
304  if ($row = mysqli_fetch_assoc($res))
305  {
306  if (!is_array($row) || (empty($row)))
307  { // not an array or empty...
308  return false;
309  }
310  else
311  { // return array
312  return $row;
313  }
314  }
315  else
316  { // could not fetch tpl properties, throw error...
317  sys::setSyslog($db, 47, 1, "failed to load properties of template id <b>$id</b> into array", 0, 0, 0, 0);
318  return false;
319  }
320  }

References $db, YAWK\template\$id, and $res.

Referenced by YAWK\template\downloadTemplate().

◆ loadSettingsTypesIntoArray()

YAWK\template::loadSettingsTypesIntoArray ( object  $db)

load template_settings_types and return as array

Parameters
object$dbdatabase object
Returns
array|false
Parameters
$db\YAWK\db $res

Definition at line 401 of file template.php.

402  {
403  /** @param $db \YAWK\db $res */
404  $res = $db->query("SELECT * FROM {template_settings_types}");
405  while ($row = mysqli_fetch_assoc($res))
406  {
407  $settingsTypes[] = $row;
408  }
409  if (isset($settingsTypes) && (is_array($settingsTypes) && (!empty($settingsTypes))))
410  { // all good,
411  return $settingsTypes;
412  }
413  else
414  { // could not fetch tpl properties, throw error...
415  sys::setSyslog($db, 47, 1, "failed to load template_settings_types into array", 0, 0, 0, 0);
416  return false;
417  }
418  }

References $db, and $res.

Referenced by YAWK\template\downloadTemplate().

◆ returnCurrentBootstrapVersion()

static YAWK\template::returnCurrentBootstrapVersion (   $db,
  $templateID 
)
static

Return which Bootstrap version is currently loaded in given template.

Parameters
object$dbdatabase
Returns
string Which Bootstrap v is setup in given template ID

Definition at line 3158 of file template.php.

3159  {
3160  // query database
3161  if ($sql = $db->query("SELECT asset FROM {assets} WHERE templateID = '" . $templateID . "' AND asset LIKE '%Bootstrap%CSS'")) { // fetch data
3162  while ($row = mysqli_fetch_row($sql)) { // store data as array
3163  $asset[] = $row;
3164  }
3165  }
3166 
3167  // check if asset array is set and not empty
3168  if (isset($asset) && (is_array($asset) && (!empty($asset[0][0]))))
3169  {
3170  if ($asset[0][0] === "Bootstrap 4 CSS")
3171  { // v4
3172  return "4";
3173  }
3174 
3175  else if ($asset[0][0] === "Bootstrap 3 CSS")
3176  { // v3
3177  return "3";
3178  }
3179  else
3180  { // unable to detect bootstrap version, maybe this template ID does not load bootstrap
3181  return "0";
3182  }
3183  }
3184  return null;
3185  }

References $db, $sql, and $templateID.

Referenced by YAWK\menu\display().

◆ saveAs()

YAWK\template::saveAs ( object  $db)

save a template as new. It copies the tpl folder and all settings into a new one.

Parameters
object$db
object$template
string$new_template
string$description
string$author
string$authorUrl
string$weblink
string$version
string$license
Returns
bool
Parameters
\YAWK\db$db

Definition at line 201 of file template.php.

201  : bool
202  {
203  /** @param \YAWK\db $db */
204  // prepare vars
205  $replace = array("/ä/", "/ü/", "/ö/", "/Ä/", "/Ãœ/", "/Ö/", "/ß/"); // array of special chars
206  $chars = array("ae", "ue", "oe", "Ae", "Ue", "Oe", "ss"); // array of replacement chars
207  $this->newTplName = preg_replace($replace, $chars, $this->newTplName); // replace with preg
208  // final check: just numbers and chars are allowed
209  $this->newTplName = preg_replace("/[^a-z0-9\-\/]/i", "", $this->newTplName);
210  // same goes on for $template->name
211  $this->name = preg_replace($replace, $chars, $this->name); // replace with preg
212  // final check: just numbers and chars are allowed
213  $this->name = preg_replace("/[^a-z0-9\-\/]/i", "", $this->name);
214  // get current timestamp
215  $now = sys::now();
216 
217  // copy new template into database
218  if ($res = $db->query("INSERT INTO {templates} (name, positions, description, releaseDate, author, authorUrl, weblink, subAuthor, subAuthorUrl, modifyDate, version, framework, license)
219  VALUES('" . $this->newTplName . "',
220  '" . $this->positions . "',
221  '" . $this->description . "',
222  '" . $now . "',
223  '" . $this->author . "',
224  '" . $this->authorUrl . "',
225  '" . $this->weblink . "',
226  '" . $this->subAuthor ."',
227  '" . $this->subAuthorUrl ."',
228  '" . $now . "',
229  '" . $this->version . "',
230  '" . $this->framework . "',
231  '" . $this->license . "')"))
232  {
233 
234  }
235  else
236  { // q failed, throw error
237  sys::setSyslog($db, 47, 1, "failed to save <b>$this->newTplName</b> as new template", 0, 0, 0, 0);
238  // \YAWK\alert::draw("warning", "Warning!", "Could not insert your template $new_template into database.", "", 6200);
239  return false;
240  }
241  // tpl added to database successful
242  // check if template folder exists
243  if (is_dir(dirname("../system/templates/$this->name")))
244  {
245  // ok, start to copy template from source to new destination
246  sys::xcopy("../system/templates/$this->name", "../system/templates/$this->newTplName");
247  sys::setSyslog($db, 47, 1, "copy template folder from ../system/templates/$this->name to ../system/templates/$this->newTplName", 0, 0, 0, 0);
248  return true;
249  }
250  else
251  { // template folder does not exist
252  // what should we copy if nothing exists?
253  sys::setSyslog($db, 47, 1, "failed to copy template - template name $this->name does not exist", 0, 0, 0, 0);
254  return false;
255  }
256  }
$now

References $db, $now, $res, name, YAWK\sys\now(), and YAWK\sys\xcopy().

◆ saveProperties()

YAWK\template::saveProperties ( object  $db,
int  $id,
array  $data,
array  $oldTplSettings 
)

save new template properties into database

Parameters
object$dbdatabase object
int$idtemplate id to save
array$datapost data from form (new settings)
array$oldTplSettingstemplate settings array (old settings)
Returns
bool true or false

Definition at line 356 of file template.php.

356  : bool
357  {
358  // check if data is set set
359  if (!isset($data) || (!isset($id))) { // if not, abort
360  return false;
361  }
362  if (empty($oldTplSettings))
363  {
364  $oldTplSettings = array();
365  }
366 
367  // walk through all post data settings
368  foreach ($data as $property => $value)
369  {
370  // check, if settings is a long value
371  if (fnmatch('*-longValue', $property))
372  { // it is, set long value indicator to true
373  $longValue = 1;
374  }
375  else
376  { // not a long value
377  $longValue = 0;
378  }
379 
380  // save this property only if its NOT save or customcss
381  if ($property != "save" && ($property != "customCSS") && ($property != "testText")) {
382  if (isset($oldTplSettings[$property]) && ($oldTplSettings[$property]) === $value)
383  { // if old settings and new settings are the same
384  // do nothing
385  }
386  else
387  { // update template setting
388  $this->setTemplateSetting($db, $id, $property, $value, $longValue);
389  }
390  }
391  }
392  return true;
393  }
$data
Definition: stats.php:78
$oldTplSettings

References $data, $db, YAWK\template\$id, $oldTplSettings, and $value.

◆ setCssBodyFontFace()

static YAWK\template::setCssBodyFontFace (   $cssTagName,
  $tplSettings 
)
static

set css code for custom fonts (ttf / otf / woff)

Parameters
$cssTagName
$tplSettings
Returns
string

Definition at line 2127 of file template.php.

2128  {
2129  $bodyFontFaceCSS = '';
2130  $fontFamily = $tplSettings["$cssTagName-fontfamily"];
2131  // get font type by cutting off file extension
2132  $fontType = substr($fontFamily, -4);
2133  // check file types
2134  if ($fontType === "-ttf") {
2135  $filename = str_replace("-ttf", ".ttf", $fontFamily);
2136  $bodyFontFaceCSS = "@font-face {
2137  font-family: $fontFamily;
2138  src: url('../../../fonts/$filename');
2139  }";
2140  } elseif ($fontType === "-otf") {
2141  $filename = str_replace("-otf", ".otf", $fontFamily);
2142  $bodyFontFaceCSS = "@font-face {
2143  font-family: $fontFamily;
2144  src: url('../../../fonts/$filename');
2145  }";
2146  } elseif ($fontType === "woff") {
2147  $filename = str_replace("-woff", ".woff", $fontFamily);
2148  $bodyFontFaceCSS = "@font-face {
2149  font-family: $fontFamily;
2150  src: url('../../../fonts/$filename') !important;
2151  }";
2152  }
2153  return $bodyFontFaceCSS;
2154  }

References $filename.

◆ setCssBodyFontSettings()

static YAWK\template::setCssBodyFontSettings (   $cssTagName,
  $tplSettings 
)
static

set body font settings css code

Parameters
$cssTagName
$tplSettings
Returns
string

Definition at line 2220 of file template.php.

2221  {
2222  $fontFamily = $tplSettings["$cssTagName-fontfamily"];
2223  $fontSize = $tplSettings["$cssTagName-size"];
2224  $fontColor = $tplSettings["$cssTagName-fontcolor"];
2225  $fontShadowSize = $tplSettings["$cssTagName-fontshadowsize"];
2226  $fontShadowColor = $tplSettings["$cssTagName-fontshadowcolor"];
2227  $fontWeight = $tplSettings["$cssTagName-fontweight"];
2228  $fontStyle = $tplSettings["$cssTagName-fontstyle"];
2229  $fontTextDecoration = $tplSettings["$cssTagName-textdecoration"];
2230  // check, if it's a google font
2231  if (substr($fontFamily, -6) === "-gfont") {
2232  $googleFont = substr($fontFamily, 0, -6);
2233  $bodyFontCSS = "
2234  font-family: $googleFont !important;
2235  font-size: $fontSize;
2236  color: #$fontColor;
2237  text-shadow: $fontShadowSize #$fontShadowColor;
2238  font-weight: $fontWeight;
2239  font-style: $fontStyle;
2240  text-decoration: $fontTextDecoration;
2241  ";
2242  } else {
2243  $bodyFontCSS = "
2244  font-family: $fontFamily;
2245  font-size: $fontSize;
2246  color: #$fontColor;
2247  text-shadow: $fontShadowSize #$fontShadowColor;
2248  font-weight: $fontWeight;
2249  font-style: $fontStyle;
2250  text-decoration: $fontTextDecoration;
2251  ";
2252  }
2253  return $bodyFontCSS;
2254  }

◆ setCssBodyLinkTags()

static YAWK\template::setCssBodyLinkTags (   $cssTagName,
  $tplSettings 
)
static

set css code for body link styling

Parameters
$cssTagName
$tplSettings
Returns
string

Definition at line 2162 of file template.php.

2163  {
2164  $aLink = $tplSettings["$cssTagName-alink"];
2165  $aVisited = $tplSettings["$cssTagName-avisited"];
2166  $aHover = $tplSettings["$cssTagName-ahover"];
2167  $aWeight = $tplSettings["$cssTagName-linkfontweight"];
2168  $aStyle = $tplSettings["$cssTagName-linkfontstyle"];
2169  $aDecoration = $tplSettings["$cssTagName-linktextdecoration"];
2170  $hoverDecoration = $tplSettings["$cssTagName-hovertextdecoration"];
2171  $bodyLinkTags = "
2172  /* TODO: must be out of body */
2173  a:link {
2174  color: #$aLink;
2175  font-weight: $aWeight;
2176  font-style: $aStyle;
2177  text-decoration: $aDecoration;
2178  }
2179  a:visited {
2180  color: #$aVisited;
2181  }
2182  a:hover {
2183  color: #$aHover;
2184  text-decoration: $hoverDecoration;
2185  }
2186  ";
2187  return $bodyLinkTags;
2188  }

◆ setCssBodySmallFontSettings()

static YAWK\template::setCssBodySmallFontSettings (   $cssTagName,
  $tplSettings 
)
static

set small font settings css code

Parameters
$cssTagName
$tplSettings
Returns
string

Definition at line 2196 of file template.php.

2197  {
2198  $smallColor = $tplSettings["$cssTagName-smallcolor"];
2199  $smallShadowSize = $tplSettings["$cssTagName-smallshadowsize"];
2200  $smallShadowColor = $tplSettings["$cssTagName-smallshadowcolor"];
2201 
2202  $bodySmallTags = "small,
2203  .small
2204  {
2205  font-weight: normal;
2206  line-height: 1;
2207  color: #$smallColor;
2208  text-shadow: $smallShadowSize #$smallShadowColor;
2209  }
2210  ";
2211  return $bodySmallTags;
2212  }

◆ setCssFontSettings()

static YAWK\template::setCssFontSettings (   $cssTagName,
  $tplSettings 
)
static

set font settings css code

Parameters
$cssTagName
$tplSettings
Returns
string

Definition at line 2262 of file template.php.

2263  {
2264  $fontFamily = $tplSettings["$cssTagName-fontfamily"];
2265  $fontSize = $tplSettings["$cssTagName-size"];
2266  $fontColor = $tplSettings["$cssTagName-fontcolor"];
2267  $fontShadowSize = $tplSettings["$cssTagName-fontshadowsize"];
2268  $fontShadowColor = $tplSettings["$cssTagName-fontshadowcolor"];
2269  $fontWeight = $tplSettings["$cssTagName-fontweight"];
2270  $fontStyle = $tplSettings["$cssTagName-fontstyle"];
2271  $fontTextDecoration = $tplSettings["$cssTagName-textdecoration"];
2272  $aLink = $tplSettings["$cssTagName-alink"];
2273  $aVisited = $tplSettings["$cssTagName-avisited"];
2274  $aHover = $tplSettings["$cssTagName-ahover"];
2275  $aWeight = $tplSettings["$cssTagName-linkfontweight"];
2276  $aStyle = $tplSettings["$cssTagName-linkfontstyle"];
2277  $aDecoration = $tplSettings["$cssTagName-linktextdecoration"];
2278  $hoverDecoration = $tplSettings["$cssTagName-hovertextdecoration"];
2279  $smallColor = $tplSettings["$cssTagName-smallcolor"];
2280  $smallShadowSize = $tplSettings["$cssTagName-smallshadowsize"];
2281  $smallShadowColor = $tplSettings["$cssTagName-smallshadowcolor"];
2282 
2283  // get font type by cutting off file extension
2284  $fontType = substr($fontFamily, -4);
2285  // check file types
2286  if ($fontType === "-ttf") {
2287  $filename = str_replace("-ttf", ".ttf", $fontFamily);
2288  $fontCSS = "@font-face {
2289  font-family: $fontFamily;
2290  src: url('../../../fonts/$filename');
2291  }
2292  $cssTagName
2293  {
2294  font-family: $fontFamily !important;
2295  font-size: $fontSize;
2296  color: #$fontColor;
2297  text-shadow: $fontShadowSize #$fontShadowColor;
2298  font-weight: $fontWeight;
2299  font-style: $fontStyle;
2300  text-decoration: $fontTextDecoration;
2301  }
2302  $cssTagName a:link { /* LINK SETTINGS */
2303  color: #$aLink;
2304  font-weight: $aWeight;
2305  font-style: $aStyle;
2306  text-decoration: $aDecoration;
2307  }
2308  $cssTagName a:visited {
2309  color: #$aVisited;
2310  }
2311  $cssTagName a:hover {
2312  color: #$aHover;
2313  text-decoration: $hoverDecoration;
2314  }
2315  $cssTagName small,
2316  .$cssTagName small
2317  {
2318  font-weight: normal;
2319  line-height: 1;
2320  color: #$smallColor;
2321  text-shadow: $smallShadowSize #$smallShadowColor;
2322  }
2323  ";
2324  } elseif ($fontType === "-otf") {
2325  $filename = str_replace("-otf", ".otf", $fontFamily);
2326  $fontCSS = "@font-face {
2327  font-family: $fontFamily;
2328  src: url('../../../fonts/$filename');
2329  }
2330  $cssTagName
2331  {
2332  font-family: $fontFamily !important;
2333  font-size: $fontSize;
2334  color: #$fontColor;
2335  text-shadow: $fontShadowSize #$fontShadowColor;
2336  font-weight: $fontWeight;
2337  font-style: $fontStyle;
2338  text-decoration: $fontTextDecoration;
2339  }
2340  $cssTagName a:link { /* LINK SETTINGS */
2341  color: #$aLink;
2342  font-weight: $aWeight;
2343  font-style: $aStyle;
2344  text-decoration: $aDecoration;
2345  }
2346  $cssTagName a:visited {
2347  color: #$aVisited;
2348  }
2349  $cssTagName a:hover {
2350  color: #$aHover;
2351  text-decoration: $hoverDecoration;
2352  }
2353  $cssTagName small,
2354  .$cssTagName small
2355  {
2356  font-weight: normal;
2357  line-height: 1;
2358  color: #$smallColor;
2359  text-shadow: $smallShadowSize #$smallShadowColor;
2360  }
2361  ";
2362  } elseif ($fontType === "woff") {
2363  $filename = str_replace("-woff", ".woff", $fontFamily);
2364  $fontCSS = "@font-face {
2365  font-family: $fontFamily;
2366  src: url('../../../fonts/$filename') !important;
2367  }
2368  $cssTagName
2369  {
2370  font-family: $fontFamily !important;
2371  font-size: $fontSize;
2372  color: #$fontColor;
2373  text-shadow: $fontShadowSize #$fontShadowColor;
2374  font-weight: $fontWeight;
2375  font-style: $fontStyle;
2376  text-decoration: $fontTextDecoration;
2377  }
2378  $cssTagName a:link { /* LINK SETTINGS */
2379  color: #$aLink;
2380  font-weight: $aWeight;
2381  font-style: $aStyle;
2382  text-decoration: $aDecoration;
2383  }
2384  $cssTagName a:visited {
2385  color: #$aVisited;
2386  }
2387  $cssTagName a:hover {
2388  color: #$aHover;
2389  text-decoration: $hoverDecoration;
2390  }
2391  $cssTagName small,
2392  .$cssTagName small
2393  {
2394  font-weight: normal;
2395  line-height: 1;
2396  color: #$smallColor;
2397  text-shadow: $smallShadowSize #$smallShadowColor;
2398  }
2399  ";
2400  } // check, if it's a google font
2401  elseif (substr($fontFamily, -6) === "-gfont") {
2402  $googleFont = substr($fontFamily, 0, -6);
2403  $fontCSS = "
2404  $cssTagName
2405  {
2406  font-family: $googleFont !important;
2407  font-size: $fontSize;
2408  color: #$fontColor;
2409  text-shadow: $fontShadowSize #$fontShadowColor;
2410  font-weight: $fontWeight;
2411  font-style: $fontStyle;
2412  text-decoration: $fontTextDecoration;
2413  }
2414 
2415  $cssTagName a:link { /* LINK SETTINGS */
2416  color: #$aLink;
2417  font-weight: $aWeight;
2418  font-style: $aStyle;
2419  text-decoration: $aDecoration;
2420  }
2421  $cssTagName a:visited {
2422  color: #$aVisited;
2423  }
2424  $cssTagName a:hover {
2425  color: #$aHover;
2426  text-decoration: $hoverDecoration;
2427  }
2428  $cssTagName small,
2429  .$cssTagName small
2430  {
2431  font-weight: normal;
2432  line-height: 1;
2433  color: #$smallColor;
2434  text-shadow: $smallShadowSize #$smallShadowColor;
2435  }
2436  ";
2437  } else {
2438  $fontCSS = "
2439  $cssTagName
2440  {
2441  font-family: $fontFamily;
2442  font-size: $fontSize;
2443  color: #$fontColor;
2444  text-shadow: $fontShadowSize #$fontShadowColor;
2445  font-weight: $fontWeight;
2446  font-style: $fontStyle;
2447  text-decoration: $fontTextDecoration;
2448  }
2449 
2450  $cssTagName a:link { /* LINK SETTINGS */
2451  color: #$aLink;
2452  font-weight: $aWeight;
2453  font-style: $aStyle;
2454  text-decoration: $aDecoration;
2455  }
2456  $cssTagName a:visited {
2457  color: #$aVisited;
2458  }
2459  $cssTagName a:hover {
2460  color: #$aHover;
2461  text-decoration: $hoverDecoration;
2462  }
2463  $cssTagName small,
2464  .$cssTagName small
2465  {
2466  font-weight: normal;
2467  line-height: 1;
2468  color: #$smallColor;
2469  text-shadow: $smallShadowSize #$smallShadowColor;
2470  }
2471  ";
2472  }
2473  return $fontCSS;
2474  }

References $filename.

◆ setPosition()

static YAWK\template::setPosition (   $db,
  $lang,
  $position,
  $currentpage,
  $user,
  $template 
)
static

set template position and output the correct data depending on position

Parameters
object$dbdatabase
object$userthe current user object
string$positionthe template position
object$templatetemplate object

Definition at line 2736 of file template.php.

2737  {
2738  $main_set = 0;
2739  $globalmenu_set = 0;
2740  // get template setting for given pos
2741  // $setting = self::getTemplateSetting($db, $position, "");
2742  if (empty($setting)) {
2743  // no property
2744  // substr, because css definitions are without -pos (changefix?!)
2745  $position = substr("$position", 0, -4);
2746  // if main, we need to include the content page
2747  if ($position == "main") {
2748  // if user is given to index.php, load userpage
2749  if (isset($_GET['user'])) {
2750  // if var is set, but empty, show all users
2751  if (empty($_GET['user'])) {
2752  echo "<h2>Show all users</h2>";
2754  } else {
2755  // show userpage
2756  echo "<h2>Show Profile of user $_GET[user]</h2>";
2757  }
2758  } // if a blog is requested, load blog by given id
2759  elseif (isset($_GET['blogid'])) {
2760  $blog = new \YAWK\PLUGINS\BLOG\blog();
2761  $blog->limitEntries = $blog->getBlogProperty($db, $_GET['blogid'], "limitEntries");
2762  $blog->getFrontendEntries($db, $_GET['blogid'], '', '', $blog->limitEntries);
2763  $blog->getFooter($db);
2764  $blog->draw();
2765  // in any other case, get content for requested static page
2766  } else {
2767  echo "<div id=\"$position\">";
2768  $currentpage->getContent($db, $lang);
2769  echo "</div>";
2770  $main_set = 1;
2771  }
2772  }
2773 
2774  // if position is globalmenu
2775  if ($position == "globalmenu") {
2776  \YAWK\menu::displayGlobalMenu($db, $user, $template);
2777  $globalmenu_set = 1;
2778  }
2779  // in any other case, simply load a div box onto given position
2780  if (!$globalmenu_set == 1) {
2781  echo "<div id=\"$position\">";
2782  echo \YAWK\widget::loadWidgets($db, $position);
2783  echo "</div>";
2784  }
2785  }
2786  }
$blog
Definition: blog.php:122
static displayGlobalMenu($db, $user, $template)
display the global menu
Definition: menu.php:69
static getUserList($db)
output a list of all users (who have not activated privacy switch)
Definition: user.php:2129
$position[$i]

References $_GET, $blog, $db, $lang, $position, YAWK\menu\displayGlobalMenu(), and YAWK\user\getUserList().

Referenced by YAWK\template\getPositionDivBox().

◆ switchPositionIndicators()

YAWK\template::switchPositionIndicators ( object  $db,
int  $templateID,
int  $status 
)

switch all positions indicators on or off

Parameters
int$templateIDID of the affected template
int$statusvalue to set (0|1)
object$db
Returns
bool true|false

Definition at line 131 of file template.php.

131  : bool
132  {
133  // if template param is not set
134  if (!isset($templateID) || (!is_numeric($templateID))) { // get current active template ID
136  }
137 
138  // if status parameter is not set
139  if (!isset($status) || (!is_numeric($status))) { // turn off is default behaviour
140  $status = 0;
141  }
142 
143  // update position indicator status
144  if ($db->query("UPDATE {template_settings}
145  SET value = '" . $status . "'
146  WHERE property
147  LIKE '%indicator%'
148  AND templateID = '" . $templateID . "'")
149  ) { // all good,
150  return true;
151  } else { // update position indicators failed
152  return false;
153  }
154  }
static getCurrentTemplateId(object $db)
return ID of current (active) template
Definition: template.php:73

References $db, $templateID, and YAWK\template\getCurrentTemplateId().

◆ uploadTemplate()

YAWK\template::uploadTemplate (   $db,
  $postData,
  $postFiles,
  $lang 
)

Upload a template (install / update)

Parameters
object$dbdatabase object
array$postDatadata that has been sent by upload form
array$postFilesuploaded file that has been sent by upload form
Returns
bool true|false

upload .zip file, unpack to tmp folder,

Definition at line 3268 of file template.php.

3269  {
3270  // check if params are set and valid...
3271  if (!isset($postData)
3272  || (empty($postData)
3273  || (!is_array($postData))))
3274  { // post data wrong
3275  return false;
3276  }
3277  if (!isset($postFiles['templateFile'])
3278  || (empty($postFiles['templateFile'])
3279  || (!is_array($postFiles['templateFile']))))
3280  { // post file data wrong
3281  return false;
3282  }
3283 
3284  // prepare (empty) temp directory
3285  $this->emptyTmpFolder();
3286 
3287  // check if tmp folder exists...
3288  if (!is_dir(dirname($this->tmpFolder)))
3289  {
3290  // try to create tmp folder
3291  if (!mkdir($this->tmpFolder))
3292  {
3293  // add syslog: failed to create $this->tmpFolder
3294  return false;
3295  }
3296  }
3297 
3298  // check if template folder is writeable
3299  if (is_writeable(dirname($this->folder)))
3300  {
3301  // check if tmp folder exits
3302  if (is_dir(dirname($this->tmpFolder)))
3303  {
3304  $this->uploadFile = $this->tmpFolder.$postFiles['templateFile']['name'];
3305 
3306  // check for errors
3307  if ($postFiles['templateFile']['error'] !== 0)
3308  { // unknown error - upload failed
3309  sys::setSyslog($db, 48, 2, "failed to upload file - unknown error (".$postFiles['templateFile']['error'].") processing file ".$postFiles['templateFile']['name']."", 0, 0, 0, 0);
3310  // echo \YAWK\alert::draw("warning", $lang['ERROR'], $lang['FILE_UPLOAD_FAILED'], "", 4800);
3311  }
3312  else
3313  { // try to move uploaded file
3314  if (!move_uploaded_file($postFiles['templateFile']['tmp_name'], $this->uploadFile))
3315  { // throw error msg
3316  sys::setSyslog($db, 48, 2, "failed to move upload file $this->uploadFile to folder ".$postFiles['templateFile']['tmp_name']."", 0, 0, 0, 0);
3317  // echo \YAWK\alert::draw("danger", "$lang[ERROR]", "$this->uploadFile - $lang[FILE_UPLOAD_ERROR]","","4800");
3318  }
3319  else
3320  { // file upload seem to be successful...
3321  // check if uploaded file is there
3322  if (is_file($this->uploadFile))
3323  {
3324  // here we could check more things - eg latest file timestamp
3325  // create zip object + extract to tmp folder
3326  $zip = new \ZipArchive;
3327  // open zip archive
3328  $res = $zip->open($this->uploadFile);
3329  // if zip open was successful
3330  if ($res === TRUE)
3331  { // extract zip file
3332  $zip->extractTo($this->tmpFolder);
3333  // close zip file
3334  $zip->close();
3335  }
3336 
3337  // check and read template.ini file - stores all information about the template
3338  if (is_file($this->tmpFolder.'template.ini'))
3339  {
3340  // try to parse ini file into array
3341  if (!$iniFile = parse_ini_file($this->tmpFolder."template.ini"))
3342  { // error: unable to parse ini file
3343  sys::setSyslog($db, 48, 2, "failed to parse ini file ".$this->tmpFolder."template.ini ", 0, 0, 0, 0);
3344  return false;
3345  }
3346  }
3347  else
3348  { // error: ini file not there
3349  sys::setSyslog($db, 48, 2, "failed to parse ini file ".$this->tmpFolder."template.ini - file not found", 0, 0, 0, 0);
3350  return false;
3351  }
3352 
3353  // set target path
3354  $this->targetPath = $iniFile['TARGET_PATH'];
3355  // set subfolder
3356  $this->subFolder = $iniFile['SUBFOLDER']."/";
3357 
3358  // read assets.json into array
3359  if (is_file($this->tmpFolder.$this->subFolder.'assets.json'))
3360  { // read and decode json file into array
3361  $assets = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'assets.json'), true);
3362  }
3363  else
3364  { // assets.json not found
3365  $assets = '';
3366  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."assets.json - file not found", 0, 0, 0, 0);
3367  }
3368 
3369  // read template settings into array
3370  if (is_file($this->tmpFolder.$this->subFolder.'template_settings.json'))
3371  { // read and decode json file into array
3372  $templateSettings = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'template_settings.json'), true);
3373  }
3374  else
3375  { // template_settings.json not found
3376  $templateSettings = '';
3377  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."template_settings.json - file not found", 0, 0, 0, 0);
3378  }
3379 
3380  // read template_settings_types into array
3381  if (is_file($this->tmpFolder.$this->subFolder.'template_settings_types.json'))
3382  { // read and decode json into array
3383  $templateSettingsTypes = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'template_settings_types.json'), true);
3384  }
3385  else
3386  { // template_settings_types json file not found
3387  $templateSettingsTypes = '';
3388  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."template_settings_types.json - file not found", 0, 0, 0, 0);
3389  }
3390 
3391  // read templates.json into array
3392  if (is_file($this->tmpFolder.$this->subFolder.'templates.json'))
3393  { // read and decode json into array
3394  $templates = json_decode(file_get_contents($this->tmpFolder.$this->subFolder.'templates.json'), true);
3395  }
3396  else
3397  { // templates.json file not found
3398  $templates = '';
3399  sys::setSyslog($db, 48, 1, "failed to get ".$this->tmpFolder.$this->subFolder."templates.json - file not found", 0, 0, 0, 0);
3400  }
3401 
3402  // check if template with same name exists
3403  if ($this->checkIfTemplateAlreadyExists($db, $iniFile['NAME']) === true)
3404  {
3405  // die('template already exists');
3406 
3407  // TEMPLATE ALREADY EXISTS - OVERWRITE IT!
3408  // .) check, which ID got this template?
3409  // .) manipulate assets + template_settings arrays
3410  // (means: change template ID to the one of the existing template that was found)
3411  // .) UPDATE data of these arrays into related db tables
3412  // .) delete json files from tmp folder (unwanted in target)
3413  // .) xcopy files and overwrite template folder
3414  // .) empty tmp directory
3415  // -fin- template updated - if all went good
3416 
3417  // get ID of installed template
3418  $this->id = self::getTemplateIdByName($db, $iniFile['NAME']);
3419 
3420  // update ID in templates array
3421  $templates['id'] = $this->id;
3422 
3423  // update ID in assets array
3424  foreach ($assets as &$asset)
3425  {
3426  $asset['templateID'] = $this->id;
3427  }
3428 
3429  // update ID in template_settings array
3430  foreach ($templateSettings as &$templateSetting)
3431  {
3432  $templateSetting['templateID'] = $this->id;
3433  }
3434 
3435  if ($db->query("UPDATE {templates}
3436  SET id = '".$this->id."',
3437  active = 1,
3438  name = '".$iniFile['NAME']."',
3439  positions ='outerTop:outerLeft:outerRight:intro:globalmenu:top:leftMenu:mainTop:mainTopLeft:mainTopCenter:mainTopRight:main:mainBottom:mainBottomLeft:mainBottomCenter:mainBottomRight:mainFooter:mainFooterLeft:mainFooterCenter:mainFooterRight:rightMenu:bottom:footer:hiddentoolbar:debug:outerBottom',
3440  description = '".$iniFile['DESCRIPTION']."',
3441  modifyDate = '".$iniFile['DATE']."',
3442  author = '".$iniFile['AUTHOR']."',
3443  authorUrl = '".$iniFile['AUTHOR_URL']."',
3444  weblink = '".$iniFile['WEBLINK']."',
3445  subAuthor = '".$iniFile['SUB_AUTHOR']."',
3446  subAuthorUrl = '".$iniFile['SUB_AUTHOR_URL']."',
3447  version = '".$iniFile['VERSION']."',
3448  framework = '".$iniFile['FRAMEWORK']."',
3449  license = '".$iniFile['LICENSE']."'
3450  WHERE name = '".$iniFile['NAME']."'"))
3451  {
3452  // success: updated templates database
3453  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - templates db updated", 0, 0, 0, 0);
3454  }
3455  else
3456  { // error: failed to update templates db
3457  sys::setSyslog($db, 47, 0, "failed to update template $iniFile[NAME] - templates db NOT updated", 0, 0, 0, 0);
3458  }
3459 
3460  // update assets database
3461  foreach ($assets as $asset)
3462  {
3463  if ($db->query("UPDATE {assets}
3464  SET templateID = '".$this->id."',
3465  type = '".$asset['type']."',
3466  sortation = '".$asset['sortation']."',
3467  asset = '".$asset['asset']."',
3468  link = '".$asset['link']."'
3469  WHERE link = '".$asset['link']."' AND templateID = '".$iniFile['ID']."'"))
3470  {
3471  // success: updated templates database
3472  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - assets db updated", 0, 0, 0, 0);
3473  }
3474  else
3475  { // error: failed to update templates db
3476  sys::setSyslog($db, 47, 0, "failed to update template $iniFile[NAME] - assets db NOT updated", 0, 0, 0, 0);
3477  }
3478  // process asset data
3479  }
3480 
3481  // update template_settings database
3482 
3483  foreach ($templateSettings as $templateSetting)
3484  {
3485  if ($db->query("UPDATE {template_settings}
3486  SET templateID = '".$this->id."',
3487  property = '".$templateSetting['property']."',
3488  value = '".$templateSetting['value']."',
3489  valueDefault = '".$templateSetting['valueDefault']."',
3490  longValue = '".$templateSetting['longValue']."',
3491  type = '".$templateSetting['type']."',
3492  activated = '".$templateSetting['activated']."',
3493  sort = '".$templateSetting['sort']."',
3494  label = '".$templateSetting['label']."',
3495  fieldClass = '".$templateSetting['fieldClass']."',
3496  fieldType = '".$templateSetting['fieldType']."',
3497  options = '".$templateSetting['options']."',
3498  placeholder = '".$templateSetting['placeholder']."',
3499  description = '".$templateSetting['description']."',
3500  icon = '".$templateSetting['icon']."',
3501  heading = '".$templateSetting['heading']."',
3502  subtext = '".$templateSetting['subtext']."'
3503  WHERE property = '".$templateSetting['property']."' AND templateID = '".$iniFile['ID']."'"))
3504  {
3505  // success: updated templates database
3506  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - template_settings db updated", 0, 0, 0, 0);
3507  }
3508  else
3509  { // error: failed to update templates db
3510  sys::setSyslog($db, 47, 0, "failed to update property $templateSetting[property] of template $iniFile[NAME] - template_settings db NOT updated", 0, 0, 0, 0);
3511  }
3512  }
3513 
3514  // update template settings types
3515  foreach ($templateSettingsTypes as $templateSettingsType)
3516  {
3517  if ($db->query("UPDATE {template_settings_types}
3518  SET type = '".$templateSettingsType['type']."'
3519  WHERE type = '".$templateSettingsType['type']."'"))
3520  {
3521  // success: updated templates database
3522  // \YAWK\sys::setSyslog($db, 45, 0, "template $iniFile[NAME] - template_settings db updated", 0, 0, 0, 0);
3523  }
3524  else
3525  { // error: failed to update templates db
3526  sys::setSyslog($db, 47, 0, "failed to update type $templateSettingsType[type] - template_settings_types db NOT updated", 0, 0, 0, 0);
3527  }
3528  }
3529 
3530  // delete unwanted json files - they are not needed anymore
3531  if (!unlink ($this->tmpFolder.$this->subFolder."assets.json"))
3532  {
3533  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."assets.json", 0, 0, 0, 0);
3534  }
3535  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings.json"))
3536  {
3537  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings.json", 0, 0, 0, 0);
3538  }
3539  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings_types.json"))
3540  {
3541  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings_types.json", 0, 0, 0, 0);
3542  }
3543  if (!unlink ($this->tmpFolder.$this->subFolder."templates.json"))
3544  {
3545  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."templates.json", 0, 0, 0, 0);
3546  }
3547 
3548  // copy template folder
3549  sys::xcopy($this->tmpFolder.$this->subFolder, $this->folder.$this->subFolder);
3550 
3551  // remove tmp folder
3552  if (!\YAWK\filemanager::recursiveRemoveDirectory($this->tmpFolder))
3553  { // failed to remove tmp folder
3554  sys::setSyslog($db, 47, 0, "failed to remove tmp folder $this->tmpFolder", 0, 0, 0, 0);
3555  }
3556 
3557  // create a fresh, empty tmp folder
3558  mkdir($this->tmpFolder);
3559  return true;
3560  }
3561  else
3562  {
3563  // TEMPLATE DOES NOT EXIST YET - INSTALL IT!
3564  // 1.) add template to templates database
3565  // 2.) retrieve ID of this new added template
3566  // 3.) manipulate assets + template_settings arrays
3567  // (means: change template ID to the new created one)
3568  //
3569  // 4.) INSERT data of these arrays into related db tables
3570  // 5.) delete json files from tmp folder (unwanted in target)
3571  // 6.) delete ini file (unwanted in target)
3572  // 7.) next step - xcopy files
3573  // -fin- template installed - if all went good
3574  // die('template does not exist');
3575 
3576  // step 1.) add template to templates database
3577  if ($res = $db->query("INSERT INTO {templates} (active, name, positions, description, releaseDate, modifyDate, author, authorUrl, weblink, subAuthor, subAuthorUrl, version, framework, license)
3578  VALUES ('1',
3579  '".$iniFile['NAME']."',
3580  'outerTop:outerLeft:outerRight:intro:globalmenu:top:leftMenu:mainTop:mainTopLeft:mainTopCenter:mainTopRight:main:mainBottom:mainBottomLeft:mainBottomCenter:mainBottomRight:mainFooter:mainFooterLeft:mainFooterCenter:mainFooterRight:rightMenu:bottom:footer:hiddentoolbar:debug:outerBottom',
3581  '".$iniFile['DESCRIPTION']."',
3582  '".$iniFile['DATE']."',
3583  '".$iniFile['DATE']."',
3584  '".$iniFile['AUTHOR']."',
3585  '".$iniFile['AUTHOR_URL']."',
3586  '".$iniFile['WEBLINK']."',
3587  '".$iniFile['SUB_AUTHOR']."',
3588  '".$iniFile['SUB_AUTHOR_URL']."',
3589  '".$iniFile['VERSION']."',
3590  '".$iniFile['FRAMEWORK']."',
3591  '".$iniFile['LICENSE']."')"))
3592  {
3593 
3594  // 2.) retrieve ID of this new added template
3595  $this->id = self::getTemplateIdByName($db, $iniFile['NAME']);
3596 
3597  // add assets to database
3598  foreach ($assets as $asset)
3599  {
3600  $db->query("INSERT INTO {assets} (templateID, type, sortation, asset, link)
3601  VALUES (
3602  '".$this->id."',
3603  '".$asset['type']."',
3604  '".$asset['sortation']."',
3605  '".$asset['asset']."',
3606  '".$asset['link']."'
3607  )");
3608  }
3609 
3610  // add template settings to database
3611  foreach ($templateSettings as $templateSetting)
3612  {
3613  $db->query("INSERT INTO {template_settings}
3614  (templateID, property, value, valueDefault, longValue, type, activated, sort, label, fieldClass, fieldType, options, placeholder, description, icon, heading, subtext)
3615  VALUES ('".$this->id."',
3616  '".$templateSetting['property']."',
3617  '".$templateSetting['value']."',
3618  '".$templateSetting['valueDefault']."',
3619  '".$templateSetting['longValue']."',
3620  '".$templateSetting['type']."',
3621  '".$templateSetting['activated']."',
3622  '".$templateSetting['sort']."',
3623  '".$templateSetting['label']."',
3624  '".$templateSetting['fieldClass']."',
3625  '".$templateSetting['fieldType']."',
3626  '".$templateSetting['options']."',
3627  '".$templateSetting['placeholder']."',
3628  '".$templateSetting['description']."',
3629  '".$templateSetting['icon']."',
3630  '".$templateSetting['heading']."',
3631  '".$templateSetting['subtext']."')");
3632  }
3633 
3634  // delete unwanted json files - they are not needed anymore
3635  if (!unlink ($this->tmpFolder.$this->subFolder."assets.json"))
3636  {
3637  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."assets.json", 0, 0, 0, 0);
3638  }
3639  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings.json"))
3640  {
3641  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings.json", 0, 0, 0, 0);
3642  }
3643  if (!unlink ($this->tmpFolder.$this->subFolder."template_settings_types.json"))
3644  {
3645  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."template_settings_types.json", 0, 0, 0, 0);
3646  }
3647  if (!unlink ($this->tmpFolder.$this->subFolder."templates.json"))
3648  {
3649  sys::setSyslog($db, 47, 0, "failed to delete ".$this->tmpFolder.$this->subFolder."templates.json", 0, 0, 0, 0);
3650  }
3651 
3652  // copy template folder
3653  sys::xcopy($this->tmpFolder.$this->subFolder, $this->folder.$this->subFolder);
3654 
3655  // remove tmp folder
3656  if (!\YAWK\filemanager::recursiveRemoveDirectory($this->tmpFolder))
3657  { // failed to remove tmp folder
3658  sys::setSyslog($db, 47, 0, "failed to remove tmp folder $this->tmpFolder", 0, 0, 0, 0);
3659  }
3660 
3661  // create a fresh, empty tmp folder
3662  mkdir($this->tmpFolder);
3663 
3664  // success: updated templates database
3665  sys::setSyslog($db, 45, 0, "added template <b>$iniFile[NAME] ID: ".$this->id."</b> to templates db", 0, 0, 0, 0);
3666  return true;
3667 
3668  }
3669  else
3670  { // error: failed to insert new template into db
3671  sys::setSyslog($db, 47, 0, "failed to insert new template: $iniFile[NAME] - templates db NOT updated", 0, 0, 0, 0);
3672  }
3673 
3674  }
3675 
3676  // xcopy files
3677  // recursive delete tmp folder
3678 
3679  // throw success message
3680  sys::setSyslog($db, 46, 3, "uploaded template package $this->uploadFile successfully", 0, 0, 0, 0);
3681  }
3682  else
3683  { // failed to check uploaded file - file not found
3684  sys::setSyslog($db, 48, 1, "failed to check uploaded file upload file: $this->uploadFile not found", 0, 0, 0, 0);
3685  }
3686  }
3687  }
3688  }
3689  else
3690  { // tmp folder does not exist
3691  sys::setSyslog($db, 48, 1, "failed to uploaded tempalte: ../system/templates/tmp/ does not exist or is not accessable", 0, 0, 0, 0);
3692  return false;
3693  }
3694  }
3695  else
3696  { // tmp folder is not writeable
3697  sys::setSyslog($db, 48, 1, "failed to uploaded template: $this->folder is not writeable", 0, 0, 0, 0);
3698  return false;
3699  }
3700 
3701  // if something else went wrong
3702  return false;
3703  }
checkIfTemplateAlreadyExists(object $db, string $name)
Check if a template with given name already exists, return true or false.
Definition: template.php:95

References $db, YAWK\template\$id, $res, $templateSettings, YAWK\template\checkIfTemplateAlreadyExists(), YAWK\template\emptyTmpFolder(), YAWK\filemanager\recursiveRemoveDirectory(), and YAWK\sys\xcopy().

Member Data Documentation

◆ $active

YAWK\template::$active
  • Parameters
    int0|1 is this template active?

Definition at line 22 of file template.php.

◆ $author

YAWK\template::$author
  • Parameters
    stringauthor of this template

Definition at line 44 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $authorUrl

YAWK\template::$authorUrl
  • Parameters
    stringauthor's url

Definition at line 46 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $bootstrapVersion

YAWK\template::$bootstrapVersion
  • Parameters
    stringthe current loaded Bootstrap version

Definition at line 58 of file template.php.

◆ $config

YAWK\template::$config
  • Parameters
    arraydb config array

Definition at line 28 of file template.php.

◆ $description

YAWK\template::$description
  • Parameters
    stringtemplate description

Definition at line 40 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $folder

YAWK\template::$folder = '../system/templates/'
  • Parameters
    stringtemplate folder (root path of all templates)

Definition at line 30 of file template.php.

Referenced by YAWK\template\downloadTemplate(), and YAWK\template\getFontsFromFolder().

◆ $framework

YAWK\template::$framework = 'bootstrap4'
  • Parameters
    stringrequired framework for this template

Definition at line 60 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $id

◆ $license

YAWK\template::$license
  • Parameters
    stringtemplate's license

Definition at line 62 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $modifyDate

YAWK\template::$modifyDate
  • Parameters
    stringdatetime when this template was modified

Definition at line 54 of file template.php.

◆ $name

YAWK\template::$name
  • Parameters
    stringtemplate name

Definition at line 24 of file template.php.

Referenced by YAWK\template\checkIfTemplateAlreadyExists(), and YAWK\template\downloadTemplate().

◆ $newId

YAWK\template::$newId
  • Parameters
    intnew TPL ID (latest template)

Definition at line 20 of file template.php.

◆ $newTplName

YAWK\template::$newTplName
  • Parameters
    stringnew template name

Definition at line 26 of file template.php.

◆ $positions

YAWK\template::$positions
  • Parameters
    stringpositions as string

Definition at line 38 of file template.php.

Referenced by YAWK\template\getPositionDivBox().

◆ $releaseDate

YAWK\template::$releaseDate
  • Parameters
    stringdatetime when this template was released

Definition at line 42 of file template.php.

◆ $selectedTemplate

int YAWK\template::$selectedTemplate
  • Parameters
    intwhich template is currently set to active?

Definition at line 64 of file template.php.

◆ $subAuthor

YAWK\template::$subAuthor = ''
  • Parameters
    stringsub-author who has modified the template

Definition at line 50 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $subAuthorUrl

YAWK\template::$subAuthorUrl = ''
  • Parameters
    stringsub-author's url

Definition at line 52 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $subFolder

YAWK\template::$subFolder
  • Parameters
    stringtemplate sub folder (template name, eg. ../system/templates/SUBFOLDER

Definition at line 36 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $tmpFolder

YAWK\template::$tmpFolder = '../system/templates/tmp/'
  • Parameters
    stringtemplate tmp folder (where uploads will be unpacked)

Definition at line 32 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $ttfPath

string YAWK\template::$ttfPath = '../system/fonts/'
  • Parameters
    stringpath to custom fonts (ttf|otf|woff)

Definition at line 66 of file template.php.

◆ $uploadFile

YAWK\template::$uploadFile = ''
  • Parameters
    stringupload file (including complete path)

Definition at line 34 of file template.php.

◆ $version

YAWK\template::$version
  • Parameters
    stringtemplate's version number

Definition at line 56 of file template.php.

Referenced by YAWK\template\downloadTemplate().

◆ $weblink

YAWK\template::$weblink
  • Parameters
    stringweblink to this template

Definition at line 48 of file template.php.

Referenced by YAWK\template\downloadTemplate().


The documentation for this class was generated from the following file: