public function getMethodComment($methodName)
 {
     try {
         $this->file->open();
         $source = $this->file->getContents();
     } catch (Exception $e) {
         return '';
     }
     $pattern = '|\\s+function\\s*' . $methodName . '\\s*\\(|ims';
     if (preg_match_all($pattern, $source, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
         foreach ($matches as $match) {
             $comment = $this->getComment(substr($source, 0, $match[0][1]));
             if ($comment !== false) {
                 return $comment;
             }
         }
     }
     return '';
 }
    /**
     * @service theme read
     */
    public function loadFile(Gpf_Rpc_Params $params) {
        $form = new Gpf_Rpc_Form($params);
        $themeId = $form->getFieldValue('themeId');
        $itemId = $form->getFieldValue("id");
        $themeBase = $this->getThemeFile($form->getFieldValue('panelName'));

        $loadFile = null;
        $file_theme = new Gpf_Io_File($themeBase.'/'.$themeId.$itemId);
        if($file_theme->isExists()){
            $loadFile = $file_theme;
        }else{
            $loadFile = new Gpf_Io_File($themeBase.'/'.Gpf_Paths::DEFAULT_THEME.$itemId);
        }
        $form->setField('text', $loadFile->getContents());
        return $form;
    }
Example #3
0
 protected function copyFile(Gpf_Io_File $source, Gpf_Io_File $target, $mode = null)
 {
     $target->open('w');
     $target->write($source->getContents());
     if ($mode !== null) {
         @chmod($target->getFileName(), $mode);
     }
 }
 public function load(Gpf_Lang_Language $language)
 {
     $file = new Gpf_Io_File($this->getFilename());
     try {
         $file->open('r');
     } catch (Exception $e) {
         try {
             $this->regenerateLanguageCacheFiles();
             $file->open('r');
         } catch (Exception $e2) {
             throw new Gpf_Exception($this->_('Could not open language file %s', $e2->getMessage()));
         }
     }
     $_name = '';
     $_engName = '';
     $_author = '';
     $_version = '';
     $_dict = '';
     $_dateFormat = '';
     $_timeFormat = '';
     $_thousandsSeparator = '';
     $_decimalSeparator = '';
     if (@eval(str_replace(array('<?php', '?>'), '', $file->getContents())) === false) {
         throw new Gpf_Exception($this->_('Corrupted language file %s', $file->getFileName()));
     }
     @$language->setName($_name);
     @$language->setEnglishName($_engName);
     @$language->setAuthor($_author);
     @$language->setVersion($_version);
     @$language->setDictionary($_dict);
     @$language->setDateFormat($_dateFormat);
     @$language->setTimeFormat($_timeFormat);
     @$language->setThousandsSeparator($_thousandsSeparator);
     @$language->setDecimalSeparator($_decimalSeparator);
 }
 private function renderPrivileges($className, $privilegeList, $privilegeTypes, $hasParentClass)
 {
     if ($fileName = Gpf::existsClass($className)) {
         $file = new Gpf_Io_File($fileName);
         $file->setFileMode('r');
         $content = $file->getContents();
         $file->close();
         if (($pos = strpos($content, self::TAG)) === false) {
             throw new Gpf_Exception('Missing tag ' . self::TAG . ' in privileges class ' . $className . ' !');
         }
         $file = new Gpf_Io_File($fileName);
         $file->open('w');
         $file->write(substr($content, 0, $pos + strlen(self::TAG)) . "\n\n");
         $file->write("\t// Privilege types\n");
         foreach ($privilegeTypes as $privilege) {
             $file->write("\t" . 'const ' . $this->formatPrivilegeType($privilege) . ' = "' . $privilege . '";' . "\n");
         }
         $file->write("\n");
         $file->write("\t// Privilege objects\n");
         foreach ($privilegeList as $object => $privileges) {
             ksort($privileges);
             $privilegeTypeComments = '// ';
             foreach ($privileges as $privilege) {
                 $privilegeTypeComments .= $this->formatPrivilegeType($privilege) . ', ';
             }
             $privilegeTypeComments = rtrim($privilegeTypeComments, ", ");
             $file->write("\t" . 'const ' . strtoupper($object) . ' = "' . $object . '"; ' . $privilegeTypeComments . "\n");
         }
         $file->write("\t\n\n\tprotected function initObjectRelation() {\n\t\t");
         if ($hasParentClass) {
             $file->write('$objectRelation = array_merge_recursive(parent::initObjectRelation(), array(');
         } else {
             $file->write('return array(');
         }
         $comma = "\n\t\t";
         foreach ($privilegeList as $object => $privileges) {
             $file->write($comma . "self::" . strtoupper($object) . "=>array(");
             ksort($privileges);
             $privilegeTypes = '';
             foreach ($privileges as $privilege) {
                 $privilegeTypes .= 'self::' . $this->formatPrivilegeType($privilege) . ', ';
             }
             $file->write(rtrim($privilegeTypes, ", ") . ")");
             $comma = ",\n\t\t";
         }
         $file->write("\n\t\t)" . ($hasParentClass ? ");\r\r\t\tforeach (\$objectRelation as \$key => \$value) {\r\t\t\t\$objectRelation[\$key] = array_unique(\$value);\r\t\t}\r\t\treturn \$objectRelation;" : ';') . "\r\t}\n");
         $file->write("\n}\n?>");
     }
 }
 protected function isFileChanged(Gpf_Io_File $source, Gpf_Io_File $target)
 {
     return $target->getContents() != $source->getContents();
 }
Example #7
0
 /**
  * Parse file content
  *
  * @param unknown_type $content
  * @param Gpf_Io_File $file
  * @return unknown
  */
 private function parseContent(Gpf_Io_File $file)
 {
     flush();
     try {
         $content = $file->getContents();
     } catch (Gpf_Exception $e) {
         echo $this->_("Failed loading file %s with error: %s", $file->getFileName(), $e->getMessage()) . "<br/>\n";
         return;
     }
     foreach ($this->matchPatterns[$file->getExtension()] as $pattern => $type) {
         $count = preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE);
         if ($count > 0) {
             foreach ($matches[1] as $sentence) {
                 if (strlen($sentence[0])) {
                     $this->addMessage($sentence[0], $file, $type);
                 }
             }
         }
     }
     return true;
 }
 private function replaceTemplatesInDirectory($cacheZipFolderPath, $filetypes, Pap_Common_User $affiliate, Pap_Common_Banner $banner, $channelcode){
     $cacheZipFolder = new Gpf_Io_DirectoryIterator($cacheZipFolderPath, '', true);
     
     $typesArray = $this->getFileTypesArray($filetypes);
     foreach ($cacheZipFolder as $fullFileName => $fileName) {
         $file = new Gpf_Io_File($fullFileName);
         if ($file->matchPatterns($typesArray)){
             $content = $this->replaceVariables($affiliate, $banner, $channelcode, $file->getContents());
             $file->putContents($content);
         }
     }
 }
Example #9
0
 protected function lazyInitDefaultValue($name)
 {
     try {
         $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getResourcePath($name . '.' . self::LARGE_TEXT_SETTING_TEMPLATE_FILE_EXTENSION, self::LARGE_TEXT_SETTINGS_DIR));
     } catch (Gpf_ResourceNotFoundException $e) {
         return;
     }
     $this->addDefaultValue($name, $file->getContents());
 }
Example #10
0
 private function containsDbSettings(Gpf_Io_File $file)
 {
     $content = $file->getContents();
     return strstr($content, Gpf_Settings_Gpf::DB_DATABASE) && strstr($content, Gpf_Settings_Gpf::DB_HOSTNAME) && strstr($content, Gpf_Settings_Gpf::DB_PASSWORD) && strstr($content, Gpf_Settings_Gpf::DB_USERNAME);
 }
Example #11
0
 protected function lazyInitDefaultValue($name) {
     
     switch($name) {
         case self::PROGRAM_LOGO:
             $this->addDefaultValue(self::PROGRAM_LOGO, Gpf_Paths::getInstance()->getImageUrl('logo_pap.gif', 'signup'));
             break;
         default:
             try {
                 $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getResourcePath($name .
                 '.' . Gpf_Settings_Define::LARGE_TEXT_SETTING_TEMPLATE_FILE_EXTENSION, Gpf_Settings_Define::LARGE_TEXT_SETTINGS_DIR, 'merchants'));
             } catch (Gpf_ResourceNotFoundException $e) {
                 return;
             }
             $this->addDefaultValue($name, $file->getContents());
     }
 }
 public function getEncodedClientMessages()
 {
     if ($this->getLanguage() != null) {
         $langCode = $this->getLanguage()->getCode();
     } else {
         $langCode = $this->getDefaultSystemLanguage();
     }
     $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getLanguageCacheDirectory() . Gpf_Application::getInstance()->getCode() . '_' . $langCode . '.c.php');
     return $file->getContents();
 }
Example #13
0
 public static function checkCompileDirRequirementsInInstallMode()
 {
     $installDir = self::resolveCompileDirInInstallMode();
     if ($installDir == self::INSTALL_STREAM . '://:') {
         ob_start();
         phpInfo();
         $info = ob_get_contents();
         ob_end_clean();
         if (strstr($info, 'Suhosin') !== false) {
             $template = new Gpf_Io_File(Gpf_Paths::getInstance()->getFullBaseServerPath() . Gpf_Paths::INSTALL_DIR . Gpf_Paths::TEMPLATES_DIR . Gpf_Paths::INSTALL_DIR . Gpf_Paths::DEFAULT_THEME . 'accounts_wrong_permission.stpl');
             $body = $template->getContents();
             $body = str_replace('{$path}', Gpf_Paths::getInstance()->getFullBaseServerPath() . Gpf_Paths::ACCOUNTS_DIR, $body);
             die($body);
         }
     }
 }
Example #14
0
 /**
  * @throws Gpf_Exception
  */
 public static function copy(Gpf_Io_File $source, Gpf_Io_File $target, $mode = null)
 {
     if (Gpf_Php::isFunctionEnabled('copy')) {
         if (false === @copy($source->getFileName(), $target->getFileName())) {
             throw new Gpf_Exception('Could not copy ' . $source->getFileName() . ' to ' . $target->getFileName());
         }
     } else {
         $target->open('w');
         $target->write($source->getContents());
     }
     if ($mode !== null) {
         @chmod($target->getFileName(), $mode);
     }
 }