예제 #1
0
 /**
  * Gets the preview for a video
  * @param string $id YouTube ID or url
  * @return string
  * @uses getId()
  */
 public static function getPreview($id)
 {
     if (isUrl($id)) {
         $id = self::getId($id);
     }
     return sprintf('http://img.youtube.com/vi/%s/0.jpg', $id);
 }
예제 #2
0
function cleanVar($var)
{
    if (!isUrl($var)) {
        $var = "NONE";
    }
    return $var;
}
예제 #3
0
 private function setUrl()
 {
     if (!isUrl($this->input['url'])) {
         $this->errorOutput(strtoupper('illegal_url'));
     }
     $this->url = trim($this->input['url']);
 }
예제 #4
0
 private function setUrl()
 {
     if (!isUrl("http://" . $this->input['url']) && !isUrl("https://" . $this->input['url'])) {
         $this->errorOutput(strtoupper('illegal_url'));
     }
     $this->url = trim($this->input['url']);
     $this->ip = gethostbyname($this->input['url']);
 }
예제 #5
0
 public function url(string $url = '') : Ajax
 {
     // Veri bir url içermiyorsa siteUrl yöntemi ile url'ye dönüştürülür.
     if (!isUrl($url)) {
         $url = siteUrl($url);
     }
     $this->sets['url'] = "\turl:\"{$url}\"," . EOL;
     return $this;
 }
예제 #6
0
 /**
  * Internal function to render a thumbnail
  * @param string $target Target file
  * @return \Cake\Network\Response|null|void
  */
 protected function _render($target)
 {
     if (isUrl($target)) {
         return $this->redirect($target);
     }
     $this->autoRender = false;
     //Renders the thumbnail
     header(sprintf('Content-type: %s', mime_content_type($target)));
     readfile($target);
     exit;
 }
예제 #7
0
 public function url($url = '')
 {
     if (!is_string($url)) {
         Error::set(lang('Error', 'stringParameter', '1.(url)'));
         return $this;
     }
     // Veri bir url içermiyorsa siteUrl yöntemi ile url'ye dönüştürülür.
     if (!isUrl($url)) {
         $url = siteUrl($url);
     }
     $this->sets['url'] = "\turl:\"{$url}\"," . eol();
     return $this;
 }
예제 #8
0
/**
 * Includes a file in template. Handy for adding html files to tpl files
 *
 * @param array $Params The parameters passed into the function.
 * The parameters that can be passed to this function are as follows.
 * - <b>name</b>: The name of the file.
 * @param Smarty $Smarty The smarty object rendering the template.
 * @return string The rendered asset.
 */
function smarty_function_include_file($Params, &$Smarty)
{
    $Name = ltrim(val('name', $Params), '/');
    if (strpos($Name, '..') !== false) {
        return '<!-- Error, moving up directory path not allowed -->';
    }
    if (isUrl($Name)) {
        return '<!-- Error, urls are not allowed -->';
    }
    $filename = rtrim($Smarty->template_dir, '/') . '/' . $Name;
    if (!file_exists($filename)) {
        return '<!-- Error, file does not exist -->';
    }
    return file_get_contents($filename);
}
예제 #9
0
 public function do(string $email = NULL, string $returnLinkPath = NULL) : bool
 {
     $email = Properties::$parameters['email'] ?? $email;
     $returnLinkPath = Properties::$parameters['returnLink'] ?? $returnLinkPath;
     Properties::$parameters = [];
     // ------------------------------------------------------------------------------
     // Settings
     // ------------------------------------------------------------------------------
     $tableName = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['table'];
     $senderInfo = INDIVIDUALSTRUCTURES_USER_CONFIG['emailSenderInfo'];
     $getColumns = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['columns'];
     $usernameColumn = $getColumns['username'];
     $passwordColumn = $getColumns['password'];
     $emailColumn = $getColumns['email'];
     // ------------------------------------------------------------------------------
     if (!empty($emailColumn)) {
         DB::where($emailColumn, $email);
     } else {
         DB::where($usernameColumn, $email);
     }
     $row = DB::get($tableName)->row();
     if (isset($row->{$usernameColumn})) {
         if (!isUrl($returnLinkPath)) {
             $returnLinkPath = siteUrl($returnLinkPath);
         }
         $encodeType = INDIVIDUALSTRUCTURES_USER_CONFIG['encode'];
         $newPassword = Encode::create(10);
         $encodePassword = !empty($encodeType) ? Encode::type($newPassword, $encodeType) : $newPassword;
         $templateData = array('usernameColumn' => $row->{$usernameColumn}, 'newPassword' => $newPassword, 'returnLinkPath' => $returnLinkPath);
         $message = Import::template('UserEmail/ForgotPassword', $templateData, true);
         Email::sender($senderInfo['mail'], $senderInfo['name'])->receiver($email, $email)->subject(lang('IndividualStructures', 'user:newYourPassword'))->content($message);
         if (Email::send()) {
             if (!empty($emailColumn)) {
                 DB::where($emailColumn, $email);
             } else {
                 DB::where($usernameColumn, $email);
             }
             if (DB::update($tableName, [$passwordColumn => $encodePassword])) {
                 return $this->success = lang('IndividualStructures', 'user:forgotPasswordSuccess');
             }
             return !($this->error = lang('Database', 'updateError'));
         } else {
             return !($this->error = lang('IndividualStructures', 'user:emailError'));
         }
     } else {
         return !($this->error = lang('IndividualStructures', 'user:forgotPasswordError'));
     }
 }
예제 #10
0
 /**
  * Gets the image preview (virtual field)
  * @return string|null
  * @uses MeTools\Utility\Youtube::getId()
  * @uses MeTools\Utility\Youtube::getPreview()
  */
 protected function _getPreview()
 {
     if (empty($this->_properties['text'])) {
         return null;
     }
     //Checks for the first image in the text
     preg_match('#<\\s*img [^\\>]*src\\s*=\\s*(["\'])(.*?)\\1#im', $this->_properties['text'], $matches);
     if (!empty($matches[2])) {
         return Router::url($matches[2], true);
     }
     //Checks for a YouTube video and its preview
     preg_match('/\\[youtube](.+?)\\[\\/youtube]/', $this->_properties['text'], $matches);
     if (!empty($matches[1])) {
         return Youtube::getPreview(isUrl($matches[1]) ? Youtube::getId($matches[1]) : $matches[1]);
     }
     return null;
 }
예제 #11
0
function redirect(string $url, int $time = 0, array $data = [], bool $exit = true)
{
    if (!isUrl($url)) {
        $url = siteUrl($url);
    }
    if (!empty($data)) {
        foreach ($data as $k => $v) {
            Session::insert('redirect:' . $k, $v);
        }
    }
    if ($time > 0) {
        sleep($time);
    }
    header("Location: {$url}", true);
    if ($exit === true) {
        exit;
    }
}
예제 #12
0
 /**
  * Construct.
  * It sets the origin file.
  *
  * If the origin is relative, it will be relative to  `APP/webroot/img`.
  * @param string $origin Origin file
  * @return \Thumbs\Utility\ThumbCreator
  * @throws InternalErrorException
  * @uses $height
  * @uses $origin
  * @uses $width
  * @uses _downloadTemporary()
  */
 public function __construct($origin)
 {
     //If the origin is a remote file, downloads as temporary file
     if (isUrl($origin)) {
         $origin = $this->_downloadTemporary($origin);
         //If it's a local file, can be relative to `APP/webroot/img/`
     } elseif (!Folder::isAbsolute($origin)) {
         $origin = WWW_ROOT . 'img' . DS . $origin;
     }
     //Checks if is readable
     if (!is_readable($origin)) {
         throw new NotFoundException(__d('thumbs', 'File or directory {0} not readable', $origin));
     }
     //Checks if has a valid extension
     if (!in_array(extension($origin), ['gif', 'jpg', 'jpeg', 'png'])) {
         throw new InternalErrorException(__d('thumbs', 'The file {0} is not an image', $origin));
     }
     //Sets path, width and height of the origin file
     $this->origin = $origin;
     $this->width = getimagesize($origin)[0];
     $this->height = getimagesize($origin)[1];
     return $this;
 }
예제 #13
0
 public function use(...$styles)
 {
     $str = '';
     $eol = EOL;
     $args = $this->_parameters($styles, 'styles');
     $lastParam = $args->lastParam;
     $arguments = $args->arguments;
     $links = $args->cdnLinks;
     foreach ($arguments as $style) {
         if (is_array($style)) {
             $style = '';
         }
         $styleFile = STYLES_DIR . suffix($style, ".css");
         if (!is_file($styleFile)) {
             $styleFile = EXTERNAL_STYLES_DIR . suffix($style, ".css");
         }
         if (!in_array("style_" . $style, Properties::$isImport)) {
             if (is_file($styleFile)) {
                 $str .= '<link href="' . baseUrl($styleFile) . '" rel="stylesheet" type="text/css" />' . $eol;
             } elseif (isUrl($style) && extension($style) === 'css') {
                 $str .= '<link href="' . $style . '" rel="stylesheet" type="text/css" />' . $eol;
             } elseif (isset($links[strtolower($style)])) {
                 $str .= '<link href="' . $links[strtolower($style)] . '" rel="stylesheet" type="text/css" />' . $eol;
             }
             Properties::$isImport[] = "style_" . $style;
         }
     }
     if (!empty($str)) {
         if ($lastParam === true) {
             return $str;
         } else {
             echo $str;
         }
     } else {
         return false;
     }
 }
예제 #14
0
 public function use(...$scripts)
 {
     $str = '';
     $eol = EOL;
     $args = $this->_parameters($scripts, 'scripts');
     $lastParam = $args->lastParam;
     $arguments = $args->arguments;
     $links = $args->cdnLinks;
     foreach ($arguments as $script) {
         if (is_array($script)) {
             $script = '';
         }
         $scriptFile = SCRIPTS_DIR . suffix($script, ".js");
         if (!is_file($scriptFile)) {
             $scriptFile = EXTERNAL_SCRIPTS_DIR . suffix($script, ".js");
         }
         if (!in_array("script_" . $script, Properties::$isImport)) {
             if (is_file($scriptFile)) {
                 $str .= '<script type="text/javascript" src="' . baseUrl($scriptFile) . '"></script>' . $eol;
             } elseif (isUrl($script) && extension($script) === 'js') {
                 $str .= '<script type="text/javascript" src="' . $script . '"></script>' . $eol;
             } elseif (isset($links[strtolower($script)])) {
                 $str .= '<script type="text/javascript" src="' . $links[strtolower($script)] . '"></script>' . $eol;
             }
             Properties::$isImport[] = "script_" . $script;
         }
     }
     if (!empty($str)) {
         if ($lastParam === true) {
             return $str;
         } else {
             echo $str;
         }
     } else {
         return false;
     }
 }
예제 #15
0
 /**
  *
  */
 public function renderMaster()
 {
     // Build the master view if necessary
     if (in_array($this->_DeliveryType, array(DELIVERY_TYPE_ALL))) {
         $this->MasterView = $this->masterView();
         // Only get css & ui components if this is NOT a syndication request
         if ($this->SyndicationMethod == SYNDICATION_NONE && is_object($this->Head)) {
             $CssAnchors = AssetModel::getAnchors();
             $this->EventArguments['CssFiles'] =& $this->_CssFiles;
             $this->fireEvent('BeforeAddCss');
             $ETag = AssetModel::eTag();
             $CombineAssets = c('Garden.CombineAssets');
             $ThemeType = isMobile() ? 'mobile' : 'desktop';
             // And now search for/add all css files.
             foreach ($this->_CssFiles as $CssInfo) {
                 $CssFile = $CssInfo['FileName'];
                 if (!array_key_exists('Options', $CssInfo) || !is_array($CssInfo['Options'])) {
                     $CssInfo['Options'] = array();
                 }
                 $Options =& $CssInfo['Options'];
                 // style.css and admin.css deserve some custom processing.
                 if (in_array($CssFile, $CssAnchors)) {
                     if (!$CombineAssets) {
                         // Grab all of the css files from the asset model.
                         $AssetModel = new AssetModel();
                         $CssFiles = $AssetModel->getCssFiles($ThemeType, ucfirst(substr($CssFile, 0, -4)), $ETag);
                         foreach ($CssFiles as $Info) {
                             $this->Head->addCss($Info[1], 'all', true, $CssInfo);
                         }
                     } else {
                         $Basename = substr($CssFile, 0, -4);
                         $this->Head->addCss(url("/asset/css/{$ThemeType}/{$Basename}-{$ETag}.css", '//'), 'all', false, $CssInfo['Options']);
                     }
                     continue;
                 }
                 $AppFolder = $CssInfo['AppFolder'];
                 $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder;
                 $Search = AssetModel::CssPath($CssFile, $LookupFolder, $ThemeType);
                 if (!$Search) {
                     continue;
                 }
                 list($Path, $UrlPath) = $Search;
                 if (isUrl($Path)) {
                     $this->Head->AddCss($Path, 'all', val('AddVersion', $Options, true), $Options);
                     continue;
                 } else {
                     // Check to see if there is a CSS cacher.
                     $CssCacher = Gdn::factory('CssCacher');
                     if (!is_null($CssCacher)) {
                         $Path = $CssCacher->get($Path, $AppFolder);
                     }
                     if ($Path !== false) {
                         $Path = substr($Path, strlen(PATH_ROOT));
                         $Path = str_replace(DS, '/', $Path);
                         $this->Head->addCss($Path, 'all', true, $Options);
                     }
                 }
             }
             // Add a custom js file.
             if (arrayHasValue($this->_CssFiles, 'style.css')) {
                 $this->addJsFile('custom.js');
                 // only to non-admin pages.
             }
             $Cdns = array();
             if (!c('Garden.Cdns.Disable', false)) {
                 $Cdns = array('jquery.js' => "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js");
             }
             // And now search for/add all JS files.
             $this->EventArguments['Cdns'] =& $Cdns;
             $this->fireEvent('AfterJsCdns');
             $this->Head->addScript('', 'text/javascript', false, array('content' => $this->definitionList(false)));
             foreach ($this->_JsFiles as $Index => $JsInfo) {
                 $JsFile = $JsInfo['FileName'];
                 if (!is_array($JsInfo['Options'])) {
                     $JsInfo['Options'] = array();
                 }
                 $Options =& $JsInfo['Options'];
                 if (isset($Cdns[$JsFile])) {
                     $JsFile = $Cdns[$JsFile];
                 }
                 $AppFolder = $JsInfo['AppFolder'];
                 $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder;
                 $Search = AssetModel::JsPath($JsFile, $LookupFolder, $ThemeType);
                 if (!$Search) {
                     continue;
                 }
                 list($Path, $UrlPath) = $Search;
                 if ($Path !== false) {
                     $AddVersion = true;
                     if (!isUrl($Path)) {
                         $Path = substr($Path, strlen(PATH_ROOT));
                         $Path = str_replace(DS, '/', $Path);
                         $AddVersion = val('AddVersion', $Options, true);
                     }
                     $this->Head->addScript($Path, 'text/javascript', $AddVersion, $Options);
                     continue;
                 }
             }
         }
         // Add the favicon.
         $Favicon = C('Garden.FavIcon');
         if ($Favicon) {
             $this->Head->setFavIcon(Gdn_Upload::url($Favicon));
         }
         // Make sure the head module gets passed into the assets collection.
         $this->addModule('Head');
     }
     // Master views come from one of four places:
     $MasterViewPaths = array();
     if (strpos($this->MasterView, '/') !== false) {
         $MasterViewPaths[] = combinePaths(array(PATH_ROOT, str_replace('/', DS, $this->MasterView) . '.master*'));
     } else {
         if ($this->Theme) {
             // 1. Application-specific theme view. eg. root/themes/theme_name/app_name/views/
             $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
             // 2. Garden-wide theme view. eg. /path/to/application/themes/theme_name/views/
             $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, 'views', $this->MasterView . '.master*'));
         }
         // 3. Plugin default. eg. root/plugin_name/views/
         $MasterViewPaths[] = combinePaths(array(PATH_ROOT, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
         // 4. Application default. eg. root/app_name/views/
         $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
         // 5. Garden default. eg. root/dashboard/views/
         $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, 'dashboard', 'views', $this->MasterView . '.master*'));
     }
     // Find the first file that matches the path.
     $MasterViewPath = false;
     foreach ($MasterViewPaths as $Glob) {
         $Paths = safeGlob($Glob);
         if (is_array($Paths) && count($Paths) > 0) {
             $MasterViewPath = $Paths[0];
             break;
         }
     }
     $this->EventArguments['MasterViewPath'] =& $MasterViewPath;
     $this->fireEvent('BeforeFetchMaster');
     if ($MasterViewPath === false) {
         trigger_error(errorMessage("Could not find master view: {$this->MasterView}.master*", $this->ClassName, '_FetchController'), E_USER_ERROR);
     }
     /// A unique identifier that can be used in the body tag of the master view if needed.
     $ControllerName = $this->ClassName;
     // Strip "Controller" from the body identifier.
     if (substr($ControllerName, -10) == 'Controller') {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Strip "Gdn_" from the body identifier.
     if (substr($ControllerName, 0, 4) == 'Gdn_') {
         $ControllerName = substr($ControllerName, 4);
     }
     $this->setData('CssClass', $this->Application . ' ' . $ControllerName . ' ' . $this->RequestMethod . ' ' . $this->CssClass, true);
     // Check to see if there is a handler for this particular extension.
     $ViewHandler = Gdn::factory('ViewHandler' . strtolower(strrchr($MasterViewPath, '.')));
     if (is_null($ViewHandler)) {
         $BodyIdentifier = strtolower($this->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($this->RequestMethod)));
         include $MasterViewPath;
     } else {
         $ViewHandler->render($MasterViewPath, $this);
     }
 }
예제 #16
0
 /**
  * Build a URL to an external site linked to this one.
  *
  * This function is used when an external site is configured with Vanilla in an embedding scenario.
  *
  * @param string $path The path within Vanilla.
  * @return string Returns the external URL.
  */
 function externalUrl($path)
 {
     $urlFormat = c('Garden.ExternalUrlFormat');
     if ($urlFormat && !isUrl($path)) {
         $result = sprintf($urlFormat, ltrim($path, '/'));
     } elseif (stringBeginsWith($path, '//')) {
         $result = Gdn::request()->scheme() . ':' . $path;
     } else {
         $result = Url($path, true);
     }
     return $result;
 }
예제 #17
0
 /**
  * Set fields that need additional manipulation after retrieval.
  *
  * @param $User
  * @throws Exception
  */
 public function setCalculatedFields(&$User)
 {
     if ($v = val('Attributes', $User)) {
         if (is_string($v)) {
             setValue('Attributes', $User, @unserialize($v));
         }
     }
     if ($v = val('Permissions', $User)) {
         if (is_string($v)) {
             setValue('Permissions', $User, @unserialize($v));
         }
     }
     if ($v = val('Preferences', $User)) {
         if (is_string($v)) {
             setValue('Preferences', $User, @unserialize($v));
         }
     }
     if ($v = val('Photo', $User)) {
         if (!isUrl($v)) {
             $PhotoUrl = Gdn_Upload::url(changeBasename($v, 'n%s'));
         } else {
             $PhotoUrl = $v;
         }
         setValue('PhotoUrl', $User, $PhotoUrl);
     }
     if ($v = val('AllIPAddresses', $User)) {
         if (is_string($v)) {
             $IPAddresses = explode(',', $v);
             foreach ($IPAddresses as $i => $IPAddress) {
                 $IPAddresses[$i] = ForceIPv4($IPAddress);
             }
             setValue('AllIPAddresses', $User, $IPAddresses);
         }
     }
     setValue('_CssClass', $User, '');
     if ($v = val('Banned', $User)) {
         setValue('_CssClass', $User, 'Banned');
     }
     $this->EventArguments['User'] =& $User;
     $this->fireEvent('SetCalculatedFields');
 }
예제 #18
0
 /**
  * Connect the user with an external source.
  *
  * This controller method is meant to be used with plugins that set its data array to work.
  * Events: ConnectData
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $Method Used to register multiple providers on ConnectData event.
  */
 public function connect($Method)
 {
     $this->addJsFile('entry.js');
     $this->View = 'connect';
     $IsPostBack = $this->Form->isPostBack() && $this->Form->getFormValue('Connect', null) !== null;
     $UserSelect = $this->Form->getFormValue('UserSelect');
     if (!$IsPostBack) {
         // Here are the initial data array values. that can be set by a plugin.
         $Data = array('Provider' => '', 'ProviderName' => '', 'UniqueID' => '', 'FullName' => '', 'Name' => '', 'Email' => '', 'Photo' => '', 'Target' => $this->target());
         $this->Form->setData($Data);
         $this->Form->addHidden('Target', $this->Request->get('Target', '/'));
     }
     // The different providers can check to see if they are being used and modify the data array accordingly.
     $this->EventArguments = array($Method);
     // Fire ConnectData event & error handling.
     $currentData = $this->Form->formValues();
     // Filter the form data for users here. SSO plugins must reset validated data each postback.
     $filteredData = Gdn::userModel()->filterForm($currentData, true);
     $filteredData = array_replace($filteredData, arrayTranslate($currentData, ['TransientKey', 'hpt']));
     unset($filteredData['Roles'], $filteredData['RoleID']);
     $this->Form->formValues($filteredData);
     try {
         $this->EventArguments['Form'] = $this->Form;
         $this->fireEvent('ConnectData');
         $this->fireEvent('AfterConnectData');
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
         return $this->render('ConnectError');
     } catch (Exception $Ex) {
         if (Debug()) {
             $this->Form->addError($Ex);
         } else {
             $this->Form->addError('There was an error fetching the connection data.');
         }
         return $this->render('ConnectError');
     }
     if (!UserModel::noEmail()) {
         if (!$this->Form->getFormValue('Email') || $this->Form->getFormValue('EmailVisible')) {
             $this->Form->setFormValue('EmailVisible', true);
             $this->Form->addHidden('EmailVisible', true);
             if ($IsPostBack) {
                 $this->Form->setFormValue('Email', val('Email', $currentData));
             }
         }
     }
     $FormData = $this->Form->formValues();
     // debug
     // Make sure the minimum required data has been provided to the connect.
     if (!$this->Form->getFormValue('Provider')) {
         $this->Form->addError('ValidateRequired', t('Provider'));
     }
     if (!$this->Form->getFormValue('UniqueID')) {
         $this->Form->addError('ValidateRequired', t('UniqueID'));
     }
     if (!$this->data('Verified')) {
         // Whatever event handler catches this must Set the data 'Verified' to true to prevent a random site from connecting without credentials.
         // This must be done EVERY postback and is VERY important.
         $this->Form->addError('The connection data has not been verified.');
     }
     if ($this->Form->errorCount() > 0) {
         return $this->render();
     }
     $UserModel = Gdn::userModel();
     // Check to see if there is an existing user associated with the information above.
     $Auth = $UserModel->getAuthentication($this->Form->getFormValue('UniqueID'), $this->Form->getFormValue('Provider'));
     $UserID = val('UserID', $Auth);
     // Check to synchronise roles upon connecting.
     if (($this->data('Trusted') || c('Garden.SSO.SyncRoles')) && $this->Form->getFormValue('Roles', null) !== null) {
         $SaveRoles = $SaveRolesRegister = true;
         // Translate the role names to IDs.
         $Roles = $this->Form->getFormValue('Roles', null);
         $Roles = RoleModel::getByName($Roles);
         $RoleIDs = array_keys($Roles);
         if (empty($RoleIDs)) {
             // The user must have at least one role. This protects that.
             $RoleIDs = $this->UserModel->newUserRoleIDs();
         }
         if (c('Garden.SSO.SyncRolesBehavior') === 'register') {
             $SaveRoles = false;
         }
         $this->Form->setFormValue('RoleID', $RoleIDs);
     } else {
         $SaveRoles = false;
         $SaveRolesRegister = false;
     }
     if ($UserID) {
         // The user is already connected.
         $this->Form->setFormValue('UserID', $UserID);
         if (c('Garden.Registration.ConnectSynchronize', true)) {
             $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY);
             $Data = $this->Form->formValues();
             // Don't overwrite the user photo if the user uploaded a new one.
             $Photo = val('Photo', $User);
             if (!val('Photo', $Data) || $Photo && !isUrl($Photo)) {
                 unset($Data['Photo']);
             }
             // Synchronize the user's data.
             $UserModel->save($Data, array('NoConfirmEmail' => true, 'FixUnique' => true, 'SaveRoles' => $SaveRoles));
         }
         // Always save the attributes because they may contain authorization information.
         if ($Attributes = $this->Form->getFormValue('Attributes')) {
             $UserModel->saveAttribute($UserID, $Attributes);
         }
         // Sign the user in.
         Gdn::session()->start($UserID, true, (bool) $this->Form->getFormValue('RememberMe', true));
         Gdn::userModel()->fireEvent('AfterSignIn');
         //         $this->_setRedirect(TRUE);
         $this->_setRedirect($this->Request->get('display') == 'popup');
     } elseif ($this->Form->getFormValue('Name') || $this->Form->getFormValue('Email')) {
         $NameUnique = c('Garden.Registration.NameUnique', true);
         $EmailUnique = c('Garden.Registration.EmailUnique', true);
         $AutoConnect = c('Garden.Registration.AutoConnect');
         if ($IsPostBack && $this->Form->getFormValue('ConnectName')) {
             $searchName = $this->Form->getFormValue('ConnectName');
         } else {
             $searchName = $this->Form->getFormValue('Name');
         }
         // Get the existing users that match the name or email of the connection.
         $Search = false;
         if ($searchName && $NameUnique) {
             $UserModel->SQL->orWhere('Name', $searchName);
             $Search = true;
         }
         if ($this->Form->getFormValue('Email') && ($EmailUnique || $AutoConnect)) {
             $UserModel->SQL->orWhere('Email', $this->Form->getFormValue('Email'));
             $Search = true;
         }
         if (is_numeric($UserSelect)) {
             $UserModel->SQL->orWhere('UserID', $UserSelect);
             $Search = true;
         }
         if ($Search) {
             $ExistingUsers = $UserModel->getWhere()->resultArray();
         } else {
             $ExistingUsers = array();
         }
         // Check to automatically link the user.
         if ($AutoConnect && count($ExistingUsers) > 0) {
             if ($IsPostBack && $this->Form->getFormValue('ConnectName')) {
                 $this->Form->setFormValue('Name', $this->Form->getFormValue('ConnectName'));
             }
             foreach ($ExistingUsers as $Row) {
                 if (strcasecmp($this->Form->getFormValue('Email'), $Row['Email']) === 0) {
                     $UserID = $Row['UserID'];
                     $this->Form->setFormValue('UserID', $UserID);
                     $Data = $this->Form->formValues();
                     if (c('Garden.Registration.ConnectSynchronize', true)) {
                         // Don't overwrite a photo if the user has already uploaded one.
                         $Photo = val('Photo', $Row);
                         if (!val('Photo', $Data) || $Photo && !stringBeginsWith($Photo, 'http')) {
                             unset($Data['Photo']);
                         }
                         $UserModel->save($Data, array('NoConfirmEmail' => true, 'FixUnique' => true, 'SaveRoles' => $SaveRoles));
                     }
                     if ($Attributes = $this->Form->getFormValue('Attributes')) {
                         $UserModel->saveAttribute($UserID, $Attributes);
                     }
                     // Save the userauthentication link.
                     $UserModel->saveAuthentication(array('UserID' => $UserID, 'Provider' => $this->Form->getFormValue('Provider'), 'UniqueID' => $this->Form->getFormValue('UniqueID')));
                     // Sign the user in.
                     Gdn::session()->start($UserID, true, (bool) $this->Form->getFormValue('RememberMe', true));
                     Gdn::userModel()->fireEvent('AfterSignIn');
                     //         $this->_setRedirect(TRUE);
                     $this->_setRedirect($this->Request->get('display') == 'popup');
                     $this->render();
                     return;
                 }
             }
         }
         $CurrentUserID = Gdn::session()->UserID;
         // Massage the existing users.
         foreach ($ExistingUsers as $Index => $UserRow) {
             if ($EmailUnique && $UserRow['Email'] == $this->Form->getFormValue('Email')) {
                 $EmailFound = $UserRow;
                 break;
             }
             if ($UserRow['Name'] == $this->Form->getFormValue('Name')) {
                 $NameFound = $UserRow;
             }
             if ($CurrentUserID > 0 && $UserRow['UserID'] == $CurrentUserID) {
                 unset($ExistingUsers[$Index]);
                 $CurrentUserFound = true;
             }
         }
         if (isset($EmailFound)) {
             // The email address was found and can be the only user option.
             $ExistingUsers = array($UserRow);
             $this->setData('NoConnectName', true);
         } elseif (isset($CurrentUserFound)) {
             $ExistingUsers = array_merge(array('UserID' => 'current', 'Name' => sprintf(t('%s (Current)'), Gdn::session()->User->Name)), $ExistingUsers);
         }
         if (!isset($NameFound) && !$IsPostBack) {
             $this->Form->setFormValue('ConnectName', $this->Form->getFormValue('Name'));
         }
         $this->setData('ExistingUsers', $ExistingUsers);
         if (UserModel::noEmail()) {
             $EmailValid = true;
         } else {
             $EmailValid = validateRequired($this->Form->getFormValue('Email'));
         }
         if ((!$UserSelect || $UserSelect == 'other') && $this->Form->getFormValue('Name') && $EmailValid && (!is_array($ExistingUsers) || count($ExistingUsers) == 0)) {
             // There is no existing user with the suggested name so we can just create the user.
             $User = $this->Form->formValues();
             $User['Password'] = randomString(50);
             // some password is required
             $User['HashMethod'] = 'Random';
             $User['Source'] = $this->Form->getFormValue('Provider');
             $User['SourceID'] = $this->Form->getFormValue('UniqueID');
             $User['Attributes'] = $this->Form->getFormValue('Attributes', null);
             $User['Email'] = $this->Form->getFormValue('ConnectEmail', $this->Form->getFormValue('Email', null));
             $UserID = $UserModel->register($User, array('CheckCaptcha' => false, 'ValidateEmail' => false, 'NoConfirmEmail' => true, 'SaveRoles' => $SaveRolesRegister));
             $User['UserID'] = $UserID;
             $this->Form->setValidationResults($UserModel->validationResults());
             if ($UserID) {
                 $UserModel->saveAuthentication(array('UserID' => $UserID, 'Provider' => $this->Form->getFormValue('Provider'), 'UniqueID' => $this->Form->getFormValue('UniqueID')));
                 $this->Form->setFormValue('UserID', $UserID);
                 $this->Form->setFormValue('UserSelect', false);
                 Gdn::session()->start($UserID, true, (bool) $this->Form->getFormValue('RememberMe', true));
                 Gdn::userModel()->fireEvent('AfterSignIn');
                 // Send the welcome email.
                 if (c('Garden.Registration.SendConnectEmail', false)) {
                     try {
                         $UserModel->sendWelcomeEmail($UserID, '', 'Connect', array('ProviderName' => $this->Form->getFormValue('ProviderName', $this->Form->getFormValue('Provider', 'Unknown'))));
                     } catch (Exception $Ex) {
                         // Do nothing if emailing doesn't work.
                     }
                 }
                 $this->_setRedirect(true);
             }
         }
     }
     // Save the user's choice.
     if ($IsPostBack) {
         // The user has made their decision.
         $PasswordHash = new Gdn_PasswordHash();
         if (!$UserSelect || $UserSelect == 'other') {
             // The user entered a username.
             $ConnectNameEntered = true;
             if ($this->Form->validateRule('ConnectName', 'ValidateRequired')) {
                 $ConnectName = $this->Form->getFormValue('ConnectName');
                 $User = false;
                 if (c('Garden.Registration.NameUnique')) {
                     // Check to see if there is already a user with the given name.
                     $User = $UserModel->getWhere(array('Name' => $ConnectName))->firstRow(DATASET_TYPE_ARRAY);
                 }
                 if (!$User) {
                     $this->Form->validateRule('ConnectName', 'ValidateUsername');
                 }
             }
         } else {
             // The user selected an existing user.
             $ConnectNameEntered = false;
             if ($UserSelect == 'current') {
                 if (Gdn::session()->UserID == 0) {
                     // This shouldn't happen, but a use could sign out in another browser and click submit on this form.
                     $this->Form->addError('@You were unexpectedly signed out.');
                 } else {
                     $UserSelect = Gdn::session()->UserID;
                 }
             }
             $User = $UserModel->getID($UserSelect, DATASET_TYPE_ARRAY);
         }
         if (isset($User) && $User) {
             // Make sure the user authenticates.
             if (!$User['UserID'] == Gdn::session()->UserID) {
                 if ($this->Form->validateRule('ConnectPassword', 'ValidateRequired', sprintf(t('ValidateRequired'), t('Password')))) {
                     try {
                         if (!$PasswordHash->checkPassword($this->Form->getFormValue('ConnectPassword'), $User['Password'], $User['HashMethod'], $this->Form->getFormValue('ConnectName'))) {
                             if ($ConnectNameEntered) {
                                 $this->Form->addError('The username you entered has already been taken.');
                             } else {
                                 $this->Form->addError('The password you entered is incorrect.');
                             }
                         }
                     } catch (Gdn_UserException $Ex) {
                         $this->Form->addError($Ex);
                     }
                 }
             }
         } elseif ($this->Form->errorCount() == 0) {
             // The user doesn't exist so we need to add another user.
             $User = $this->Form->formValues();
             $User['Name'] = $User['ConnectName'];
             $User['Password'] = randomString(50);
             // some password is required
             $User['HashMethod'] = 'Random';
             $UserID = $UserModel->register($User, array('CheckCaptcha' => false, 'NoConfirmEmail' => true, 'SaveRoles' => $SaveRolesRegister));
             $User['UserID'] = $UserID;
             $this->Form->setValidationResults($UserModel->validationResults());
             if ($UserID && c('Garden.Registration.SendConnectEmail', false)) {
                 // Send the welcome email.
                 $UserModel->sendWelcomeEmail($UserID, '', 'Connect', array('ProviderName' => $this->Form->getFormValue('ProviderName', $this->Form->getFormValue('Provider', 'Unknown'))));
             }
         }
         if ($this->Form->errorCount() == 0) {
             // Save the authentication.
             if (isset($User) && val('UserID', $User)) {
                 $UserModel->saveAuthentication(array('UserID' => $User['UserID'], 'Provider' => $this->Form->getFormValue('Provider'), 'UniqueID' => $this->Form->getFormValue('UniqueID')));
                 $this->Form->setFormValue('UserID', $User['UserID']);
             }
             // Sign the appropriate user in.
             Gdn::session()->start($this->Form->getFormValue('UserID'), true, (bool) $this->Form->getFormValue('RememberMe', true));
             Gdn::userModel()->fireEvent('AfterSignIn');
             $this->_setRedirect(true);
         }
     }
     $this->render();
 }
 include "getProjectsFromJSON.php";
 if (!empty($projectArray)) {
     for ($i = 0; $i < sizeof($projectArray); $i++) {
         if ($projectArray[$i]->{'UUID'} == $UUID) {
             $selectedProject = $projectArray[$i];
             $allowedFilesArray = json_decode($selectedProject->{$property});
             if (isset($options) && $options != null) {
                 if ($options == "option") {
                     for ($j = 0; $j < sizeof($allowedFilesArray); $j++) {
                         $currentFile = $allowedFilesArray[$j];
                         $length = strlen($currentFile);
                         if ($length > 30) {
                             $currentFile = substr($allowedFilesArray[$j], 0, 20) . "..." . substr($allowedFilesArray[$j], $length - 9, $length);
                         }
                         include_once "functions.php";
                         if (file_exists("../executables/" . $allowedFilesArray[$j]) || isUrl($allowedFilesArray[$j])) {
                             echo '<option id="' . rawurldecode($allowedFilesArray[$j]) . '">' . $currentFile . "</option>";
                         }
                     }
                 } elseif ($options == "image") {
                     $directory = "../images/screenshots/";
                     for ($j = 0; $j < sizeof($allowedFilesArray); $j++) {
                         if (file_exists($directory . $allowedFilesArray[$j])) {
                             echo '<a href="' . $directory . rawurlencode($allowedFilesArray[$j]) . '" data-lightbox="' . $directory . rawurlencode($allowedFilesArray[$j]) . '">' . '<div class="entry-icon medium container space">' . '<div class="entry-icon" style="background-image: url(' . $directory . rawurlencode($allowedFilesArray[$j]) . ');"> </div>	' . '</div>' . '</a>';
                         }
                     }
                 }
             }
             break;
         }
     }
예제 #20
0
$RemotePhoto = IsUrl($this->User->Photo, 0, 7);
// Define the current profile picture
$Picture = '';
if ($this->User->Photo != '') {
    if (IsUrl($this->User->Photo)) {
        $Picture = img($this->User->Photo, array('class' => 'ProfilePhotoLarge'));
    } else {
        $Picture = img(Gdn_Upload::url(changeBasename($this->User->Photo, 'p%s')), array('class' => 'ProfilePhotoLarge'));
    }
}
// Define the current thumbnail icon
$Thumbnail = $this->User->Photo;
if (!$Thumbnail && function_exists('UserPhotoDefaultUrl')) {
    $Thumbnail = UserPhotoDefaultUrl($this->User);
}
if ($Thumbnail && !isUrl($Thumbnail)) {
    $Thumbnail = Gdn_Upload::url(changeBasename($Thumbnail, 'n%s'));
}
$Thumbnail = img($Thumbnail, array('alt' => t('Thumbnail')));
?>
<div class="SmallPopup FormTitleWrapper">
    <h1 class="H"><?php 
echo $this->data('Title');
?>
</h1>
    <?php 
echo $this->Form->open(array('enctype' => 'multipart/form-data'));
echo $this->Form->errors();
?>
    <ul>
        <?php 
예제 #21
0
/**
 * @return \Closure
 */
function isNotUrl()
{
    return negate(isUrl());
}
예제 #22
0
 /**
  * Take a user object an return the URL to their photo.
  *
  * @param object|array $User
  */
 function userPhotoUrl($User)
 {
     $FullUser = Gdn::userModel()->getID(val('UserID', $User), DATASET_TYPE_ARRAY);
     $Photo = val('Photo', $User);
     if ($FullUser && $FullUser['Banned']) {
         $Photo = 'https://c3409409.ssl.cf0.rackcdn.com/images/banned_100.png';
     }
     if ($Photo) {
         if (!isUrl($Photo)) {
             $PhotoUrl = Gdn_Upload::url(changeBasename($Photo, 'n%s'));
         } else {
             $PhotoUrl = $Photo;
         }
         return $PhotoUrl;
     }
     return UserModel::getDefaultAvatarUrl($User);
 }
예제 #23
0
 /**
  * Set fields that need additional manipulation after retrieval.
  *
  * @param array|object &$User
  * @throws Exception
  */
 public function setCalculatedFields(&$User)
 {
     if ($v = val('Attributes', $User)) {
         if (is_string($v)) {
             setValue('Attributes', $User, dbdecode($v));
         }
     }
     if ($v = val('Permissions', $User)) {
         if (is_string($v)) {
             setValue('Permissions', $User, dbdecode($v));
         }
     }
     if ($v = val('Preferences', $User)) {
         if (is_string($v)) {
             setValue('Preferences', $User, dbdecode($v));
         }
     }
     if ($v = val('Photo', $User)) {
         if (!isUrl($v)) {
             $PhotoUrl = Gdn_Upload::url(changeBasename($v, 'n%s'));
         } else {
             $PhotoUrl = $v;
         }
         setValue('PhotoUrl', $User, $PhotoUrl);
     }
     // We store IPs in the UserIP table. To avoid unnecessary queries, the full list is not built here. Shim for BC.
     setValue('AllIPAddresses', $User, [val('InsertIPAddress', $User), val('LastIPAddress', $User)]);
     setValue('_CssClass', $User, '');
     if (val('Banned', $User)) {
         setValue('_CssClass', $User, 'Banned');
     }
     $this->EventArguments['User'] =& $User;
     $this->fireEvent('SetCalculatedFields');
 }
예제 #24
0
function redirect($url = '', $time = 0, $data = array(), $exit = true)
{
    if (!is_string($url) || empty($url)) {
        return false;
    }
    if (!is_numeric($time)) {
        $time = '0';
    }
    if (!is_bool($exit)) {
        $exit = true;
    }
    if (!isUrl($url)) {
        $url = siteUrl($url);
    }
    if (!empty($data)) {
        if (!isset($_SESSION)) {
            session_start();
        }
        foreach ($data as $k => $v) {
            $_SESSION[md5('redirect:' . $k)] = $v;
        }
    }
    if ($time === 0) {
        header("Location: {$url}", true);
    } else {
        sleep($time);
        header("Location: {$url}", true);
    }
    if ($exit === true) {
        exit;
    }
}
예제 #25
0
 public function action(string $url = NULL)
 {
     $this->settings['attr']['action'] = isUrl($url) ? $url : siteUrl($url);
     return $this;
 }
 /**
  * Special manipulations.
  */
 public function parseSpecialFields($Fields = array())
 {
     if (!is_array($Fields)) {
         return $Fields;
     }
     foreach ($Fields as $Label => $Value) {
         if ($Value == '') {
             continue;
         }
         // Use plaintext for building these
         $Value = Gdn_Format::text($Value);
         switch ($Label) {
             case 'Twitter':
                 $Fields['Twitter'] = '@' . anchor($Value, 'http://twitter.com/' . $Value);
                 break;
             case 'Facebook':
                 $Fields['Facebook'] = anchor($Value, 'http://facebook.com/' . $Value);
                 break;
             case 'LinkedIn':
                 $Fields['LinkedIn'] = anchor($Value, 'http://www.linkedin.com/in/' . $Value);
                 break;
             case 'GitHub':
                 $Fields['GitHub'] = anchor($Value, 'https://github.com/' . $Value);
                 break;
             case 'Google':
                 $Fields['Google'] = anchor('Google+', $Value, '', array('rel' => 'me'));
                 break;
             case 'Website':
                 $LinkValue = isUrl($Value) ? $Value : 'http://' . $Value;
                 $Fields['Website'] = anchor($Value, $LinkValue);
                 break;
             case 'Real Name':
                 $Fields['Real Name'] = wrap(htmlspecialchars($Value), 'span', array('itemprop' => 'name'));
                 break;
         }
     }
     return $Fields;
 }
예제 #27
0
 public function forgotPassword($email = "", $returnLinkPath = "")
 {
     if (!is_string($email)) {
         return Error::set(lang('Error', 'stringParameter', 'email'));
     }
     if (!is_string($returnLinkPath)) {
         $returnLinkPath = '';
     }
     // ------------------------------------------------------------------------------
     // CONFIG/USER.PHP AYARLARI
     // Config/User.php dosyasında belirtilmiş ayarlar alınıyor.
     // ------------------------------------------------------------------------------
     $userConfig = $this->config;
     $usernameColumn = $userConfig['usernameColumn'];
     $passwordColumn = $userConfig['passwordColumn'];
     $emailColumn = $userConfig['emailColumn'];
     $tableName = $userConfig['tableName'];
     // ------------------------------------------------------------------------------
     $db = uselib('DB');
     if (!empty($emailColumn)) {
         $db->where($emailColumn . ' =', $email);
     } else {
         $db->where($usernameColumn . ' =', $email);
     }
     $row = $db->get($tableName)->row();
     $result = "";
     if (isset($row->{$usernameColumn})) {
         if (!isUrl($returnLinkPath)) {
             $returnLinkPath = siteUrl($returnLinkPath);
         }
         $newPassword = Encode::create(10);
         $encodePassword = Encode::super($newPassword);
         $templateData = array('usernameColumn' => $row->{$usernameColumn}, 'newPassword' => $newPassword, 'returnLinkPath' => $returnLinkPath);
         $message = Import::template('UserEmail/ForgotPassword', $templateData, true);
         $sendEmail = uselib('Email');
         $sendEmail->receiver($email, $email);
         $sendEmail->subject(lang('User', 'newYourPassword'));
         $sendEmail->content($message);
         if ($sendEmail->send()) {
             if (!empty($emailColumn)) {
                 $db->where($emailColumn . ' =', $email);
             } else {
                 $db->where($usernameColumn . ' =', $email);
             }
             $db->update($tableName, array($passwordColumn => $encodePassword));
             $this->error = true;
             $this->success = lang('User', 'forgotPasswordSuccess');
             return false;
         } else {
             $this->success = false;
             $this->error = lang('User', 'emailError');
             return Error::set($this->error);
         }
     } else {
         $this->success = false;
         $this->error = lang('User', 'forgotPasswordError');
         return Error::set($this->error);
     }
 }
예제 #28
0
 /**
  * Lookup the path to a JS file and return its info array
  *
  * @param string $filename name/relative path to js file
  * @param string $folder optional. app or plugin folder to search
  * @param string $themeType mobile or desktop
  * @return array|bool
  */
 public static function jsPath($filename, $folder = '', $themeType = '')
 {
     if (!$themeType) {
         $themeType = isMobile() ? 'mobile' : 'desktop';
     }
     // 1. Check for a url.
     if (isUrl($filename)) {
         return [$filename, $filename];
     }
     $paths = [];
     // 2. Check for a full path.
     if (strpos($filename, '/') === 0) {
         $filename = ltrim($filename, '/');
         // Direct path was given
         $filename = "/{$filename}";
         $path = PATH_ROOT . $filename;
         if (file_exists($path)) {
             deprecated(htmlspecialchars($path) . ": AssetModel::JsPath() with direct paths");
             return [$path, $filename];
         }
         return false;
     }
     // 3. Check the theme.
     $theme = Gdn::themeManager()->themeFromType($themeType);
     if ($theme) {
         $path = "/{$theme}/js/{$filename}";
         $paths[] = [PATH_THEMES . $path, "/themes{$path}"];
     }
     // 4. Static, Plugin, or App relative file
     if ($folder) {
         if (in_array($folder, ['resources', 'static'])) {
             $path = "/resources/js/{$filename}";
             $paths[] = [PATH_ROOT . $path, $path];
             // A plugin-relative path was given
         } elseif (stringBeginsWith($folder, 'plugins/')) {
             $folder = substr($folder, strlen('plugins/'));
             $path = "/{$folder}/js/{$filename}";
             $paths[] = [PATH_PLUGINS . $path, "/plugins{$path}"];
             // Allow direct-to-file links for plugins
             $paths[] = [PATH_PLUGINS . "/{$folder}/{$filename}", "/plugins/{$folder}/{$filename}", true];
             // deprecated
             // An app-relative path was given
         } else {
             // App-relative path under the theme
             if ($theme) {
                 $path = "/{$theme}/{$folder}/js/{$filename}";
                 $paths[] = [PATH_THEMES . $path, "/themes{$path}"];
             }
             $path = "/{$folder}/js/{$filename}";
             $paths[] = [PATH_APPLICATIONS . $path, "/applications{$path}"];
         }
     }
     // 5. Check the global js folder.
     $paths[] = [PATH_ROOT . "/js/{$filename}", "/js/{$filename}"];
     $paths[] = [PATH_ROOT . "/js/library/{$filename}", "/js/library/{$filename}"];
     foreach ($paths as $info) {
         if (file_exists($info[0])) {
             if (!empty($info[2])) {
                 // This path is deprecated.
                 unset($info[2]);
                 deprecated("The js file '{$filename}' in folder '{$folder}'");
             }
             return $info;
         }
     }
     if (!stringEndsWith($filename, 'custom.js')) {
         trace("Could not find file '{$filename}' in folder '{$folder}'.");
     }
     return false;
 }
예제 #29
0
 /**
  * Parses Youtube code.
  * You can use video ID or video url.
  *
  * Examples:
  * <code>
  * [youtube]bL_CJKq9rIw[/youtube]
  * </code>
  *
  * <code>
  * [youtube]http://youtube.com/watch?v=bL_CJKq9rIw[/youtube]
  * </code>
  * @param string $text Text
  * @return string
  * @uses MeTools\Utility\Youtube::getId()
  * @uses MeTools\View\Helper\HtmlHelper::youtube()
  * @uses $pattern
  */
 public function youtube($text)
 {
     return preg_replace_callback($this->pattern['youtube'], function ($matches) {
         if (isUrl($matches[1])) {
             return $this->Html->youtube(Youtube::getId($matches[1]));
         }
         return $this->Html->youtube($matches[1]);
     }, $text);
 }
예제 #30
0
 public function script()
 {
     $str = '';
     $eol = eol();
     $args = $this->_parameters(func_get_args(), 'scripts');
     $lastParam = $args->lastParam;
     $arguments = $args->arguments;
     $links = $args->cdnLinks;
     foreach ($arguments as $script) {
         if (is_array($script)) {
             $script = '';
         }
         $scriptFile = restorationPath(SCRIPTS_DIR . suffix($script, ".js"));
         if (!in_array("script_" . $script, $this->isImport)) {
             if (is_file($scriptFile)) {
                 $str .= '<script type="text/javascript" src="' . baseUrl($scriptFile) . '"></script>' . $eol;
             } elseif (isUrl($script) && extension($script) === 'js') {
                 $str .= '<script type="text/javascript" src="' . $script . '"></script>' . $eol;
             } elseif (isset($links[strtolower($script)])) {
                 $str .= '<script type="text/javascript" src="' . $links[strtolower($script)] . '"></script>' . $eol;
             }
             $this->isImport[] = "script_" . $script;
         }
     }
     if (!empty($str)) {
         if ($lastParam === true) {
             return $str;
         } else {
             echo $str;
         }
     } else {
         return false;
     }
 }