Example #1
0
 /**
  * Получает формулы TeX для поста
  */
 public function getCommentsFormules($postId = null)
 {
     $formules = array();
     foreach ($this->DISCUSSION->getMsgsContentWithTex($postId) as $comment) {
         $formules = array_merge($formules, TexImager::inst()->extractTexImages($comment));
     }
     return $formules;
 }
Example #2
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $hash = $params->str('hash');
     $tex = TexImager::inst()->decodeTexFromHash($hash);
     return $tex ? new AjaxSuccess($tex) : "Нет формулы с хэш-кодом [{$hash}]";
 }
Example #3
0
 /**
  * Вызывается после компиляции и выполнения макета, но до показа пользователю.
  * TODO - функция вызывается довольно часто, и было бы не плохо вызывать её как можно реже
  * Метод сделан статическим, чтобы его можно было вызвать отдельно, но ьез необходимости создавать объект Smarty.
  */
 public static function output($source)
 {
     return TexImager::inst()->replaceInText($source);
 }
Example #4
0
 /**
  * Основной метод, выполняющий загрузку содержимого тестовой страницы
  */
 private function getContentImpl(RequestArrayAdapter $params, Smarty $smarty)
 {
     //Силовые упражнения
     $exId = $params->int('ex_id');
     if ($exId) {
         //$ex = GymManager::getInstance()->getExercise($exId);
         $tplPath = "gym/exercises/{$exId}.tpl";
         return $smarty->templateExists($tplPath) ? $smarty->fetch($tplPath) : null;
     }
     //Специальные страницы
     $pageType = $params->str('pagetype');
     if ($pageType) {
         $smParams = array();
         switch ($pageType) {
             case 'smarty':
                 foreach (array('blocks', 'functions', 'modifiers') as $type) {
                     $items = DirManager::smarty('plugins/' . $type)->getDirContentFull(null, PsConst::EXT_PHP);
                     /* @var $item DirItem */
                     foreach ($items as $item) {
                         //Название
                         $name = explode('.', $item->getName());
                         $name = $name[1];
                         //Первый комментарий
                         $tokens = token_get_all($item->getFileContents());
                         $comment = array(T_COMMENT, T_DOC_COMMENT);
                         $fileComment = '';
                         foreach ($tokens as $token) {
                             if (in_array($token[0], $comment)) {
                                 $fileComment = trim($token[1]);
                                 break;
                             }
                         }
                         $smParams[$type][] = array('name' => $name, 'comment' => $fileComment);
                     }
                 }
                 break;
             case 'doubleimg':
                 $images = DirManager::images()->getDirContentFull(null, DirItemFilter::IMAGES);
                 $sorted = array();
                 /* @var $img DirItem */
                 foreach ($images as $img) {
                     $ident = $img->getSize() . 'x' . $img->getImageAdapter()->getWidth() . 'x' . $img->getImageAdapter()->getHeight();
                     $sorted[$ident][] = $img;
                 }
                 $result = array();
                 /* @var $img DirItem */
                 foreach ($sorted as $ident => $imgs) {
                     if (count($imgs) > 1) {
                         $result[$ident] = $imgs;
                     }
                 }
                 $smParams = array('images' => $result);
                 break;
             case 'testmethods':
                 $smParams['methods'] = TestManagerCaller::getMethodsList();
                 break;
             case 'imgbysize':
                 $images = DirManager::images()->getDirContentFull(null, DirItemFilter::IMAGES, array('GymExercises'));
                 DirItemSorter::inst()->sort($images, DirItemSorter::BY_SIZE);
                 $smParams = array('images' => $images);
                 break;
             case 'formules':
                 $formules = TexImager::inst()->getAllFormules();
                 $totalSize = 0;
                 /* @var $formula DirItem */
                 foreach ($formules as $formula) {
                     $totalSize += $formula->getSize();
                     $formula->setData('class', 'TeX');
                 }
                 DirItemSorter::inst()->sort($formules, DirItemSorter::BY_SIZE);
                 $smParams = array('formules' => $formules, 'formules_size' => $totalSize);
                 break;
         }
         $content = $smarty->fetch("test/page_{$pageType}.tpl", $smParams);
         if ($pageType) {
             switch ($pageType) {
                 case 'patterns':
                     $out = array();
                     preg_match_all("/===(.*?)===/", $content, $out, PREG_PATTERN_ORDER);
                     $params = array();
                     for ($i = 0; $i < count($out[0]); $i++) {
                         $full = $out[0][$i];
                         $ctt = $out[1][$i];
                         $params[$full] = "<div class=\"demo-head\">{$ctt}</div>";
                     }
                     $content = PsStrings::replaceMap($content, $params);
             }
         }
         return $content;
     }
     //Тестовая страница
     $num = $params->int('num');
     $num = $num ? $num : 1;
     return $smarty->fetch("test/page{$num}.tpl");
 }
Example #5
0
 public function doProcess(ArrayAdapter $params)
 {
     $texHash = $params->str('hash');
     $this->params['formula'] = $texHash ? '\\[' . TexImager::inst()->decodeTexFromHash($texHash) . '\\]' : '';
 }
Example #6
0
 public function getPostFormules($ident)
 {
     return TexImager::inst()->extractTexImages($this->POST_FOLDING->getTplDi($ident)->getFileContents());
 }
Example #7
0
 /** @return DirItem */
 public function export2zip($ident)
 {
     $this->assertExistsEntity($ident);
     $this->assertAdminCanDo(__FUNCTION__, $ident);
     $ftype = $this->getFoldingType();
     $fsubtype = $this->getFoldingSubType();
     $name = "{$ftype}-{$fsubtype}-{$ident}";
     $zipDi = $this->getAutogenDi($ident, null, $name, 'zip')->remove();
     $zip = $zipDi->startZip();
     /*
      * Экспортировать будем всё содержимое + извлечём формулы из .tpl
      */
     $ITEMS = $this->getResourcesDm($ident)->getDirContentFull();
     if ($this->isAllowedResourceType(self::RTYPE_TPL)) {
         $ITEMS[] = TexImager::inst()->extractTexImages($this->getResourceDi($ident, self::RTYPE_TPL)->getFileContents(false), false, true);
     }
     $this->addZipContents($zip, $ITEMS);
     $secret = $this->ZIP_SECRET;
     $sign = md5("{$name}-{$secret}");
     $comment = "{$name};{$sign}";
     $zip->setArchiveComment($comment);
     $zip->close();
     return $zipDi;
 }
Example #8
0
 /**
  * Вызывается после компиляции макета (построения php-файла).
  * Может быть переопределён в наследнике.
  * 
  * @param string $source - "сырой" код шаблона
  * @param Smarty_Internal_Template $template
  */
 protected function outputImpl($source, Smarty_Internal_Template $template)
 {
     if (PsDefines::isReplaceFormulesWithImages()) {
         return TexImager::inst()->replaceInText($source);
     }
     return $source;
 }
Example #9
0
 public final function teximg()
 {
     $src = TexImager::inst()->getImgDi('\\sin(\\alpha+\\beta)')->getRelPath();
     return "Ps plugin included. <img src='{$src}'/>";
 }