コード例 #1
0
/**
* Lite Publisher
* Copyright (C) 2010 - 2015 Vladimir Yushko http://litepublisher.ru/ http://litepublisher.com/
* Dual licensed under the MIT (mit.txt)
* and GPL (gpl.txt) licenses.
**/
function tpollsInstall($self)
{
    $name = basename(dirname(__FILE__));
    $res = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR;
    $dir = litepublisher::$paths->data . 'polls';
    @mkdir($dir, 0777);
    @chmod($dir, 0777);
    $manager = tdbmanager::i();
    $manager->createtable($self->table, file_get_contents($res . 'polls.sql'));
    $manager->createtable($self->users1, file_get_contents($res . 'users.sql'));
    $manager->createtable($self->users2, file_get_contents($res . 'users.sql'));
    $manager->createtable($self->votes, file_get_contents($res . 'votes.sql'));
    tlocalmerger::i()->addplugin($name);
    $lang = tlocal::admin('poll');
    tjsonserver::i()->addevent('polls_sendvote', get_class($self), 'polls_sendvote');
    $jsmerger = tjsmerger::i();
    $jsmerger->lock();
    $jsmerger->add('default', '/plugins/polls/polls.client.min.js');
    $jsmerger->addtext('default', 'poll', sprintf('var lang = $.extend(true, lang, {poll: %s});', json_encode(array('voted' => $lang->voted))));
    $jsmerger->unlock();
    tcssmerger::i()->addstyle(dirname(__FILE__) . '/stars.min.css');
    $lang = tlocal::admin('polls');
    litepublisher::$classes->add('tpolltypes', 'poll.types.php', $name);
    litepublisher::$classes->add('tpollsman', 'polls.man.php', $name);
    litepublisher::$classes->add('tpullpolls', 'pullpolls.class.php', $name);
    litepublisher::$classes->add('tadminpolltemplates', 'admin.poll.templates.php', $name);
    litepublisher::$classes->add('tadminpolltypes', 'admin.poll.types.php', $name);
    litepublisher::$classes->add('tadminpolloptions', 'admin.polloptions.class.php', $name);
    litepublisher::$classes->add('tadminpolls', 'admin.polls.class.php', $name);
    $adminmenus = tadminmenus::i();
    $adminmenus->lock();
    $parent = $adminmenus->createitem($adminmenus->url2id('/admin/plugins/'), 'polls', 'editor', 'tadminpolls');
    $adminmenus->items[$parent]['title'] = $lang->polls;
    $idmenu = $adminmenus->createitem($parent, 'templates', 'editor', 'tadminpolltemplates');
    $adminmenus->items[$idmenu]['title'] = $lang->templates;
    $idmenu = $adminmenus->createitem($parent, 'prototypes', 'editor', 'tadminpolltypes');
    $adminmenus->items[$idmenu]['title'] = $lang->prototypes;
    $idmenu = $adminmenus->createitem($parent, 'options', 'admin', 'tadminpolloptions');
    $adminmenus->items[$idmenu]['title'] = $lang->options;
    $adminmenus->unlock();
    //add sample templates
    $man = tpollsman::i();
    $man->lock();
    $man->fivestars = $self->add_tml('star', $lang->fivestars, $lang->poll, array(1, 2, 3, 4, 5));
    $man->pollpost = $man->fivestars;
    $btn = $self->add_tml('bigbutton', $lang->likepoll, $lang->poll, array($lang->like, $lang->unlike));
    if (litepublisher::$classes->exists('ttickets')) {
        $man->pollpost = $btn;
    }
    $man->unlock();
}
コード例 #2
0
 public function setadddtopost($v)
 {
     $man = tpollsman::i();
     if ($v == $man->addtopost) {
         return;
     }
     $man->data['addtopost'] = $v;
     $man->save();
     $posts = tposts::i();
     if ($v) {
         $posts->added = $man->postadded;
         $posts->deleted = $man->postdeleted;
         $posts->aftercontent = $man->afterpost;
         $posts->syncmeta = true;
     } else {
         $posts->delete_event_class('added', get_class($man));
         $posts->delete_event_class('deleted', get_class($man));
         $posts->delete_event_class('aftercontent', get_class($man));
     }
 }
コード例 #3
0
 public function getcontent()
 {
     $result = '';
     $polls = tpolls::i();
     $html = tadminhtml::i();
     $lang = tlocal::admin('polls');
     $args = new targs();
     $adminurl = $this->adminurl;
     if ($action = $this->action) {
         $id = $this->idget();
         switch ($action) {
             case 'delete':
                 if ($this->confirmed) {
                     $polls->delete($id);
                     $result .= $html->h4->deleted;
                 } else {
                     $result .= $html->confirmdelete($id, $adminurl, $lang->confirmdelete);
                 }
                 break;
             case 'edit':
                 if (!$polls->itemexists($id)) {
                     $result .= $this->notfound();
                 } else {
                     $result .= sprintf($html->h4->shorttag, $id);
                     $item = $polls->getitem($id);
                     $args->status = $this->getcombostatus($item['status']);
                     $args->id_tml = $this->getcombotml($item['id_tml']);
                     $args->id = $id;
                     $args->formtitle = $lang->editpoll;
                     $result .= $html->adminform('[combo=status]
       [combo=id_tml]
       ', $args);
                 }
                 break;
             case 'add':
                 $args->status = $this->getcombostatus('opened');
                 $args->id_tml = $this->getcombotml(tpollsman::i()->pollpost);
                 $args->formtitle = $lang->addpoll;
                 $result .= $html->adminform('[combo=status]
     [combo=id_tml]
     ', $args);
                 break;
             case 'create':
                 $args->status = $this->getcombostatus('opened');
                 $args->status = '';
                 $args->title = '';
                 $types = array_keys(tpolltypes::i()->items);
                 $args->type = tadminhtml::array2combo(array_combine($types, $types), $types[0]);
                 $args->newitems = '';
                 $args->formtitle = $lang->createpoll;
                 $result .= $html->adminform('[combo=status]
     [text=name]
     [text=title]
     [combo=type]
     [editor=newitems]
     ', $args);
                 break;
         }
     }
     $result .= "<ul>\n    <li><a href='{$adminurl}=0&amp;action=add'>{$lang->addpoll}</a></li>\n    <li><a href='{$adminurl}=0&amp;action=create'>{$lang->createpoll}</a></li>\n    </ul>";
     $args->adminurl = $adminurl;
     $table = '';
     $tr = '<tr>
 <td><a href="$adminurl=$id&amp;action=edit">$name</a></td>
 <td><a href=$adminurl=$id&amp;action=delete">$lang.delete</a></td>
 </tr>';
     $perpage = 20;
     $count = $polls->db->getcount();
     $from = $this->getfrom($perpage, $count);
     $items = $polls->select('', " order by id desc limit {$from}, {$perpage}");
     $result .= sprintf($html->h4->count, $from, $from + count($items), $count);
     foreach ($items as $id) {
         $item = $polls->getitem($id);
         $args->id = $id;
         $args->add($item);
         $tml = $polls->get_tml($item['id_tml']);
         $args->name = $tml['name'];
         $args->title = $tml['title'];
         $table .= $html->parsearg($tr, $args);
     }
     $head = "<tr>\n    <th>{$lang->edit}</th>\n    <th>{$lang->delete}</th>\n    </tr>";
     $result .= $html->gettable($head, $table);
     $theme = ttheme::i();
     $result .= $theme->getpages($this->url, litepublisher::$urlmap->page, ceil($count / $perpage));
     return $result;
 }
コード例 #4
0
 public function getcontent()
 {
     $result = '';
     $polls = tpolls::i();
     $html = tadminhtml::i();
     $lang = tlocal::admin('polls');
     $args = new targs();
     $dir = litepublisher::$paths->data . 'polls';
     $adminurl = $this->adminurl;
     if ($action = $this->action) {
         $id = $this->idget();
         switch ($action) {
             case 'delete':
                 $man = tpollsman::i();
                 if ($id == $man->pollpost) {
                     return $html->h4->deletepullpost;
                 }
                 if ($this->confirmed) {
                     tfilestorage::delete($dir . DIRECTORY_SEPARATOR . "{$id}.php");
                     tfilestorage::delete($dir . DIRECTORY_SEPARATOR . "{$id}.bak.php");
                     unset($polls->tml_items[$id]);
                     $polls->db->update('id_tml = ' . $man->pollpost, "id_tml = {$id}");
                     $result .= $html->h4->deleted;
                 } else {
                     $result .= $html->confirmdelete($id, $adminurl, $lang->confirmdelete);
                 }
                 break;
             case 'edit':
                 if ($tml = $polls->get_tml($id)) {
                     $args->add($tml);
                     $args->id = $id;
                     $args->name = tcontentfilter::unescape($tml['name']);
                     $args->title = tcontentfilter::unescape($tml['title']);
                     //$args->items = implode("\n", $tml['items']);
                     $tabs = new tuitabs();
                     //$tabs->add($lang->pollitems, "[editor=items]");
                     $tabs->add($lang->opened, "[editor=opened]");
                     $tabs->add($lang->closed, "[editor=closed]");
                     $args->formtitle = $lang->edittemplate;
                     $result .= $html->adminform('
       [text=name]
       [text=title]' . $tabs->get(), $args);
                 }
                 break;
             case 'add':
                 $types = array_keys(tpolltypes::i()->items);
                 $args->type = tadminhtml::array2combo(array_combine($types, $types), $types[0]);
                 $args->name = '';
                 $args->title = '';
                 $args->newitems = '';
                 $args->formtitle = $lang->newtemplate;
                 $result .= $html->adminform('[text=name]
     [text=title]
     [combo=type]
     [editor=newitems]', $args);
                 break;
         }
     }
     $result .= $html->h3("<a href='{$adminurl}=0&amp;action=add'>{$lang->addtemplate}</a>");
     $result .= $html->h4->alltemplates;
     $args->adminurl = $adminurl;
     $table = '';
     $tr = '<tr>
 <td><a href="$adminurl=$id&amp;action=edit">$name</a></td>
 <td><a href="$adminurl=$id&amp;action=delete">$lang.delete</a></td>
 </tr>';
     $polls->loadall_tml();
     foreach ($polls->tml_items as $id => $tml) {
         $args->id = $id;
         $args->name = $tml['name'];
         $args->title = $tml['title'];
         $table .= $html->parsearg($tr, $args);
     }
     $head = "<tr>\n    <th>{$lang->edit}</th>\n    <th>{$lang->delete}</th>\n    </tr>";
     $result .= $html->gettable($head, $table);
     return $result;
 }
コード例 #5
0
ファイル: polls.class.php プロジェクト: laiello/litepublisher
 public function edit($id, $id_tml, $status)
 {
     return tpollsman::i()->edit($id, $id_tml, $status);
 }