<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class Stories_Form_Admin_Settings_Global extends Engine_Form
{

	public function init()
	{

		$settings = Engine_Api::_()->getApi('settings', 'core');
		$this->setTitle('Global Settings')
			->setDescription('These settings affect all members in your community.');

		$supportTicket = '<a href="https://socialengine.com/store/clientarea.php?action=products&module=licensing" target="_blank">click here</a>';
		$descriptionLicense = sprintf('Enter your license key that is provided to you when you purchased this plugin. If you do not know your license key, please %s. (Key Format: SEPHP-XXXXXXXXXXXXXXXX)',$supportTicket);

		$this->addElement('Text', 'stories_licensekey', array(
			'label' => 'License Key',
			'description' => $descriptionLicense,
			'required' => true,
			'allowEmpty' => false,
			'validators' => array(
				array('NotEmpty', true),
			),
			'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('stories.licensekey'),
		));
		$this->getElement('stories_licensekey')->getDecorator('Description')->setOptions(array('placement' => 'PREPEND', 'escape' => false));

		if (engine_in_array($_SERVER['SERVER_NAME'], ['localhost', '127.0.0.1'])) {
			$this->addElement('Text', 'domain_name', array(
				'label' => 'Domain Name',
				'required' => true,
				'allowEmpty' => false,
				'validators' => array(
					array('NotEmpty', true),
				),
				'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('domain.name'),
			));
		}

		if (Engine_Api::_()->getApi('settings', 'core')->getSetting('stories.pluginactivated')) {

			$this->addElement('Text', "stories_videouplimit", array(
				'label' => 'Video Size Limit',
				'description' => "Enter the size of video you want your users to upload on your website in MB.",
				'allowEmpty' => false,
				'required' => true,
				'value' => $settings->getSetting('stories.videouplimit', '10'),
			));

			$this->addElement('Text', "stories_dayslimit", array(
				'label' => 'Stories Duration',
				'description' => "Enter the duration (in days) for which Stories uploaded by the members will be visible on your website.",
				'allowEmpty' => false,
				'required' => true,
				'validators' => array(
					array('Int', true),
					array('GreaterThan', true, array(0)),
				),
				'value' => $settings->getSetting('stories.dayslimit', '1'),
			));

			$this->addElement('Text', "stories_storyviewtime", array(
				'label' => 'Delay Time for Photos in Slideshow',
				'description' => "Enter the delay time (in seconds) for photos to be shown in the story slideshow. (Note: Videos will play according to the video length, so this setting will not be applicable on videos.",
				'allowEmpty' => false,
				'required' => true,
				'value' => $settings->getSetting('stories.storyviewtime', '5'),
			));

			$this->addElement('Text', 'video_ffmpeg_path', array(
				'label' => 'Path to FFMPEG',
				'description' => 'Please enter the full path to your FFMPEG installation. (Environment variables are not present)',
				'value' => Engine_Api::_()->getApi('settings', 'core')->getSetting('video.ffmpeg.path', ''),
			));

			// Add submit button
			$this->addElement('Button', 'submit', array(
				'label' => 'Save Changes',
				'type' => 'submit',
				'ignore' => true
			));
		} else {
			//Add submit button
			$this->addElement('Button', 'submit', array(
					'label' => 'Activate your plugin',
					'type' => 'submit',
					'ignore' => true
			));
		}
	}
}
