Esempio n. 1
0
 function run()
 {
     global $_out;
     $mysql = new mysql();
     $row = filter_var(param('row'), FILTER_VALIDATE_INT);
     if (($rs = $mysql->query('select * from `' . $mysql->getTableName($this->table) . '` where ' . '`section`="' . $this->getSection()->getId() . '" and `module`="' . $this->getConf('module', true) . '" and `id_article`=' . ($row ? $row : 0))) && ($r = $mysql->fetch($rs))) {
         if ($v = $r['title']) {
             $_out->setMeta('title', $v);
         }
         if ($v = $r['keywords']) {
             $_out->setMeta('keywords', $v);
         }
         if ($v = $r['description']) {
             $_out->setMeta('description', $v);
         }
         if (($v = $r['h1']) && ($e = $_out->query('/page/section')->item(0))) {
             $e->setAttribute('h1', $v);
         }
     }
 }
Esempio n. 2
0
 function uninstall()
 {
     $mysql = new mysql();
     if ($md = $this->getConf('module')) {
         $mysql->query('delete from `' . $mysql->getTableName($this->table) . '` where `section`="' . $this->getSection()->getID() . '" AND `module`="' . $md . '"');
     }
     if ($sec = ap::getClientSection($this->getSection()->getId())) {
         $modules = $sec->getModules();
         if ($modules->remove($this->getId())) {
             $modules->getXML()->save();
         }
         return true;
     }
 }
Esempio n. 3
0
 function uninstall()
 {
     $mysql = new mysql();
     $table = $this->table;
     if ($rs = $mysql->query('select * from `' . $mysql->getTableName($table) . '` where `section`="' . $this->getSection()->getID() . '" AND `module`="' . $this->getId() . '"')) {
         while ($r = mysql_fetch_array($rs)) {
             $this->deleteRow($r['id']);
         }
     }
     if ($sec = ap::getClientSection($this->getSection()->getId())) {
         $modules = $sec->getModules();
         if ($modules->remove($this->getId())) {
             $modules->getXML()->save();
         }
         return true;
     }
 }
Esempio n. 4
0
    function getNextSortIndex($form)
    {
        $mysql = new mysql();
        $index = 1;
        $rs = $mysql->query('select max(`sort`)+1 as `new_sort_index`
		from `' . $mysql->getTableName($form->getAttribute('dbTable')) . '`
		where `section`="' . $this->getName() . '" AND `module`="' . $this->getId() . '"');
        if ($rs && ($row = mysql_fetch_assoc($rs)) && $row['new_sort_index']) {
            $index = $row['new_sort_index'];
        }
        return $index;
    }
Esempio n. 5
0
    /**
    * Картинки
    */
    static function getImages($id, $preview = false, $limit = null)
    {
        global $_out;
        if (!is_array($id)) {
            $id = array($id);
        }
        if (!count($id)) {
            return;
        }
        $res = array();
        $mysql = new mysql();
        $counter = array();
        if ($rs = $mysql->query('SELECT img.*,art.section,art.module
FROM `' . $mysql->getTableName('articles_images') . '` AS img
LEFT JOIN `' . $mysql->getTableName('articles') . '` AS art ON art.id=img.id_article
WHERE `id_article` IN (' . implode(',', $id) . ') AND img.`active`=1
ORDER BY `id_article`,`sort`')) {
            while ($r = mysql_fetch_assoc($rs)) {
                if ($limit > 0) {
                    if (!isset($counter[$r['id_article']])) {
                        $counter[$r['id_article']] = 0;
                    }
                    if ($counter[$r['id_article']] >= $limit) {
                        continue;
                    }
                    $counter[$r['id_article']]++;
                }
                $v = array();
                if (is_file($path = 'userfiles/articles/' . $r['section'] . '/' . $r['id'] . '.jpg')) {
                    list($width, $height) = getimagesize($path);
                    $v['img'] = $_out->createElement('img', array('id' => $r['id'], 'src' => $path, 'width' => $width, 'height' => $height));
                    if ($r['title']) {
                        $v['img']->setAttribute('alt', $r['title']);
                    }
                }
                if ($preview && is_file($path = 'userfiles/articles/' . $r['section'] . '/' . $r['id'] . ($preview ? '_preview' : null) . '.jpg')) {
                    list($width, $height) = getimagesize($path);
                    $v['prv'] = $_out->createElement('preview', array('src' => $path, 'width' => $width, 'height' => $height));
                    if ($r['title']) {
                        $v['prv']->setAttribute('alt', $r['title']);
                    }
                }
                if (count($v)) {
                    $res[$r['id_article']][] = $v;
                }
            }
        }
        return $res;
    }
Esempio n. 6
0
 function fixedFields($form)
 {
     global $_sec;
     $clientSection = ap::getClientSection($_sec->getId());
     $md = $clientSection->getXML()->getElementById($this->getId());
     if ($clientSection->getXML()->evaluate('string(./form[1]/@dbSave)', $md) && ($dbConnect = $clientSection->getXML()->evaluate('string(./form[1]/@dbConnect)', $md)) && ($dbTable = $clientSection->getXML()->evaluate('string(./form[1]/@dbTable)', $md)) && ($ff = $form->appendField(formSelect::create('uri', 'Database field name:', '/@uri')))) {
         $ff->addOption('', '...');
         $mysql = new mysql($dbConnect);
         $q = 'SHOW COLUMNS FROM ' . $mysql->getTableName($dbTable);
         $rs = $mysql->query($q);
         while ($res = mysql_fetch_assoc($rs)) {
             if (!$res['Extra']) {
                 $ff->addOption($res['Field'], $res['Field']);
             }
         }
     }
 }
Esempio n. 7
0
 function getTableName()
 {
     $params = mysqllist::getParams($this->params);
     $mysql = new mysql($params['con']);
     return $mysql->getTableName($params['table']);
 }
Esempio n. 8
0
 function getRow($con, $table, $cond)
 {
     if (isset($cache[$con][$table][$cond])) {
         return $cache[$con][$table][$cond];
     }
     if ($table && $cond) {
         $mysql = new mysql($con);
         $query = 'SELECT * FROM `' . $mysql->getTableName($table) . '` WHERE ' . $cond;
         if ($rs = $mysql->query($query)) {
             return $cache[$con][$table][$cond] = mysql_fetch_assoc($rs);
         }
     }
 }
Esempio n. 9
0
 private function load($id_article)
 {
     $mysql = new mysql();
     $values = $this->getSubmitImages();
     $isUpdate = is_array($values);
     $arId = $isUpdate ? array_keys($values['exist']) : array();
     if (($rs = $mysql->query('select `id`,`title` from `' . $mysql->getTableName($this->getTable()) . '` where `id_article`=' . $id_article . ' and `field_name`="' . addslashes($this->ff->getName()) . '"' . (count($arId) ? ' and `id` not in(' . implode(',', $arId) . ')' : null) . ' order by `sort`')) && mysql_num_rows($rs)) {
         $rowsToDelete = array();
         while ($r = mysql_fetch_assoc($rs)) {
             $fieldName = $this->fieldName($r['id']);
             if ($isUpdate) {
                 $this->values[$fieldName] = jpgScheme::VALUE_DELETE;
                 $rowsToDelete[] = $r['id'];
             }
             foreach ($this->formats as $param) {
                 if (!$isUpdate && !$param->hasAttribute('preview')) {
                     continue;
                 }
                 $e = $this->ff->getRootElement()->appendChild($param->cloneNode(true));
                 $e->setAttribute('name', $fieldName);
                 $e->setAttribute('uri', str_replace('%IMG_ID%', $r['id'], $e->getAttribute('uri')));
                 if ($r['title']) {
                     $e->setAttribute('title', $r['title']);
                 }
             }
         }
         if ($isUpdate && count($rowsToDelete)) {
             $mysql->query('delete from `' . $mysql->getTableName($this->getTable()) . '` where id in(' . implode(',', $rowsToDelete) . ')');
         }
     }
     if ($isUpdate) {
         $v = array();
         foreach ($this->sortOrder as $i => $str) {
             if (preg_match('/id([0-9]+)/', $str, $m)) {
                 $v[$m[1]] = '(' . $m[1] . ',"' . addslashes($values['exist'][$m[1]]['title']) . '",' . ($i + 1) . ')';
             }
         }
         //vdump($values);
         if (count($v)) {
             $mysql->query('insert into `' . $mysql->getTableName($this->getTable()) . '` (`id`,`title`,`sort`) values ' . implode(',', $v) . ' on duplicate key update `title`=values(`title`),`sort`=values(`sort`)');
         }
     }
 }