Example #1
4
 public function get($limit = 1024)
 {
     header('Content-Type: application/json');
     $dates = json_decode(file_get_contents('hoa://Application/Database/Dates.json'), true);
     echo json_encode(array_slice($dates, 0, $limit));
     return;
 }
Example #2
1
/**
 * Function used to auto load the framework classes
 * 
 * It imlements PSR-0 and PSR-4 autoloading standards
 * The required class name should be prefixed with a namespace
 * This lowercaser of the namespace should match the folder name of the class 
 * 
 * @since 1.0.0
 * @param string $class_name name of the class that needs to be included
 */
function autoload_framework_classes($class_name)
{
    error_reporting(E_ALL);
    ini_set('display_errors', true);
    ini_set('display_startup_errors', true);
    /** If the required class is in the global namespace then no need to autoload the class */
    if (strpos($class_name, "\\") === false) {
        return false;
    }
    /** The namespace seperator is replaced with directory seperator */
    $class_name = str_replace("\\", DIRECTORY_SEPARATOR, $class_name);
    /** The class name is split into namespace and short class name */
    $path_info = explode(DIRECTORY_SEPARATOR, $class_name);
    /** The namepsace is extracted */
    $namespace = implode(DIRECTORY_SEPARATOR, array_slice($path_info, 0, count($path_info) - 1));
    /** The class name is extracted */
    $class_name = $path_info[count($path_info) - 1];
    /** The namespace is converted to lower case */
    $namespace_folder = trim(strtolower($namespace), DIRECTORY_SEPARATOR);
    /** .php is added to class name */
    $class_name = $class_name . ".php";
    /** The applications folder name */
    $framework_folder_path = realpath(dirname(__FILE__));
    /** The application folder is checked for file name */
    $file_name = $framework_folder_path . DIRECTORY_SEPARATOR . $namespace_folder . DIRECTORY_SEPARATOR . $class_name;
    if (is_file($file_name)) {
        include_once $file_name;
    }
}
Example #3
1
 /**
  * Execute requested action
  */
 public function execute()
 {
     $method = $_SERVER['REQUEST_METHOD'];
     $verbs = $this->verbs();
     if (isset($verbs[$this->requestMethod])) {
         $action = 'action' . ucfirst(mb_strtolower($verbs[$method]));
         $reflectionMethod = new \ReflectionMethod($this, $action);
         $parsePath = array_slice($this->path, count($this->route));
         $args = [];
         $errors = [];
         if ($params = $reflectionMethod->getParameters()) {
             foreach ($params as $key => $param) {
                 if (isset($parsePath[$key])) {
                     $args[$param->name] = $parsePath[$key];
                 } else {
                     $errors[] = ['code' => 'required', 'message' => ucfirst(mb_strtolower(explode('_', $param->name)[0])) . ' cannot be blank.', 'name' => $param->name];
                 }
             }
             if ($errors) {
                 throw new \phantomd\ShopCart\modules\base\HttpException(400, 'Invalid data parameters', 0, null, $errors);
             }
         }
         if (count($parsePath) === count($params)) {
             return call_user_func_array([$this, $action], $args);
         }
     }
     throw new HttpException(404, 'Unable to resolve the request "' . $this->requestPath . '".', 0, null, $errors);
 }
Example #4
1
 /**
  *
  * @see XenForo_Route_PrefixAdmin_AddOns::match()
  */
 public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
 {
     $parts = explode('/', $routePath, 3);
     switch ($parts[0]) {
         case 'languages':
             $parts = array_slice($parts, 1);
             $routePath = implode('/', $parts);
             $action = $router->resolveActionWithIntegerParam($routePath, $request, 'language_id');
             return $router->getRouteMatch('XenForo_ControllerAdmin_Language', $action, 'languages');
         case 'phrases':
             $parts = array_slice($parts, 1);
             $routePath = implode('/', $parts);
             return $router->getRouteMatch('XenForo_ControllerAdmin_Phrase', $routePath, 'phrases');
     }
     if (count($parts) > 1) {
         switch ($parts[1]) {
             case 'languages':
                 $action = $router->resolveActionWithStringParam($routePath, $request, 'addon_id');
                 $parts = array_slice($parts, 2);
                 $routePath = implode('/', $parts);
                 $action = $router->resolveActionWithIntegerParam($routePath, $request, 'language_id');
                 return $router->getRouteMatch('XenForo_ControllerAdmin_Language', $action, 'languages');
             case 'phrases':
                 $action = $router->resolveActionWithStringParam($routePath, $request, 'addon_id');
                 $parts = array_slice($parts, 2);
                 $routePath = implode('/', $parts);
                 return $router->getRouteMatch('XenForo_ControllerAdmin_Phrase', $routePath, 'phrases');
         }
     }
     return parent::match($routePath, $request, $router);
 }
 function display(&$args, $request)
 {
     $templateMgr =& TemplateManager::getManager();
     parent::display($args, $request);
     $issueDao =& DAORegistry::getDAO('IssueDAO');
     $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
     $articleGalleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
     $journal =& Request::getJournal();
     switch (array_shift($args)) {
         case 'exportGalley':
             $articleId = array_shift($args);
             $galleyId = array_shift($args);
             $article =& $publishedArticleDao->getPublishedArticleByArticleId($articleId);
             $galley =& $articleGalleyDao->getGalley($galleyId, $articleId);
             if ($article && $galley && ($issue =& $issueDao->getIssueById($article->getIssueId(), $journal->getId()))) {
                 $this->exportArticle($journal, $issue, $article, $galley);
                 break;
             }
         default:
             // Display a list of articles for export
             $this->setBreadcrumbs();
             AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION);
             $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
             $rangeInfo = Handler::getRangeInfo('articles');
             $articleIds = $publishedArticleDao->getPublishedArticleIdsAlphabetizedByJournal($journal->getId(), false);
             $totalArticles = count($articleIds);
             $articleIds = array_slice($articleIds, $rangeInfo->getCount() * ($rangeInfo->getPage() - 1), $rangeInfo->getCount());
             import('lib.pkp.classes.core.VirtualArrayIterator');
             $iterator = new VirtualArrayIterator(ArticleSearch::formatResults($articleIds), $totalArticles, $rangeInfo->getPage(), $rangeInfo->getCount());
             $templateMgr->assign_by_ref('articles', $iterator);
             $templateMgr->display($this->getTemplatePath() . 'index.tpl');
             break;
     }
 }
Example #6
0
 /** (non-PHPdoc)
  * @see IfwPsn_Wp_Plugin_Admin_Menu_ListTable_Data_Interface::getItems()
  */
 public function getItems($limit, $page, $order = null, $where = null)
 {
     $offset = ($page - 1) * $limit;
     if (empty($order)) {
         $order = array('name' => 'asc');
     }
     $data = IfwPsn_Wp_ORM_Model::factory('Psn_Model_Rule')->limit($limit)->offset($offset);
     if (!empty($order)) {
         $orderBy = key($order);
         $orderDir = $order[$orderBy];
         if ($orderDir == 'desc') {
             $data->order_by_desc($orderBy);
         } else {
             $data->order_by_asc($orderBy);
         }
     }
     if (!empty($where)) {
         $data->where_like('name', '%' . $where . '%');
     }
     $result = $data->find_array();
     if (Psn_Model_Rule::hasMax()) {
         $result = array_slice($result, 0, Psn_Model_Rule::getMax());
     }
     return $result;
 }
 public function get_datas()
 {
     //on commence par récupérer l'identifiant retourné par le sélecteur...
     if ($this->parameters['selector'] != "") {
         for ($i = 0; $i < count($this->selectors); $i++) {
             if ($this->selectors[$i]['name'] == $this->parameters['selector']) {
                 $selector = new $this->parameters['selector']($this->selectors[$i]['id']);
                 break;
             }
         }
         $bannettes = $selector->get_value();
         if (is_array($bannettes) && count($bannettes)) {
             foreach ($bannettes as $bannette_id) {
                 $records = $notices = array();
                 notices_bannette($bannette_id, $notices);
                 foreach ($notices as $id => $niv) {
                     $records[] = $id;
                 }
             }
         }
         $records = $this->filter_datas("notices", $records);
         $records = array_slice($records, 0, $this->parameters['nb_max_elements']);
         $return = array('title' => 'Liste de Notices', 'records' => $records);
         return $return;
     }
     return false;
 }
 public function get_paged_jobs()
 {
     $paged = isset($_GET['paged']) ? filter_var($_GET['paged'], FILTER_SANITIZE_NUMBER_INT) : '';
     $paged = $paged ? $paged : 1;
     $per_page = $this->jobs_per_page;
     return array_slice($this->translation_jobs, ($paged - 1) * $per_page, $per_page);
 }
Example #9
0
 protected static function _parse_doc_comment($comment)
 {
     // Normalize all new lines to \n
     $comment = str_replace(array("\r\n", "\n"), "\n", $comment);
     // Remove the phpdoc open/close tags and split
     $comment = array_slice(explode("\n", $comment), 1, -1);
     // Tag content
     $param = array();
     foreach ($comment as $i => $line) {
         // Remove all leading whitespace
         $line = preg_replace('/^\\s*\\* ?/m', '', $line);
         // Search this line for a tag
         if (preg_match('/^@(\\S+)(?:\\s*(.+))?$/', $line, $matches)) {
             // This is a tag line
             unset($comment[$i]);
             $name = $matches[1];
             $text = isset($matches[2]) ? $matches[2] : '';
             if ($text && $name == 'param') {
                 // Add the tag
                 $param[] = $text;
             } else {
                 continue;
             }
         } else {
             // Overwrite the comment line
             $comment[$i] = (string) $line;
         }
     }
     return array('title' => $comment, 'param' => $param);
 }
 /**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function index()
 {
     $gallery = Page::where('slug', '=', 'gallery')->first();
     $images = explode(',', $gallery->content);
     $images = array_slice($images, 0, 16);
     return view('frontend.index', ['images' => $images]);
 }
 /**
  * 用户去向 add
  */
 public function add($user_id = NULL, $shop_id = NULL)
 {
     if (IS_POST) {
         /* 定义变量 */
         $model = D(CONTROLLER_NAME);
         $result = $model->do_add();
         /* 返回信息 */
         if ($result) {
             /* 关注的人收到通知 */
             // 获取关注你的人
             $where_attention['user_attention.to_user_id'] = array('EQ', $user_id);
             $where_attention['user.push_id'] = array('NEQ', '');
             $where_attention['user.status'] = array('EQ', 1);
             $where_attention['user.display'] = array('EQ', 1);
             $where_attention['user.trace_notify'] = array('EQ', 1);
             $attention_user_id = M('UserAttention')->alias('user_attention')->field('user.push_id')->where($where_attention)->join('__USER__ user on user_attention.user_id = user.id')->select();
             if ($attention_user_id) {
                 // 获取去向资料
                 $data_shop_user_went = get_shop_user_went($user_id, $shop_id);
                 if ($data_shop_user_went) {
                     foreach ($attention_user_id as $k => $v) {
                         $push_id[] = $v['push_id'];
                     }
                     $push_id = array_filter(array_unique(array_slice($push_id, 0, 1000)));
                     $this->push_one($push_id, $data_shop_user_went);
                 }
             }
             $this->ajaxReturn(array('RESPONSE_STATUS' => 100, 'Tips' => L('YZ_return_success')));
         } else {
             $this->return_post($model);
         }
     }
     $this->ajaxReturn(array('RESPONSE_STATUS' => 500, 'Tips' => L('YZ_return_failure')));
 }
Example #12
0
 /**
  * Duplicated from the admin controller to give a user list.
  *
  * @TODO: There's a method on the UserController that could be used, so would be worth consolidating)
  */
 public function actionUserFind()
 {
     $res = array();
     if (\Yii::app()->request->isAjaxRequest && !empty($_REQUEST['search'])) {
         $criteria = new \CDbCriteria();
         $criteria->compare('LOWER(username)', strtolower($_REQUEST['search']), true, 'OR');
         $criteria->compare('LOWER(first_name)', strtolower($_REQUEST['search']), true, 'OR');
         $criteria->compare('LOWER(last_name)', strtolower($_REQUEST['search']), true, 'OR');
         $words = explode(' ', $_REQUEST['search']);
         if (count($words) > 1) {
             // possibly slightly verbose approach to checking first and last name combinations
             // for searches
             $first_criteria = new \CDbCriteria();
             $first_criteria->compare('LOWER(first_name)', strtolower($words[0]), true);
             $first_criteria->compare('LOWER(last_name)', strtolower(implode(' ', array_slice($words, 1, count($words) - 1))), true);
             $last_criteria = new \CDbCriteria();
             $last_criteria->compare('LOWER(first_name)', strtolower($words[count($words) - 1]), true);
             $last_criteria->compare('LOWER(last_name)', strtolower(implode(' ', array_slice($words, 0, count($words) - 2))), true);
             $first_criteria->mergeWith($last_criteria, 'OR');
             $criteria->mergeWith($first_criteria, 'OR');
         }
         foreach (\User::model()->findAll($criteria) as $user) {
             $res[] = array('id' => $user->id, 'label' => $user->getFullNameAndTitle(), 'value' => $user->getFullName(), 'username' => $user->username);
         }
     }
     echo \CJSON::encode($res);
 }
Example #13
0
 function Folder(&$tdb, $arrayValues, $childInfo = FALSE, $nested = false)
 {
     $this->tdb = $tdb;
     $this->id = $arrayValues[0];
     $this->idParent = $arrayValues[1];
     $this->path = $arrayValues[2];
     $this->level = $arrayValues[3];
     $this->nested = $nested;
     if ($nested) {
         $this->iLeft = $arrayValues[4];
         $this->iRight = $arrayValues[5];
         if ($childInfo) {
             $this->otherValues = array_slice($arrayValues, 7);
             $this->countChildrens = $arrayValues[6];
         } else {
             if (is_array($arrayValues)) {
                 $this->otherValues = array_slice($arrayValues, 6);
                 $this->hasChildrens = NULL;
             }
         }
     } else {
         if ($childInfo) {
             $this->otherValues = array_slice($arrayValues, 5);
             $this->countChildrens = $arrayValues[4];
         } else {
             if (is_array($arrayValues)) {
                 $this->otherValues = array_slice($arrayValues, 4);
                 $this->hasChildrens = NULL;
             }
         }
     }
 }
 public function get_datas()
 {
     $selector = $this->get_selected_selector();
     if ($selector) {
         $query = "select distinct id_article,if(article_start_date != '0000-00-00 00:00:00',article_start_date,article_creation_date) as publication_date from cms_articles join cms_articles_descriptors on id_article=num_article where num_article != '" . $selector->get_value() . "' and num_noeud in (select num_noeud from cms_articles_descriptors where num_article = '" . $selector->get_value() . "')";
         if ($this->parameters["sort_by"] != "") {
             $query .= " order by " . $this->parameters["sort_by"];
             if ($this->parameters["sort_order"] != "") {
                 $query .= " " . $this->parameters["sort_order"];
             }
         }
         $result = pmb_mysql_query($query);
         $return = array();
         if (pmb_mysql_num_rows($result) > 0) {
             while ($row = pmb_mysql_fetch_object($result)) {
                 $return[] = $row->id_article;
             }
         }
         $return = $this->filter_datas("articles", $return);
         if ($this->parameters["nb_max_elements"] > 0) {
             $return = array_slice($return, 0, $this->parameters["nb_max_elements"]);
         }
         return $return;
     }
     return false;
 }
Example #15
0
 /**
  * Check whether scheduled task exists or not.
  *
  * @access protected
  * @param string $name Task name
  * @return boolean True is task exists.
  */
 public static function check($name)
 {
     $output = null;
     if (It::isLinux()) {
         exec('crontab -l | grep -i ' . $name, $output);
         //            return (is_array($output) && (count($output) > 0));
         if (is_array($output) && count($output) > 0) {
             return true;
         }
     } else {
         if (It::isWindows()) {
             exec('schtasks /query /nh /fo:CSV', $output);
             // strip header
             $output = array_slice($output, 1);
             if (count($output) > 0) {
                 foreach ($output as $csvLine) {
                     $lines = explode(',', $csvLine);
                     if (count($lines) > 1 && $lines[0] == '"' . $name . '"') {
                         return true;
                     }
                 }
             }
             return false;
         }
     }
     return false;
 }
Example #16
0
  function Render()
  {
    global $currentUser;
    if (!$currentUser)
      return;

    if (!$currentUser->CanSubmitItems())
      return;

    echo "\n\n";
    echo "<div class='pouettbl' id='".$this->uniqueID."'>\n";

    echo "  <h2>".$this->title."</h2>\n";
    echo "  <div class='content'>\n";

    $width = 15;

    $g = glob(POUET_CONTENT_LOCAL."avatars/*.gif");
    shuffle($g);
    $g = array_slice($g,0,$width * $width);

    echo "<ul id='avatargallery'>\n";
    foreach($g as $v)
      printf("  <li><img src='".POUET_CONTENT_URL."avatars/%s' alt='%s' title='%s'/></li>\n",basename($v),basename($v),basename($v));
    echo "</ul>\n";

    echo "  </div>\n";
    echo "</div>\n";
  }
Example #17
0
 /**
  * Checks the queue for matches to this request.
  * If a group can be formed, returns an array with the sessions that will form this group.
  * Otherwise, returns FALSE.
  *
  * @param GroupRequest $request
  * @return array<Session> if a group can be formed, FALSE otherwise
  */
 public function newRequest(GroupRequest $request)
 {
     // filter all requests that match this one
     $matches = array_filter($this->requests, function ($potential_match) use($request) {
         return !$potential_match->expired() && $request->match($potential_match);
     });
     if (count($matches) + 1 >= $request->size()) {
         // we have enough people to form a group!
         // get as many of the matches as we need for the group
         $selected_requests = array_slice($matches, 0, $request->size() - 1);
         // remove the fulfilled grouprequests from the queue
         $this->removeRequests($selected_requests);
         // get the sessions that will make up this group
         $sessions = array_map(function ($selected_request) {
             return $selected_request->session;
         }, $selected_requests);
         $sessions[] = $request->session;
         // don't forget the new request
         return $sessions;
     } else {
         // not enough requests matching this one
         // add this request to the queue
         $this->addRequest($request);
         return FALSE;
     }
 }
Example #18
0
 function apply_filters_ref_array($tag, $args)
 {
     global $wp_filter, $merged_filters, $wp_current_filter;
     // Do 'all' actions first
     if (isset($wp_filter['all'])) {
         $wp_current_filter[] = $tag;
         $all_args = func_get_args();
         _wp_call_all_hook($all_args);
     }
     if (!isset($wp_filter[$tag])) {
         if (isset($wp_filter['all'])) {
             array_pop($wp_current_filter);
         }
         return $args[0];
     }
     if (!isset($wp_filter['all'])) {
         $wp_current_filter[] = $tag;
     }
     // Sort
     if (!isset($merged_filters[$tag])) {
         ksort($wp_filter[$tag]);
         $merged_filters[$tag] = true;
     }
     reset($wp_filter[$tag]);
     do {
         foreach ((array) current($wp_filter[$tag]) as $the_) {
             if (!is_null($the_['function'])) {
                 $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
             }
         }
     } while (next($wp_filter[$tag]) !== false);
     array_pop($wp_current_filter);
     return $args[0];
 }
Example #19
0
 function do_main()
 {
     $notifications = (array) KTNotification::getList(array("user_id = ?", $this->oUser->getId()));
     $num_notifications = count($notifications);
     $PAGE_SIZE = 5;
     $page = (int) KTUtil::arrayGet($_REQUEST, 'page', 0);
     $page_count = ceil($num_notifications / $PAGE_SIZE);
     if ($page >= $page_count) {
         $page = $page_count - 1;
     }
     if ($page < 0) {
         $page = 0;
     }
     // slice the notification array.
     $notifications = array_slice($notifications, $page * $PAGE_SIZE, $PAGE_SIZE);
     // prepare the batch html.  easier to do this here than in the template.
     $batch = array();
     for ($i = 0; $i < $page_count; $i++) {
         if ($i == $page) {
             $batch[] = sprintf("<strong>%d</strong>", $i + 1);
         } else {
             $batch[] = sprintf('<a href="%s">%d</a>', KTUtil::addQueryStringSelf($this->meldPersistQuery(array("page" => $i), "main", true)), $i + 1);
         }
     }
     $batch_html = implode(' &middot; ', $batch);
     $count_string = sprintf(_kt("Showing Notifications %d - %d of %d"), $page * $PAGE_SIZE + 1, min(($page + 1) * $PAGE_SIZE, $num_notifications), $num_notifications);
     $this->oPage->setTitle(_kt("Items that require your attention"));
     $oTemplate =& $this->oValidator->validateTemplate("ktcore/misc/notification_overflow");
     $oTemplate->setData(array('count_string' => $count_string, 'batch_html' => $batch_html, 'notifications' => $notifications));
     return $oTemplate->render();
 }
 public function get_datas()
 {
     global $dbh;
     $return = array();
     $selector = $this->get_selected_selector();
     if ($selector) {
         $value = $selector->get_value();
         $records = array();
         if (is_array($value) && count($value)) {
             for ($i = 0; $i < count($value); $i++) {
                 $query = "select notice_id from notices where notice_id='" . $value[$i] . "'";
                 $result = pmb_mysql_query($query, $dbh);
                 if (pmb_mysql_num_rows($result) > 0) {
                     $row = pmb_mysql_fetch_object($result);
                     $records[] = $row->notice_id;
                 }
             }
             $records = array_reverse($records);
             $return['records'] = $this->filter_datas("notices", $records);
             if ($this->parameters['nb_max_elements'] > 0) {
                 $return['records'] = array_slice($return['records'], 0, $this->parameters['nb_max_elements']);
             }
         }
         return $return;
     }
     return false;
 }
Example #21
0
 protected function modelUserTag($limit)
 {
     $tags = Wekit::load('usertag.srv.PwUserTagService')->getUserTagList($this->spaceUid);
     $count = count($tags);
     $tags = is_array($tags) ? array_slice($tags, 0, $limit, true) : array();
     return array($count, $tags);
 }
Example #22
0
 function __construct()
 {
     // Extract the query from the tag chunk
     if (($sql = ee()->TMPL->fetch_param('sql')) === FALSE) {
         return FALSE;
     }
     // Rudimentary check to see if it's a SELECT query, most definitely not
     // bulletproof
     if (substr(strtolower(trim($sql)), 0, 6) != 'select') {
         return FALSE;
     }
     $query = ee()->db->query($sql);
     $results = $query->result_array();
     if ($query->num_rows() == 0) {
         return $this->return_data = ee()->TMPL->no_results();
     }
     // Start up pagination
     ee()->load->library('pagination');
     $pagination = ee()->pagination->create();
     ee()->TMPL->tagdata = $pagination->prepare(ee()->TMPL->tagdata);
     $per_page = ee()->TMPL->fetch_param('limit', 0);
     // Disable pagination if the limit parameter isn't set
     if (empty($per_page)) {
         $pagination->paginate = FALSE;
     }
     if ($pagination->paginate) {
         $pagination->build($query->num_rows(), $per_page);
         $results = array_slice($results, $pagination->offset, $pagination->per_page);
     }
     $this->return_data = ee()->TMPL->parse_variables(ee()->TMPL->tagdata, array_values($results));
     if ($pagination->paginate === TRUE) {
         $this->return_data = $pagination->render($this->return_data);
     }
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function add(ItemInterface $item, ItemInterface $before = null)
 {
     $hash = spl_object_hash($item);
     if ($before) {
         $hashes = array_keys($this->items);
         $beforeHash = spl_object_hash($before);
         $indexOf = array_search($beforeHash, $hashes);
         if ($indexOf === false) {
             throw new \InvalidArgumentException('The before item is not part of this collection');
         }
         $existingIndex = array_search($hash, $hashes);
         if ($existingIndex === false || $existingIndex != $indexOf - 1) {
             if ($existingIndex !== false) {
                 unset($this->items[$hash]);
                 if ($existingIndex < $indexOf) {
                     $indexOf = array_search($beforeHash, $hashes);
                 }
             }
             $this->items = array_merge(array_slice($this->items, 0, $indexOf), array($hash => $item), array_slice($this->items, $indexOf));
             if ($existingIndex === false) {
                 $item->setParentCollection($this);
             }
         }
     } else {
         if (!isset($this->items[$hash])) {
             $this->items[$hash] = $item;
             $item->setParentCollection($this);
         }
     }
     return $this;
 }
Example #24
0
 public function addCommandsFromClass($className, $passThrough = null)
 {
     $roboTasks = new $className();
     $commandNames = array_filter(get_class_methods($className), function ($m) {
         return !in_array($m, ['__construct']);
     });
     foreach ($commandNames as $commandName) {
         $command = $this->createCommand(new TaskInfo($className, $commandName));
         $command->setCode(function (InputInterface $input) use($roboTasks, $commandName, $passThrough) {
             // get passthru args
             $args = $input->getArguments();
             array_shift($args);
             if ($passThrough) {
                 $args[key(array_slice($args, -1, 1, TRUE))] = $passThrough;
             }
             $args[] = $input->getOptions();
             $res = call_user_func_array([$roboTasks, $commandName], $args);
             if (is_int($res)) {
                 exit($res);
             }
             if (is_bool($res)) {
                 exit($res ? 0 : 1);
             }
             if ($res instanceof Result) {
                 exit($res->getExitCode());
             }
         });
         $this->add($command);
     }
 }
 function build_editform($item, $feedback, $cm)
 {
     global $DB, $CFG;
     require_once 'multichoicerated_form.php';
     //get the lastposition number of the feedback_items
     $position = $item->position;
     $lastposition = $DB->count_records('feedback_item', array('feedback' => $feedback->id));
     if ($position == -1) {
         $i_formselect_last = $lastposition + 1;
         $i_formselect_value = $lastposition + 1;
         $item->position = $lastposition + 1;
     } else {
         $i_formselect_last = $lastposition;
         $i_formselect_value = $item->position;
     }
     //the elements for position dropdownlist
     $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
     $item->presentation = empty($item->presentation) ? '' : $item->presentation;
     $info = $this->get_info($item);
     $item->ignoreempty = $this->ignoreempty($item);
     $item->hidenoselect = $this->hidenoselect($item);
     //all items for dependitem
     $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
     $commonparams = array('cmid' => $cm->id, 'id' => isset($item->id) ? $item->id : NULL, 'typ' => $item->typ, 'items' => $feedbackitems, 'feedback' => $feedback->id);
     //build the form
     $this->item_form = new feedback_multichoicerated_form('edit_item.php', array('item' => $item, 'common' => $commonparams, 'positionlist' => $positionlist, 'position' => $position, 'info' => $info));
 }
 public function getHot($hour = 1, $num = 10, $page = 1)
 {
     $map['create_time'] = array('gt', time() - $hour * 60 * 60);
     $map['status'] = 1;
     $weiboModel = D('Weibo');
     $all_topic = $this->where(array('status' => 1), array(array('read_count' => array('neq', 0))))->select();
     foreach ($all_topic as $key => &$v) {
         $map['content'] = array('like', "%#{$v['name']}#%");
         $v['weibos'] = $weiboModel->where($map)->count();
         if ($v['weibos'] == 0) {
             unset($all_topic[$key]);
         }
         $v['user'] = query_user(array('space_link'), $v['uadmin']);
     }
     unset($v);
     $all_topic = $this->arraySortByKey($all_topic, 'weibos', false);
     $i = 0;
     foreach ($all_topic as &$v) {
         $v['top_num'] = ++$i;
     }
     unset($v);
     $pager = new Page(count($all_topic), $num);
     // dump($all_topic);exit;
     $list['data'] = array_slice($all_topic, ($page - 1) * $num, $num);
     $list['html'] = $pager->show();
     return $list;
 }
 /**
  * Set up the columns, dataset, paginator
  * @return void
  */
 public function prepare_items()
 {
     // Set up columns
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Perform bulk actions
     $this->do_bulk_action();
     $data = $this->_get_profiles();
     // Sort data
     $orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'name';
     $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'asc';
     $data = $this->_sort($data, $orderby, $order);
     // 20 items per page
     $per_page = 20;
     // Get page number
     $current_page = $this->get_pagenum();
     // Get total items
     $total_items = count($data);
     // Carve out only the visible dataset
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     $this->items = $data;
     // Set up the paginator
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
 public function getPosition($from = 1, $count = 1)
 {
     $console = Console::getInstance();
     $console->operationStart('Collecting search results');
     $this->pageNumber = ceil($from / $this->positionsPerPage);
     if ($count < 1 || $count > 10) {
         $console->operationEnd();
         $console - error('Count must be in 1-10. ' . $count . ' is setted');
         return false;
     }
     $sites = array();
     $position = 1;
     do {
         $console->operationStep();
         $pageResults = $this->getPageResults();
         foreach ($pageResults as $pr) {
             $sitesCount = count($sites);
             $domain = ($domain = String::rebuildUrl($pr->url, false, false, true, false)) ? $domain : $pr->url;
             if (IgnoreList::isInList($domain) || $sitesCount && $sites[$sitesCount - 1]->domain == $domain) {
                 continue;
             }
             $site = new Site();
             $site->name = strip_tags($pr->title);
             $site->position = $position++;
             $site->link = $pr->url;
             $site->domain = $domain;
             $sites[] = $site;
         }
         $this->pageNumber++;
     } while ($sitesCount < $count);
     //$this->pageNumber++ * $this->positionsPerPage < $count // old
     $console->operationEnd();
     return array_slice($sites, 0, $count);
 }
Example #29
0
 /**
  * Returns an object list
  *
  * @param	string The query
  * @param	int Offset
  * @param	int The number of records
  * @return	array
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $ordering = $this->getState('list.ordering');
     $search = $this->getState('filter.search');
     // Replace slashes so preg_match will work
     $search = str_replace('/', ' ', $search);
     $db = $this->getDbo();
     if ($ordering == 'name' || !empty($search) && stripos($search, 'id:') !== 0) {
         $db->setQuery($query);
         $result = $db->loadObjectList();
         $lang = JFactory::getLanguage();
         $this->translate($result);
         if (!empty($search)) {
             foreach ($result as $i => $item) {
                 if (!preg_match("/{$search}/i", $item->name)) {
                     unset($result[$i]);
                 }
             }
         }
         JArrayHelper::sortObjects($result, $this->getState('list.ordering'), $this->getState('list.direction') == 'desc' ? -1 : 1, true, $lang->getLocale());
         $total = count($result);
         $this->cache[$this->getStoreId('getTotal')] = $total;
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     } else {
         $query->order($db->quoteName($ordering) . ' ' . $this->getState('list.direction'));
         $result = parent::_getList($query, $limitstart, $limit);
         $this->translate($result);
         return $result;
     }
 }
Example #30
-15
 function onls()
 {
     $logdir = UC_ROOT . 'data/logs/';
     $dir = opendir($logdir);
     $logs = $loglist = array();
     while ($entry = readdir($dir)) {
         if (is_file($logdir . $entry) && strpos($entry, '.php') !== FALSE) {
             $logs = array_merge($logs, file($logdir . $entry));
         }
     }
     closedir($dir);
     $logs = array_reverse($logs);
     foreach ($logs as $k => $v) {
         if (count($v = explode("\t", $v)) > 1) {
             $v[3] = $this->date($v[3]);
             $v[4] = $this->lang[$v[4]];
             $loglist[$k] = $v;
         }
     }
     $page = max(1, intval($_GET['page']));
     $start = ($page - 1) * UC_PPP;
     $num = count($loglist);
     $multipage = $this->page($num, UC_PPP, $page, 'admin.php?m=log&a=ls');
     $loglist = array_slice($loglist, $start, UC_PPP);
     $this->view->assign('loglist', $loglist);
     $this->view->assign('multipage', $multipage);
     $this->view->display('admin_log');
 }